ifw-ccf  1.0.0
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 <ctd/param/Parameter.hpp>
9 
10 #include <ccf/common/base.hpp>
11 
12 namespace ccf::common {
13 
15  class DataFrame: public Base {
16  public:
17 
19  static int16_t DataTypeToResolution(const ImageDataType data_type);
20 
22  DataFrame(const std::string& frame_id,
23  const int16_t frame_q_nb);
24 
26  DataFrame(const DataFrame& source);
27 
28  DataFrame();
29 
30  ~DataFrame();
31 
32  void Reset();
33 
35  const std::string& GetFrameId() const;
36 
38  int16_t GetFrameQNb() const;
39 
56  void Store(const void* buffer,
57  const uint32_t size,
58  const double time,
59  const int64_t cam_frame_count,
60  const int64_t int_frame_count,
61  const int64_t sub_frame_count,
62  const int64_t exp_nb_sub_frames,
63  const ImageDataType data_type,
64  const int32_t offset_x,
65  const int32_t offset_y,
66  const int32_t width,
67  const int32_t height,
68  const int32_t depth = 1);
69 
71  const void* GetBuffer() const;
72 
75  void* GetBufferReadWrite() const;
76 
78  uint32_t GetBufferSize() const;
79 
81  uint32_t GetDataSize() const;
82 
84  void ResetDataSize();
85 
87  double GetDataSum() const;
88 
90  double GetTime() const;
91 
93  int64_t GetCamFrameCount() const;
94 
96  int64_t GetIntFrameCount() const;
97 
99  int64_t GetSubFrameCount() const;
100 
102  int64_t GetExpNbSubFrames() const;
103 
105  int32_t GetOffsetX() const;
106 
108  int32_t GetOffsetY() const;
109 
111  int32_t GetWidth() const;
112 
114  int32_t GetHeight() const;
115 
117  int32_t GetDepth() const;
118 
120  ImageDataType GetDataType() const;
121 
123  int32_t GetResolution() const;
124 
127  template <class TYPE>
128  void AddMetaData(const std::string& name,
129  TYPE& value) {
130  CCFTRACE;
131  m_meta_data[name] = ctd::param::Parameter(name, std::to_string(value));
132  }
133 
135  void RemoveMetaData(const std::string& name);
136 
138  template <class TYPE>
139  bool HasMetadata(const std::string& name,
140  TYPE& value) const {
141  CCFTRACE;
142  auto it = m_meta_data.find(name);
143  if (it == m_meta_data.end()) {
144  return false;
145  }
146  it->second.GetValue(value);
147  return true;
148  }
149 
151  std::string ToString(const bool full = false) const;
152 
155  void SetConsumerCount(const uint8_t count);
156 
159  uint8_t GetConsumerCount() const;
160 
163  void DecrementConsumerCount(const uint8_t decr = 1);
164 
166  void SetHandlingStartTime(const double time);
167 
169  double GetHandlingStartTime() const;
170 
172  double GetHandlingTime() const;
173 
174  DataFrame& operator = (const DataFrame& source);
175 
176  protected:
177 
178  private:
179  void _Initialise(const std::string& frame_id = "",
180  const int64_t frame_nb = -1);
181  void _Copy(const DataFrame& source);
182 
183  std::string m_frame_id;
184  int64_t m_frame_q_nb;
185 
186  int64_t m_cam_frame_count;
187  int64_t m_int_frame_count;
188 
189  int64_t m_sub_frame_count;
190  int64_t m_exp_nb_sub_frames;
191 
192  uint8_t m_consumer_count;
193 
194  double m_handling_start_time;
195 
196  void* m_buffer;
197  uint32_t m_size;
198  uint32_t m_cur_allocated;
199 
200  double m_time;
201 
202  ImageDataType m_data_type;
203  int32_t m_offset_x;
204  int32_t m_offset_y;
205  int32_t m_width;
206  int32_t m_height;
207  int32_t m_depth;
208 
209  std::map<std::string, ctd::param::Parameter> m_meta_data;
210 
211  template <class DATA_TYPE>
212  double _Sum() const {
213  CCFTRACE;
214  double sum = 0;
215  DATA_TYPE* p = static_cast<DATA_TYPE*>(m_buffer);
216  for (int64_t i = 0; i < GetDataSize(); i++) {
217  sum += static_cast<DATA_TYPE>(*p++);
218  }
219  return sum;
220  }
221 
222  };
223 
224 }
225 
226 #endif // CCF_COMMON_DATA_FRAME_HPP_H_
ccf::common::ImageDataType
ImageDataType
CCF image data types. Based on the values defined for BITPIX in the FITS standard.
Definition: base.hpp:153
ccf::common::DataFrame::GetDataSize
uint32_t GetDataSize() const
Return the sizein bytes of the image.
Definition: dataFrame.cpp:222
ccf::common::DataFrame::GetCamFrameCount
int64_t GetCamFrameCount() const
Counter indicating the number of the frame received from the camera, if provided by the camera (first...
Definition: dataFrame.cpp:192
ccf::common::DataFrame::ToString
std::string ToString(const bool full=false) const
Generate a representative (short) string representation (summary) of the object.
Definition: dataFrame.cpp:79
ccf::common::DataFrame::GetWidth
int32_t GetWidth() const
Get the width of the ROI applied by the camera.
Definition: dataFrame.cpp:247
ccf::common::DataFrame::GetConsumerCount
uint8_t GetConsumerCount() const
Definition: dataFrame.cpp:117
ccf::common::DataFrame::GetFrameId
const std::string & GetFrameId() const
Return the frame ID allocated.
Definition: dataFrame.cpp:69
ccf::common::DataFrame::GetHeight
int32_t GetHeight() const
Get the height of the ROI applied by the camera.
Definition: dataFrame.cpp:252
ccf::common::DataFrame::GetBufferReadWrite
void * GetBufferReadWrite() const
Definition: dataFrame.cpp:217
ccf::common::DataFrame::GetResolution
int32_t GetResolution() const
Get the resolution (bits/pixel) of the image currently stored in the object.
Definition: dataFrame.cpp:267
ccf::common::DataFrame::RemoveMetaData
void RemoveMetaData(const std::string &name)
Remove a given metadata parameter from the object.
Definition: dataFrame.cpp:314
ccf::common::DataFrame::GetIntFrameCount
int64_t GetIntFrameCount() const
Internall frame counter, counting the frames receives since the last Start command (first frame == 1)...
Definition: dataFrame.cpp:197
ccf::common::DataFrame::SetConsumerCount
void SetConsumerCount(const uint8_t count)
Definition: dataFrame.cpp:106
ccf::common::Base
Class to be used as parent all CCF classes.
Definition: base.hpp:93
ccf::common::DataFrame::ResetDataSize
void ResetDataSize()
Reset the size of the image. This indicates that no image is stored in the object.
Definition: dataFrame.cpp:141
ccf::common::DataFrame::GetDataType
ImageDataType GetDataType() const
Get the type of the image pixels currently stored in the object. The types defined by the FITS specif...
Definition: dataFrame.cpp:262
ccf::common::DataFrame::GetBuffer
const void * GetBuffer() const
Get read-only pointer to internal image buffer.
Definition: dataFrame.cpp:212
ccf::common::DataFrame::GetFrameQNb
int16_t GetFrameQNb() const
Return the frame queue number, when used in a queue.
Definition: dataFrame.cpp:74
ccf::common::DataFrame::HasMetadata
bool HasMetadata(const std::string &name, TYPE &value) const
Get a parameter value from the configuration.
Definition: dataFrame.hpp:139
ccf::common::DataFrame::DataTypeToResolution
static int16_t DataTypeToResolution(const ImageDataType data_type)
Derive resolution (bytes per pixel) from data type.
Definition: dataFrame.cpp:12
ccf::common::DataFrame::GetDataSum
double GetDataSum() const
Compute the data sum of all pixels.
Definition: dataFrame.cpp:322
ccf::common::DataFrame::Store
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 ImageDataType 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:146
ccf::common::DataFrame::AddMetaData
void AddMetaData(const std::string &name, TYPE &value)
Definition: dataFrame.hpp:128
ccf::common::DataFrame::GetExpNbSubFrames
int64_t GetExpNbSubFrames() const
Expected number of sub-frames if the data of a frame is received in sub-frames (blocks).
Definition: dataFrame.cpp:207
ccf::common::DataFrame::GetOffsetY
int32_t GetOffsetY() const
Get vertical offset of the ROI applied by the camera.
Definition: dataFrame.cpp:242
ccf::common::DataFrame::Reset
void Reset()
Definition: dataFrame.cpp:65
ccf::common::DataFrame::~DataFrame
~DataFrame()
Definition: dataFrame.cpp:57
ccf::common::DataFrame::DataFrame
DataFrame()
Definition: dataFrame.cpp:52
ccf::common::DataFrame::GetHandlingStartTime
double GetHandlingStartTime() const
Get the time for starting the handling of the frame.
Definition: dataFrame.cpp:283
base.hpp
ccf::common
Definition: appBase.cpp:8
ccf::common::DataFrame::DecrementConsumerCount
void DecrementConsumerCount(const uint8_t decr=1)
Definition: dataFrame.cpp:122
ccf::common::DataFrame::GetHandlingTime
double GetHandlingTime() const
Get handling time (duration for handling the frame in the given context).
Definition: dataFrame.cpp:288
ccf::common::DataFrame::GetDepth
int32_t GetDepth() const
Get the number of frames if a three dimensional image is contained in the object.
Definition: dataFrame.cpp:257
ccf::common::DataFrame::GetBufferSize
uint32_t GetBufferSize() const
Get the internal buffer size in bytes.
Definition: dataFrame.cpp:227
CCFTRACE
#define CCFTRACE
TRACE log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:403
ccf::common::DataFrame::GetSubFrameCount
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:202
ccf::common::DataFrame::GetTime
double GetTime() const
Get the current time stamp stored in the object.
Definition: dataFrame.cpp:232
ccf::common::DataFrame::GetOffsetX
int32_t GetOffsetX() const
Get horisontal offset of the ROI applied by the camera.
Definition: dataFrame.cpp:237
ccf::common::DataFrame::SetHandlingStartTime
void SetHandlingStartTime(const double time)
Set the start time for handling handling the frame.
Definition: dataFrame.cpp:278
ccf::common::DataFrame
Frame class used to store the data and metadata for one frames received from the camera.
Definition: dataFrame.hpp:15
ccf::common::DataFrame::operator=
DataFrame & operator=(const DataFrame &source)
Definition: dataFrame.cpp:272