Time-of-Flight Library(ToF) 3.10.9
 
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};
227
228/** Select the streams you want to get from the camera
229 * @param camera A camera
230 * @param frame_types The frame types to select
231 * @return The amount of selected streams
232 */
233inline size_t select_streams(const Camera &camera, const std::vector<FrameType> &frame_types) {
234 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{});
235}
236
237/** Select the streams you want to get from the camera with the specified
238 * modulation frequency
239 * @param camera A camera
240 * @param frame_types The frame types to select
241 * @param mod_freq The modulation frequency to select
242 * @return The amount of selected streams
243 */
244inline size_t select_streams_mod_freq(const Camera &camera, const std::vector<FrameType> &frame_types, float mod_freq) {
245 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{});
246}
247
248} // tof
249} // chronoptics
250
251#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
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
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
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
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
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
Calibration get_calibration() const
Get calibration from the camera.
Definition: camera.hpp:172
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
Processing that can be done.