Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2011-2012, 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 #ifndef __PCL_IO_ONI_PLAYER__ 00042 #define __PCL_IO_ONI_PLAYER__ 00043 00044 #include <pcl/io/eigen.h> 00045 #include <pcl/io/boost.h> 00046 #include <pcl/io/grabber.h> 00047 #include <pcl/io/openni_camera/openni_driver.h> 00048 #include <pcl/io/openni_camera/openni_device_oni.h> 00049 #include <pcl/io/openni_camera/openni_image.h> 00050 #include <pcl/io/openni_camera/openni_depth_image.h> 00051 #include <pcl/io/openni_camera/openni_ir_image.h> 00052 #include <string> 00053 #include <deque> 00054 #include <pcl/common/synchronizer.h> 00055 00056 namespace pcl 00057 { 00058 /** */ 00059 template <typename T> class PointCloud; 00060 /** */ 00061 struct PointXYZ; 00062 /** */ 00063 struct PointXYZRGB; 00064 /** */ 00065 struct PointXYZRGBA; 00066 /** */ 00067 struct PointXYZI; 00068 00069 /** \brief A simple ONI grabber. 00070 * \author Suat Gedikli 00071 * \ingroup io 00072 */ 00073 class PCL_EXPORTS ONIGrabber : public Grabber 00074 { 00075 public: 00076 //define callback signature typedefs 00077 typedef void (sig_cb_openni_image) (const boost::shared_ptr<openni_wrapper::Image>&); 00078 typedef void (sig_cb_openni_depth_image) (const boost::shared_ptr<openni_wrapper::DepthImage>&); 00079 typedef void (sig_cb_openni_ir_image) (const boost::shared_ptr<openni_wrapper::IRImage>&); 00080 typedef void (sig_cb_openni_image_depth_image) (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ; 00081 typedef void (sig_cb_openni_ir_depth_image) (const boost::shared_ptr<openni_wrapper::IRImage>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float constant) ; 00082 typedef void (sig_cb_openni_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&); 00083 typedef void (sig_cb_openni_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&); 00084 typedef void (sig_cb_openni_point_cloud_rgba) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGBA> >&); 00085 typedef void (sig_cb_openni_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&); 00086 00087 /** \brief constuctor 00088 * \param[in] file_name the path to the ONI file 00089 * \param[in] repeat whether the play back should be in an infinite loop or not 00090 * \param[in] stream whether the playback should be in streaming mode or in triggered mode. 00091 */ 00092 ONIGrabber (const std::string& file_name, bool repeat, bool stream); 00093 00094 /** \brief destructor never throws an exception */ 00095 virtual ~ONIGrabber () throw (); 00096 00097 /** \brief For devices that are streaming, the streams are started by calling this method. 00098 * Trigger-based devices, just trigger the device once for each call of start. 00099 */ 00100 virtual void 00101 start (); 00102 00103 /** \brief For devices that are streaming, the streams are stopped. 00104 * This method has no effect for triggered devices. 00105 */ 00106 virtual void 00107 stop (); 00108 00109 /** \brief returns the name of the concrete subclass. 00110 * \return the name of the concrete driver. 00111 */ 00112 virtual std::string 00113 getName () const; 00114 00115 /** \brief Indicates whether the grabber is streaming or not. This value is not defined for triggered devices. 00116 * \return true if grabber is running / streaming. False otherwise. 00117 */ 00118 virtual bool 00119 isRunning () const; 00120 00121 /** \brief returns the frames pre second. 0 if it is trigger based. */ 00122 virtual float 00123 getFramesPerSecond () const; 00124 00125 /** \brief Check if there is any data left in the ONI file to process. */ 00126 inline bool 00127 hasDataLeft () 00128 { 00129 return (device_->hasDataLeft ()); 00130 } 00131 00132 protected: 00133 /** \brief internal OpenNI (openni_wrapper) callback that handles image streams */ 00134 void 00135 imageCallback (boost::shared_ptr<openni_wrapper::Image> image, void* cookie); 00136 00137 /** \brief internal OpenNI (openni_wrapper) callback that handles depth streams */ 00138 void 00139 depthCallback (boost::shared_ptr<openni_wrapper::DepthImage> depth_image, void* cookie); 00140 00141 /** \brief internal OpenNI (openni_wrapper) callback that handles IR streams */ 00142 void 00143 irCallback (boost::shared_ptr<openni_wrapper::IRImage> ir_image, void* cookie); 00144 00145 /** \brief internal callback that handles synchronized image + depth streams */ 00146 void 00147 imageDepthImageCallback (const boost::shared_ptr<openni_wrapper::Image> &image, 00148 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image); 00149 00150 /** \brief internal callback that handles synchronized IR + depth streams */ 00151 void 00152 irDepthImageCallback (const boost::shared_ptr<openni_wrapper::IRImage> &image, 00153 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image); 00154 00155 /** \brief internal method to assemble a point cloud object */ 00156 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> > 00157 convertToXYZPointCloud (const boost::shared_ptr<openni_wrapper::DepthImage> &depth) const; 00158 00159 /** \brief internal method to assemble a point cloud object */ 00160 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> > 00161 convertToXYZRGBPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image, 00162 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const; 00163 00164 /** \brief internal method to assemble a point cloud object */ 00165 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> > 00166 convertToXYZRGBAPointCloud (const boost::shared_ptr<openni_wrapper::Image> &image, 00167 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const; 00168 00169 /** \brief internal method to assemble a point cloud object */ 00170 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> > 00171 convertToXYZIPointCloud (const boost::shared_ptr<openni_wrapper::IRImage> &image, 00172 const boost::shared_ptr<openni_wrapper::DepthImage> &depth_image) const; 00173 00174 /** \brief synchronizer object to synchronize image and depth streams*/ 00175 Synchronizer<boost::shared_ptr<openni_wrapper::Image>, boost::shared_ptr<openni_wrapper::DepthImage> > rgb_sync_; 00176 00177 /** \brief synchronizer object to synchronize IR and depth streams*/ 00178 Synchronizer<boost::shared_ptr<openni_wrapper::IRImage>, boost::shared_ptr<openni_wrapper::DepthImage> > ir_sync_; 00179 00180 /** \brief the actual openni device*/ 00181 boost::shared_ptr<openni_wrapper::DeviceONI> device_; 00182 std::string rgb_frame_id_; 00183 std::string depth_frame_id_; 00184 bool running_; 00185 unsigned image_width_; 00186 unsigned image_height_; 00187 unsigned depth_width_; 00188 unsigned depth_height_; 00189 openni_wrapper::OpenNIDevice::CallbackHandle depth_callback_handle; 00190 openni_wrapper::OpenNIDevice::CallbackHandle image_callback_handle; 00191 openni_wrapper::OpenNIDevice::CallbackHandle ir_callback_handle; 00192 boost::signals2::signal<sig_cb_openni_image >* image_signal_; 00193 boost::signals2::signal<sig_cb_openni_depth_image >* depth_image_signal_; 00194 boost::signals2::signal<sig_cb_openni_ir_image >* ir_image_signal_; 00195 boost::signals2::signal<sig_cb_openni_image_depth_image>* image_depth_image_signal_; 00196 boost::signals2::signal<sig_cb_openni_ir_depth_image>* ir_depth_image_signal_; 00197 boost::signals2::signal<sig_cb_openni_point_cloud >* point_cloud_signal_; 00198 boost::signals2::signal<sig_cb_openni_point_cloud_i >* point_cloud_i_signal_; 00199 boost::signals2::signal<sig_cb_openni_point_cloud_rgb >* point_cloud_rgb_signal_; 00200 boost::signals2::signal<sig_cb_openni_point_cloud_rgba >* point_cloud_rgba_signal_; 00201 00202 public: 00203 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00204 }; 00205 00206 } // namespace 00207 00208 #endif // __PCL_IO_ONI_PLAYER__ 00209 #endif // HAVE_OPENNI 00210