Time-of-Flight Library(ToF)  3.2.4
data.hpp
1 #ifndef _CHRONOPTICS_TOF_DATA_HPP_
2 #define _CHRONOPTICS_TOF_DATA_HPP_
3 
4 #include <chronoptics/tof/data.h>
5 
6 #include <chronoptics/tof/stream.hpp>
7 
8 namespace chronoptics {
9 namespace tof {
10 
11 /** The different matrix types
12  */
13 enum class MatType {
14  UINT8 = 0, /** A single unsigned byte */
15  INT8 = 1, /** A single signed byte */
16  UINT16 = 2, /** Two unsigned bytes */
17  INT16 = 3, /** Two signed bytes */
18  INT32 = 4, /** Four signed bytes */
19  FLOAT = 5, /** Four bytes floating point value */
20  DOUBLE = 6, /** Eight bytes floating point value */
21  FLOAT_4 = 29, /** Four bytes floating point value with four channels */
22  FLOAT_8 = 61, /** Four bytes floating point value with eight channels */
23 };
24 
25 // Function signature of callback that's called after a tof_data object is destructed containing a user pointer
26 using user_pointer_destructed_fn = std::function<void(uint8_t*, size_t)>;
27 constexpr auto user_pointer_destructed_cb_handler = &detail::callback_handler<void, uint8_t*, size_t>;
28 
29 /** This is the class that contains depth or image data
30 */
31 class Data : public detail::Base<tof_data, tof_data_delete> {
32  public:
33  /** Construct from pointer */
34  Data(tof_data_t ptr = nullptr) {
35  this->ptr_ = ptr;
36  }
37 
38  /** Get pointer to data
39  * @return
40  */
41  void* data() {
42  return tof_data_data(this->ptr_, TOF_ERROR_HANDLER{});
43  }
44 
45  /** Get size of the data
46  * @return The size
47  */
48  size_t size() const {
49  return tof_data_size(this->ptr_, TOF_ERROR_HANDLER{});
50  }
51 
52  /** Get user data that will get saved to csf file
53  * @return Set user data
54  */
55  uint64_t get_user_data() const {
56  return tof_data_get_user_data(this->ptr_, TOF_ERROR_HANDLER{});
57  }
58 
59  /** Set user data that will get saved to csf file
60  * @param user_data Set user data
61  */
62  void set_user_data(uint64_t user_data) {
63  return tof_data_set_user_data(this->ptr_, user_data, TOF_ERROR_HANDLER{});
64  }
65 
66  /** Get the matrix type
67  * @return The matrix type
68  */
69  MatType mat_type() const {
70  return static_cast<MatType>(tof_data_mat_type(this->ptr_, TOF_ERROR_HANDLER{}));
71  }
72 
73  /** Get the number of rows
74  * @return Number of rows
75  */
76  int32_t rows() const {
77  return tof_data_rows(this->ptr_, TOF_ERROR_HANDLER{});
78  }
79 
80  /** Get the number of columns
81  * @return Number of columns
82  */
83  int32_t cols() const {
84  return tof_data_cols(this->ptr_, TOF_ERROR_HANDLER{});
85  }
86 
87  /** The frame counter
88  * @return Frame count
89  */
90  uint16_t frame_count() const {
91  return tof_data_frame_count(this->ptr_, TOF_ERROR_HANDLER{});
92  }
93 
94  /** Get the frame type
95  * @return The frame type
96  */
97  FrameType frame_type() const {
98  return static_cast<FrameType>(tof_data_frame_type(this->ptr_, TOF_ERROR_HANDLER{}));
99  }
100 
101  /** Get the frame id
102  * @return The frame id
103  */
104  uint32_t frame_id() const {
105  return tof_data_frame_id(this->ptr_, TOF_ERROR_HANDLER{});
106  }
107 
108  /** Get the modulation frequency of the frame
109  * @return The modulation frequency
110  */
111  float modulation_frequency() const {
112  return tof_data_modulation_frequency(this->ptr_, TOF_ERROR_HANDLER{});
113  }
114 
115  /** Get the integration time of the frame
116  * @return The integration time
117  */
118  uint32_t integration_time() const {
119  return tof_data_integration_time(this->ptr_, TOF_ERROR_HANDLER{});
120  }
121 
122  /** Get a bit array of the processing performed on the frame
123  * @return A bit array
124  */
125  uint32_t process() const {
126  return tof_data_process(this->ptr_, TOF_ERROR_HANDLER{});
127  }
128 
129  /** Get the scale used for integer frames, to get the original value divide by
130  * scale
131  * @return The scale
132  */
133  float scale() const {
134  return tof_data_scale(this->ptr_, TOF_ERROR_HANDLER{});
135  }
136 
137  /** Get the addition used for integer frames, to get the original value
138  * substract the addition
139  * @return The addition
140  */
141  float addition() const {
142  return tof_data_addition(this->ptr_, TOF_ERROR_HANDLER{});
143  }
144 
145  /** Get the temperature of various parts of the camera
146  * @return Temperatures
147  */
148  std::vector<float> temperatures() const {
149  size_t size = tof_data_temperatures(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
150  std::vector<float> vec(size);
151  size = tof_data_temperatures(this->ptr_, vec.data(), vec.size(), TOF_ERROR_HANDLER{});
152  return vec;
153  }
154 
155  /** Get the synchronization count
156  * @return Sync count
157  */
158  uint8_t sync_count() const {
159  return tof_data_sync_count(this->ptr_, TOF_ERROR_HANDLER{});
160  }
161 
162  /** Check whether the data uses a pointer supplied by the user
163  * @return Data allocated by user
164  */
165  bool user_allocated() const {
166  return tof_data_user_allocated(this->ptr_, TOF_ERROR_HANDLER{});
167  }
168 
169  /** The user data that was given in the add_user_pointer function
170  * @return User pointer
171  */
172  void* user_pointer() const {
173  return tof_data_user_pointer(this->ptr_, TOF_ERROR_HANDLER{});
174  }
175 
176 // Custom code
177 
178  /** Get the data at location p, templated because the data type can differ.
179  * @param pos Location of the data to get
180  * @returns Data of type T
181  */
182  template <typename T>
183  const T& at(size_t pos) const {
184  auto non_const = const_cast<tof::Data*>(this);
185  return reinterpret_cast<const T*>(non_const->data())[pos];
186  }
187 
188  /** Get the data at location p, templated because the data type can differ.
189  * @param pos Location of the data to get
190  * @returns Data of type T
191  */
192  template <typename T>
193  T& at(size_t pos) {
194  return reinterpret_cast<T*>(data())[pos];
195  }
196 
197  /** Return iterator to beginning, templated because the data type can differ.
198  * @returns Begin iterator to T
199  */
200  template <typename T>
201  const T* begin() const {
202  auto non_const = const_cast<tof::Data*>(this);
203  return reinterpret_cast<const T*>(non_const->data());
204  }
205 
206  /** Return iterator to beginning, templated because the data type can differ.
207  * @returns Begin iterator to T
208  */
209  template <typename T>
210  T* begin() {
211  return reinterpret_cast<T*>(data());
212  }
213 
214  /** Return iterator to end, templated because the data type can differ.
215  * @returns End iterator to T
216  */
217  template <typename T>
218  const T* end() const {
219  auto non_const = const_cast<tof::Data*>(this);
220  return reinterpret_cast<const T*>(non_const->data()) + rows() * cols();
221  }
222 
223  /** Return iterator to end, templated because the data type can differ.
224  * @returns End iterator to T
225  */
226  template <typename T>
227  T* end() {
228  return reinterpret_cast<T*>(data()) + rows() * cols();
229  }
230 };
231 
232 } // tof
233 } // chronoptics
234 
235 #endif
This is the class that contains depth or image data.
Definition: data.hpp:31
uint64_t get_user_data() const
Get user data that will get saved to csf file.
Definition: data.hpp:55
float modulation_frequency() const
Get the modulation frequency of the frame.
Definition: data.hpp:111
bool user_allocated() const
Check whether the data uses a pointer supplied by the user.
Definition: data.hpp:165
float scale() const
Get the scale used for integer frames, to get the original value divide by scale.
Definition: data.hpp:133
const T * begin() const
Return iterator to beginning, templated because the data type can differ.
Definition: data.hpp:201
size_t size() const
Get size of the data.
Definition: data.hpp:48
FrameType frame_type() const
Get the frame type.
Definition: data.hpp:97
int32_t cols() const
Get the number of columns.
Definition: data.hpp:83
T * end()
Return iterator to end, templated because the data type can differ.
Definition: data.hpp:227
void * user_pointer() const
The user data that was given in the add_user_pointer function.
Definition: data.hpp:172
uint16_t frame_count() const
The frame counter.
Definition: data.hpp:90
MatType mat_type() const
Get the matrix type.
Definition: data.hpp:69
T & at(size_t pos)
Get the data at location p, templated because the data type can differ.
Definition: data.hpp:193
void * data()
Get pointer to data.
Definition: data.hpp:41
const T * end() const
Return iterator to end, templated because the data type can differ.
Definition: data.hpp:218
const T & at(size_t pos) const
Get the data at location p, templated because the data type can differ.
Definition: data.hpp:183
Data(tof_data_t ptr=nullptr)
Construct from pointer.
Definition: data.hpp:34
uint32_t process() const
Get a bit array of the processing performed on the frame.
Definition: data.hpp:125
uint32_t integration_time() const
Get the integration time of the frame.
Definition: data.hpp:118
void set_user_data(uint64_t user_data)
Set user data that will get saved to csf file.
Definition: data.hpp:62
float addition() const
Get the addition used for integer frames, to get the original value substract the addition.
Definition: data.hpp:141
uint32_t frame_id() const
Get the frame id.
Definition: data.hpp:104
T * begin()
Return iterator to beginning, templated because the data type can differ.
Definition: data.hpp:210
int32_t rows() const
Get the number of rows.
Definition: data.hpp:76
uint8_t sync_count() const
Get the synchronization count.
Definition: data.hpp:158
std::vector< float > temperatures() const
Get the temperature of various parts of the camera.
Definition: data.hpp:148