Go to the documentation of this file.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 
00038 #include <pcl/pcl_config.h>
00039 #ifdef HAVE_OPENNI
00040 
00041 #ifdef __GNUC__
00042 #pragma GCC diagnostic ignored "-Wold-style-cast"
00043 #endif
00044 
00045 #include <pcl/io/openni_camera/openni_device_primesense.h>
00046 #include <pcl/io/openni_camera/openni_image_yuv_422.h>
00047 #include <iostream>
00048 #include <sstream>
00049 #include <pcl/io/boost.h>
00050 
00052 openni_wrapper::DevicePrimesense::DevicePrimesense (
00053     xn::Context& context, 
00054     const xn::NodeInfo& device_node, 
00055     const xn::NodeInfo& image_node, 
00056     const xn::NodeInfo& depth_node, 
00057     const xn::NodeInfo& ir_node) : OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
00058 {
00059   
00060   enumAvailableModes ();
00061   setDepthOutputMode (getDefaultDepthMode ());
00062   setImageOutputMode (getDefaultImageMode ());
00063   setIROutputMode (getDefaultIRMode ());
00064 
00065   boost::unique_lock<boost::mutex> image_lock (image_mutex_);
00066   XnStatus status = image_generator_.SetIntProperty ("InputFormat", 5);
00067   if (status != XN_STATUS_OK)
00068     THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed YUV422. Reason: %s", xnGetStatusString (status));
00069 
00070   status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_YUV422);
00071   if (status != XN_STATUS_OK)
00072     THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to YUV422. Reason: %s", xnGetStatusString (status));
00073 
00074   image_lock.unlock ();
00075 
00076   boost::lock_guard<boost::mutex> depth_lock (depth_mutex_);
00077   status = depth_generator_.SetIntProperty ("RegistrationType", 1);
00078   if (status != XN_STATUS_OK)
00079     THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
00080 }
00081 
00083 openni_wrapper::DevicePrimesense::~DevicePrimesense () throw ()
00084 {
00085   setDepthRegistration (false);
00086   setSynchronization (false);
00087 
00088   depth_mutex_.lock ();
00089   depth_generator_.UnregisterFromNewDataAvailable (depth_callback_handle_);
00090   depth_mutex_.unlock ();
00091 
00092   image_mutex_.lock ();
00093   image_generator_.UnregisterFromNewDataAvailable (image_callback_handle_);
00094   image_mutex_.unlock ();
00095 }
00096 
00098 bool 
00099 openni_wrapper::DevicePrimesense::isImageResizeSupported (
00100     unsigned input_width, 
00101     unsigned input_height, 
00102     unsigned output_width, 
00103     unsigned output_height) const throw ()
00104 {
00105   return (ImageYUV422::resizingSupported (input_width, input_height, output_width, output_height));
00106 }
00107 
00109 void 
00110 openni_wrapper::DevicePrimesense::enumAvailableModes () throw ()
00111 {
00112   XnMapOutputMode output_mode;
00113   available_image_modes_.clear ();
00114   available_depth_modes_.clear ();
00115 
00116   
00117   output_mode.nFPS = 30;
00118   output_mode.nXRes = XN_VGA_X_RES;
00119   output_mode.nYRes = XN_VGA_Y_RES;
00120   available_depth_modes_.push_back (output_mode);
00121 
00122   output_mode.nFPS = 25;
00123   output_mode.nXRes = XN_VGA_X_RES;
00124   output_mode.nYRes = XN_VGA_Y_RES;
00125   available_depth_modes_.push_back (output_mode);
00126 
00127   output_mode.nFPS = 25;
00128   output_mode.nXRes = XN_QVGA_X_RES;
00129   output_mode.nYRes = XN_QVGA_Y_RES;
00130   available_depth_modes_.push_back (output_mode);
00131 
00132   output_mode.nFPS = 30;
00133   output_mode.nXRes = XN_QVGA_X_RES;
00134   output_mode.nYRes = XN_QVGA_Y_RES;
00135   available_depth_modes_.push_back (output_mode);
00136 
00137   output_mode.nFPS = 60;
00138   output_mode.nXRes = XN_QVGA_X_RES;
00139   output_mode.nYRes = XN_QVGA_Y_RES;
00140   available_depth_modes_.push_back (output_mode);
00141 
00142   
00143   output_mode.nFPS = 30;
00144   output_mode.nXRes = XN_VGA_X_RES;
00145   output_mode.nYRes = XN_VGA_Y_RES;
00146   available_image_modes_.push_back (output_mode);
00147 
00148   output_mode.nFPS = 25;
00149   output_mode.nXRes = XN_VGA_X_RES;
00150   output_mode.nYRes = XN_VGA_Y_RES;
00151   available_image_modes_.push_back (output_mode);
00152 
00153   output_mode.nFPS = 25;
00154   output_mode.nXRes = XN_QVGA_X_RES;
00155   output_mode.nYRes = XN_QVGA_Y_RES;
00156   available_image_modes_.push_back (output_mode);
00157 
00158   output_mode.nFPS = 30;
00159   output_mode.nXRes = XN_QVGA_X_RES;
00160   output_mode.nYRes = XN_QVGA_Y_RES;
00161   available_image_modes_.push_back (output_mode);
00162 
00163   output_mode.nFPS = 60;
00164   output_mode.nXRes = XN_QVGA_X_RES;
00165   output_mode.nYRes = XN_QVGA_Y_RES;
00166   available_image_modes_.push_back (output_mode);
00167 }
00168 
00170 boost::shared_ptr<openni_wrapper::Image> 
00171 openni_wrapper::DevicePrimesense::getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data) const throw ()
00172 {
00173   return (boost::shared_ptr<openni_wrapper::Image> (new ImageYUV422 (image_data)));
00174 }
00175 
00177 void 
00178 openni_wrapper::DevicePrimesense::startImageStream ()
00179 {
00180   
00181   
00182 
00183   if (isDepthStreamRunning ())
00184   {
00185     if (isDepthRegistered ())
00186     {
00187      
00188       setDepthRegistration (false);
00189 
00190       
00191       setDepthRegistration (true);
00192 
00193      
00194       setDepthRegistration (false);
00195 
00196       
00197       OpenNIDevice::startImageStream ();
00198 
00199       
00200       setDepthRegistration (true);
00201     }
00202     else
00203     {
00204       
00205       setDepthRegistration (true);
00206       
00207       setDepthRegistration (false);
00208 
00209       
00210       OpenNIDevice::startImageStream ();
00211     }
00212   }
00213   else
00214     
00215     OpenNIDevice::startImageStream ();
00216 }
00217 
00219 void 
00220 openni_wrapper::DevicePrimesense::startDepthStream ()
00221 {
00222   if (isDepthRegistered ())
00223   {
00224     
00225     setDepthRegistration (false);
00226 
00227     
00228     OpenNIDevice::startDepthStream ();
00229 
00230     
00231     setDepthRegistration (true);
00232   }
00233   else
00234     
00235     OpenNIDevice::startDepthStream ();
00236 }
00237 
00238 #endif