Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
oni_grabber.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #include "pcl/pcl_config.h"
00036 #ifdef HAVE_OPENNI
00037 
00038 #ifndef __PCL_IO_ONI_PLAYER__
00039 #define __PCL_IO_ONI_PLAYER__
00040 
00041 #include <Eigen/Core>
00042 #include <pcl/io/grabber.h>
00043 #include <pcl/io/openni_camera/openni_driver.h>
00044 #include <pcl/io/openni_camera/openni_device_oni.h>
00045 #include <pcl/io/openni_camera/openni_image.h>
00046 #include <pcl/io/openni_camera/openni_depth_image.h>
00047 #include <pcl/io/openni_camera/openni_ir_image.h>
00048 #include <string>
00049 #include <deque>
00050 #include <boost/thread/mutex.hpp>
00051 #include <pcl/common/synchronizer.h>
00052 
00053 
00054 namespace pcl
00055 {
00056   struct PointXYZ;
00057   struct PointXYZRGB;
00058   struct PointXYZI;
00059   template <typename T> class PointCloud;
00060 
00061   class PCL_EXPORTS ONIGrabber : public Grabber
00062   {
00063   public:
00064     //define callback signature typedefs
00065     typedef void (sig_cb_openni_image) (const boost::shared_ptr<openni_wrapper::Image>&);
00066     typedef void (sig_cb_openni_depth_image) (const boost::shared_ptr<openni_wrapper::DepthImage>&);
00067     typedef void (sig_cb_openni_ir_image) (const boost::shared_ptr<openni_wrapper::IRImage>&);
00068     typedef void (sig_cb_openni_image_depth_image) (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ;
00069     typedef void (sig_cb_openni_ir_depth_image) (const boost::shared_ptr<openni_wrapper::IRImage>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ;
00070     typedef void (sig_cb_openni_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&);
00071     typedef void (sig_cb_openni_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&);
00072     typedef void (sig_cb_openni_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&);
00073 
00080     ONIGrabber (const std::string& file_name, bool repeat, bool stream);
00081 
00085     virtual ~ONIGrabber () throw ();
00086 
00092     virtual void start ();
00093 
00099     virtual void stop ();
00100 
00106     virtual std::string getName () const;
00107 
00112     virtual bool isRunning () const;
00113 
00117     virtual float getFramesPerSecond () const;
00118 
00119   protected:
00121     void
00122     imageCallback (boost::shared_ptr<openni_wrapper::Image> image, void* cookie);
00123 
00125     void
00126     depthCallback (boost::shared_ptr<openni_wrapper::DepthImage> depth_image, void* cookie);
00127 
00129     void
00130     irCallback (boost::shared_ptr<openni_wrapper::IRImage> ir_image, void* cookie);
00131 
00133     void
00134     imageDepthImageCallback (const boost::shared_ptr<openni_wrapper::Image> &image,
00135                              const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image);
00136 
00138     void
00139     irDepthImageCallback (const boost::shared_ptr<openni_wrapper::IRImage> &image,
00140                           const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image);
00141 
00143     boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >
00144     convertToXYZPointCloud (const boost::shared_ptr<openni_wrapper::DepthImage> &depth) const;
00145 
00147     boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> >
00148     convertToXYZRGBPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image,
00149                                const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
00150 
00152     boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> >
00153     convertToXYZIPointCloud (const boost::shared_ptr<openni_wrapper::IRImage> &image,
00154                              const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const;
00155 
00157     Synchronizer<boost::shared_ptr<openni_wrapper::Image>, boost::shared_ptr<openni_wrapper::DepthImage> > rgb_sync_;
00158 
00160     Synchronizer<boost::shared_ptr<openni_wrapper::IRImage>, boost::shared_ptr<openni_wrapper::DepthImage> > ir_sync_;
00161 
00163     boost::shared_ptr<openni_wrapper::DeviceONI> device_;
00164     std::string rgb_frame_id_;
00165     std::string depth_frame_id_;
00166     bool running_;
00167     unsigned image_width_;
00168     unsigned image_height_;
00169     unsigned depth_width_;
00170     unsigned depth_height_;
00171     openni_wrapper::OpenNIDevice::CallbackHandle depth_callback_handle;
00172     openni_wrapper::OpenNIDevice::CallbackHandle image_callback_handle;
00173     openni_wrapper::OpenNIDevice::CallbackHandle ir_callback_handle;
00174     boost::signals2::signal<sig_cb_openni_image >*            image_signal_;
00175     boost::signals2::signal<sig_cb_openni_depth_image >*      depth_image_signal_;
00176     boost::signals2::signal<sig_cb_openni_ir_image >*         ir_image_signal_;
00177     boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_;
00178     boost::signals2::signal<sig_cb_openni_ir_depth_image>*    ir_depth_image_signal_;
00179     boost::signals2::signal<sig_cb_openni_point_cloud >*      point_cloud_signal_;
00180     boost::signals2::signal<sig_cb_openni_point_cloud_i >*    point_cloud_i_signal_;
00181     boost::signals2::signal<sig_cb_openni_point_cloud_rgb >*  point_cloud_rgb_signal_;
00182 
00183   public:
00184     EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
00185   } ;
00186 
00187 } // namespace
00188 
00189 #endif // __PCL_IO_ONI_PLAYER__
00190 #endif // HAVE_OPENNI
00191 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines