Time-of-Flight Library(ToF) 3.11.1
 
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
8namespace chronoptics {
9namespace tof {
10
11/** The different matrix types
12 */
13enum 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
26using user_pointer_destructed_fn = std::function<void(uint8_t*, size_t)>;
27constexpr 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*/
31class 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() const {
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 /** The acceleration measured by the imu
177 * @return Acceleration, x y z
178 */
179 std::array<int16_t, 3> acceleration() const {
180 std::array<int16_t, 3> array;
181 auto data = tof_data_acceleration(this->ptr_, TOF_ERROR_HANDLER{});
182 std::copy(data, data + array.size(), array.data());
183 return array;
184 }
185
186 /** The angular velocity measured by the imu
187 * @return Angular velocity, x y z
188 */
189 std::array<int16_t, 3> angular_velocity() const {
190 std::array<int16_t, 3> array;
191 auto data = tof_data_angular_velocity(this->ptr_, TOF_ERROR_HANDLER{});
192 std::copy(data, data + array.size(), array.data());
193 return array;
194 }
195
196// Custom code
197
198 /** Get the data at location p, templated because the data type can differ.
199 * @param pos Location of the data to get
200 * @returns Data of type T
201 */
202 template <typename T>
203 const T& at(size_t pos) const {
204 auto non_const = const_cast<tof::Data*>(this);
205 return reinterpret_cast<const T*>(non_const->data())[pos];
206 }
207
208 /** Get the data at location p, templated because the data type can differ.
209 * @param pos Location of the data to get
210 * @returns Data of type T
211 */
212 template <typename T>
213 T& at(size_t pos) {
214 return reinterpret_cast<T*>(data())[pos];
215 }
216
217 /** Return iterator to beginning, templated because the data type can differ.
218 * @returns Begin iterator to T
219 */
220 template <typename T>
221 const T* begin() const {
222 auto non_const = const_cast<tof::Data*>(this);
223 return reinterpret_cast<const T*>(non_const->data());
224 }
225
226 /** Return iterator to beginning, templated because the data type can differ.
227 * @returns Begin iterator to T
228 */
229 template <typename T>
230 T* begin() {
231 return reinterpret_cast<T*>(data());
232 }
233
234 /** Return iterator to end, templated because the data type can differ.
235 * @returns End iterator to T
236 */
237 template <typename T>
238 const T* end() const {
239 auto non_const = const_cast<tof::Data*>(this);
240 return reinterpret_cast<const T*>(non_const->data()) + rows() * cols();
241 }
242
243 /** Return iterator to end, templated because the data type can differ.
244 * @returns End iterator to T
245 */
246 template <typename T>
247 T* end() {
248 return reinterpret_cast<T*>(data()) + rows() * cols();
249 }
250};
251
252} // tof
253} // chronoptics
254
255#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
T & at(size_t pos)
Get the data at location p, templated because the data type can differ.
Definition: data.hpp:213
const T * end() const
Return iterator to end, templated because the data type can differ.
Definition: data.hpp:238
float scale() const
Get the scale used for integer frames, to get the original value divide by scale.
Definition: data.hpp:133
size_t size() const
Get size of the data.
Definition: data.hpp:48
std::array< int16_t, 3 > acceleration() const
The acceleration measured by the imu.
Definition: data.hpp:179
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:247
std::vector< float > temperatures() const
Get the temperature of various parts of the camera.
Definition: data.hpp:148
uint16_t frame_count() const
The frame counter.
Definition: data.hpp:90
const T * begin() const
Return iterator to beginning, templated because the data type can differ.
Definition: data.hpp:221
MatType mat_type() const
Get the matrix type.
Definition: data.hpp:69
void * user_pointer() const
The user data that was given in the add_user_pointer function.
Definition: data.hpp:172
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
T * begin()
Return iterator to beginning, templated because the data type can differ.
Definition: data.hpp:230
float addition() const
Get the addition used for integer frames, to get the original value substract the addition.
Definition: data.hpp:141
void * data() const
Get pointer to data.
Definition: data.hpp:41
uint32_t frame_id() const
Get the frame id.
Definition: data.hpp:104
int32_t rows() const
Get the number of rows.
Definition: data.hpp:76
const T & at(size_t pos) const
Get the data at location p, templated because the data type can differ.
Definition: data.hpp:203
uint8_t sync_count() const
Get the synchronization count.
Definition: data.hpp:158
std::array< int16_t, 3 > angular_velocity() const
The angular velocity measured by the imu.
Definition: data.hpp:189