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 #ifndef PCL_POINT_CLOUD_HANDLERS_H_
00038 #define PCL_POINT_CLOUD_HANDLERS_H_
00039
00040 #include <pcl_visualization/common/common.h>
00041
00042 #include <pcl/point_types.h>
00043 #include <pcl/point_cloud.h>
00044 #include <pcl/io/io.h>
00045
00046 #include <vtkSmartPointer.h>
00047 #include <vtkDataArray.h>
00048 #include <vtkUnsignedCharArray.h>
00049 #include <vtkFloatArray.h>
00050 #include <vtkPoints.h>
00051
00052 namespace pcl_visualization
00053 {
00057
00058 template <typename PointT>
00059 class PointCloudGeometryHandler
00060 {
00061 public:
00062 typedef pcl::PointCloud<PointT> PointCloud;
00063 typedef typename PointCloud::Ptr PointCloudPtr;
00064 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00065
00066 typedef typename boost::shared_ptr<PointCloudGeometryHandler<PointT> > Ptr;
00067 typedef typename boost::shared_ptr<const PointCloudGeometryHandler<PointT> > ConstPtr;
00068
00069 inline Ptr makeShared () const { return (boost::make_shared<PointCloudGeometryHandler<PointT> >) (*this); }
00070
00072 PointCloudGeometryHandler (const PointCloud &cloud) : cloud_ (), capable_ (false)
00073 {
00074 cloud_.reset (new PointCloud (cloud));
00075 }
00076
00078 virtual std::string getName () const = 0;
00079
00081 virtual std::string getFieldName () const = 0;
00082
00084 inline bool isCapable () const { return (capable_); }
00085
00089 virtual void getGeometry (vtkSmartPointer<vtkPoints> &points) const = 0;
00090
00091 protected:
00093 PointCloudPtr cloud_;
00094
00096 bool capable_;
00097
00099 int field_x_idx_;
00100
00102 int field_y_idx_;
00103
00105 int field_z_idx_;
00106
00109 std::vector<sensor_msgs::PointField> fields_;
00110 };
00111
00113
00114 template <typename PointT>
00115 class PointCloudGeometryHandlerXYZ : public PointCloudGeometryHandler<PointT>
00116 {
00117 public:
00118 typedef typename PointCloudGeometryHandler<PointT>::PointCloud PointCloud;
00119 typedef typename PointCloud::Ptr PointCloudPtr;
00120 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00121
00122 typedef typename boost::shared_ptr<PointCloudGeometryHandlerXYZ<PointT> > Ptr;
00123 typedef typename boost::shared_ptr<const PointCloudGeometryHandlerXYZ<PointT> > ConstPtr;
00124
00126 PointCloudGeometryHandlerXYZ (const PointCloud &cloud);
00127
00129 virtual inline std::string getName () const { return ("PointCloudGeometryHandlerXYZ"); }
00130
00132 virtual std::string getFieldName () const { return ("xyz"); }
00133
00137 virtual void getGeometry (vtkSmartPointer<vtkPoints> &points) const;
00138
00139 private:
00140
00141 using PointCloudGeometryHandler<PointT>::cloud_;
00142 using PointCloudGeometryHandler<PointT>::capable_;
00143 using PointCloudGeometryHandler<PointT>::field_x_idx_;
00144 using PointCloudGeometryHandler<PointT>::field_y_idx_;
00145 using PointCloudGeometryHandler<PointT>::field_z_idx_;
00146 using PointCloudGeometryHandler<PointT>::fields_;
00147 };
00148
00150
00151 template <typename PointT>
00152 class PointCloudGeometryHandlerSurfaceNormal : public PointCloudGeometryHandler<PointT>
00153 {
00154 public:
00155 typedef typename PointCloudGeometryHandler<PointT>::PointCloud PointCloud;
00156 typedef typename PointCloud::Ptr PointCloudPtr;
00157 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00158
00159 typedef typename boost::shared_ptr<PointCloudGeometryHandlerSurfaceNormal<PointT> > Ptr;
00160 typedef typename boost::shared_ptr<const PointCloudGeometryHandlerSurfaceNormal<PointT> > ConstPtr;
00161
00163 PointCloudGeometryHandlerSurfaceNormal (const PointCloud &cloud);
00164
00166 virtual inline std::string getName () const { return ("PointCloudGeometryHandlerSurfaceNormal"); }
00167
00169 virtual std::string getFieldName () const { return ("normal_xyz"); }
00170
00174 virtual void getGeometry (vtkSmartPointer<vtkPoints> &points) const;
00175
00176 private:
00177
00178 using PointCloudGeometryHandler<PointT>::cloud_;
00179 using PointCloudGeometryHandler<PointT>::capable_;
00180 using PointCloudGeometryHandler<PointT>::field_x_idx_;
00181 using PointCloudGeometryHandler<PointT>::field_y_idx_;
00182 using PointCloudGeometryHandler<PointT>::field_z_idx_;
00183 using PointCloudGeometryHandler<PointT>::fields_;
00184 };
00185
00187
00188 template <typename PointT>
00189 class PointCloudGeometryHandlerCustom : public PointCloudGeometryHandler<PointT>
00190 {
00191 public:
00192 typedef typename PointCloudGeometryHandler<PointT>::PointCloud PointCloud;
00193 typedef typename PointCloud::Ptr PointCloudPtr;
00194 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00195
00196 typedef typename boost::shared_ptr<PointCloudGeometryHandlerCustom<PointT> > Ptr;
00197 typedef typename boost::shared_ptr<const PointCloudGeometryHandlerCustom<PointT> > ConstPtr;
00198
00200 PointCloudGeometryHandlerCustom (const PointCloud &cloud, const std::string &x_field_name, const std::string &y_field_name, const std::string &z_field_name);
00201
00203 virtual inline std::string getName () const { return ("PointCloudGeometryHandlerCustom"); }
00204
00206 virtual std::string getFieldName () const { return (field_name_); }
00207
00211 virtual void getGeometry (vtkSmartPointer<vtkPoints> &points) const;
00212
00213 private:
00214
00215 using PointCloudGeometryHandler<PointT>::cloud_;
00216 using PointCloudGeometryHandler<PointT>::capable_;
00217 using PointCloudGeometryHandler<PointT>::field_x_idx_;
00218 using PointCloudGeometryHandler<PointT>::field_y_idx_;
00219 using PointCloudGeometryHandler<PointT>::field_z_idx_;
00220 using PointCloudGeometryHandler<PointT>::fields_;
00221
00223 std::string field_name_;
00224 };
00225
00229
00230 template <>
00231 class PointCloudGeometryHandler<sensor_msgs::PointCloud2>
00232 {
00233 public:
00234 typedef sensor_msgs::PointCloud2 PointCloud;
00235 typedef PointCloud::Ptr PointCloudPtr;
00236 typedef PointCloud::ConstPtr PointCloudConstPtr;
00237
00238 typedef boost::shared_ptr<PointCloudGeometryHandler<PointCloud> > Ptr;
00239 typedef boost::shared_ptr<const PointCloudGeometryHandler<PointCloud> > ConstPtr;
00240
00242 PointCloudGeometryHandler (const PointCloud &cloud) : cloud_ (), capable_ (false)
00243 {
00244 cloud_.reset (new PointCloud (cloud));
00245 fields_ = cloud_->fields;
00246 }
00247
00249 virtual std::string getName () const = 0;
00250
00252 virtual std::string getFieldName () const = 0;
00253
00255 inline bool isCapable () const { return (capable_); }
00256
00260 virtual void getGeometry (vtkSmartPointer<vtkPoints> &points) const;
00261
00262 protected:
00264 PointCloudPtr cloud_;
00265
00267 bool capable_;
00268
00270 int field_x_idx_;
00271
00273 int field_y_idx_;
00274
00276 int field_z_idx_;
00277
00279 std::vector<sensor_msgs::PointField> fields_;
00280 };
00281
00283
00284 template <>
00285 class PointCloudGeometryHandlerXYZ<sensor_msgs::PointCloud2> : public PointCloudGeometryHandler<sensor_msgs::PointCloud2>
00286 {
00287 public:
00288 typedef PointCloudGeometryHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00289 typedef PointCloud::Ptr PointCloudPtr;
00290 typedef PointCloud::ConstPtr PointCloudConstPtr;
00291
00292 typedef boost::shared_ptr<PointCloudGeometryHandlerXYZ<PointCloud> > Ptr;
00293 typedef boost::shared_ptr<const PointCloudGeometryHandlerXYZ<PointCloud> > ConstPtr;
00294
00296 PointCloudGeometryHandlerXYZ (const PointCloud &cloud);
00297
00299 virtual inline std::string getName () const { return ("PointCloudGeometryHandlerXYZ"); }
00300
00302 virtual std::string getFieldName () const { return ("xyz"); }
00303 };
00304
00306
00307 template <>
00308 class PointCloudGeometryHandlerSurfaceNormal<sensor_msgs::PointCloud2> : public PointCloudGeometryHandler<sensor_msgs::PointCloud2>
00309 {
00310 public:
00311 typedef PointCloudGeometryHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00312 typedef PointCloud::Ptr PointCloudPtr;
00313 typedef PointCloud::ConstPtr PointCloudConstPtr;
00314
00315 typedef boost::shared_ptr<PointCloudGeometryHandlerSurfaceNormal<PointCloud> > Ptr;
00316 typedef boost::shared_ptr<const PointCloudGeometryHandlerSurfaceNormal<PointCloud> > ConstPtr;
00317
00319 PointCloudGeometryHandlerSurfaceNormal (const PointCloud &cloud);
00320
00322 virtual inline std::string getName () const { return ("PointCloudGeometryHandlerSurfaceNormal"); }
00323
00325 virtual std::string getFieldName () const { return ("normal_xyz"); }
00326 };
00327
00329
00330 template <>
00331 class PointCloudGeometryHandlerCustom<sensor_msgs::PointCloud2> : public PointCloudGeometryHandler<sensor_msgs::PointCloud2>
00332 {
00333 public:
00334 typedef PointCloudGeometryHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00335 typedef PointCloud::Ptr PointCloudPtr;
00336 typedef PointCloud::ConstPtr PointCloudConstPtr;
00337
00339 PointCloudGeometryHandlerCustom (const PointCloud &cloud, const std::string &x_field_name, const std::string &y_field_name, const std::string &z_field_name);
00340
00342 virtual inline std::string getName () const { return ("PointCloudGeometryHandlerCustom"); }
00343
00345 virtual std::string getFieldName () const { return (field_name_); }
00346 private:
00348 std::string field_name_;
00349 };
00350
00354
00355 template <typename PointT>
00356 class PointCloudColorHandler
00357 {
00358 public:
00359 typedef pcl::PointCloud<PointT> PointCloud;
00360 typedef typename PointCloud::Ptr PointCloudPtr;
00361 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00362
00363 typedef boost::shared_ptr<PointCloudColorHandler<PointT> > Ptr;
00364 typedef boost::shared_ptr<const PointCloudColorHandler<PointT> > ConstPtr;
00365
00366 inline Ptr makeShared () const { return (boost::make_shared<PointCloudColorHandler<PointT> >) (*this); }
00367
00369 PointCloudColorHandler (const PointCloud &cloud) : cloud_ (), capable_ (false)
00370 {
00371 cloud_.reset (new PointCloud (cloud));
00372 }
00373
00374
00376 inline bool isCapable () const { return (capable_); }
00377
00378
00380 virtual std::string getName () const = 0;
00381
00382
00384 virtual std::string getFieldName () const = 0;
00385
00386
00390 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const = 0;
00391
00392 protected:
00394 PointCloudPtr cloud_;
00395
00397 bool capable_;
00398
00400 int field_idx_;
00401
00404 std::vector<sensor_msgs::PointField> fields_;
00405 };
00406
00408
00409 template <typename PointT>
00410 class PointCloudColorHandlerRandom : public PointCloudColorHandler<PointT>
00411 {
00412 typedef typename PointCloudColorHandler<PointT>::PointCloud PointCloud;
00413 typedef typename PointCloud::Ptr PointCloudPtr;
00414 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00415
00416 public:
00417 typedef boost::shared_ptr<PointCloudColorHandlerRandom<PointT> > Ptr;
00418 typedef boost::shared_ptr<const PointCloudColorHandlerRandom<PointT> > ConstPtr;
00419
00421 PointCloudColorHandlerRandom (const PointCloud &cloud) : PointCloudColorHandler<PointT> (cloud) { capable_ = true; }
00422
00424 virtual inline std::string getName () const { return ("PointCloudColorHandlerRandom"); }
00425
00427 virtual std::string getFieldName () const { return ("[random]"); }
00428
00432 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00433
00434 protected:
00435
00436 using PointCloudColorHandler<PointT>::cloud_;
00437 using PointCloudColorHandler<PointT>::capable_;
00438 };
00439
00441
00442 template <typename PointT>
00443 class PointCloudColorHandlerCustom : public PointCloudColorHandler<PointT>
00444 {
00445 typedef typename PointCloudColorHandler<PointT>::PointCloud PointCloud;
00446 typedef typename PointCloud::Ptr PointCloudPtr;
00447 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00448
00449 public:
00450 typedef boost::shared_ptr<PointCloudColorHandlerCustom<PointT> > Ptr;
00451 typedef boost::shared_ptr<const PointCloudColorHandlerCustom<PointT> > ConstPtr;
00452
00454 PointCloudColorHandlerCustom (const PointCloud &cloud, double r, double g, double b) : PointCloudColorHandler<PointT> (cloud)
00455 {
00456 capable_ = true;
00457 r_ = r;
00458 g_ = g;
00459 b_ = b;
00460 }
00461
00463 virtual inline std::string getName () const { return ("PointCloudColorHandlerCustom"); }
00464
00466 virtual std::string getFieldName () const { return (""); }
00467
00471 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00472
00473 protected:
00474
00475 using PointCloudColorHandler<PointT>::cloud_;
00476 using PointCloudColorHandler<PointT>::capable_;
00477
00479 double r_, g_, b_;
00480 };
00481
00483
00484 template <typename PointT>
00485 class PointCloudColorHandlerRGBField : public PointCloudColorHandler<PointT>
00486 {
00487 typedef typename PointCloudColorHandler<PointT>::PointCloud PointCloud;
00488 typedef typename PointCloud::Ptr PointCloudPtr;
00489 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00490
00491 public:
00492 typedef boost::shared_ptr<PointCloudColorHandlerRGBField<PointT> > Ptr;
00493 typedef boost::shared_ptr<const PointCloudColorHandlerRGBField<PointT> > ConstPtr;
00494
00496 PointCloudColorHandlerRGBField (const PointCloud &cloud);
00497
00499 virtual std::string getFieldName () const { return ("rgb"); }
00500
00501 protected:
00503 virtual inline std::string getName () const { return ("PointCloudColorHandlerRGBField"); }
00504
00508 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00509
00510 private:
00511
00512 using PointCloudColorHandler<PointT>::cloud_;
00513 using PointCloudColorHandler<PointT>::capable_;
00514 using PointCloudColorHandler<PointT>::field_idx_;
00515 using PointCloudColorHandler<PointT>::fields_;
00516 };
00517
00519
00520 template <typename PointT>
00521 class PointCloudColorHandlerGenericField : public PointCloudColorHandler<PointT>
00522 {
00523 typedef typename PointCloudColorHandler<PointT>::PointCloud PointCloud;
00524 typedef typename PointCloud::Ptr PointCloudPtr;
00525 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00526
00527 public:
00528 typedef boost::shared_ptr<PointCloudColorHandlerGenericField<PointT> > Ptr;
00529 typedef boost::shared_ptr<const PointCloudColorHandlerGenericField<PointT> > ConstPtr;
00530
00532 PointCloudColorHandlerGenericField (const PointCloud &cloud, const std::string &field_name);
00533
00535 virtual std::string getFieldName () const { return (field_name_); }
00536
00537 protected:
00539 virtual inline std::string getName () const { return ("PointCloudColorHandlerGenericField"); }
00540
00544 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00545
00546 private:
00547 using PointCloudColorHandler<PointT>::cloud_;
00548 using PointCloudColorHandler<PointT>::capable_;
00549 using PointCloudColorHandler<PointT>::field_idx_;
00550 using PointCloudColorHandler<PointT>::fields_;
00551
00553 std::string field_name_;
00554 };
00555
00559
00560 template <>
00561 class PointCloudColorHandler<sensor_msgs::PointCloud2>
00562 {
00563 public:
00564 typedef sensor_msgs::PointCloud2 PointCloud;
00565 typedef PointCloud::Ptr PointCloudPtr;
00566 typedef PointCloud::ConstPtr PointCloudConstPtr;
00567
00568 typedef boost::shared_ptr<PointCloudColorHandler<PointCloud> > Ptr;
00569 typedef boost::shared_ptr<const PointCloudColorHandler<PointCloud> > ConstPtr;
00570
00572 PointCloudColorHandler (const PointCloud &cloud) : cloud_ (), capable_ (false)
00573 {
00574 cloud_.reset (new PointCloud (cloud));
00575 }
00576
00578 inline bool isCapable () const { return (capable_); }
00579
00581 virtual std::string getName () const = 0;
00582
00584 virtual std::string getFieldName () const = 0;
00585
00589 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const = 0;
00590
00591 protected:
00593 PointCloudPtr cloud_;
00594
00596 bool capable_;
00597
00599 int field_idx_;
00600 };
00601
00603
00604 template <>
00605 class PointCloudColorHandlerRandom<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
00606 {
00607 typedef PointCloudColorHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00608 typedef PointCloud::Ptr PointCloudPtr;
00609 typedef PointCloud::ConstPtr PointCloudConstPtr;
00610
00611 public:
00612 typedef boost::shared_ptr<PointCloudColorHandlerRandom<PointCloud> > Ptr;
00613 typedef boost::shared_ptr<const PointCloudColorHandlerRandom<PointCloud> > ConstPtr;
00614
00616 PointCloudColorHandlerRandom (const PointCloud &cloud) : PointCloudColorHandler<sensor_msgs::PointCloud2> (cloud) { capable_ = true; }
00617
00619 virtual inline std::string getName () const { return ("PointCloudColorHandlerRandom"); }
00620
00622 virtual std::string getFieldName () const { return ("[random]"); }
00623
00627 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00628 };
00629
00631
00632 template <>
00633 class PointCloudColorHandlerCustom<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
00634 {
00635 typedef PointCloudColorHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00636 typedef PointCloud::Ptr PointCloudPtr;
00637 typedef PointCloud::ConstPtr PointCloudConstPtr;
00638
00639 public:
00641 PointCloudColorHandlerCustom (const PointCloud &cloud, double r, double g, double b) : PointCloudColorHandler<sensor_msgs::PointCloud2> (cloud)
00642 {
00643 capable_ = true;
00644 r_ = r;
00645 g_ = g;
00646 b_ = b;
00647 }
00648
00650 virtual inline std::string getName () const { return ("PointCloudColorHandlerCustom"); }
00651
00653 virtual std::string getFieldName () const { return (""); }
00654
00658 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00659
00660 protected:
00662 double r_, g_, b_;
00663 };
00664
00666
00667 template <>
00668 class PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
00669 {
00670 typedef PointCloudColorHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00671 typedef PointCloud::Ptr PointCloudPtr;
00672 typedef PointCloud::ConstPtr PointCloudConstPtr;
00673
00674 public:
00675 typedef boost::shared_ptr<PointCloudColorHandlerRGBField<PointCloud> > Ptr;
00676 typedef boost::shared_ptr<const PointCloudColorHandlerRGBField<PointCloud> > ConstPtr;
00677
00679 PointCloudColorHandlerRGBField (const PointCloud &cloud);
00680
00681 protected:
00683 virtual inline std::string getName () const { return ("PointCloudColorHandlerRGBField"); }
00684
00686 virtual std::string getFieldName () const { return ("rgb"); }
00687
00691 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00692 };
00693
00695
00696 template <>
00697 class PointCloudColorHandlerGenericField<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
00698 {
00699 typedef PointCloudColorHandler<sensor_msgs::PointCloud2>::PointCloud PointCloud;
00700 typedef PointCloud::Ptr PointCloudPtr;
00701 typedef PointCloud::ConstPtr PointCloudConstPtr;
00702
00703 public:
00704 typedef boost::shared_ptr<PointCloudColorHandlerGenericField<PointCloud> > Ptr;
00705 typedef boost::shared_ptr<const PointCloudColorHandlerGenericField<PointCloud> > ConstPtr;
00706
00708 PointCloudColorHandlerGenericField (const PointCloud &cloud, const std::string &field_name);
00709
00710 protected:
00712 virtual inline std::string getName () const { return ("PointCloudColorHandlerGenericField"); }
00713
00715 virtual std::string getFieldName () const { return (field_name_); }
00716
00720 virtual void getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
00721
00722 private:
00724 std::string field_name_;
00725 };
00726
00727 }
00728
00729 #include "libpcl_visualization/point_cloud_handlers.hpp"
00730
00731 #endif