14 #include <XnCppWrapper.h> 18 class KinectController::KinectControllerPrivate
21 KinectControllerPrivate();
22 ~KinectControllerPrivate();
24 bool ErrorText(
unsigned int error);
26 xn::Context m_Context;
27 xn::DepthGenerator m_DepthGenerator;
28 xn::ImageGenerator m_ImageGenerator;
29 xn::IRGenerator m_IRGenerator;
32 bool m_ConnectionCheck;
36 unsigned int m_CaptureWidth;
37 unsigned int m_CaptureHeight;
40 KinectController::KinectControllerPrivate::KinectControllerPrivate():
42 m_DepthGenerator(nullptr),
43 m_ImageGenerator(nullptr),
44 m_IRGenerator(nullptr),
45 m_ConnectionCheck(false),
52 KinectController::KinectControllerPrivate::~KinectControllerPrivate()
56 bool KinectController::KinectControllerPrivate::ErrorText(
unsigned int error)
58 if(error != XN_STATUS_OK)
60 MITK_ERROR <<
"Kinect Camera Error " << xnGetStatusString(error);
61 mitkThrow() <<
"Kinect Camera Error " << xnGetStatusString(error);
67 KinectController::KinectController(): d(new KinectControllerPrivate)
78 if (!d->m_ConnectionCheck)
81 d->m_ConnectionCheck = d->ErrorText(d->m_Context.Init());
82 if (!d->m_ConnectionCheck)
return false;
84 XnMapOutputMode DepthMode;
85 d->m_ConnectionCheck = d->ErrorText(d->m_DepthGenerator.Create(d->m_Context));
86 if (!d->m_ConnectionCheck)
return false;
87 d->m_DepthGenerator.GetMapOutputMode(DepthMode);
88 DepthMode.nXRes = xn::Resolution((XnResolution)XN_RES_VGA).GetXResolution();
89 DepthMode.nYRes = xn::Resolution((XnResolution)XN_RES_VGA).GetYResolution();
90 d->m_ConnectionCheck = d->ErrorText(d->m_DepthGenerator.SetMapOutputMode(DepthMode));
91 if (!d->m_ConnectionCheck)
return false;
96 d->m_ConnectionCheck = d->ErrorText(d->m_IRGenerator.Create(d->m_Context));
97 if (!d->m_ConnectionCheck)
return false;
98 XnMapOutputMode IRMode;
99 d->m_IRGenerator.GetMapOutputMode(IRMode);
100 IRMode.nXRes = XN_VGA_X_RES;
101 IRMode.nYRes = XN_VGA_Y_RES;
103 d->m_ConnectionCheck = d->ErrorText(d->m_IRGenerator.SetMapOutputMode(IRMode));
104 if (!d->m_ConnectionCheck)
return false;
109 XnMapOutputMode ImageMode;
110 d->m_ConnectionCheck = d->ErrorText(d->m_ImageGenerator.Create(d->m_Context));
111 if (!d->m_ConnectionCheck)
return false;
112 d->m_ImageGenerator.GetMapOutputMode(ImageMode);
113 ImageMode.nXRes = xn::Resolution((XnResolution)XN_RES_VGA).GetXResolution();
114 ImageMode.nYRes = xn::Resolution((XnResolution)XN_RES_VGA).GetYResolution();
115 d->m_ConnectionCheck = d->ErrorText(d->m_ImageGenerator.SetMapOutputMode(ImageMode));
116 if (!d->m_ConnectionCheck)
return false;
120 if( d->m_DepthGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT) )
124 d->m_ConnectionCheck = d->ErrorText(d->m_DepthGenerator.GetAlternativeViewPointCap().SetViewPoint(d->m_ImageGenerator));
129 MITK_ERROR <<
"Alternative view point not supported by the depth generator...";
133 if( d->m_IRGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT) )
135 d->m_ConnectionCheck = d->ErrorText(d->m_IRGenerator.GetAlternativeViewPointCap().SetViewPoint(d->m_DepthGenerator));
139 MITK_ERROR <<
"Alternative view point not supported by the depth generator...";
144 d->m_ConnectionCheck = d->ErrorText(d->m_Context.StartGeneratingAll());
145 if (!d->m_ConnectionCheck)
return false;
147 return d->m_ConnectionCheck;
152 d->m_ConnectionCheck = !d->ErrorText(d->m_Context.StopGeneratingAll());
153 return !d->m_ConnectionCheck;
158 bool updateSuccessful = d->ErrorText(d->m_Context.WaitAndUpdateAll());
159 xn::DepthMetaData DepthMD;
160 d->m_DepthGenerator.GetMetaData(DepthMD);
161 d->m_CaptureWidth = DepthMD.XRes();
162 d->m_CaptureHeight = DepthMD.YRes();
163 return updateSuccessful;
168 xn::DepthMetaData DepthMD;
169 d->m_DepthGenerator.GetMetaData(DepthMD);
170 const XnDepthPixel* DepthData = DepthMD.Data();
172 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
174 distances[i] =
static_cast<float>(DepthData[i]);
182 xn::ImageMetaData ImageMD;
183 d->m_ImageGenerator.GetMetaData(ImageMD);
184 const XnRGB24Pixel* rgbPixelArray = ImageMD.RGB24Data();
185 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
187 rgb[i*3] = rgbPixelArray[i].nRed;
188 rgb[i*3+1] = rgbPixelArray[i].nGreen;
189 rgb[i*3+2] = rgbPixelArray[i].nBlue;
197 xn::DepthMetaData DepthMD;
198 d->m_DepthGenerator.GetMetaData(DepthMD);
199 const XnDepthPixel* DepthData = DepthMD.Data();
201 xn::IRMetaData IRData;
202 const XnIRPixel* IRPixelData =
nullptr;
204 xn::ImageMetaData ImageMD;
205 const XnRGB24Pixel* rgbPixelArray =
nullptr;
208 d->m_IRGenerator.GetMetaData(IRData);
209 IRPixelData = IRData.Data();
214 d->m_ImageGenerator.GetMetaData(ImageMD);
215 rgbPixelArray = ImageMD.RGB24Data();
218 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
220 distances[i] =
static_cast<float>(DepthData[i]);
223 amplitudes[i] =
static_cast<float>(IRPixelData[i]);
227 rgb[i*3] = rgbPixelArray[i].nRed;
228 rgb[i*3+1] = rgbPixelArray[i].nGreen;
229 rgb[i*3+2] = rgbPixelArray[i].nBlue;
238 xn::IRMetaData IRData;
239 d->m_IRGenerator.GetMetaData(IRData);
240 const XnIRPixel* IRPixelData = IRData.Data();
242 for (
unsigned int i=0; i<d->m_CaptureWidth*d->m_CaptureHeight; i++)
244 amplitudes[i] =
static_cast<float>(IRPixelData[i]);
255 return d->m_CaptureWidth;
260 return d->m_CaptureHeight;
269 if (d->m_UseIR!=useIR)
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
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)
unsigned int GetCaptureHeight() const
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
unsigned int GetCaptureWidth() const