Point Cloud Library (PCL)  1.7.2
point_cloud_color_handlers.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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  */
37 #ifndef PCL_POINT_CLOUD_COLOR_HANDLERS_H_
38 #define PCL_POINT_CLOUD_COLOR_HANDLERS_H_
39 
40 #if defined __GNUC__
41 #pragma GCC system_header
42 #endif
43 
44 // PCL includes
45 #include <pcl/point_cloud.h>
46 #include <pcl/common/io.h>
47 #include <pcl/visualization/common/common.h>
48 // VTK includes
49 #include <vtkSmartPointer.h>
50 #include <vtkDataArray.h>
51 #include <vtkFloatArray.h>
52 #include <vtkUnsignedCharArray.h>
53 
54 namespace pcl
55 {
56  namespace visualization
57  {
58  //////////////////////////////////////////////////////////////////////////////////////
59  /** \brief Base Handler class for PointCloud colors.
60  * \author Radu B. Rusu
61  * \ingroup visualization
62  */
63  template <typename PointT>
65  {
66  public:
68  typedef typename PointCloud::Ptr PointCloudPtr;
70 
71  typedef boost::shared_ptr<PointCloudColorHandler<PointT> > Ptr;
72  typedef boost::shared_ptr<const PointCloudColorHandler<PointT> > ConstPtr;
73 
74  /** \brief Constructor. */
76  cloud_ (), capable_ (false), field_idx_ (-1), fields_ ()
77  {}
78 
79  /** \brief Constructor. */
81  cloud_ (cloud), capable_ (false), field_idx_ (-1), fields_ ()
82  {}
83 
84  /** \brief Destructor. */
86 
87  /** \brief Check if this handler is capable of handling the input data or not. */
88  inline bool
89  isCapable () const { return (capable_); }
90 
91  /** \brief Abstract getName method. */
92  virtual std::string
93  getName () const = 0;
94 
95  /** \brief Abstract getFieldName method. */
96  virtual std::string
97  getFieldName () const = 0;
98 
99  /** \brief Obtain the actual color for the input dataset as vtk scalars.
100  * \param[out] scalars the output scalars containing the color for the dataset
101  * \return true if the operation was successful (the handler is capable and
102  * the input cloud was given as a valid pointer), false otherwise
103  */
104  virtual bool
105  getColor (vtkSmartPointer<vtkDataArray> &scalars) const = 0;
106 
107  /** \brief Set the input cloud to be used.
108  * \param[in] cloud the input cloud to be used by the handler
109  */
110  virtual void
112  {
113  cloud_ = cloud;
114  }
115 
116  protected:
117  /** \brief A pointer to the input dataset. */
119 
120  /** \brief True if this handler is capable of handling the input data, false
121  * otherwise.
122  */
123  bool capable_;
124 
125  /** \brief The index of the field holding the data that represents the color. */
127 
128  /** \brief The list of fields available for this PointCloud. */
129  std::vector<pcl::PCLPointField> fields_;
130  };
131 
132  //////////////////////////////////////////////////////////////////////////////////////
133  /** \brief Handler for random PointCloud colors (i.e., R, G, B will be randomly chosen)
134  * \author Radu B. Rusu
135  * \ingroup visualization
136  */
137  template <typename PointT>
139  {
141  typedef typename PointCloud::Ptr PointCloudPtr;
142  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
143 
144  public:
145  typedef boost::shared_ptr<PointCloudColorHandlerRandom<PointT> > Ptr;
146  typedef boost::shared_ptr<const PointCloudColorHandlerRandom<PointT> > ConstPtr;
147 
148  /** \brief Constructor. */
151  {
152  capable_ = true;
153  }
154 
155  /** \brief Constructor. */
158  {
159  capable_ = true;
160  }
161 
162  /** \brief Abstract getName method. */
163  virtual std::string
164  getName () const { return ("PointCloudColorHandlerRandom"); }
165 
166  /** \brief Get the name of the field used. */
167  virtual std::string
168  getFieldName () const { return ("[random]"); }
169 
170  /** \brief Obtain the actual color for the input dataset as vtk scalars.
171  * \param[out] scalars the output scalars containing the color for the dataset
172  * \return true if the operation was successful (the handler is capable and
173  * the input cloud was given as a valid pointer), false otherwise
174  */
175  virtual bool
176  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
177 
178  protected:
179  // Members derived from the base class
182  };
183 
184  //////////////////////////////////////////////////////////////////////////////////////
185  /** \brief Handler for predefined user colors. The color at each point will be drawn
186  * as the use given R, G, B values.
187  * \author Radu B. Rusu
188  * \ingroup visualization
189  */
190  template <typename PointT>
192  {
194  typedef typename PointCloud::Ptr PointCloudPtr;
195  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
196 
197  public:
198  typedef boost::shared_ptr<PointCloudColorHandlerCustom<PointT> > Ptr;
199  typedef boost::shared_ptr<const PointCloudColorHandlerCustom<PointT> > ConstPtr;
200 
201  /** \brief Constructor. */
202  PointCloudColorHandlerCustom (double r, double g, double b)
204  , r_ (r)
205  , g_ (g)
206  , b_ (b)
207  {
208  capable_ = true;
209  }
210 
211  /** \brief Constructor. */
213  double r, double g, double b)
214  : PointCloudColorHandler<PointT> (cloud)
215  , r_ (r)
216  , g_ (g)
217  , b_ (b)
218  {
219  capable_ = true;
220  }
221 
222  /** \brief Destructor. */
224 
225  /** \brief Abstract getName method. */
226  virtual std::string
227  getName () const { return ("PointCloudColorHandlerCustom"); }
228 
229  /** \brief Get the name of the field used. */
230  virtual std::string
231  getFieldName () const { return (""); }
232 
233  /** \brief Obtain the actual color for the input dataset as vtk scalars.
234  * \param[out] scalars the output scalars containing the color for the dataset
235  * \return true if the operation was successful (the handler is capable and
236  * the input cloud was given as a valid pointer), false otherwise
237  */
238  virtual bool
239  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
240 
241  protected:
242  // Members derived from the base class
245 
246  /** \brief Internal R, G, B holding the values given by the user. */
247  double r_, g_, b_;
248  };
249 
250  //////////////////////////////////////////////////////////////////////////////////////
251  /** \brief RGB handler class for colors. Uses the data present in the "rgb" or "rgba"
252  * fields as the color at each point.
253  * \author Radu B. Rusu
254  * \ingroup visualization
255  */
256  template <typename PointT>
258  {
260  typedef typename PointCloud::Ptr PointCloudPtr;
261  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
262 
263  public:
264  typedef boost::shared_ptr<PointCloudColorHandlerRGBField<PointT> > Ptr;
265  typedef boost::shared_ptr<const PointCloudColorHandlerRGBField<PointT> > ConstPtr;
266 
267  /** \brief Constructor. */
269  {
270  capable_ = false;
271  }
272 
273  /** \brief Constructor. */
275  : PointCloudColorHandler<PointT> (cloud)
276  {
277  setInputCloud (cloud);
278  }
279 
280  /** \brief Destructor. */
282 
283  /** \brief Get the name of the field used. */
284  virtual std::string
285  getFieldName () const { return ("rgb"); }
286 
287  /** \brief Obtain the actual color for the input dataset as vtk scalars.
288  * \param[out] scalars the output scalars containing the color for the dataset
289  * \return true if the operation was successful (the handler is capable and
290  * the input cloud was given as a valid pointer), false otherwise
291  */
292  virtual bool
293  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
294 
295  /** \brief Set the input cloud to be used.
296  * \param[in] cloud the input cloud to be used by the handler
297  */
298  virtual void
299  setInputCloud (const PointCloudConstPtr &cloud);
300 
301  protected:
302  /** \brief Class getName method. */
303  virtual std::string
304  getName () const { return ("PointCloudColorHandlerRGBField"); }
305 
306  private:
307  // Members derived from the base class
312  };
313 
314  //////////////////////////////////////////////////////////////////////////////////////
315  /** \brief HSV handler class for colors. Uses the data present in the "h", "s", "v"
316  * fields as the color at each point.
317  * \ingroup visualization
318  */
319  template <typename PointT>
321  {
323  typedef typename PointCloud::Ptr PointCloudPtr;
324  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
325 
326  public:
327  typedef boost::shared_ptr<PointCloudColorHandlerHSVField<PointT> > Ptr;
328  typedef boost::shared_ptr<const PointCloudColorHandlerHSVField<PointT> > ConstPtr;
329 
330  /** \brief Constructor. */
332 
333  /** \brief Empty destructor */
335 
336  /** \brief Get the name of the field used. */
337  virtual std::string
338  getFieldName () const { return ("hsv"); }
339 
340  /** \brief Obtain the actual color for the input dataset as vtk scalars.
341  * \param[out] scalars the output scalars containing the color for the dataset
342  * \return true if the operation was successful (the handler is capable and
343  * the input cloud was given as a valid pointer), false otherwise
344  */
345  virtual bool
346  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
347 
348  protected:
349  /** \brief Class getName method. */
350  virtual std::string
351  getName () const { return ("PointCloudColorHandlerHSVField"); }
352 
353  /** \brief The field index for "S". */
355 
356  /** \brief The field index for "V". */
358  private:
359  // Members derived from the base class
364  };
365 
366  //////////////////////////////////////////////////////////////////////////////////////
367  /** \brief Generic field handler class for colors. Uses an user given field to extract
368  * 1D data and display the color at each point using a min-max lookup table.
369  * \author Radu B. Rusu
370  * \ingroup visualization
371  */
372  template <typename PointT>
374  {
376  typedef typename PointCloud::Ptr PointCloudPtr;
377  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
378 
379  public:
380  typedef boost::shared_ptr<PointCloudColorHandlerGenericField<PointT> > Ptr;
381  typedef boost::shared_ptr<const PointCloudColorHandlerGenericField<PointT> > ConstPtr;
382 
383  /** \brief Constructor. */
384  PointCloudColorHandlerGenericField (const std::string &field_name)
385  : field_name_ (field_name)
386  {
387  capable_ = false;
388  }
389 
390  /** \brief Constructor. */
392  const std::string &field_name)
393  : PointCloudColorHandler<PointT> (cloud)
394  , field_name_ (field_name)
395  {
396  setInputCloud (cloud);
397  }
398 
399  /** \brief Destructor. */
401 
402  /** \brief Get the name of the field used. */
403  virtual std::string getFieldName () const { return (field_name_); }
404 
405  /** \brief Obtain the actual color for the input dataset as vtk scalars.
406  * \param[out] scalars the output scalars containing the color for the dataset
407  * \return true if the operation was successful (the handler is capable and
408  * the input cloud was given as a valid pointer), false otherwise
409  */
410  virtual bool
411  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
412 
413  /** \brief Set the input cloud to be used.
414  * \param[in] cloud the input cloud to be used by the handler
415  */
416  virtual void
417  setInputCloud (const PointCloudConstPtr &cloud);
418 
419  protected:
420  /** \brief Class getName method. */
421  virtual std::string
422  getName () const { return ("PointCloudColorHandlerGenericField"); }
423 
424  private:
429 
430  /** \brief Name of the field used to create the color handler. */
431  std::string field_name_;
432  };
433 
434 
435  //////////////////////////////////////////////////////////////////////////////////////
436  /** \brief RGBA handler class for colors. Uses the data present in the "rgba" field as
437  * the color at each point. Transparency is handled.
438  * \author Nizar Sallem
439  * \ingroup visualization
440  */
441  template <typename PointT>
443  {
445  typedef typename PointCloud::Ptr PointCloudPtr;
446  typedef typename PointCloud::ConstPtr PointCloudConstPtr;
447 
448  public:
449  typedef boost::shared_ptr<PointCloudColorHandlerRGBAField<PointT> > Ptr;
450  typedef boost::shared_ptr<const PointCloudColorHandlerRGBAField<PointT> > ConstPtr;
451 
452  /** \brief Constructor. */
454  {
455  capable_ = false;
456  }
457 
458  /** \brief Constructor. */
460  : PointCloudColorHandler<PointT> (cloud)
461  {
462  setInputCloud (cloud);
463  }
464 
465  /** \brief Destructor. */
467 
468  /** \brief Get the name of the field used. */
469  virtual std::string
470  getFieldName () const { return ("rgba"); }
471 
472  /** \brief Obtain the actual color for the input dataset as vtk scalars.
473  * \param[out] scalars the output scalars containing the color for the dataset
474  * \return true if the operation was successful (the handler is capable and
475  * the input cloud was given as a valid pointer), false otherwise
476  */
477  virtual bool
478  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
479 
480  /** \brief Set the input cloud to be used.
481  * \param[in] cloud the input cloud to be used by the handler
482  */
483  virtual void
484  setInputCloud (const PointCloudConstPtr &cloud);
485 
486  protected:
487  /** \brief Class getName method. */
488  virtual std::string
489  getName () const { return ("PointCloudColorHandlerRGBAField"); }
490 
491  // Members derived from the base class
496  };
497 
498  //////////////////////////////////////////////////////////////////////////////////////
499  /** \brief Base Handler class for PointCloud colors.
500  * \author Radu B. Rusu
501  * \ingroup visualization
502  */
503  template <>
504  class PCL_EXPORTS PointCloudColorHandler<pcl::PCLPointCloud2>
505  {
506  public:
510 
511  typedef boost::shared_ptr<PointCloudColorHandler<PointCloud> > Ptr;
512  typedef boost::shared_ptr<const PointCloudColorHandler<PointCloud> > ConstPtr;
513 
514  /** \brief Constructor. */
516  cloud_ (cloud), capable_ (false), field_idx_ ()
517  {}
518 
519  /** \brief Destructor. */
521 
522  /** \brief Return whether this handler is capable of handling the input data or not. */
523  inline bool
524  isCapable () const { return (capable_); }
525 
526  /** \brief Abstract getName method. */
527  virtual std::string
528  getName () const = 0;
529 
530  /** \brief Abstract getFieldName method. */
531  virtual std::string
532  getFieldName () const = 0;
533 
534  /** \brief Obtain the actual color for the input dataset as vtk scalars.
535  * \param[out] scalars the output scalars containing the color for the dataset
536  * \return true if the operation was successful (the handler is capable and
537  * the input cloud was given as a valid pointer), false otherwise
538  */
539  virtual bool
540  getColor (vtkSmartPointer<vtkDataArray> &scalars) const = 0;
541 
542  /** \brief Set the input cloud to be used.
543  * \param[in] cloud the input cloud to be used by the handler
544  */
545  void
547  {
548  cloud_ = cloud;
549  }
550 
551  protected:
552  /** \brief A pointer to the input dataset. */
554 
555  /** \brief True if this handler is capable of handling the input data, false
556  * otherwise.
557  */
558  bool capable_;
559 
560  /** \brief The index of the field holding the data that represents the color. */
562  };
563 
564  //////////////////////////////////////////////////////////////////////////////////////
565  /** \brief Handler for random PointCloud colors (i.e., R, G, B will be randomly chosen)
566  * \author Radu B. Rusu
567  * \ingroup visualization
568  */
569  template <>
570  class PCL_EXPORTS PointCloudColorHandlerRandom<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
571  {
575 
576  public:
577  typedef boost::shared_ptr<PointCloudColorHandlerRandom<PointCloud> > Ptr;
578  typedef boost::shared_ptr<const PointCloudColorHandlerRandom<PointCloud> > ConstPtr;
579 
580  /** \brief Constructor. */
583  {
584  capable_ = true;
585  }
586 
587  /** \brief Empty destructor */
589 
590  /** \brief Get the name of the class. */
591  virtual std::string
592  getName () const { return ("PointCloudColorHandlerRandom"); }
593 
594  /** \brief Get the name of the field used. */
595  virtual std::string
596  getFieldName () const { return ("[random]"); }
597 
598  /** \brief Obtain the actual color for the input dataset as vtk scalars.
599  * \param[out] scalars the output scalars containing the color for the dataset
600  * \return true if the operation was successful (the handler is capable and
601  * the input cloud was given as a valid pointer), false otherwise
602  */
603  virtual bool
604  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
605  };
606 
607  //////////////////////////////////////////////////////////////////////////////////////
608  /** \brief Handler for predefined user colors. The color at each point will be drawn
609  * as the use given R, G, B values.
610  * \author Radu B. Rusu
611  * \ingroup visualization
612  */
613  template <>
614  class PCL_EXPORTS PointCloudColorHandlerCustom<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
615  {
619 
620  public:
621  /** \brief Constructor. */
623  double r, double g, double b) :
625  r_ (r), g_ (g), b_ (b)
626  {
627  capable_ = true;
628  }
629 
630  /** \brief Empty destructor */
632 
633  /** \brief Get the name of the class. */
634  virtual std::string
635  getName () const { return ("PointCloudColorHandlerCustom"); }
636 
637  /** \brief Get the name of the field used. */
638  virtual std::string
639  getFieldName () const { return (""); }
640 
641  /** \brief Obtain the actual color for the input dataset as vtk scalars.
642  * \param[out] scalars the output scalars containing the color for the dataset
643  * \return true if the operation was successful (the handler is capable and
644  * the input cloud was given as a valid pointer), false otherwise
645  */
646  virtual bool
647  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
648 
649  protected:
650  /** \brief Internal R, G, B holding the values given by the user. */
651  double r_, g_, b_;
652  };
653 
654  //////////////////////////////////////////////////////////////////////////////////////
655  /** \brief RGB handler class for colors. Uses the data present in the "rgb" or "rgba"
656  * fields as the color at each point.
657  * \author Radu B. Rusu
658  * \ingroup visualization
659  */
660  template <>
661  class PCL_EXPORTS PointCloudColorHandlerRGBField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
662  {
666 
667  public:
668  typedef boost::shared_ptr<PointCloudColorHandlerRGBField<PointCloud> > Ptr;
669  typedef boost::shared_ptr<const PointCloudColorHandlerRGBField<PointCloud> > ConstPtr;
670 
671  /** \brief Constructor. */
673 
674  /** \brief Empty destructor */
676 
677  /** \brief Obtain the actual color for the input dataset as vtk scalars.
678  * \param[out] scalars the output scalars containing the color for the dataset
679  * \return true if the operation was successful (the handler is capable and
680  * the input cloud was given as a valid pointer), false otherwise
681  */
682  virtual bool
683  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
684 
685  protected:
686  /** \brief Get the name of the class. */
687  virtual std::string
688  getName () const { return ("PointCloudColorHandlerRGBField"); }
689 
690  /** \brief Get the name of the field used. */
691  virtual std::string
692  getFieldName () const { return ("rgb"); }
693  };
694 
695  //////////////////////////////////////////////////////////////////////////////////////
696  /** \brief HSV handler class for colors. Uses the data present in the "h", "s", "v"
697  * fields as the color at each point.
698  * \ingroup visualization
699  */
700  template <>
701  class PCL_EXPORTS PointCloudColorHandlerHSVField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
702  {
706 
707  public:
708  typedef boost::shared_ptr<PointCloudColorHandlerHSVField<PointCloud> > Ptr;
709  typedef boost::shared_ptr<const PointCloudColorHandlerHSVField<PointCloud> > ConstPtr;
710 
711  /** \brief Constructor. */
713 
714  /** \brief Empty destructor */
716 
717  /** \brief Obtain the actual color for the input dataset as vtk scalars.
718  * \param[out] scalars the output scalars containing the color for the dataset
719  * \return true if the operation was successful (the handler is capable and
720  * the input cloud was given as a valid pointer), false otherwise
721  */
722  virtual bool
723  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
724 
725  protected:
726  /** \brief Get the name of the class. */
727  virtual std::string
728  getName () const { return ("PointCloudColorHandlerHSVField"); }
729 
730  /** \brief Get the name of the field used. */
731  virtual std::string
732  getFieldName () const { return ("hsv"); }
733 
734  /** \brief The field index for "S". */
736 
737  /** \brief The field index for "V". */
739  };
740 
741  //////////////////////////////////////////////////////////////////////////////////////
742  /** \brief Generic field handler class for colors. Uses an user given field to extract
743  * 1D data and display the color at each point using a min-max lookup table.
744  * \author Radu B. Rusu
745  * \ingroup visualization
746  */
747  template <>
748  class PCL_EXPORTS PointCloudColorHandlerGenericField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
749  {
753 
754  public:
755  typedef boost::shared_ptr<PointCloudColorHandlerGenericField<PointCloud> > Ptr;
756  typedef boost::shared_ptr<const PointCloudColorHandlerGenericField<PointCloud> > ConstPtr;
757 
758  /** \brief Constructor. */
760  const std::string &field_name);
761 
762  /** \brief Empty destructor */
764 
765  /** \brief Obtain the actual color for the input dataset as vtk scalars.
766  * \param[out] scalars the output scalars containing the color for the dataset
767  * \return true if the operation was successful (the handler is capable and
768  * the input cloud was given as a valid pointer), false otherwise
769  */
770  virtual bool
771  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
772 
773  protected:
774  /** \brief Get the name of the class. */
775  virtual std::string
776  getName () const { return ("PointCloudColorHandlerGenericField"); }
777 
778  /** \brief Get the name of the field used. */
779  virtual std::string
780  getFieldName () const { return (field_name_); }
781 
782  private:
783  /** \brief Name of the field used to create the color handler. */
784  std::string field_name_;
785  };
786 
787  //////////////////////////////////////////////////////////////////////////////////////
788  /** \brief RGBA handler class for colors. Uses the data present in the "rgba" field as
789  * the color at each point. Transparency is handled.
790  * \author Nizar Sallem
791  * \ingroup visualization
792  */
793  template <>
794  class PCL_EXPORTS PointCloudColorHandlerRGBAField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
795  {
799 
800  public:
801  typedef boost::shared_ptr<PointCloudColorHandlerRGBAField<PointCloud> > Ptr;
802  typedef boost::shared_ptr<const PointCloudColorHandlerRGBAField<PointCloud> > ConstPtr;
803 
804  /** \brief Constructor. */
806 
807  /** \brief Empty destructor */
809 
810  /** \brief Obtain the actual color for the input dataset as vtk scalars.
811  * \param[out] scalars the output scalars containing the color for the dataset
812  * \return true if the operation was successful (the handler is capable and
813  * the input cloud was given as a valid pointer), false otherwise
814  */
815  virtual bool
816  getColor (vtkSmartPointer<vtkDataArray> &scalars) const;
817 
818  protected:
819  /** \brief Get the name of the class. */
820  virtual std::string
821  getName () const { return ("PointCloudColorHandlerRGBAField"); }
822 
823  /** \brief Get the name of the field used. */
824  virtual std::string
825  getFieldName () const { return ("rgba"); }
826  };
827  }
828 }
829 
830 #include <pcl/visualization/impl/point_cloud_color_handlers.hpp>
831 
832 #endif // PCL_POINT_CLOUD_COLOR_HANDLERS_H_
833 
bool isCapable() const
Check if this handler is capable of handling the input data or not.
virtual std::string getName() const
Class getName method.
virtual std::string getName() const
Get the name of the class.
boost::shared_ptr< const PointCloudColorHandlerRGBField< PointT > > ConstPtr
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
boost::shared_ptr< const PointCloudColorHandlerHSVField< PointCloud > > ConstPtr
Handler for random PointCloud colors (i.e., R, G, B will be randomly chosen)
boost::shared_ptr< const PointCloudColorHandlerGenericField< PointCloud > > ConstPtr
virtual std::string getFieldName() const
Get the name of the field used.
boost::shared_ptr< const PointCloudColorHandlerRandom< PointCloud > > ConstPtr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
boost::shared_ptr< PointCloudColorHandlerGenericField< PointCloud > > Ptr
boost::shared_ptr< PointCloudColorHandlerGenericField< PointT > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
PointCloudColorHandlerCustom(const PointCloudConstPtr &cloud, double r, double g, double b)
Constructor.
boost::shared_ptr< const PointCloudColorHandler< PointCloud > > ConstPtr
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual std::string getFieldName() const
Get the name of the field used.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
boost::shared_ptr< PointCloudColorHandlerHSVField< PointCloud > > Ptr
PointCloudColorHandlerHSVField(const PointCloudConstPtr &cloud)
Constructor.
PointCloudColorHandlerRGBField(const PointCloudConstPtr &cloud)
Constructor.
virtual std::string getFieldName() const
Get the name of the field used.
PointCloudColorHandler(const PointCloudConstPtr &cloud)
Constructor.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
virtual std::string getName() const
Abstract getName method.
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Base Handler class for PointCloud colors.
boost::shared_ptr< const PointCloudColorHandlerRGBAField< PointT > > ConstPtr
boost::shared_ptr< const PointCloudColorHandlerRGBAField< PointCloud > > ConstPtr
virtual std::string getFieldName() const
Get the name of the field used.
virtual std::string getName() const
Get the name of the class.
void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
PointCloudColorHandlerCustom(double r, double g, double b)
Constructor.
std::vector< pcl::PCLPointField > fields_
The list of fields available for this PointCloud.
virtual std::string getFieldName() const
Get the name of the field used.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
PointCloudColorHandlerGenericField(const std::string &field_name)
Constructor.
boost::shared_ptr< PointCloudColorHandlerRandom< PointCloud > > Ptr
boost::shared_ptr< PointCloudColorHandlerRGBAField< PointT > > Ptr
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
boost::shared_ptr< PointCloudColorHandlerHSVField< PointT > > Ptr
virtual std::string getName() const
Class getName method.
double r_
Internal R, G, B holding the values given by the user.
virtual std::string getFieldName() const
Get the name of the field used.
virtual std::string getFieldName() const
Get the name of the field used.
boost::shared_ptr< const PointCloudColorHandlerRGBField< PointCloud > > ConstPtr
PointCloudColorHandlerRandom(const PointCloudConstPtr &cloud)
Constructor.
boost::shared_ptr< const PointCloudColorHandlerRandom< PointT > > ConstPtr
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
boost::shared_ptr< PointCloudColorHandlerRandom< PointT > > Ptr
virtual std::string getName() const
Abstract getName method.
boost::shared_ptr< PointCloudColorHandler< PointCloud > > Ptr
boost::shared_ptr< const PointCloudColorHandlerCustom< PointT > > ConstPtr
PointCloudColorHandlerRGBAField(const PointCloudConstPtr &cloud)
Constructor.
int field_idx_
The index of the field holding the data that represents the color.
boost::shared_ptr< PointCloudColorHandler< PointT > > Ptr
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
PointCloudConstPtr cloud_
A pointer to the input dataset.
boost::shared_ptr< const PointCloudColorHandler< PointT > > ConstPtr
virtual std::string getFieldName() const =0
Abstract getFieldName method.
boost::shared_ptr< const PointCloudColorHandlerGenericField< PointT > > ConstPtr
boost::shared_ptr< PointCloudColorHandlerCustom< PointT > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
boost::shared_ptr< PointCloudColorHandlerRGBField< PointT > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
bool isCapable() const
Return whether this handler is capable of handling the input data or not.
PointCloudColorHandlerGenericField(const PointCloudConstPtr &cloud, const std::string &field_name)
Constructor.
virtual std::string getName() const
Class getName method.
int field_idx_
The index of the field holding the data that represents the color.
A point structure representing Euclidean xyz coordinates, and the RGB color.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
boost::shared_ptr< const PointCloudColorHandlerHSVField< PointT > > ConstPtr
virtual std::string getName() const =0
Abstract getName method.
bool capable_
True if this handler is capable of handling the input data, false otherwise.
virtual std::string getFieldName() const
Get the name of the field used.
virtual std::string getFieldName() const
Get the name of the field used.
boost::shared_ptr< PointCloudColorHandlerRGBField< PointCloud > > Ptr
boost::shared_ptr< PointCloudColorHandlerRGBAField< PointCloud > > Ptr
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const =0
Obtain the actual color for the input dataset as vtk scalars.
bool capable_
True if this handler is capable of handling the input data, false otherwise.
virtual std::string getName() const
Class getName method.
double r_
Internal R, G, B holding the values given by the user.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
PointCloudColorHandlerCustom(const PointCloudConstPtr &cloud, double r, double g, double b)
Constructor.