OpenNI 1.3.2
XnCppWrapper.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * OpenNI 1.1 Alpha *
4 * Copyright (C) 2011 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * OpenNI is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published *
10 * by the Free Software Foundation, either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * OpenNI is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20 * *
21 ****************************************************************************/
22 #ifndef __XN_CPP_WRAPPER_H__
23 #define __XN_CPP_WRAPPER_H__
24 
25 //---------------------------------------------------------------------------
26 // Includes
27 //---------------------------------------------------------------------------
28 #include <XnOpenNI.h>
29 #include <XnCodecIDs.h>
30 
31 //---------------------------------------------------------------------------
32 // Types
33 //---------------------------------------------------------------------------
34 namespace xn
35 {
36  //---------------------------------------------------------------------------
37  // Forward Declarations
38  //---------------------------------------------------------------------------
39  class ProductionNode;
40  class EnumerationErrors;
41  class NodeInfo;
42  class NodeInfoList;
43  class Context;
44  class Query;
45  class Generator;
46 
52  //---------------------------------------------------------------------------
53  // Types
54  //---------------------------------------------------------------------------
55 
62  typedef void (XN_CALLBACK_TYPE* StateChangedHandler)(ProductionNode& node, void* pCookie);
63 
64  //---------------------------------------------------------------------------
65  // Internal stuff
66  //---------------------------------------------------------------------------
67  typedef XnStatus (*_XnRegisterStateChangeFuncPtr)(XnNodeHandle hNode, XnStateChangedHandler handler, void* pCookie, XnCallbackHandle* phCallback);
68  typedef void (*_XnUnregisterStateChangeFuncPtr)(XnNodeHandle hNode, XnCallbackHandle hCallback);
69 
70  static XnStatus _RegisterToStateChange(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback);
71  static void _UnregisterFromStateChange(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, XnCallbackHandle hCallback);
72 
73  //---------------------------------------------------------------------------
74  // Some Utilities
75  //---------------------------------------------------------------------------
76  class Version
77  {
78  public:
79  Version(const XnVersion& version) : m_version(version) {}
80  Version(XnUInt8 nMajor, XnUInt8 nMinor, XnUInt16 nMaintenance, XnUInt32 nBuild)
81  {
82  m_version.nMajor = nMajor;
83  m_version.nMinor = nMinor;
84  m_version.nMaintenance = nMaintenance;
85  m_version.nBuild = nBuild;
86  }
87 
88  bool operator==(const Version& other) const
89  {
90  return (xnVersionCompare(&m_version, &other.m_version) == 0);
91  }
92  bool operator!=(const Version& other) const
93  {
94  return (xnVersionCompare(&m_version, &other.m_version) != 0);
95  }
96  bool operator<(const Version& other) const
97  {
98  return (xnVersionCompare(&m_version, &other.m_version) < 0);
99  }
100  bool operator<=(const Version& other) const
101  {
102  return (xnVersionCompare(&m_version, &other.m_version) <= 0);
103  }
104  bool operator>(const Version& other) const
105  {
106  return (xnVersionCompare(&m_version, &other.m_version) > 0);
107  }
108  bool operator>=(const Version& other) const
109  {
110  return (xnVersionCompare(&m_version, &other.m_version) >= 0);
111  }
112  private:
113  XnVersion m_version;
114  };
115 
116  //---------------------------------------------------------------------------
117  // Meta Data
118  //---------------------------------------------------------------------------
119 
125  {
126  public:
132  inline OutputMetaData(const XnUInt8** ppData) : m_pAllocatedData(NULL), m_ppData(ppData), m_nAllocatedSize(0)
133  {
134  xnOSMemSet(&m_output, 0, sizeof(XnOutputMetaData));
135  }
136 
140  virtual ~OutputMetaData() { Free(); }
141 
143  inline XnUInt64 Timestamp() const { return m_output.nTimestamp; }
145  inline XnUInt64& Timestamp() { return m_output.nTimestamp; }
146 
148  inline XnUInt32 FrameID() const { return m_output.nFrameID; }
150  inline XnUInt32& FrameID() { return m_output.nFrameID; }
151 
153  inline XnUInt32 DataSize() const { return m_output.nDataSize; }
155  inline XnUInt32& DataSize() { return m_output.nDataSize; }
156 
158  inline XnBool IsDataNew() const { return m_output.bIsNew; }
160  inline XnBool& IsDataNew() { return m_output.bIsNew; }
161 
163  inline const XnOutputMetaData* GetUnderlying() const { return &m_output; }
165  inline XnOutputMetaData* GetUnderlying() { return &m_output; }
166 
168  inline const XnUInt8* Data() const { return *m_ppData; }
170  inline const XnUInt8*& Data() { return *m_ppData; }
172  inline XnUInt8* WritableData()
173  {
175  return m_pAllocatedData;
176  }
177 
184  XnStatus AllocateData(XnUInt32 nBytes)
185  {
186  if (nBytes > m_nAllocatedSize)
187  {
188  // reallocate
189  XnUInt8* pData = (XnUInt8*)xnOSMallocAligned(nBytes, XN_DEFAULT_MEM_ALIGN);
190  XN_VALIDATE_ALLOC_PTR(pData);
191 
192  // allocation succeeded, replace
193  Free();
194  m_pAllocatedData = pData;
195  m_nAllocatedSize = nBytes;
196  }
197 
198  DataSize() = nBytes;
199  *m_ppData = m_pAllocatedData;
200 
201  return XN_STATUS_OK;
202  }
203 
207  void Free()
208  {
209  if (m_nAllocatedSize != 0)
210  {
212  m_pAllocatedData = NULL;
213  m_nAllocatedSize = 0;
214  }
215  }
216 
222  {
223  XnStatus nRetVal = XN_STATUS_OK;
224 
225  // check data isn't already writable
226  if (Data() != m_pAllocatedData || DataSize() > m_nAllocatedSize)
227  {
228  const XnUInt8* pOrigData = *m_ppData;
229 
230  nRetVal = AllocateData(DataSize());
231  XN_IS_STATUS_OK(nRetVal);
232 
233  if (pOrigData != NULL)
234  {
235  xnOSMemCopy(m_pAllocatedData, pOrigData, DataSize());
236  }
237  else
238  {
240  }
241  }
242 
243  return (XN_STATUS_OK);
244  }
245 
246  protected:
248 
249  private:
250  XnOutputMetaData m_output;
251 
252  const XnUInt8** m_ppData;
253  XnUInt32 m_nAllocatedSize;
254  };
255 
261  {
262  public:
269  inline MapMetaData(XnPixelFormat format, const XnUInt8** ppData) : OutputMetaData(ppData)
270  {
271  xnOSMemSet(&m_map, 0, sizeof(XnMapMetaData));
273  m_map.PixelFormat = format;
274  }
275 
277  inline XnUInt32 XRes() const { return m_map.Res.X; }
279  inline XnUInt32& XRes() { return m_map.Res.X; }
280 
282  inline XnUInt32 YRes() const { return m_map.Res.Y; }
284  inline XnUInt32& YRes() { return m_map.Res.Y; }
285 
287  inline XnUInt32 XOffset() const { return m_map.Offset.X; }
289  inline XnUInt32& XOffset() { return m_map.Offset.X; }
290 
292  inline XnUInt32 YOffset() const { return m_map.Offset.Y; }
294  inline XnUInt32& YOffset() { return m_map.Offset.Y; }
295 
297  inline XnUInt32 FullXRes() const { return m_map.FullRes.X; }
299  inline XnUInt32& FullXRes() { return m_map.FullRes.X; }
300 
302  inline XnUInt32 FullYRes() const { return m_map.FullRes.Y; }
304  inline XnUInt32& FullYRes() { return m_map.FullRes.Y; }
305 
307  inline XnUInt32 FPS() const { return m_map.nFPS; }
309  inline XnUInt32& FPS() { return m_map.nFPS; }
310 
312  inline XnPixelFormat PixelFormat() const { return m_map.PixelFormat; }
313 
315  inline const XnMapMetaData* GetUnderlying() const { return &m_map; }
317  inline XnMapMetaData* GetUnderlying() { return &m_map; }
318 
320  inline XnUInt32 BytesPerPixel() const
321  {
322  switch (PixelFormat())
323  {
325  return sizeof(XnRGB24Pixel);
327  return sizeof(XnYUV422DoublePixel)/2;
329  return sizeof(XnGrayscale8Pixel);
331  return sizeof(XnGrayscale16Pixel);
333  return 2;
334  default:
335  XN_ASSERT(FALSE);
336  return 0;
337  }
338  }
339 
346  XnStatus AllocateData(XnUInt32 nXRes, XnUInt32 nYRes)
347  {
348  XnStatus nRetVal = XN_STATUS_OK;
349 
350  XnUInt32 nSize = nXRes * nYRes * BytesPerPixel();
351  nRetVal = OutputMetaData::AllocateData(nSize);
352  XN_IS_STATUS_OK(nRetVal);
353 
354  FullXRes() = XRes() = nXRes;
355  FullYRes() = YRes() = nYRes;
356  XOffset() = YOffset() = 0;
357 
358  return (XN_STATUS_OK);
359  }
360 
369  XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnUInt8* pExternalBuffer)
370  {
371  XnStatus nRetVal = XN_STATUS_OK;
372 
373  if (pExternalBuffer == NULL)
374  {
375  nRetVal = AllocateData(nXRes, nYRes);
376  XN_IS_STATUS_OK(nRetVal);
377  }
378  else
379  {
380  FullXRes() = XRes() = nXRes;
381  FullYRes() = YRes() = nYRes;
382  XOffset() = YOffset() = 0;
383  Data() = pExternalBuffer;
384  DataSize() = nXRes * nYRes * BytesPerPixel();
385  }
386 
387  return (XN_STATUS_OK);
388  }
389 
390  protected:
392 
393  private:
394  // block copy ctor and assignment operator
395  MapMetaData& operator=(const MapMetaData&);
396  inline MapMetaData(const MapMetaData& other);
397 
398  // Members
399  XnMapMetaData m_map;
400  };
401 
402 /* Declares a map data accessor class */
403 #define _XN_DECLARE_MAP_DATA_CLASS(_name, _pixelType) \
404  class _name \
405  { \
406  public: \
407  inline _name(_pixelType*& pData, XnUInt32& nXRes, XnUInt32 &nYRes) : \
408  m_pData(pData), m_nXRes(nXRes), m_nYRes(nYRes) {} \
409  \
410  inline XnUInt32 XRes() const { return m_nXRes; } \
411  inline XnUInt32 YRes() const { return m_nYRes; } \
412  \
413  inline const _pixelType& operator[](XnUInt32 nIndex) const \
414  { \
415  XN_ASSERT(nIndex < (m_nXRes * m_nYRes)); \
416  return m_pData[nIndex]; \
417  } \
418  inline _pixelType& operator[](XnUInt32 nIndex) \
419  { \
420  XN_ASSERT(nIndex < (m_nXRes *m_nYRes)); \
421  return m_pData[nIndex]; \
422  } \
423  \
424  inline const _pixelType& operator()(XnUInt32 x, XnUInt32 y) const \
425  { \
426  XN_ASSERT(x < m_nXRes && y < m_nYRes); \
427  return m_pData[y*m_nXRes + x]; \
428  } \
429  inline _pixelType& operator()(XnUInt32 x, XnUInt32 y) \
430  { \
431  XN_ASSERT(x < m_nXRes && y < m_nYRes); \
432  return m_pData[y*m_nXRes + x]; \
433  } \
434  \
435  private: \
436  /* block copy ctor and assignment operator */ \
437  _name(const _name& other); \
438  _name& operator=(const _name&); \
439  \
440  _pixelType*& m_pData; \
441  XnUInt32& m_nXRes; \
442  XnUInt32& m_nYRes; \
443  };
444 
445  _XN_DECLARE_MAP_DATA_CLASS(DepthMap, XnDepthPixel);
446  _XN_DECLARE_MAP_DATA_CLASS(ImageMap, XnUInt8);
447  _XN_DECLARE_MAP_DATA_CLASS(RGB24Map, XnRGB24Pixel);
448  _XN_DECLARE_MAP_DATA_CLASS(Grayscale16Map, XnGrayscale16Pixel);
449  _XN_DECLARE_MAP_DATA_CLASS(Grayscale8Map, XnGrayscale8Pixel);
450  _XN_DECLARE_MAP_DATA_CLASS(IRMap, XnIRPixel);
451  _XN_DECLARE_MAP_DATA_CLASS(LabelMap, XnLabel);
452 
457  class DepthMetaData : public MapMetaData
458  {
459  public:
463  inline DepthMetaData() :
464  MapMetaData(XN_PIXEL_FORMAT_GRAYSCALE_16_BIT, (const XnUInt8**)&m_depth.pData),
465  m_depthMap(const_cast<XnDepthPixel*&>(m_depth.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
466  m_writableDepthMap((XnDepthPixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
467  {
468  xnOSMemSet(&m_depth, 0, sizeof(XnDepthMetaData));
469  m_depth.pMap = MapMetaData::GetUnderlying();
470  }
471 
477  inline void InitFrom(const DepthMetaData& other)
478  {
479  xnCopyDepthMetaData(&m_depth, &other.m_depth);
480  }
481 
491  inline XnStatus InitFrom(const DepthMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, const XnDepthPixel* pExternalBuffer)
492  {
493  InitFrom(other);
494  return ReAdjust(nXRes, nYRes, pExternalBuffer);
495  }
496 
503  {
504  // copy props
505  InitFrom(other);
506  // and make a copy of the data (this will allocate and copy data)
507  return MakeDataWritable();
508  }
509 
511  XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnDepthPixel* pExternalBuffer = NULL)
512  {
513  return MapMetaData::ReAdjust(nXRes, nYRes, (const XnUInt8*)pExternalBuffer);
514  }
515 
517  inline XnDepthPixel ZRes() const { return m_depth.nZRes; }
519  inline XnDepthPixel& ZRes() { return m_depth.nZRes; }
520 
522  inline const XnDepthPixel* Data() const { return (const XnDepthPixel*)MapMetaData::Data(); }
524  inline const XnDepthPixel*& Data() { return (const XnDepthPixel*&)MapMetaData::Data(); }
527 
529  inline const xn::DepthMap& DepthMap() const { return m_depthMap; }
531  inline xn::DepthMap& WritableDepthMap()
532  {
534  return m_writableDepthMap;
535  }
536 
542  inline const XnDepthPixel& operator[](XnUInt32 nIndex) const
543  {
544  XN_ASSERT(nIndex < (XRes()*YRes()));
545  return Data()[nIndex];
546  }
547 
554  inline const XnDepthPixel& operator()(XnUInt32 x, XnUInt32 y) const
555  {
556  XN_ASSERT(x < XRes() && y < YRes());
557  return Data()[y*XRes() + x];
558  }
559 
561  inline const XnDepthMetaData* GetUnderlying() const { return &m_depth; }
563  inline XnDepthMetaData* GetUnderlying() { return &m_depth; }
564 
565  private:
566  // block copy ctor and assignment operator (because we can't return errors in those)
567  DepthMetaData(const DepthMetaData& other);
568  DepthMetaData& operator=(const DepthMetaData&);
569 
570  XnDepthMetaData m_depth;
571  const xn::DepthMap m_depthMap;
572  xn::DepthMap m_writableDepthMap;
573  };
574 
579  class ImageMetaData : public MapMetaData
580  {
581  public:
583  inline ImageMetaData() :
584  MapMetaData(XN_PIXEL_FORMAT_RGB24, &m_image.pData),
585  m_imageMap(const_cast<XnUInt8*&>(m_image.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
586  m_writableImageMap((XnUInt8*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
587  m_rgb24Map((XnRGB24Pixel*&)m_image.pData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
588  m_writableRgb24Map((XnRGB24Pixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
589  m_gray16Map((XnGrayscale16Pixel*&)m_image.pData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
590  m_writableGray16Map((XnGrayscale16Pixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
591  m_gray8Map((XnGrayscale8Pixel*&)m_image.pData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
592  m_writableGray8Map((XnGrayscale8Pixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
593  {
594  xnOSMemSet(&m_image, 0, sizeof(XnImageMetaData));
595  m_image.pMap = MapMetaData::GetUnderlying();
596  }
597 
603  inline void InitFrom(const ImageMetaData& other)
604  {
605  xnCopyImageMetaData(&m_image, &other.m_image);
606  }
607 
618  inline XnStatus InitFrom(const ImageMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, XnPixelFormat format, const XnUInt8* pExternalBuffer)
619  {
620  InitFrom(other);
621  XnStatus nRetVal = ReAdjust(nXRes, nYRes, format, pExternalBuffer);
622  XN_IS_STATUS_OK(nRetVal);
623  PixelFormat() = format;
624  return XN_STATUS_OK;
625  }
626 
634  inline XnStatus AllocateData(XnUInt32 nXRes, XnUInt32 nYRes, XnPixelFormat format)
635  {
636  XnPixelFormat origFormat = PixelFormat();
637  PixelFormat() = format;
638  XnStatus nRetVal = MapMetaData::AllocateData(nXRes, nYRes);
639  if (nRetVal != XN_STATUS_OK)
640  {
641  PixelFormat() = origFormat;
642  return (nRetVal);
643  }
644 
645  return XN_STATUS_OK;
646  }
647 
649  inline XnStatus CopyFrom(const ImageMetaData& other)
650  {
651  // copy props
652  xnCopyImageMetaData(&m_image, &other.m_image);
653  // and make a copy of the data (this will allocate and copy data)
654  return MakeDataWritable();
655  }
656 
666  XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, XnPixelFormat format, const XnUInt8* pExternalBuffer = NULL)
667  {
668  XnPixelFormat origFormat = PixelFormat();
669  PixelFormat() = format;
670  XnStatus nRetVal = MapMetaData::ReAdjust(nXRes, nYRes, pExternalBuffer);
671  if (nRetVal != XN_STATUS_OK)
672  {
673  PixelFormat() = origFormat;
674  return (nRetVal);
675  }
676 
677  return XN_STATUS_OK;
678  }
679 
684 
686  inline XnUInt8* WritableData() { return MapMetaData::WritableData(); }
687 
689  inline const XnRGB24Pixel* RGB24Data() const { return (const XnRGB24Pixel*)MapMetaData::Data(); }
691  inline const XnRGB24Pixel*& RGB24Data() { return (const XnRGB24Pixel*&)MapMetaData::Data(); }
694 
696  inline const XnYUV422DoublePixel* YUV422Data() const { return (const XnYUV422DoublePixel*)MapMetaData::Data(); }
698  inline const XnYUV422DoublePixel*& YUV422Data() { return (const XnYUV422DoublePixel*&)MapMetaData::Data(); }
701 
703  inline const XnGrayscale8Pixel* Grayscale8Data() const { return (const XnGrayscale8Pixel*)MapMetaData::Data(); }
705  inline const XnGrayscale8Pixel*& Grayscale8Data() { return (const XnGrayscale8Pixel*&)MapMetaData::Data(); }
708 
710  inline const XnGrayscale16Pixel* Grayscale16Data() const { return (const XnGrayscale16Pixel*)MapMetaData::Data(); }
715 
717  inline const xn::ImageMap& ImageMap() const { return m_imageMap; }
719  inline xn::ImageMap& WritableImageMap() { MakeDataWritable(); return m_writableImageMap; }
720 
722  inline const xn::RGB24Map& RGB24Map() const { return m_rgb24Map; }
724  inline xn::RGB24Map& WritableRGB24Map() { MakeDataWritable(); return m_writableRgb24Map; }
725 
727  inline const xn::Grayscale8Map& Grayscale8Map() const { return m_gray8Map; }
729  inline xn::Grayscale8Map& WritableGrayscale8Map() { MakeDataWritable(); return m_writableGray8Map; }
730 
732  inline const xn::Grayscale16Map& Grayscale16Map() const { return m_gray16Map; }
734  inline xn::Grayscale16Map& WritableGrayscale16Map() { MakeDataWritable(); return m_writableGray16Map; }
735 
737  inline const XnImageMetaData* GetUnderlying() const { return &m_image; }
739  inline XnImageMetaData* GetUnderlying() { return &m_image; }
740 
741  private:
742  // block copy ctor and assignment operator
743  ImageMetaData(const ImageMetaData& other);
744  ImageMetaData& operator=(const ImageMetaData&);
745 
746  XnImageMetaData m_image;
747  const xn::ImageMap m_imageMap;
748  xn::ImageMap m_writableImageMap;
749  const xn::RGB24Map m_rgb24Map;
750  xn::RGB24Map m_writableRgb24Map;
751  const xn::Grayscale16Map m_gray16Map;
752  xn::Grayscale16Map m_writableGray16Map;
753  const xn::Grayscale8Map m_gray8Map;
754  xn::Grayscale8Map m_writableGray8Map;
755  };
756 
761  class IRMetaData : public MapMetaData
762  {
763  public:
765  inline IRMetaData() :
766  MapMetaData(XN_PIXEL_FORMAT_GRAYSCALE_16_BIT, (const XnUInt8**)&m_ir.pData),
767  m_irMap(const_cast<XnIRPixel*&>(m_ir.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
768  m_writableIRMap((XnIRPixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
769  {
770  xnOSMemSet(&m_ir, 0, sizeof(XnIRMetaData));
772  }
773 
779  inline void InitFrom(const IRMetaData& other)
780  {
781  xnCopyIRMetaData(&m_ir, &other.m_ir);
782  }
783 
785  inline XnStatus InitFrom(const IRMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, const XnIRPixel* pExternalBuffer)
786  {
787  InitFrom(other);
788  return ReAdjust(nXRes, nYRes, pExternalBuffer);
789  }
790 
793  {
794  // copy props
795  xnCopyIRMetaData(&m_ir, &other.m_ir);
796  // and make a copy of the data (this will allocate and copy data)
797  return MakeDataWritable();
798  }
799 
801  XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnIRPixel* pExternalBuffer = NULL)
802  {
803  return MapMetaData::ReAdjust(nXRes, nYRes, (const XnUInt8*)pExternalBuffer);
804  }
805 
807  inline const XnIRPixel* Data() const { return (const XnIRPixel*)MapMetaData::Data(); }
809  inline const XnIRPixel*& Data() { return (const XnIRPixel*&)MapMetaData::Data(); }
812 
814  inline const xn::IRMap& IRMap() const { return m_irMap; }
816  inline xn::IRMap& WritableIRMap() { MakeDataWritable(); return m_writableIRMap; }
817 
819  inline const XnIRMetaData* GetUnderlying() const { return &m_ir; }
821  inline XnIRMetaData* GetUnderlying() { return &m_ir; }
822 
823  private:
824  // block copy ctor and assignment operator
825  IRMetaData(const IRMetaData& other);
826  IRMetaData& operator=(const IRMetaData&);
827 
828  XnIRMetaData m_ir;
829  const xn::IRMap m_irMap;
830  xn::IRMap m_writableIRMap;
831  };
832 
838  {
839  public:
841  inline AudioMetaData() : OutputMetaData(&m_audio.pData)
842  {
843  xnOSMemSet(&m_audio, 0, sizeof(XnAudioMetaData));
845  }
846 
852  inline void InitFrom(const AudioMetaData& other)
853  {
854  xnCopyAudioMetaData(&m_audio, &other.m_audio);
855  }
856 
858  inline XnUInt8 NumberOfChannels() const { return m_audio.Wave.nChannels; }
860  inline XnUInt8& NumberOfChannels() { return m_audio.Wave.nChannels; }
861 
863  inline XnUInt32 SampleRate() const { return m_audio.Wave.nSampleRate; }
865  inline XnUInt32& SampleRate() { return m_audio.Wave.nSampleRate; }
866 
868  inline XnUInt16 BitsPerSample() const { return m_audio.Wave.nBitsPerSample; }
870  inline XnUInt16& BitsPerSample() { return m_audio.Wave.nBitsPerSample; }
871 
873  inline const XnAudioMetaData* GetUnderlying() const { return &m_audio; }
875  inline XnAudioMetaData* GetUnderlying() { return &m_audio; }
876 
877  private:
878  // block copy ctor and assignment operator
879  AudioMetaData(const AudioMetaData& other);
880  AudioMetaData& operator=(const AudioMetaData&);
881 
882  XnAudioMetaData m_audio;
883  XnBool m_bAllocated;
884  };
885 
890  class SceneMetaData : public MapMetaData
891  {
892  public:
894  inline SceneMetaData() :
895  MapMetaData(XN_PIXEL_FORMAT_GRAYSCALE_16_BIT, (const XnUInt8**)&m_scene.pData),
896  m_labelMap(const_cast<XnLabel*&>(m_scene.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
897  m_writableLabelMap((XnLabel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
898  {
899  xnOSMemSet(&m_scene, 0, sizeof(XnSceneMetaData));
900  m_scene.pMap = MapMetaData::GetUnderlying();
901  }
902 
908  inline void InitFrom(const SceneMetaData& other)
909  {
910  xnCopySceneMetaData(&m_scene, &other.m_scene);
911  }
912 
914  inline XnStatus InitFrom(const SceneMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, const XnLabel* pExternalBuffer)
915  {
916  InitFrom(other);
917  return ReAdjust(nXRes, nYRes, pExternalBuffer);
918  }
919 
922  {
923  // copy props
924  xnCopySceneMetaData(&m_scene, &other.m_scene);
925  // and make a copy of the data (this will allocate and copy data)
926  return MakeDataWritable();
927  }
928 
930  XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnLabel* pExternalBuffer = NULL)
931  {
932  return MapMetaData::ReAdjust(nXRes, nYRes, (const XnUInt8*)pExternalBuffer);
933  }
934 
936  inline const XnLabel* Data() const { return (const XnLabel*)MapMetaData::Data(); }
938  inline const XnLabel*& Data() { return (const XnLabel*&)MapMetaData::Data(); }
941 
943  inline const xn::LabelMap& LabelMap() const { return m_labelMap; }
945  inline xn::LabelMap& WritableLabelMap() { MakeDataWritable(); return m_writableLabelMap; }
946 
952  inline const XnLabel& operator[](XnUInt32 nIndex) const
953  {
954  XN_ASSERT(nIndex < (XRes()*YRes()));
955  return Data()[nIndex];
956  }
957 
964  inline const XnLabel& operator()(XnUInt32 x, XnUInt32 y) const
965  {
966  XN_ASSERT(x < XRes() && y < YRes());
967  return (*this)[y*XRes() + x];
968  }
969 
971  inline const XnSceneMetaData* GetUnderlying() const { return &m_scene; }
973  inline XnSceneMetaData* GetUnderlying() { return &m_scene; }
974 
975  private:
976  // block copy ctor and assignment operator
977  SceneMetaData(const SceneMetaData& other);
978  SceneMetaData& operator=(const SceneMetaData&);
979 
980  XnSceneMetaData m_scene;
981  const xn::LabelMap m_labelMap;
982  xn::LabelMap m_writableLabelMap;
983  };
984 
985  //---------------------------------------------------------------------------
986  // NodeWrapper
987  //---------------------------------------------------------------------------
988 
994  {
995  public:
996  friend class Context;
997 
1003  inline NodeWrapper(XnNodeHandle hNode) : m_hNode(NULL), m_hShuttingDownCallback(NULL)
1004  {
1005  NodeWrapper::SetHandle(hNode);
1006  }
1007 
1008  inline NodeWrapper(const NodeWrapper& other) : m_hNode(NULL), m_hShuttingDownCallback(NULL)
1009  {
1011  }
1012 
1013  inline NodeWrapper& operator=(const NodeWrapper& other)
1014  {
1016  return *this;
1017  }
1018 
1019  inline ~NodeWrapper()
1020  {
1021  NodeWrapper::SetHandle(NULL);
1022  }
1023 
1024  inline operator XnNodeHandle() const { return GetHandle(); }
1025 
1027  inline XnNodeHandle GetHandle() const { return m_hNode; }
1028 
1034  inline XnBool operator==(const NodeWrapper& other)
1035  {
1036  return (GetHandle() == other.GetHandle());
1037  }
1038 
1044  inline XnBool operator!=(const NodeWrapper& other)
1045  {
1046  return (GetHandle() != other.GetHandle());
1047  }
1048 
1050  inline XnBool IsValid() const { return (GetHandle() != NULL); }
1051 
1055  const XnChar* GetName() const {return xnGetNodeName(GetHandle()); }
1056 
1061 
1065  inline void Release()
1066  {
1067  NodeWrapper::SetHandle(NULL);
1068  }
1069 
1070  inline XnStatus XN_API_DEPRECATED("Please use AddRef() instead.") Ref() { return AddRef(); }
1071  inline void XN_API_DEPRECATED("Please use Release() instead.") Unref() { Release(); }
1072 
1074  inline void SetHandle(XnNodeHandle hNode)
1075  {
1076  if (m_hNode == hNode)
1077  {
1078  // Optimization: do nothing
1079  return;
1080  }
1081 
1082  // check currently held node. If we're holding a node, release it
1083  if (m_hNode != NULL)
1084  {
1085  XnContext* pContext = xnGetRefContextFromNodeHandle(m_hNode);
1086  xnContextUnregisterFromShutdown(pContext, m_hShuttingDownCallback);
1087  xnContextRelease(pContext);
1088  xnProductionNodeRelease(m_hNode);
1089  }
1090 
1091  // check new node handle, if it points to a node, add ref to it
1092  if (hNode != NULL)
1093  {
1094  XnStatus nRetVal = xnProductionNodeAddRef(hNode);
1095  XN_ASSERT(nRetVal == XN_STATUS_OK);
1096 
1097  XnContext* pContext = xnGetRefContextFromNodeHandle(hNode);
1098 
1099  nRetVal = xnContextRegisterForShutdown(pContext, ContextShuttingDownCallback, this, &m_hShuttingDownCallback);
1100  XN_ASSERT(nRetVal == XN_STATUS_OK);
1101 
1102  xnContextRelease(pContext);
1103  }
1104 
1105  m_hNode = hNode;
1106  }
1107 
1108  inline void TakeOwnership(XnNodeHandle hNode)
1109  {
1110  SetHandle(hNode);
1111 
1112  if (hNode != NULL)
1113  {
1114  xnProductionNodeRelease(hNode);
1115  }
1116  }
1117 
1118  private:
1119  XnNodeHandle m_hNode;
1120  XnCallbackHandle m_hShuttingDownCallback;
1121 
1122  static void XN_CALLBACK_TYPE ContextShuttingDownCallback(XnContext* /*pContext*/, void* pCookie)
1123  {
1124  NodeWrapper* pThis = (NodeWrapper*)pCookie;
1125  pThis->m_hNode = NULL;
1126  }
1127  };
1128 
1129  //---------------------------------------------------------------------------
1130  // Node Info
1131  //---------------------------------------------------------------------------
1132 
1137  class NodeInfo
1138  {
1139  public:
1145  NodeInfo(XnNodeInfo* pInfo) : m_pNeededNodes(NULL), m_bOwnerOfNode(FALSE)
1146  {
1147  SetUnderlyingObject(pInfo);
1148  }
1149 
1156  NodeInfo(const NodeInfo& other) : m_pNeededNodes(NULL), m_bOwnerOfNode(FALSE)
1157  {
1158  SetUnderlyingObject(other.m_pInfo);
1159  }
1160 
1163  {
1164  SetUnderlyingObject(NULL);
1165  }
1166 
1172  inline NodeInfo& operator=(const NodeInfo& other)
1173  {
1174  SetUnderlyingObject(other.m_pInfo);
1175  return *this;
1176  }
1177 
1179  inline operator XnNodeInfo*()
1180  {
1181  return m_pInfo;
1182  }
1183 
1187  inline XnStatus SetInstanceName(const XnChar* strName)
1188  {
1189  return xnNodeInfoSetInstanceName(m_pInfo, strName);
1190  }
1191 
1196  {
1197  return *xnNodeInfoGetDescription(m_pInfo);
1198  }
1199 
1203  inline const XnChar* GetInstanceName() const
1204  {
1205  return xnNodeInfoGetInstanceName(m_pInfo);
1206  }
1207  inline const XnChar* GetCreationInfo() const
1211  {
1212  return xnNodeInfoGetCreationInfo(m_pInfo);
1213  }
1214 
1218  inline NodeInfoList& GetNeededNodes() const;
1219 
1227  inline XnStatus GetInstance(ProductionNode& node) const;
1228 
1232  inline const void* GetAdditionalData() const
1233  {
1234  return xnNodeInfoGetAdditionalData(m_pInfo);
1235  }
1236 
1237  private:
1238  inline void SetUnderlyingObject(XnNodeInfo* pInfo);
1239 
1240  XnNodeInfo* m_pInfo;
1241  mutable NodeInfoList* m_pNeededNodes;
1242  XnBool m_bOwnerOfNode; // backwards compatibility
1243  friend class Context;
1244  };
1245 
1246  //---------------------------------------------------------------------------
1247  // Query
1248  //---------------------------------------------------------------------------
1249 
1255  class Query
1256  {
1257  public:
1259  inline Query() : m_bAllocated(TRUE)
1260  {
1261  xnNodeQueryAllocate(&m_pQuery);
1262  }
1263 
1264  inline Query(XnNodeQuery* pNodeQuery) : m_pQuery(pNodeQuery), m_bAllocated(FALSE)
1265  {
1266  }
1267 
1270  {
1271  if (m_bAllocated)
1272  {
1273  xnNodeQueryFree(m_pQuery);
1274  }
1275  }
1276 
1278  inline const XnNodeQuery* GetUnderlyingObject() const { return m_pQuery; }
1279  inline XnNodeQuery* GetUnderlyingObject() { return m_pQuery; }
1280 
1284  inline XnStatus SetVendor(const XnChar* strVendor)
1285  {
1286  return xnNodeQuerySetVendor(m_pQuery, strVendor);
1287  }
1288 
1292  inline XnStatus SetName(const XnChar* strName)
1293  {
1294  return xnNodeQuerySetName(m_pQuery, strName);
1295  }
1296 
1300  inline XnStatus SetMinVersion(const XnVersion& minVersion)
1301  {
1302  return xnNodeQuerySetMinVersion(m_pQuery, &minVersion);
1303  }
1304 
1308  inline XnStatus SetMaxVersion(const XnVersion& maxVersion)
1309  {
1310  return xnNodeQuerySetMaxVersion(m_pQuery, &maxVersion);
1311  }
1312 
1316  inline XnStatus AddSupportedCapability(const XnChar* strNeededCapability)
1317  {
1318  return xnNodeQueryAddSupportedCapability(m_pQuery, strNeededCapability);
1319  }
1320 
1325  {
1326  return xnNodeQueryAddSupportedMapOutputMode(m_pQuery, &MapOutputMode);
1327  }
1328 
1332  inline XnStatus SetSupportedMinUserPositions(const XnUInt32 nCount)
1333  {
1334  return xnNodeQuerySetSupportedMinUserPositions(m_pQuery, nCount);
1335  }
1336 
1340  inline XnStatus SetExistingNodeOnly(XnBool bExistingNode)
1341  {
1342  return xnNodeQuerySetExistingNodeOnly(m_pQuery, bExistingNode);
1343  }
1344 
1348  inline XnStatus AddNeededNode(const XnChar* strInstanceName)
1349  {
1350  return xnNodeQueryAddNeededNode(m_pQuery, strInstanceName);
1351  }
1352 
1356  inline XnStatus SetCreationInfo(const XnChar* strCreationInfo)
1357  {
1358  return xnNodeQuerySetCreationInfo(m_pQuery, strCreationInfo);
1359  }
1360 
1361  private:
1362  XnNodeQuery* m_pQuery;
1363  XnBool m_bAllocated;
1364  };
1365 
1366  //---------------------------------------------------------------------------
1367  // Node Info List
1368  //---------------------------------------------------------------------------
1369 
1375  {
1376  public:
1378  class Iterator
1379  {
1380  public:
1381  friend class NodeInfoList;
1382 
1388  XnBool operator==(const Iterator& other) const
1389  {
1390  return m_it.pCurrent == other.m_it.pCurrent;
1391  }
1392 
1398  XnBool operator!=(const Iterator& other) const
1399  {
1400  return m_it.pCurrent != other.m_it.pCurrent;
1401  }
1402 
1408  {
1409  UpdateInternalObject(xnNodeInfoListGetNext(m_it));
1410  return *this;
1411  }
1412 
1417  inline Iterator operator++(int)
1418  {
1419  XnNodeInfoListIterator curr = m_it;
1420  UpdateInternalObject(xnNodeInfoListGetNext(m_it));
1421  return Iterator(curr);
1422  }
1423 
1428  {
1429  UpdateInternalObject(xnNodeInfoListGetPrevious(m_it));
1430  return *this;
1431  }
1432 
1436  inline Iterator operator--(int)
1437  {
1438  XnNodeInfoListIterator curr = m_it;
1439  UpdateInternalObject(xnNodeInfoListGetPrevious(m_it));
1440  return Iterator(curr);
1441  }
1442 
1445  {
1446  return m_Info;
1447  }
1448 
1449  private:
1450  inline Iterator(XnNodeInfoListIterator it) : m_Info(NULL)
1451  {
1452  UpdateInternalObject(it);
1453  }
1454 
1455  inline void UpdateInternalObject(XnNodeInfoListIterator it)
1456  {
1457  m_it = it;
1459  {
1460  XnNodeInfo* pInfo = xnNodeInfoListGetCurrent(it);
1461  m_Info = NodeInfo(pInfo);
1462  }
1463  else
1464  {
1465  m_Info = NodeInfo(NULL);
1466  }
1467  }
1468 
1469  NodeInfo m_Info;
1471  };
1472 
1476  inline NodeInfoList()
1477  {
1478  xnNodeInfoListAllocate(&m_pList);
1479  m_bAllocated = TRUE;
1480  }
1481 
1488  inline NodeInfoList(XnNodeInfoList* pList) : m_pList(pList), m_bAllocated(FALSE) {}
1489 
1491  inline ~NodeInfoList()
1492  {
1493  FreeImpl();
1494  }
1495 
1497  inline XnNodeInfoList* GetUnderlyingObject() const { return m_pList; }
1498 
1506  {
1507  FreeImpl();
1508  m_pList = pList;
1509  m_bAllocated = TRUE;
1510  }
1511 
1515  inline XnStatus Add(XnProductionNodeDescription& description, const XnChar* strCreationInfo, NodeInfoList* pNeededNodes)
1516  {
1517  XnNodeInfoList* pList = (pNeededNodes == NULL) ? NULL : pNeededNodes->GetUnderlyingObject();
1518  return xnNodeInfoListAdd(m_pList, &description, strCreationInfo, pList);
1519  }
1520 
1524  inline XnStatus AddEx(XnProductionNodeDescription& description, const XnChar* strCreationInfo, NodeInfoList* pNeededNodes, const void* pAdditionalData, XnFreeHandler pFreeHandler)
1525  {
1526  XnNodeInfoList* pList = (pNeededNodes == NULL) ? NULL : pNeededNodes->GetUnderlyingObject();
1527  return xnNodeInfoListAddEx(m_pList, &description, strCreationInfo, pList, pAdditionalData, pFreeHandler);
1528  }
1529 
1533  inline XnStatus AddNode(NodeInfo& info)
1534  {
1535  return xnNodeInfoListAddNode(m_pList, info);
1536  }
1537 
1542  {
1543  return xnNodeInfoListAddNodeFromList(m_pList, it.m_it);
1544  }
1545 
1547  inline Iterator Begin() const
1548  {
1549  return Iterator(xnNodeInfoListGetFirst(m_pList));
1550  }
1551 
1553  inline Iterator End() const
1554  {
1555  XnNodeInfoListIterator it = { NULL };
1556  return Iterator(it);
1557  }
1558 
1560  inline Iterator RBegin() const
1561  {
1562  return Iterator(xnNodeInfoListGetLast(m_pList));
1563  }
1564 
1566  inline Iterator REnd() const
1567  {
1568  XnNodeInfoListIterator it = { NULL };
1569  return Iterator(it);
1570  }
1571 
1576  {
1577  return xnNodeInfoListRemove(m_pList, it.m_it);
1578  }
1579 
1583  inline XnStatus Clear()
1584  {
1585  return xnNodeInfoListClear(m_pList);
1586  }
1587 
1592  {
1593  return xnNodeInfoListAppend(m_pList, other.GetUnderlyingObject());
1594  }
1595 
1599  inline XnBool IsEmpty()
1600  {
1601  return xnNodeInfoListIsEmpty(m_pList);
1602  }
1603 
1607  inline XnStatus FilterList(Context& context, Query& query);
1608 
1609  private:
1610  inline void FreeImpl()
1611  {
1612  if (m_bAllocated)
1613  {
1614  xnNodeInfoListFree(m_pList);
1615  m_bAllocated = FALSE;
1616  m_pList = NULL;
1617  }
1618  }
1619 
1620  XnNodeInfoList* m_pList;
1621  XnBool m_bAllocated;
1622  };
1623 
1624  //---------------------------------------------------------------------------
1625  // Production Nodes Functionality
1626  //---------------------------------------------------------------------------
1627 
1632  class Capability : public NodeWrapper
1633  {
1634  public:
1641  Capability(const NodeWrapper& node) : NodeWrapper(node) {}
1642  };
1643 
1649  {
1650  public:
1658 
1662  inline XnStatus GetErrorState() const
1663  {
1664  return xnGetNodeErrorState(GetHandle());
1665  }
1666 
1671  {
1672  return _RegisterToStateChange(xnRegisterToNodeErrorStateChange, GetHandle(), handler, pCookie, hCallback);
1673  }
1674 
1679  {
1680  _UnregisterFromStateChange(xnUnregisterFromNodeErrorStateChange, GetHandle(), hCallback);
1681  }
1682  };
1683 
1689  {
1690  public:
1697  GeneralIntCapability(XnNodeHandle hNode, const XnChar* strCap) : Capability(hNode), m_strCap(strCap) {}
1699 
1703  inline void GetRange(XnInt32& nMin, XnInt32& nMax, XnInt32& nStep, XnInt32& nDefault, XnBool& bIsAutoSupported) const
1704  {
1705  xnGetGeneralIntRange(GetHandle(), m_strCap, &nMin, &nMax, &nStep, &nDefault, &bIsAutoSupported);
1706  }
1707 
1711  inline XnInt32 Get()
1712  {
1713  XnInt32 nValue;
1714  xnGetGeneralIntValue(GetHandle(), m_strCap, &nValue);
1715  return nValue;
1716  }
1717 
1721  inline XnStatus Set(XnInt32 nValue)
1722  {
1723  return xnSetGeneralIntValue(GetHandle(), m_strCap, nValue);
1724  }
1725 
1729  XnStatus RegisterToValueChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback);
1730 
1735 
1736  private:
1737  const XnChar* m_strCap;
1738  };
1739 
1745  {
1746  public:
1752  inline ProductionNode(XnNodeHandle hNode = NULL) : NodeWrapper(hNode) {}
1753  inline ProductionNode(const NodeWrapper& other) : NodeWrapper(other) {}
1754 
1758  inline NodeInfo GetInfo() const { return NodeInfo(xnGetNodeInfo(GetHandle())); }
1759 
1764  {
1765  return xnAddNeededNode(GetHandle(), needed.GetHandle());
1766  }
1767 
1772  {
1773  return xnRemoveNeededNode(GetHandle(), needed.GetHandle());
1774  }
1775 
1779  inline void GetContext(Context& context) const;
1780 
1784  inline XnBool IsCapabilitySupported(const XnChar* strCapabilityName) const
1785  {
1786  return xnIsCapabilitySupported(GetHandle(), strCapabilityName);
1787  }
1788 
1792  inline XnStatus SetIntProperty(const XnChar* strName, XnUInt64 nValue)
1793  {
1794  return xnSetIntProperty(GetHandle(), strName, nValue);
1795  }
1796 
1800  inline XnStatus SetRealProperty(const XnChar* strName, XnDouble dValue)
1801  {
1802  return xnSetRealProperty(GetHandle(), strName, dValue);
1803  }
1804 
1808  inline XnStatus SetStringProperty(const XnChar* strName, const XnChar* strValue)
1809  {
1810  return xnSetStringProperty(GetHandle(), strName, strValue);
1811  }
1812 
1816  inline XnStatus SetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, const void* pBuffer)
1817  {
1818  return xnSetGeneralProperty(GetHandle(), strName, nBufferSize, pBuffer);
1819  }
1820 
1824  inline XnStatus GetIntProperty(const XnChar* strName, XnUInt64& nValue) const
1825  {
1826  return xnGetIntProperty(GetHandle(), strName, &nValue);
1827  }
1828 
1832  inline XnStatus GetRealProperty(const XnChar* strName, XnDouble &dValue) const
1833  {
1834  return xnGetRealProperty(GetHandle(), strName, &dValue);
1835  }
1836 
1840  inline XnStatus GetStringProperty(const XnChar* strName, XnChar* csValue, XnUInt32 nBufSize) const
1841  {
1842  return xnGetStringProperty(GetHandle(), strName, csValue, nBufSize);
1843  }
1844 
1848  inline XnStatus GetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, void* pBuffer) const
1849  {
1850  return xnGetGeneralProperty(GetHandle(), strName, nBufferSize, pBuffer);
1851  }
1852 
1857  {
1858  return xnLockNodeForChanges(GetHandle(), phLock);
1859  }
1860 
1864  inline void UnlockForChanges(XnLockHandle hLock)
1865  {
1867  }
1868 
1873  {
1874  return xnLockedNodeStartChanges(GetHandle(), hLock);
1875  }
1876 
1881  {
1883  }
1884 
1891  {
1892  return ErrorStateCapability(GetHandle());
1893  }
1894 
1901  {
1902  return ErrorStateCapability(GetHandle());
1903  }
1904 
1912  inline GeneralIntCapability GetGeneralIntCap(const XnChar* strCapability)
1913  {
1914  return GeneralIntCapability(GetHandle(), strCapability);
1915  }
1916  };
1917 
1923  {
1924  public:
1932 
1936  inline XnStatus GetDeviceName(XnChar* strBuffer, XnUInt32 nBufferSize)
1937  {
1938  return xnGetDeviceName(GetHandle(), strBuffer, &nBufferSize);
1939  }
1940 
1944  inline XnStatus GetVendorSpecificData(XnChar* strBuffer, XnUInt32 nBufferSize)
1945  {
1946  return xnGetVendorSpecificData(GetHandle(), strBuffer, &nBufferSize);
1947  }
1948 
1952  inline XnStatus GetSerialNumber(XnChar* strBuffer, XnUInt32 nBufferSize)
1953  {
1954  return xnGetSerialNumber(GetHandle(), strBuffer, &nBufferSize);
1955  }
1956  };
1957 
1962  class Device : public ProductionNode
1963  {
1964  public:
1970  inline Device(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
1971  inline Device(const NodeWrapper& other) : ProductionNode(other) {}
1972 
1976  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
1977 
1984  {
1986  }
1987  };
1988 
1994  {
1995  public:
2001  inline MirrorCapability(XnNodeHandle hNode) : Capability(hNode) {}
2002  MirrorCapability(const NodeWrapper& node) : Capability(node) {}
2003 
2007  inline XnStatus SetMirror(XnBool bMirror)
2008  {
2009  return xnSetMirror(GetHandle(), bMirror);
2010  }
2011 
2015  inline XnBool IsMirrored() const
2016  {
2017  return xnIsMirrored(GetHandle());
2018  }
2019 
2023  inline XnStatus RegisterToMirrorChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
2024  {
2025  return _RegisterToStateChange(xnRegisterToMirrorChange, GetHandle(), handler, pCookie, hCallback);
2026  }
2027 
2032  {
2033  _UnregisterFromStateChange(xnUnregisterFromMirrorChange, GetHandle(), hCallback);
2034  }
2035  };
2036 
2042  {
2043  public:
2051 
2055  inline XnBool IsViewPointSupported(ProductionNode& otherNode) const
2056  {
2057  return xnIsViewPointSupported(GetHandle(), otherNode.GetHandle());
2058  }
2059 
2064  {
2065  return xnSetViewPoint(GetHandle(), otherNode.GetHandle());
2066  }
2067 
2072  {
2073  return xnResetViewPoint(GetHandle());
2074  }
2075 
2079  inline XnBool IsViewPointAs(ProductionNode& otherNode) const
2080  {
2081  return xnIsViewPointAs(GetHandle(), otherNode.GetHandle());
2082  }
2083 
2087  inline XnStatus RegisterToViewPointChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
2088  {
2089  return _RegisterToStateChange(xnRegisterToViewPointChange, GetHandle(), handler, pCookie, hCallback);
2090  }
2091 
2096  {
2097  _UnregisterFromStateChange(xnUnregisterFromViewPointChange, GetHandle(), hCallback);
2098  }
2099  };
2100 
2106  {
2107  public:
2113  inline FrameSyncCapability(XnNodeHandle hNode) : Capability(hNode) {}
2115 
2119  inline XnBool CanFrameSyncWith(Generator& other) const;
2120 
2124  inline XnStatus FrameSyncWith(Generator& other);
2125 
2129  inline XnStatus StopFrameSyncWith(Generator& other);
2130 
2134  inline XnBool IsFrameSyncedWith(Generator& other) const;
2135 
2139  inline XnStatus RegisterToFrameSyncChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
2140  {
2141  return _RegisterToStateChange(xnRegisterToFrameSyncChange, GetHandle(), handler, pCookie, hCallback);
2142  }
2143 
2148  {
2149  _UnregisterFromStateChange(xnUnregisterFromFrameSyncChange, GetHandle(), hCallback);
2150  }
2151  };
2152 
2157  class Generator : public ProductionNode
2158  {
2159  public:
2165  inline Generator(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
2166  inline Generator(const NodeWrapper& other) : ProductionNode(other) {}
2167 
2172  {
2173  return xnStartGenerating(GetHandle());
2174  }
2175 
2179  inline XnBool IsGenerating() const
2180  {
2181  return xnIsGenerating(GetHandle());
2182  }
2183 
2188  {
2189  return xnStopGenerating(GetHandle());
2190  }
2191 
2196  {
2197  return _RegisterToStateChange(xnRegisterToGenerationRunningChange, GetHandle(), handler, pCookie, hCallback);
2198  }
2199 
2204  {
2205  _UnregisterFromStateChange(xnUnregisterFromGenerationRunningChange, GetHandle(), hCallback);
2206  }
2207 
2212  {
2213  return _RegisterToStateChange(xnRegisterToNewDataAvailable, GetHandle(), handler, pCookie, hCallback);
2214  }
2215 
2220  {
2221  _UnregisterFromStateChange(xnUnregisterFromNewDataAvailable, GetHandle(), hCallback);
2222  }
2223 
2227  inline XnBool IsNewDataAvailable(XnUInt64* pnTimestamp = NULL) const
2228  {
2229  return xnIsNewDataAvailable(GetHandle(), pnTimestamp);
2230  }
2231 
2236  {
2237  return xnWaitAndUpdateData(GetHandle());
2238  }
2239 
2243  inline XnBool IsDataNew() const
2244  {
2245  return xnIsDataNew(GetHandle());
2246  }
2247 
2251  inline const void* GetData()
2252  {
2253  return xnGetData(GetHandle());
2254  }
2255 
2259  inline XnUInt32 GetDataSize() const
2260  {
2261  return xnGetDataSize(GetHandle());
2262  }
2263 
2267  inline XnUInt64 GetTimestamp() const
2268  {
2269  return xnGetTimestamp(GetHandle());
2270  }
2271 
2275  inline XnUInt32 GetFrameID() const
2276  {
2277  return xnGetFrameID(GetHandle());
2278  }
2279 
2285  inline const MirrorCapability GetMirrorCap() const
2286  {
2287  return MirrorCapability(GetHandle());
2288  }
2289 
2296  {
2297  return MirrorCapability(GetHandle());
2298  }
2299 
2306  {
2308  }
2309 
2316  {
2318  }
2319 
2326  {
2327  return FrameSyncCapability(GetHandle());
2328  }
2329 
2336  {
2337  return FrameSyncCapability(GetHandle());
2338  }
2339  };
2340 
2345  class Recorder : public ProductionNode
2346  {
2347  public:
2353  inline Recorder(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
2354  inline Recorder(const NodeWrapper& other) : ProductionNode(other) {}
2355 
2359  inline XnStatus Create(Context& context, const XnChar* strFormatName = NULL);
2360 
2364  inline XnStatus SetDestination(XnRecordMedium destType, const XnChar* strDest)
2365  {
2366  return xnSetRecorderDestination(GetHandle(), destType, strDest);
2367  }
2368 
2369  inline XnStatus GetDestination(XnRecordMedium& destType, XnChar* strDest, XnUInt32 nBufSize)
2370  {
2371  return xnGetRecorderDestination(GetHandle(), &destType, strDest, nBufSize);
2372  }
2373 
2378  {
2379  return xnAddNodeToRecording(GetHandle(), Node.GetHandle(), compression);
2380  }
2381 
2386  {
2387  return xnRemoveNodeFromRecording(GetHandle(), Node.GetHandle());
2388  }
2389 
2393  inline XnStatus Record()
2394  {
2395  return xnRecord(GetHandle());
2396  }
2397  };
2398 
2403  class Player : public ProductionNode
2404  {
2405  public:
2411  inline Player(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
2412  inline Player(const NodeWrapper& other) : ProductionNode(other) {}
2413 
2417  inline XnStatus Create(Context& context, const XnChar* strFormatName);
2418 
2422  inline XnStatus SetRepeat(XnBool bRepeat)
2423  {
2424  return xnSetPlayerRepeat(GetHandle(), bRepeat);
2425  }
2426 
2430  inline XnStatus SetSource(XnRecordMedium sourceType, const XnChar* strSource)
2431  {
2432  return xnSetPlayerSource(GetHandle(), sourceType, strSource);
2433  }
2434 
2438  inline XnStatus GetSource(XnRecordMedium &sourceType, XnChar* strSource, XnUInt32 nBufSize) const
2439  {
2440  return xnGetPlayerSource(GetHandle(), &sourceType, strSource, nBufSize);
2441  }
2442 
2447  {
2448  return xnPlayerReadNext(GetHandle());
2449  }
2450 
2454  inline XnStatus SeekToTimeStamp(XnInt64 nTimeOffset, XnPlayerSeekOrigin origin)
2455  {
2456  return xnSeekPlayerToTimeStamp(GetHandle(), nTimeOffset, origin);
2457  }
2458 
2462  inline XnStatus SeekToFrame(const XnChar* strNodeName, XnInt32 nFrameOffset, XnPlayerSeekOrigin origin)
2463  {
2464  return xnSeekPlayerToFrame(GetHandle(), strNodeName, nFrameOffset, origin);
2465  }
2466 
2470  inline XnStatus TellTimestamp(XnUInt64& nTimestamp) const
2471  {
2472  return xnTellPlayerTimestamp(GetHandle(), &nTimestamp);
2473  }
2474 
2478  inline XnStatus TellFrame(const XnChar* strNodeName, XnUInt32& nFrame) const
2479  {
2480  return xnTellPlayerFrame(GetHandle(), strNodeName, &nFrame);
2481  }
2482 
2486  inline XnStatus GetNumFrames(const XnChar* strNodeName, XnUInt32& nFrames) const
2487  {
2488  return xnGetPlayerNumFrames(GetHandle(), strNodeName, &nFrames);
2489  }
2490 
2494  inline const XnChar* GetSupportedFormat() const
2495  {
2497  }
2498 
2503  {
2504  XnNodeInfoList* pList;
2505  XnStatus nRetVal = xnEnumeratePlayerNodes(GetHandle(), &pList);
2506  XN_IS_STATUS_OK(nRetVal);
2507 
2508  list.ReplaceUnderlyingObject(pList);
2509 
2510  return (XN_STATUS_OK);
2511  }
2512 
2516  inline XnBool IsEOF() const
2517  {
2518  return xnIsPlayerAtEOF(GetHandle());
2519  }
2520 
2525  {
2526  return _RegisterToStateChange(xnRegisterToEndOfFileReached, GetHandle(), handler, pCookie, hCallback);
2527  }
2528 
2533  {
2534  _UnregisterFromStateChange(xnUnregisterFromEndOfFileReached, GetHandle(), hCallback);
2535  }
2536 
2540  inline XnStatus SetPlaybackSpeed(XnDouble dSpeed)
2541  {
2542  return xnSetPlaybackSpeed(GetHandle(), dSpeed);
2543  }
2544 
2548  inline XnDouble GetPlaybackSpeed() const
2549  {
2550  return xnGetPlaybackSpeed(GetHandle());
2551  }
2552  };
2553 
2559  {
2560  public:
2566  inline CroppingCapability(XnNodeHandle hNode) : Capability(hNode) {}
2568 
2572  inline XnStatus SetCropping(const XnCropping& Cropping)
2573  {
2574  return xnSetCropping(GetHandle(), &Cropping);
2575  }
2576 
2580  inline XnStatus GetCropping(XnCropping& Cropping) const
2581  {
2582  return xnGetCropping(GetHandle(), &Cropping);
2583  }
2584 
2588  inline XnStatus RegisterToCroppingChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
2589  {
2590  return _RegisterToStateChange(xnRegisterToCroppingChange, GetHandle(), handler, pCookie, hCallback);
2591  }
2592 
2597  {
2598  _UnregisterFromStateChange(xnUnregisterFromCroppingChange, GetHandle(), hCallback);
2599  }
2600  };
2601 
2607  {
2608  public:
2616 
2621  {
2622  return xnSetPowerLineFrequency(GetHandle(), nFrequency);
2623  }
2624 
2629  {
2631  }
2632 
2637  {
2638  return _RegisterToStateChange(xnRegisterToPowerLineFrequencyChange, GetHandle(), handler, pCookie, hCallback);
2639  }
2640 
2645  {
2646  _UnregisterFromStateChange(xnUnregisterFromPowerLineFrequencyChange, GetHandle(), hCallback);
2647  }
2648  };
2649 
2654  class MapGenerator : public Generator
2655  {
2656  public:
2662  inline MapGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
2663  inline MapGenerator(const NodeWrapper& other) : Generator(other) {}
2664 
2668  inline XnUInt32 GetSupportedMapOutputModesCount() const
2669  {
2671  }
2672 
2676  inline XnStatus GetSupportedMapOutputModes(XnMapOutputMode* aModes, XnUInt32& nCount) const
2677  {
2678  return xnGetSupportedMapOutputModes(GetHandle(), aModes, &nCount);
2679  }
2680 
2684  inline XnStatus SetMapOutputMode(const XnMapOutputMode& OutputMode)
2685  {
2686  return xnSetMapOutputMode(GetHandle(), &OutputMode);
2687  }
2688 
2692  inline XnStatus GetMapOutputMode(XnMapOutputMode &OutputMode) const
2693  {
2694  return xnGetMapOutputMode(GetHandle(), &OutputMode);
2695  }
2696 
2700  inline XnUInt32 GetBytesPerPixel() const
2701  {
2702  return xnGetBytesPerPixel(GetHandle());
2703  }
2704 
2709  {
2710  return _RegisterToStateChange(xnRegisterToMapOutputModeChange, GetHandle(), handler, pCookie, hCallback);
2711  }
2712 
2717  {
2718  _UnregisterFromStateChange(xnUnregisterFromMapOutputModeChange, GetHandle(), hCallback);
2719  }
2720 
2726  inline const CroppingCapability GetCroppingCap() const
2727  {
2728  return CroppingCapability(GetHandle());
2729  }
2730 
2737  {
2738  return CroppingCapability(GetHandle());
2739  }
2740 
2747  {
2749  }
2750 
2757  {
2759  }
2760 
2767  {
2769  }
2770 
2777  {
2779  }
2780 
2787  {
2789  }
2790 
2797  {
2799  }
2800 
2807  {
2809  }
2810 
2817  {
2819  }
2820 
2827  {
2829  }
2830 
2837  {
2839  }
2840 
2847  {
2849  }
2850 
2857  {
2859  }
2860 
2867  {
2869  }
2870 
2877  {
2879  }
2880 
2887  {
2889  }
2890 
2897  {
2899  }
2900 
2907  {
2909  }
2910 
2917  {
2918  return AntiFlickerCapability(GetHandle());
2919  }
2920  };
2921 
2927  {
2928  public:
2934  inline UserPositionCapability(XnNodeHandle hNode = NULL) : Capability(hNode) {}
2936 
2940  inline XnUInt32 GetSupportedUserPositionsCount() const
2941  {
2943  }
2944 
2948  inline XnStatus SetUserPosition(XnUInt32 nIndex, const XnBoundingBox3D& Position)
2949  {
2950  return xnSetUserPosition(GetHandle(), nIndex, &Position);
2951  }
2952 
2956  inline XnStatus GetUserPosition(XnUInt32 nIndex, XnBoundingBox3D& Position) const
2957  {
2958  return xnGetUserPosition(GetHandle(), nIndex, &Position);
2959  }
2960 
2965  {
2966  return _RegisterToStateChange(xnRegisterToUserPositionChange, GetHandle(), handler, pCookie, hCallback);
2967  }
2968 
2973  {
2974  _UnregisterFromStateChange(xnUnregisterFromUserPositionChange, GetHandle(), hCallback);
2975  }
2976  };
2977 
2983  {
2984  public:
2990  inline DepthGenerator(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
2991  inline DepthGenerator(const NodeWrapper& other) : MapGenerator(other) {}
2992 
2996  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
2997 
3001  inline void GetMetaData(DepthMetaData& metaData) const
3002  {
3004  }
3005 
3009  inline const XnDepthPixel* GetDepthMap() const
3010  {
3011  return xnGetDepthMap(GetHandle());
3012  }
3013 
3018  {
3019  return xnGetDeviceMaxDepth(GetHandle());
3020  }
3021 
3026  {
3027  return xnGetDepthFieldOfView(GetHandle(), &FOV);
3028  }
3029 
3034  {
3035  return _RegisterToStateChange(xnRegisterToDepthFieldOfViewChange, GetHandle(), handler, pCookie, hCallback);
3036  }
3037 
3042  {
3043  _UnregisterFromStateChange(xnUnregisterFromDepthFieldOfViewChange, GetHandle(), hCallback);
3044  }
3045 
3049  inline XnStatus ConvertProjectiveToRealWorld(XnUInt32 nCount, const XnPoint3D aProjective[], XnPoint3D aRealWorld[]) const
3050  {
3051  return xnConvertProjectiveToRealWorld(GetHandle(), nCount, aProjective, aRealWorld);
3052  }
3053 
3057  inline XnStatus ConvertRealWorldToProjective(XnUInt32 nCount, const XnPoint3D aRealWorld[], XnPoint3D aProjective[]) const
3058  {
3059  return xnConvertRealWorldToProjective(GetHandle(), nCount, aRealWorld, aProjective);
3060  }
3061 
3068  {
3070  }
3071 
3078  {
3080  }
3081  };
3082 
3088  {
3089  public:
3095  inline MockDepthGenerator(XnNodeHandle hNode = NULL) : DepthGenerator(hNode) {}
3096  inline MockDepthGenerator(const NodeWrapper& other) : DepthGenerator(other) {}
3097 
3104  XnStatus Create(Context& context, const XnChar* strName = NULL);
3105 
3112  XnStatus CreateBasedOn(DepthGenerator& other, const XnChar* strName = NULL);
3113 
3117  inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnDepthPixel* pDepthMap)
3118  {
3119  return xnMockDepthSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pDepthMap);
3120  }
3121 
3129  inline XnStatus SetData(const DepthMetaData& depthMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
3130  {
3131  return SetData(nFrameID, nTimestamp, depthMD.DataSize(), depthMD.Data());
3132  }
3133 
3139  inline XnStatus SetData(const DepthMetaData& depthMD)
3140  {
3141  return SetData(depthMD, depthMD.FrameID(), depthMD.Timestamp());
3142  }
3143  };
3144 
3150  {
3151  public:
3157  inline ImageGenerator(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
3158  inline ImageGenerator(const NodeWrapper& other) : MapGenerator(other) {}
3159 
3163  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
3164 
3168  inline void GetMetaData(ImageMetaData& metaData) const
3169  {
3171  }
3172 
3176  inline const XnRGB24Pixel* GetRGB24ImageMap() const
3177  {
3178  return xnGetRGB24ImageMap(GetHandle());
3179  }
3180 
3185  {
3186  return xnGetYUV422ImageMap(GetHandle());
3187  }
3188 
3193  {
3195  }
3196 
3201  {
3203  }
3204 
3208  inline const XnUInt8* GetImageMap() const
3209  {
3210  return xnGetImageMap(GetHandle());
3211  }
3212 
3216  inline XnBool IsPixelFormatSupported(XnPixelFormat Format) const
3217  {
3218  return xnIsPixelFormatSupported(GetHandle(), Format);
3219  }
3220 
3225  {
3226  return xnSetPixelFormat(GetHandle(), Format);
3227  }
3228 
3233  {
3234  return xnGetPixelFormat(GetHandle());
3235  }
3236 
3241  {
3242  return _RegisterToStateChange(xnRegisterToPixelFormatChange, GetHandle(), handler, pCookie, hCallback);
3243  }
3244 
3249  {
3250  _UnregisterFromStateChange(xnUnregisterFromPixelFormatChange, GetHandle(), hCallback);
3251  }
3252  };
3253 
3259  {
3260  public:
3266  inline MockImageGenerator(XnNodeHandle hNode = NULL) : ImageGenerator(hNode) {}
3267  inline MockImageGenerator(const NodeWrapper& other) : ImageGenerator(other) {}
3268 
3275  XnStatus Create(Context& context, const XnChar* strName = NULL);
3276 
3283  XnStatus CreateBasedOn(ImageGenerator& other, const XnChar* strName = NULL);
3284 
3288  inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnUInt8* pImageMap)
3289  {
3290  return xnMockImageSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pImageMap);
3291  }
3292 
3300  inline XnStatus SetData(const ImageMetaData& imageMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
3301  {
3302  return SetData(nFrameID, nTimestamp, imageMD.DataSize(), imageMD.Data());
3303  }
3304 
3310  inline XnStatus SetData(const ImageMetaData& imageMD)
3311  {
3312  return SetData(imageMD, imageMD.FrameID(), imageMD.Timestamp());
3313  }
3314  };
3315 
3320  class IRGenerator : public MapGenerator
3321  {
3322  public:
3328  inline IRGenerator(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
3329  inline IRGenerator(const NodeWrapper& other) : MapGenerator(other) {}
3330 
3334  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
3335 
3339  inline void GetMetaData(IRMetaData& metaData) const
3340  {
3341  xnGetIRMetaData(GetHandle(), metaData.GetUnderlying());
3342  }
3343 
3347  inline const XnIRPixel* GetIRMap() const
3348  {
3349  return xnGetIRMap(GetHandle());
3350  }
3351  };
3352 
3358  {
3359  public:
3365  inline MockIRGenerator(XnNodeHandle hNode = NULL) : IRGenerator(hNode) {}
3366  inline MockIRGenerator(const NodeWrapper& other) : IRGenerator(other) {}
3367 
3374  XnStatus Create(Context& context, const XnChar* strName = NULL);
3381  XnStatus CreateBasedOn(IRGenerator& other, const XnChar* strName = NULL);
3382 
3386  inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnIRPixel* pIRMap)
3387  {
3388  return xnMockIRSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pIRMap);
3389  }
3390 
3398  inline XnStatus SetData(const IRMetaData& irMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
3399  {
3400  return SetData(nFrameID, nTimestamp, irMD.DataSize(), irMD.Data());
3401  }
3402 
3408  inline XnStatus SetData(const IRMetaData& irMD)
3409  {
3410  return SetData(irMD, irMD.FrameID(), irMD.Timestamp());
3411  }
3412  };
3413 
3419  {
3420  public:
3426  inline GestureGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
3427  inline GestureGenerator(const NodeWrapper& other) : Generator(other) {}
3428 
3432  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
3433 
3437  inline XnStatus AddGesture(const XnChar* strGesture, XnBoundingBox3D* pArea)
3438  {
3439  return xnAddGesture(GetHandle(), strGesture, pArea);
3440  }
3441 
3445  inline XnStatus RemoveGesture(const XnChar* strGesture)
3446  {
3447  return xnRemoveGesture(GetHandle(), strGesture);
3448  }
3449 
3453  inline XnStatus GetActiveGestures(XnChar*& astrGestures, XnUInt16& nGestures) const
3454  {
3455  return xnGetActiveGestures(GetHandle(), &astrGestures, &nGestures);
3456  }
3457 
3461  inline XnStatus GetAllActiveGestures(XnChar** astrGestures, XnUInt32 nNameLength, XnUInt16& nGestures) const
3462  {
3463  return xnGetAllActiveGestures(GetHandle(), astrGestures, nNameLength, &nGestures);
3464  }
3465 
3469  inline XnStatus EnumerateGestures(XnChar*& astrGestures, XnUInt16& nGestures) const
3470  {
3471  return xnEnumerateGestures(GetHandle(), &astrGestures, &nGestures);
3472  }
3476  inline XnStatus EnumerateAllGestures(XnChar** astrGestures, XnUInt32 nNameLength, XnUInt16& nGestures) const
3477  {
3478  return xnEnumerateAllGestures(GetHandle(), astrGestures, nNameLength, &nGestures);
3479  }
3480 
3484  inline XnBool IsGestureAvailable(const XnChar* strGesture) const
3485  {
3486  return xnIsGestureAvailable(GetHandle(), strGesture);
3487  }
3488 
3492  inline XnBool IsGestureProgressSupported(const XnChar* strGesture) const
3493  {
3494  return xnIsGestureProgressSupported(GetHandle(), strGesture);
3495  }
3496 
3506  typedef void (XN_CALLBACK_TYPE* GestureRecognized)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pIDPosition, const XnPoint3D* pEndPosition, void* pCookie);
3516  typedef void (XN_CALLBACK_TYPE* GestureProgress)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie);
3517 
3521  XnStatus RegisterGestureCallbacks(GestureRecognized RecognizedCB, GestureProgress ProgressCB, void* pCookie, XnCallbackHandle& hCallback)
3522  {
3523  XnStatus nRetVal = XN_STATUS_OK;
3524 
3525  GestureCookie* pGestureCookie;
3526  XN_VALIDATE_ALLOC(pGestureCookie, GestureCookie);
3527  pGestureCookie->recognizedHandler = RecognizedCB;
3528  pGestureCookie->progressHandler = ProgressCB;
3529  pGestureCookie->pUserCookie = pCookie;
3530 
3531  nRetVal = xnRegisterGestureCallbacks(GetHandle(), GestureRecognizedCallback, GestureProgressCallback, pGestureCookie, &pGestureCookie->hCallback);
3532  if (nRetVal != XN_STATUS_OK)
3533  {
3534  xnOSFree(pGestureCookie);
3535  return (nRetVal);
3536  }
3537 
3538  hCallback = pGestureCookie;
3539 
3540  return (XN_STATUS_OK);
3541  }
3542 
3547  {
3548  GestureCookie* pGestureCookie = (GestureCookie*)hCallback;
3549  xnUnregisterGestureCallbacks(GetHandle(), pGestureCookie->hCallback);
3550  xnOSFree(pGestureCookie);
3551  }
3552 
3556  inline XnStatus RegisterToGestureChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
3557  {
3558  return _RegisterToStateChange(xnRegisterToGestureChange, GetHandle(), handler, pCookie, hCallback);
3559  }
3560 
3565  {
3566  _UnregisterFromStateChange(xnUnregisterFromGestureChange, GetHandle(), hCallback);
3567  }
3568 
3577  typedef void (XN_CALLBACK_TYPE* GestureIntermediateStageCompleted)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie);
3582  {
3583  XnStatus nRetVal = XN_STATUS_OK;
3584 
3585  GestureIntermediateStageCompletedCookie* pGestureCookie;
3586  XN_VALIDATE_ALLOC(pGestureCookie, GestureIntermediateStageCompletedCookie);
3587  pGestureCookie->handler = handler;
3588  pGestureCookie->pUserCookie = pCookie;
3589 
3590  nRetVal = xnRegisterToGestureIntermediateStageCompleted(GetHandle(), GestureIntermediateStageCompletedCallback, pGestureCookie, &pGestureCookie->hCallback);
3591  if (nRetVal != XN_STATUS_OK)
3592  {
3593  xnOSFree(pGestureCookie);
3594  return (nRetVal);
3595  }
3596 
3597  hCallback = pGestureCookie;
3598 
3599  return (XN_STATUS_OK);
3600  }
3605  {
3606  GestureIntermediateStageCompletedCookie* pGestureCookie = (GestureIntermediateStageCompletedCookie*)hCallback;
3607  xnUnregisterFromGestureIntermediateStageCompleted(GetHandle(), pGestureCookie->hCallback);
3608  xnOSFree(pGestureCookie);
3609  }
3610 
3619  typedef void (XN_CALLBACK_TYPE* GestureReadyForNextIntermediateStage)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie);
3624  {
3625  XnStatus nRetVal = XN_STATUS_OK;
3626 
3627  GestureReadyForNextIntermediateStageCookie* pGestureCookie;
3628  XN_VALIDATE_ALLOC(pGestureCookie, GestureReadyForNextIntermediateStageCookie);
3629  pGestureCookie->handler = handler;
3630  pGestureCookie->pUserCookie = pCookie;
3631 
3632  nRetVal = xnRegisterToGestureReadyForNextIntermediateStage(GetHandle(), GestureReadyForNextIntermediateStageCallback, pGestureCookie, &pGestureCookie->hCallback);
3633  if (nRetVal != XN_STATUS_OK)
3634  {
3635  xnOSFree(pGestureCookie);
3636  return (nRetVal);
3637  }
3638 
3639  hCallback = pGestureCookie;
3640 
3641  return (XN_STATUS_OK);
3642  }
3643 
3648  {
3649  GestureReadyForNextIntermediateStageCookie* pGestureCookie = (GestureReadyForNextIntermediateStageCookie*)hCallback;
3651  xnOSFree(pGestureCookie);
3652  }
3653 
3654  private:
3655  typedef struct GestureCookie
3656  {
3657  GestureRecognized recognizedHandler;
3658  GestureProgress progressHandler;
3659  void* pUserCookie;
3660  XnCallbackHandle hCallback;
3661  } GestureCookie;
3662 
3663  static void XN_CALLBACK_TYPE GestureRecognizedCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pIDPosition, const XnPoint3D* pEndPosition, void* pCookie)
3664  {
3665  GestureCookie* pGestureCookie = (GestureCookie*)pCookie;
3666  GestureGenerator gen(hNode);
3667  if (pGestureCookie->recognizedHandler != NULL)
3668  {
3669  pGestureCookie->recognizedHandler(gen, strGesture, pIDPosition, pEndPosition, pGestureCookie->pUserCookie);
3670  }
3671  }
3672 
3673  static void XN_CALLBACK_TYPE GestureProgressCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie)
3674  {
3675  GestureCookie* pGestureCookie = (GestureCookie*)pCookie;
3676  GestureGenerator gen(hNode);
3677  if (pGestureCookie->progressHandler != NULL)
3678  {
3679  pGestureCookie->progressHandler(gen, strGesture, pPosition, fProgress, pGestureCookie->pUserCookie);
3680  }
3681  }
3682 
3683  typedef struct GestureIntermediateStageCompletedCookie
3684  {
3686  void* pUserCookie;
3687  XnCallbackHandle hCallback;
3688  } GestureIntermediateStageCompletedCookie;
3689 
3690  static void XN_CALLBACK_TYPE GestureIntermediateStageCompletedCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie)
3691  {
3692  GestureIntermediateStageCompletedCookie* pGestureCookie = (GestureIntermediateStageCompletedCookie*)pCookie;
3693  GestureGenerator gen(hNode);
3694  if (pGestureCookie->handler != NULL)
3695  {
3696  pGestureCookie->handler(gen, strGesture, pPosition, pGestureCookie->pUserCookie);
3697  }
3698  }
3699 
3700  typedef struct GestureReadyForNextIntermediateStageCookie
3701  {
3703  void* pUserCookie;
3704  XnCallbackHandle hCallback;
3705  } GestureReadyForNextIntermediateStageCookie;
3706 
3707  static void XN_CALLBACK_TYPE GestureReadyForNextIntermediateStageCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie)
3708  {
3709  GestureReadyForNextIntermediateStageCookie* pGestureCookie = (GestureReadyForNextIntermediateStageCookie*)pCookie;
3710  GestureGenerator gen(hNode);
3711  if (pGestureCookie->handler != NULL)
3712  {
3713  pGestureCookie->handler(gen, strGesture, pPosition, pGestureCookie->pUserCookie);
3714  }
3715  }
3716  };
3717 
3723  {
3724  public:
3730  inline SceneAnalyzer(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
3731  inline SceneAnalyzer(const NodeWrapper& other) : MapGenerator(other) {}
3732 
3736  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
3737 
3741  inline void GetMetaData(SceneMetaData& metaData) const
3742  {
3744  }
3745 
3749  inline const XnLabel* GetLabelMap() const
3750  {
3751  return xnGetLabelMap(GetHandle());
3752  }
3753 
3757  inline XnStatus GetFloor(XnPlane3D& Plane) const
3758  {
3759  return xnGetFloor(GetHandle(), &Plane);
3760  }
3761  };
3762 
3768  {
3769  public:
3777 
3788  typedef void (XN_CALLBACK_TYPE* HandTouchingFOVEdge)(HandTouchingFOVEdgeCapability& touchingfov, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, XnDirection eDir, void* pCookie);
3793  {
3794  XnStatus nRetVal = XN_STATUS_OK;
3795 
3796  HandTouchingFOVEdgeCookie* pHandCookie;
3797  XN_VALIDATE_ALLOC(pHandCookie, HandTouchingFOVEdgeCookie);
3798  pHandCookie->handler = handler;
3799  pHandCookie->pUserCookie = pCookie;
3800 
3801  nRetVal = xnRegisterToHandTouchingFOVEdge(GetHandle(), HandTouchingFOVEdgeCB, pHandCookie, &pHandCookie->hCallback);
3802  if (nRetVal != XN_STATUS_OK)
3803  {
3804  xnOSFree(pHandCookie);
3805  return (nRetVal);
3806  }
3807 
3808  hCallback = pHandCookie;
3809 
3810  return (XN_STATUS_OK);
3811  }
3812 
3817  {
3818  HandTouchingFOVEdgeCookie* pHandCookie = (HandTouchingFOVEdgeCookie*)hCallback;
3819  xnUnregisterFromHandTouchingFOVEdge(GetHandle(), pHandCookie->hCallback);
3820  xnOSFree(pHandCookie);
3821  }
3822  private:
3823  typedef struct HandTouchingFOVEdgeCookie
3824  {
3825  HandTouchingFOVEdge handler;
3826  void* pUserCookie;
3827  XnCallbackHandle hCallback;
3828  } HandTouchingFOVEdgeCookie;
3829 
3830  static void XN_CALLBACK_TYPE HandTouchingFOVEdgeCB(XnNodeHandle hNode, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, XnDirection eDir, void* pCookie)
3831  {
3832  HandTouchingFOVEdgeCookie* pHandCookie = (HandTouchingFOVEdgeCookie*)pCookie;
3833  HandTouchingFOVEdgeCapability cap(hNode);
3834  if (pHandCookie->handler != NULL)
3835  {
3836  pHandCookie->handler(cap, user, pPosition, fTime, eDir, pHandCookie->pUserCookie);
3837  }
3838  }
3839 
3840  };
3845  class HandsGenerator : public Generator
3846  {
3847  public:
3853  inline HandsGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
3854  inline HandsGenerator(const NodeWrapper& other) : Generator(other) {}
3855 
3859  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
3860 
3870  typedef void (XN_CALLBACK_TYPE* HandCreate)(HandsGenerator& generator, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie);
3880  typedef void (XN_CALLBACK_TYPE* HandUpdate)(HandsGenerator& generator, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie);
3889  typedef void (XN_CALLBACK_TYPE* HandDestroy)(HandsGenerator& generator, XnUserID user, XnFloat fTime, void* pCookie);
3890 
3894  inline XnStatus RegisterHandCallbacks(HandCreate CreateCB, HandUpdate UpdateCB, HandDestroy DestroyCB, void* pCookie, XnCallbackHandle& hCallback)
3895  {
3896  XnStatus nRetVal = XN_STATUS_OK;
3897 
3898  HandCookie* pHandCookie;
3899  XN_VALIDATE_ALLOC(pHandCookie, HandCookie);
3900  pHandCookie->createHandler = CreateCB;
3901  pHandCookie->updateHandler = UpdateCB;
3902  pHandCookie->destroyHandler = DestroyCB;
3903  pHandCookie->pUserCookie = pCookie;
3904 
3905  nRetVal = xnRegisterHandCallbacks(GetHandle(), HandCreateCB, HandUpdateCB, HandDestroyCB, pHandCookie, &pHandCookie->hCallback);
3906  if (nRetVal != XN_STATUS_OK)
3907  {
3908  xnOSFree(pHandCookie);
3909  return (nRetVal);
3910  }
3911 
3912  hCallback = pHandCookie;
3913 
3914  return (XN_STATUS_OK);
3915  }
3916 
3921  {
3922  HandCookie* pHandCookie = (HandCookie*)hCallback;
3923  xnUnregisterHandCallbacks(GetHandle(), pHandCookie->hCallback);
3924  xnOSFree(pHandCookie);
3925  }
3926 
3931  {
3932  return xnStopTracking(GetHandle(), user);
3933  }
3934 
3939  {
3940  return xnStopTrackingAll(GetHandle());
3941  }
3942 
3946  inline XnStatus StartTracking(const XnPoint3D& ptPosition)
3947  {
3948  return xnStartTracking(GetHandle(), &ptPosition);
3949  }
3950 
3954  inline XnStatus SetSmoothing(XnFloat fSmoothingFactor)
3955  {
3956  return xnSetTrackingSmoothing(GetHandle(), fSmoothingFactor);
3957  }
3958 
3965  {
3967  }
3968 
3975  {
3977  }
3978 
3979  private:
3980  typedef struct HandCookie
3981  {
3982  HandCreate createHandler;
3983  HandUpdate updateHandler;
3984  HandDestroy destroyHandler;
3985  void* pUserCookie;
3986  XnCallbackHandle hCallback;
3987  } HandCookie;
3988 
3989  static void XN_CALLBACK_TYPE HandCreateCB(XnNodeHandle hNode, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie)
3990  {
3991  HandCookie* pHandCookie = (HandCookie*)pCookie;
3992  HandsGenerator gen(hNode);
3993  if (pHandCookie->createHandler != NULL)
3994  {
3995  pHandCookie->createHandler(gen, user, pPosition, fTime, pHandCookie->pUserCookie);
3996  }
3997  }
3998  static void XN_CALLBACK_TYPE HandUpdateCB(XnNodeHandle hNode, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie)
3999  {
4000  HandCookie* pHandCookie = (HandCookie*)pCookie;
4001  HandsGenerator gen(hNode);
4002  if (pHandCookie->updateHandler != NULL)
4003  {
4004  pHandCookie->updateHandler(gen, user, pPosition, fTime, pHandCookie->pUserCookie);
4005  }
4006  }
4007  static void XN_CALLBACK_TYPE HandDestroyCB(XnNodeHandle hNode, XnUserID user, XnFloat fTime, void* pCookie)
4008  {
4009  HandCookie* pHandCookie = (HandCookie*)pCookie;
4010  HandsGenerator gen(hNode);
4011  if (pHandCookie->destroyHandler != NULL)
4012  {
4013  pHandCookie->destroyHandler(gen, user, fTime, pHandCookie->pUserCookie);
4014  }
4015  }
4016  };
4017 
4023  {
4024  public:
4030  inline SkeletonCapability(XnNodeHandle hNode) : Capability(hNode) {}
4032 
4036  inline XnBool IsJointAvailable(XnSkeletonJoint eJoint) const
4037  {
4038  return xnIsJointAvailable(GetHandle(), eJoint);
4039  }
4040 
4044  inline XnBool IsProfileAvailable(XnSkeletonProfile eProfile) const
4045  {
4046  return xnIsProfileAvailable(GetHandle(), eProfile);
4047  }
4048 
4053  {
4054  return xnSetSkeletonProfile(GetHandle(), eProfile);
4055  }
4056 
4060  inline XnStatus SetJointActive(XnSkeletonJoint eJoint, XnBool bState)
4061  {
4062  return xnSetJointActive(GetHandle(), eJoint, bState);
4063  }
4064 
4068  XN_API_DEPRECATED("Use the version with one argument")
4069  inline XnBool IsJointActive(XnSkeletonJoint eJoint, XnBool /*bState*/) const
4070  {
4071  return xnIsJointActive(GetHandle(), eJoint);
4072  }
4073 
4077  inline XnBool IsJointActive(XnSkeletonJoint eJoint) const
4078  {
4079  return xnIsJointActive(GetHandle(), eJoint);
4080  }
4081 
4086  {
4087  return _RegisterToStateChange(xnRegisterToJointConfigurationChange, GetHandle(), handler, pCookie, hCallback);
4088  }
4089 
4094  {
4095  _UnregisterFromStateChange(xnUnregisterFromJointConfigurationChange, GetHandle(), hCallback);
4096  }
4097 
4101  inline XnStatus EnumerateActiveJoints(XnSkeletonJoint* pJoints, XnUInt16& nJoints) const
4102  {
4103  return xnEnumerateActiveJoints(GetHandle(), pJoints, &nJoints);
4104  }
4105 
4110  {
4111  return xnGetSkeletonJoint(GetHandle(), user, eJoint, &Joint);
4112  }
4113 
4118  {
4119  return xnGetSkeletonJointPosition(GetHandle(), user, eJoint, &Joint);
4120  }
4121 
4126  {
4127  return xnGetSkeletonJointOrientation(GetHandle(), user, eJoint, &Joint);
4128  }
4129 
4133  inline XnBool IsTracking(XnUserID user) const
4134  {
4135  return xnIsSkeletonTracking(GetHandle(), user);
4136  }
4137 
4141  inline XnBool IsCalibrated(XnUserID user) const
4142  {
4143 
4144  return xnIsSkeletonCalibrated(GetHandle(), user);
4145  }
4146 
4150  inline XnBool IsCalibrating(XnUserID user) const
4151  {
4152  return xnIsSkeletonCalibrating(GetHandle(), user);
4153  }
4154 
4158  inline XnStatus RequestCalibration(XnUserID user, XnBool bForce)
4159  {
4160  return xnRequestSkeletonCalibration(GetHandle(), user, bForce);
4161  }
4162 
4167  {
4168  return xnAbortSkeletonCalibration(GetHandle(), user);
4169  }
4170 
4174  inline XnStatus SaveCalibrationDataToFile(XnUserID user, const XnChar* strFileName)
4175  {
4176  return xnSaveSkeletonCalibrationDataToFile(GetHandle(), user, strFileName);
4177  }
4178 
4182  inline XnStatus LoadCalibrationDataFromFile(XnUserID user, const XnChar* strFileName)
4183  {
4184  return xnLoadSkeletonCalibrationDataFromFile(GetHandle(), user, strFileName);
4185  }
4186 
4190  inline XnStatus SaveCalibrationData(XnUserID user, XnUInt32 nSlot)
4191  {
4192  return xnSaveSkeletonCalibrationData(GetHandle(), user, nSlot);
4193  }
4194 
4198  inline XnStatus LoadCalibrationData(XnUserID user, XnUInt32 nSlot)
4199  {
4200  return xnLoadSkeletonCalibrationData(GetHandle(), user, nSlot);
4201  }
4202 
4206  inline XnStatus ClearCalibrationData(XnUInt32 nSlot)
4207  {
4208  return xnClearSkeletonCalibrationData(GetHandle(), nSlot);
4209  }
4210 
4214  inline XnBool IsCalibrationData(XnUInt32 nSlot) const
4215  {
4216  return xnIsSkeletonCalibrationData(GetHandle(), nSlot);
4217  }
4218 
4223  {
4224  return xnStartSkeletonTracking(GetHandle(), user);
4225  }
4226 
4231  {
4232  return xnStopSkeletonTracking(GetHandle(), user);
4233  }
4234 
4238  inline XnStatus Reset(XnUserID user)
4239  {
4240  return xnResetSkeleton(GetHandle(), user);
4241  }
4242 
4246  inline XnBool NeedPoseForCalibration() const
4247  {
4249  }
4250 
4254  inline XnStatus GetCalibrationPose(XnChar* strPose) const
4255  {
4256  return xnGetSkeletonCalibrationPose(GetHandle(), strPose);
4257  }
4258 
4262  inline XnStatus SetSmoothing(XnFloat fSmoothingFactor)
4263  {
4264  return xnSetSkeletonSmoothing(GetHandle(), fSmoothingFactor);
4265  }
4266 
4274  typedef void (XN_CALLBACK_TYPE* CalibrationStart)(SkeletonCapability& skeleton, XnUserID user, void* pCookie);
4283  typedef void (XN_CALLBACK_TYPE* CalibrationEnd)(SkeletonCapability& skeleton, XnUserID user, XnBool bSuccess, void* pCookie);
4284 
4288  inline XnStatus XN_API_DEPRECATED("Please use RegisterToCalibrationStart/Complete") RegisterCalibrationCallbacks(CalibrationStart CalibrationStartCB, CalibrationEnd CalibrationEndCB, void* pCookie, XnCallbackHandle& hCallback)
4289  {
4290  XnStatus nRetVal = XN_STATUS_OK;
4291 
4292  SkeletonCookie* pSkeletonCookie;
4293  XN_VALIDATE_ALLOC(pSkeletonCookie, SkeletonCookie);
4294  pSkeletonCookie->startHandler = CalibrationStartCB;
4295  pSkeletonCookie->endHandler = CalibrationEndCB;
4296  pSkeletonCookie->pUserCookie = pCookie;
4297 
4298 #pragma warning (push)
4299 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
4300  nRetVal = xnRegisterCalibrationCallbacks(GetHandle(), CalibrationStartBundleCallback, CalibrationEndBundleCallback, pSkeletonCookie, &pSkeletonCookie->hCallback);
4301 #pragma warning (pop)
4302  if (nRetVal != XN_STATUS_OK)
4303  {
4304  xnOSFree(pSkeletonCookie);
4305  return (nRetVal);
4306  }
4307 
4308  hCallback = pSkeletonCookie;
4309 
4310  return (XN_STATUS_OK);
4311  }
4312 
4316  inline void XN_API_DEPRECATED("Please use UnregisterFromCalibrationStart/Complete") UnregisterCalibrationCallbacks(XnCallbackHandle hCallback)
4317  {
4318  SkeletonCookie* pSkeletonCookie = (SkeletonCookie*)hCallback;
4319 #pragma warning (push)
4320 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
4321  xnUnregisterCalibrationCallbacks(GetHandle(), pSkeletonCookie->hCallback);
4322 #pragma warning (pop)
4323  xnOSFree(pSkeletonCookie);
4324  }
4325 
4329  inline XnStatus RegisterToCalibrationStart(CalibrationStart handler, void* pCookie, XnCallbackHandle& hCallback)
4330  {
4331  XnStatus nRetVal = XN_STATUS_OK;
4332  CalibrationStartCookie* pCalibrationCookie;
4333  XN_VALIDATE_ALLOC(pCalibrationCookie, CalibrationStartCookie);
4334  pCalibrationCookie->handler = handler;
4335  pCalibrationCookie->pUserCookie = pCookie;
4336  nRetVal = xnRegisterToCalibrationStart(GetHandle(), CalibrationStartCallback, pCalibrationCookie, &pCalibrationCookie->hCallback);
4337  if (nRetVal != XN_STATUS_OK)
4338  {
4339  xnOSFree(pCalibrationCookie);
4340  return nRetVal;
4341  }
4342  hCallback = pCalibrationCookie;
4343  return XN_STATUS_OK;
4344  }
4349  {
4350  CalibrationStartCookie* pCalibrationCookie = (CalibrationStartCookie*)hCallback;
4351  xnUnregisterFromCalibrationStart(GetHandle(), pCalibrationCookie->hCallback);
4352  xnOSFree(pCalibrationCookie);
4353  return XN_STATUS_OK;
4354  }
4355 
4364  typedef void (XN_CALLBACK_TYPE* CalibrationInProgress)(SkeletonCapability& skeleton, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie);
4365 
4370  {
4371  XnStatus nRetVal = XN_STATUS_OK;
4372 
4373  CalibrationInProgressCookie* pSkeletonCookie;
4374  XN_VALIDATE_ALLOC(pSkeletonCookie, CalibrationInProgressCookie);
4375  pSkeletonCookie->handler = handler;
4376  pSkeletonCookie->pUserCookie = pCookie;
4377 
4378  nRetVal = xnRegisterToCalibrationInProgress(GetHandle(), CalibrationInProgressCallback, pSkeletonCookie, &pSkeletonCookie->hCallback);
4379  if (nRetVal != XN_STATUS_OK)
4380  {
4381  xnOSFree(pSkeletonCookie);
4382  return (nRetVal);
4383  }
4384 
4385  hCallback = pSkeletonCookie;
4386 
4387  return (XN_STATUS_OK);
4388  }
4389 
4394  {
4395  CalibrationInProgressCookie* pSkeletonCookie = (CalibrationInProgressCookie*)hCallback;
4396  xnUnregisterFromCalibrationInProgress(GetHandle(), pSkeletonCookie->hCallback);
4397  xnOSFree(pSkeletonCookie);
4398  }
4399 
4408  typedef void (XN_CALLBACK_TYPE* CalibrationComplete)(SkeletonCapability& skeleton, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie);
4413  {
4414  XnStatus nRetVal = XN_STATUS_OK;
4415 
4416  CalibrationCompleteCookie* pSkeletonCookie;
4417  XN_VALIDATE_ALLOC(pSkeletonCookie, CalibrationCompleteCookie);
4418  pSkeletonCookie->handler = handler;
4419  pSkeletonCookie->pUserCookie = pCookie;
4420 
4421  nRetVal = xnRegisterToCalibrationComplete(GetHandle(), CalibrationCompleteCallback, pSkeletonCookie, &pSkeletonCookie->hCallback);
4422  if (nRetVal != XN_STATUS_OK)
4423  {
4424  xnOSFree(pSkeletonCookie);
4425  return (nRetVal);
4426  }
4427 
4428  hCallback = pSkeletonCookie;
4429 
4430  return (XN_STATUS_OK);
4431  }
4432 
4437  {
4438  CalibrationCompleteCookie* pSkeletonCookie = (CalibrationCompleteCookie*)hCallback;
4439  xnUnregisterFromCalibrationComplete(GetHandle(), pSkeletonCookie->hCallback);
4440  xnOSFree(pSkeletonCookie);
4441  }
4442  private:
4443  typedef struct SkeletonCookie
4444  {
4445  CalibrationStart startHandler;
4446  CalibrationEnd endHandler;
4447  void* pUserCookie;
4448  XnCallbackHandle hCallback;
4449  } SkeletonCookie;
4450 
4451  static void XN_CALLBACK_TYPE CalibrationStartBundleCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
4452  {
4453  SkeletonCookie* pSkeletonCookie = (SkeletonCookie*)pCookie;
4454  SkeletonCapability cap(hNode);
4455  if (pSkeletonCookie->startHandler != NULL)
4456  {
4457  pSkeletonCookie->startHandler(cap, user, pSkeletonCookie->pUserCookie);
4458  }
4459  }
4460 
4461  static void XN_CALLBACK_TYPE CalibrationEndBundleCallback(XnNodeHandle hNode, XnUserID user, XnBool bSuccess, void* pCookie)
4462  {
4463  SkeletonCookie* pSkeletonCookie = (SkeletonCookie*)pCookie;
4464  SkeletonCapability cap(hNode);
4465  if (pSkeletonCookie->endHandler != NULL)
4466  {
4467  pSkeletonCookie->endHandler(cap, user, bSuccess, pSkeletonCookie->pUserCookie);
4468  }
4469  }
4470  typedef struct CalibrationStartCookie
4471  {
4472  CalibrationStart handler;
4473  void* pUserCookie;
4474  XnCallbackHandle hCallback;
4475  } CalibrationStartCookie;
4476 
4477  static void XN_CALLBACK_TYPE CalibrationStartCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
4478  {
4479  CalibrationStartCookie* pCalibrationCookie = (CalibrationStartCookie*)pCookie;
4480  SkeletonCapability cap(hNode);
4481  if (pCalibrationCookie->handler != NULL)
4482  {
4483  pCalibrationCookie->handler(cap, user, pCalibrationCookie->pUserCookie);
4484  }
4485  }
4486  typedef struct CalibrationInProgressCookie
4487  {
4488  CalibrationInProgress handler;
4489  void* pUserCookie;
4490  XnCallbackHandle hCallback;
4491  } CalibrationInProgressCookie;
4492 
4493  static void XN_CALLBACK_TYPE CalibrationInProgressCallback(XnNodeHandle hNode, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie)
4494  {
4495  CalibrationInProgressCookie* pSkeletonCookie = (CalibrationInProgressCookie*)pCookie;
4496  SkeletonCapability cap(hNode);
4497  if (pSkeletonCookie->handler != NULL)
4498  {
4499  pSkeletonCookie->handler(cap, user, calibrationError, pSkeletonCookie->pUserCookie);
4500  }
4501  }
4502 
4503  typedef struct CalibrationCompleteCookie
4504  {
4505  CalibrationComplete handler;
4506  void* pUserCookie;
4507  XnCallbackHandle hCallback;
4508  } CalibrationCompleteCookie;
4509 
4510  static void XN_CALLBACK_TYPE CalibrationCompleteCallback(XnNodeHandle hNode, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie)
4511  {
4512  CalibrationCompleteCookie* pSkeletonCookie = (CalibrationCompleteCookie*)pCookie;
4513  SkeletonCapability cap(hNode);
4514  if (pSkeletonCookie->handler != NULL)
4515  {
4516  pSkeletonCookie->handler(cap, user, calibrationError, pSkeletonCookie->pUserCookie);
4517  }
4518  }
4519  };
4520 
4526  {
4527  public:
4535 
4544  typedef void (XN_CALLBACK_TYPE* PoseDetection)(PoseDetectionCapability& pose, const XnChar* strPose, XnUserID user, void* pCookie);
4545 
4549  inline XnUInt32 GetNumberOfPoses() const
4550  {
4551  return xnGetNumberOfPoses(GetHandle());
4552  }
4553 
4557  inline XnStatus GetAvailablePoses(XnChar** pstrPoses, XnUInt32& nPoses) const
4558  {
4559  return xnGetAvailablePoses(GetHandle(), pstrPoses, &nPoses);
4560  }
4564  inline XnStatus GetAllAvailablePoses(XnChar** pstrPoses, XnUInt32 nNameLength, XnUInt32& nPoses) const
4565  {
4566  return xnGetAllAvailablePoses(GetHandle(), pstrPoses, nNameLength, &nPoses);
4567  }
4568 
4572  inline XnStatus StartPoseDetection(const XnChar* strPose, XnUserID user)
4573  {
4574  return xnStartPoseDetection(GetHandle(), strPose, user);
4575  }
4576 
4581  {
4582  return xnStopPoseDetection(GetHandle(), user);
4583  }
4584 
4588  inline XnStatus XN_API_DEPRECATED("Please use RegisterToPoseDetected/RegisterToOutOfPose instead") RegisterToPoseCallbacks(PoseDetection PoseStartCB, PoseDetection PoseEndCB, void* pCookie, XnCallbackHandle& hCallback)
4589  {
4590  XnStatus nRetVal = XN_STATUS_OK;
4591 
4592  PoseCookie* pPoseCookie;
4593  XN_VALIDATE_ALLOC(pPoseCookie, PoseCookie);
4594  pPoseCookie->startHandler = PoseStartCB;
4595  pPoseCookie->endHandler = PoseEndCB;
4596  pPoseCookie->pPoseCookie = pCookie;
4597 
4598 #pragma warning (push)
4599 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
4600  nRetVal = xnRegisterToPoseCallbacks(GetHandle(), PoseDetectionStartBundleCallback, PoseDetectionStartEndBundleCallback, pPoseCookie, &pPoseCookie->hCallback);
4601 #pragma warning (pop)
4602  if (nRetVal != XN_STATUS_OK)
4603  {
4604  xnOSFree(pPoseCookie);
4605  return (nRetVal);
4606  }
4607 
4608  hCallback = pPoseCookie;
4609 
4610  return (XN_STATUS_OK);
4611  }
4612 
4616  inline void XN_API_DEPRECATED("Please use UnregisterFromPoseDetected/UnregisterFromOutOfPose instead") UnregisterFromPoseCallbacks(XnCallbackHandle hCallback)
4617  {
4618  PoseCookie* pPoseCookie = (PoseCookie*)hCallback;
4619 #pragma warning (push)
4620 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
4621  xnUnregisterFromPoseCallbacks(GetHandle(), pPoseCookie->hCallback);
4622 #pragma warning (pop)
4623  xnOSFree(pPoseCookie);
4624  }
4625 
4629  inline XnStatus RegisterToPoseDetected(PoseDetection handler, void* pCookie, XnCallbackHandle& hCallback)
4630  {
4631  XnStatus nRetVal = XN_STATUS_OK;
4632  PoseDetectionCookie* pPoseCookie;
4633  XN_VALIDATE_ALLOC(pPoseCookie, PoseDetectionCookie);
4634  pPoseCookie->handler = handler;
4635  pPoseCookie->pPoseCookie = pCookie;
4636 
4637  nRetVal = xnRegisterToPoseDetected(GetHandle(), PoseDetectionCallback, pPoseCookie, &pPoseCookie->hCallback);
4638  if (nRetVal != XN_STATUS_OK)
4639  {
4640  xnOSFree(pPoseCookie);
4641  return nRetVal;
4642  }
4643  hCallback = pPoseCookie;
4644  return XN_STATUS_OK;
4645  }
4649  inline XnStatus RegisterToOutOfPose(PoseDetection handler, void* pCookie, XnCallbackHandle& hCallback)
4650  {
4651  XnStatus nRetVal = XN_STATUS_OK;
4652  PoseDetectionCookie* pPoseCookie;
4653  XN_VALIDATE_ALLOC(pPoseCookie, PoseDetectionCookie);
4654  pPoseCookie->handler = handler;
4655  pPoseCookie->pPoseCookie = pCookie;
4656 
4657  nRetVal = xnRegisterToOutOfPose(GetHandle(), PoseDetectionCallback, pPoseCookie, &pPoseCookie->hCallback);
4658  if (nRetVal != XN_STATUS_OK)
4659  {
4660  xnOSFree(pPoseCookie);
4661  return nRetVal;
4662  }
4663  hCallback = pPoseCookie;
4664  return XN_STATUS_OK;
4665  }
4670  {
4671  PoseDetectionCookie* pPoseCookie = (PoseDetectionCookie*)hCallback;
4672  xnUnregisterFromPoseDetected(GetHandle(), pPoseCookie->hCallback);
4673  xnOSFree(pPoseCookie);
4674  }
4679  {
4680  PoseDetectionCookie* pPoseCookie = (PoseDetectionCookie*)hCallback;
4681  xnUnregisterFromOutOfPose(GetHandle(), pPoseCookie->hCallback);
4682  xnOSFree(pPoseCookie);
4683  }
4684 
4694  typedef void (XN_CALLBACK_TYPE* PoseInProgress)(PoseDetectionCapability& pose, const XnChar* strPose, XnUserID user, XnPoseDetectionStatus poseError, void* pCookie);
4698  inline XnStatus RegisterToPoseInProgress(PoseInProgress handler, void* pCookie, XnCallbackHandle& hCallback)
4699  {
4700  XnStatus nRetVal = XN_STATUS_OK;
4701 
4702  PoseInProgressCookie* pPoseCookie;
4703  XN_VALIDATE_ALLOC(pPoseCookie, PoseInProgressCookie);
4704  pPoseCookie->handler = handler;
4705  pPoseCookie->pPoseCookie = pCookie;
4706 
4707  nRetVal = xnRegisterToPoseDetectionInProgress(GetHandle(), PoseDetectionInProgressCallback, pPoseCookie, &pPoseCookie->hCallback);
4708  if (nRetVal != XN_STATUS_OK)
4709  {
4710  xnOSFree(pPoseCookie);
4711  return (nRetVal);
4712  }
4713 
4714  hCallback = pPoseCookie;
4715 
4716  return (XN_STATUS_OK);
4717  }
4718 
4723  {
4724  PoseInProgressCookie* pPoseCookie = (PoseInProgressCookie*)hCallback;
4725  xnUnregisterFromPoseDetectionInProgress(GetHandle(), pPoseCookie->hCallback);
4726  xnOSFree(pPoseCookie);
4727  }
4728 
4729  private:
4730  typedef struct PoseCookie
4731  {
4732  PoseDetection startHandler;
4733  PoseDetection endHandler;
4734  void* pPoseCookie;
4735  XnCallbackHandle hCallback;
4736  } PoseCookie;
4737 
4738  static void XN_CALLBACK_TYPE PoseDetectionStartBundleCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, void* pCookie)
4739  {
4740  PoseCookie* pPoseCookie = (PoseCookie*)pCookie;
4741  PoseDetectionCapability cap(hNode);
4742  if (pPoseCookie->startHandler != NULL)
4743  {
4744  pPoseCookie->startHandler(cap, strPose, user, pPoseCookie->pPoseCookie);
4745  }
4746  }
4747 
4748  static void XN_CALLBACK_TYPE PoseDetectionStartEndBundleCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, void* pCookie)
4749  {
4750  PoseCookie* pPoseCookie = (PoseCookie*)pCookie;
4751  PoseDetectionCapability cap(hNode);
4752  if (pPoseCookie->endHandler != NULL)
4753  {
4754  pPoseCookie->endHandler(cap, strPose, user, pPoseCookie->pPoseCookie);
4755  }
4756  }
4757  typedef struct PoseDetectionCookie
4758  {
4759  PoseDetection handler;
4760  void* pPoseCookie;
4761  XnCallbackHandle hCallback;
4762  } PoseDetectionCookie;
4763  static void XN_CALLBACK_TYPE PoseDetectionCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, void* pCookie)
4764  {
4765  PoseDetectionCookie* pPoseDetectionCookie = (PoseDetectionCookie*)pCookie;
4766  PoseDetectionCapability cap(hNode);
4767  if (pPoseDetectionCookie->handler != NULL)
4768  {
4769  pPoseDetectionCookie->handler(cap, strPose, user, pPoseDetectionCookie->pPoseCookie);
4770  }
4771  }
4772 
4773  typedef struct PoseInProgressCookie
4774  {
4775  PoseInProgress handler;
4776  void* pPoseCookie;
4777  XnCallbackHandle hCallback;
4778  } PoseInProgressCookie;
4779 
4780  static void XN_CALLBACK_TYPE PoseDetectionInProgressCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, XnPoseDetectionStatus poseErrors, void* pCookie)
4781  {
4782  PoseInProgressCookie* pPoseCookie = (PoseInProgressCookie*)pCookie;
4783  PoseDetectionCapability cap(hNode);
4784  if (pPoseCookie->handler != NULL)
4785  {
4786  pPoseCookie->handler(cap, strPose, user, poseErrors, pPoseCookie->pPoseCookie);
4787  }
4788  }
4789  };
4790 
4795  class UserGenerator : public Generator
4796  {
4797  public:
4803  inline UserGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
4804  inline UserGenerator(const NodeWrapper& other) : Generator(other) {}
4805 
4809  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
4810 
4811  typedef void (XN_CALLBACK_TYPE* UserHandler)(UserGenerator& generator, XnUserID user, void* pCookie);
4812 
4816  inline XnUInt16 GetNumberOfUsers() const
4817  {
4818  return xnGetNumberOfUsers(GetHandle());
4819  }
4820 
4824  inline XnStatus GetUsers(XnUserID aUsers[], XnUInt16& nUsers) const
4825  {
4826  return xnGetUsers(GetHandle(), aUsers, &nUsers);
4827  }
4828 
4832  inline XnStatus GetCoM(XnUserID user, XnPoint3D& com) const
4833  {
4834  return xnGetUserCoM(GetHandle(), user, &com);
4835  }
4836 
4841  {
4842  return xnGetUserPixels(GetHandle(), user, smd.GetUnderlying());
4843  }
4844 
4848  inline XnStatus RegisterUserCallbacks(UserHandler NewUserCB, UserHandler LostUserCB, void* pCookie, XnCallbackHandle& hCallback)
4849  {
4850  XnStatus nRetVal = XN_STATUS_OK;
4851 
4852  UserCookie* pUserCookie;
4853  XN_VALIDATE_ALLOC(pUserCookie, UserCookie);
4854  pUserCookie->newHandler = NewUserCB;
4855  pUserCookie->lostHandler = LostUserCB;
4856  pUserCookie->pUserCookie = pCookie;
4857 
4858  nRetVal = xnRegisterUserCallbacks(GetHandle(), NewUserCallback, LostUserCallback, pUserCookie, &pUserCookie->hCallback);
4859  if (nRetVal != XN_STATUS_OK)
4860  {
4861  xnOSFree(pUserCookie);
4862  return (nRetVal);
4863  }
4864 
4865  hCallback = pUserCookie;
4866 
4867  return (XN_STATUS_OK);
4868  }
4869 
4874  {
4875  UserCookie* pUserCookie = (UserCookie*)hCallback;
4876  xnUnregisterUserCallbacks(GetHandle(), pUserCookie->hCallback);
4877  xnOSFree(pUserCookie);
4878  }
4879 
4885  inline const SkeletonCapability GetSkeletonCap() const
4886  {
4887  return SkeletonCapability(GetHandle());
4888  }
4889 
4896  {
4897  return SkeletonCapability(GetHandle());
4898  }
4899 
4906  {
4908  }
4909 
4916  {
4918  }
4919 
4923  inline XnStatus RegisterToUserExit(UserHandler handler, void* pCookie, XnCallbackHandle& hCallback)
4924  {
4925  XnStatus nRetVal = XN_STATUS_OK;
4926 
4927  UserSingleCookie* pUserCookie;
4928  XN_VALIDATE_ALLOC(pUserCookie, UserSingleCookie);
4929  pUserCookie->handler = handler;
4930  pUserCookie->pUserCookie = pCookie;
4931 
4932  nRetVal = xnRegisterToUserExit(GetHandle(), UserSingleCallback, pUserCookie, &pUserCookie->hCallback);
4933  if (nRetVal != XN_STATUS_OK)
4934  {
4935  xnOSFree(pUserCookie);
4936  return (nRetVal);
4937  }
4938 
4939  hCallback = pUserCookie;
4940 
4941  return (XN_STATUS_OK);
4942  }
4943 
4948  {
4949  UserSingleCookie* pUserCookie = (UserSingleCookie*)hCallback;
4950  xnUnregisterFromUserExit(GetHandle(), pUserCookie->hCallback);
4951  xnOSFree(pUserCookie);
4952  }
4953 
4957  inline XnStatus RegisterToUserReEnter(UserHandler handler, void* pCookie, XnCallbackHandle& hCallback)
4958  {
4959  XnStatus nRetVal = XN_STATUS_OK;
4960 
4961  UserSingleCookie* pUserCookie;
4962  XN_VALIDATE_ALLOC(pUserCookie, UserSingleCookie);
4963  pUserCookie->handler = handler;
4964  pUserCookie->pUserCookie = pCookie;
4965 
4966  nRetVal = xnRegisterToUserReEnter(GetHandle(), UserSingleCallback, pUserCookie, &pUserCookie->hCallback);
4967  if (nRetVal != XN_STATUS_OK)
4968  {
4969  xnOSFree(pUserCookie);
4970  return (nRetVal);
4971  }
4972 
4973  hCallback = pUserCookie;
4974 
4975  return (XN_STATUS_OK);
4976  }
4977 
4982  {
4983  UserSingleCookie* pUserCookie = (UserSingleCookie*)hCallback;
4984  xnUnregisterFromUserReEnter(GetHandle(), pUserCookie->hCallback);
4985  xnOSFree(pUserCookie);
4986  }
4987 
4988  private:
4989  typedef struct UserCookie
4990  {
4991  UserHandler newHandler;
4992  UserHandler lostHandler;
4993  void* pUserCookie;
4994  XnCallbackHandle hCallback;
4995  } UserCookie;
4996 
4997  static void XN_CALLBACK_TYPE NewUserCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
4998  {
4999  UserCookie* pUserCookie = (UserCookie*)pCookie;
5000  UserGenerator gen(hNode);
5001  if (pUserCookie->newHandler != NULL)
5002  {
5003  pUserCookie->newHandler(gen, user, pUserCookie->pUserCookie);
5004  }
5005  }
5006 
5007  static void XN_CALLBACK_TYPE LostUserCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
5008  {
5009  UserCookie* pUserCookie = (UserCookie*)pCookie;
5010  UserGenerator gen(hNode);
5011  if (pUserCookie->lostHandler != NULL)
5012  {
5013  pUserCookie->lostHandler(gen, user, pUserCookie->pUserCookie);
5014  }
5015  }
5016 
5017  typedef struct UserSingleCookie
5018  {
5019  UserHandler handler;
5020  void* pUserCookie;
5021  XnCallbackHandle hCallback;
5022  } UserSingleCookie;
5023 
5024  static void XN_CALLBACK_TYPE UserSingleCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
5025  {
5026  UserSingleCookie* pUserCookie = (UserSingleCookie*)pCookie;
5027  UserGenerator gen(hNode);
5028  if (pUserCookie->handler != NULL)
5029  {
5030  pUserCookie->handler(gen, user, pUserCookie->pUserCookie);
5031  }
5032  }
5033  };
5034 
5039  class AudioGenerator : public Generator
5040  {
5041  public:
5047  inline AudioGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
5048  inline AudioGenerator(const NodeWrapper& other) : Generator(other) {}
5049 
5053  inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
5054 
5058  inline void GetMetaData(AudioMetaData& metaData) const
5059  {
5061  }
5062 
5066  inline const XnUChar* GetAudioBuffer() const
5067  {
5068  return xnGetAudioBuffer(GetHandle());
5069  }
5070 
5074  inline XnUInt32 GetSupportedWaveOutputModesCount() const
5075  {
5077  }
5078 
5082  inline XnStatus GetSupportedWaveOutputModes(XnWaveOutputMode* aSupportedModes, XnUInt32& nCount) const
5083  {
5084  return xnGetSupportedWaveOutputModes(GetHandle(), aSupportedModes, &nCount);
5085  }
5086 
5090  inline XnStatus SetWaveOutputMode(const XnWaveOutputMode& OutputMode)
5091  {
5092  return xnSetWaveOutputMode(GetHandle(), &OutputMode);
5093  }
5094 
5098  inline XnStatus GetWaveOutputMode(XnWaveOutputMode& OutputMode) const
5099  {
5100  return xnGetWaveOutputMode(GetHandle(), &OutputMode);
5101  }
5102 
5107  {
5108  return _RegisterToStateChange(xnRegisterToWaveOutputModeChanges, GetHandle(), handler, pCookie, hCallback);
5109  }
5110 
5115  {
5116  _UnregisterFromStateChange(xnUnregisterFromWaveOutputModeChanges, GetHandle(), hCallback);
5117  }
5118  };
5119 
5125  {
5126  public:
5132  inline MockAudioGenerator(XnNodeHandle hNode = NULL) : AudioGenerator(hNode) {}
5133  inline MockAudioGenerator(const NodeWrapper& other) : AudioGenerator(other) {}
5134 
5141  XnStatus Create(Context& context, const XnChar* strName = NULL);
5142 
5149  XnStatus CreateBasedOn(AudioGenerator& other, const XnChar* strName = NULL);
5150 
5154  inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnUInt8* pAudioBuffer)
5155  {
5156  return xnMockAudioSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pAudioBuffer);
5157  }
5158 
5166  inline XnStatus SetData(const AudioMetaData& audioMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
5167  {
5168  return SetData(nFrameID, nTimestamp, audioMD.DataSize(), audioMD.Data());
5169  }
5170 
5176  inline XnStatus SetData(const AudioMetaData& audioMD)
5177  {
5178  return SetData(audioMD, audioMD.FrameID(), audioMD.Timestamp());
5179  }
5180  };
5181 
5183  {
5184  public:
5185  MockRawGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
5186  MockRawGenerator(const NodeWrapper& other) : Generator(other) {}
5187 
5188  inline XnStatus Create(Context& context, const XnChar* strName = NULL);
5189 
5190  inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const void* pData)
5191  {
5192  return xnMockRawSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pData);
5193  }
5194 
5195  };
5196 
5201  class Codec : public ProductionNode
5202  {
5203  public:
5209  inline Codec(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
5210  inline Codec(const NodeWrapper& other) : ProductionNode(other) {}
5211 
5215  inline XnStatus Create(Context& context, XnCodecID codecID, ProductionNode& initializerNode);
5216 
5220  inline XnCodecID GetCodecID() const
5221  {
5222  return xnGetCodecID(GetHandle());
5223  }
5224 
5228  inline XnStatus EncodeData(const void* pSrc, XnUInt32 nSrcSize, void* pDst, XnUInt32 nDstSize, XnUInt* pnBytesWritten) const
5229  {
5230  return xnEncodeData(GetHandle(), pSrc, nSrcSize, pDst, nDstSize, pnBytesWritten);
5231  }
5232 
5236  inline XnStatus DecodeData(const void* pSrc, XnUInt32 nSrcSize, void* pDst, XnUInt32 nDstSize, XnUInt* pnBytesWritten) const
5237  {
5238  return xnDecodeData(GetHandle(), pSrc, nSrcSize, pDst, nDstSize, pnBytesWritten);
5239  }
5240  };
5241 
5247  {
5248  public:
5254  inline ScriptNode(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
5255  inline ScriptNode(const NodeWrapper& other) : ProductionNode(other) {}
5256 
5257  inline const XnChar* GetSupportedFormat()
5258  {
5260  }
5261 
5262  inline XnStatus LoadScriptFromFile(const XnChar* strFileName)
5263  {
5264  return xnLoadScriptFromFile(GetHandle(), strFileName);
5265  }
5266 
5267  inline XnStatus LoadScriptFromString(const XnChar* strScript)
5268  {
5269  return xnLoadScriptFromString(GetHandle(), strScript);
5270  }
5271 
5272  inline XnStatus Run(EnumerationErrors* pErrors);
5273  };
5274 
5275  //---------------------------------------------------------------------------
5276  // EnumerationErrors
5277  //---------------------------------------------------------------------------
5283  {
5284  public:
5286  inline EnumerationErrors() : m_pErrors(NULL), m_bAllocated(TRUE) { xnEnumerationErrorsAllocate(&m_pErrors); }
5287 
5294  inline EnumerationErrors(XnEnumerationErrors* pErrors, XnBool bOwn = FALSE) : m_pErrors(pErrors), m_bAllocated(bOwn) {}
5295 
5298 
5300  class Iterator
5301  {
5302  public:
5303  friend class EnumerationErrors;
5304 
5310  XnBool operator==(const Iterator& other) const
5311  {
5312  return m_it == other.m_it;
5313  }
5314 
5320  XnBool operator!=(const Iterator& other) const
5321  {
5322  return m_it != other.m_it;
5323  }
5324 
5330  {
5331  m_it = xnEnumerationErrorsGetNext(m_it);
5332  return *this;
5333  }
5334 
5339  inline Iterator operator++(int)
5340  {
5341  return Iterator(xnEnumerationErrorsGetNext(m_it));
5342  }
5343 
5348 
5349  private:
5350  inline Iterator(XnEnumerationErrorsIterator it) : m_it(it) {}
5351 
5353  };
5354 
5356  inline Iterator Begin() const { return Iterator(xnEnumerationErrorsGetFirst(m_pErrors)); }
5358  inline Iterator End() const { return Iterator(NULL); }
5359 
5363  inline XnStatus ToString(XnChar* csBuffer, XnUInt32 nSize)
5364  {
5365  return xnEnumerationErrorsToString(m_pErrors, csBuffer, nSize);
5366  }
5367 
5371  inline void Free()
5372  {
5373  if (m_bAllocated)
5374  {
5375  xnEnumerationErrorsFree(m_pErrors);
5376  m_pErrors = NULL;
5377  m_bAllocated = FALSE;
5378  }
5379  }
5380 
5382  inline XnEnumerationErrors* GetUnderlying() { return m_pErrors; }
5383 
5384  private:
5385  XnEnumerationErrors* m_pErrors;
5386  XnBool m_bAllocated;
5387  };
5388 
5389  //---------------------------------------------------------------------------
5390  // Context
5391  //---------------------------------------------------------------------------
5392 
5397  class Context
5398  {
5399  public:
5401  inline Context() : m_pContext(NULL), m_bUsingDeprecatedAPI(FALSE), m_bAllocated(FALSE), m_hShuttingDownCallback(NULL) {}
5402 
5408  inline Context(XnContext* pContext) : m_pContext(NULL), m_bUsingDeprecatedAPI(FALSE), m_bAllocated(FALSE), m_hShuttingDownCallback(NULL)
5409  {
5410  SetHandle(pContext);
5411  }
5412 
5419  inline Context(const Context& other) : m_pContext(NULL), m_bUsingDeprecatedAPI(FALSE), m_bAllocated(FALSE), m_hShuttingDownCallback(NULL)
5420  {
5421  SetHandle(other.m_pContext);
5422  }
5423 
5426  {
5427  SetHandle(NULL);
5428  }
5429 
5430  inline Context& operator=(const Context& other)
5431  {
5432  SetHandle(other.m_pContext);
5433  return *this;
5434  }
5435 
5437  inline XnContext* GetUnderlyingObject() const { return m_pContext; }
5438 
5442  inline XnStatus Init()
5443  {
5444  XnContext* pContext = NULL;
5445  XnStatus nRetVal = xnInit(&pContext);
5446  XN_IS_STATUS_OK(nRetVal);
5447 
5448  TakeOwnership(pContext);
5449  m_bAllocated = TRUE;
5450 
5451  return (XN_STATUS_OK);
5452  }
5453 
5457  inline XnStatus XN_API_DEPRECATED("Use other overload!") RunXmlScript(const XnChar* strScript, EnumerationErrors* pErrors = NULL)
5458  {
5459  m_bUsingDeprecatedAPI = TRUE;
5460  #pragma warning (push)
5461  #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
5462  return xnContextRunXmlScript(m_pContext, strScript, pErrors == NULL ? NULL : pErrors->GetUnderlying());
5463  #pragma warning (pop)
5464  }
5465 
5469  inline XnStatus RunXmlScript(const XnChar* strScript, ScriptNode& scriptNode, EnumerationErrors* pErrors = NULL)
5470  {
5471  XnStatus nRetVal = XN_STATUS_OK;
5472 
5473  XnNodeHandle hScriptNode;
5474  nRetVal = xnContextRunXmlScriptEx(m_pContext, strScript, pErrors == NULL ? NULL : pErrors->GetUnderlying(), &hScriptNode);
5475  XN_IS_STATUS_OK(nRetVal);
5476 
5477  scriptNode.TakeOwnership(hScriptNode);
5478 
5479  return (XN_STATUS_OK);
5480  }
5481 
5485  inline XnStatus XN_API_DEPRECATED("Use other overload!") RunXmlScriptFromFile(const XnChar* strFileName, EnumerationErrors* pErrors = NULL)
5486  {
5487  m_bUsingDeprecatedAPI = TRUE;
5488  #pragma warning (push)
5489  #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
5490  return xnContextRunXmlScriptFromFile(m_pContext, strFileName, pErrors == NULL ? NULL : pErrors->GetUnderlying());
5491  #pragma warning (pop)
5492  }
5493 
5497  inline XnStatus RunXmlScriptFromFile(const XnChar* strFileName, ScriptNode& scriptNode, EnumerationErrors* pErrors = NULL)
5498  {
5499  XnStatus nRetVal = XN_STATUS_OK;
5500 
5501  XnNodeHandle hScriptNode;
5502  nRetVal = xnContextRunXmlScriptFromFileEx(m_pContext, strFileName, pErrors == NULL ? NULL : pErrors->GetUnderlying(), &hScriptNode);
5503  XN_IS_STATUS_OK(nRetVal);
5504 
5505  scriptNode.TakeOwnership(hScriptNode);
5506 
5507  return (XN_STATUS_OK);
5508  }
5509 
5513  inline XnStatus XN_API_DEPRECATED("Use other overload!") InitFromXmlFile(const XnChar* strFileName, EnumerationErrors* pErrors = NULL)
5514  {
5515  XnContext* pContext = NULL;
5516  m_bUsingDeprecatedAPI = TRUE;
5517 
5518  #pragma warning (push)
5519  #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
5520  XnStatus nRetVal = xnInitFromXmlFile(strFileName, &pContext, pErrors == NULL ? NULL : pErrors->GetUnderlying());
5521  #pragma warning (pop)
5522  XN_IS_STATUS_OK(nRetVal);
5523 
5524  TakeOwnership(pContext);
5525  m_bAllocated = TRUE;
5526 
5527  return (XN_STATUS_OK);
5528  }
5529 
5533  inline XnStatus InitFromXmlFile(const XnChar* strFileName, ScriptNode& scriptNode, EnumerationErrors* pErrors = NULL)
5534  {
5535  XnContext* pContext = NULL;
5536 
5537  XnNodeHandle hScriptNode;
5538  XnStatus nRetVal = xnInitFromXmlFileEx(strFileName, &pContext, pErrors == NULL ? NULL : pErrors->GetUnderlying(), &hScriptNode);
5539  XN_IS_STATUS_OK(nRetVal);
5540 
5541  scriptNode.TakeOwnership(hScriptNode);
5542  TakeOwnership(pContext);
5543  m_bAllocated = TRUE;
5544 
5545  return (XN_STATUS_OK);
5546  }
5547 
5551  inline XnStatus XN_API_DEPRECATED("Use other overload!") OpenFileRecording(const XnChar* strFileName)
5552  {
5553  m_bUsingDeprecatedAPI = TRUE;
5554  #pragma warning (push)
5555  #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
5556  return xnContextOpenFileRecording(m_pContext, strFileName);
5557  #pragma warning (pop)
5558  }
5559 
5563  inline XnStatus OpenFileRecording(const XnChar* strFileName, ProductionNode& playerNode)
5564  {
5565  XnStatus nRetVal = XN_STATUS_OK;
5566 
5567  XnNodeHandle hPlayer;
5568  nRetVal = xnContextOpenFileRecordingEx(m_pContext, strFileName, &hPlayer);
5569  XN_IS_STATUS_OK(nRetVal);
5570 
5571  playerNode.TakeOwnership(hPlayer);
5572 
5573  return (XN_STATUS_OK);
5574  }
5575 
5579  inline XnStatus CreateMockNode(XnProductionNodeType type, const XnChar* strName, ProductionNode& mockNode)
5580  {
5581  XnStatus nRetVal = XN_STATUS_OK;
5582 
5583  XnNodeHandle hMockNode;
5584  nRetVal = xnCreateMockNode(m_pContext, type, strName, &hMockNode);
5585  XN_IS_STATUS_OK(nRetVal);
5586 
5587  mockNode.TakeOwnership(hMockNode);
5588 
5589  return (XN_STATUS_OK);
5590  }
5591 
5595  inline XnStatus CreateMockNodeBasedOn(ProductionNode& originalNode, const XnChar* strName, ProductionNode& mockNode)
5596  {
5597  XnStatus nRetVal = XN_STATUS_OK;
5598 
5599  XnNodeHandle hMockNode;
5600  nRetVal = xnCreateMockNodeBasedOn(m_pContext, originalNode, strName, &hMockNode);
5601  XN_IS_STATUS_OK(nRetVal);
5602 
5603  mockNode.TakeOwnership(hMockNode);
5604 
5605  return (XN_STATUS_OK);
5606  }
5607 
5611  inline XnStatus CreateCodec(XnCodecID codecID, ProductionNode& initializerNode, Codec& codec)
5612  {
5613  XnStatus nRetVal = XN_STATUS_OK;
5614 
5615  XnNodeHandle hCodec;
5616  nRetVal = xnCreateCodec(m_pContext, codecID, initializerNode.GetHandle(), &hCodec);
5617  XN_IS_STATUS_OK(nRetVal);
5618 
5619  codec.TakeOwnership(hCodec);
5620 
5621  return (XN_STATUS_OK);
5622  }
5623 
5627  inline XnStatus AddRef()
5628  {
5629  return xnContextAddRef(m_pContext);
5630  }
5631 
5635  inline void Release()
5636  {
5637  SetHandle(NULL);
5638  }
5639 
5643  inline void XN_API_DEPRECATED("You may use Release() instead, or count on dtor") Shutdown()
5644  {
5645  if (m_pContext != NULL)
5646  {
5647  #pragma warning (push)
5648  #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
5649  xnShutdown(m_pContext);
5650  #pragma warning (pop)
5651  m_pContext = NULL;
5652  }
5653  }
5654 
5658  inline XnStatus AddLicense(const XnLicense& License)
5659  {
5660  return xnAddLicense(m_pContext, &License);
5661  }
5662 
5666  inline XnStatus EnumerateLicenses(XnLicense*& aLicenses, XnUInt32& nCount) const
5667  {
5668  return xnEnumerateLicenses(m_pContext, &aLicenses, &nCount);
5669  }
5670 
5674  inline static void FreeLicensesList(XnLicense aLicenses[])
5675  {
5676  xnFreeLicensesList(aLicenses);
5677  }
5678 
5682  XnStatus EnumerateProductionTrees(XnProductionNodeType Type, const Query* pQuery, NodeInfoList& TreesList, EnumerationErrors* pErrors = NULL) const
5683  {
5684  XnStatus nRetVal = XN_STATUS_OK;
5685 
5686  const XnNodeQuery* pInternalQuery = (pQuery != NULL) ? pQuery->GetUnderlyingObject() : NULL;
5687 
5688  XnNodeInfoList* pList = NULL;
5689  nRetVal = xnEnumerateProductionTrees(m_pContext, Type, pInternalQuery, &pList, pErrors == NULL ? NULL : pErrors->GetUnderlying());
5690  XN_IS_STATUS_OK(nRetVal);
5691 
5692  TreesList.ReplaceUnderlyingObject(pList);
5693 
5694  return (XN_STATUS_OK);
5695  }
5696 
5701  {
5702  XnStatus nRetVal = XN_STATUS_OK;
5703 
5704  XnNodeQuery* pInternalQuery = (pQuery != NULL) ? pQuery->GetUnderlyingObject() : NULL;
5705 
5706  XnNodeHandle hNode;
5707  nRetVal = xnCreateAnyProductionTree(m_pContext, type, pInternalQuery, &hNode, pErrors == NULL ? NULL : pErrors->GetUnderlying());
5708  XN_IS_STATUS_OK(nRetVal);
5709 
5710  node.TakeOwnership(hNode);
5711 
5712  return (XN_STATUS_OK);
5713  }
5714 
5718  XnStatus XN_API_DEPRECATED("Please use other overload") CreateProductionTree(NodeInfo& Tree)
5719  {
5720  XnStatus nRetVal = XN_STATUS_OK;
5721 
5722  XnNodeHandle hNode;
5723  nRetVal = xnCreateProductionTree(m_pContext, Tree, &hNode);
5724  XN_IS_STATUS_OK(nRetVal);
5725 
5726  Tree.m_bOwnerOfNode = TRUE;
5727 
5728  return (XN_STATUS_OK);
5729  }
5730 
5735  {
5736  XnStatus nRetVal = XN_STATUS_OK;
5737 
5738  XnNodeHandle hNode;
5739  nRetVal = xnCreateProductionTree(m_pContext, Tree, &hNode);
5740  XN_IS_STATUS_OK(nRetVal);
5741 
5742  node.TakeOwnership(hNode);
5743 
5744  return (XN_STATUS_OK);
5745  }
5746 
5751  {
5752  XnNodeInfoList* pList;
5753  XnStatus nRetVal = xnEnumerateExistingNodes(m_pContext, &pList);
5754  XN_IS_STATUS_OK(nRetVal);
5755 
5756  list.ReplaceUnderlyingObject(pList);
5757 
5758  return (XN_STATUS_OK);
5759  }
5760 
5765  {
5766  XnNodeInfoList* pList;
5767  XnStatus nRetVal = xnEnumerateExistingNodesByType(m_pContext, type, &pList);
5768  XN_IS_STATUS_OK(nRetVal);
5769 
5770  list.ReplaceUnderlyingObject(pList);
5771 
5772  return (XN_STATUS_OK);
5773  }
5774 
5779  {
5780  XnStatus nRetVal = XN_STATUS_OK;
5781 
5782  XnNodeHandle hNode;
5783  nRetVal = xnFindExistingRefNodeByType(m_pContext, type, &hNode);
5784  XN_IS_STATUS_OK(nRetVal);
5785 
5786  node.TakeOwnership(hNode);
5787 
5788  return (XN_STATUS_OK);
5789  }
5790 
5794  XnStatus GetProductionNodeByName(const XnChar* strInstanceName, ProductionNode& node) const
5795  {
5796  XnStatus nRetVal = XN_STATUS_OK;
5797 
5798  XnNodeHandle hNode;
5799  nRetVal = xnGetRefNodeHandleByName(m_pContext, strInstanceName, &hNode);
5800  XN_IS_STATUS_OK(nRetVal);
5801 
5802  node.TakeOwnership(hNode);
5803 
5804  return (XN_STATUS_OK);
5805  }
5806 
5810  XnStatus GetProductionNodeInfoByName(const XnChar* strInstanceName, NodeInfo& nodeInfo) const
5811  {
5812  XnStatus nRetVal = XN_STATUS_OK;
5813 
5814  XnNodeHandle hNode;
5815  nRetVal = xnGetRefNodeHandleByName(m_pContext, strInstanceName, &hNode);
5816  XN_IS_STATUS_OK(nRetVal);
5817 
5818  xnProductionNodeRelease(hNode);
5819 
5820  nodeInfo = NodeInfo(xnGetNodeInfo(hNode));
5821 
5822  return (XN_STATUS_OK);
5823  }
5824 
5829  {
5830  return xnStartGeneratingAll(m_pContext);
5831  }
5832 
5837  {
5838  return xnStopGeneratingAll(m_pContext);
5839  }
5840 
5844  inline XnStatus SetGlobalMirror(XnBool bMirror)
5845  {
5846  return xnSetGlobalMirror(m_pContext, bMirror);
5847  }
5848 
5852  inline XnBool GetGlobalMirror()
5853  {
5854  return xnGetGlobalMirror(m_pContext);
5855  }
5856 
5861  {
5862  return xnGetGlobalErrorState(m_pContext);
5863  }
5864 
5869  {
5870  return xnRegisterToGlobalErrorStateChange(m_pContext, handler, pCookie, &hCallback);
5871  }
5872 
5878  {
5879  xnUnregisterFromGlobalErrorStateChange(m_pContext, hCallback);
5880  }
5881 
5886  {
5887  return xnWaitAndUpdateAll(m_pContext);
5888  }
5889 
5894  {
5895  return xnWaitAnyUpdateAll(m_pContext);
5896  }
5897 
5902  {
5903  return xnWaitOneUpdateAll(m_pContext, node.GetHandle());
5904  }
5905 
5910  {
5911  return xnWaitNoneUpdateAll(m_pContext);
5912  }
5913 
5917  inline XnStatus AutoEnumerateOverSingleInput(NodeInfoList& List, XnProductionNodeDescription& description, const XnChar* strCreationInfo, XnProductionNodeType InputType, EnumerationErrors* pErrors, Query* pQuery = NULL) const
5918  {
5919  return xnAutoEnumerateOverSingleInput(m_pContext, List.GetUnderlyingObject(), &description, strCreationInfo, InputType, pErrors == NULL ? NULL : pErrors->GetUnderlying(), pQuery == NULL ? NULL : pQuery->GetUnderlyingObject());
5920  }
5921 
5923  inline void SetHandle(XnContext* pContext)
5924  {
5925  if (m_pContext == pContext)
5926  {
5927  return;
5928  }
5929 
5930  if (m_pContext != NULL)
5931  {
5932  if (m_bUsingDeprecatedAPI && m_bAllocated)
5933  {
5934  // Backwards compatibility: call shutdown instead of release, to make old programs get the
5935  // exact same behavior they used to have.
5936  xnForceShutdown(m_pContext);
5937  }
5938  else
5939  {
5940  xnContextUnregisterFromShutdown(m_pContext, m_hShuttingDownCallback);
5941  xnContextRelease(m_pContext);
5942  }
5943  }
5944 
5945  if (pContext != NULL)
5946  {
5947  XnStatus nRetVal = xnContextAddRef(pContext);
5948  XN_ASSERT(nRetVal == XN_STATUS_OK);
5949 
5950  nRetVal = xnContextRegisterForShutdown(pContext, ContextShuttingDownCallback, this, &m_hShuttingDownCallback);
5951  XN_ASSERT(nRetVal == XN_STATUS_OK);
5952  }
5953 
5954  m_pContext = pContext;
5955  }
5956 
5957  inline void TakeOwnership(XnContext* pContext)
5958  {
5959  SetHandle(pContext);
5960 
5961  if (pContext != NULL)
5962  {
5963  xnContextRelease(pContext);
5964  }
5965  }
5966 
5967  private:
5968  static void XN_CALLBACK_TYPE ContextShuttingDownCallback(XnContext* /*pContext*/, void* pCookie)
5969  {
5970  Context* pThis = (Context*)pCookie;
5971  pThis->m_pContext = NULL;
5972  }
5973 
5974  XnContext* m_pContext;
5975  XnBool m_bUsingDeprecatedAPI;
5976  XnBool m_bAllocated;
5977  XnCallbackHandle m_hShuttingDownCallback;
5978  };
5979 
5985  {
5986  public:
5992  inline Resolution(XnResolution res) : m_Res(res)
5993  {
5994  m_nXRes = xnResolutionGetXRes(res);
5995  m_nYRes = xnResolutionGetYRes(res);
5996  m_strName = xnResolutionGetName(res);
5997  }
5998 
6005  inline Resolution(XnUInt32 xRes, XnUInt32 yRes) : m_nXRes(xRes), m_nYRes(yRes)
6006  {
6007  m_Res = xnResolutionGetFromXYRes(xRes, yRes);
6008  m_strName = xnResolutionGetName(m_Res);
6009  }
6010 
6016  inline Resolution(const XnChar* strName)
6017  {
6018  m_Res = xnResolutionGetFromName(strName);
6019  m_nXRes = xnResolutionGetXRes(m_Res);
6020  m_nYRes = xnResolutionGetYRes(m_Res);
6021  m_strName = xnResolutionGetName(m_Res);
6022  }
6023 
6025  inline XnResolution GetResolution() const { return m_Res; }
6027  inline XnUInt32 GetXResolution() const { return m_nXRes; }
6029  inline XnUInt32 GetYResolution() const { return m_nYRes; }
6031  inline const XnChar* GetName() const { return m_strName; }
6032 
6033  private:
6034  XnResolution m_Res;
6035  XnUInt32 m_nXRes;
6036  XnUInt32 m_nYRes;
6037  const XnChar* m_strName;
6038  };
6039 
6040  //---------------------------------------------------------------------------
6041  // Functions Implementation
6042  //---------------------------------------------------------------------------
6044  {
6045  return xnNodeQueryFilterList(context.GetUnderlyingObject(), query.GetUnderlyingObject(), m_pList);
6046  }
6047 
6048  inline void ProductionNode::GetContext(Context& context) const
6049  {
6051  }
6052 
6054  {
6055  if (m_pNeededNodes == NULL)
6056  {
6057  XnNodeInfoList* pList = xnNodeInfoGetNeededNodes(m_pInfo);
6058  m_pNeededNodes = XN_NEW(NodeInfoList, pList);
6059  }
6060 
6061  return *m_pNeededNodes;
6062  }
6063 
6064  inline void NodeInfo::SetUnderlyingObject(XnNodeInfo* pInfo)
6065  {
6066  if (m_pNeededNodes != NULL)
6067  {
6068  XN_DELETE(m_pNeededNodes);
6069  }
6070 
6071  m_bOwnerOfNode = FALSE;
6072  m_pInfo = pInfo;
6073  m_pNeededNodes = NULL;
6074  }
6075 
6077  {
6078  return xnCanFrameSyncWith(GetHandle(), other.GetHandle());
6079  }
6080 
6082  {
6083  return xnFrameSyncWith(GetHandle(), other.GetHandle());
6084  }
6085 
6087  {
6088  return xnStopFrameSyncWith(GetHandle(), other.GetHandle());
6089  }
6090 
6092  {
6093  return xnIsFrameSyncedWith(GetHandle(), other.GetHandle());
6094  }
6095 
6097  {
6098  if (m_pInfo == NULL)
6099  {
6100  return XN_STATUS_INVALID_OPERATION;
6101  }
6102 
6103  XnNodeHandle hNode = xnNodeInfoGetRefHandle(m_pInfo);
6104  node.TakeOwnership(hNode);
6105 
6106  if (m_bOwnerOfNode)
6107  {
6108  xnProductionNodeRelease(hNode);
6109  }
6110 
6111  return (XN_STATUS_OK);
6112  }
6113 
6114  //---------------------------------------------------------------------------
6115  // Node creation functions
6116  //---------------------------------------------------------------------------
6117 
6118  inline XnStatus Device::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6119  {
6120  XnNodeHandle hNode;
6121  XnStatus nRetVal = xnCreateDevice(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6122  XN_IS_STATUS_OK(nRetVal);
6123  TakeOwnership(hNode);
6124  return (XN_STATUS_OK);
6125  }
6126 
6127  inline XnStatus Recorder::Create(Context& context, const XnChar* strFormatName /*= NULL*/)
6128  {
6129  XnNodeHandle hNode;
6130  XnStatus nRetVal = xnCreateRecorder(context.GetUnderlyingObject(), strFormatName, &hNode);
6131  XN_IS_STATUS_OK(nRetVal);
6132  TakeOwnership(hNode);
6133  return (XN_STATUS_OK);
6134  }
6135 
6136  inline XnStatus Player::Create(Context& context, const XnChar* strFormatName)
6137  {
6138  XnNodeHandle hNode;
6139  XnStatus nRetVal = xnCreatePlayer(context.GetUnderlyingObject(), strFormatName, &hNode);
6140  XN_IS_STATUS_OK(nRetVal);
6141  TakeOwnership(hNode);
6142  return (XN_STATUS_OK);
6143  }
6144 
6145  inline XnStatus DepthGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6146  {
6147  XnNodeHandle hNode;
6148  XnStatus nRetVal = xnCreateDepthGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6149  XN_IS_STATUS_OK(nRetVal);
6150  TakeOwnership(hNode);
6151  return (XN_STATUS_OK);
6152  }
6153 
6154  inline XnStatus MockDepthGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
6155  {
6156  XnNodeHandle hNode;
6157  XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_DEPTH, strName, &hNode);
6158  XN_IS_STATUS_OK(nRetVal);
6159  TakeOwnership(hNode);
6160  return (XN_STATUS_OK);
6161  }
6162 
6163  inline XnStatus MockDepthGenerator::CreateBasedOn(DepthGenerator& other, const XnChar* strName /* = NULL */)
6164  {
6165  Context context;
6166  other.GetContext(context);
6167  XnNodeHandle hNode;
6168  XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
6169  XN_IS_STATUS_OK(nRetVal);
6170  TakeOwnership(hNode);
6171  return (XN_STATUS_OK);
6172  }
6173 
6174  inline XnStatus ImageGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6175  {
6176  XnNodeHandle hNode;
6177  XnStatus nRetVal = xnCreateImageGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6178  XN_IS_STATUS_OK(nRetVal);
6179  TakeOwnership(hNode);
6180  return (XN_STATUS_OK);
6181  }
6182 
6183  inline XnStatus MockImageGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
6184  {
6185  XnNodeHandle hNode;
6186  XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_IMAGE, strName, &hNode);
6187  XN_IS_STATUS_OK(nRetVal);
6188  TakeOwnership(hNode);
6189  return (XN_STATUS_OK);
6190  }
6191 
6192  inline XnStatus MockImageGenerator::CreateBasedOn(ImageGenerator& other, const XnChar* strName /* = NULL */)
6193  {
6194  Context context;
6195  other.GetContext(context);
6196  XnNodeHandle hNode;
6197  XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
6198  XN_IS_STATUS_OK(nRetVal);
6199  TakeOwnership(hNode);
6200  return (XN_STATUS_OK);
6201  }
6202 
6203  inline XnStatus IRGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6204  {
6205  XnNodeHandle hNode;
6206  XnStatus nRetVal = xnCreateIRGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6207  XN_IS_STATUS_OK(nRetVal);
6208  TakeOwnership(hNode);
6209  return (XN_STATUS_OK);
6210  }
6211 
6212  inline XnStatus MockIRGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
6213  {
6214  XnNodeHandle hNode;
6215  XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_IR, strName, &hNode);
6216  XN_IS_STATUS_OK(nRetVal);
6217  TakeOwnership(hNode);
6218  return (XN_STATUS_OK);
6219  }
6220 
6221  inline XnStatus MockIRGenerator::CreateBasedOn(IRGenerator& other, const XnChar* strName /* = NULL */)
6222  {
6223  Context context;
6224  other.GetContext(context);
6225  XnNodeHandle hNode;
6226  XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
6227  XN_IS_STATUS_OK(nRetVal);
6228  TakeOwnership(hNode);
6229  return (XN_STATUS_OK);
6230  }
6231 
6232  inline XnStatus GestureGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6233  {
6234  XnNodeHandle hNode;
6235  XnStatus nRetVal = xnCreateGestureGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6236  XN_IS_STATUS_OK(nRetVal);
6237  TakeOwnership(hNode);
6238  return (XN_STATUS_OK);
6239  }
6240 
6241  inline XnStatus SceneAnalyzer::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6242  {
6243  //You're creating a scene!
6244  XnNodeHandle hNode;
6245  XnStatus nRetVal = xnCreateSceneAnalyzer(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6246  XN_IS_STATUS_OK(nRetVal);
6247  TakeOwnership(hNode);
6248  return (XN_STATUS_OK);
6249  }
6250 
6251  inline XnStatus HandsGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6252  {
6253  XnNodeHandle hNode;
6254  XnStatus nRetVal = xnCreateHandsGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6255  XN_IS_STATUS_OK(nRetVal);
6256  TakeOwnership(hNode);
6257  return (XN_STATUS_OK);
6258  }
6259 
6260  inline XnStatus UserGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6261  {
6262  XnNodeHandle hNode;
6263  XnStatus nRetVal = xnCreateUserGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6264  XN_IS_STATUS_OK(nRetVal);
6265  TakeOwnership(hNode);
6266  return (XN_STATUS_OK);
6267  }
6268 
6269  inline XnStatus AudioGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
6270  {
6271  XnNodeHandle hNode;
6272  XnStatus nRetVal = xnCreateAudioGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6273  XN_IS_STATUS_OK(nRetVal);
6274  TakeOwnership(hNode);
6275  return (XN_STATUS_OK);
6276  }
6277 
6278  inline XnStatus MockAudioGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
6279  {
6280  XnNodeHandle hNode;
6281  XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_AUDIO, strName, &hNode);
6282  XN_IS_STATUS_OK(nRetVal);
6283  TakeOwnership(hNode);
6284  return (XN_STATUS_OK);
6285  }
6286 
6287  inline XnStatus MockAudioGenerator::CreateBasedOn(AudioGenerator& other, const XnChar* strName /* = NULL */)
6288  {
6289  Context context;
6290  other.GetContext(context);
6291  XnNodeHandle hNode;
6292  XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
6293  XN_IS_STATUS_OK(nRetVal);
6294  TakeOwnership(hNode);
6295  return (XN_STATUS_OK);
6296  }
6297 
6298  inline XnStatus MockRawGenerator::Create(Context& context, const XnChar* strName /*= NULL*/)
6299  {
6300  XnNodeHandle hNode;
6301  XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_GENERATOR, strName, &hNode);
6302  XN_IS_STATUS_OK(nRetVal);
6303  TakeOwnership(hNode);
6304  return (XN_STATUS_OK);
6305  }
6306 
6307  inline XnStatus Codec::Create(Context& context, XnCodecID codecID, ProductionNode& initializerNode)
6308  {
6309  XnNodeHandle hNode;
6310  XnStatus nRetVal = xnCreateCodec(context.GetUnderlyingObject(), codecID, initializerNode.GetHandle(), &hNode);
6311  XN_IS_STATUS_OK(nRetVal);
6312  TakeOwnership(hNode);
6313  return (XN_STATUS_OK);
6314  }
6315 
6317  {
6318  return xnScriptNodeRun(GetHandle(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
6319  }
6320 
6321  //---------------------------------------------------------------------------
6322  // Global Helper Functions
6323  //---------------------------------------------------------------------------
6324 
6329  {
6330  xnGetVersion(&Version);
6331  }
6332 
6333  //---------------------------------------------------------------------------
6334  // Internal Helper Classes and Functions
6335  //---------------------------------------------------------------------------
6336 
6338  {
6339  public:
6340  StateChangedCallbackTranslator(StateChangedHandler handler, void* pCookie) : m_UserHandler(handler), m_pUserCookie(pCookie), m_hCallback(NULL) {}
6341 
6342  XnStatus Register(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode)
6343  {
6344  return xnFunc(hNode, StateChangedCallback, this, &m_hCallback);
6345  }
6346 
6347  void Unregister(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode)
6348  {
6349  xnFunc(hNode, m_hCallback);
6350  }
6351 
6352  static XnStatus RegisterToUnderlying(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
6353  {
6354  XnStatus nRetVal = XN_STATUS_OK;
6355 
6357  XN_VALIDATE_NEW(pTrans, StateChangedCallbackTranslator, handler, pCookie);
6358 
6359  nRetVal = pTrans->Register(xnFunc, hNode);
6360  if (nRetVal != XN_STATUS_OK)
6361  {
6362  XN_DELETE(pTrans);
6363  return (nRetVal);
6364  }
6365 
6366  hCallback = pTrans;
6367 
6368  return (XN_STATUS_OK);
6369  }
6370 
6371  static XnStatus UnregisterFromUnderlying(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, XnCallbackHandle hCallback)
6372  {
6374  pTrans->Unregister(xnFunc, hNode);
6375  XN_DELETE(pTrans);
6376  return XN_STATUS_OK;
6377  }
6378 
6379  private:
6380  friend class GeneralIntCapability;
6381 
6382  typedef struct StateChangeCookie
6383  {
6384  StateChangedHandler userHandler;
6385  void* pUserCookie;
6386  XnCallbackHandle hCallback;
6387  } StateChangeCookie;
6388 
6389  static void XN_CALLBACK_TYPE StateChangedCallback(XnNodeHandle hNode, void* pCookie)
6390  {
6392  ProductionNode node(hNode);
6393  pTrans->m_UserHandler(node, pTrans->m_pUserCookie);
6394  }
6395 
6396  StateChangedHandler m_UserHandler;
6397  void* m_pUserCookie;
6398  XnCallbackHandle m_hCallback;
6399  };
6400 
6401  static XnStatus _RegisterToStateChange(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
6402  {
6403  return StateChangedCallbackTranslator::RegisterToUnderlying(xnFunc, hNode, handler, pCookie, hCallback);
6404  }
6405 
6406  static void _UnregisterFromStateChange(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, XnCallbackHandle hCallback)
6407  {
6409  }
6410 
6412  {
6413  XnStatus nRetVal = XN_STATUS_OK;
6414 
6416  XN_VALIDATE_NEW(pTrans, StateChangedCallbackTranslator, handler, pCookie);
6417 
6418  nRetVal = xnRegisterToGeneralIntValueChange(GetHandle(), m_strCap, pTrans->StateChangedCallback, pTrans, &pTrans->m_hCallback);
6419  if (nRetVal != XN_STATUS_OK)
6420  {
6421  XN_DELETE(pTrans);
6422  return (nRetVal);
6423  }
6424 
6425  hCallback = pTrans;
6426 
6427  return (XN_STATUS_OK);
6428  }
6429 
6431  {
6433  xnUnregisterFromGeneralIntValueChange(GetHandle(), m_strCap, pTrans->m_hCallback);
6434  XN_DELETE(pTrans);
6435  }
6436 
6438 };
6439 
6440 #endif // __XN_CPP_WRAPPER_H__