Ocean
Loading...
Searching...
No Matches
ImageFileSequence.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_MEDIA_IMAGE_FILE_SEQUENCE_H
9#define META_OCEAN_MEDIA_IMAGE_FILE_SEQUENCE_H
10
11#include "ocean/media/Media.h"
13
14#include "ocean/base/Thread.h"
15
17
18namespace Ocean
19{
20
21namespace Media
22{
23
24/*
25 * This class implements the base class for all image sequences based on actual files (and not on databases containing images).
26 * the class is mainly an intermediate helper class to simplify the implementation of an ImageSequence based on files.
27 * @ingroup media
28 */
29class OCEAN_MEDIA_EXPORT ImageFileSequence :
30 public virtual ImageSequence,
31 protected Thread
32{
33 public:
34
35 /**
36 * Returns the duration of the finite medium.
37 * @see FiniteMedium::duration().
38 */
39 double duration() const override;
40
41 /**
42 * Returns the duration without speed consideration.
43 * @see FiniteMedium::normalDuration().
44 */
45 double normalDuration() const override;
46
47 /**
48 * Returns the recent position of the finite medium.
49 * @see FiniteMedium::position().
50 */
51 double position() const override;
52
53 /**
54 * Returns the speed of the finite medium.
55 * The speed of an image sequence is identical with the preferred frame rate (fps).
56 * @return The current speed of this image sequence in fps, with range [0, infinity)
57 */
58 float speed() const override;
59
60 /**
61 * Returns the url of the current image.
62 * @see ImageSequence::currentUrl().
63 */
64 std::string currentUrl() const override;
65
66 /**
67 * Returns the number of images part of the sequence.
68 * @see ImageSequence::images().
69 */
70 unsigned int images() const override;
71
72 /**
73 * Starts the medium.
74 * @see Medium::start().
75 */
76 bool start() override;
77
78 /**
79 * Pauses the medium.
80 * @see Medium::pause().
81 */
82 bool pause() override;
83
84 /**
85 * Stops the medium.
86 * @see Medium::stop().
87 */
88 bool stop() override;
89
90 /**
91 * Returns whether the medium is started currently.
92 * @see Medium::isStarted().
93 */
94 bool isStarted() const override;
95
96 /**
97 * Returns the start timestamp.
98 * @see FiniteMedium::startTimestamp().
99 */
100 Timestamp startTimestamp() const override;
101
102 /**
103 * Returns the pause timestamp.
104 * @see FiniteMedium::pauseTimestamp().
105 */
106 Timestamp pauseTimestamp() const override;
107
108 /**
109 * Returns the stop timestamp.
110 * @see FiniteMedium::stopTimestamp().
111 */
112 Timestamp stopTimestamp() const override;
113
114 /**
115 * Sets the recent position of the finite medium.
116 * @see FiniteMedium::setPosition().
117 */
118 bool setPosition(const double position) override;
119
120 /**
121 * Sets the speed of the finite medium.
122 * The speed of an image sequence is identical with the preferred frame rate (fps).
123 * @param speed The speed to be set in fps, with range [0, infinity)
124 * @see setPreferredFrameFrequency().
125 */
126 bool setSpeed(const float speed) override;
127
128 /**
129 * Sets the known camera profile of this frame medium.
130 * @see FrameMedium::setCamera().
131 */
132 bool setCamera(SharedAnyCamera&& camera) override;
133
134 /**
135 * Forces the loading of the next image in the sequence.
136 * @see ImageSequence::forceNextFrame().
137 */
138 bool forceNextFrame() override;
139
140 /**
141 * Returns whether a given filename is the start of an image file sequence.
142 * The function checks whether the file exists, whether the filename ends with a numeric index pattern, and whether a subsequent image file exists at the next index.
143 * @param filename The path of the file to check, must be valid
144 * @param isIndividualImage Optional resulting flag; True, if the file is an individual image (not part of a sequence); False, otherwise
145 * @return True, if the file is the start of an image file sequence
146 */
147 static bool isFileSequence(const std::string& filename, bool* isIndividualImage = nullptr);
148
149 protected:
150
151 /**
152 * Creates a new image file sequence by a given url.
153 * @param url Url of the image
154 */
155 explicit ImageFileSequence(const std::string& url);
156
157 /**
158 * Destructs an image file sequence object.
159 */
161
162 /**
163 * Thread run function.
164 * @see Thread::threadRun().
165 */
166 void threadRun() override;
167
168 /**
169 * Determines the image sequence parameters.
170 * @return True, if succeeded
171 */
173
174 /**
175 * Returns the filename of a specific sequence image.
176 * @param index The index of the sequence image to create the filename for
177 * @return Sequence image filename
178 */
179 std::string imageFilename(const unsigned int index) const;
180
181 /**
182 * Loads a new image specified by the filename.
183 * @param filename The filename of the image to be loaded
184 * @param timestamp Frame timestamp to be used
185 * @param frame Optional frame receiving the image data, otherwise the frame will be added to the frame container
186 * @return True, if succeeded
187 */
188 virtual bool loadImage(const std::string& filename, const Timestamp timestamp, Frame* frame = nullptr) = 0;
189
190 protected:
191
192 /// Start timestamp.
194
195 /// Pause timestamp.
197
198 /// Stop timestamp.
200
201 /// Image sequence prefix filename.
202 std::string filenamePrefix_;
203
204 /// Image sequence filename type.
205 std::string filenameType_;
206
207 /// Next frame in the sequence.
209
210 /// The camera profile for all images.
212};
213
214}
215
216}
217
218#endif // META_OCEAN_MEDIA_IMAGE_FILE_SEQUENCE_H
This class implements Ocean's image class.
Definition Frame.h:1879
Definition ImageFileSequence.h:32
std::string currentUrl() const override
Returns the url of the current image.
Frame nextFrame_
Next frame in the sequence.
Definition ImageFileSequence.h:208
Timestamp startTimestamp() const override
Returns the start timestamp.
std::string imageFilename(const unsigned int index) const
Returns the filename of a specific sequence image.
void threadRun() override
Thread run function.
bool forceNextFrame() override
Forces the loading of the next image in the sequence.
bool setPosition(const double position) override
Sets the recent position of the finite medium.
unsigned int images() const override
Returns the number of images part of the sequence.
std::string filenameType_
Image sequence filename type.
Definition ImageFileSequence.h:205
bool stop() override
Stops the medium.
Timestamp stopTimestamp_
Stop timestamp.
Definition ImageFileSequence.h:199
double normalDuration() const override
Returns the duration without speed consideration.
bool isStarted() const override
Returns whether the medium is started currently.
std::string filenamePrefix_
Image sequence prefix filename.
Definition ImageFileSequence.h:202
ImageFileSequence(const std::string &url)
Creates a new image file sequence by a given url.
Timestamp stopTimestamp() const override
Returns the stop timestamp.
float speed() const override
Returns the speed of the finite medium.
Timestamp startTimestamp_
Start timestamp.
Definition ImageFileSequence.h:193
double position() const override
Returns the recent position of the finite medium.
bool setSpeed(const float speed) override
Sets the speed of the finite medium.
static bool isFileSequence(const std::string &filename, bool *isIndividualImage=nullptr)
Returns whether a given filename is the start of an image file sequence.
SharedAnyCamera camera_
The camera profile for all images.
Definition ImageFileSequence.h:211
Timestamp pauseTimestamp() const override
Returns the pause timestamp.
double duration() const override
Returns the duration of the finite medium.
Timestamp pauseTimestamp_
Pause timestamp.
Definition ImageFileSequence.h:196
virtual bool loadImage(const std::string &filename, const Timestamp timestamp, Frame *frame=nullptr)=0
Loads a new image specified by the filename.
bool start() override
Starts the medium.
~ImageFileSequence() override
Destructs an image file sequence object.
bool pause() override
Pauses the medium.
bool determineSequence()
Determines the image sequence parameters.
bool setCamera(SharedAnyCamera &&camera) override
Sets the known camera profile of this frame medium.
This class is the base class for all image sequences.
Definition ImageSequence.h:52
This class implements a thread.
Definition Thread.h:115
This class implements a timestamp.
Definition Timestamp.h:64
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
The namespace covering the entire Ocean framework.
Definition Accessor.h:15