DepthStream.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm> // for transform()
4 #include <cmath> // for M_PI
5 #include <cstdio> // for memcpy
6 #include "libfreenect.hpp"
7 #include "Driver/OniDriverAPI.h"
8 #include "PS1080.h"
9 #include "VideoStream.hpp"
10 #include "S2D.h"
11 #include "D2S.h"
12 
13 
14 namespace FreenectDriver
15 {
16  class DepthStream : public VideoStream
17  {
18  public:
19  // from NUI library and converted to radians
20  static const float DIAGONAL_FOV = 70 * (M_PI / 180);
21  static const float HORIZONTAL_FOV = 58.5 * (M_PI / 180);
22  static const float VERTICAL_FOV = 45.6 * (M_PI / 180);
23  // from DepthKinectStream.cpp
24  static const int MAX_VALUE = 10000;
25  static const unsigned long long GAIN_VAL = 42;
26  static const unsigned long long CONST_SHIFT_VAL = 200;
27  static const unsigned long long MAX_SHIFT_VAL = 2047;
28  static const unsigned long long PARAM_COEFF_VAL = 4;
29  static const unsigned long long SHIFT_SCALE_VAL = 10;
30  static const unsigned long long ZERO_PLANE_DISTANCE_VAL = 120;
31  static const double ZERO_PLANE_PIXEL_SIZE_VAL = 0.10520000010728836;
32  static const double EMITTER_DCMOS_DISTANCE_VAL = 7.5;
33 
34  private:
35  typedef std::map< OniVideoMode, std::pair<freenect_depth_format, freenect_resolution> > FreenectDepthModeMap;
38 
39  static FreenectDepthModeMap getSupportedVideoModes();
40  OniStatus setVideoMode(OniVideoMode requested_mode);
41  void populateFrame(void* data, OniFrame* frame) const;
42 
43  public:
45  //~DepthStream() { }
46 
48  {
49  FreenectDepthModeMap supported_modes = getSupportedVideoModes();
50  OniVideoMode* modes = new OniVideoMode[supported_modes.size()];
51  std::transform(supported_modes.begin(), supported_modes.end(), modes, ExtractKey());
52  OniSensorInfo sensors = { sensor_type, static_cast<int>(supported_modes.size()), modes };
53  return sensors;
54  }
55 
58  {
61  image_registration_mode = mode;
62  return setVideoMode(video_mode);
63  }
64 
65  // from StreamBase
67 
68  OniBool isPropertySupported(int propertyId)
69  {
70  switch(propertyId)
71  {
72  default:
73  return VideoStream::isPropertySupported(propertyId);
87  return true;
88  }
89  }
90 
91  OniStatus getProperty(int propertyId, void* data, int* pDataSize)
92  {
93  switch (propertyId)
94  {
95  default:
96  return VideoStream::getProperty(propertyId, data, pDataSize);
97 
98  case ONI_STREAM_PROPERTY_HORIZONTAL_FOV: // float (radians)
99  if (*pDataSize != sizeof(float))
100  {
101  LogError("Unexpected size for ONI_STREAM_PROPERTY_HORIZONTAL_FOV");
102  return ONI_STATUS_ERROR;
103  }
104  *(static_cast<float*>(data)) = HORIZONTAL_FOV;
105  return ONI_STATUS_OK;
106  case ONI_STREAM_PROPERTY_VERTICAL_FOV: // float (radians)
107  if (*pDataSize != sizeof(float))
108  {
109  LogError("Unexpected size for ONI_STREAM_PROPERTY_VERTICAL_FOV");
110  return ONI_STATUS_ERROR;
111  }
112  *(static_cast<float*>(data)) = VERTICAL_FOV;
113  return ONI_STATUS_OK;
114  case ONI_STREAM_PROPERTY_MAX_VALUE: // int
115  if (*pDataSize != sizeof(int))
116  {
117  LogError("Unexpected size for ONI_STREAM_PROPERTY_MAX_VALUE");
118  return ONI_STATUS_ERROR;
119  }
120  *(static_cast<int*>(data)) = MAX_VALUE;
121  return ONI_STATUS_OK;
122 
123  case XN_STREAM_PROPERTY_PIXEL_REGISTRATION: // XnPixelRegistration (get only)
124  case XN_STREAM_PROPERTY_WHITE_BALANCE_ENABLED: // unsigned long long
125  case XN_STREAM_PROPERTY_HOLE_FILTER: // unsigned long long
126  case XN_STREAM_PROPERTY_REGISTRATION_TYPE: // XnProcessingType
127  case XN_STREAM_PROPERTY_AGC_BIN: // XnDepthAGCBin*
128  case XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR: // unsigned long long
130  case XN_STREAM_PROPERTY_CLOSE_RANGE: // unsigned long long
132 
133  case XN_STREAM_PROPERTY_GAIN: // unsigned long long
134  if (*pDataSize != sizeof(unsigned long long))
135  {
136  LogError("Unexpected size for XN_STREAM_PROPERTY_GAIN");
137  return ONI_STATUS_ERROR;
138  }
139  *(static_cast<unsigned long long*>(data)) = GAIN_VAL;
140  return ONI_STATUS_OK;
141  case XN_STREAM_PROPERTY_CONST_SHIFT: // unsigned long long
142  if (*pDataSize != sizeof(unsigned long long))
143  {
144  LogError("Unexpected size for XN_STREAM_PROPERTY_CONST_SHIFT");
145  return ONI_STATUS_ERROR;
146  }
147  *(static_cast<unsigned long long*>(data)) = CONST_SHIFT_VAL;
148  return ONI_STATUS_OK;
149  case XN_STREAM_PROPERTY_MAX_SHIFT: // unsigned long long
150  if (*pDataSize != sizeof(unsigned long long))
151  {
152  LogError("Unexpected size for XN_STREAM_PROPERTY_MAX_SHIFT");
153  return ONI_STATUS_ERROR;
154  }
155  *(static_cast<unsigned long long*>(data)) = MAX_SHIFT_VAL;
156  return ONI_STATUS_OK;
157  case XN_STREAM_PROPERTY_PARAM_COEFF: // unsigned long long
158  if (*pDataSize != sizeof(unsigned long long))
159  {
160  LogError("Unexpected size for XN_STREAM_PROPERTY_PARAM_COEFF");
161  return ONI_STATUS_ERROR;
162  }
163  *(static_cast<unsigned long long*>(data)) = PARAM_COEFF_VAL;
164  return ONI_STATUS_OK;
165  case XN_STREAM_PROPERTY_SHIFT_SCALE: // unsigned long long
166  if (*pDataSize != sizeof(unsigned long long))
167  {
168  LogError("Unexpected size for XN_STREAM_PROPERTY_SHIFT_SCALE");
169  return ONI_STATUS_ERROR;
170  }
171  *(static_cast<unsigned long long*>(data)) = SHIFT_SCALE_VAL;
172  return ONI_STATUS_OK;
173  case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE: // unsigned long long
174  if (*pDataSize != sizeof(unsigned long long))
175  {
176  LogError("Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE");
177  return ONI_STATUS_ERROR;
178  }
179  *(static_cast<unsigned long long*>(data)) = ZERO_PLANE_DISTANCE_VAL;
180  return ONI_STATUS_OK;
182  if (*pDataSize != sizeof(double))
183  {
184  LogError("Unexpected size for XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE");
185  return ONI_STATUS_ERROR;
186  }
187  *(static_cast<double*>(data)) = ZERO_PLANE_PIXEL_SIZE_VAL;
188  return ONI_STATUS_OK;
190  if (*pDataSize != sizeof(double))
191  {
192  LogError("Unexpected size for XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE");
193  return ONI_STATUS_ERROR;
194  }
195  *(static_cast<double*>(data)) = EMITTER_DCMOS_DISTANCE_VAL;
196  return ONI_STATUS_OK;
197  case XN_STREAM_PROPERTY_S2D_TABLE: // OniDepthPixel[]
198  *pDataSize = sizeof(S2D);
199  //std::copy(S2D, S2D+1, static_cast<OniDepthPixel*>(data));
200  memcpy(data, S2D, *pDataSize);
201  return ONI_STATUS_OK;
202  case XN_STREAM_PROPERTY_D2S_TABLE: // unsigned short[]
203  *pDataSize = sizeof(D2S);
204  //std::copy(D2S, D2S+1, static_cast<unsigned short*>(data));
205  memcpy(data, D2S, *pDataSize);
206  return ONI_STATUS_OK;
207  }
208  }
209  };
210 }
OniImageRegistrationMode image_registration_mode
Definition: DepthStream.hpp:37
OniImageRegistrationMode
Definition: OniCEnums.h:72
static void LogError(std::string error)
Definition: Utility.hpp:66
static const OniSensorType sensor_type
Definition: DepthStream.hpp:36
OniImageRegistrationMode getImageRegistrationMode() const
Definition: DepthStream.hpp:56
OniBool isPropertySupported(int propertyId)
Definition: DepthStream.hpp:68
std::map< OniVideoMode, std::pair< freenect_depth_format, freenect_resolution > > FreenectDepthModeMap
Definition: DepthStream.hpp:35
int OniBool
Definition: OniCTypes.h:28
OniStatus getProperty(int propertyId, void *data, int *pDataSize)
Definition: DepthStream.hpp:91
static const int MAX_VALUE
Definition: DepthStream.hpp:24
static const float DIAGONAL_FOV
Definition: DepthStream.hpp:20
Extracts first from pair, for transforming a map into its keys.
Definition: Utility.hpp:36
static const unsigned long long PARAM_COEFF_VAL
Definition: DepthStream.hpp:28
int frame
Definition: regview.c:72
static FreenectDepthModeMap getSupportedVideoModes()
Definition: DepthStream.cpp:18
OniStatus setImageRegistrationMode(OniImageRegistrationMode mode)
Definition: DepthStream.hpp:57
void populateFrame(void *data, OniFrame *frame) const
Definition: DepthStream.cpp:56
static const unsigned long long GAIN_VAL
Definition: DepthStream.hpp:25
OniSensorType
Definition: OniCEnums.h:38
static const unsigned long long CONST_SHIFT_VAL
Definition: DepthStream.hpp:26
static const float VERTICAL_FOV
Definition: DepthStream.hpp:22
OniBool isPropertySupported(int propertyId)
Definition: VideoStream.hpp:66
static const unsigned long long SHIFT_SCALE_VAL
Definition: DepthStream.hpp:29
static const float HORIZONTAL_FOV
Definition: DepthStream.hpp:21
OniStatus setVideoMode(OniVideoMode requested_mode)
Definition: DepthStream.cpp:28
static OniSensorInfo getSensorInfo()
Definition: DepthStream.hpp:47
OniBool isImageRegistrationModeSupported(OniImageRegistrationMode mode)
Definition: DepthStream.hpp:66
DepthStream(Freenect::FreenectDevice *pDevice)
Definition: DepthStream.cpp:7
const uint16_t S2D[]
Definition: S2D.h:1
static const double EMITTER_DCMOS_DISTANCE_VAL
Definition: DepthStream.hpp:32
const unsigned short D2S[]
Definition: D2S.h:1
static const double ZERO_PLANE_PIXEL_SIZE_VAL
Definition: DepthStream.hpp:31
OniStatus
Definition: OniCEnums.h:25
static const unsigned long long ZERO_PLANE_DISTANCE_VAL
Definition: DepthStream.hpp:30
virtual OniStatus getProperty(int propertyId, void *data, int *pDataSize)
Definition: VideoStream.hpp:79
static const unsigned long long MAX_SHIFT_VAL
Definition: DepthStream.hpp:27


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Thu Jun 6 2019 19:25:38