18 #include <XnCppWrapper.h>
22 class KinectController::KinectControllerPrivate
25 KinectControllerPrivate();
26 ~KinectControllerPrivate();
28 bool ErrorText(
unsigned int error);
30 xn::Context m_Context;
31 xn::DepthGenerator m_DepthGenerator;
32 xn::ImageGenerator m_ImageGenerator;
33 xn::IRGenerator m_IRGenerator;
36 bool m_ConnectionCheck;
40 unsigned int m_CaptureWidth;
41 unsigned int m_CaptureHeight;
44 KinectController::KinectControllerPrivate::KinectControllerPrivate():
46 m_DepthGenerator(NULL),
47 m_ImageGenerator(NULL),
49 m_ConnectionCheck(false),
56 KinectController::KinectControllerPrivate::~KinectControllerPrivate()
60 bool KinectController::KinectControllerPrivate::ErrorText(
unsigned int error)
62 if(error != XN_STATUS_OK)
64 MITK_ERROR <<
"Kinect Camera Error " << xnGetStatusString(error);
65 mitkThrow() <<
"Kinect Camera Error " << xnGetStatusString(error);
71 KinectController::KinectController(): d(new KinectControllerPrivate)
82 if (!d->m_ConnectionCheck)
85 d->m_ConnectionCheck = d->ErrorText(d->m_Context.Init());
86 if (!d->m_ConnectionCheck)
return false;
88 XnMapOutputMode DepthMode;
89 d->m_ConnectionCheck = d->ErrorText(d->m_DepthGenerator.Create(d->m_Context));
90 if (!d->m_ConnectionCheck)
return false;
91 d->m_DepthGenerator.GetMapOutputMode(DepthMode);
92 DepthMode.nXRes = xn::Resolution((XnResolution)XN_RES_VGA).GetXResolution();
93 DepthMode.nYRes = xn::Resolution((XnResolution)XN_RES_VGA).GetYResolution();
94 d->m_ConnectionCheck = d->ErrorText(d->m_DepthGenerator.SetMapOutputMode(DepthMode));
95 if (!d->m_ConnectionCheck)
return false;
100 d->m_ConnectionCheck = d->ErrorText(d->m_IRGenerator.Create(d->m_Context));
101 if (!d->m_ConnectionCheck)
return false;
102 XnMapOutputMode IRMode;
103 d->m_IRGenerator.GetMapOutputMode(IRMode);
104 IRMode.nXRes = XN_VGA_X_RES;
105 IRMode.nYRes = XN_VGA_Y_RES;
107 d->m_ConnectionCheck = d->ErrorText(d->m_IRGenerator.SetMapOutputMode(IRMode));
108 if (!d->m_ConnectionCheck)
return false;
113 XnMapOutputMode ImageMode;
114 d->m_ConnectionCheck = d->ErrorText(d->m_ImageGenerator.Create(d->m_Context));
115 if (!d->m_ConnectionCheck)
return false;
116 d->m_ImageGenerator.GetMapOutputMode(ImageMode);
117 ImageMode.nXRes = xn::Resolution((XnResolution)XN_RES_VGA).GetXResolution();
118 ImageMode.nYRes = xn::Resolution((XnResolution)XN_RES_VGA).GetYResolution();
119 d->m_ConnectionCheck = d->ErrorText(d->m_ImageGenerator.SetMapOutputMode(ImageMode));
120 if (!d->m_ConnectionCheck)
return false;
124 if( d->m_DepthGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT) )
128 d->m_ConnectionCheck = d->ErrorText(d->m_DepthGenerator.GetAlternativeViewPointCap().SetViewPoint(d->m_ImageGenerator));
133 MITK_ERROR <<
"Alternative view point not supported by the depth generator...";
137 if( d->m_IRGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT) )
139 d->m_ConnectionCheck = d->ErrorText(d->m_IRGenerator.GetAlternativeViewPointCap().SetViewPoint(d->m_DepthGenerator));
143 MITK_ERROR <<
"Alternative view point not supported by the depth generator...";
148 d->m_ConnectionCheck = d->ErrorText(d->m_Context.StartGeneratingAll());
149 if (!d->m_ConnectionCheck)
return false;
151 return d->m_ConnectionCheck;
156 d->m_ConnectionCheck = !d->ErrorText(d->m_Context.StopGeneratingAll());
157 return !d->m_ConnectionCheck;
162 bool updateSuccessful = d->ErrorText(d->m_Context.WaitAndUpdateAll());
163 xn::DepthMetaData DepthMD;
164 d->m_DepthGenerator.GetMetaData(DepthMD);
165 d->m_CaptureWidth = DepthMD.XRes();
166 d->m_CaptureHeight = DepthMD.YRes();
167 return updateSuccessful;
172 xn::DepthMetaData DepthMD;
173 d->m_DepthGenerator.GetMetaData(DepthMD);
174 const XnDepthPixel* DepthData = DepthMD.Data();
176 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
178 distances[i] =
static_cast<float>(DepthData[i]);
186 xn::ImageMetaData ImageMD;
187 d->m_ImageGenerator.GetMetaData(ImageMD);
188 const XnRGB24Pixel* rgbPixelArray = ImageMD.RGB24Data();
189 for (
int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
191 rgb[i*3] = rgbPixelArray[i].nRed;
192 rgb[i*3+1] = rgbPixelArray[i].nGreen;
193 rgb[i*3+2] = rgbPixelArray[i].nBlue;
201 xn::DepthMetaData DepthMD;
202 d->m_DepthGenerator.GetMetaData(DepthMD);
203 const XnDepthPixel* DepthData = DepthMD.Data();
205 xn::IRMetaData IRData;
206 const XnIRPixel* IRPixelData;
208 xn::ImageMetaData ImageMD;
209 const XnRGB24Pixel* rgbPixelArray;
212 d->m_IRGenerator.GetMetaData(IRData);
213 IRPixelData = IRData.Data();
218 d->m_ImageGenerator.GetMetaData(ImageMD);
219 rgbPixelArray = ImageMD.RGB24Data();
222 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
224 distances[i] =
static_cast<float>(DepthData[i]);
227 amplitudes[i] =
static_cast<float>(IRPixelData[i]);
231 rgb[i*3] = rgbPixelArray[i].nRed;
232 rgb[i*3+1] = rgbPixelArray[i].nGreen;
233 rgb[i*3+2] = rgbPixelArray[i].nBlue;
242 xn::IRMetaData IRData;
243 d->m_IRGenerator.GetMetaData(IRData);
244 const XnIRPixel* IRPixelData = IRData.Data();
246 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
248 amplitudes[i] =
static_cast<float>(IRPixelData[i]);
259 return d->m_CaptureWidth;
264 return d->m_CaptureHeight;
273 if (d->m_UseIR!=useIR)
unsigned int GetCaptureHeight() const
void GetIntensities(float *intensities)
virtual bool UpdateCamera()
updates the camera. The update function of the hardware interface is called only when new data is ava...
void GetRgb(unsigned char *rgb)
acquire new rgb data from the Kinect camera
unsigned int GetCaptureWidth() const
DataCollection - Class to facilitate loading/accessing structured data.
void GetAllData(float *distances, float *amplitudes, unsigned char *rgb)
convenience method for faster access to distance and rgb data
void SetUseIR(bool useIR)
void GetDistances(float *distances)
acquire new distance data from the Kinect camera
virtual bool OpenCameraConnection()
opens a connection to the Kinect camera.
void GetAmplitudes(float *amplitudes)
virtual bool CloseCameraConnection()
closes the connection to the camera