openni_device_kinect.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2011, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
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_kinect.h>
00046 #include <pcl/io/openni_camera/openni_image_bayer_grbg.h>
00047 
00048 namespace openni_wrapper
00049 {
00050 
00052 bool 
00053 openni_wrapper::DeviceKinect::isSynchronizationSupported () const throw ()
00054 {
00055   return (false);
00056 }
00057 
00059 openni_wrapper::DeviceKinect::DeviceKinect (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node, const xn::NodeInfo& depth_node, const xn::NodeInfo& ir_node)
00060 : OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
00061 , debayering_method_ (ImageBayerGRBG::EdgeAwareWeighted)
00062 {
00063   // setup stream modes
00064   enumAvailableModes ();
00065   setDepthOutputMode (getDefaultDepthMode ());
00066   setImageOutputMode (getDefaultImageMode ());
00067   setIROutputMode (getDefaultIRMode ());
00068 
00069   // device specific initialization
00070   XnStatus status;
00071 
00072   boost::unique_lock<boost::mutex> image_lock (image_mutex_);
00073   // set kinect specific format. Thus input = uncompressed Bayer, output = grayscale = bypass = bayer
00074   status = image_generator_.SetIntProperty ("InputFormat", 6);
00075   if (status != XN_STATUS_OK)
00076     THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed 8-bit BAYER. Reason: %s", xnGetStatusString (status));
00077 
00078   // Grayscale: bypass debayering -> gives us bayer pattern!
00079   status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_GRAYSCALE_8_BIT);
00080   if (status != XN_STATUS_OK)
00081     THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to 8bit-grayscale. Reason: %s", xnGetStatusString (status));
00082   image_lock.unlock ();
00083 
00084   boost::lock_guard<boost::mutex> depth_lock (depth_mutex_);
00085   // RegistrationType should be 2 (software) for Kinect, 1 (hardware) for PS
00086   status = depth_generator_.SetIntProperty ("RegistrationType", 2);
00087   if (status != XN_STATUS_OK)
00088     THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
00089 }
00090 
00092 openni_wrapper::DeviceKinect::~DeviceKinect () throw ()
00093 {
00094   depth_mutex_.lock ();
00095   depth_generator_.UnregisterFromNewDataAvailable (depth_callback_handle_);
00096   depth_mutex_.unlock ();
00097 
00098   image_mutex_.lock ();
00099   image_generator_.UnregisterFromNewDataAvailable (image_callback_handle_);
00100   image_mutex_.unlock ();
00101 }
00102 
00104 bool 
00105 openni_wrapper::DeviceKinect::isImageResizeSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const throw ()
00106 {
00107   return (ImageBayerGRBG::resizingSupported (input_width, input_height, output_width, output_height));
00108 }
00109 
00111 void 
00112 openni_wrapper::DeviceKinect::enumAvailableModes () throw ()
00113 {
00114   XnMapOutputMode output_mode;
00115   available_image_modes_.clear();
00116   available_depth_modes_.clear();
00117 
00118   output_mode.nFPS = 30;
00119   output_mode.nXRes = XN_VGA_X_RES;
00120   output_mode.nYRes = XN_VGA_Y_RES;
00121   available_image_modes_.push_back (output_mode);
00122   available_depth_modes_.push_back (output_mode);
00123 
00124   output_mode.nFPS = 15;
00125   output_mode.nXRes = XN_SXGA_X_RES;
00126   output_mode.nYRes = XN_SXGA_Y_RES;
00127   available_image_modes_.push_back (output_mode);
00128 }
00129 
00131 boost::shared_ptr<openni_wrapper::Image> 
00132 openni_wrapper::DeviceKinect::getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data) const throw ()
00133 {
00134   return (boost::shared_ptr<Image> (new ImageBayerGRBG (image_data, debayering_method_)));
00135 }
00136 
00137 }//namespace
00138 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:23