ColorStream.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 "libfreenect.hpp"
6 #include "Driver/OniDriverAPI.h"
7 #include "VideoStream.hpp"
8 
9 
10 namespace FreenectDriver
11 {
12  class ColorStream : public VideoStream
13  {
14  public:
15  // from NUI library & converted to radians
16  static const float DIAGONAL_FOV = 73.9 * (M_PI / 180);
17  static const float HORIZONTAL_FOV = 62 * (M_PI / 180);
18  static const float VERTICAL_FOV = 48.6 * (M_PI / 180);
19 
20  private:
21  typedef std::map< OniVideoMode, std::pair<freenect_video_format, freenect_resolution> > FreenectVideoModeMap;
23 
24  static FreenectVideoModeMap getSupportedVideoModes();
25  OniStatus setVideoMode(OniVideoMode requested_mode);
26  void populateFrame(void* data, OniFrame* frame) const;
27 
30 
31  public:
33  //~ColorStream() { }
34 
36  {
37  FreenectVideoModeMap supported_modes = getSupportedVideoModes();
38  OniVideoMode* modes = new OniVideoMode[supported_modes.size()];
39  std::transform(supported_modes.begin(), supported_modes.end(), modes, ExtractKey());
40  OniSensorInfo sensors = { sensor_type, static_cast<int>(supported_modes.size()), modes };
41  return sensors;
42  }
43 
44  // from StreamBase
45  OniBool isPropertySupported(int propertyId)
46  {
47  switch(propertyId)
48  {
49  default:
50  return VideoStream::isPropertySupported(propertyId);
51 
56  return true;
57  }
58  }
59 
60  OniStatus getProperty(int propertyId, void* data, int* pDataSize)
61  {
62  switch (propertyId)
63  {
64  default:
65  return VideoStream::getProperty(propertyId, data, pDataSize);
66 
67  case ONI_STREAM_PROPERTY_HORIZONTAL_FOV: // float (radians)
68  {
69  if (*pDataSize != sizeof(float))
70  {
71  LogError("Unexpected size for ONI_STREAM_PROPERTY_HORIZONTAL_FOV");
72  return ONI_STATUS_ERROR;
73  }
74  *(static_cast<float*>(data)) = HORIZONTAL_FOV;
75  return ONI_STATUS_OK;
76  }
77  case ONI_STREAM_PROPERTY_VERTICAL_FOV: // float (radians)
78  {
79  if (*pDataSize != sizeof(float))
80  {
81  LogError("Unexpected size for ONI_STREAM_PROPERTY_VERTICAL_FOV");
82  return ONI_STATUS_ERROR;
83  }
84  *(static_cast<float*>(data)) = VERTICAL_FOV;
85  return ONI_STATUS_OK;
86  }
87 
88  // camera
90  {
91  if (*pDataSize != sizeof(OniBool))
92  {
93  LogError("Unexpected size for ONI_STREAM_PROPERTY_AUTO_WHITE_BALANCE");
94  return ONI_STATUS_ERROR;
95  }
96  *(static_cast<OniBool*>(data)) = auto_white_balance;
97  return ONI_STATUS_OK;
98  }
99  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE: // OniBool
100  {
101  if (*pDataSize != sizeof(OniBool))
102  {
103  LogError("Unexpected size for ONI_STREAM_PROPERTY_AUTO_EXPOSURE");
104  return ONI_STATUS_ERROR;
105  }
106  *(static_cast<OniBool*>(data)) = auto_exposure;
107  return ONI_STATUS_OK;
108  }
109  }
110  }
111 
112  OniStatus setProperty(int propertyId, const void* data, int dataSize)
113  {
114  switch (propertyId)
115  {
116  default:
117  return VideoStream::setProperty(propertyId, data, dataSize);
118 
119  // camera
121  {
122  if (dataSize != sizeof(OniBool))
123  {
124  LogError("Unexpected size for ONI_STREAM_PROPERTY_AUTO_WHITE_BALANCE");
125  return ONI_STATUS_ERROR;
126  }
127  auto_white_balance = *(static_cast<const OniBool*>(data));
128  int ret = device->setFlag(FREENECT_AUTO_WHITE_BALANCE, auto_white_balance);
129  return (ret == 0) ? ONI_STATUS_OK : ONI_STATUS_ERROR;
130  }
131  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE: // OniBool
132  {
133  if (dataSize != sizeof(OniBool))
134  {
135  LogError("Unexpected size for ONI_STREAM_PROPERTY_AUTO_EXPOSURE");
136  return ONI_STATUS_ERROR;
137  }
138  auto_exposure = *(static_cast<const OniBool*>(data));
139  int ret = device->setFlag(FREENECT_AUTO_WHITE_BALANCE, auto_exposure);
140  return (ret == 0) ? ONI_STATUS_OK : ONI_STATUS_ERROR;
141  }
142  case ONI_STREAM_PROPERTY_MIRRORING: // OniBool
143  {
144  if (dataSize != sizeof(OniBool))
145  {
146  LogError("Unexpected size for ONI_STREAM_PROPERTY_MIRRORING");
147  return ONI_STATUS_ERROR;
148  }
149  mirroring = *(static_cast<const OniBool*>(data));
151  return (ret == 0) ? ONI_STATUS_OK : ONI_STATUS_ERROR;
152  }
153  }
154  }
155  };
156 }
OniStatus setProperty(int propertyId, const void *data, int dataSize)
static void LogError(std::string error)
Definition: Utility.hpp:66
virtual OniStatus setProperty(int propertyId, const void *data, int dataSize)
int setFlag(freenect_flag flag, bool value)
int OniBool
Definition: OniCTypes.h:28
ColorStream(Freenect::FreenectDevice *pDevice)
Definition: ColorStream.cpp:7
static FreenectVideoModeMap getSupportedVideoModes()
Definition: ColorStream.cpp:15
Extracts first from pair, for transforming a map into its keys.
Definition: Utility.hpp:36
static const float VERTICAL_FOV
Definition: ColorStream.hpp:18
int frame
Definition: regview.c:72
void populateFrame(void *data, OniFrame *frame) const
Definition: ColorStream.cpp:51
OniSensorType
Definition: OniCEnums.h:38
static const float HORIZONTAL_FOV
Definition: ColorStream.hpp:17
OniBool isPropertySupported(int propertyId)
Definition: VideoStream.hpp:66
std::map< OniVideoMode, std::pair< freenect_video_format, freenect_resolution > > FreenectVideoModeMap
Definition: ColorStream.hpp:21
OniBool isPropertySupported(int propertyId)
Definition: ColorStream.hpp:45
Freenect::FreenectDevice * device
Definition: VideoStream.hpp:20
OniStatus setVideoMode(OniVideoMode requested_mode)
Definition: ColorStream.cpp:31
static const float DIAGONAL_FOV
Definition: ColorStream.hpp:16
static const OniSensorType sensor_type
Definition: ColorStream.hpp:22
OniStatus getProperty(int propertyId, void *data, int *pDataSize)
Definition: ColorStream.hpp:60
OniStatus
Definition: OniCEnums.h:25
static OniSensorInfo getSensorInfo()
Definition: ColorStream.hpp:35
virtual OniStatus getProperty(int propertyId, void *data, int *pDataSize)
Definition: VideoStream.hpp:79


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