ImageSequencePlaybackStrategy.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package visionx::imrec
17  * @author Christian R. G. Dreher <christian.dreher@student.kit.edu>
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #pragma once
25 
26 
27 // STD/STL
28 #include <filesystem>
29 #include <string>
30 #include <vector>
31 
32 // VisionX
34 
35 
36 namespace visionx::imrec::strats
37 {
38  class ImageSequencePlaybackStrategy;
39 }
40 
41 
42 
45 {
46 
47 private:
48 
49  /**
50  * @brief Flag to indicate whether the instance is configured for playback or not
51  */
52  bool playingBack;
53 
54  /**
55  * @brief Index of the current frame
56  */
57  unsigned int currentFrame;
58 
59  /**
60  * @brief Total amount of frames
61  */
62  unsigned int frameCount;
63 
64  /**
65  * @brief Base path of the recordig frame files
66  */
67  std::filesystem::path basePath;
68 
69  /**
70  * @brief Prefix of an image file which must match to be considered a frame
71  */
72  std::string requiredPrefix;
73 
74  /**
75  * @brief Suffix of an image file which must match to be considered a frame
76  */
77  std::string requiredSuffix;
78 
79  /**
80  * @brief Sorted list of each frame in the image sequence
81  */
82  std::vector<std::filesystem::path> framePaths;
83 
84  /**
85  * @brief Height of an individual frame in pixel
86  */
87  unsigned int frameHeight;
88 
89  /**
90  * @brief Width of an individual frame in pixel
91  */
92  unsigned int frameWidth;
93 
94 public:
95 
96  /**
97  * @brief Default constructor to manually setup later
98  */
100 
101  /**
102  * @brief Constructor initialising the playback immediately
103  * @param filePath Path to the recording
104  */
105  ImageSequencePlaybackStrategy(const std::filesystem::path& filePath);
106 
107  /**
108  * @brief Destructor
109  */
110  virtual ~ImageSequencePlaybackStrategy() override;
111 
112  /**
113  * @brief Indicates whether the instance is configured to be able to play back
114  * @return True if it is playing back, false otherwise
115  */
116  virtual bool isPlayingBack() const override;
117 
118  /**
119  * @brief Gets the amount of frames per second of the recording
120  * @return Amount of frames per second of the recording
121  */
122  virtual unsigned int getFps() const override;
123 
124  /**
125  * @brief Gets the total amout of frames in the recording
126  * @return Total amount of frames in the recording
127  */
128  virtual unsigned int getFrameCount() const override;
129 
130  /**
131  * @brief Gets the height of a frame in pixel
132  * @return Height of a frame in pixel
133  */
134  virtual unsigned int getFrameHeight() const override;
135 
136  /**
137  * @brief Gets the width of a frame in pixel
138  * @return Width of a frame in pixel
139  */
140  virtual unsigned int getFrameWidth() const override;
141 
142  /**
143  * @brief Sets the frame from there the playback should resume afterwards (seek)
144  * @param frame Frame from where the playback should be resumed (e.g. "0" to replay from the beginning)
145  */
146  virtual void setCurrentFrame(unsigned int frame) override;
147 
148  /**
149  * @brief Gets the current frame index of the playback
150  * @return The current frame index
151  */
152  virtual unsigned int getCurrentFrame() const override;
153 
154  /**
155  * @brief Indicates whether the recording has a consecutive frame
156  * @return True, if there is a consecutive frame, false otherwise
157  */
158  virtual bool hasNextFrame() const override;
159 
160  /**
161  * @brief Starts the playback
162  * @param filePath Path to the recording to play back
163  */
164  virtual void startPlayback(const std::filesystem::path& filePath) override;
165 
166  /**
167  * @brief Writes the next frame into a buffer of any form (RGB)
168  * @param buffer Output parameter where the frame data of the next frame should be written to
169  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
170  */
171  virtual bool getNextFrame(void* buffer) override;
172 
173  /**
174  * @brief Writes the next frame into an IVT CByteImage buffer (RGB)
175  * @param buffer Output parameter where the frame data of the next frame should be written to
176  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
177  */
178  virtual bool getNextFrame(::CByteImage& buffer) override;
179 
180  /**
181  * @brief Writes the next frame into an OpenCV Mat buffer (BGR)
182  * @param buffer Output parameter where the frame data of the next frame should be written to
183  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
184  */
185  virtual bool getNextFrame(cv::Mat& buffer) override;
186 
187  /**
188  * @brief Stops the playback
189  */
190  virtual void stopPlayback() override;
191 
192 private:
193 
194  /**
195  * @brief Initialises the base path, and the required prefix and suffix for each frame file
196  * @param filePath Given path
197  */
198  void initBasePathPrefixSuffix(const std::filesystem::path& filePath);
199 
200  /**
201  * @brief Initialises each frame path given the requirements
202  */
203  void initFramePaths();
204 
205  /**
206  * @brief Initialise the height and width of an individual frame
207  */
208  void initFrameDimensions();
209 
210 };
visionx::imrec::strats::ImageSequencePlaybackStrategy::getCurrentFrame
virtual unsigned int getCurrentFrame() const override
Gets the current frame index of the playback.
Definition: ImageSequencePlaybackStrategy.cpp:115
AbstractPlaybackStrategy.h
visionx::imrec::strats::ImageSequencePlaybackStrategy::startPlayback
virtual void startPlayback(const std::filesystem::path &filePath) override
Starts the playback.
Definition: ImageSequencePlaybackStrategy.cpp:129
visionx::imrec::strats::ImageSequencePlaybackStrategy::hasNextFrame
virtual bool hasNextFrame() const override
Indicates whether the recording has a consecutive frame.
Definition: ImageSequencePlaybackStrategy.cpp:122
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFrameWidth
virtual unsigned int getFrameWidth() const override
Gets the width of a frame in pixel.
Definition: ImageSequencePlaybackStrategy.cpp:101
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFps
virtual unsigned int getFps() const override
Gets the amount of frames per second of the recording.
Definition: ImageSequencePlaybackStrategy.cpp:78
visionx::imrec::strats::ImageSequencePlaybackStrategy
Definition: ImageSequencePlaybackStrategy.h:43
visionx::imrec::strats::ImageSequencePlaybackStrategy::~ImageSequencePlaybackStrategy
virtual ~ImageSequencePlaybackStrategy() override
Destructor.
Definition: ImageSequencePlaybackStrategy.cpp:64
visionx::imrec::strats::ImageSequencePlaybackStrategy::ImageSequencePlaybackStrategy
ImageSequencePlaybackStrategy()
Default constructor to manually setup later.
Definition: ImageSequencePlaybackStrategy.cpp:47
visionx::imrec::strats::ImageSequencePlaybackStrategy::stopPlayback
virtual void stopPlayback() override
Stops the playback.
Definition: ImageSequencePlaybackStrategy.cpp:196
visionx::imrec::strats
Definition: ChunkedImageSequencePlaybackStrategy.h:38
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFrameHeight
virtual unsigned int getFrameHeight() const override
Gets the height of a frame in pixel.
Definition: ImageSequencePlaybackStrategy.cpp:94
visionx::imrec::strats::ImageSequencePlaybackStrategy::setCurrentFrame
virtual void setCurrentFrame(unsigned int frame) override
Sets the frame from there the playback should resume afterwards (seek)
Definition: ImageSequencePlaybackStrategy.cpp:108
visionx::imrec::strats::ImageSequencePlaybackStrategy::getNextFrame
virtual bool getNextFrame(void *buffer) override
Writes the next frame into a buffer of any form (RGB)
Definition: ImageSequencePlaybackStrategy.cpp:142
visionx::imrec::strats::ImageSequencePlaybackStrategy::getFrameCount
virtual unsigned int getFrameCount() const override
Gets the total amout of frames in the recording.
Definition: ImageSequencePlaybackStrategy.cpp:87
visionx::imrec::AbstractPlaybackStrategy
Definition: AbstractPlaybackStrategy.h:52
visionx::imrec::strats::ImageSequencePlaybackStrategy::isPlayingBack
virtual bool isPlayingBack() const override
Indicates whether the instance is configured to be able to play back.
Definition: ImageSequencePlaybackStrategy.cpp:71