Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
rs.hpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #ifndef LIBREALSENSE_RS_HPP
5 #define LIBREALSENSE_RS_HPP
6 
7 #include "rsutil.h"
8 #include "rscore.hpp"
9 #include <cmath>
10 #include <cstdint>
11 #include <cstring>
12 #include <sstream>
13 #include <stdexcept>
14 #include <functional>
15 #include <vector>
16 
17 namespace rs
18 {
19  /* streams are different types of data provided by RealSense devices */
20  enum class stream : int32_t
21  {
22  depth ,
23  color ,
24  infrared ,
25  infrared2 ,
26  fisheye ,
27  points ,
34  };
35 
36  /* formats define how each stream can be encoded
37  format is closely relateed to Linux pixel-formats, but is trying to abstract away the platform specific constructs */
38  enum class format : int32_t
39  {
40  any ,
41  z16 ,
42  disparity16 ,
43  xyz32f ,
44  yuyv ,
45  rgb8 ,
46  bgr8 ,
47  rgba8 ,
48  bgra8 ,
49  y8 ,
50  y16 ,
51  raw10 ,
52  raw16 ,
53  raw8
54  };
55 
56  /* Output buffer format sets how librealsense will work with frame memory */
57  enum class output_buffer_format : int32_t
58  {
59  continous ,
60  native
61  };
62 
63  /* Presets hint general preference that is translated by librealsense into concrete resultion and fps */
64  enum class preset : int32_t
65  {
66  best_quality ,
69  };
70 
71  /* Distortion model define how pixel coordinates should be mapped to sensor coordinates */
72  enum class distortion : int32_t
73  {
74  none ,
78  };
79 
80  /* Camera options define general configuration controls.
81  These can generally be mapped to camera UVC controls, and unless stated otherwise can be set/queried at any time */
82  enum class option : int32_t
83  {
88  color_gain ,
89  color_gamma ,
90  color_hue ,
97  f200_accuracy ,
113  r200_lr_gain ,
141  fisheye_gain ,
142  fisheye_strobe ,
152  };
153 
154  /* frame metadata enum discriminates between the different types of values provided from the device with each frame */
155  enum class frame_metadata
156  {
158  actual_fps
159  };
160 
161  /* rs_capabilities defines the full set of functionality that a RealSense device might provide
162  to check what functionality is supported by a particular device at runtime call dev->supports(capability) */
163  enum class capabilities : int32_t
164  {
165  depth,
166  color,
167  infrared,
168  infrared2,
169  fish_eye,
170  motion_events,
172  adapter_board,
173  enumeration,
174  };
175 
176  /* This type defines proprietary formats for direct communication with device firmware */
177  enum class blob_type
178  {
180  };
181 
182  /* Camera Info feilds are read-only strings that can be queried from the device
183  Not all info feilds are available on all camera types
184  This information is mainly available for camera debug and troubleshooting and should not be used in applications */
185  enum class camera_info {
186  device_name ,
187  serial_number ,
191  camera_type ,
192  oem_id ,
193  isp_fw_version ,
194  content_version ,
195  module_version ,
197  build_date ,
199  program_date ,
201  emitter_type ,
202  focus_value ,
203  lens_type ,
204  third_lens_type ,
209  };
210 
211  /* Source allows the user to choose between available hardware subdevices */
212  enum class source : uint8_t
213  {
214  video ,
215  motion_data,
216  all_sources,
217  };
218 
219  /* Source device that tiggered specific timestamp event from the motion module */
220  enum class event : uint8_t
221  {
222  event_imu_accel ,
223  event_imu_gyro ,
229  };
230 
231  /* When working with motion microcontroller, motion data timestamps are always in microcontroller timestamp domain.
232  Some frames, however, might not succesfully receive microcontroller timestamp and will be marked as camera domain */
233  enum class timestamp_domain
234  {
235  camera,
237  };
238 
239  struct float2 { float x,y; };
240  struct float3 { float x,y,z; };
241 
242  /* Video stream intrinsics */
244  {
245  float hfov() const { return (atan2f(ppx + 0.5f, fx) + atan2f(width - (ppx + 0.5f), fx)) * 57.2957795f; }
246  float vfov() const { return (atan2f(ppy + 0.5f, fy) + atan2f(height - (ppy + 0.5f), fy)) * 57.2957795f; }
248 
249  // Helpers for mapping between pixel coordinates and texture coordinates
250  float2 pixel_to_texcoord(const float2 & pixel) const { return {(pixel.x+0.5f)/width, (pixel.y+0.5f)/height}; }
251  float2 texcoord_to_pixel(const float2 & coord) const { return {coord.x*width - 0.5f, coord.y*height - 0.5f}; }
252 
253  // Helpers for mapping from image coordinates into 3D space
254  float3 deproject(const float2 & pixel, float depth) const { float3 point = {}; rs_deproject_pixel_to_point(&point.x, this, &pixel.x, depth); return point; }
255  float3 deproject_from_texcoord(const float2 & coord, float depth) const { return deproject(texcoord_to_pixel(coord), depth); }
256 
257  // Helpers for mapping from 3D space into image coordinates
258  float2 project(const float3 & point) const { float2 pixel = {}; rs_project_point_to_pixel(&pixel.x, this, &point.x); return pixel; }
259  float2 project_to_texcoord(const float3 & point) const { return pixel_to_texcoord(project(point)); }
260 
261  bool operator == (const intrinsics & r) const { return memcmp(this, &r, sizeof(r)) == 0; }
262 
263  };
264 
265  /* represents motion device intrinsic - scale, bias and variances */
267  {
269  };
270 
271  /* Cross-stream extrinsics, encode the topology of how the different devices are connected */
273  {
274  bool is_identity() const { return (rotation[0] == 1) && (rotation[4] == 1) && (translation[0] == 0) && (translation[1] == 0) && (translation[2] == 0); }
275  float3 transform(const float3 & point) const { float3 p = {}; rs_transform_point_to_point(&p.x, this, &point.x); return p; }
276  };
277 
278  /* Timestamp data from the motion microcontroller */
280  {
283  };
284 
285  /* Motion data from Gyro / Accel from the microcontroller */
287  {
290  };
291 
292  class context;
293  class device;
294 
295  class error : public std::runtime_error
296  {
297  std::string function, args;
298  public:
299  error(rs_error * err) : std::runtime_error(rs_get_error_message(err))
300  {
301  function = (nullptr != rs_get_failed_function(err)) ? rs_get_failed_function(err) : std::string();
302  args = (nullptr != rs_get_failed_args(err)) ? rs_get_failed_args(err) : std::string();
303  rs_free_error(err);
304  }
305  const std::string & get_failed_function() const { return function; }
306  const std::string & get_failed_args() const { return args; }
307  static void handle(rs_error * e) { if(e) throw error(e); }
308  };
309 
310  class context
311  {
312  rs_context * handle;
313  context(const context &) = delete;
314  context & operator = (const context &) = delete;
315  public:
316 
317  // create realsense context required for rest of the API
319  {
320  rs_error * e = nullptr;
321  handle = rs_create_context(RS_API_VERSION, &e);
322  error::handle(e);
323  }
324 
325  explicit context(rs_context * handle) : handle(handle) {}
326 
328  {
329  rs_delete_context(handle, nullptr);
330  }
331 
334  int get_device_count() const
335  {
336  rs_error * e = nullptr;
337  auto r = rs_get_device_count(handle, &e);
338  error::handle(e);
339  return r;
340  }
341 
345  device * get_device(int index)
346  {
347  rs_error * e = nullptr;
348  auto r = rs_get_device(handle, index, &e);
349  error::handle(e);
350  return (device *)r;
351  }
352  };
353 
355  {
356  std::function<void(motion_data)> on_event_function;
357  public:
358  explicit motion_callback(std::function<void(motion_data)> on_event) : on_event_function(on_event) {}
359 
360  void on_event(rs_motion_data e) override
361  {
362  on_event_function(motion_data(e));
363  }
364 
365  void release() override { delete this; }
366  };
367 
369  {
370  std::function<void(timestamp_data)> on_event_function;
371  public:
372  explicit timestamp_callback(std::function<void(timestamp_data)> on_event) : on_event_function(on_event) {}
373 
374  void on_event(rs_timestamp_data data) override
375  {
376  on_event_function(std::move(data));
377  }
378 
379  void release() override { delete this; }
380  };
381 
382  class frame
383  {
384  rs_device * device;
385  rs_frame_ref * frame_ref;
386 
387  frame(const frame &) = delete;
388 
389  public:
390  frame() : device(nullptr), frame_ref(nullptr) {}
391  frame(rs_device * device, rs_frame_ref * frame_ref) : device(device), frame_ref(frame_ref) {}
392  frame(frame&& other) : device(other.device), frame_ref(other.frame_ref) { other.frame_ref = nullptr; }
394  {
395  swap(other);
396  return *this;
397  }
398  void swap(frame& other)
399  {
400  std::swap(device, other.device);
401  std::swap(frame_ref, other.frame_ref);
402  }
403 
405  {
406  if (device && frame_ref)
407  {
408  rs_error * e = nullptr;
409  rs_release_frame(device, frame_ref, &e);
410  error::handle(e);
411  }
412  }
413 
416  double get_timestamp() const
417  {
418  rs_error * e = nullptr;
419  auto r = rs_get_detached_frame_timestamp(frame_ref, &e);
420  error::handle(e);
421  return r;
422  }
423 
427  {
428  rs_error * e = nullptr;
429  auto r = rs_get_detached_frame_timestamp_domain(frame_ref, &e);
430  error::handle(e);
431  return static_cast<timestamp_domain>(r);
432  }
433 
438  {
439  rs_error * e = nullptr;
440  auto r = rs_get_detached_frame_metadata(frame_ref, (rs_frame_metadata)frame_metadata, &e);
441  error::handle(e);
442  return r;
443  }
444 
449  {
450  rs_error * e = nullptr;
451  auto r = rs_supports_frame_metadata(frame_ref, frame_metadata, &e);
452  error::handle(e);
453  return r != 0;
454  }
455 
456  // retrieve the frame number
457  // \return the frame number
458  unsigned long long get_frame_number() const
459  {
460  rs_error * e = nullptr;
461  auto r = rs_get_detached_frame_number(frame_ref, &e);
462  error::handle(e);
463  return r;
464  }
465 
466  // retrieve the frame content
467  // \return frame content
468  const void * get_data() const
469  {
470  rs_error * e = nullptr;
471  auto r = rs_get_detached_frame_data(frame_ref, &e);
472  error::handle(e);
473  return r;
474  }
475 
476  // returns image width in pixels
477  int get_width() const
478  {
479  rs_error * e = nullptr;
480  auto r = rs_get_detached_frame_width(frame_ref, &e);
481  error::handle(e);
482  return r;
483  }
484 
485  // returns image height in pixels
486  int get_height() const
487  {
488  rs_error * e = nullptr;
489  auto r = rs_get_detached_frame_height(frame_ref, &e);
490  error::handle(e);
491  return r;
492  }
493 
494  // returns the configured framerate
495  int get_framerate() const
496  {
497  rs_error * e = nullptr;
498  auto r = rs_get_detached_framerate(frame_ref, &e);
499  error::handle(e);
500  return r;
501  }
502 
503  // retrive frame stride, meaning the actual line width in memory in bytes (not the logical image width)
504  int get_stride() const
505  {
506  rs_error * e = nullptr;
507  auto r = rs_get_detached_frame_stride(frame_ref, &e);
508  error::handle(e);
509  return r;
510  }
511 
514  int get_bpp() const
515  {
516  rs_error * e = nullptr;
517  auto r = rs_get_detached_frame_bpp(frame_ref, &e);
518  error::handle(e);
519  return r;
520  }
521 
522  // retrieve the frame format
523  // \return frame format
525  {
526  rs_error * e = nullptr;
527  auto r = rs_get_detached_frame_format(frame_ref, &e);
528  error::handle(e);
529  return static_cast<format>(r);
530  }
531 
532  // retrieve the frame stream type
533  // \return frame stream type
535  {
536  rs_error * e = nullptr;
537  auto s = rs_get_detached_frame_stream_type(frame_ref, &e);
538  error::handle(e);
539  return static_cast<stream>(s);
540  }
541  };
542 
544  {
545  std::function<void(frame)> on_frame_function;
546  public:
547  explicit frame_callback(std::function<void(frame)> on_frame) : on_frame_function(on_frame) {}
548 
549  void on_frame(rs_device * device, rs_frame_ref * fref) override
550  {
551  on_frame_function(std::move(frame(device, fref)));
552  }
553 
554  void release() override { delete this; }
555  };
556 
557  class device
558  {
559  device() = delete;
560  device(const device &) = delete;
561  device & operator = (const device &) = delete;
562  ~device() = delete;
563 
564 
565  public:
568  const char * get_name() const
569  {
570  rs_error * e = nullptr;
571  auto r = rs_get_device_name((const rs_device *)this, &e);
572  error::handle(e);
573  return r;
574  }
575 
578  const char * get_serial() const
579  {
580  rs_error * e = nullptr;
581  auto r = rs_get_device_serial((const rs_device *)this, &e);
582  error::handle(e);
583  return r;
584  }
585 
588  const char * get_usb_port_id() const
589  {
590  rs_error * e = nullptr;
591  auto r = rs_get_device_usb_port_id((const rs_device *)this, &e);
592  error::handle(e);
593  return r;
594  }
595 
598  const char * get_firmware_version() const
599  {
600  rs_error * e = nullptr;
601  auto r = rs_get_device_firmware_version((const rs_device *)this, &e);
602  error::handle(e);
603  return r;
604  }
605 
608  const char * get_info(camera_info info) const
609  {
610  rs_error * e = nullptr;
611  auto r = rs_get_device_info((const rs_device *)this, (rs_camera_info)info, &e);
612  error::handle(e);
613  return r;
614  }
615 
620  extrinsics get_extrinsics(stream from_stream, stream to_stream) const
621  {
622  rs_error * e = nullptr;
623  extrinsics extrin;
624  rs_get_device_extrinsics((const rs_device *)this, (rs_stream)from_stream, (rs_stream)to_stream, &extrin, &e);
625  error::handle(e);
626  return extrin;
627  }
628 
633  {
634  rs_error * e = nullptr;
635  extrinsics extrin;
636  rs_get_motion_extrinsics_from((const rs_device *)this, (rs_stream)from_stream, &extrin, &e);
637  error::handle(e);
638  return extrin;
639  }
640 
643  float get_depth_scale() const
644  {
645  rs_error * e = nullptr;
646  auto r = rs_get_device_depth_scale((const rs_device *)this, &e);
647  error::handle(e);
648  return r;
649  }
650 
655  {
656  rs_error * e = nullptr;
657  auto r = rs_device_supports_option((const rs_device *)this, (rs_option)option, &e);
658  error::handle(e);
659  return r != 0;
660  }
661 
666  {
667  rs_error * e = nullptr;
668  auto r = rs_get_stream_mode_count((const rs_device *)this, (rs_stream)stream, &e);
669  error::handle(e);
670  return r;
671  }
672 
680  void get_stream_mode(stream stream, int index, int & width, int & height, format & format, int & framerate) const
681  {
682  rs_error * e = nullptr;
683  rs_get_stream_mode((const rs_device *)this, (rs_stream)stream, index, &width, &height, (rs_format *)&format, &framerate, &e);
684  error::handle(e);
685  }
686 
694  void enable_stream(stream stream, int width, int height, format format, int framerate, output_buffer_format output_buffer_type = output_buffer_format::continous)
695  {
696  rs_error * e = nullptr;
697  rs_enable_stream_ex((rs_device *)this, (rs_stream)stream, width, height, (rs_format)format, framerate, (rs_output_buffer_format)output_buffer_type, &e);
698  error::handle(e);
699  }
700 
705  {
706  rs_error * e = nullptr;
707  rs_enable_stream_preset((rs_device *)this, (rs_stream)stream, (rs_preset)preset, &e);
708  error::handle(e);
709  }
710 
714  {
715  rs_error * e = nullptr;
716  rs_disable_stream((rs_device *)this, (rs_stream)stream, &e);
717  error::handle(e);
718  }
719 
724  {
725  rs_error * e = nullptr;
726  auto r = rs_is_stream_enabled((const rs_device *)this, (rs_stream)stream, &e);
727  error::handle(e);
728  return r != 0;
729  }
730 
735  {
736  rs_error * e = nullptr;
737  auto r = rs_get_stream_width((const rs_device *)this, (rs_stream)stream, &e);
738  error::handle(e);
739  return r;
740  }
741 
746  {
747  rs_error * e = nullptr;
748  auto r = rs_get_stream_height((const rs_device *)this, (rs_stream)stream, &e);
749  error::handle(e);
750  return r;
751  }
752 
757  {
758  rs_error * e = nullptr;
759  auto r = rs_get_stream_format((const rs_device *)this, (rs_stream)stream, &e);
760  error::handle(e);
761  return (format)r;
762  }
763 
768  {
769  rs_error * e = nullptr;
770  auto r = rs_get_stream_framerate((const rs_device *)this, (rs_stream)stream, &e);
771  error::handle(e);
772  return r;
773  }
774 
779  {
780  rs_error * e = nullptr;
781  intrinsics intrin;
782  rs_get_stream_intrinsics((const rs_device *)this, (rs_stream)stream, &intrin, &e);
783  error::handle(e);
784  return intrin;
785  }
786 
790  {
791  rs_error * e = nullptr;
793  rs_get_motion_intrinsics((const rs_device *)this, &intrinsics, &e);
794  error::handle(e);
795  return intrinsics;
796  }
797 
805  void set_frame_callback(rs::stream stream, std::function<void(frame)> frame_handler)
806  {
807  rs_error * e = nullptr;
808  rs_set_frame_callback_cpp((rs_device *)this, (rs_stream)stream, new frame_callback(frame_handler), &e);
809  error::handle(e);
810  }
811 
820  void enable_motion_tracking(std::function<void(motion_data)> motion_handler, std::function<void(timestamp_data)> timestamp_handler)
821  {
822  rs_error * e = nullptr;
823  rs_enable_motion_tracking_cpp((rs_device *)this, new motion_callback(motion_handler), new timestamp_callback(timestamp_handler), &e);
824  error::handle(e);
825  }
826 
831  void enable_motion_tracking(std::function<void(motion_data)> motion_handler)
832  {
833  rs_error * e = nullptr;
834  rs_enable_motion_tracking_cpp((rs_device *)this, new motion_callback(motion_handler), new timestamp_callback([](rs::timestamp_data data) {}), &e);
835  error::handle(e);
836  }
837 
840  {
841  rs_error * e = nullptr;
843  error::handle(e);
844  }
845 
848  {
849  rs_error * e = nullptr;
850  auto result = rs_is_motion_tracking_active((rs_device *)this,&e);
851  error::handle(e);
852  return result;
853  }
854 
855 
858  {
859  rs_error * e = nullptr;
860  rs_start_source((rs_device *)this, (rs_source)source, &e);
861  error::handle(e);
862  }
863 
866  {
867  rs_error * e = nullptr;
868  rs_stop_source((rs_device *)this, (rs_source)source, &e);
869  error::handle(e);
870  }
871 
874  bool is_streaming() const
875  {
876  rs_error * e = nullptr;
877  auto r = rs_is_device_streaming((const rs_device *)this, &e);
878  error::handle(e);
879  return r != 0;
880  }
881 
887  void get_option_range(option option, double & min, double & max, double & step)
888  {
889  rs_error * e = nullptr;
890  rs_get_device_option_range((rs_device *)this, (rs_option)option, &min, &max, &step, &e);
891  error::handle(e);
892  }
893 
900  void get_option_range(option option, double & min, double & max, double & step, double & def)
901  {
902  rs_error * e = nullptr;
903  rs_get_device_option_range_ex((rs_device *)this, (rs_option)option, &min, &max, &step, &def, &e);
904  error::handle(e);
905  }
906 
911  void get_options(const option * options, size_t count, double * values)
912  {
913  rs_error * e = nullptr;
914  rs_get_device_options((rs_device *)this, (const rs_option *)options, (unsigned int)count, values, &e);
915  error::handle(e);
916  }
917 
922  void set_options(const option * options, size_t count, const double * values)
923  {
924  rs_error * e = nullptr;
925  rs_set_device_options((rs_device *)this, (const rs_option *)options, (unsigned int)count, values, &e);
926  error::handle(e);
927  }
928 
933  {
934  rs_error * e = nullptr;
935  auto r = rs_get_device_option((rs_device *)this, (rs_option)option, &e);
936  error::handle(e);
937  return r;
938  }
939 
944  {
945  rs_error * e = nullptr;
946  auto r = rs_get_device_option_description((rs_device *)this, (rs_option)option, &e);
947  error::handle(e);
948  return r;
949  }
950 
954  void set_option(option option, double value)
955  {
956  rs_error * e = nullptr;
957  rs_set_device_option((rs_device *)this, (rs_option)option, value, &e);
958  error::handle(e);
959  }
960 
964  {
965  rs_error * e = nullptr;
966  rs_wait_for_frames((rs_device *)this, &e);
967  error::handle(e);
968  }
969 
973  {
974  rs_error * e = nullptr;
975  auto r = rs_poll_for_frames((rs_device *)this, &e);
976  error::handle(e);
977  return r != 0;
978  }
979 
983  bool supports(capabilities capability) const
984  {
985  rs_error * e = nullptr;
986  auto r = rs_supports((rs_device *)this, (rs_capabilities)capability, &e);
987  error::handle(e);
988  return r? true: false;
989  }
990 
991 
995  bool supports(camera_info info_param) const
996  {
997  rs_error * e = nullptr;
998  auto r = rs_supports_camera_info((rs_device *)this, (rs_camera_info)info_param, &e);
999  error::handle(e);
1000  return r ? true : false;
1001  }
1002 
1006  double get_frame_timestamp(stream stream) const
1007  {
1008  rs_error * e = nullptr;
1009  auto r = rs_get_frame_timestamp((const rs_device *)this, (rs_stream)stream, &e);
1010  error::handle(e);
1011  return r;
1012  }
1013 
1017  unsigned long long get_frame_number(stream stream) const
1018  {
1019  rs_error * e = nullptr;
1020  auto r = rs_get_frame_number((const rs_device *)this, (rs_stream)stream, &e);
1021  error::handle(e);
1022  return r;
1023  }
1024 
1028  const void * get_frame_data(stream stream) const
1029  {
1030  rs_error * e = nullptr;
1031  auto r = rs_get_frame_data((const rs_device *)this, (rs_stream)stream, &e);
1032  error::handle(e);
1033  return r;
1034  }
1035 
1040  void send_blob_to_device(rs::blob_type type, void * data, int size)
1041  {
1042  rs_error * e = nullptr;
1043  rs_send_blob_to_device((rs_device *)this, (rs_blob_type)type, data, size, &e);
1044  error::handle(e);
1045  }
1046  };
1047 
1048  inline std::ostream & operator << (std::ostream & o, stream stream) { return o << rs_stream_to_string((rs_stream)stream); }
1049  inline std::ostream & operator << (std::ostream & o, format format) { return o << rs_format_to_string((rs_format)format); }
1050  inline std::ostream & operator << (std::ostream & o, preset preset) { return o << rs_preset_to_string((rs_preset)preset); }
1051  inline std::ostream & operator << (std::ostream & o, distortion distortion) { return o << rs_distortion_to_string((rs_distortion)distortion); }
1052  inline std::ostream & operator << (std::ostream & o, option option) { return o << rs_option_to_string((rs_option)option); }
1053  inline std::ostream & operator << (std::ostream & o, capabilities capability) { return o << rs_capabilities_to_string((rs_capabilities)capability); }
1054  inline std::ostream & operator << (std::ostream & o, source src) { return o << rs_source_to_string((rs_source)src); }
1055  inline std::ostream & operator << (std::ostream & o, event evt) { return o << rs_event_to_string((rs_event_source)evt); }
1056 
1057  /* Severity of the librealsense logger */
1058  enum class log_severity : int32_t
1059  {
1060  debug = 0,
1061  info = 1,
1062  warn = 2,
1063  error = 3,
1064  fatal = 4,
1065  none = 5,
1066  };
1067 
1069  {
1070  std::function<void(log_severity, const char *)> on_event_function;
1071  public:
1072  explicit log_callback(std::function<void(log_severity, const char *)> on_event) : on_event_function(on_event) {}
1073 
1074  void on_event(rs_log_severity severity, const char * message) override
1075  {
1076  on_event_function((log_severity)severity, message);
1077  }
1078 
1079  void release() override { delete this; }
1080  };
1081 
1082  inline void log_to_console(log_severity min_severity)
1083  {
1084  rs_error * e = nullptr;
1085  rs_log_to_console((rs_log_severity)min_severity, &e);
1086  error::handle(e);
1087  }
1088 
1089  inline void log_to_file(log_severity min_severity, const char * file_path)
1090  {
1091  rs_error * e = nullptr;
1092  rs_log_to_file((rs_log_severity)min_severity, file_path, &e);
1093  error::handle(e);
1094  }
1095 
1096  inline void log_to_callback(log_severity min_severity, std::function<void(log_severity, const char *)> callback)
1097  {
1098  rs_error * e = nullptr;
1099  rs_log_to_callback_cpp((rs_log_severity)min_severity, new log_callback(callback), &e);
1100  error::handle(e);
1101  }
1102 
1103  // Additional utilities
1104  inline void apply_depth_control_preset(device * device, int preset) { rs_apply_depth_control_preset((rs_device *)device, preset); }
1105  inline void apply_ivcam_preset(device * device, rs_ivcam_preset preset) { rs_apply_ivcam_preset((rs_device *)device, preset); }
1106  inline void apply_ivcam_preset(device * device, int preset) { rs_apply_ivcam_preset((rs_device *)device, (rs_ivcam_preset)preset); } // duplicate for better backward compatibility with existing applications
1107 }
1108 #endif
float2 project_to_texcoord(const float3 &point) const
Definition: rs.hpp:259
int rs_get_stream_width(const rs_device *device, rs_stream stream, rs_error **error)
void log_to_console(log_severity min_severity)
Definition: rs.hpp:1082
Definition: rs.hpp:557
intrinsics get_stream_intrinsics(stream stream) const
Definition: rs.hpp:778
#define RS_API_VERSION
Definition: rs.h:22
motion_data(rs_motion_data orig)
Definition: rs.hpp:288
int get_width() const
Definition: rs.hpp:477
int rs_supports(rs_device *device, rs_capabilities capability, rs_error **error)
void rs_get_motion_extrinsics_from(const rs_device *device, rs_stream from, rs_extrinsics *extrin, rs_error **error)
void rs_get_stream_intrinsics(const rs_device *device, rs_stream stream, rs_intrinsics *intrin, rs_error **error)
void enable_stream(stream stream, int width, int height, format format, int framerate, output_buffer_format output_buffer_type=output_buffer_format::continous)
Definition: rs.hpp:694
int get_stride() const
Definition: rs.hpp:504
const char * rs_stream_to_string(rs_stream stream)
void rs_start_source(rs_device *device, rs_source source, rs_error **error)
void rs_disable_motion_tracking(rs_device *device, rs_error **error)
void rs_log_to_callback_cpp(rs_log_severity min_severity, rs_log_callback *callback, rs_error **error)
Definition: rscore.hpp:132
const char * rs_source_to_string(rs_source source)
float vfov() const
Definition: rs.hpp:246
const std::string & get_failed_args() const
Definition: rs.hpp:306
int rs_supports_frame_metadata(const rs_frame_ref *frame, rs_frame_metadata frame_metadata, rs_error **error)
float3 deproject_from_texcoord(const float2 &coord, float depth) const
Definition: rs.hpp:255
motion_intrinsics()
Definition: rs.hpp:268
float y
Definition: rs.hpp:239
extrinsics get_extrinsics(stream from_stream, stream to_stream) const
Definition: rs.hpp:620
int rs_get_device_count(const rs_context *context, rs_error **error)
std::ostream & operator<<(std::ostream &o, stream stream)
Definition: rs.hpp:1048
frame_metadata
Definition: rs.hpp:155
Definition: rs.hpp:272
const char * get_firmware_version() const
Definition: rs.hpp:598
rs_blob_type
Definition: rs.h:219
void rs_log_to_console(rs_log_severity min_severity, rs_error **error)
log_severity
Definition: rs.hpp:1058
rs_format rs_get_detached_frame_format(const rs_frame_ref *frame, rs_error **error)
void rs_enable_stream_ex(rs_device *device, rs_stream stream, int width, int height, rs_format format, int framerate, rs_output_buffer_format output_format, rs_error **error)
void rs_get_device_options(rs_device *device, const rs_option *options, unsigned int count, double *values, rs_error **error)
Definition: rs.hpp:354
void rs_set_device_options(rs_device *device, const rs_option *options, unsigned int count, const double *values, rs_error **error)
const char * get_info(camera_info info) const
Definition: rs.hpp:608
void on_event(rs_timestamp_data data) override
Definition: rs.hpp:374
unsigned long long rs_get_detached_frame_number(const rs_frame_ref *frame, rs_error **error)
double get_frame_metadata(rs_frame_metadata frame_metadata) const
Definition: rs.hpp:437
void get_option_range(option option, double &min, double &max, double &step)
Definition: rs.hpp:887
double rs_get_frame_timestamp(const rs_device *device, rs_stream stream, rs_error **error)
void on_event(rs_motion_data e) override
Definition: rs.hpp:360
const void * rs_get_frame_data(const rs_device *device, rs_stream stream, rs_error **error)
int rs_is_device_streaming(const rs_device *device, rs_error **error)
Definition: rs.hpp:243
bool supports(camera_info info_param) const
Definition: rs.hpp:995
const char * get_usb_port_id() const
Definition: rs.hpp:588
int get_stream_width(stream stream) const
Definition: rs.hpp:734
Definition: rs.hpp:286
void enable_stream(stream stream, preset preset)
Definition: rs.hpp:704
void apply_depth_control_preset(device *device, int preset)
Definition: rs.hpp:1104
rs_timestamp_domain rs_get_detached_frame_timestamp_domain(const rs_frame_ref *frameset, rs_error **error)
const char * rs_distortion_to_string(rs_distortion distortion)
void log_to_callback(log_severity min_severity, std::function< void(log_severity, const char *)> callback)
Definition: rs.hpp:1096
float2 pixel_to_texcoord(const float2 &pixel) const
Definition: rs.hpp:250
void rs_delete_context(rs_context *context, rs_error **error)
frame(frame &&other)
Definition: rs.hpp:392
camera_info
Definition: rs.hpp:185
Definition: rs.hpp:1068
void enable_motion_tracking(std::function< void(motion_data)> motion_handler)
Definition: rs.hpp:831
void rs_set_device_option(rs_device *device, rs_option option, double value, rs_error **error)
const char * rs_get_device_name(const rs_device *device, rs_error **error)
int rs_get_detached_framerate(const rs_frame_ref *frameset, rs_error **error)
rs_option
Definition: rs.h:120
Definition: rs.hpp:543
const char * rs_get_error_message(const rs_error *error)
float rs_get_device_depth_scale(const rs_device *device, rs_error **error)
rs_output_buffer_format
Definition: rs.h:66
const void * get_frame_data(stream stream) const
Definition: rs.hpp:1028
Definition: rs.hpp:240
timestamp_data(rs_timestamp_data orig)
Definition: rs.hpp:281
const char * rs_get_device_usb_port_id(const rs_device *device, rs_error **error)
void rs_log_to_file(rs_log_severity min_severity, const char *file_path, rs_error **error)
context(rs_context *handle)
Definition: rs.hpp:325
format get_stream_format(stream stream) const
Definition: rs.hpp:756
option
Definition: rs.hpp:82
void rs_get_stream_mode(const rs_device *device, rs_stream stream, int index, int *width, int *height, rs_format *format, int *framerate, rs_error **error)
timestamp_domain get_frame_timestamp_domain() const
Definition: rs.hpp:426
event
Definition: rs.hpp:220
void send_blob_to_device(rs::blob_type type, void *data, int size)
Definition: rs.hpp:1040
bool is_identity() const
Definition: rs.hpp:274
float x
Definition: rs.hpp:239
int rs_get_stream_mode_count(const rs_device *device, rs_stream stream, rs_error **error)
frame & operator=(frame other)
Definition: rs.hpp:393
int get_stream_mode_count(stream stream) const
Definition: rs.hpp:665
int rs_poll_for_frames(rs_device *device, rs_error **error)
void apply_ivcam_preset(device *device, rs_ivcam_preset preset)
Definition: rs.hpp:1105
frame_callback(std::function< void(frame)> on_frame)
Definition: rs.hpp:547
void release() override
Definition: rs.hpp:379
Definition: rs.hpp:266
void stop(rs::source source=rs::source::video)
end streaming on all streams for this device
Definition: rs.hpp:865
const char * rs_get_failed_function(const rs_error *error)
rs_format rs_get_stream_format(const rs_device *device, rs_stream stream, rs_error **error)
rs_context * rs_create_context(int api_version, rs_error **error)
int get_height() const
Definition: rs.hpp:486
const char * rs_capabilities_to_string(rs_capabilities capability)
double rs_get_device_option(rs_device *device, rs_option option, rs_error **error)
void rs_get_device_option_range_ex(rs_device *device, rs_option option, double *min, double *max, double *step, double *def, rs_error **error)
int rs_get_detached_frame_bpp(const rs_frame_ref *frame, rs_error **error)
stream
Definition: rs.hpp:20
timestamp_domain
Definition: rs.hpp:233
void rs_disable_stream(rs_device *device, rs_stream stream, rs_error **error)
int get_stream_height(stream stream) const
Definition: rs.hpp:745
void rs_release_frame(rs_device *device, rs_frame_ref *frame, rs_error **error)
void set_options(const option *options, size_t count, const double *values)
Definition: rs.hpp:922
Definition: rs.h:335
bool is_stream_enabled(stream stream) const
Definition: rs.hpp:723
void rs_get_device_extrinsics(const rs_device *device, rs_stream from_stream, rs_stream to_stream, rs_extrinsics *extrin, rs_error **error)
error(rs_error *err)
Definition: rs.hpp:299
Definition: rs.hpp:310
void disable_motion_tracking(void)
disable events polling
Definition: rs.hpp:839
rs_camera_info
Definition: rs.h:227
void swap(frame &other)
Definition: rs.hpp:398
int rs_device_supports_option(const rs_device *device, rs_option option, rs_error **error)
Definition: rs.h:313
format get_format() const
Definition: rs.hpp:524
const char * get_name() const
Definition: rs.hpp:568
format
Definition: rs.hpp:38
void rs_send_blob_to_device(rs_device *device, rs_blob_type type, void *data, int size, rs_error **error)
void get_stream_mode(stream stream, int index, int &width, int &height, format &format, int &framerate) const
Definition: rs.hpp:680
int rs_get_detached_frame_height(const rs_frame_ref *frame, rs_error **error)
void start(rs::source source=rs::source::video)
begin streaming on all enabled streams for this device
Definition: rs.hpp:857
int get_stream_framerate(stream stream) const
Definition: rs.hpp:767
const char * rs_get_device_firmware_version(const rs_device *device, rs_error **error)
void enable_motion_tracking(std::function< void(motion_data)> motion_handler, std::function< void(timestamp_data)> timestamp_handler)
Definition: rs.hpp:820
float2 texcoord_to_pixel(const float2 &coord) const
Definition: rs.hpp:251
void on_event(rs_log_severity severity, const char *message) override
Definition: rs.hpp:1074
const void * get_data() const
Definition: rs.hpp:468
double get_option(option option)
Definition: rs.hpp:932
Definition: rs.hpp:17
unsigned long long get_frame_number(stream stream) const
Definition: rs.hpp:1017
const char * rs_get_device_option_description(rs_device *device, rs_option option, rs_error **error)
source
Definition: rs.hpp:212
const char * rs_get_failed_args(const rs_error *error)
Definition: rscore.hpp:125
rs_format
Definition: rs.h:46
const char * rs_event_to_string(rs_event_source event)
void get_option_range(option option, double &min, double &max, double &step, double &def)
Definition: rs.hpp:900
Definition: rscore.hpp:118
double rs_get_detached_frame_timestamp(const rs_frame_ref *frame, rs_error **error)
int is_motion_tracking_active()
check if data acquisition is active
Definition: rs.hpp:847
Definition: rscore.hpp:146
const char * rs_get_device_info(const rs_device *device, rs_camera_info info, rs_error **error)
struct rs_error rs_error
Definition: rs.h:345
int get_framerate() const
Definition: rs.hpp:495
void rs_stop_source(rs_device *device, rs_source source, rs_error **error)
distortion model() const
Definition: rs.hpp:247
int rs_get_detached_frame_width(const rs_frame_ref *frame, rs_error **error)
void release() override
Definition: rs.hpp:365
Definition: rs.h:327
extrinsics get_motion_extrinsics_from(stream from_stream) const
Definition: rs.hpp:632
void log_to_file(log_severity min_severity, const char *file_path)
Definition: rs.hpp:1089
int rs_get_detached_frame_stride(const rs_frame_ref *frame, rs_error **error)
unsigned long long rs_get_frame_number(const rs_device *device, rs_stream stream, rs_error **error)
int rs_supports_camera_info(rs_device *device, rs_camera_info info_param, rs_error **error)
static void handle(rs_error *e)
Definition: rs.hpp:307
motion_data()
Definition: rs.hpp:289
void rs_free_error(rs_error *error)
const char * get_serial() const
Definition: rs.hpp:578
rs_source
Definition: rs.h:83
void on_frame(rs_device *device, rs_frame_ref *fref) override
Definition: rs.hpp:549
output_buffer_format
Definition: rs.hpp:57
Definition: rs.h:288
int rs_is_motion_tracking_active(rs_device *device, rs_error **error)
bool supports_option(option option) const
Definition: rs.hpp:654
double get_frame_timestamp(stream stream) const
Definition: rs.hpp:1006
blob_type
Definition: rs.hpp:177
Definition: rs.h:320
void disable_stream(stream stream)
Definition: rs.hpp:713
void rs_get_device_option_range(rs_device *device, rs_option option, double *min, double *max, double *step, rs_error **error)
stream get_stream_type() const
Definition: rs.hpp:534
frame(rs_device *device, rs_frame_ref *frame_ref)
Definition: rs.hpp:391
frame()
Definition: rs.hpp:390
const char * rs_preset_to_string(rs_preset preset)
rs_preset
Definition: rs.h:74
Definition: rs.hpp:382
int rs_get_stream_framerate(const rs_device *device, rs_stream stream, rs_error **error)
bool poll_for_frames()
Definition: rs.hpp:972
const char * rs_format_to_string(rs_format format)
distortion
Definition: rs.hpp:72
rs_stream
Definition: rs.h:27
const char * rs_option_to_string(rs_option option)
double get_timestamp() const
Definition: rs.hpp:416
float z
Definition: rs.hpp:240
void release() override
Definition: rs.hpp:554
int get_bpp() const
Definition: rs.hpp:514
unsigned long long get_frame_number() const
Definition: rs.hpp:458
motion_intrinsics get_motion_intrinsics() const
Definition: rs.hpp:789
rs_log_severity
Definition: rs.h:255
Definition: rs.hpp:239
double rs_get_detached_frame_metadata(const rs_frame_ref *frame, rs_frame_metadata frame_metadata, rs_error **error)
rs_capabilities
Definition: rs.h:204
void rs_set_frame_callback_cpp(rs_device *device, rs_stream stream, rs_frame_callback *callback, rs_error **error)
void set_frame_callback(rs::stream stream, std::function< void(frame)> frame_handler)
Definition: rs.hpp:805
Definition: rscore.hpp:64
rs_device * rs_get_device(rs_context *context, int index, rs_error **error)
const char * rs_get_device_serial(const rs_device *device, rs_error **error)
void rs_wait_for_frames(rs_device *device, rs_error **error)
void rs_enable_stream_preset(rs_device *device, rs_stream stream, rs_preset preset, rs_error **error)
float get_depth_scale() const
Definition: rs.hpp:643
Definition: rs.hpp:295
const char * get_option_description(option option)
Definition: rs.hpp:943
rs_distortion model
Definition: rs.h:296
bool supports_frame_metadata(rs_frame_metadata frame_metadata) const
Definition: rs.hpp:448
Definition: rscore.hpp:139
Definition: rscore.hpp:44
~frame()
Definition: rs.hpp:404
bool supports(capabilities capability) const
Definition: rs.hpp:983
rs_distortion
Definition: rs.h:92
float x
Definition: rs.hpp:240
rs_frame_metadata
Definition: rs.h:195
float3 deproject(const float2 &pixel, float depth) const
Definition: rs.hpp:254
context()
Definition: rs.hpp:318
bool is_streaming() const
Definition: rs.hpp:874
timestamp_callback(std::function< void(timestamp_data)> on_event)
Definition: rs.hpp:372
timestamp_data()
Definition: rs.hpp:282
bool operator==(const float3 &a, const float3 &b)
Definition: types.h:113
device * get_device(int index)
Definition: rs.hpp:345
float3 transform(const float3 &point) const
Definition: rs.hpp:275
void set_option(option option, double value)
Definition: rs.hpp:954
log_callback(std::function< void(log_severity, const char *)> on_event)
Definition: rs.hpp:1072
int rs_is_stream_enabled(const rs_device *device, rs_stream stream, rs_error **error)
rs_ivcam_preset
Definition: rs.h:102
const std::string & get_failed_function() const
Definition: rs.hpp:305
Definition: rs.hpp:279
capabilities
Definition: rs.hpp:163
int rs_get_stream_height(const rs_device *device, rs_stream stream, rs_error **error)
void release() override
Definition: rs.hpp:1079
rs_stream rs_get_detached_frame_stream_type(const rs_frame_ref *frameset, rs_error **error)
rs_event_source
Definition: rs.h:266
const void * rs_get_detached_frame_data(const rs_frame_ref *frame, rs_error **error)
void get_options(const option *options, size_t count, double *values)
Definition: rs.hpp:911
motion_callback(std::function< void(motion_data)> on_event)
Definition: rs.hpp:358
float2 project(const float3 &point) const
Definition: rs.hpp:258
void wait_for_frames()
Definition: rs.hpp:963
Definition: rs.hpp:368
int get_device_count() const
Definition: rs.hpp:334
void rs_get_motion_intrinsics(const rs_device *device, rs_motion_intrinsics *intrinsic, rs_error **error)
float hfov() const
Definition: rs.hpp:245
~context()
Definition: rs.hpp:327
preset
Definition: rs.hpp:64
void rs_enable_motion_tracking_cpp(rs_device *device, rs_motion_callback *motion_callback, rs_timestamp_callback *timestamp_callback, rs_error **error)