ifw-ccf 6.0.0
 
Loading...
Searching...
No Matches
dataFrame.hpp
Go to the documentation of this file.
1
6
7#ifndef CCF_COMMON_DATA_FRAME_HPP_H_
8#define CCF_COMMON_DATA_FRAME_HPP_H_
9
10#include <ifw/fnd/defs/dataType.hpp>
11
12#include <ifw/core/utils/param/parameter.hpp>
13
15
16
17namespace ifw::ccf::common {
18
20 class DataFrame: public Base {
21 public:
22
24 //inline static int32_t GetCFitsioType(const DataType data_type);
25
27 DataFrame(const std::string& frame_id,
28 const int16_t frame_q_nb);
29
31 DataFrame(const DataFrame& source);
32
33 DataFrame();
34
35 ~DataFrame();
36
37 void Reset();
38
40 const std::string& GetFrameId() const;
41
43 int16_t GetFrameQNb() const;
44
61 void Store(const void* buffer,
62 const uint32_t size,
63 const double time,
64 const int64_t cam_frame_count,
65 const int64_t int_frame_count,
66 const int64_t sub_frame_count,
67 const int64_t exp_nb_sub_frames,
68 const ifw::fnd::datatype::DataType data_type,
69 const int32_t offset_x,
70 const int32_t offset_y,
71 const int32_t width,
72 const int32_t height,
73 const int32_t depth = 1);
74
76 void AddData(const void* buffer,
77 const uint32_t size);
78
80 const void* GetBuffer() const;
81
84 void* GetBufferReadWrite() const;
85
87 uint32_t GetBufferSize() const;
88
90 uint32_t GetDataSize() const;
91
93 void ResetDataSize();
94
96 double GetDataSum() const;
97
99 double GetTime() const;
100
103 int64_t GetCamFrameCount() const;
104
106 int64_t GetIntFrameCount() const;
107
109 int64_t GetSubFrameCount() const;
110
112 int64_t GetExpNbSubFrames() const;
113
115 int32_t GetOffsetX() const;
116
118 int32_t GetOffsetY() const;
119
121 int32_t GetWidth() const;
122
124 int32_t GetHeight() const;
125
127 int32_t GetDepth() const;
128
131 ifw::fnd::datatype::DataType GetDataType() const;
132
134 int32_t GetResolution() const;
135
137 bool GetCompleted() const;
138
140 void SetCompleted();
141
145 template <class TYPE>
146 void AddMetaData(const std::string& name,
147 TYPE& value) {
148 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
149 //m_meta_data[name] = ifw::core::utils::param::Parameter(name, std::to_string(value));
150 if constexpr(std::is_arithmetic_v<TYPE>) {
151 // Use std::to_string for numeric types
152 m_meta_data[name] = ifw::core::utils::param::Parameter(name, std::to_string(value));
153 } else if constexpr(std::is_same_v<TYPE, std::string>) {
154 // Use the string directly
155 m_meta_data[name] = ifw::core::utils::param::Parameter(name, value);
156 } else {
157 // Compilation error for unsupported types
158 static_assert(std::is_arithmetic_v<TYPE> || std::is_same_v<TYPE, std::string>,
159 "Unsupported type: AddMetaData only supports numeric types and "
160 "std::string");
161 }
162 }
163
165 void RemoveMetaData(const std::string& name);
166
168 template <class TYPE>
169 bool HasMetadata(const std::string& name,
170 TYPE& value) const {
171 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
172 auto it = m_meta_data.find(name);
173 if (it == m_meta_data.end()) {
174 return false;
175 }
176 it->second.GetValue(value);
177 return true;
178 }
179
181 std::string ToString(const bool full = false) const;
182
185 void SetConsumerCount(const uint8_t count);
186
189 uint8_t GetConsumerCount() const;
190
193 void DecrementConsumerCount(const uint8_t decr = 1);
194
196 void SetHandlingStartTime(const double time);
197
199 double GetHandlingStartTime() const;
200
202 double GetHandlingTime() const;
203
204 DataFrame& operator = (const DataFrame& source);
205
206 protected:
207
208 private:
209 void Initialise(const std::string& frame_id = "",
210 const int64_t frame_nb = -1);
211 void Copy(const DataFrame& source);
212
213 std::string m_frame_id;
214 int64_t m_frame_q_nb;
215
216 int64_t m_cam_frame_count{0};
217 int64_t m_int_frame_count{0};
218
219 int64_t m_sub_frame_count{0};
220 int64_t m_exp_nb_sub_frames{0};
221
222 uint8_t m_consumer_count{0};
223
224 double m_handling_start_time{0.0};
225
226 void* m_buffer{nullptr};
227 uint32_t m_size{0};
228 uint32_t m_expected_size{0};
229 uint32_t m_cur_allocated{0};
230 bool m_completed{false};
231
232 double m_time{0.0};
233
234 ifw::fnd::datatype::DataType m_data_type{ifw::fnd::datatype::DataType::UNSPECIFIED};
235 int32_t m_offset_x{1};
236 int32_t m_offset_y{1};
237 int32_t m_width{0};
238 int32_t m_height{0};
239 int32_t m_depth{1};
240
241 std::map<std::string, ifw::core::utils::param::Parameter> m_meta_data;
242
243 template <class DATA_TYPE>
244 double Sum() const {
245 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
246 double sum = 0;
247 DATA_TYPE* p = static_cast<DATA_TYPE*>(m_buffer);
248 for (int64_t i = 0; i < GetDataSize(); i++) {
249 sum += static_cast<DATA_TYPE>(*p++);
250 }
251 return sum;
252 }
253
254 };
255
256}
257
258#endif // CCF_COMMON_DATA_FRAME_HPP_H_
Base()
Definition base.cpp:121
Frame class used to store the data and metadata for one frames received from the camera.
Definition dataFrame.hpp:20
std::string ToString(const bool full=false) const
Generate a representative (short) string representation (summary) of the object.
Definition dataFrame.cpp:65
ifw::fnd::datatype::DataType GetDataType() const
Definition dataFrame.cpp:312
bool GetCompleted() const
Return true if the image in the object is complete according to width/height/data type.
Definition dataFrame.cpp:232
double GetHandlingStartTime() const
Get the time for starting the handling of the frame.
Definition dataFrame.cpp:333
uint32_t GetBufferSize() const
Get the size of the internal buffer allocated, in bytes.
Definition dataFrame.cpp:277
int32_t GetWidth() const
Get the width of the ROI applied by the camera.
Definition dataFrame.cpp:297
void RemoveMetaData(const std::string &name)
Remove a given metadata parameter from the object.
Definition dataFrame.cpp:365
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:272
int32_t GetDepth() const
Get the number of frames if a three dimensional image is contained in the object.
Definition dataFrame.cpp:307
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:194
double GetDataSum() const
Compute the data sum of all pixels.
Definition dataFrame.cpp:373
~DataFrame()
Definition dataFrame.cpp:40
void SetCompleted()
Mark the frame as completed.
Definition dataFrame.cpp:237
void * GetBufferReadWrite() const
Definition dataFrame.cpp:267
int32_t GetHeight() const
Get the height of the ROI applied by the camera.
Definition dataFrame.cpp:302
const std::string & GetFrameId() const
Return the frame ID allocated.
Definition dataFrame.cpp:55
int32_t GetOffsetY() const
Get vertical offset of the ROI applied by the camera.
Definition dataFrame.cpp:292
int32_t GetOffsetX() const
Get horisontal offset of the ROI applied by the camera.
Definition dataFrame.cpp:287
double GetTime() const
Get the current time stamp stored in the object.
Definition dataFrame.cpp:282
DataFrame & operator=(const DataFrame &source)
Definition dataFrame.cpp:322
int64_t GetExpNbSubFrames() const
Expected number of sub-frames if the data of a frame is received in sub-frames (blocks).
Definition dataFrame.cpp:257
const void * GetBuffer() const
Get read-only pointer to internal image buffer.
Definition dataFrame.cpp:262
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:252
int64_t GetCamFrameCount() const
Definition dataFrame.cpp:242
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:60
int64_t GetIntFrameCount() const
Internall frame counter, counting the frames receives since the last Start command (first frame == 1)...
Definition dataFrame.cpp:247
double GetHandlingTime() const
Get handling time (duration for handling the frame in the given context).
Definition dataFrame.cpp:338
void SetHandlingStartTime(const double time)
Set the start time for handling handling the frame.
Definition dataFrame.cpp:328
void Reset()
Definition dataFrame.cpp:48
bool HasMetadata(const std::string &name, TYPE &value) const
Get a parameter value from the configuration.
Definition dataFrame.hpp:169
void AddMetaData(const std::string &name, TYPE &value)
Definition dataFrame.hpp:146
DataFrame(const std::string &frame_id, const int16_t frame_q_nb)
Get CFITSIO data type.
Definition dataFrame.cpp:14
int32_t GetResolution() const
Get the resolution (bytes/pixel) of the image currently stored in the object.
Definition dataFrame.cpp:317
void SetConsumerCount(const uint8_t count)
Definition dataFrame.cpp:93
void DecrementConsumerCount(const uint8_t decr=1)
Definition dataFrame.cpp:108
DataFrame()
Definition dataFrame.cpp:35
Definition appBase.cpp:10
log4cplus::Logger & Logger()
Definition base.cpp:24