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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <openni_camera/openni_device.h>
00038 #include <openni_camera/openni_depth_image.h>
00039 #include <iostream>
00040 #include <limits>
00041 #include <sstream>
00042 #include <map>
00043 #include <vector>
00044
00045 using namespace std;
00046 using namespace boost;
00047
00048 namespace openni_wrapper
00049 {
00050
00051 OpenNIDevice::OpenNIDevice (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node,
00052 const xn::NodeInfo& depth_node) throw (OpenNIException)
00053 : device_node_info_ (device_node)
00054 , context_ (context)
00055 {
00056
00057 XnStatus status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(depth_node));
00058 if (status != XN_STATUS_OK)
00059 THROW_OPENNI_EXCEPTION ("creating depth generator failed. Reason: %s", xnGetStatusString (status));
00060
00061 status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(image_node));
00062 if (status != XN_STATUS_OK)
00063 THROW_OPENNI_EXCEPTION ("creating image generator failed. Reason: %s", xnGetStatusString (status));
00064
00065
00066 status = depth_node.GetInstance (depth_generator_);
00067 if (status != XN_STATUS_OK)
00068 THROW_OPENNI_EXCEPTION ("creating depth generator instance failed. Reason: %s", xnGetStatusString (status));
00069
00070 status = image_node.GetInstance (image_generator_);
00071 if (status != XN_STATUS_OK)
00072 THROW_OPENNI_EXCEPTION ("creating image generator instance failed. Reason: %s", xnGetStatusString (status));
00073
00074
00075 running_ = true;
00076 image_thread_ = boost::thread (&OpenNIDevice::ImageDataThreadFunction, this);
00077 depth_thread_ = boost::thread (&OpenNIDevice::DepthDataThreadFunction, this);
00078 }
00079
00080 OpenNIDevice::~OpenNIDevice () throw ()
00081 {
00082
00083 if (image_generator_.IsGenerating ())
00084 image_generator_.StopGenerating ();
00085
00086 if (depth_generator_.IsGenerating ())
00087 depth_generator_.StopGenerating ();
00088
00089
00090 image_mutex_.lock ();
00091 depth_mutex_.lock ();
00092 running_ = false;
00093
00094 depth_condition_.notify_all ();
00095 image_condition_.notify_all ();
00096 depth_mutex_.unlock ();
00097 image_mutex_.unlock ();
00098
00099 image_thread_.join ();
00100 depth_thread_.join ();
00101 }
00102
00103 void OpenNIDevice::Init () throw (OpenNIException)
00104 {
00105
00106 this->getAvailableModes ();
00107
00108
00109 setDepthOutputMode (getDefaultDepthMode ());
00110 setImageOutputMode (getDefaultImageMode ());
00111
00112 XnDouble pixel_size;
00113
00114 unique_lock<mutex> depth_lock (depth_mutex_);
00115 XnStatus status = depth_generator_.GetRealProperty ("ZPPS", pixel_size);
00116 if (status != XN_STATUS_OK)
00117 THROW_OPENNI_EXCEPTION ("reading the pixel size of IR camera failed. Reason: %s", xnGetStatusString (status));
00118
00119 XnUInt64 depth_focal_length_SXGA;
00120 status = depth_generator_.GetIntProperty ("ZPD", depth_focal_length_SXGA);
00121 if (status != XN_STATUS_OK)
00122 THROW_OPENNI_EXCEPTION ("reading the focal length of IR camera failed. Reason: %s", xnGetStatusString (status));
00123
00124 XnDouble baseline;
00125 status = depth_generator_.GetRealProperty ("LDDIS", baseline);
00126 if (status != XN_STATUS_OK)
00127 THROW_OPENNI_EXCEPTION ("reading the baseline failed. Reason: %s", xnGetStatusString (status));
00128
00129 status = depth_generator_.GetIntProperty ("ShadowValue", shadow_value_);
00130 if (status != XN_STATUS_OK)
00131 THROW_OPENNI_EXCEPTION ("reading the value for pixels in shadow regions failed. Reason: %s", xnGetStatusString (status));
00132
00133 status = depth_generator_.GetIntProperty ("NoSampleValue", no_sample_value_);
00134 if (status != XN_STATUS_OK)
00135 THROW_OPENNI_EXCEPTION ("reading the value for pixels with no depth estimation failed. Reason: %s", xnGetStatusString (status));
00136
00137
00138 baseline_ = (float)(baseline * 0.01);
00139
00140
00141 depth_focal_length_SXGA_ = (float)depth_focal_length_SXGA / pixel_size;
00142
00143
00144 depth_generator_.RegisterToNewDataAvailable ((xn::StateChangedHandler)NewDepthDataAvailable, this, depth_callback_handle_);
00145 depth_lock.unlock ();
00146
00147 lock_guard<mutex> image_lock (image_mutex_);
00148 image_generator_.RegisterToNewDataAvailable ((xn::StateChangedHandler)NewImageDataAvailable, this, image_callback_handle_);
00149 }
00150
00151 void OpenNIDevice::startImageStream () throw (OpenNIException)
00152 {
00153 lock_guard<mutex> image_lock (image_mutex_);
00154 if (!image_generator_.IsGenerating ())
00155 {
00156 XnStatus status = image_generator_.StartGenerating ();
00157 if (status != XN_STATUS_OK)
00158 THROW_OPENNI_EXCEPTION ("starting image stream failed. Reason: %s", xnGetStatusString (status));
00159 }
00160 }
00161
00162 void OpenNIDevice::stopImageStream () throw (OpenNIException)
00163 {
00164 lock_guard<mutex> image_lock (image_mutex_);
00165 if (image_generator_.IsGenerating ())
00166 {
00167 XnStatus status = image_generator_.StopGenerating ();
00168 if (status != XN_STATUS_OK)
00169 THROW_OPENNI_EXCEPTION ("stopping image stream failed. Reason: %s", xnGetStatusString (status));
00170 }
00171 }
00172
00173 void OpenNIDevice::startDepthStream () throw (OpenNIException)
00174 {
00175 lock_guard<mutex> depth_lock (depth_mutex_);
00176 if (!depth_generator_.IsGenerating ())
00177 {
00178 XnStatus status = depth_generator_.StartGenerating ();
00179
00180 if (status != XN_STATUS_OK)
00181 THROW_OPENNI_EXCEPTION ("starting depth stream failed. Reason: %s", xnGetStatusString (status));
00182 }
00183 }
00184
00185 void OpenNIDevice::stopDepthStream () throw (OpenNIException)
00186 {
00187 lock_guard<mutex> depth_lock (depth_mutex_);
00188 if (depth_generator_.IsGenerating ())
00189 {
00190 XnStatus status = depth_generator_.StopGenerating ();
00191
00192 if (status != XN_STATUS_OK)
00193 THROW_OPENNI_EXCEPTION ("stopping depth stream failed. Reason: %s", xnGetStatusString (status));
00194 }
00195 }
00196
00197 bool OpenNIDevice::isImageStreamRunning () const throw (OpenNIException)
00198 {
00199 lock_guard<mutex> image_lock (image_mutex_);
00200 return image_generator_.IsGenerating ();
00201 }
00202
00203 bool OpenNIDevice::isDepthStreamRunning () const throw (OpenNIException)
00204 {
00205 lock_guard<mutex> depth_lock (depth_mutex_);
00206 return depth_generator_.IsGenerating ();
00207 }
00208
00209 void OpenNIDevice::setDepthRegistration (bool on_off) throw (OpenNIException)
00210 {
00211 lock_guard<mutex> image_lock (image_mutex_);
00212 lock_guard<mutex> depth_lock (depth_mutex_);
00213 if (on_off && !depth_generator_.GetAlternativeViewPointCap ().IsViewPointAs (image_generator_))
00214 {
00215 if (depth_generator_.GetAlternativeViewPointCap ().IsViewPointSupported (image_generator_))
00216 {
00217 XnStatus status = depth_generator_.GetAlternativeViewPointCap ().SetViewPoint (image_generator_);
00218 if (status != XN_STATUS_OK)
00219 THROW_OPENNI_EXCEPTION ("turning registration on failed. Reason: %s", xnGetStatusString (status));
00220 }
00221 else
00222 THROW_OPENNI_EXCEPTION ("turning registration on failed. Reason: unsopported viewpoint");
00223 }
00224 else if (!on_off)
00225 {
00226 XnStatus status = depth_generator_.GetAlternativeViewPointCap ().ResetViewPoint ();
00227
00228 if (status != XN_STATUS_OK)
00229 THROW_OPENNI_EXCEPTION ("turning registration off failed. Reason: %s", xnGetStatusString (status));
00230 }
00231 }
00232
00233 bool OpenNIDevice::isDepthRegistered () const throw (OpenNIException)
00234 {
00235 xn::DepthGenerator& depth_generator = const_cast<xn::DepthGenerator&>(depth_generator_);
00236 xn::ImageGenerator& image_generator = const_cast<xn::ImageGenerator&>(image_generator_);
00237
00238 lock_guard<mutex> image_lock (image_mutex_);
00239 lock_guard<mutex> depth_lock (depth_mutex_);
00240 return (depth_generator.GetAlternativeViewPointCap ().IsViewPointAs (image_generator));
00241 }
00242
00243 bool OpenNIDevice::isSynchronizationSupported () const throw ()
00244 {
00245 lock_guard<mutex> depth_lock (depth_mutex_);
00246 return depth_generator_.IsCapabilitySupported (XN_CAPABILITY_FRAME_SYNC);
00247 }
00248
00249 void OpenNIDevice::setSynchronization (bool on_off) throw (OpenNIException)
00250 {
00251 lock_guard<mutex> image_lock (image_mutex_);
00252 lock_guard<mutex> depth_lock (depth_mutex_);
00253 XnStatus status;
00254
00255 if (on_off && depth_generator_.GetFrameSyncCap ().CanFrameSyncWith (image_generator_) && !depth_generator_.GetFrameSyncCap ().IsFrameSyncedWith (image_generator_))
00256 {
00257 status = depth_generator_.GetFrameSyncCap ().FrameSyncWith (image_generator_);
00258 if (status != XN_STATUS_OK)
00259 THROW_OPENNI_EXCEPTION ("could not turn on frame synchronization. Reason: %s", xnGetStatusString (status));
00260 }
00261 else if (!on_off && depth_generator_.GetFrameSyncCap ().CanFrameSyncWith (image_generator_) && depth_generator_.GetFrameSyncCap ().IsFrameSyncedWith (image_generator_))
00262 {
00263 status = depth_generator_.GetFrameSyncCap ().StopFrameSyncWith (image_generator_);
00264 if (status != XN_STATUS_OK)
00265 THROW_OPENNI_EXCEPTION ("could not turn off frame synchronization. Reason: %s", xnGetStatusString (status));
00266 }
00267 }
00268
00269 bool OpenNIDevice::isSynchronized () const throw (OpenNIException)
00270 {
00271 lock_guard<mutex> image_lock (image_mutex_);
00272 lock_guard<mutex> depth_lock (depth_mutex_);
00273 xn::DepthGenerator& depth_generator = const_cast<xn::DepthGenerator&>(depth_generator_);
00274 xn::ImageGenerator& image_generator = const_cast<xn::ImageGenerator&>(image_generator_);
00275 return (depth_generator.GetFrameSyncCap ().CanFrameSyncWith (image_generator) && depth_generator.GetFrameSyncCap ().IsFrameSyncedWith (image_generator));
00276 }
00277
00278 bool OpenNIDevice::isDepthCroppingSupported () const throw ()
00279 {
00280 lock_guard<mutex> depth_lock (depth_mutex_);
00281 return depth_generator_.IsCapabilitySupported (XN_CAPABILITY_CROPPING);
00282 }
00283
00284 bool OpenNIDevice::isDepthCropped () const throw (OpenNIException)
00285 {
00286 lock_guard<mutex> depth_lock (depth_mutex_);
00287 XnCropping cropping;
00288 xn::DepthGenerator& depth_generator = const_cast<xn::DepthGenerator&>(depth_generator_);
00289 XnStatus status = depth_generator.GetCroppingCap ().GetCropping (cropping);
00290 if (status != XN_STATUS_OK)
00291 THROW_OPENNI_EXCEPTION ("could not read cropping information for depth stream. Reason: %s", xnGetStatusString (status));
00292
00293 return cropping.bEnabled;
00294 }
00295
00296 void OpenNIDevice::setDepthCropping (unsigned x, unsigned y, unsigned width, unsigned height) throw (OpenNIException)
00297 {
00298 lock_guard<mutex> depth_lock (depth_mutex_);
00299 XnCropping cropping;
00300 cropping.nXOffset = x;
00301 cropping.nYOffset = y;
00302 cropping.nXSize = width;
00303 cropping.nYSize = height;
00304
00305 cropping.bEnabled = (width != 0 && height != 0);
00306 XnStatus status = depth_generator_.GetCroppingCap ().SetCropping (cropping);
00307 if (status != XN_STATUS_OK)
00308 THROW_OPENNI_EXCEPTION ("could not set cropping information for depth stream. Reason: %s", xnGetStatusString (status));
00309 }
00310
00311 void OpenNIDevice::ImageDataThreadFunction () throw (OpenNIException)
00312 {
00313 while (running_)
00314 {
00315
00316 unique_lock<mutex> image_lock (image_mutex_);
00317 if (!running_)
00318 return;
00319 image_condition_.wait (image_lock);
00320 if (!running_)
00321 return;
00322
00323 image_generator_.WaitAndUpdateData ();
00324
00325 boost::shared_ptr<xn::ImageMetaData> image_data (new xn::ImageMetaData);
00326 image_generator_.GetMetaData (*image_data);
00327
00328 image_lock.unlock ();
00329
00330 boost::shared_ptr<Image> image = getCurrentImage (image_data);
00331 for (map< OpenNIDevice::CallbackHandle, ActualImageCallbackFunction >::iterator callbackIt = image_callback_.begin (); callbackIt != image_callback_.end (); ++callbackIt)
00332 {
00333 callbackIt->second.operator()(image);
00334 }
00335 }
00336 }
00337
00338 void OpenNIDevice::DepthDataThreadFunction () throw (OpenNIException)
00339 {
00340 while (running_)
00341 {
00342
00343 unique_lock<mutex> depth_lock (depth_mutex_);
00344 if (!running_)
00345 return;
00346 depth_condition_.wait (depth_lock);
00347 if (!running_)
00348 return;
00349
00350 depth_generator_.WaitAndUpdateData ();
00351 boost::shared_ptr<xn::DepthMetaData> depth_data (new xn::DepthMetaData);
00352 depth_generator_.GetMetaData (*depth_data);
00353 depth_lock.unlock ();
00354
00355 boost::shared_ptr<DepthImage> depth_image ( new DepthImage (depth_data, baseline_, getDepthFocalLength (), shadow_value_, no_sample_value_) );
00356
00357 for (map< OpenNIDevice::CallbackHandle, ActualDepthImageCallbackFunction >::iterator callbackIt = depth_callback_.begin ();
00358 callbackIt != depth_callback_.end (); ++callbackIt)
00359 {
00360 callbackIt->second.operator()(depth_image);
00361 }
00362 }
00363 }
00364
00365 void __stdcall OpenNIDevice::NewDepthDataAvailable (xn::ProductionNode& node, void* cookie) throw ()
00366 {
00367 OpenNIDevice* device = reinterpret_cast<OpenNIDevice*>(cookie);
00368 device->depth_condition_.notify_all ();
00369 }
00370
00371 void __stdcall OpenNIDevice::NewImageDataAvailable (xn::ProductionNode& node, void* cookie) throw ()
00372 {
00373 OpenNIDevice* device = reinterpret_cast<OpenNIDevice*>(cookie);
00374 device->image_condition_.notify_all ();
00375 }
00376
00377 OpenNIDevice::CallbackHandle OpenNIDevice::registerImageCallback (const ImageCallbackFunction& callback, void* custom_data) throw ()
00378 {
00379 image_callback_[image_callback_handle_counter_] = boost::bind (callback, _1, custom_data);
00380 return image_callback_handle_counter_++;
00381 }
00382
00383 bool OpenNIDevice::unregisterImageCallback (const OpenNIDevice::CallbackHandle& callbackHandle) throw ()
00384 {
00385 return (image_callback_.erase (callbackHandle) != 0);
00386 }
00387
00388 OpenNIDevice::CallbackHandle OpenNIDevice::registerDepthCallback (const DepthImageCallbackFunction& callback, void* custom_data) throw ()
00389 {
00390 depth_callback_[depth_callback_handle_counter_] = boost::bind (callback, _1, custom_data);
00391 return depth_callback_handle_counter_++;
00392 }
00393
00394 bool OpenNIDevice::unregisterDepthCallback (const OpenNIDevice::CallbackHandle& callbackHandle) throw ()
00395 {
00396 return (depth_callback_.erase (callbackHandle) != 0);
00397 }
00398
00399 const char* OpenNIDevice::getSerialNumber () const throw ()
00400 {
00401 return device_node_info_.GetInstanceName ();
00402 }
00403
00404 const char* OpenNIDevice::getConnectionString () const throw ()
00405 {
00406 return device_node_info_.GetCreationInfo ();
00407 }
00408
00409 unsigned short OpenNIDevice::getVendorID () const throw ()
00410 {
00411 unsigned short vendor_id;
00412 unsigned short product_id;
00413 unsigned char bus;
00414 unsigned char address;
00415 sscanf (device_node_info_.GetCreationInfo (), "%hx/%hx@%hhu/%hhu", &vendor_id, &product_id, &bus, &address);
00416
00417 return vendor_id;
00418 }
00419
00420 unsigned short OpenNIDevice::getProductID () const throw ()
00421 {
00422 unsigned short vendor_id;
00423 unsigned short product_id;
00424 unsigned char bus;
00425 unsigned char address;
00426 sscanf (device_node_info_.GetCreationInfo (), "%hx/%hx@%hhu/%hhu", &vendor_id, &product_id, &bus, &address);
00427
00428 return product_id;
00429 }
00430
00431 unsigned char OpenNIDevice::getBus () const throw ()
00432 {
00433 unsigned short vendor_id;
00434 unsigned short product_id;
00435 unsigned char bus;
00436 unsigned char address;
00437 sscanf (device_node_info_.GetCreationInfo (), "%hx/%hx@%hhu/%hhu", &vendor_id, &product_id, &bus, &address);
00438
00439 return bus;
00440 }
00441
00442 unsigned char OpenNIDevice::getAddress () const throw ()
00443 {
00444 unsigned short vendor_id;
00445 unsigned short product_id;
00446 unsigned char bus;
00447 unsigned char address;
00448 sscanf (device_node_info_.GetCreationInfo (), "%hx/%hx@%hhu/%hhu", &vendor_id, &product_id, &bus, &address);
00449
00450 return address;
00451 }
00452
00453 const char* OpenNIDevice::getVendorName () const throw ()
00454 {
00455 XnProductionNodeDescription& description = const_cast<XnProductionNodeDescription&>(device_node_info_.GetDescription ());
00456 return description.strVendor;
00457 }
00458
00459 const char* OpenNIDevice::getProductName () const throw ()
00460 {
00461 XnProductionNodeDescription& description = const_cast<XnProductionNodeDescription&>(device_node_info_.GetDescription ());
00462 return description.strName;
00463 }
00464
00465 bool OpenNIDevice::findCompatibleImageMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode) const throw (OpenNIException)
00466 {
00467 if (isImageModeSupported (output_mode))
00468 {
00469 mode = output_mode;
00470 return true;
00471 }
00472 else
00473 {
00474 bool found = false;
00475 for (vector<XnMapOutputMode>::const_iterator modeIt = available_image_modes_.begin (); modeIt != available_image_modes_.end (); ++modeIt)
00476 {
00477 if (modeIt->nFPS == output_mode.nFPS && isImageResizeSupported (modeIt->nXRes, modeIt->nYRes, output_mode.nXRes, output_mode.nYRes))
00478 {
00479 if (found)
00480 {
00481 if (mode.nXRes * mode.nYRes > modeIt->nXRes * modeIt->nYRes )
00482 mode = *modeIt;
00483 }
00484 else
00485 {
00486 mode = *modeIt;
00487 found = true;
00488 }
00489 }
00490 }
00491 return found;
00492 }
00493 }
00494
00495 bool OpenNIDevice::findCompatibleDepthMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode) const throw (OpenNIException)
00496 {
00497 if (isDepthModeSupported (output_mode))
00498 {
00499 mode = output_mode;
00500 return true;
00501 }
00502 else
00503 {
00504 bool found = false;
00505 for (vector<XnMapOutputMode>::const_iterator modeIt = available_depth_modes_.begin (); modeIt != available_depth_modes_.end (); ++modeIt)
00506 {
00507 if (modeIt->nFPS == output_mode.nFPS && isImageResizeSupported (modeIt->nXRes, modeIt->nYRes, output_mode.nXRes, output_mode.nYRes))
00508 {
00509 if (found)
00510 {
00511 if (mode.nXRes * mode.nYRes > modeIt->nXRes * modeIt->nYRes )
00512 mode = *modeIt;
00513 }
00514 else
00515 {
00516 mode = *modeIt;
00517 found = true;
00518 }
00519 }
00520 }
00521 return found;
00522 }
00523 }
00524
00525 void OpenNIDevice::getAvailableModes () throw (OpenNIException)
00526 {
00527 available_image_modes_.clear ();
00528 unique_lock<mutex> image_lock (image_mutex_);
00529 unsigned mode_count = image_generator_.GetSupportedMapOutputModesCount ();
00530 XnMapOutputMode* modes = new XnMapOutputMode[mode_count];
00531 XnStatus status = image_generator_.GetSupportedMapOutputModes (modes, mode_count);
00532 if (status != XN_STATUS_OK)
00533 {
00534 delete[] modes;
00535 THROW_OPENNI_EXCEPTION ("Could not enumerate image stream output modes. Reason: %s", xnGetStatusString (status));
00536 }
00537 image_lock.unlock ();
00538
00539 for (unsigned modeIdx = 0; modeIdx < mode_count; ++modeIdx)
00540 available_image_modes_.push_back (modes[modeIdx]);
00541 delete[] modes;
00542
00543 available_depth_modes_.clear ();
00544 unique_lock<mutex> depth_lock (depth_mutex_);
00545 mode_count = depth_generator_.GetSupportedMapOutputModesCount ();
00546 modes = new XnMapOutputMode[mode_count];
00547 status = depth_generator_.GetSupportedMapOutputModes (modes, mode_count);
00548 if (status != XN_STATUS_OK)
00549 {
00550 delete[] modes;
00551 THROW_OPENNI_EXCEPTION ("Could not enumerate depth stream output modes. Reason: %s", xnGetStatusString (status));
00552 }
00553 depth_lock.unlock ();
00554
00555 for (unsigned modeIdx = 0; modeIdx < mode_count; ++modeIdx)
00556 available_depth_modes_.push_back (modes[modeIdx]);
00557 delete[] modes;
00558 }
00559
00560 bool OpenNIDevice::isImageModeSupported (const XnMapOutputMode& output_mode) const throw (OpenNIException)
00561 {
00562 for (vector<XnMapOutputMode>::const_iterator modeIt = available_image_modes_.begin (); modeIt != available_image_modes_.end (); ++modeIt)
00563 {
00564 if (modeIt->nFPS == output_mode.nFPS && modeIt->nXRes == output_mode.nXRes && modeIt->nYRes == output_mode.nYRes)
00565 return true;
00566 }
00567 return false;
00568 }
00569
00570 bool OpenNIDevice::isDepthModeSupported (const XnMapOutputMode& output_mode) const throw (OpenNIException)
00571 {
00572 for (vector<XnMapOutputMode>::const_iterator modeIt = available_depth_modes_.begin (); modeIt != available_depth_modes_.end (); ++modeIt)
00573 {
00574 if (modeIt->nFPS == output_mode.nFPS && modeIt->nXRes == output_mode.nXRes && modeIt->nYRes == output_mode.nYRes)
00575 return true;
00576 }
00577 return false;
00578 }
00579
00580 const XnMapOutputMode& OpenNIDevice::getDefaultImageMode () const throw ()
00581 {
00582 return available_image_modes_[0];
00583 }
00584
00585 const XnMapOutputMode& OpenNIDevice::getDefaultDepthMode () const throw ()
00586 {
00587 return available_depth_modes_[0];
00588 }
00589
00590 void OpenNIDevice::setImageOutputMode (const XnMapOutputMode& output_mode) throw (OpenNIException)
00591 {
00592 lock_guard<mutex> image_lock (image_mutex_);
00593 XnStatus status = image_generator_.SetMapOutputMode (output_mode);
00594 if (status != XN_STATUS_OK)
00595 THROW_OPENNI_EXCEPTION ("Could not set image stream output mode to %dx%d@%d. Reason: %s", output_mode.nXRes, output_mode.nYRes, output_mode.nFPS, xnGetStatusString (status));
00596 }
00597
00598 void OpenNIDevice::setDepthOutputMode (const XnMapOutputMode& output_mode) throw (OpenNIException)
00599 {
00600 lock_guard<mutex> depth_lock (depth_mutex_);
00601 XnStatus status = depth_generator_.SetMapOutputMode (output_mode);
00602 if (status != XN_STATUS_OK)
00603 THROW_OPENNI_EXCEPTION ("Could not set depth stream output mode to %dx%d@%d. Reason: %s", output_mode.nXRes, output_mode.nYRes, output_mode.nFPS, xnGetStatusString (status));
00604 }
00605
00606 XnMapOutputMode OpenNIDevice::getImageOutputMode () const throw (OpenNIException)
00607 {
00608 lock_guard<mutex> image_lock (image_mutex_);
00609 XnMapOutputMode output_mode;
00610 XnStatus status = image_generator_.GetMapOutputMode (output_mode);
00611 if (status != XN_STATUS_OK)
00612 THROW_OPENNI_EXCEPTION ("Could not get image stream output mode. Reason: %s", xnGetStatusString (status));
00613
00614 return output_mode;
00615 }
00616
00617 XnMapOutputMode OpenNIDevice::getDepthOutputMode () const throw (OpenNIException)
00618 {
00619 lock_guard<mutex> depth_lock (depth_mutex_);
00620 XnMapOutputMode output_mode;
00621 XnStatus status = depth_generator_.GetMapOutputMode (output_mode);
00622 if (status != XN_STATUS_OK)
00623 THROW_OPENNI_EXCEPTION ("Could not get depth stream output mode. Reason: %s", xnGetStatusString (status));
00624
00625 return output_mode;
00626 }
00627
00628 const float OpenNIDevice::rgb_focal_length_SXGA_ = 1050;
00629 }