00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #pragma once
00042 #ifndef __PCL_IO_IMAGE_GRABBER__
00043 #define __PCL_IO_IMAGE_GRABBER__
00044
00045 #include "pcl/pcl_config.h"
00046 #include <pcl/io/grabber.h>
00047 #include <pcl/io/file_grabber.h>
00048 #include <pcl/common/time_trigger.h>
00049 #include <string>
00050 #include <vector>
00051 #include <pcl/conversions.h>
00052
00053 namespace pcl
00054 {
00058 class PCL_EXPORTS ImageGrabberBase : public Grabber
00059 {
00060 public:
00066 ImageGrabberBase (const std::string& directory, float frames_per_second, bool repeat, bool pclzf_mode);
00067
00068 ImageGrabberBase (const std::string& depth_directory, const std::string& rgb_directory, float frames_per_second, bool repeat);
00074 ImageGrabberBase (const std::vector<std::string>& depth_image_files, float frames_per_second, bool repeat);
00075
00079 ImageGrabberBase (const ImageGrabberBase &src) : Grabber (), impl_ ()
00080 {
00081 *this = src;
00082 }
00083
00087 ImageGrabberBase&
00088 operator = (const ImageGrabberBase &src)
00089 {
00090 impl_ = src.impl_;
00091 return (*this);
00092 }
00093
00095 virtual ~ImageGrabberBase () throw ();
00096
00098 virtual void
00099 start ();
00100
00102 virtual void
00103 stop ();
00104
00106 virtual void
00107 trigger ();
00108
00112 virtual bool
00113 isRunning () const;
00114
00116 virtual std::string
00117 getName () const;
00118
00120 virtual void
00121 rewind ();
00122
00124 virtual float
00125 getFramesPerSecond () const;
00126
00128 bool
00129 isRepeatOn () const;
00130
00132 bool
00133 atLastFrame () const;
00134
00136 std::string
00137 getCurrentDepthFileName () const;
00138
00141 std::string
00142 getPrevDepthFileName () const;
00143
00145 std::string
00146 getDepthFileNameAtIndex (size_t idx) const;
00147
00149 bool
00150 getTimestampAtIndex (size_t idx, uint64_t ×tamp) const;
00151
00155 void
00156 setRGBImageFiles (const std::vector<std::string>& rgb_image_files);
00157
00164 virtual void
00165 setCameraIntrinsics (const double focal_length_x,
00166 const double focal_length_y,
00167 const double principal_point_x,
00168 const double principal_point_y);
00169
00176 virtual void
00177 getCameraIntrinsics (double &focal_length_x,
00178 double &focal_length_y,
00179 double &principal_point_x,
00180 double &principal_point_y) const;
00181
00184 void
00185 setDepthImageUnits (float units);
00186
00189 void
00190 setNumberOfThreads (unsigned int nr_threads = 0);
00191
00192 protected:
00194 size_t
00195 numFrames () const;
00196
00198 bool
00199 getCloudAt (size_t idx, pcl::PCLPointCloud2 &blob, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation) const;
00200
00201
00202 private:
00203 virtual void
00204 publish (const pcl::PCLPointCloud2& blob, const Eigen::Vector4f& origin, const Eigen::Quaternionf& orientation) const = 0;
00205
00206
00207
00208 struct ImageGrabberImpl;
00209 ImageGrabberImpl* impl_;
00210 };
00211
00213 template <typename T> class PointCloud;
00214 template <typename PointT> class ImageGrabber : public ImageGrabberBase, public FileGrabber<PointT>
00215 {
00216 public:
00217 ImageGrabber (const std::string& dir,
00218 float frames_per_second = 0,
00219 bool repeat = false,
00220 bool pclzf_mode = false);
00221
00222 ImageGrabber (const std::string& depth_dir,
00223 const std::string& rgb_dir,
00224 float frames_per_second = 0,
00225 bool repeat = false);
00226
00227 ImageGrabber (const std::vector<std::string>& depth_image_files,
00228 float frames_per_second = 0,
00229 bool repeat = false);
00230
00232 virtual ~ImageGrabber () throw () {}
00233
00234
00235 const boost::shared_ptr< const pcl::PointCloud<PointT> >
00236 operator[] (size_t idx) const;
00237
00238
00239 size_t
00240 size () const;
00241
00242 protected:
00243 virtual void
00244 publish (const pcl::PCLPointCloud2& blob,
00245 const Eigen::Vector4f& origin,
00246 const Eigen::Quaternionf& orientation) const;
00247 boost::signals2::signal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>* signal_;
00248 };
00249
00251 template<typename PointT>
00252 ImageGrabber<PointT>::ImageGrabber (const std::string& dir,
00253 float frames_per_second,
00254 bool repeat,
00255 bool pclzf_mode)
00256 : ImageGrabberBase (dir, frames_per_second, repeat, pclzf_mode)
00257 {
00258 signal_ = createSignal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>();
00259 }
00260
00262 template<typename PointT>
00263 ImageGrabber<PointT>::ImageGrabber (const std::string& depth_dir,
00264 const std::string& rgb_dir,
00265 float frames_per_second,
00266 bool repeat)
00267 : ImageGrabberBase (depth_dir, rgb_dir, frames_per_second, repeat)
00268 {
00269 signal_ = createSignal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>();
00270 }
00271
00273 template<typename PointT>
00274 ImageGrabber<PointT>::ImageGrabber (const std::vector<std::string>& depth_image_files,
00275 float frames_per_second,
00276 bool repeat)
00277 : ImageGrabberBase (depth_image_files, frames_per_second, repeat), signal_ ()
00278 {
00279 signal_ = createSignal<void (const boost::shared_ptr<const pcl::PointCloud<PointT> >&)>();
00280 }
00281
00283 template<typename PointT> const boost::shared_ptr< const pcl::PointCloud<PointT> >
00284 ImageGrabber<PointT>::operator[] (size_t idx) const
00285 {
00286 pcl::PCLPointCloud2 blob;
00287 Eigen::Vector4f origin;
00288 Eigen::Quaternionf orientation;
00289 getCloudAt (idx, blob, origin, orientation);
00290 typename pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT> ());
00291 pcl::fromPCLPointCloud2 (blob, *cloud);
00292 cloud->sensor_origin_ = origin;
00293 cloud->sensor_orientation_ = orientation;
00294 return (cloud);
00295 }
00296
00298 template <typename PointT> size_t
00299 ImageGrabber<PointT>::size () const
00300 {
00301 return (numFrames ());
00302 }
00303
00305 template<typename PointT> void
00306 ImageGrabber<PointT>::publish (const pcl::PCLPointCloud2& blob, const Eigen::Vector4f& origin, const Eigen::Quaternionf& orientation) const
00307 {
00308 typename pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT> ());
00309 pcl::fromPCLPointCloud2 (blob, *cloud);
00310 cloud->sensor_origin_ = origin;
00311 cloud->sensor_orientation_ = orientation;
00312
00313 signal_->operator () (cloud);
00314 }
00315 }
00316 #endif