ifw-ccf  3.0.0-pre2
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 <core/utils/param/parameter.hpp>
9 
10 #include <ccf/common/base.hpp>
11 #include <ccf/common/dataType.hpp>
12 
13 
14 namespace ccf::common {
15 
17  class DataFrame: public Base {
18  public:
19 
21  inline static int32_t GetCFitsioType(const DataTypes data_type);
22 
24  //static int16_t BitpixToResolution(const FitsBitpixTypes bitpix);
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 DataTypes 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  DataTypes 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] = core::utils::param::Parameter(name, std::to_string(value));
150  }
151 
153  void RemoveMetaData(const std::string& name);
154 
156  template <class TYPE>
157  bool HasMetadata(const std::string& name,
158  TYPE& value) const {
159  LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
160  auto it = m_meta_data.find(name);
161  if (it == m_meta_data.end()) {
162  return false;
163  }
164  it->second.GetValue(value);
165  return true;
166  }
167 
169  std::string ToString(const bool full = false) const;
170 
173  void SetConsumerCount(const uint8_t count);
174 
177  uint8_t GetConsumerCount() const;
178 
181  void DecrementConsumerCount(const uint8_t decr = 1);
182 
184  void SetHandlingStartTime(const double time);
185 
187  double GetHandlingStartTime() const;
188 
190  double GetHandlingTime() const;
191 
192  DataFrame& operator = (const DataFrame& source);
193 
194  protected:
195 
196  private:
197  void _Initialise(const std::string& frame_id = "",
198  const int64_t frame_nb = -1);
199  void _Copy(const DataFrame& source);
200 
201  std::string m_frame_id;
202  int64_t m_frame_q_nb;
203 
204  int64_t m_cam_frame_count;
205  int64_t m_int_frame_count;
206 
207  int64_t m_sub_frame_count;
208  int64_t m_exp_nb_sub_frames;
209 
210  uint8_t m_consumer_count;
211 
212  double m_handling_start_time;
213 
214  void* m_buffer;
215  uint32_t m_size;
216  uint32_t m_expected_size;
217  uint32_t m_cur_allocated;
218  bool m_completed;
219 
220  double m_time;
221 
222  DataTypes m_data_type;
223  int32_t m_offset_x;
224  int32_t m_offset_y;
225  int32_t m_width;
226  int32_t m_height;
227  int32_t m_depth;
228 
229  std::map<std::string, core::utils::param::Parameter> m_meta_data;
230 
231  template <class DATA_TYPE>
232  double _Sum() const {
233  LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
234  double sum = 0;
235  DATA_TYPE* p = static_cast<DATA_TYPE*>(m_buffer);
236  for (int64_t i = 0; i < GetDataSize(); i++) {
237  sum += static_cast<DATA_TYPE>(*p++);
238  }
239  return sum;
240  }
241 
242  };
243 
244 }
245 
246 #endif // CCF_COMMON_DATA_FRAME_HPP_H_
Class to be used as parent all CCF classes.
Definition: base.hpp:151
Frame class used to store the data and metadata for one frames received from the camera.
Definition: dataFrame.hpp:17
void SetConsumerCount(const uint8_t count)
Definition: dataFrame.cpp:110
void DecrementConsumerCount(const uint8_t decr=1)
Definition: dataFrame.cpp:126
const void * GetBuffer() const
Get read-only pointer to internal image buffer.
Definition: dataFrame.cpp:274
int32_t GetWidth() const
Get the width of the ROI applied by the camera.
Definition: dataFrame.cpp:309
int32_t GetResolution() const
Get the resolution (bytes/pixel) of the image currently stored in the object.
Definition: dataFrame.cpp:329
void Reset()
Definition: dataFrame.cpp:65
int16_t GetFrameQNb() const
Return the frame queue number, when used in a queue.
Definition: dataFrame.cpp:77
double GetDataSum() const
Compute the data sum of all pixels.
Definition: dataFrame.cpp:385
int64_t GetCamFrameCount() const
Definition: dataFrame.cpp:254
double GetHandlingTime() const
Get handling time (duration for handling the frame in the given context).
Definition: dataFrame.cpp:350
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:264
~DataFrame()
Definition: dataFrame.cpp:57
DataTypes GetDataType() const
Definition: dataFrame.cpp:324
double GetHandlingStartTime() const
Get the time for starting the handling of the frame.
Definition: dataFrame.cpp:345
DataFrame & operator=(const DataFrame &source)
Definition: dataFrame.cpp:334
bool HasMetadata(const std::string &name, TYPE &value) const
Get a parameter value from the configuration.
Definition: dataFrame.hpp:157
void * GetBufferReadWrite() const
Definition: dataFrame.cpp:279
void RemoveMetaData(const std::string &name)
Remove a given metadata parameter from the object.
Definition: dataFrame.cpp:377
DataFrame()
Definition: dataFrame.cpp:52
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:212
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 DataTypes 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:150
static int32_t GetCFitsioType(const DataTypes data_type)
Get CFITSIO data type.
int32_t GetDepth() const
Get the number of frames if a three dimensional image is contained in the object.
Definition: dataFrame.cpp:319
int64_t GetExpNbSubFrames() const
Expected number of sub-frames if the data of a frame is received in sub-frames (blocks).
Definition: dataFrame.cpp:269
double GetTime() const
Get the current time stamp stored in the object.
Definition: dataFrame.cpp:294
int32_t GetOffsetX() const
Get horisontal offset of the ROI applied by the camera.
Definition: dataFrame.cpp:299
uint8_t GetConsumerCount() const
Definition: dataFrame.cpp:121
void ResetDataSize()
Reset the size of the image. This indicates that no image is stored in the object.
Definition: dataFrame.cpp:145
bool GetCompleted() const
Return true if the image in the object is complete according to width/height/data type.
Definition: dataFrame.cpp:244
uint32_t GetBufferSize() const
Get the size of the internal buffer allocated, in bytes.
Definition: dataFrame.cpp:289
int64_t GetIntFrameCount() const
Internall frame counter, counting the frames receives since the last Start command (first frame == 1)...
Definition: dataFrame.cpp:259
uint32_t GetDataSize() const
Return the size in bytes of the image.
Definition: dataFrame.cpp:284
void SetCompleted()
Mark the frame as completed.
Definition: dataFrame.cpp:249
int32_t GetHeight() const
Get the height of the ROI applied by the camera.
Definition: dataFrame.cpp:314
void AddMetaData(const std::string &name, TYPE &value)
Definition: dataFrame.hpp:146
const std::string & GetFrameId() const
Return the frame ID allocated.
Definition: dataFrame.cpp:72
void SetHandlingStartTime(const double time)
Set the start time for handling handling the frame.
Definition: dataFrame.cpp:340
std::string ToString(const bool full=false) const
Generate a representative (short) string representation (summary) of the object.
Definition: dataFrame.cpp:82
int32_t GetOffsetY() const
Get vertical offset of the ROI applied by the camera.
Definition: dataFrame.cpp:304
Definition: appBase.cpp:8
log4cplus::Logger & Logger()
Definition: base.cpp:9
DataTypes
Definition: dataType.hpp:46