Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
pcd_grabber.h
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) 2010-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  */
00037 
00038 #include "pcl/pcl_config.h"
00039 
00040 #ifndef __PCL_IO_PCD_GRABBER__
00041 #define __PCL_IO_PCD_GRABBER__
00042 
00043 #include <pcl/io/grabber.h>
00044 #include <pcl/common/time_trigger.h>
00045 #include <string>
00046 #include <vector>
00047 #include <pcl/ros/conversions.h>
00048 
00049 namespace pcl
00050 {
00054   class PCL_EXPORTS PCDGrabberBase : public Grabber
00055   {
00056     public:
00062       PCDGrabberBase (const std::string& pcd_file, float frames_per_second, bool repeat);
00063 
00070       PCDGrabberBase (const std::vector<std::string>& pcd_files, float frames_per_second, bool repeat);
00074       virtual ~PCDGrabberBase () throw ();
00078       virtual void start ();
00082       virtual void stop ();
00086       virtual void trigger ();
00091       virtual bool isRunning () const;
00096       virtual std::string getName () const;
00100       virtual void rewind ();
00101 
00105       virtual float getFramesPerSecond () const;
00106 
00110       bool isRepeatOn () const;
00111 
00112     private:
00113       virtual void publish (const sensor_msgs::PointCloud2& blob, const Eigen::Vector4f& origin, const Eigen::Quaternionf& orientation) const = 0;
00114 
00115       // to separate and hide the implementation from interface: PIMPL
00116       struct PCDGrabberImpl;
00117       PCDGrabberImpl* impl_;
00118   };
00119 
00123   template <typename T> class PointCloud;
00124   //class sensor_msgs::PointCloud2;
00125   template <typename PointT> class PCDGrabber : public PCDGrabberBase
00126   {
00127     public:
00128       PCDGrabber (const std::string& pcd_path, float frames_per_second = 0, bool repeat = false);
00129       PCDGrabber (const std::vector<std::string>& pcd_files, float frames_per_second = 0, bool repeat = false);
00130     protected:
00131       virtual void publish (const sensor_msgs::PointCloud2& blob, const Eigen::Vector4f& origin, const Eigen::Quaternionf& orientation) const;
00132       boost::signals2::signal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>* signal_;
00133   };
00134 
00135   template<typename PointT>
00136   PCDGrabber<PointT>::PCDGrabber (const std::string& pcd_path, float frames_per_second, bool repeat)
00137   : PCDGrabberBase ( pcd_path, frames_per_second, repeat)
00138   {
00139     signal_ = createSignal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>();
00140   }
00141 
00142   template<typename PointT>
00143   PCDGrabber<PointT>::PCDGrabber (const std::vector<std::string>& pcd_files, float frames_per_second, bool repeat)
00144   : PCDGrabberBase ( pcd_files, frames_per_second, repeat)
00145   {
00146     signal_ = createSignal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>();
00147   }
00148 
00149   template<typename PointT>
00150   void PCDGrabber<PointT>::publish (const sensor_msgs::PointCloud2& blob, const Eigen::Vector4f& origin, const Eigen::Quaternionf& orientation) const
00151   {
00152     typename pcl::PointCloud<PointT>::Ptr cloud( new pcl::PointCloud<PointT> () );
00153     pcl::fromROSMsg (blob, *cloud);
00154     cloud->sensor_origin_ = origin;
00155     cloud->sensor_orientation_ = orientation;
00156 
00157     signal_->operator () (cloud);
00158   }
00159 }
00160 #endif