OpenNI 2.0
OpenNI.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * *
3 * OpenNI 2.x Alpha *
4 * Copyright (C) 2012 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * Licensed under the Apache License, Version 2.0 (the "License"); *
9 * you may not use this file except in compliance with the License. *
10 * You may obtain a copy of the License at *
11 * *
12 * http://www.apache.org/licenses/LICENSE-2.0 *
13 * *
14 * Unless required by applicable law or agreed to in writing, software *
15 * distributed under the License is distributed on an "AS IS" BASIS, *
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17 * See the License for the specific language governing permissions and *
18 * limitations under the License. *
19 * *
20 *****************************************************************************/
21 #ifndef OPENNI_H
22 #define OPENNI_H
23 
24 #include "OniPlatform.h"
25 #include "OniProperties.h"
26 #include "OniEnums.h"
27 
28 #include "OniCAPI.h"
29 #include "OniCProperties.h"
30 
34 namespace openni
35 {
36 
38 typedef uint16_t DepthPixel;
39 
41 typedef uint16_t Grayscale16Pixel;
42 
43 // structs
45 typedef struct
46 {
48  int major;
50  int minor;
54  int build;
55 } Version;
56 
58 typedef struct
59 {
60  /* Red value of this pixel. */
61  uint8_t r;
62  /* Green value of this pixel. */
63  uint8_t g;
64  /* Blue value of this pixel. */
65  uint8_t b;
66 } RGB888Pixel;
67 
73 typedef struct
74 {
76  uint8_t u;
78  uint8_t y1;
80  uint8_t v;
82  uint8_t y2;
84 
90 typedef struct
91 {
93  uint8_t y1;
95  uint8_t u;
97  uint8_t y2;
99  uint8_t v;
101 
103 class _NullString
104 {
105 public:
106  _NullString() {}
107  operator const char*() const { return NULL; }
108 };
109 
110 static const _NullString ANY_DEVICE;
111 
116 template<class T>
117 class Array
118 {
119 public:
123  Array() : m_data(NULL), m_count(0), m_owner(false) {}
124 
132  Array(const T* data, int count) : m_owner(false) { _setData(data, count); }
133 
138  {
139  clear();
140  }
141 
146  int getSize() const { return m_count; }
147 
151  const T& operator[](int index) const {return m_data[index];}
152 
163  void _setData(const T* data, int count, bool isOwner = false)
164  {
165  clear();
166  m_count = count;
167  m_owner = isOwner;
168  if (!isOwner)
169  {
170  m_data = data;
171  }
172  else
173  {
174  m_data = new T[count];
175  memcpy((void*)m_data, data, count*sizeof(T));
176  }
177  }
178 
179 private:
180  Array(const Array<T>&);
181  Array<T>& operator=(const Array<T>&);
182 
183  void clear()
184  {
185  if (m_owner && m_data != NULL)
186  delete []m_data;
187  m_owner = false;
188  m_data = NULL;
189  m_count = 0;
190  }
191 
192  const T* m_data;
193  int m_count;
194  bool m_owner;
195 };
196 
197 // Forward declaration of all
198 class SensorInfo;
199 class VideoStream;
200 class VideoFrameRef;
201 class Device;
202 class OpenNI;
203 class CameraSettings;
204 class PlaybackControl;
205 
220 class VideoMode : private OniVideoMode
221 {
222 public:
229  {}
230 
236  VideoMode(const VideoMode& other)
237  {
238  *this = other;
239  }
240 
248  {
250  setResolution(other.getResolutionX(), other.getResolutionY());
251  setFps(other.getFps());
252 
253  return *this;
254  }
255 
260  PixelFormat getPixelFormat() const { return (PixelFormat)pixelFormat; }
261 
266  int getResolutionX() const { return resolutionX; }
267 
272  int getResolutionY() const {return resolutionY;}
273 
278  int getFps() const { return fps; }
279 
286  void setPixelFormat(PixelFormat format) { this->pixelFormat = (OniPixelFormat)format; }
287 
295  void setResolution(int resolutionX, int resolutionY)
296  {
297  this->resolutionX = resolutionX;
298  this->resolutionY = resolutionY;
299  }
300 
307  void setFps(int fps) { this->fps = fps; }
308 
309  friend class SensorInfo;
310  friend class VideoStream;
311  friend class VideoFrameRef;
312 };
313 
332 {
333 public:
338  SensorType getSensorType() const { return (SensorType)m_pInfo->sensorType; }
339 
347  const Array<VideoMode>& getSupportedVideoModes() const { return m_videoModes; }
348 
349 private:
350  SensorInfo(const SensorInfo&);
351  SensorInfo& operator=(const SensorInfo&);
352 
353  SensorInfo() : m_pInfo(NULL), m_videoModes(NULL, 0) {}
354 
355  SensorInfo(const OniSensorInfo* pInfo) : m_pInfo(NULL), m_videoModes(NULL, 0)
356  {
357  _setInternal(pInfo);
358  }
359 
360  void _setInternal(const OniSensorInfo* pInfo)
361  {
362  m_pInfo = pInfo;
363  if (pInfo == NULL)
364  {
365  m_videoModes._setData(NULL, 0);
366  }
367  else
368  {
369  m_videoModes._setData(static_cast<VideoMode*>(pInfo->pSupportedVideoModes), pInfo->numSupportedVideoModes);
370  }
371  }
372 
373  const OniSensorInfo* m_pInfo;
374  Array<VideoMode> m_videoModes;
375 
376  friend class VideoStream;
377  friend class Device;
378 };
379 
389 class DeviceInfo : private OniDeviceInfo
390 {
391 public:
396  const char* getUri() const { return uri; }
398  const char* getVendor() const { return vendor; }
400  const char* getName() const { return name; }
402  uint16_t getUsbVendorId() const { return usbVendorId; }
404  uint16_t getUsbProductId() const { return usbProductId; }
405 
406  friend class Device;
407  friend class OpenNI;
408 };
409 
424 {
425 public:
431  {
432  m_pFrame = NULL;
433  }
434 
439  {
440  release();
441  }
442 
448  VideoFrameRef(const VideoFrameRef& other) : m_pFrame(NULL)
449  {
450  _setFrame(other.m_pFrame);
451  }
452 
459  {
460  _setFrame(other.m_pFrame);
461  return *this;
462  }
463 
469  inline int getDataSize() const
470  {
471  return m_pFrame->dataSize;
472  }
473 
479  inline const void* getData() const
480  {
481  return m_pFrame->data;
482  }
483 
490  inline SensorType getSensorType() const
491  {
492  return (SensorType)m_pFrame->sensorType;
493  }
494 
502  inline const VideoMode& getVideoMode() const
503  {
504  return static_cast<const VideoMode&>(m_pFrame->videoMode);
505  }
506 
514  inline uint64_t getTimestamp() const
515  {
516  return m_pFrame->timestamp;
517  }
518 
529  inline int getFrameIndex() const
530  {
531  return m_pFrame->frameIndex;
532  }
533 
540  inline int getWidth() const
541  {
542  return m_pFrame->width;
543  }
544 
550  inline int getHeight() const
551  {
552  return m_pFrame->height;
553  }
554 
559  inline bool getCroppingEnabled() const
560  {
561  return m_pFrame->croppingEnabled == TRUE;
562  }
563 
568  inline int getCropOriginX() const
569  {
570  return m_pFrame->cropOriginX;
571  }
572 
577  inline int getCropOriginY() const
578  {
579  return m_pFrame->cropOriginY;
580  }
581 
587  inline int getStrideInBytes() const
588  {
589  return m_pFrame->stride;
590  }
591 
595  inline bool isValid() const
596  {
597  return m_pFrame != NULL;
598  }
599 
604  void release()
605  {
606  if (m_pFrame != NULL)
607  {
608  oniFrameRelease(m_pFrame);
609  m_pFrame = NULL;
610  }
611  }
612 
614  void _setFrame(OniFrame* pFrame)
615  {
616  setReference(pFrame);
617  if (pFrame != NULL)
618  {
619  oniFrameAddRef(pFrame);
620  }
621  }
622 
624  OniFrame* _getFrame()
625  {
626  return m_pFrame;
627  }
628 
629 private:
630  friend class VideoStream;
631  inline void setReference(OniFrame* pFrame)
632  {
633  // Initial - don't addref. This is the reference from OpenNI
634  release();
635  m_pFrame = pFrame;
636  }
637 
638  OniFrame* m_pFrame; // const!!?
639 };
640 
663 {
664 public:
673  {
674  public:
678  NewFrameListener() : m_callbackHandle(NULL)
679  {
680  }
681 
683  {
684  }
685 
689  virtual void onNewFrame(VideoStream&) = 0;
690 
691  private:
692  friend class VideoStream;
693 
694  static void ONI_CALLBACK_TYPE callback(OniStreamHandle streamHandle, void* pCookie)
695  {
696  NewFrameListener* pListener = (NewFrameListener*)pCookie;
697  VideoStream stream;
698  stream._setHandle(streamHandle);
699  pListener->onNewFrame(stream);
700  stream._setHandle(NULL);
701  }
702  OniCallbackHandle m_callbackHandle;
703  };
704 
706  {
707  public:
708  virtual ~FrameAllocator() {}
709  virtual void* allocateFrameBuffer(int size) = 0;
710  virtual void freeFrameBuffer(void* data) = 0;
711 
712  private:
713  friend class VideoStream;
714 
715  static void* ONI_CALLBACK_TYPE allocateFrameBufferCallback(int size, void* pCookie)
716  {
717  FrameAllocator* pThis = (FrameAllocator*)pCookie;
718  return pThis->allocateFrameBuffer(size);
719  }
720 
721  static void ONI_CALLBACK_TYPE freeFrameBufferCallback(void* data, void* pCookie)
722  {
723  FrameAllocator* pThis = (FrameAllocator*)pCookie;
724  pThis->freeFrameBuffer(data);
725  }
726  };
727 
732  VideoStream() : m_stream(NULL), m_sensorInfo(), m_pCameraSettings(NULL), m_isOwner(true)
733  {}
734 
739  explicit VideoStream(OniStreamHandle handle) : m_stream(NULL), m_sensorInfo(), m_pCameraSettings(NULL), m_isOwner(false)
740  {
741  _setHandle(handle);
742  }
743 
749  {
750  destroy();
751  }
752 
757  bool isValid() const
758  {
759  return m_stream != NULL;
760  }
761 
771  inline Status create(const Device& device, SensorType sensorType);
772 
778  inline void destroy();
779 
788  const SensorInfo& getSensorInfo() const
789  {
790  return m_sensorInfo;
791  }
792 
797  {
798  if (!isValid())
799  {
800  return STATUS_ERROR;
801  }
802 
803  return (Status)oniStreamStart(m_stream);
804  }
805 
809  void stop()
810  {
811  if (!isValid())
812  {
813  return;
814  }
815 
816  oniStreamStop(m_stream);
817  }
818 
830  {
831  if (!isValid())
832  {
833  return STATUS_ERROR;
834  }
835 
836  OniFrame* pOniFrame;
837  Status rc = (Status)oniStreamReadFrame(m_stream, &pOniFrame);
838 
839  pFrame->setReference(pOniFrame);
840  return rc;
841  }
842 
851  {
852  if (!isValid())
853  {
854  return STATUS_ERROR;
855  }
856 
857  return (Status)oniStreamRegisterNewFrameCallback(m_stream, pListener->callback, pListener, &pListener->m_callbackHandle);
858  }
859 
865  {
866  if (!isValid())
867  {
868  return;
869  }
870 
871  oniStreamUnregisterNewFrameCallback(m_stream, pListener->m_callbackHandle);
872  pListener->m_callbackHandle = NULL;
873  }
874 
881  {
882  if (!isValid())
883  {
884  return STATUS_ERROR;
885  }
886 
887  if (pAllocator == NULL)
888  {
889  return (Status)oniStreamSetFrameBuffersAllocator(m_stream, NULL, NULL, NULL);
890  }
891  else
892  {
893  return (Status)oniStreamSetFrameBuffersAllocator(m_stream, pAllocator->allocateFrameBufferCallback, pAllocator->freeFrameBufferCallback, pAllocator);
894  }
895  }
896 
901  OniStreamHandle _getHandle() const
902  {
903  return m_stream;
904  }
905 
910  CameraSettings* getCameraSettings() {return m_pCameraSettings;}
911 
922  Status getProperty(int propertyId, void* data, int* dataSize) const
923  {
924  if (!isValid())
925  {
926  return STATUS_ERROR;
927  }
928 
929  return (Status)oniStreamGetProperty(m_stream, propertyId, data, dataSize);
930  }
931 
942  Status setProperty(int propertyId, const void* data, int dataSize)
943  {
944  if (!isValid())
945  {
946  return STATUS_ERROR;
947  }
948 
949  return (Status)oniStreamSetProperty(m_stream, propertyId, data, dataSize);
950  }
951 
959  {
960  VideoMode videoMode;
961  getProperty<OniVideoMode>(STREAM_PROPERTY_VIDEO_MODE, static_cast<OniVideoMode*>(&videoMode));
962  return videoMode;
963  }
964 
973  Status setVideoMode(const VideoMode& videoMode)
974  {
975  return setProperty<OniVideoMode>(STREAM_PROPERTY_VIDEO_MODE, static_cast<const OniVideoMode&>(videoMode));
976  }
977 
983  int getMaxPixelValue() const
984  {
985  int maxValue;
986  Status rc = getProperty<int>(STREAM_PROPERTY_MAX_VALUE, &maxValue);
987  if (rc != STATUS_OK)
988  {
989  return 0;
990  }
991  return maxValue;
992  }
993 
999  int getMinPixelValue() const
1000  {
1001  int minValue;
1002  Status rc = getProperty<int>(STREAM_PROPERTY_MIN_VALUE, &minValue);
1003  if (rc != STATUS_OK)
1004  {
1005  return 0;
1006  }
1007  return minValue;
1008  }
1009 
1014  bool isCroppingSupported() const
1015  {
1016  return isPropertySupported(STREAM_PROPERTY_CROPPING);
1017  }
1018 
1027  bool getCropping(int* pOriginX, int* pOriginY, int* pWidth, int* pHeight) const
1028  {
1029  OniCropping cropping;
1030  bool enabled = false;
1031 
1032  Status rc = getProperty<OniCropping>(STREAM_PROPERTY_CROPPING, &cropping);
1033 
1034  if (rc == STATUS_OK)
1035  {
1036  *pOriginX = cropping.originX;
1037  *pOriginY = cropping.originY;
1038  *pWidth = cropping.width;
1039  *pHeight = cropping.height;
1040  enabled = (cropping.enabled == TRUE);
1041  }
1042 
1043  return enabled;
1044  }
1045 
1055  Status setCropping(int originX, int originY, int width, int height)
1056  {
1057  OniCropping cropping;
1058  cropping.enabled = true;
1059  cropping.originX = originX;
1060  cropping.originY = originY;
1061  cropping.width = width;
1062  cropping.height = height;
1063  return setProperty<OniCropping>(STREAM_PROPERTY_CROPPING, cropping);
1064  }
1065 
1071  {
1072  OniCropping cropping;
1073  cropping.enabled = false;
1074  return setProperty<OniCropping>(STREAM_PROPERTY_CROPPING, cropping);
1075  }
1076 
1081  bool getMirroringEnabled() const
1082  {
1083  OniBool enabled;
1084  Status rc = getProperty<OniBool>(STREAM_PROPERTY_MIRRORING, &enabled);
1085  if (rc != STATUS_OK)
1086  {
1087  return false;
1088  }
1089  return enabled == TRUE;
1090  }
1091 
1097  Status setMirroringEnabled(bool isEnabled)
1098  {
1099  return setProperty<OniBool>(STREAM_PROPERTY_MIRRORING, isEnabled ? TRUE : FALSE);
1100  }
1101 
1107  {
1108  float horizontal = 0;
1109  getProperty<float>(STREAM_PROPERTY_HORIZONTAL_FOV, &horizontal);
1110  return horizontal;
1111  }
1112 
1118  {
1119  float vertical = 0;
1120  getProperty<float>(STREAM_PROPERTY_VERTICAL_FOV, &vertical);
1121  return vertical;
1122  }
1123 
1133  template <class T>
1134  Status setProperty(int propertyId, const T& value)
1135  {
1136  return setProperty(propertyId, &value, sizeof(T));
1137  }
1138 
1148  template <class T>
1149  Status getProperty(int propertyId, T* value) const
1150  {
1151  int size = sizeof(T);
1152  return getProperty(propertyId, value, &size);
1153  }
1154 
1160  bool isPropertySupported(int propertyId) const
1161  {
1162  if (!isValid())
1163  {
1164  return false;
1165  }
1166 
1167  return oniStreamIsPropertySupported(m_stream, propertyId) == TRUE;
1168  }
1169 
1179  Status invoke(int commandId, void* data, int dataSize)
1180  {
1181  if (!isValid())
1182  {
1183  return STATUS_ERROR;
1184  }
1185 
1186  return (Status)oniStreamInvoke(m_stream, commandId, data, dataSize);
1187  }
1188 
1198  template <class T>
1199  Status invoke(int commandId, T& value)
1200  {
1201  return invoke(commandId, &value, sizeof(T));
1202  }
1203 
1209  bool isCommandSupported(int commandId) const
1210  {
1211  if (!isValid())
1212  {
1213  return false;
1214  }
1215 
1216  return (Status)oniStreamIsCommandSupported(m_stream, commandId) == TRUE;
1217  }
1218 
1219 private:
1220  friend class Device;
1221 
1222  void _setHandle(OniStreamHandle stream)
1223  {
1224  m_sensorInfo._setInternal(NULL);
1225  m_stream = stream;
1226 
1227  if (stream != NULL)
1228  {
1229  m_sensorInfo._setInternal(oniStreamGetSensorInfo(m_stream));
1230  }
1231  }
1232 
1233 private:
1234  VideoStream(const VideoStream& other);
1235  VideoStream& operator=(const VideoStream& other);
1236 
1237  OniStreamHandle m_stream;
1238  SensorInfo m_sensorInfo;
1239  CameraSettings* m_pCameraSettings;
1240  bool m_isOwner;
1241 };
1242 
1259 class Device
1260 {
1261 public:
1266  Device() : m_pPlaybackControl(NULL), m_device(NULL), m_isOwner(true)
1267  {
1268  clearSensors();
1269  }
1270 
1275  explicit Device(OniDeviceHandle handle) : m_pPlaybackControl(NULL), m_device(NULL), m_isOwner(false)
1276  {
1277  _setHandle(handle);
1278  }
1279 
1285  {
1286  if (m_device != NULL)
1287  {
1288  close();
1289  }
1290  }
1291 
1321  inline Status open(const char* uri);
1322 
1328  inline void close();
1329 
1339  const DeviceInfo& getDeviceInfo() const
1340  {
1341  return m_deviceInfo;
1342  }
1343 
1351  bool hasSensor(SensorType sensorType)
1352  {
1353  int i;
1354  for (i = 0; (i < ONI_MAX_SENSORS) && (m_aSensorInfo[i].m_pInfo != NULL); ++i)
1355  {
1356  if (m_aSensorInfo[i].getSensorType() == sensorType)
1357  {
1358  return true;
1359  }
1360  }
1361 
1362  if (i == ONI_MAX_SENSORS)
1363  {
1364  return false;
1365  }
1366 
1367  const OniSensorInfo* pInfo = oniDeviceGetSensorInfo(m_device, (OniSensorType)sensorType);
1368 
1369  if (pInfo == NULL)
1370  {
1371  return false;
1372  }
1373 
1374  m_aSensorInfo[i]._setInternal(pInfo);
1375 
1376  return true;
1377  }
1378 
1387  {
1388  int i;
1389  for (i = 0; (i < ONI_MAX_SENSORS) && (m_aSensorInfo[i].m_pInfo != NULL); ++i)
1390  {
1391  if (m_aSensorInfo[i].getSensorType() == sensorType)
1392  {
1393  return &m_aSensorInfo[i];
1394  }
1395  }
1396 
1397  // not found. check to see we have additional space
1398  if (i == ONI_MAX_SENSORS)
1399  {
1400  return NULL;
1401  }
1402 
1403  const OniSensorInfo* pInfo = oniDeviceGetSensorInfo(m_device, (OniSensorType)sensorType);
1404  if (pInfo == NULL)
1405  {
1406  return NULL;
1407  }
1408 
1409  m_aSensorInfo[i]._setInternal(pInfo);
1410  return &m_aSensorInfo[i];
1411  }
1412 
1417  OniDeviceHandle _getHandle() const
1418  {
1419  return m_device;
1420  }
1421 
1426  PlaybackControl* getPlaybackControl() {return m_pPlaybackControl;}
1427 
1439  Status getProperty(int propertyId, void* data, int* dataSize) const
1440  {
1441  return (Status)oniDeviceGetProperty(m_device, propertyId, data, dataSize);
1442  }
1443 
1455  Status setProperty(int propertyId, const void* data, int dataSize)
1456  {
1457  return (Status)oniDeviceSetProperty(m_device, propertyId, data, dataSize);
1458  }
1459 
1468  {
1469  return (oniDeviceIsImageRegistrationModeSupported(m_device, (OniImageRegistrationMode)mode) == TRUE);
1470  }
1471 
1480  {
1481  ImageRegistrationMode mode;
1482  Status rc = getProperty<ImageRegistrationMode>(DEVICE_PROPERTY_IMAGE_REGISTRATION, &mode);
1483  if (rc != STATUS_OK)
1484  {
1485  return IMAGE_REGISTRATION_OFF;
1486  }
1487  return mode;
1488  }
1489 
1504  {
1505  return setProperty<ImageRegistrationMode>(DEVICE_PROPERTY_IMAGE_REGISTRATION, mode);
1506  }
1507 
1512  bool isValid() const
1513  {
1514  return m_device != NULL;
1515  }
1516 
1521  bool isFile() const
1522  {
1523  return isPropertySupported(DEVICE_PROPERTY_PLAYBACK_SPEED) &&
1524  isPropertySupported(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED) &&
1525  isCommandSupported(DEVICE_COMMAND_SEEK);
1526  }
1527 
1537  {
1538  Status rc = STATUS_OK;
1539 
1540  if (isEnabled)
1541  {
1542  rc = (Status)oniDeviceEnableDepthColorSync(m_device);
1543  }
1544  else
1545  {
1546  oniDeviceDisableDepthColorSync(m_device);
1547  }
1548 
1549  return rc;
1550  }
1551 
1553  {
1554  return oniDeviceGetDepthColorSyncEnabled(m_device) == TRUE;
1555  }
1556 
1567  template <class T>
1568  Status setProperty(int propertyId, const T& value)
1569  {
1570  return setProperty(propertyId, &value, sizeof(T));
1571  }
1572 
1582  template <class T>
1583  Status getProperty(int propertyId, T* value) const
1584  {
1585  int size = sizeof(T);
1586  return getProperty(propertyId, value, &size);
1587  }
1588 
1594  bool isPropertySupported(int propertyId) const
1595  {
1596  return oniDeviceIsPropertySupported(m_device, propertyId) == TRUE;
1597  }
1598 
1608  Status invoke(int commandId, void* data, int dataSize)
1609  {
1610  return (Status)oniDeviceInvoke(m_device, commandId, data, dataSize);
1611  }
1612 
1622  template <class T>
1623  Status invoke(int propertyId, T& value)
1624  {
1625  return invoke(propertyId, &value, sizeof(T));
1626  }
1627 
1633  bool isCommandSupported(int commandId) const
1634  {
1635  return oniDeviceIsCommandSupported(m_device, commandId) == TRUE;
1636  }
1637 
1639  inline Status _openEx(const char* uri, const char* mode);
1640 
1641 private:
1642  Device(const Device&);
1643  Device& operator=(const Device&);
1644 
1645  void clearSensors()
1646  {
1647  for (int i = 0; i < ONI_MAX_SENSORS; ++i)
1648  {
1649  m_aSensorInfo[i]._setInternal(NULL);
1650  }
1651  }
1652 
1653  inline Status _setHandle(OniDeviceHandle deviceHandle);
1654 
1655 private:
1656  PlaybackControl* m_pPlaybackControl;
1657 
1658  OniDeviceHandle m_device;
1659  DeviceInfo m_deviceInfo;
1660  SensorInfo m_aSensorInfo[ONI_MAX_SENSORS];
1661 
1662  bool m_isOwner;
1663 };
1664 
1679 {
1680 public:
1681 
1688  {
1689  detach();
1690  }
1691 
1712  float getSpeed() const
1713  {
1714  if (!isValid())
1715  {
1716  return 0.0f;
1717  }
1718  float speed;
1719  Status rc = m_pDevice->getProperty<float>(DEVICE_PROPERTY_PLAYBACK_SPEED, &speed);
1720  if (rc != STATUS_OK)
1721  {
1722  return 1.0f;
1723  }
1724  return speed;
1725  }
1733  Status setSpeed(float speed)
1734  {
1735  if (!isValid())
1736  {
1737  return STATUS_NO_DEVICE;
1738  }
1739  return m_pDevice->setProperty<float>(DEVICE_PROPERTY_PLAYBACK_SPEED, speed);
1740  }
1741 
1747  bool getRepeatEnabled() const
1748  {
1749  if (!isValid())
1750  {
1751  return false;
1752  }
1753 
1754  OniBool repeat;
1755  Status rc = m_pDevice->getProperty<OniBool>(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED, &repeat);
1756  if (rc != STATUS_OK)
1757  {
1758  return false;
1759  }
1760 
1761  return repeat == TRUE;
1762  }
1763 
1773  {
1774  if (!isValid())
1775  {
1776  return STATUS_NO_DEVICE;
1777  }
1778 
1779  return m_pDevice->setProperty<OniBool>(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED, repeat ? TRUE : FALSE);
1780  }
1781 
1792  Status seek(const VideoStream& stream, int frameIndex)
1793  {
1794  if (!isValid())
1795  {
1796  return STATUS_NO_DEVICE;
1797  }
1798  OniSeek seek;
1799  seek.frameIndex = frameIndex;
1800  seek.stream = stream._getHandle();
1801  return m_pDevice->invoke(DEVICE_COMMAND_SEEK, seek);
1802  }
1803 
1812  int getNumberOfFrames(const VideoStream& stream) const
1813  {
1814  int numOfFrames = -1;
1815  Status rc = stream.getProperty<int>(STREAM_PROPERTY_NUMBER_OF_FRAMES, &numOfFrames);
1816  if (rc != STATUS_OK)
1817  {
1818  return 0;
1819  }
1820  return numOfFrames;
1821  }
1822 
1823  bool isValid() const
1824  {
1825  return m_pDevice != NULL;
1826  }
1827 private:
1828  Status attach(Device* device)
1829  {
1830  if (!device->isValid() || !device->isFile())
1831  {
1832  return STATUS_ERROR;
1833  }
1834 
1835  detach();
1836  m_pDevice = device;
1837 
1838  return STATUS_OK;
1839  }
1840  void detach()
1841  {
1842  m_pDevice = NULL;
1843  }
1844 
1845  friend class Device;
1846  PlaybackControl(Device* pDevice) : m_pDevice(NULL)
1847  {
1848  if (pDevice != NULL)
1849  {
1850  attach(pDevice);
1851  }
1852  }
1853 
1854  Device* m_pDevice;
1855 };
1856 
1858 {
1859 public:
1860  // setters
1862  {
1863  return setProperty(STREAM_PROPERTY_AUTO_EXPOSURE, enabled ? TRUE : FALSE);
1864  }
1866  {
1867  return setProperty(STREAM_PROPERTY_AUTO_WHITE_BALANCE, enabled ? TRUE : FALSE);
1868  }
1869 
1871  {
1872  OniBool enabled = FALSE;
1873 
1874  Status rc = getProperty(STREAM_PROPERTY_AUTO_EXPOSURE, &enabled);
1875  return rc == STATUS_OK && enabled == TRUE;
1876  }
1878  {
1879  OniBool enabled = FALSE;
1880 
1881  Status rc = getProperty(STREAM_PROPERTY_AUTO_WHITE_BALANCE, &enabled);
1882  return rc == STATUS_OK && enabled == TRUE;
1883  }
1884 
1885  Status setGain(int gain)
1886  {
1887  return setProperty(STREAM_PROPERTY_GAIN, gain);
1888  }
1889  Status setExposure(int exposure)
1890  {
1891  return setProperty(STREAM_PROPERTY_EXPOSURE, exposure);
1892  }
1893  int getGain()
1894  {
1895  int gain;
1896  Status rc = getProperty(STREAM_PROPERTY_GAIN, &gain);
1897  if (rc != STATUS_OK)
1898  {
1899  return 100;
1900  }
1901  return gain;
1902  }
1904  {
1905  int exposure;
1906  Status rc = getProperty(STREAM_PROPERTY_EXPOSURE, &exposure);
1907  if (rc != STATUS_OK)
1908  {
1909  return 0;
1910  }
1911  return exposure;
1912  }
1913 
1914  bool isValid() const {return m_pStream != NULL;}
1915 private:
1916  template <class T>
1917  Status getProperty(int propertyId, T* value) const
1918  {
1919  if (!isValid()) return STATUS_NOT_SUPPORTED;
1920 
1921  return m_pStream->getProperty<T>(propertyId, value);
1922  }
1923  template <class T>
1924  Status setProperty(int propertyId, const T& value)
1925  {
1926  if (!isValid()) return STATUS_NOT_SUPPORTED;
1927 
1928  return m_pStream->setProperty<T>(propertyId, value);
1929  }
1930 
1931  friend class VideoStream;
1932  CameraSettings(VideoStream* pStream)
1933  {
1934  m_pStream = pStream;
1935  }
1936 
1937  VideoStream* m_pStream;
1938 };
1939 
1940 
1953 class OpenNI
1954 {
1955 public:
1956 
1973  {
1974  public:
1976  {
1977  m_deviceConnectedCallbacks.deviceConnected = deviceConnectedCallback;
1978  m_deviceConnectedCallbacks.deviceDisconnected = NULL;
1979  m_deviceConnectedCallbacks.deviceStateChanged = NULL;
1980  m_deviceConnectedCallbacksHandle = NULL;
1981  }
1982 
1984  {
1985  }
1986 
1998  virtual void onDeviceConnected(const DeviceInfo*) = 0;
1999  private:
2000  static void ONI_CALLBACK_TYPE deviceConnectedCallback(const OniDeviceInfo* pInfo, void* pCookie)
2001  {
2002  DeviceConnectedListener* pListener = (DeviceConnectedListener*)pCookie;
2003  pListener->onDeviceConnected(static_cast<const DeviceInfo*>(pInfo));
2004  }
2005 
2006  friend class OpenNI;
2007  OniDeviceCallbacks m_deviceConnectedCallbacks;
2008  OniCallbackHandle m_deviceConnectedCallbacksHandle;
2009 
2010  };
2028  {
2029  public:
2031  {
2032  m_deviceDisconnectedCallbacks.deviceConnected = NULL;
2033  m_deviceDisconnectedCallbacks.deviceDisconnected = deviceDisconnectedCallback;
2034  m_deviceDisconnectedCallbacks.deviceStateChanged = NULL;
2035  m_deviceDisconnectedCallbacksHandle = NULL;
2036  }
2037 
2039  {
2040  }
2041 
2050  virtual void onDeviceDisconnected(const DeviceInfo*) = 0;
2051  private:
2052  static void ONI_CALLBACK_TYPE deviceDisconnectedCallback(const OniDeviceInfo* pInfo, void* pCookie)
2053  {
2055  pListener->onDeviceDisconnected(static_cast<const DeviceInfo*>(pInfo));
2056  }
2057 
2058  friend class OpenNI;
2059  OniDeviceCallbacks m_deviceDisconnectedCallbacks;
2060  OniCallbackHandle m_deviceDisconnectedCallbacksHandle;
2061  };
2076  {
2077  public:
2079  {
2080  m_deviceStateChangedCallbacks.deviceConnected = NULL;
2081  m_deviceStateChangedCallbacks.deviceDisconnected = NULL;
2082  m_deviceStateChangedCallbacks.deviceStateChanged = deviceStateChangedCallback;
2083  m_deviceStateChangedCallbacksHandle = NULL;
2084  }
2085 
2087  {
2088  }
2089 
2096  virtual void onDeviceStateChanged(const DeviceInfo*, DeviceState) = 0;
2097  private:
2098  static void ONI_CALLBACK_TYPE deviceStateChangedCallback(const OniDeviceInfo* pInfo, OniDeviceState state, void* pCookie)
2099  {
2101  pListener->onDeviceStateChanged(static_cast<const DeviceInfo*>(pInfo), DeviceState(state));
2102  }
2103 
2104  friend class OpenNI;
2105  OniDeviceCallbacks m_deviceStateChangedCallbacks;
2106  OniCallbackHandle m_deviceStateChangedCallbacksHandle;
2107  };
2108 
2115  {
2116  return (Status)oniInitialize(ONI_API_VERSION); // provide version of API, to make sure proper struct sizes are used
2117  }
2118 
2123  static void shutdown()
2124  {
2125  oniShutdown();
2126  }
2127 
2132  {
2133  OniVersion oniVersion = oniGetVersion();
2134  Version version;
2135  version.major = oniVersion.major;
2136  version.minor = oniVersion.minor;
2137  version.maintenance = oniVersion.maintenance;
2138  version.build = oniVersion.build;
2139  return version;
2140  }
2141 
2149  static const char* getExtendedError()
2150  {
2151  return oniGetExtendedError();
2152  }
2153 
2158  static void enumerateDevices(Array<DeviceInfo>* deviceInfoList)
2159  {
2160  OniDeviceInfo* m_pDeviceInfos;
2161  int m_deviceInfoCount;
2162  oniGetDeviceList(&m_pDeviceInfos, &m_deviceInfoCount);
2163  deviceInfoList->_setData((DeviceInfo*)m_pDeviceInfos, m_deviceInfoCount, true);
2164  oniReleaseDeviceList(m_pDeviceInfos);
2165  }
2166 
2175  static Status waitForAnyStream(VideoStream** pStreams, int streamCount, int* pReadyStreamIndex, int timeout = TIMEOUT_FOREVER)
2176  {
2177  static const int ONI_MAX_STREAMS = 50;
2178  OniStreamHandle streams[ONI_MAX_STREAMS];
2179 
2180  if (streamCount > ONI_MAX_STREAMS)
2181  {
2182  printf("Too many streams for wait: %d > %d\n", streamCount, ONI_MAX_STREAMS);
2183  return STATUS_BAD_PARAMETER;
2184  }
2185 
2186  *pReadyStreamIndex = -1;
2187  for (int i = 0; i < streamCount; ++i)
2188  {
2189  if (pStreams[i] != NULL)
2190  {
2191  streams[i] = pStreams[i]->_getHandle();
2192  }
2193  else
2194  {
2195  streams[i] = NULL;
2196  }
2197  }
2198  Status rc = (Status)oniWaitForAnyStream(streams, streamCount, pReadyStreamIndex, timeout);
2199 
2200  return rc;
2201  }
2202 
2211  {
2212  if (pListener->m_deviceConnectedCallbacksHandle != NULL)
2213  {
2214  return STATUS_ERROR;
2215  }
2216  return (Status)oniRegisterDeviceCallbacks(&pListener->m_deviceConnectedCallbacks, pListener, &pListener->m_deviceConnectedCallbacksHandle);
2217  }
2226  {
2227  if (pListener->m_deviceDisconnectedCallbacksHandle != NULL)
2228  {
2229  return STATUS_ERROR;
2230  }
2231  return (Status)oniRegisterDeviceCallbacks(&pListener->m_deviceDisconnectedCallbacks, pListener, &pListener->m_deviceDisconnectedCallbacksHandle);
2232  }
2241  {
2242  if (pListener->m_deviceStateChangedCallbacksHandle != NULL)
2243  {
2244  return STATUS_ERROR;
2245  }
2246  return (Status)oniRegisterDeviceCallbacks(&pListener->m_deviceStateChangedCallbacks, pListener, &pListener->m_deviceStateChangedCallbacksHandle);
2247  }
2256  {
2257  oniUnregisterDeviceCallbacks(pListener->m_deviceConnectedCallbacksHandle);
2258  pListener->m_deviceConnectedCallbacksHandle = NULL;
2259  }
2268  {
2269  oniUnregisterDeviceCallbacks(pListener->m_deviceDisconnectedCallbacksHandle);
2270  pListener->m_deviceDisconnectedCallbacksHandle = NULL;
2271  }
2280  {
2281  oniUnregisterDeviceCallbacks(pListener->m_deviceStateChangedCallbacksHandle);
2282  pListener->m_deviceStateChangedCallbacksHandle = NULL;
2283  }
2284 
2293  static Status setLogOutputFolder(const char *strLogOutputFolder)
2294  {
2295  return (Status)oniSetLogOutputFolder(strLogOutputFolder);
2296  }
2297 
2307  static Status getLogFileName(char *strFileName, int nBufferSize)
2308  {
2309  return (Status)oniGetLogFileName(strFileName, nBufferSize);
2310  }
2311 
2320  static Status setLogMinSeverity(int nMinSeverity)
2321  {
2322  return(Status) oniSetLogMinSeverity(nMinSeverity);
2323  }
2324 
2333  static Status setLogConsoleOutput(bool bConsoleOutput)
2334  {
2335  return (Status)oniSetLogConsoleOutput(bConsoleOutput);
2336  }
2337 
2346  static Status setLogFileOutput(bool bFileOutput)
2347  {
2348  return (Status)oniSetLogFileOutput(bFileOutput);
2349  }
2350 
2351  #if ONI_PLATFORM == ONI_PLATFORM_ANDROID_ARM
2352 
2361  static Status setLogAndroidOutput(bool bAndroidOutput)
2362  {
2363  return (Status)oniSetLogAndroidOutput(bAndroidOutput);
2364  }
2365  #endif
2366 
2367 private:
2368  OpenNI()
2369  {
2370  }
2371 };
2372 
2409 {
2410 public:
2421  static Status convertWorldToDepth(const VideoStream& depthStream, float worldX, float worldY, float worldZ, int* pDepthX, int* pDepthY, DepthPixel* pDepthZ)
2422  {
2423  float depthX, depthY, depthZ;
2424  Status rc = (Status)oniCoordinateConverterWorldToDepth(depthStream._getHandle(), worldX, worldY, worldZ, &depthX, &depthY, &depthZ);
2425  *pDepthX = (int)depthX;
2426  *pDepthY = (int)depthY;
2427  *pDepthZ = (DepthPixel)depthZ;
2428  return rc;
2429  }
2430 
2441  static Status convertWorldToDepth(const VideoStream& depthStream, float worldX, float worldY, float worldZ, float* pDepthX, float* pDepthY, float* pDepthZ)
2442  {
2443  return (Status)oniCoordinateConverterWorldToDepth(depthStream._getHandle(), worldX, worldY, worldZ, pDepthX, pDepthY, pDepthZ);
2444  }
2445 
2456  static Status convertDepthToWorld(const VideoStream& depthStream, int depthX, int depthY, DepthPixel depthZ, float* pWorldX, float* pWorldY, float* pWorldZ)
2457  {
2458  return (Status)oniCoordinateConverterDepthToWorld(depthStream._getHandle(), float(depthX), float(depthY), float(depthZ), pWorldX, pWorldY, pWorldZ);
2459  }
2460 
2471  static Status convertDepthToWorld(const VideoStream& depthStream, float depthX, float depthY, float depthZ, float* pWorldX, float* pWorldY, float* pWorldZ)
2472  {
2473  return (Status)oniCoordinateConverterDepthToWorld(depthStream._getHandle(), depthX, depthY, depthZ, pWorldX, pWorldY, pWorldZ);
2474  }
2475 
2487  static Status convertDepthToColor(const VideoStream& depthStream, const VideoStream& colorStream, int depthX, int depthY, DepthPixel depthZ, int* pColorX, int* pColorY)
2488  {
2489  return (Status)oniCoordinateConverterDepthToColor(depthStream._getHandle(), colorStream._getHandle(), depthX, depthY, depthZ, pColorX, pColorY);
2490  }
2491 };
2492 
2508 {
2509 public:
2514  Recorder() : m_recorder(NULL)
2515  {
2516  }
2517 
2522  {
2523  destroy();
2524  }
2525 
2537  Status create(const char* fileName)
2538  {
2539  if (!isValid())
2540  {
2541  return (Status)oniCreateRecorder(fileName, &m_recorder);
2542  }
2543  return STATUS_ERROR;
2544  }
2545 
2552  bool isValid() const
2553  {
2554  return NULL != getHandle();
2555  }
2556 
2567  Status attach(VideoStream& stream, bool allowLossyCompression = false)
2568  {
2569  if (!isValid() || !stream.isValid())
2570  {
2571  return STATUS_ERROR;
2572  }
2573  return (Status)oniRecorderAttachStream(
2574  m_recorder,
2575  stream._getHandle(),
2576  allowLossyCompression);
2577  }
2578 
2586  {
2587  if (!isValid())
2588  {
2589  return STATUS_ERROR;
2590  }
2591  return (Status)oniRecorderStart(m_recorder);
2592  }
2593 
2597  void stop()
2598  {
2599  if (isValid())
2600  {
2601  oniRecorderStop(m_recorder);
2602  }
2603  }
2604 
2608  void destroy()
2609  {
2610  if (isValid())
2611  {
2612  oniRecorderDestroy(&m_recorder);
2613  }
2614  }
2615 
2616 private:
2617  Recorder(const Recorder&);
2618  Recorder& operator=(const Recorder&);
2619 
2623  OniRecorderHandle getHandle() const
2624  {
2625  return m_recorder;
2626  }
2627 
2628 
2629  OniRecorderHandle m_recorder;
2630 };
2631 
2632 // Implemetation
2633 Status VideoStream::create(const Device& device, SensorType sensorType)
2634 {
2635  OniStreamHandle streamHandle;
2636  Status rc = (Status)oniDeviceCreateStream(device._getHandle(), (OniSensorType)sensorType, &streamHandle);
2637  if (rc != STATUS_OK)
2638  {
2639  return rc;
2640  }
2641 
2642  m_isOwner = true;
2643  _setHandle(streamHandle);
2644 
2645  if (isPropertySupported(STREAM_PROPERTY_AUTO_WHITE_BALANCE) && isPropertySupported(STREAM_PROPERTY_AUTO_EXPOSURE))
2646  {
2647  m_pCameraSettings = new CameraSettings(this);
2648  }
2649 
2650  return STATUS_OK;
2651 }
2652 
2654 {
2655  if (!isValid())
2656  {
2657  return;
2658  }
2659 
2660  if (m_pCameraSettings != NULL)
2661  {
2662  delete m_pCameraSettings;
2663  m_pCameraSettings = NULL;
2664  }
2665 
2666  if (m_stream != NULL)
2667  {
2668  if(m_isOwner)
2669  oniStreamDestroy(m_stream);
2670  m_stream = NULL;
2671  }
2672 }
2673 
2674 Status Device::open(const char* uri)
2675 {
2676  //If we are not the owners, we stick with our own device
2677  if(!m_isOwner)
2678  {
2679  if(isValid()){
2680  return STATUS_OK;
2681  }else{
2682  return STATUS_OUT_OF_FLOW;
2683  }
2684  }
2685 
2686  OniDeviceHandle deviceHandle;
2687  Status rc = (Status)oniDeviceOpen(uri, &deviceHandle);
2688  if (rc != STATUS_OK)
2689  {
2690  return rc;
2691  }
2692 
2693  _setHandle(deviceHandle);
2694 
2695  return STATUS_OK;
2696 }
2697 
2698 Status Device::_openEx(const char* uri, const char* mode)
2699 {
2700  //If we are not the owners, we stick with our own device
2701  if(!m_isOwner)
2702  {
2703  if(isValid()){
2704  return STATUS_OK;
2705  }else{
2706  return STATUS_OUT_OF_FLOW;
2707  }
2708  }
2709 
2710  OniDeviceHandle deviceHandle;
2711  Status rc = (Status)oniDeviceOpenEx(uri, mode, &deviceHandle);
2712  if (rc != STATUS_OK)
2713  {
2714  return rc;
2715  }
2716 
2717  _setHandle(deviceHandle);
2718 
2719  return STATUS_OK;
2720 }
2721 
2722 Status Device::_setHandle(OniDeviceHandle deviceHandle)
2723 {
2724  if (m_device == NULL)
2725  {
2726  m_device = deviceHandle;
2727 
2728  clearSensors();
2729 
2730  oniDeviceGetInfo(m_device, &m_deviceInfo);
2731 
2732  if (isFile())
2733  {
2734  m_pPlaybackControl = new PlaybackControl(this);
2735  }
2736 
2737  // Read deviceInfo
2738  return STATUS_OK;
2739  }
2740 
2741  return STATUS_OUT_OF_FLOW;
2742 }
2743 
2745 {
2746  if (m_pPlaybackControl != NULL)
2747  {
2748  delete m_pPlaybackControl;
2749  m_pPlaybackControl = NULL;
2750  }
2751 
2752  if (m_device != NULL)
2753  {
2754  if(m_isOwner)
2755  {
2756  oniDeviceClose(m_device);
2757  }
2758 
2759  m_device = NULL;
2760  }
2761 }
2762 
2763 }
2764 
2765 #endif // OPENNI_H
bool isValid() const
Definition: OpenNI.h:1823
Status setAutoExposureEnabled(bool enabled)
Definition: OpenNI.h:1861
uint8_t v
Definition: OpenNI.h:80
Status start()
Definition: OpenNI.h:2585
~Array()
Definition: OpenNI.h:137
DeviceState
Definition: OniEnums.h:67
Definition: OniEnums.h:33
uint8_t y1
Definition: OpenNI.h:93
Status setVideoMode(const VideoMode &videoMode)
Definition: OpenNI.h:973
PixelFormat
Definition: OniEnums.h:50
uint8_t y2
Definition: OpenNI.h:97
static Status addDeviceDisconnectedListener(DeviceDisconnectedListener *pListener)
Definition: OpenNI.h:2225
virtual ~DeviceDisconnectedListener()
Definition: OpenNI.h:2038
SensorType getSensorType() const
Definition: OpenNI.h:338
int maintenance
Definition: OpenNI.h:52
float getVerticalFieldOfView() const
Definition: OpenNI.h:1117
Recorder()
Definition: OpenNI.h:2514
virtual ~DeviceConnectedListener()
Definition: OpenNI.h:1983
bool isValid() const
Definition: OpenNI.h:595
int getWidth() const
Definition: OpenNI.h:540
const SensorInfo & getSensorInfo() const
Definition: OpenNI.h:788
Status create(const Device &device, SensorType sensorType)
Definition: OpenNI.h:2633
Status start()
Definition: OpenNI.h:796
const VideoMode & getVideoMode() const
Definition: OpenNI.h:502
float getSpeed() const
Definition: OpenNI.h:1712
static Status convertDepthToWorld(const VideoStream &depthStream, int depthX, int depthY, DepthPixel depthZ, float *pWorldX, float *pWorldY, float *pWorldZ)
Definition: OpenNI.h:2456
virtual void onDeviceStateChanged(const DeviceInfo *, DeviceState)=0
uint8_t u
Definition: OpenNI.h:95
bool getDepthColorSyncEnabled()
Definition: OpenNI.h:1552
int getStrideInBytes() const
Definition: OpenNI.h:587
Status invoke(int propertyId, T &value)
Definition: OpenNI.h:1623
void setPixelFormat(PixelFormat format)
Definition: OpenNI.h:286
static void enumerateDevices(Array< DeviceInfo > *deviceInfoList)
Definition: OpenNI.h:2158
int getHeight() const
Definition: OpenNI.h:550
Array()
Definition: OpenNI.h:123
VideoMode()
Definition: OpenNI.h:228
bool isValid() const
Definition: OpenNI.h:1914
virtual void freeFrameBuffer(void *data)=0
int getFps() const
Definition: OpenNI.h:278
static Status addDeviceConnectedListener(DeviceConnectedListener *pListener)
Definition: OpenNI.h:2210
Status setMirroringEnabled(bool isEnabled)
Definition: OpenNI.h:1097
bool isCommandSupported(int commandId) const
Definition: OpenNI.h:1209
Status getProperty(int propertyId, T *value) const
Definition: OpenNI.h:1149
Status setAutoWhiteBalanceEnabled(bool enabled)
Definition: OpenNI.h:1865
static Status setLogFileOutput(bool bFileOutput)
Definition: OpenNI.h:2346
static Status convertDepthToColor(const VideoStream &depthStream, const VideoStream &colorStream, int depthX, int depthY, DepthPixel depthZ, int *pColorX, int *pColorY)
Definition: OpenNI.h:2487
static Status setLogConsoleOutput(bool bConsoleOutput)
Definition: OpenNI.h:2333
Device()
Definition: OpenNI.h:1266
static const char * getExtendedError()
Definition: OpenNI.h:2149
void setResolution(int resolutionX, int resolutionY)
Definition: OpenNI.h:295
~Device()
Definition: OpenNI.h:1284
bool hasSensor(SensorType sensorType)
Definition: OpenNI.h:1351
Definition: OpenNI.h:389
Definition: OpenNI.h:1678
Status setGain(int gain)
Definition: OpenNI.h:1885
SensorType
Definition: OniEnums.h:41
Status invoke(int commandId, T &value)
Definition: OpenNI.h:1199
virtual ~DeviceStateChangedListener()
Definition: OpenNI.h:2086
Status setProperty(int propertyId, const T &value)
Definition: OpenNI.h:1134
static Status setLogMinSeverity(int nMinSeverity)
Definition: OpenNI.h:2320
Definition: OpenNI.h:90
int getCropOriginY() const
Definition: OpenNI.h:577
Status attach(VideoStream &stream, bool allowLossyCompression=false)
Definition: OpenNI.h:2567
Definition: OpenNI.h:73
Definition: OniEnums.h:31
Status
Definition: OniEnums.h:28
virtual void * allocateFrameBuffer(int size)=0
uint8_t r
Definition: OpenNI.h:61
int major
Definition: OpenNI.h:48
void setFps(int fps)
Definition: OpenNI.h:307
~VideoStream()
Definition: OpenNI.h:748
Status getProperty(int propertyId, void *data, int *dataSize) const
Definition: OpenNI.h:922
ImageRegistrationMode
Definition: OniEnums.h:75
Definition: OpenNI.h:1953
virtual void onNewFrame(VideoStream &)=0
Status readFrame(VideoFrameRef *pFrame)
Definition: OpenNI.h:829
Definition: OpenNI.h:2507
virtual void onDeviceConnected(const DeviceInfo *)=0
Status resetCropping()
Definition: OpenNI.h:1070
bool getCroppingEnabled() const
Definition: OpenNI.h:559
Status setSpeed(float speed)
Definition: OpenNI.h:1733
int getExposure()
Definition: OpenNI.h:1903
Definition: OniEnums.h:35
VideoStream()
Definition: OpenNI.h:732
uint16_t DepthPixel
Definition: OpenNI.h:38
static void removeDeviceConnectedListener(DeviceConnectedListener *pListener)
Definition: OpenNI.h:2255
VideoFrameRef(const VideoFrameRef &other)
Definition: OpenNI.h:448
uint8_t y2
Definition: OpenNI.h:82
static void shutdown()
Definition: OpenNI.h:2123
int getMaxPixelValue() const
Definition: OpenNI.h:983
CameraSettings * getCameraSettings()
Definition: OpenNI.h:910
void close()
Definition: OpenNI.h:2744
bool getCropping(int *pOriginX, int *pOriginY, int *pWidth, int *pHeight) const
Definition: OpenNI.h:1027
virtual ~NewFrameListener()
Definition: OpenNI.h:682
Status setCropping(int originX, int originY, int width, int height)
Definition: OpenNI.h:1055
Definition: OniEnums.h:36
int getSize() const
Definition: OpenNI.h:146
int build
Definition: OpenNI.h:54
Status create(const char *fileName)
Definition: OpenNI.h:2537
Definition: OpenNI.h:662
bool getMirroringEnabled() const
Definition: OpenNI.h:1081
virtual ~FrameAllocator()
Definition: OpenNI.h:708
uint8_t u
Definition: OpenNI.h:76
friend class Device
Definition: OpenNI.h:1845
static Version getVersion()
Definition: OpenNI.h:2131
Definition: OpenNI.h:45
Definition: OpenNI.h:423
static Status convertDepthToWorld(const VideoStream &depthStream, float depthX, float depthY, float depthZ, float *pWorldX, float *pWorldY, float *pWorldZ)
Definition: OpenNI.h:2471
Definition: OpenNI.h:331
VideoMode & operator=(const VideoMode &other)
Definition: OpenNI.h:247
int getGain()
Definition: OpenNI.h:1893
bool isCroppingSupported() const
Definition: OpenNI.h:1014
int getMinPixelValue() const
Definition: OpenNI.h:999
static Status addDeviceStateChangedListener(DeviceStateChangedListener *pListener)
Definition: OpenNI.h:2240
uint8_t y1
Definition: OpenNI.h:78
VideoMode getVideoMode() const
Definition: OpenNI.h:958
uint16_t getUsbProductId() const
Definition: OpenNI.h:404
Definition: OpenNI.h:1259
Definition: OniEnums.h:77
~PlaybackControl()
Definition: OpenNI.h:1687
static const int TIMEOUT_FOREVER
Definition: OniEnums.h:82
int getResolutionX() const
Definition: OpenNI.h:266
uint16_t Grayscale16Pixel
Definition: OpenNI.h:41
bool isValid() const
Definition: OpenNI.h:757
static Status setLogOutputFolder(const char *strLogOutputFolder)
Definition: OpenNI.h:2293
Array(const T *data, int count)
Definition: OpenNI.h:132
void release()
Definition: OpenNI.h:604
void removeNewFrameListener(NewFrameListener *pListener)
Definition: OpenNI.h:864
VideoMode(const VideoMode &other)
Definition: OpenNI.h:236
VideoFrameRef()
Definition: OpenNI.h:430
Status setDepthColorSyncEnabled(bool isEnabled)
Definition: OpenNI.h:1536
static Status convertWorldToDepth(const VideoStream &depthStream, float worldX, float worldY, float worldZ, float *pDepthX, float *pDepthY, float *pDepthZ)
Definition: OpenNI.h:2441
Status setProperty(int propertyId, const T &value)
Definition: OpenNI.h:1568
bool getAutoExposureEnabled() const
Definition: OpenNI.h:1870
Definition: OpenNI.h:705
bool getAutoWhiteBalanceEnabled() const
Definition: OpenNI.h:1877
Status invoke(int commandId, void *data, int dataSize)
Definition: OpenNI.h:1608
int getResolutionY() const
Definition: OpenNI.h:272
Device(OniDeviceHandle handle)
Definition: OpenNI.h:1275
static void removeDeviceStateChangedListener(DeviceStateChangedListener *pListener)
Definition: OpenNI.h:2279
bool isPropertySupported(int propertyId) const
Definition: OpenNI.h:1160
bool isImageRegistrationModeSupported(ImageRegistrationMode mode) const
Definition: OpenNI.h:1467
static Status waitForAnyStream(VideoStream **pStreams, int streamCount, int *pReadyStreamIndex, int timeout=TIMEOUT_FOREVER)
Definition: OpenNI.h:2175
const char * getVendor() const
Definition: OpenNI.h:398
VideoFrameRef & operator=(const VideoFrameRef &other)
Definition: OpenNI.h:458
bool isFile() const
Definition: OpenNI.h:1521
Status setExposure(int exposure)
Definition: OpenNI.h:1889
const T & operator[](int index) const
Definition: OpenNI.h:151
Status getProperty(int propertyId, T *value) const
Definition: OpenNI.h:1583
uint64_t getTimestamp() const
Definition: OpenNI.h:514
static Status convertWorldToDepth(const VideoStream &depthStream, float worldX, float worldY, float worldZ, int *pDepthX, int *pDepthY, DepthPixel *pDepthZ)
Definition: OpenNI.h:2421
virtual void onDeviceDisconnected(const DeviceInfo *)=0
int getDataSize() const
Definition: OpenNI.h:469
bool isCommandSupported(int commandId) const
Definition: OpenNI.h:1633
int minor
Definition: OpenNI.h:50
Status open(const char *uri)
Definition: OpenNI.h:2674
Status invoke(int commandId, void *data, int dataSize)
Definition: OpenNI.h:1179
int getCropOriginX() const
Definition: OpenNI.h:568
PixelFormat getPixelFormat() const
Definition: OpenNI.h:260
Status getProperty(int propertyId, void *data, int *dataSize) const
Definition: OpenNI.h:1439
const DeviceInfo & getDeviceInfo() const
Definition: OpenNI.h:1339
DeviceConnectedListener()
Definition: OpenNI.h:1975
uint8_t g
Definition: OpenNI.h:63
DeviceDisconnectedListener()
Definition: OpenNI.h:2030
int getNumberOfFrames(const VideoStream &stream) const
Definition: OpenNI.h:1812
void stop()
Definition: OpenNI.h:809
Status setFrameBuffersAllocator(FrameAllocator *pAllocator)
Definition: OpenNI.h:880
DeviceStateChangedListener()
Definition: OpenNI.h:2078
Status setImageRegistrationMode(ImageRegistrationMode mode)
Definition: OpenNI.h:1503
const SensorInfo * getSensorInfo(SensorType sensorType)
Definition: OpenNI.h:1386
float getHorizontalFieldOfView() const
Definition: OpenNI.h:1106
const char * getUri() const
Definition: OpenNI.h:396
bool isPropertySupported(int propertyId) const
Definition: OpenNI.h:1594
const Array< VideoMode > & getSupportedVideoModes() const
Definition: OpenNI.h:347
bool isValid() const
Definition: OpenNI.h:2552
~VideoFrameRef()
Definition: OpenNI.h:438
uint8_t v
Definition: OpenNI.h:99
~Recorder()
Definition: OpenNI.h:2521
VideoStream(OniStreamHandle handle)
Definition: OpenNI.h:739
Definition: OpenNI.h:220
PlaybackControl * getPlaybackControl()
Definition: OpenNI.h:1426
static void removeDeviceDisconnectedListener(DeviceDisconnectedListener *pListener)
Definition: OpenNI.h:2267
uint16_t getUsbVendorId() const
Definition: OpenNI.h:402
void destroy()
Definition: OpenNI.h:2653
NewFrameListener()
Definition: OpenNI.h:678
Status setProperty(int propertyId, const void *data, int dataSize)
Definition: OpenNI.h:1455
void destroy()
Definition: OpenNI.h:2608
Definition: OpenNI.h:2408
Definition: OpenNI.h:1857
Status setRepeatEnabled(bool repeat)
Definition: OpenNI.h:1772
Definition: OniEnums.h:30
const char * getName() const
Definition: OpenNI.h:400
Definition: OpenNI.h:58
Definition: OpenNI.h:117
int getFrameIndex() const
Definition: OpenNI.h:529
bool getRepeatEnabled() const
Definition: OpenNI.h:1747
ImageRegistrationMode getImageRegistrationMode() const
Definition: OpenNI.h:1479
const void * getData() const
Definition: OpenNI.h:479
Status setProperty(int propertyId, const void *data, int dataSize)
Definition: OpenNI.h:942
bool isValid() const
Definition: OpenNI.h:1512
static Status initialize()
Definition: OpenNI.h:2114
Definition: OniEnums.h:34
static Status getLogFileName(char *strFileName, int nBufferSize)
Definition: OpenNI.h:2307
void stop()
Definition: OpenNI.h:2597
SensorType getSensorType() const
Definition: OpenNI.h:490
uint8_t b
Definition: OpenNI.h:65
static const _NullString ANY_DEVICE
Definition: OpenNI.h:110
Status addNewFrameListener(NewFrameListener *pListener)
Definition: OpenNI.h:850
Status seek(const VideoStream &stream, int frameIndex)
Definition: OpenNI.h:1792