00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #ifndef __GENERICGENERATOR_H__
00036 #define __GENERICGENERATOR_H__
00037
00038 #include "../lib/common.h"
00039
00040 #include "../core/Exception.h"
00041
00042 #include "../objects/KinectDevice.h"
00043
00044 namespace NIDevice
00045 {
00046 namespace Core
00047 {
00048 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> class GenericGenerator
00049 {
00050 public:
00051 GenericGenerator(NIDevice::Objects::KinectDevice* pDevice);
00052 ~GenericGenerator();
00053
00054 GENERATOR_TYPE& GetGenerator();
00055 const std::string GetType();
00056 int Update();
00057 void SetMirror(bool state);
00058
00059 NIDevice::Objects::KinectDevice* GetParentDevice();
00063 NIDEVICE_GET_OBJECT_TYPE_AS_STRING(GenericGenerator);
00064 NIDEVICE_GET_ERROR_MESSAGE(nRetVal, description);
00065
00066 private:
00067 XnProductionNodeType type;
00068 xn::Generator generator;
00069 XnStatus nRetVal;
00070 std::string description;
00071
00072 NIDevice::Objects::KinectDevice* m_parentDevice;
00073
00074 protected:
00075 GenericGenerator();
00076 };
00077
00078 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::GenericGenerator()
00079 {
00080
00081 };
00082
00083 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::GenericGenerator(NIDevice::Objects::KinectDevice* pDevice)
00084 {
00085 m_parentDevice = pDevice;
00086
00087
00088 GENERATOR_TYPE specializedGenerator = static_cast<GENERATOR_TYPE> (generator);
00089 nRetVal = specializedGenerator.Create(pDevice->GetContext());
00090 if (nRetVal != XN_STATUS_OK)
00091 {
00092
00093 KINECT_EXCEPT(NIDevice::Core::ExceptionKinect, GetNiDeviceMessage(), GetObjectTypeAsString());
00094 }
00095
00096 generator = specializedGenerator;
00097 };
00098
00099 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::~GenericGenerator()
00100 {
00101
00102 };
00103
00104 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> int GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::Update()
00105 {
00106 nRetVal = m_parentDevice->GetContextPtr()->WaitOneUpdateAll(generator);
00107 if (nRetVal != XN_STATUS_OK)
00108 {
00109
00110 KINECT_EXCEPT(NIDevice::Core::ExceptionKinect, GetNiDeviceMessage(), GetObjectTypeAsString());
00111 return nRetVal;
00112 }
00113
00114 return XN_STATUS_OK;
00115 };
00116
00117 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> GENERATOR_TYPE& GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::GetGenerator()
00118 {
00119 assert(generator);
00120 GENERATOR_TYPE& specializedGenerator = static_cast<GENERATOR_TYPE&> (generator);
00121 return specializedGenerator;
00122 };
00123
00124 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> NIDevice::Objects::KinectDevice* GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::GetParentDevice()
00125 {
00126 assert(m_parentDevice);
00127 return m_parentDevice;
00128 };
00129
00130 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> const std::string GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::GetType()
00131 {
00132 return type;
00133 };
00134
00135 template<class GENERATOR_TYPE, XnProductionNodeType OPENNI_GENERATOR_TYPE> void GenericGenerator<GENERATOR_TYPE, OPENNI_GENERATOR_TYPE>::SetMirror(bool state)
00136 {
00137
00138 generator.GetMirrorCap().SetMirror(state == true ? 1 : 0);
00139 };
00140 }
00141 }
00142
00143
00144 #endif