Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
tm-conversions.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #include <map>
6 #include "tm-device.h"
7 #include "TrackingData.h"
8 #include "stream.h"
9 
10 namespace librealsense
11 {
12  const std::map<perc::PixelFormat, rs2_format> tm2_formats_map =
13  {
14  { perc::PixelFormat::ANY, RS2_FORMAT_ANY },
15  { perc::PixelFormat::Z16, RS2_FORMAT_Z16 },
16  { perc::PixelFormat::DISPARITY16, RS2_FORMAT_DISPARITY16 },
17  { perc::PixelFormat::XYZ32F, RS2_FORMAT_XYZ32F },
18  { perc::PixelFormat::YUYV, RS2_FORMAT_YUYV },
19  { perc::PixelFormat::RGB8, RS2_FORMAT_RGB8 },
20  { perc::PixelFormat::BGR8, RS2_FORMAT_BGR8 },
21  { perc::PixelFormat::RGBA8, RS2_FORMAT_RGBA8 },
22  { perc::PixelFormat::BGRA8, RS2_FORMAT_BGRA8 },
23  { perc::PixelFormat::Y8, RS2_FORMAT_Y8 },
24  { perc::PixelFormat::Y16, RS2_FORMAT_Y16 },
25  { perc::PixelFormat::RAW8, RS2_FORMAT_RAW8 },
26  { perc::PixelFormat::RAW10, RS2_FORMAT_RAW10 },
27  { perc::PixelFormat::RAW16, RS2_FORMAT_RAW16 }
28  };
29 
30  inline rs2_format convertTm2PixelFormat(perc::PixelFormat format)
31  {
32  auto iter = tm2_formats_map.find(format);
33  if (iter == tm2_formats_map.end())
34  {
35  throw invalid_value_exception("Invalid TM2 pixel format");
36  }
37  return iter->second;
38  }
39 
40  inline perc::PixelFormat convertToTm2PixelFormat(rs2_format format)
41  {
42  for (auto m : tm2_formats_map)
43  {
44  if (m.second == format)
45  {
46  return m.first;
47  }
48  }
49  throw invalid_value_exception("No matching TM2 pixel format");
50  }
51 
52  inline bool try_convert(rs2_stream stream, perc::SensorType& out)
53  {
54  switch (stream) {
55  case RS2_STREAM_DEPTH : out = perc::SensorType::Depth; return true;
56  case RS2_STREAM_COLOR : out = perc::SensorType::Color; return true;
57  case RS2_STREAM_INFRARED : out = perc::SensorType::IR; return true;
58  case RS2_STREAM_FISHEYE : out = perc::SensorType::Fisheye; return true;
59  case RS2_STREAM_GYRO : out = perc::SensorType::Gyro; return true;
60  case RS2_STREAM_ACCEL : out = perc::SensorType::Accelerometer; return true;
61  case RS2_STREAM_POSE : out = perc::SensorType::Controller; return true;
62  default:
63  return false;
64  }
65  }
67  {
68  switch (model)
69  {
70  case 0: return RS2_DISTORTION_NONE;
73  case 3: return RS2_DISTORTION_FTHETA;
74  case 4: //TODO - add KANNALA_BRANDT4;
75  default:
76  throw invalid_value_exception("Invalid TM2 camera model");
77  }
78  }
79 
80  inline uint32_t convertTm2InterruptRate(perc::SIXDOF_INTERRUPT_RATE rate)
81  {
82  switch (rate)
83  {
84  case perc::SIXDOF_INTERRUPT_RATE_NONE:
85  return 0;
86  case perc::SIXDOF_INTERRUPT_RATE_FISHEYE:
87  return 30;
88  case perc::SIXDOF_INTERRUPT_RATE_IMU:
89  return 262; //TODO - going to change by TM2 to something else...
90  default:
91  throw invalid_value_exception("Invalid TM2 pose rate");
92  }
93  }
94 
95  inline float3 toFloat3(perc::TrackingData::Axis a) { return float3{ a.x, a.y, a.z }; }
96 
97  inline float3 toFloat3(perc::TrackingData::EulerAngles a) { return float3{ a.x, a.y, a.z }; }
98 
99  inline float4 toFloat4(perc::TrackingData::Quaternion q) { return float4{ q.i, q.j, q.k, q.r }; }
100 }
Definition: rs_sensor.h:60
float x
Definition: types.h:414
Definition: rs_types.h:46
rs2_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs_types.h:43
float4 toFloat4(perc::TrackingData::Quaternion q)
Definition: tm-conversions.h:99
Definition: rs_sensor.h:42
Definition: rs_sensor.h:55
const std::map< perc::PixelFormat, rs2_format > tm2_formats_map
Definition: tm-conversions.h:12
Definition: rs_sensor.h:46
Definition: rs_sensor.h:58
Definition: rs_sensor.h:56
Definition: rs_sensor.h:43
perc::PixelFormat convertToTm2PixelFormat(rs2_format format)
Definition: tm-conversions.h:40
rs2_format convertTm2PixelFormat(perc::PixelFormat format)
Definition: tm-conversions.h:30
Definition: rs_sensor.h:40
bool try_convert(rs2_stream stream, perc::SensorType &out)
Definition: tm-conversions.h:52
Definition: rs_sensor.h:59
Definition: algo.h:16
Definition: rs_sensor.h:57
Definition: rs_types.h:45
Definition: types.h:414
Definition: rs_types.h:48
Definition: rs_sensor.h:54
rs2_format
Format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:52
rs2_distortion convertTm2CameraModel(int model)
Definition: tm-conversions.h:66
uint32_t convertTm2InterruptRate(perc::SIXDOF_INTERRUPT_RATE rate)
Definition: tm-conversions.h:80
Definition: rs_types.h:47
Definition: rs_sensor.h:39
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:36
Definition: rs_sensor.h:41
Definition: rs_sensor.h:44
Definition: rs_sensor.h:66
Definition: types.h:415
Definition: stream.h:14
Definition: rs_sensor.h:62
float3 toFloat3(perc::TrackingData::Axis a)
Definition: tm-conversions.h:95
Definition: rs_sensor.h:64
Definition: rs_sensor.h:67
Definition: rs_sensor.h:61
Definition: rs_sensor.h:63
Definition: rs_sensor.h:65