ifw-ccf 5.0.2
Loading...
Searching...
No Matches
dataFrame.hpp
Go to the documentation of this file.
1
5#ifndef CCF_COMMON_DATA_FRAME_HPP_H_
6#define CCF_COMMON_DATA_FRAME_HPP_H_
7
8#include <ifw/fnd/defs/dataType.hpp>
9
10#include <ifw/core/utils/param/parameter.hpp>
11
13
14
15namespace ifw::ccf::common {
16
18 class DataFrame: public Base {
19 public:
20
22 //inline static int32_t GetCFitsioType(const DataType data_type);
23
25 DataFrame(const std::string& frame_id,
26 const int16_t frame_q_nb);
27
29 DataFrame(const DataFrame& source);
30
31 DataFrame();
32
33 ~DataFrame();
34
35 void Reset();
36
38 const std::string& GetFrameId() const;
39
41 int16_t GetFrameQNb() const;
42
59 void Store(const void* buffer,
60 const uint32_t size,
61 const double time,
62 const int64_t cam_frame_count,
63 const int64_t int_frame_count,
64 const int64_t sub_frame_count,
65 const int64_t exp_nb_sub_frames,
66 const ifw::fnd::datatype::DataType data_type,
67 const int32_t offset_x,
68 const int32_t offset_y,
69 const int32_t width,
70 const int32_t height,
71 const int32_t depth = 1);
72
74 void AddData(const void* buffer,
75 const uint32_t size);
76
78 const void* GetBuffer() const;
79
82 void* GetBufferReadWrite() const;
83
85 uint32_t GetBufferSize() const;
86
88 uint32_t GetDataSize() const;
89
91 void ResetDataSize();
92
94 double GetDataSum() const;
95
97 double GetTime() const;
98
101 int64_t GetCamFrameCount() const;
102
104 int64_t GetIntFrameCount() const;
105
107 int64_t GetSubFrameCount() const;
108
110 int64_t GetExpNbSubFrames() const;
111
113 int32_t GetOffsetX() const;
114
116 int32_t GetOffsetY() const;
117
119 int32_t GetWidth() const;
120
122 int32_t GetHeight() const;
123
125 int32_t GetDepth() const;
126
129 ifw::fnd::datatype::DataType GetDataType() const;
130
132 int32_t GetResolution() const;
133
135 bool GetCompleted() const;
136
138 void SetCompleted();
139
143 template <class TYPE>
144 void AddMetaData(const std::string& name,
145 TYPE& value) {
146 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
147 //m_meta_data[name] = ifw::core::utils::param::Parameter(name, std::to_string(value));
148 if constexpr(std::is_arithmetic_v<TYPE>) {
149 // Use std::to_string for numeric types
150 m_meta_data[name] = ifw::core::utils::param::Parameter(name, std::to_string(value));
151 } else if constexpr(std::is_same_v<TYPE, std::string>) {
152 // Use the string directly
153 m_meta_data[name] = ifw::core::utils::param::Parameter(name, value);
154 } else {
155 // Compilation error for unsupported types
156 static_assert(std::is_arithmetic_v<TYPE> || std::is_same_v<TYPE, std::string>,
157 "Unsupported type: AddMetaData only supports numeric types and "
158 "std::string");
159 }
160 }
161
163 void RemoveMetaData(const std::string& name);
164
166 template <class TYPE>
167 bool HasMetadata(const std::string& name,
168 TYPE& value) const {
169 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
170 auto it = m_meta_data.find(name);
171 if (it == m_meta_data.end()) {
172 return false;
173 }
174 it->second.GetValue(value);
175 return true;
176 }
177
179 std::string ToString(const bool full = false) const;
180
183 void SetConsumerCount(const uint8_t count);
184
187 uint8_t GetConsumerCount() const;
188
191 void DecrementConsumerCount(const uint8_t decr = 1);
192
194 void SetHandlingStartTime(const double time);
195
197 double GetHandlingStartTime() const;
198
200 double GetHandlingTime() const;
201
202 DataFrame& operator = (const DataFrame& source);
203
204 protected:
205
206 private:
207 void Initialise(const std::string& frame_id = "",
208 const int64_t frame_nb = -1);
209 void Copy(const DataFrame& source);
210
211 std::string m_frame_id;
212 int64_t m_frame_q_nb;
213
214 int64_t m_cam_frame_count{0};
215 int64_t m_int_frame_count{0};
216
217 int64_t m_sub_frame_count{0};
218 int64_t m_exp_nb_sub_frames{0};
219
220 uint8_t m_consumer_count{0};
221
222 double m_handling_start_time{0.0};
223
224 void* m_buffer{nullptr};
225 uint32_t m_size{0};
226 uint32_t m_expected_size{0};
227 uint32_t m_cur_allocated{0};
228 bool m_completed{false};
229
230 double m_time{0.0};
231
232 ifw::fnd::datatype::DataType m_data_type{ifw::fnd::datatype::DataType::UNSPECIFIED};
233 int32_t m_offset_x{1};
234 int32_t m_offset_y{1};
235 int32_t m_width{0};
236 int32_t m_height{0};
237 int32_t m_depth{1};
238
239 std::map<std::string, ifw::core::utils::param::Parameter> m_meta_data;
240
241 template <class DATA_TYPE>
242 double Sum() const {
243 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
244 double sum = 0;
245 DATA_TYPE* p = static_cast<DATA_TYPE*>(m_buffer);
246 for (int64_t i = 0; i < GetDataSize(); i++) {
247 sum += static_cast<DATA_TYPE>(*p++);
248 }
249 return sum;
250 }
251
252 };
253
254}
255
256#endif // CCF_COMMON_DATA_FRAME_HPP_H_
Class to be used as parent all CCF classes.
Definition base.hpp:120
Frame class used to store the data and metadata for one frames received from the camera.
Definition dataFrame.hpp:18
std::string ToString(const bool full=false) const
Generate a representative (short) string representation (summary) of the object.
Definition dataFrame.cpp:64
ifw::fnd::datatype::DataType GetDataType() const
Definition dataFrame.cpp:313
bool GetCompleted() const
Return true if the image in the object is complete according to width/height/data type.
Definition dataFrame.cpp:233
double GetHandlingStartTime() const
Get the time for starting the handling of the frame.
Definition dataFrame.cpp:334
uint32_t GetBufferSize() const
Get the size of the internal buffer allocated, in bytes.
Definition dataFrame.cpp:278
int32_t GetWidth() const
Get the width of the ROI applied by the camera.
Definition dataFrame.cpp:298
void RemoveMetaData(const std::string &name)
Remove a given metadata parameter from the object.
Definition dataFrame.cpp:366
void ResetDataSize()
Reset the size of the image. This indicates that no image is stored in the object.
Definition dataFrame.cpp:127
uint32_t GetDataSize() const
Return the size in bytes of the image.
Definition dataFrame.cpp:273
int32_t GetDepth() const
Get the number of frames if a three dimensional image is contained in the object.
Definition dataFrame.cpp:308
uint8_t GetConsumerCount() const
Definition dataFrame.cpp:103
void AddData(const void *buffer, const uint32_t size)
Add a new chunk of data in the image buffer. Used to build up the image incrementally.
Definition dataFrame.cpp:195
double GetDataSum() const
Compute the data sum of all pixels.
Definition dataFrame.cpp:374
~DataFrame()
Definition dataFrame.cpp:39
void SetCompleted()
Mark the frame as completed.
Definition dataFrame.cpp:238
void * GetBufferReadWrite() const
Definition dataFrame.cpp:268
int32_t GetHeight() const
Get the height of the ROI applied by the camera.
Definition dataFrame.cpp:303
const std::string & GetFrameId() const
Return the frame ID allocated.
Definition dataFrame.cpp:54
int32_t GetOffsetY() const
Get vertical offset of the ROI applied by the camera.
Definition dataFrame.cpp:293
int32_t GetOffsetX() const
Get horisontal offset of the ROI applied by the camera.
Definition dataFrame.cpp:288
double GetTime() const
Get the current time stamp stored in the object.
Definition dataFrame.cpp:283
DataFrame & operator=(const DataFrame &source)
Definition dataFrame.cpp:323
int64_t GetExpNbSubFrames() const
Expected number of sub-frames if the data of a frame is received in sub-frames (blocks).
Definition dataFrame.cpp:258
const void * GetBuffer() const
Get read-only pointer to internal image buffer.
Definition dataFrame.cpp:263
int64_t GetSubFrameCount() const
Number of a sub-frame if the data of a frame is received in sub-frames (blocks) (first sub-frame == 1...
Definition dataFrame.cpp:253
int64_t GetCamFrameCount() const
Definition dataFrame.cpp:243
void Store(const void *buffer, const uint32_t size, const double time, const int64_t cam_frame_count, const int64_t int_frame_count, const int64_t sub_frame_count, const int64_t exp_nb_sub_frames, const ifw::fnd::datatype::DataType data_type, const int32_t offset_x, const int32_t offset_y, const int32_t width, const int32_t height, const int32_t depth=1)
Store an image frame (or sub-frame) in the object.
Definition dataFrame.cpp:132
int16_t GetFrameQNb() const
Return the frame queue number, when used in a queue.
Definition dataFrame.cpp:59
int64_t GetIntFrameCount() const
Internall frame counter, counting the frames receives since the last Start command (first frame == 1)...
Definition dataFrame.cpp:248
double GetHandlingTime() const
Get handling time (duration for handling the frame in the given context).
Definition dataFrame.cpp:339
void SetHandlingStartTime(const double time)
Set the start time for handling handling the frame.
Definition dataFrame.cpp:329
void Reset()
Definition dataFrame.cpp:47
bool HasMetadata(const std::string &name, TYPE &value) const
Get a parameter value from the configuration.
Definition dataFrame.hpp:167
void AddMetaData(const std::string &name, TYPE &value)
Definition dataFrame.hpp:144
int32_t GetResolution() const
Get the resolution (bytes/pixel) of the image currently stored in the object.
Definition dataFrame.cpp:318
void SetConsumerCount(const uint8_t count)
Definition dataFrame.cpp:92
void DecrementConsumerCount(const uint8_t decr=1)
Definition dataFrame.cpp:108
DataFrame()
Definition dataFrame.cpp:34
Definition appBase.cpp:9
log4cplus::Logger & Logger()
Definition base.cpp:23