Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
point_cloud_handlers.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: point_cloud_handlers.h 5162 2012-03-17 22:30:39Z rusu $
37  *
38  */
39 #ifndef PCL_POINT_CLOUD_HANDLERS_H_
40 #define PCL_POINT_CLOUD_HANDLERS_H_
41 
43 // PCL includes
44 #include <pcl/point_types.h>
45 #include <pcl/point_cloud.h>
46 #include <pcl/common/io.h>
47 // VTK includes
48 #include <pcl/visualization/vtk.h>
49 
50 namespace pcl
51 {
52  namespace visualization
53  {
57  template <typename PointT>
59  {
60  public:
62  typedef typename PointCloud::Ptr PointCloudPtr;
64 
65  typedef typename boost::shared_ptr<PointCloudGeometryHandler<PointT> > Ptr;
66  typedef typename boost::shared_ptr<const PointCloudGeometryHandler<PointT> > ConstPtr;
67 
70  cloud_ (cloud), capable_ (false),
71  field_x_idx_ (-1), field_y_idx_ (-1), field_z_idx_ (-1),
72  fields_ ()
73  {}
74 
77 
81  virtual std::string
82  getName () const = 0;
83 
85  virtual std::string
86  getFieldName () const = 0;
87 
89  inline bool
90  isCapable () const { return (capable_); }
91 
95  virtual void
96  getGeometry (vtkSmartPointer<vtkPoints> &points) const = 0;
97 
98  protected:
100  PointCloudConstPtr cloud_;
101 
105  bool capable_;
106 
108  int field_x_idx_;
109 
111  int field_y_idx_;
112 
114  int field_z_idx_;
115 
117  std::vector<sensor_msgs::PointField> fields_;
118  };
119 
121 
125  template <typename PointT>
127  {
128  public:
130  typedef typename PointCloud::Ptr PointCloudPtr;
132 
133  typedef typename boost::shared_ptr<PointCloudGeometryHandlerXYZ<PointT> > Ptr;
134  typedef typename boost::shared_ptr<const PointCloudGeometryHandlerXYZ<PointT> > ConstPtr;
135 
138 
141 
143  virtual inline std::string
144  getName () const { return ("PointCloudGeometryHandlerXYZ"); }
145 
147  virtual std::string
148  getFieldName () const { return ("xyz"); }
149 
153  virtual void
154  getGeometry (vtkSmartPointer<vtkPoints> &points) const;
155 
156  private:
157  // Members derived from the base class
164  };
165 
167 
172  template <typename PointT>
174  {
175  public:
177  typedef typename PointCloud::Ptr PointCloudPtr;
179 
180  typedef typename boost::shared_ptr<PointCloudGeometryHandlerSurfaceNormal<PointT> > Ptr;
181  typedef typename boost::shared_ptr<const PointCloudGeometryHandlerSurfaceNormal<PointT> > ConstPtr;
182 
185 
187  virtual inline std::string
188  getName () const { return ("PointCloudGeometryHandlerSurfaceNormal"); }
189 
191  virtual std::string
192  getFieldName () const { return ("normal_xyz"); }
193 
197  virtual void
198  getGeometry (vtkSmartPointer<vtkPoints> &points) const;
199 
200  private:
201  // Members derived from the base class
208  };
209 
211 
216  template <typename PointT>
218  {
219  public:
221  typedef typename PointCloud::Ptr PointCloudPtr;
223 
224  typedef typename boost::shared_ptr<PointCloudGeometryHandlerCustom<PointT> > Ptr;
225  typedef typename boost::shared_ptr<const PointCloudGeometryHandlerCustom<PointT> > ConstPtr;
226 
229  const std::string &x_field_name,
230  const std::string &y_field_name,
231  const std::string &z_field_name);
232 
234  virtual inline std::string
235  getName () const { return ("PointCloudGeometryHandlerCustom"); }
236 
238  virtual std::string
239  getFieldName () const { return (field_name_); }
240 
244  virtual void
245  getGeometry (vtkSmartPointer<vtkPoints> &points) const;
246 
247  private:
248  // Members derived from the base class
255 
257  std::string field_name_;
258  };
259 
261 
264  template <>
265  class PCL_EXPORTS PointCloudGeometryHandler<sensor_msgs::PointCloud2>
266  {
267  public:
271 
272  typedef boost::shared_ptr<PointCloudGeometryHandler<PointCloud> > Ptr;
273  typedef boost::shared_ptr<const PointCloudGeometryHandler<PointCloud> > ConstPtr;
274 
276  PointCloudGeometryHandler (const PointCloudConstPtr &cloud, const Eigen::Vector4f &sensor_origin = Eigen::Vector4f::Zero ())
277  : cloud_ (cloud)
278  , capable_ (false)
279  {
280  fields_ = cloud_->fields;
281  }
282 
284  virtual std::string
285  getName () const = 0;
286 
288  virtual std::string
289  getFieldName () const = 0;
290 
292  inline bool
293  isCapable () const { return (capable_); }
294 
298  virtual void
299  getGeometry (vtkSmartPointer<vtkPoints> &points) const;
300 
301  protected:
303  PointCloudConstPtr cloud_;
304 
308  bool capable_;
309 
311  int field_x_idx_;
312 
314  int field_y_idx_;
315 
317  int field_z_idx_;
318 
320  std::vector<sensor_msgs::PointField> fields_;
321  };
322 
324 
328  template <>
329  class PCL_EXPORTS PointCloudGeometryHandlerXYZ<sensor_msgs::PointCloud2> : public PointCloudGeometryHandler<sensor_msgs::PointCloud2>
330  {
331  public:
335 
336  typedef boost::shared_ptr<PointCloudGeometryHandlerXYZ<PointCloud> > Ptr;
337  typedef boost::shared_ptr<const PointCloudGeometryHandlerXYZ<PointCloud> > ConstPtr;
338 
341 
344 
346  virtual inline
347  std::string getName () const { return ("PointCloudGeometryHandlerXYZ"); }
348 
350  virtual std::string
351  getFieldName () const { return ("xyz"); }
352  };
353 
355 
360  template <>
361  class PCL_EXPORTS PointCloudGeometryHandlerSurfaceNormal<sensor_msgs::PointCloud2> : public PointCloudGeometryHandler<sensor_msgs::PointCloud2>
362  {
363  public:
367 
368  typedef boost::shared_ptr<PointCloudGeometryHandlerSurfaceNormal<PointCloud> > Ptr;
369  typedef boost::shared_ptr<const PointCloudGeometryHandlerSurfaceNormal<PointCloud> > ConstPtr;
370 
373 
375  virtual inline std::string
376  getName () const { return ("PointCloudGeometryHandlerSurfaceNormal"); }
377 
379  virtual std::string
380  getFieldName () const { return ("normal_xyz"); }
381  };
382 
384 
389  template <>
390  class PCL_EXPORTS PointCloudGeometryHandlerCustom<sensor_msgs::PointCloud2> : public PointCloudGeometryHandler<sensor_msgs::PointCloud2>
391  {
392  public:
396 
399  const std::string &x_field_name,
400  const std::string &y_field_name,
401  const std::string &z_field_name);
402 
405 
407  virtual inline std::string
408  getName () const { return ("PointCloudGeometryHandlerCustom"); }
409 
411  virtual std::string
412  getFieldName () const { return (field_name_); }
413 
414  private:
416  std::string field_name_;
417  };
418 
420 
423  template <typename PointT>
425  {
426  public:
428  typedef typename PointCloud::Ptr PointCloudPtr;
430 
431  typedef boost::shared_ptr<PointCloudColorHandler<PointT> > Ptr;
432  typedef boost::shared_ptr<const PointCloudColorHandler<PointT> > ConstPtr;
433 
436  cloud_ (cloud), capable_ (false), field_idx_ (-1), fields_ ()
437  {}
438 
441 
443  inline bool
444  isCapable () const { return (capable_); }
445 
447  virtual std::string
448  getName () const = 0;
449 
451  virtual std::string
452  getFieldName () const = 0;
453 
457  virtual void
458  getColor (vtkSmartPointer<vtkDataArray> &scalars) const = 0;
459 
460  protected:
462  PointCloudConstPtr cloud_;
463 
467  bool capable_;
468 
470  int field_idx_;
471 
473  std::vector<sensor_msgs::PointField> fields_;
474  };
475 
477 
480  template <typename PointT>
482  {
484  typedef typename PointCloud::Ptr PointCloudPtr;
485  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
486 
487  public:
488  typedef boost::shared_ptr<PointCloudColorHandlerRandom<PointT> > Ptr;
489  typedef boost::shared_ptr<const PointCloudColorHandlerRandom<PointT> > ConstPtr;
490 
494  {
495  capable_ = true;
496  }
497 
499  virtual inline std::string
500  getName () const { return ("PointCloudColorHandlerRandom"); }
501 
503  virtual std::string
504  getFieldName () const { return ("[random]"); }
505 
509  virtual void
510  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
511 
512  protected:
513  // Members derived from the base class
516  };
517 
519 
523  template <typename PointT>
525  {
527  typedef typename PointCloud::Ptr PointCloudPtr;
528  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
529 
530  public:
531  typedef boost::shared_ptr<PointCloudColorHandlerCustom<PointT> > Ptr;
532  typedef boost::shared_ptr<const PointCloudColorHandlerCustom<PointT> > ConstPtr;
533 
536  double r, double g, double b)
537  : PointCloudColorHandler<PointT> (cloud)
538  , r_ (r)
539  , g_ (g)
540  , b_ (b)
541  {
542  capable_ = true;
543  }
544 
547 
549  virtual inline std::string
550  getName () const { return ("PointCloudColorHandlerCustom"); }
551 
553  virtual std::string
554  getFieldName () const { return (""); }
555 
559  virtual void
560  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
561 
562  protected:
563  // Members derived from the base class
566 
568  double r_, g_, b_;
569  };
570 
572 
576  template <typename PointT>
578  {
580  typedef typename PointCloud::Ptr PointCloudPtr;
581  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
582 
583  public:
584  typedef boost::shared_ptr<PointCloudColorHandlerRGBField<PointT> > Ptr;
585  typedef boost::shared_ptr<const PointCloudColorHandlerRGBField<PointT> > ConstPtr;
586 
589 
592 
594  virtual std::string
595  getFieldName () const { return ("rgb"); }
596 
600  virtual void
601  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
602 
603  protected:
605  virtual inline std::string
606  getName () const { return ("PointCloudColorHandlerRGBField"); }
607 
608  private:
609  // Members derived from the base class
610  using PointCloudColorHandler<PointT>::cloud_;
611  using PointCloudColorHandler<PointT>::capable_;
612  using PointCloudColorHandler<PointT>::field_idx_;
613  using PointCloudColorHandler<PointT>::fields_;
614  };
615 
617 
621  template <typename PointT>
623  {
625  typedef typename PointCloud::Ptr PointCloudPtr;
626  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
627 
628  public:
629  typedef boost::shared_ptr<PointCloudColorHandlerHSVField<PointT> > Ptr;
630  typedef boost::shared_ptr<const PointCloudColorHandlerHSVField<PointT> > ConstPtr;
631 
634 
636  virtual std::string
637  getFieldName () const { return ("hsv"); }
638 
642  virtual void
643  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
644 
645  protected:
647  virtual inline std::string
648  getName () const { return ("PointCloudColorHandlerHSVField"); }
649 
651  int s_field_idx_;
652 
654  int v_field_idx_;
655  private:
656  // Members derived from the base class
657  using PointCloudColorHandler<PointT>::cloud_;
658  using PointCloudColorHandler<PointT>::capable_;
659  using PointCloudColorHandler<PointT>::field_idx_;
660  using PointCloudColorHandler<PointT>::fields_;
661  };
662 
664 
668  template <typename PointT>
670  {
672  typedef typename PointCloud::Ptr PointCloudPtr;
673  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
674 
675  public:
676  typedef boost::shared_ptr<PointCloudColorHandlerGenericField<PointT> > Ptr;
677  typedef boost::shared_ptr<const PointCloudColorHandlerGenericField<PointT> > ConstPtr;
678 
681  const std::string &field_name);
682 
685 
687  virtual std::string getFieldName () const { return (field_name_); }
688 
692  virtual void
693  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
694 
695  protected:
697  virtual inline std::string
698  getName () const { return ("PointCloudColorHandlerGenericField"); }
699 
700  private:
701  using PointCloudColorHandler<PointT>::cloud_;
702  using PointCloudColorHandler<PointT>::capable_;
703  using PointCloudColorHandler<PointT>::field_idx_;
704  using PointCloudColorHandler<PointT>::fields_;
705 
707  std::string field_name_;
708  };
709 
711 
714  template <>
715  class PCL_EXPORTS PointCloudColorHandler<sensor_msgs::PointCloud2>
716  {
717  public:
721 
722  typedef boost::shared_ptr<PointCloudColorHandler<PointCloud> > Ptr;
723  typedef boost::shared_ptr<const PointCloudColorHandler<PointCloud> > ConstPtr;
724 
727  cloud_ (cloud), capable_ (false), field_idx_ ()
728  {}
729 
732 
734  inline bool
735  isCapable () const { return (capable_); }
736 
738  virtual std::string
739  getName () const = 0;
740 
742  virtual std::string
743  getFieldName () const = 0;
744 
748  virtual void
749  getColor (vtkSmartPointer<vtkDataArray> &scalars) const = 0;
750 
751  protected:
753  PointCloudConstPtr cloud_;
754 
758  bool capable_;
759 
761  int field_idx_;
762  };
763 
765 
768  template <>
769  class PCL_EXPORTS PointCloudColorHandlerRandom<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
770  {
774 
775  public:
776  typedef boost::shared_ptr<PointCloudColorHandlerRandom<PointCloud> > Ptr;
777  typedef boost::shared_ptr<const PointCloudColorHandlerRandom<PointCloud> > ConstPtr;
778 
781  PointCloudColorHandler<sensor_msgs::PointCloud2> (cloud)
782  {
783  capable_ = true;
784  }
785 
787  virtual inline std::string
788  getName () const { return ("PointCloudColorHandlerRandom"); }
789 
791  virtual std::string
792  getFieldName () const { return ("[random]"); }
793 
797  virtual void
798  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
799  };
800 
802 
806  template <>
807  class PCL_EXPORTS PointCloudColorHandlerCustom<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
808  {
812 
813  public:
816  double r, double g, double b) :
817  PointCloudColorHandler<sensor_msgs::PointCloud2> (cloud),
818  r_ (r), g_ (g), b_ (b)
819  {
820  capable_ = true;
821  }
822 
824  virtual inline std::string
825  getName () const { return ("PointCloudColorHandlerCustom"); }
826 
828  virtual std::string
829  getFieldName () const { return (""); }
830 
834  virtual void
835  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
836 
837  protected:
839  double r_, g_, b_;
840  };
841 
843 
847  template <>
848  class PCL_EXPORTS PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
849  {
853 
854  public:
855  typedef boost::shared_ptr<PointCloudColorHandlerRGBField<PointCloud> > Ptr;
856  typedef boost::shared_ptr<const PointCloudColorHandlerRGBField<PointCloud> > ConstPtr;
857 
860 
864  virtual void
865  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
866 
867  protected:
869  virtual inline std::string
870  getName () const { return ("PointCloudColorHandlerRGBField"); }
871 
873  virtual std::string
874  getFieldName () const { return ("rgb"); }
875  };
876 
878 
882  template <>
883  class PCL_EXPORTS PointCloudColorHandlerHSVField<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
884  {
888 
889  public:
890  typedef boost::shared_ptr<PointCloudColorHandlerHSVField<PointCloud> > Ptr;
891  typedef boost::shared_ptr<const PointCloudColorHandlerHSVField<PointCloud> > ConstPtr;
892 
895 
899  virtual void
900  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
901 
902  protected:
904  virtual inline std::string
905  getName () const { return ("PointCloudColorHandlerHSVField"); }
906 
908  virtual std::string
909  getFieldName () const { return ("hsv"); }
910 
912  int s_field_idx_;
913 
915  int v_field_idx_;
916  };
917 
919 
923  template <>
924  class PCL_EXPORTS PointCloudColorHandlerGenericField<sensor_msgs::PointCloud2> : public PointCloudColorHandler<sensor_msgs::PointCloud2>
925  {
929 
930  public:
931  typedef boost::shared_ptr<PointCloudColorHandlerGenericField<PointCloud> > Ptr;
932  typedef boost::shared_ptr<const PointCloudColorHandlerGenericField<PointCloud> > ConstPtr;
933 
936  const std::string &field_name);
937 
941  virtual void
942  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
943 
944  protected:
946  virtual inline std::string
947  getName () const { return ("PointCloudColorHandlerGenericField"); }
948 
950  virtual std::string
951  getFieldName () const { return (field_name_); }
952 
953  private:
955  std::string field_name_;
956  };
957 
958  }
959 }
960 
962 
963 #endif