Point Cloud Library (PCL)
1.3.1
|
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 * Author: Suat Gedikli (gedikli@willowgarage.com) 00035 */ 00036 00037 #include "pcl/pcl_config.h" 00038 #ifdef HAVE_OPENNI 00039 00040 #ifndef __PCL_IO_ONI_PLAYER__ 00041 #define __PCL_IO_ONI_PLAYER__ 00042 00043 #include <Eigen/Core> 00044 #include <pcl/io/grabber.h> 00045 #include <pcl/io/openni_camera/openni_driver.h> 00046 #include <pcl/io/openni_camera/openni_device_oni.h> 00047 #include <pcl/io/openni_camera/openni_image.h> 00048 #include <pcl/io/openni_camera/openni_depth_image.h> 00049 #include <pcl/io/openni_camera/openni_ir_image.h> 00050 #include <string> 00051 #include <deque> 00052 #include <boost/thread/mutex.hpp> 00053 #include <pcl/common/synchronizer.h> 00054 00055 00056 namespace pcl 00057 { 00058 struct PointXYZ; 00059 struct PointXYZRGB; 00060 struct PointXYZI; 00061 template <typename T> class PointCloud; 00062 00063 class PCL_EXPORTS ONIGrabber : public Grabber 00064 { 00065 public: 00066 //define callback signature typedefs 00067 typedef void (sig_cb_openni_image) (const boost::shared_ptr<openni_wrapper::Image>&); 00068 typedef void (sig_cb_openni_depth_image) (const boost::shared_ptr<openni_wrapper::DepthImage>&); 00069 typedef void (sig_cb_openni_ir_image) (const boost::shared_ptr<openni_wrapper::IRImage>&); 00070 typedef void (sig_cb_openni_image_depth_image) (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ; 00071 typedef void (sig_cb_openni_ir_depth_image) (const boost::shared_ptr<openni_wrapper::IRImage>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ; 00072 typedef void (sig_cb_openni_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&); 00073 typedef void (sig_cb_openni_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&); 00074 typedef void (sig_cb_openni_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&); 00075 00076 ONIGrabber (const std::string& file_name, bool repeat, bool stream); 00077 00078 virtual ~ONIGrabber () throw (); 00079 00085 virtual void start (); 00086 00092 virtual void stop (); 00093 00099 virtual std::string getName () const; 00100 00105 virtual bool isRunning () const; 00106 00107 protected: 00108 void 00109 imageCallback (boost::shared_ptr<openni_wrapper::Image> image, void* cookie); 00110 00112 void 00113 depthCallback (boost::shared_ptr<openni_wrapper::DepthImage> depth_image, void* cookie); 00114 00116 void 00117 irCallback (boost::shared_ptr<openni_wrapper::IRImage> ir_image, void* cookie); 00118 00120 void 00121 imageDepthImageCallback (const boost::shared_ptr<openni_wrapper::Image> &image, 00122 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image); 00123 00125 void 00126 irDepthImageCallback (const boost::shared_ptr<openni_wrapper::IRImage> &image, 00127 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image); 00128 00130 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> > 00131 convertToXYZPointCloud (const boost::shared_ptr<openni_wrapper::DepthImage> &depth) const; 00132 00134 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> > 00135 convertToXYZRGBPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image, 00136 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const; 00138 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> > 00139 convertToXYZIPointCloud (const boost::shared_ptr<openni_wrapper::IRImage> &image, 00140 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const; 00141 Synchronizer<boost::shared_ptr<openni_wrapper::Image>, boost::shared_ptr<openni_wrapper::DepthImage> > rgb_sync_; 00142 Synchronizer<boost::shared_ptr<openni_wrapper::IRImage>, boost::shared_ptr<openni_wrapper::DepthImage> > ir_sync_; 00143 00145 boost::shared_ptr<openni_wrapper::DeviceONI> device_; 00146 std::string rgb_frame_id_; 00147 std::string depth_frame_id_; 00148 bool running_; 00149 unsigned image_width_; 00150 unsigned image_height_; 00151 unsigned depth_width_; 00152 unsigned depth_height_; 00153 openni_wrapper::OpenNIDevice::CallbackHandle depth_callback_handle; 00154 openni_wrapper::OpenNIDevice::CallbackHandle image_callback_handle; 00155 openni_wrapper::OpenNIDevice::CallbackHandle ir_callback_handle; 00156 boost::signals2::signal<sig_cb_openni_image >* image_signal_; 00157 boost::signals2::signal<sig_cb_openni_depth_image >* depth_image_signal_; 00158 boost::signals2::signal<sig_cb_openni_ir_image >* ir_image_signal_; 00159 boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_; 00160 boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_; 00161 boost::signals2::signal<sig_cb_openni_point_cloud >* point_cloud_signal_; 00162 boost::signals2::signal<sig_cb_openni_point_cloud_i >* point_cloud_i_signal_; 00163 boost::signals2::signal<sig_cb_openni_point_cloud_rgb >* point_cloud_rgb_signal_; 00164 00165 public: 00166 EIGEN_MAKE_ALIGNED_OPERATOR_NEW; 00167 }; 00168 00169 } // namespace 00170 00171 #endif // __PCL_IO_ONI_PLAYER__ 00172 #endif // HAVE_OPENNI 00173