Time-of-Flight Library(ToF) 3.11.1
 
camera.hpp
1#ifndef _CHRONOPTICS_TOF_CAMERA_HPP_
2#define _CHRONOPTICS_TOF_CAMERA_HPP_
3
4#include <chronoptics/tof/camera.h>
5
6#include <chronoptics/tof/stream.hpp>
7#include <chronoptics/tof/processing_config.hpp>
8#include <chronoptics/tof/data.hpp>
9#include <chronoptics/tof/camera_config.hpp>
10#include <chronoptics/tof/calibration.hpp>
11
12namespace chronoptics {
13namespace tof {
14
15/** The main interface to the depth cameras
16*/
17class Camera : public detail::Base<tof_camera, tof_camera_delete> {
18 public:
19 /** Construct from pointer */
20 Camera(tof_camera_t ptr = nullptr) {
21 this->ptr_ = ptr;
22 }
23
24 /** Start streaming of the camera
25 */
26 void start() {
27 return tof_camera_start(this->ptr_, TOF_ERROR_HANDLER{});
28 }
29
30 /** Stop streaming of the camera
31 */
32 void stop() {
33 return tof_camera_stop(this->ptr_, TOF_ERROR_HANDLER{});
34 }
35
36 /** Check whether the camera is streaming
37 * @return Is streaming
38 */
39 bool is_streaming() const {
40 return tof_camera_is_streaming(this->ptr_, TOF_ERROR_HANDLER{});
41 }
42
43 /** Check whether the camera is still connected
44 * @return Is connected
45 */
46 bool is_connected() const {
47 return tof_camera_is_connected(this->ptr_, TOF_ERROR_HANDLER{});
48 }
49
50 /** Get the different output streams the camera can provide
51 * @return The streams
52 */
53 std::vector<Stream> get_stream_list() const {
54 size_t size = tof_camera_get_stream_list(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
55 std::vector<Stream> vec;
56 vec.reserve(size);
57 for (size_t i = 0; i < size; i++)
58 vec.emplace_back(static_cast<tof_stream_t>(nullptr));
59 auto data = reinterpret_cast<tof_stream_t*>(vec.data());
60 size = tof_camera_get_stream_list(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
61 return vec;
62 }
63
64 /** Set the streams that you want to get from the camera
65 * @param streams The wanted streams
66 */
67 void set_stream_list(const std::vector<Stream> &streams) {
68 return tof_camera_set_stream_list(this->ptr_, reinterpret_cast<const tof_stream_t*>(streams.data()), streams.size(), TOF_ERROR_HANDLER{});
69 }
70
71 /** Check whether the stream list is set
72 * @return Is stream list set
73 */
74 bool is_stream_list_set() const {
75 return tof_camera_is_stream_list_set(this->ptr_, TOF_ERROR_HANDLER{});
76 }
77
78 /** Get the stream list that is set on the camera
79 * @return The currently set streams
80 */
81 std::vector<Stream> get_set_stream_list() {
82 size_t size = tof_camera_get_set_stream_list(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
83 std::vector<Stream> vec;
84 vec.reserve(size);
85 for (size_t i = 0; i < size; i++)
86 vec.emplace_back(static_cast<tof_stream_t>(nullptr));
87 auto data = reinterpret_cast<tof_stream_t*>(vec.data());
88 size = tof_camera_get_set_stream_list(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
89 return vec;
90 }
91
92 /** Get the processing config of the camera
93 * @return The processing config
94 */
96 ProcessingConfig new_processing_config(static_cast<tof_processing_config_t>(nullptr));
97 auto ptr = reinterpret_cast<tof_processing_config_t*>(&new_processing_config);
98 *ptr = tof_camera_get_process_config(this->ptr_, TOF_ERROR_HANDLER{});
99 return new_processing_config;
100 }
101
102 /** Set the processing config of the camera
103 * @param config The processing config
104 */
106 return tof_camera_set_process_config(this->ptr_, *reinterpret_cast<tof_processing_config_t*>(&config), TOF_ERROR_HANDLER{});
107 }
108
109 /** Check if the camera has frames available
110 * @return Has frames available
111 */
112 bool has_frames() const {
113 return tof_camera_has_frames(this->ptr_, TOF_ERROR_HANDLER{});
114 }
115
116 /** Get data frames from camera
117 * @return Data frames
118 */
119 std::vector<Data> get_frames() {
120 size_t size = tof_camera_get_frames(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
121 std::vector<Data> vec;
122 vec.reserve(size);
123 for (size_t i = 0; i < size; i++)
124 vec.emplace_back(static_cast<tof_data_t>(nullptr));
125 auto data = reinterpret_cast<tof_data_t*>(vec.data());
126 size = tof_camera_get_frames(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
127 return vec;
128 }
129
130 /** Clear the circular buffer used to store frames
131 */
133 return tof_camera_clear_buffer(this->ptr_, TOF_ERROR_HANDLER{});
134 }
135
136 /** Get the circular buffer size
137 * @return The maximum number of sets of frames that is stored before the
138 * oldest is overwritten
139 */
140 size_t get_buffer_size() const {
141 return tof_camera_get_buffer_size(this->ptr_, TOF_ERROR_HANDLER{});
142 }
143
144 /** Set the circular buffer size
145 * @param size The maximum number of sets of frames that is stored before the
146 * oldest is overwritten
147 */
148 void set_buffer_size(size_t size) {
149 return tof_camera_set_buffer_size(this->ptr_, size, TOF_ERROR_HANDLER{});
150 }
151
152 /** Get the currently active camera config
153 * @return The camera config
154 */
156 CameraConfig new_camera_config(static_cast<tof_camera_config_t>(nullptr));
157 auto ptr = reinterpret_cast<tof_camera_config_t*>(&new_camera_config);
158 *ptr = tof_camera_get_camera_config(this->ptr_, TOF_ERROR_HANDLER{});
159 return new_camera_config;
160 }
161
162 /** Get the serial number of the current camera
163 * @return The serial
164 */
165 const char* get_serial() const {
166 return tof_camera_get_serial(this->ptr_, TOF_ERROR_HANDLER{});
167 }
168
169 /** Get calibration from the camera
170 * @return The calibration
171 */
173 Calibration new_calibration(static_cast<tof_calibration_t>(nullptr));
174 auto ptr = reinterpret_cast<tof_calibration_t*>(&new_calibration);
175 *ptr = tof_camera_get_calibration(this->ptr_, TOF_ERROR_HANDLER{});
176 return new_calibration;
177 }
178
179 /** Get the amount of user pointers that can be stored
180 * @return The capacity
181 */
183 return tof_camera_get_user_pointer_capacity(this->ptr_, TOF_ERROR_HANDLER{});
184 }
185
186 /** Set the amount of user pointers that can be stored
187 * @param capacity The capacity
188 */
189 void set_user_pointer_capacity(size_t capacity) {
190 return tof_camera_set_user_pointer_capacity(this->ptr_, capacity, TOF_ERROR_HANDLER{});
191 }
192
193 /** Add a pointer that will be filled with the specified data type. This
194 * method allows you to fill data straight into your own data type without any
195 * additional copying.
196 * @param pointer The pointer to the data to write into
197 * @param capacity The amount of data the pointer can hold
198 * @param callback Callback that will be called when pointer is no longer in
199 * use
200 * @param frame_type The frame type that will be filled into the pointer
201 */
202 void add_user_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback, FrameType frame_type) {
203 return tof_camera_add_user_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, static_cast<tof_frame_type>(frame_type), TOF_ERROR_HANDLER{});
204 }
205
206 /** Add a pointer that will be filled with the specified data type. This
207 * method allows you to fill data straight into your own data type without any
208 * additional copying.
209 * @param pointer The pointer to the data to write into
210 * @param capacity The amount of data the pointer can hold
211 * @param callback Callback that will be called when pointer is no longer in
212 * use
213 * @param callback_user_data User data that will be passed back when the function pointer is called
214 * @param frame_type The frame type that will be filled into the pointer
215 */
216 void add_user_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data, FrameType frame_type) {
217 return tof_camera_add_user_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, static_cast<tof_frame_type>(frame_type), TOF_ERROR_HANDLER{});
218 }
219
220 /** Clear all user pointers in memory
221 */
223 return tof_camera_clear_user_pointers(this->ptr_, TOF_ERROR_HANDLER{});
224 }
225
226 /** Get the currently set configuration index
227 * @return config index
228 */
229 uint32_t config_index() const {
230 return tof_camera_config_index(this->ptr_, TOF_ERROR_HANDLER{});
231 }
232
233 /** Switch to a different config in real time, depending on configuration and
234 * camera, this can take 100-300ms
235 * @param config_index Config index to switch to
236 */
238 return tof_camera_switch_config(this->ptr_, config_index, TOF_ERROR_HANDLER{});
239 }
240
241 /** Get the frame types that this camera can output
242 * @return Possible frame types
243 */
244 std::vector<FrameType> possible_frame_types() const {
245 size_t size = tof_camera_possible_frame_types(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
246 std::vector<FrameType> vec(size);
247 size = tof_camera_possible_frame_types(this->ptr_, reinterpret_cast<tof_frame_type*>(vec.data()), vec.size(), TOF_ERROR_HANDLER{});
248 return vec;
249 }
250
251 /** Get the frame types the camera should output
252 * @return Output frame types
253 */
254 std::vector<FrameType> get_output_frame_types() const {
255 size_t size = tof_camera_get_output_frame_types(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
256 std::vector<FrameType> vec(size);
257 size = tof_camera_get_output_frame_types(this->ptr_, reinterpret_cast<tof_frame_type*>(vec.data()), vec.size(), TOF_ERROR_HANDLER{});
258 return vec;
259 }
260
261 /** Set the frame types the camera should output
262 * @param output_frame_types Output frame types
263 */
264 void set_output_frame_types(const std::vector<FrameType> &output_frame_types) {
265 return tof_camera_set_output_frame_types(this->ptr_, reinterpret_cast<const tof_frame_type*>(output_frame_types.data()), output_frame_types.size(), TOF_ERROR_HANDLER{});
266 }
267
268 /** Check if multiple configurations are set. Switch config can only be used
269 * when this is the case.
270 * @return Is set
271 */
273 return tof_camera_has_multiple_configurations(this->ptr_, TOF_ERROR_HANDLER{});
274 }
275
276 /** Get all the set camera configurations
277 * @return Multiple camera configurations
278 */
279 std::vector<CameraConfig> get_multiple_camera_configurations() const {
280 size_t size = tof_camera_get_multiple_camera_configurations(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
281 std::vector<CameraConfig> vec;
282 vec.reserve(size);
283 for (size_t i = 0; i < size; i++)
284 vec.emplace_back(static_cast<tof_camera_config_t>(nullptr));
285 auto data = reinterpret_cast<tof_camera_config_t*>(vec.data());
286 size = tof_camera_get_multiple_camera_configurations(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
287 return vec;
288 }
289
290 /** Get all the set processing configurations
291 * @return Multiple processing configurations
292 */
293 std::vector<ProcessingConfig> get_multiple_processing_configurations() const {
294 size_t size = tof_camera_get_multiple_processing_configurations(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
295 std::vector<ProcessingConfig> vec;
296 vec.reserve(size);
297 for (size_t i = 0; i < size; i++)
298 vec.emplace_back(static_cast<tof_processing_config_t>(nullptr));
299 auto data = reinterpret_cast<tof_processing_config_t*>(vec.data());
300 size = tof_camera_get_multiple_processing_configurations(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
301 return vec;
302 }
303
304 /** Get the name for each configuration
305 * @return Names
306 */
307 std::vector<const char*> get_multiple_names() const {
308 size_t size = tof_camera_get_multiple_names(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
309 std::vector<const char*> vec(size);
310 size = tof_camera_get_multiple_names(this->ptr_, vec.data(), vec.size(), TOF_ERROR_HANDLER{});
311 return vec;
312 }
313
314 /** Get the description for each configuration
315 * @return Descriptions
316 */
317 std::vector<const char*> get_multiple_descriptions() const {
318 size_t size = tof_camera_get_multiple_descriptions(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
319 std::vector<const char*> vec(size);
320 size = tof_camera_get_multiple_descriptions(this->ptr_, vec.data(), vec.size(), TOF_ERROR_HANDLER{});
321 return vec;
322 }
323
324};
325
326/** Select the streams you want to get from the camera
327 * @param camera A camera
328 * @param frame_types The frame types to select
329 * @return The amount of selected streams
330 */
331inline size_t select_streams(const Camera &camera, const std::vector<FrameType> &frame_types) {
332 return tof_select_streams(*reinterpret_cast<const tof_camera_t*>(&camera), reinterpret_cast<const tof_frame_type*>(frame_types.data()), frame_types.size(), TOF_ERROR_HANDLER{});
333}
334
335/** Select the streams you want to get from the camera with the specified
336 * modulation frequency
337 * @param camera A camera
338 * @param frame_types The frame types to select
339 * @param mod_freq The modulation frequency to select
340 * @return The amount of selected streams
341 */
342inline size_t select_streams_mod_freq(const Camera &camera, const std::vector<FrameType> &frame_types, float mod_freq) {
343 return tof_select_streams_mod_freq(*reinterpret_cast<const tof_camera_t*>(&camera), reinterpret_cast<const tof_frame_type*>(frame_types.data()), frame_types.size(), mod_freq, TOF_ERROR_HANDLER{});
344}
345
346} // tof
347} // chronoptics
348
349#endif
This class contains all the calibration information.
Definition: calibration.hpp:38
This class allows you to view/edit the camera settings.
The main interface to the depth cameras.
Definition: camera.hpp:17
const char * get_serial() const
Get the serial number of the current camera.
Definition: camera.hpp:165
bool is_streaming() const
Check whether the camera is streaming.
Definition: camera.hpp:39
bool is_connected() const
Check whether the camera is still connected.
Definition: camera.hpp:46
void clear_buffer()
Clear the circular buffer used to store frames.
Definition: camera.hpp:132
void stop()
Stop streaming of the camera.
Definition: camera.hpp:32
void set_process_config(ProcessingConfig &config)
Set the processing config of the camera.
Definition: camera.hpp:105
void set_user_pointer_capacity(size_t capacity)
Set the amount of user pointers that can be stored.
Definition: camera.hpp:189
std::vector< Stream > get_stream_list() const
Get the different output streams the camera can provide.
Definition: camera.hpp:53
std::vector< FrameType > possible_frame_types() const
Get the frame types that this camera can output.
Definition: camera.hpp:244
std::vector< CameraConfig > get_multiple_camera_configurations() const
Get all the set camera configurations.
Definition: camera.hpp:279
void set_stream_list(const std::vector< Stream > &streams)
Set the streams that you want to get from the camera.
Definition: camera.hpp:67
CameraConfig get_camera_config() const
Get the currently active camera config.
Definition: camera.hpp:155
void clear_user_pointers()
Clear all user pointers in memory.
Definition: camera.hpp:222
std::vector< const char * > get_multiple_descriptions() const
Get the description for each configuration.
Definition: camera.hpp:317
std::vector< FrameType > get_output_frame_types() const
Get the frame types the camera should output.
Definition: camera.hpp:254
Camera(tof_camera_t ptr=nullptr)
Construct from pointer.
Definition: camera.hpp:20
bool is_stream_list_set() const
Check whether the stream list is set.
Definition: camera.hpp:74
void add_user_pointer(uint8_t *pointer, size_t capacity, tof_user_pointer_destructed_t callback, void *callback_user_data, FrameType frame_type)
Add a pointer that will be filled with the specified data type.
Definition: camera.hpp:216
size_t get_user_pointer_capacity() const
Get the amount of user pointers that can be stored.
Definition: camera.hpp:182
void set_output_frame_types(const std::vector< FrameType > &output_frame_types)
Set the frame types the camera should output.
Definition: camera.hpp:264
ProcessingConfig get_process_config() const
Get the processing config of the camera.
Definition: camera.hpp:95
bool has_frames() const
Check if the camera has frames available.
Definition: camera.hpp:112
uint32_t config_index() const
Get the currently set configuration index.
Definition: camera.hpp:229
size_t get_buffer_size() const
Get the circular buffer size.
Definition: camera.hpp:140
std::vector< Stream > get_set_stream_list()
Get the stream list that is set on the camera.
Definition: camera.hpp:81
std::vector< const char * > get_multiple_names() const
Get the name for each configuration.
Definition: camera.hpp:307
void set_buffer_size(size_t size)
Set the circular buffer size.
Definition: camera.hpp:148
void add_user_pointer(uint8_t *pointer, size_t capacity, user_pointer_destructed_fn &callback, FrameType frame_type)
Add a pointer that will be filled with the specified data type.
Definition: camera.hpp:202
std::vector< ProcessingConfig > get_multiple_processing_configurations() const
Get all the set processing configurations.
Definition: camera.hpp:293
Calibration get_calibration() const
Get calibration from the camera.
Definition: camera.hpp:172
void switch_config(uint32_t config_index)
Switch to a different config in real time, depending on configuration and camera, this can take 100-3...
Definition: camera.hpp:237
std::vector< Data > get_frames()
Get data frames from camera.
Definition: camera.hpp:119
void start()
Start streaming of the camera.
Definition: camera.hpp:26
bool has_multiple_configurations() const
Check if multiple configurations are set.
Definition: camera.hpp:272
Processing that can be done.