41 #ifndef __OPENNI_IDEVICE_H__
42 #define __OPENNI_IDEVICE_H__
47 #include <XnCppWrapper.h>
48 #include <boost/function.hpp>
49 #include <boost/thread.hpp>
50 #include <boost/thread/condition.hpp>
60 namespace openni_wrapper
73 typedef boost::function<void(boost::shared_ptr<Image>,
void* cookie) > ImageCallbackFunction;
74 typedef boost::function<void(boost::shared_ptr<DepthImage>,
void* cookie) > DepthImageCallbackFunction;
75 typedef boost::function<void(boost::shared_ptr<IRImage>,
void* cookie) > IRImageCallbackFunction;
76 typedef unsigned CallbackHandle;
81 virtual ~OpenNIDevice () throw ();
91 findCompatibleImageMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode ) const throw ();
101 findCompatibleDepthMode (const XnMapOutputMode& output_mode, XnMapOutputMode& mode ) const throw ();
108 isImageModeSupported (const XnMapOutputMode& output_mode) const throw ();
115 isDepthModeSupported (const XnMapOutputMode& output_mode) const throw ();
121 const XnMapOutputMode&
122 getDefaultImageMode () const throw ();
127 const XnMapOutputMode&
128 getDefaultDepthMode () const throw ();
133 const XnMapOutputMode&
134 getDefaultIRMode () const throw ();
140 setImageOutputMode (const XnMapOutputMode& output_mode);
146 setDepthOutputMode (const XnMapOutputMode& output_mode);
152 setIROutputMode (const XnMapOutputMode& output_mode);
156 getImageOutputMode () const;
160 getDepthOutputMode () const;
164 getIROutputMode () const;
170 setDepthRegistration (
bool on_off);
174 isDepthRegistered () const throw ();
178 isDepthRegistrationSupported () const throw ();
184 setSynchronization (
bool on_off);
188 isSynchronized () const throw ();
192 isSynchronizationSupported () const throw ();
196 isDepthCropped () const;
205 setDepthCropping (
unsigned x,
unsigned y,
unsigned width,
unsigned height);
209 isDepthCroppingSupported () const throw ();
215 getImageFocalLength (
int output_x_resolution = 0) const throw ();
221 getDepthFocalLength (
int output_x_resolution = 0) const throw ();
225 getBaseline () const throw ();
253 hasImageStream () const throw ();
257 hasDepthStream () const throw ();
261 hasIRStream () const throw ();
265 isImageStreamRunning () const throw ();
269 isDepthStreamRunning () const throw ();
273 isIRStreamRunning () const throw ();
282 registerImageCallback (const ImageCallbackFunction& callback,
void* cookie = NULL) throw ();
291 template<typename T> CallbackHandle
292 registerImageCallback (
void (T::*callback)(boost::shared_ptr<Image>,
void* cookie), T& instance,
void* cookie = NULL) throw ();
299 unregisterImageCallback (const CallbackHandle& callbackHandle) throw ();
309 registerDepthCallback (const DepthImageCallbackFunction& callback,
void* cookie = NULL) throw ();
318 template<typename T> CallbackHandle
319 registerDepthCallback (
void (T::*callback)(boost::shared_ptr<DepthImage>,
void* cookie), T& instance,
void* cookie = NULL) throw ();
326 unregisterDepthCallback (const CallbackHandle& callbackHandle) throw ();
335 registerIRCallback (const IRImageCallbackFunction& callback,
void* cookie = NULL) throw ();
344 template<typename T> CallbackHandle
345 registerIRCallback (
void (T::*callback)(boost::shared_ptr<IRImage>,
void* cookie), T& instance,
void* cookie = NULL) throw ();
352 unregisterIRCallback (const CallbackHandle& callbackHandle) throw ();
358 getSerialNumber () const throw ();
362 getConnectionString () const throw ();
366 getVendorName () const throw ();
370 getProductName () const throw ();
374 getVendorID () const throw ();
378 getProductID () const throw ();
382 getBus () const throw ();
386 getAddress () const throw ();
392 setRGBFocalLength (
float focal_length)
394 rgb_focal_length_SXGA_ = focal_length;
401 setDepthFocalLength (
float focal_length)
403 depth_focal_length_SXGA_ = focal_length;
407 OpenNIDevice (OpenNIDevice
const &);
408 OpenNIDevice& operator=(OpenNIDevice
const &);
410 typedef boost::function<void(boost::shared_ptr<Image>) > ActualImageCallbackFunction;
411 typedef boost::function<void(boost::shared_ptr<DepthImage>) > ActualDepthImageCallbackFunction;
412 typedef boost::function<void(boost::shared_ptr<IRImage>) > ActualIRImageCallbackFunction;
414 OpenNIDevice (xn::Context& context,
const xn::NodeInfo& device_node,
const xn::NodeInfo& image_node,
const xn::NodeInfo& depth_node,
const xn::NodeInfo& ir_node);
415 OpenNIDevice (xn::Context& context,
const xn::NodeInfo& device_node,
const xn::NodeInfo& depth_node,
const xn::NodeInfo& ir_node);
416 OpenNIDevice (xn::Context& context);
417 static void __stdcall NewDepthDataAvailable (xn::ProductionNode& node,
void* cookie)
throw ();
418 static void __stdcall NewImageDataAvailable (xn::ProductionNode& node,
void* cookie)
throw ();
419 static void __stdcall NewIRDataAvailable (xn::ProductionNode& node,
void* cookie)
throw ();
424 ImageDataThreadFunction ();
427 DepthDataThreadFunction ();
430 IRDataThreadFunction ();
433 isImageResizeSupported (
unsigned input_width,
unsigned input_height,
unsigned output_width,
unsigned output_height)
const throw () = 0;
436 setRegistration (
bool on_off);
438 virtual boost::shared_ptr<Image>
439 getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data)
const throw () = 0;
446 std::map<CallbackHandle, ActualImageCallbackFunction> image_callback_;
447 std::map<CallbackHandle, ActualDepthImageCallbackFunction> depth_callback_;
448 std::map<CallbackHandle, ActualIRImageCallbackFunction> ir_callback_;
450 std::vector<XnMapOutputMode> available_image_modes_;
451 std::vector<XnMapOutputMode> available_depth_modes_;
454 xn::Context& context_;
456 xn::NodeInfo device_node_info_;
459 xn::DepthGenerator depth_generator_;
461 xn::ImageGenerator image_generator_;
463 xn::IRGenerator ir_generator_;
465 XnCallbackHandle depth_callback_handle_;
466 XnCallbackHandle image_callback_handle_;
467 XnCallbackHandle ir_callback_handle_;
470 float depth_focal_length_SXGA_;
474 float rgb_focal_length_SXGA_;
477 XnUInt64 shadow_value_;
479 XnUInt64 no_sample_value_;
481 OpenNIDevice::CallbackHandle image_callback_handle_counter_;
482 OpenNIDevice::CallbackHandle depth_callback_handle_counter_;
483 OpenNIDevice::CallbackHandle ir_callback_handle_counter_;
486 mutable boost::mutex image_mutex_;
487 mutable boost::mutex depth_mutex_;
488 mutable boost::mutex ir_mutex_;
489 boost::condition_variable image_condition_;
490 boost::condition_variable depth_condition_;
491 boost::condition_variable ir_condition_;
492 boost::thread image_thread_;
493 boost::thread depth_thread_;
494 boost::thread ir_thread_;
499 OpenNIDevice::getImageFocalLength (
int output_x_resolution)
const throw ()
501 if (output_x_resolution == 0)
502 output_x_resolution = getImageOutputMode ().nXRes;
504 float scale =
static_cast<float> (output_x_resolution) / static_cast<float> (XN_SXGA_X_RES);
505 return (rgb_focal_length_SXGA_ * scale);
510 OpenNIDevice::getDepthFocalLength (
int output_x_resolution)
const throw ()
512 if (output_x_resolution == 0)
513 output_x_resolution = getDepthOutputMode ().nXRes;
515 float scale =
static_cast<float> (output_x_resolution) / static_cast<float> (XN_SXGA_X_RES);
516 if (isDepthRegistered ())
517 return (rgb_focal_length_SXGA_ * scale);
519 return (depth_focal_length_SXGA_ * scale);
524 OpenNIDevice::getBaseline ()
const throw ()
530 template<
typename T> OpenNIDevice::CallbackHandle
531 OpenNIDevice::registerImageCallback (
void (T::*callback)(boost::shared_ptr<Image>,
void* cookie), T& instance,
void* custom_data)
throw ()
533 image_callback_[image_callback_handle_counter_] = boost::bind (callback, boost::ref (instance), _1, custom_data);
534 return (image_callback_handle_counter_++);
538 template<
typename T> OpenNIDevice::CallbackHandle
539 OpenNIDevice::registerDepthCallback (
void (T::*callback)(boost::shared_ptr<DepthImage>,
void* cookie), T& instance,
void* custom_data)
throw ()
541 depth_callback_[depth_callback_handle_counter_] = boost::bind ( callback, boost::ref (instance), _1, custom_data);
542 return (depth_callback_handle_counter_++);
546 template<
typename T> OpenNIDevice::CallbackHandle
547 OpenNIDevice::registerIRCallback (
void (T::*callback)(boost::shared_ptr<IRImage>,
void* cookie), T& instance,
void* custom_data)
throw ()
549 ir_callback_[ir_callback_handle_counter_] = boost::bind ( callback, boost::ref (instance), _1, custom_data);
550 return (ir_callback_handle_counter_++);
554 #endif // __OPENNI_IDEVICE_H__
555 #endif // HAVE_OPENNI