Point Cloud Library (PCL) 1.12.1
Loading...
Searching...
No Matches
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
38#pragma once
39
40#if defined __GNUC__
41#pragma GCC system_header
42#endif
43
44// PCL includes
45#include <pcl/pcl_macros.h>
46#include <pcl/point_cloud.h>
47#include <pcl/PCLPointCloud2.h> // for PCLPointCloud2
48#include <pcl/visualization/common/common.h>
49// VTK includes
50#include <vtkSmartPointer.h>
51#include <vtkDataArray.h>
52#include <vtkFloatArray.h>
53#include <vtkUnsignedCharArray.h>
54
55namespace pcl
56{
57 namespace visualization
58 {
59 //////////////////////////////////////////////////////////////////////////////////////
60 /** \brief Base Handler class for PointCloud colors.
61 * \author Radu B. Rusu
62 * \ingroup visualization
63 */
64 template <typename PointT>
66 {
67 public:
71
72 using Ptr = shared_ptr<PointCloudColorHandler<PointT> >;
73 using ConstPtr = shared_ptr<const PointCloudColorHandler<PointT> >;
74
75 /** \brief Constructor. */
77 cloud_ (), capable_ (false), field_idx_ (-1), fields_ ()
78 {}
79
80 /** \brief Constructor. */
82 cloud_ (cloud), capable_ (false), field_idx_ (-1), fields_ ()
83 {}
84
85 /** \brief Destructor. */
87
88 /** \brief Check if this handler is capable of handling the input data or not. */
89 inline bool
90 isCapable () const { return (capable_); }
91
92 /** \brief Abstract getName method. */
93 virtual std::string
94 getName () const = 0;
95
96 /** \brief Abstract getFieldName method. */
97 virtual std::string
98 getFieldName () const = 0;
99
100 /** Obtain the actual color for the input dataset as a VTK data array.
101 * Deriving handlers should override this method.
102 * \return smart pointer to VTK array if the operation was successful (the
103 * handler is capable and the input cloud was given), a null pointer otherwise */
105 getColor () 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 */
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 {
140 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
141 using PointCloudPtr = typename PointCloud::Ptr;
142 using PointCloudConstPtr = typename PointCloud::ConstPtr;
143
144 public:
145 using Ptr = shared_ptr<PointCloudColorHandlerRandom<PointT> >;
146 using ConstPtr = shared_ptr<const PointCloudColorHandlerRandom<PointT> >;
147
148 /** \brief Constructor. */
150 PointCloudColorHandler<PointT> ()
151 {
152 capable_ = true;
153 }
154
155 /** \brief Constructor. */
156 PointCloudColorHandlerRandom (const PointCloudConstPtr &cloud) :
157 PointCloudColorHandler<PointT> (cloud)
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
171 getColor () const override;
172
173 protected:
174 // Members derived from the base class
175 using PointCloudColorHandler<PointT>::cloud_;
177 };
178
179 //////////////////////////////////////////////////////////////////////////////////////
180 /** \brief Handler for predefined user colors. The color at each point will be drawn
181 * as the use given R, G, B values.
182 * \author Radu B. Rusu
183 * \ingroup visualization
184 */
185 template <typename PointT>
187 {
188 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
189 using PointCloudPtr = typename PointCloud::Ptr;
190 using PointCloudConstPtr = typename PointCloud::ConstPtr;
191
192 public:
193 using Ptr = shared_ptr<PointCloudColorHandlerCustom<PointT> >;
194 using ConstPtr = shared_ptr<const PointCloudColorHandlerCustom<PointT> >;
195
196 /** \brief Constructor. */
197 PointCloudColorHandlerCustom (double r, double g, double b)
198 : PointCloudColorHandler<PointT> ()
199 , r_ (r)
200 , g_ (g)
201 , b_ (b)
202 {
203 capable_ = true;
204 }
205
206 /** \brief Constructor. */
207 PointCloudColorHandlerCustom (const PointCloudConstPtr &cloud,
208 double r, double g, double b)
209 : PointCloudColorHandler<PointT> (cloud)
210 , r_ (r)
211 , g_ (g)
212 , b_ (b)
213 {
214 capable_ = true;
215 }
216
217 /** \brief Destructor. */
219
220 /** \brief Abstract getName method. */
221 virtual std::string
222 getName () const { return ("PointCloudColorHandlerCustom"); }
223
224 /** \brief Get the name of the field used. */
225 virtual std::string
226 getFieldName () const { return (""); }
227
229 getColor () const override;
230
231 protected:
232 // Members derived from the base class
233 using PointCloudColorHandler<PointT>::cloud_;
235
236 /** \brief Internal R, G, B holding the values given by the user. */
237 double r_, g_, b_;
238 };
239
240 //////////////////////////////////////////////////////////////////////////////////////
241 /** \brief RGB handler class for colors. Uses the data present in the "rgb" or "rgba"
242 * fields as the color at each point.
243 * \author Radu B. Rusu
244 * \ingroup visualization
245 */
246 template <typename PointT>
248 {
249 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
250 using PointCloudPtr = typename PointCloud::Ptr;
251 using PointCloudConstPtr = typename PointCloud::ConstPtr;
252
253 public:
254 using Ptr = shared_ptr<PointCloudColorHandlerRGBField<PointT> >;
255 using ConstPtr = shared_ptr<const PointCloudColorHandlerRGBField<PointT> >;
256
257 /** \brief Constructor. */
259 {
260 capable_ = false;
261 }
262
263 /** \brief Constructor. */
264 PointCloudColorHandlerRGBField (const PointCloudConstPtr &cloud)
265 : PointCloudColorHandler<PointT> (cloud)
266 {
267 setInputCloud (cloud);
268 }
269
270 /** \brief Destructor. */
272
273 /** \brief Get the name of the field used. */
274 virtual std::string
275 getFieldName () const { return ("rgb"); }
276
278 getColor () const override;
279
280 /** \brief Set the input cloud to be used.
281 * \param[in] cloud the input cloud to be used by the handler
282 */
283 virtual void
284 setInputCloud (const PointCloudConstPtr &cloud);
285
286 protected:
287 /** \brief Class getName method. */
288 virtual std::string
289 getName () const { return ("PointCloudColorHandlerRGBField"); }
290
291 private:
292 // Members derived from the base class
293 using PointCloudColorHandler<PointT>::cloud_;
297 };
298
299 //////////////////////////////////////////////////////////////////////////////////////
300 /** \brief HSV handler class for colors. Uses the data present in the "h", "s", "v"
301 * fields as the color at each point.
302 * \ingroup visualization
303 */
304 template <typename PointT>
306 {
307 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
308 using PointCloudPtr = typename PointCloud::Ptr;
309 using PointCloudConstPtr = typename PointCloud::ConstPtr;
310
311 public:
312 using Ptr = shared_ptr<PointCloudColorHandlerHSVField<PointT> >;
313 using ConstPtr = shared_ptr<const PointCloudColorHandlerHSVField<PointT> >;
314
315 /** \brief Constructor. */
316 PointCloudColorHandlerHSVField (const PointCloudConstPtr &cloud);
317
318 /** \brief Empty destructor */
320
321 /** \brief Get the name of the field used. */
322 virtual std::string
323 getFieldName () const { return ("hsv"); }
324
326 getColor () const override;
327
328 protected:
329 /** \brief Class getName method. */
330 virtual std::string
331 getName () const { return ("PointCloudColorHandlerHSVField"); }
332
333 /** \brief The field index for "S". */
335
336 /** \brief The field index for "V". */
338 private:
339 // Members derived from the base class
340 using PointCloudColorHandler<PointT>::cloud_;
344 };
345
346 //////////////////////////////////////////////////////////////////////////////////////
347 /** \brief Generic field handler class for colors. Uses an user given field to extract
348 * 1D data and display the color at each point using a min-max lookup table.
349 * \author Radu B. Rusu
350 * \ingroup visualization
351 */
352 template <typename PointT>
354 {
355 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
356 using PointCloudPtr = typename PointCloud::Ptr;
357 using PointCloudConstPtr = typename PointCloud::ConstPtr;
358
359 public:
360 using Ptr = shared_ptr<PointCloudColorHandlerGenericField<PointT> >;
361 using ConstPtr = shared_ptr<const PointCloudColorHandlerGenericField<PointT> >;
362
363 /** \brief Constructor. */
364 PointCloudColorHandlerGenericField (const std::string &field_name)
365 : field_name_ (field_name)
366 {
367 capable_ = false;
368 }
369
370 /** \brief Constructor. */
371 PointCloudColorHandlerGenericField (const PointCloudConstPtr &cloud,
372 const std::string &field_name)
373 : PointCloudColorHandler<PointT> (cloud)
374 , field_name_ (field_name)
375 {
376 setInputCloud (cloud);
377 }
378
379 /** \brief Destructor. */
381
382 /** \brief Get the name of the field used. */
383 virtual std::string getFieldName () const { return (field_name_); }
384
386 getColor () const override;
387
388 /** \brief Set the input cloud to be used.
389 * \param[in] cloud the input cloud to be used by the handler
390 */
391 virtual void
392 setInputCloud (const PointCloudConstPtr &cloud);
393
394 protected:
395 /** \brief Class getName method. */
396 virtual std::string
397 getName () const { return ("PointCloudColorHandlerGenericField"); }
398
399 private:
400 using PointCloudColorHandler<PointT>::cloud_;
404
405 /** \brief Name of the field used to create the color handler. */
406 std::string field_name_;
407 };
408
409
410 //////////////////////////////////////////////////////////////////////////////////////
411 /** \brief RGBA handler class for colors. Uses the data present in the "rgba" field as
412 * the color at each point. Transparency is handled.
413 * \author Nizar Sallem
414 * \ingroup visualization
415 */
416 template <typename PointT>
418 {
419 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
420 using PointCloudPtr = typename PointCloud::Ptr;
421 using PointCloudConstPtr = typename PointCloud::ConstPtr;
422
423 public:
424 using Ptr = shared_ptr<PointCloudColorHandlerRGBAField<PointT> >;
425 using ConstPtr = shared_ptr<const PointCloudColorHandlerRGBAField<PointT> >;
426
427 /** \brief Constructor. */
429 {
430 capable_ = false;
431 }
432
433 /** \brief Constructor. */
434 PointCloudColorHandlerRGBAField (const PointCloudConstPtr &cloud)
435 : PointCloudColorHandler<PointT> (cloud)
436 {
437 setInputCloud (cloud);
438 }
439
440 /** \brief Destructor. */
442
443 /** \brief Get the name of the field used. */
444 virtual std::string
445 getFieldName () const { return ("rgba"); }
446
448 getColor () const override;
449
450 /** \brief Set the input cloud to be used.
451 * \param[in] cloud the input cloud to be used by the handler
452 */
453 virtual void
454 setInputCloud (const PointCloudConstPtr &cloud);
455
456 protected:
457 /** \brief Class getName method. */
458 virtual std::string
459 getName () const { return ("PointCloudColorHandlerRGBAField"); }
460
461 private:
462 // Members derived from the base class
463 using PointCloudColorHandler<PointT>::cloud_;
467 };
468
469 //////////////////////////////////////////////////////////////////////////////////////
470 /** \brief Label field handler class for colors. Paints the points according to their
471 * labels, assigning a unique color from a predefined color lookup table to each label.
472 * \author Sergey Alexandrov
473 * \ingroup visualization
474 */
475 template <typename PointT>
477 {
478 using PointCloud = typename PointCloudColorHandler<PointT>::PointCloud;
479 using PointCloudPtr = typename PointCloud::Ptr;
480 using PointCloudConstPtr = typename PointCloud::ConstPtr;
481
482 public:
483 using Ptr = shared_ptr<PointCloudColorHandlerLabelField<PointT> >;
484 using ConstPtr = shared_ptr<const PointCloudColorHandlerLabelField<PointT> >;
485
486 /** \brief Constructor.
487 * \param[in] static_mapping Use a static colormapping from label_id to color (default true) */
488 PointCloudColorHandlerLabelField (const bool static_mapping = true)
489 : PointCloudColorHandler<PointT> ()
490 {
491 capable_ = false;
492 static_mapping_ = static_mapping;
493 }
494
495 /** \brief Constructor.
496 * \param[in] static_mapping Use a static colormapping from label_id to color (default true) */
497 PointCloudColorHandlerLabelField (const PointCloudConstPtr &cloud,
498 const bool static_mapping = true)
499 : PointCloudColorHandler<PointT> (cloud)
500 {
501 setInputCloud (cloud);
502 static_mapping_ = static_mapping;
503 }
504
505 /** \brief Destructor. */
507
508 /** \brief Get the name of the field used. */
509 virtual std::string
510 getFieldName () const { return ("label"); }
511
513 getColor () const override;
514
516
517 /** \brief Set the input cloud to be used.
518 * \param[in] cloud the input cloud to be used by the handler
519 */
520 virtual void
521 setInputCloud (const PointCloudConstPtr &cloud);
522
523 protected:
524 /** \brief Class getName method. */
525 virtual std::string
526 getName () const { return ("PointCloudColorHandlerLabelField"); }
527
528 private:
529 // Members derived from the base class
530 using PointCloudColorHandler<PointT>::cloud_;
534 bool static_mapping_;
535 };
536
537 //////////////////////////////////////////////////////////////////////////////////////
538 /** \brief Base Handler class for PointCloud colors.
539 * \author Radu B. Rusu
540 * \ingroup visualization
541 */
542 template <>
543 class PCL_EXPORTS PointCloudColorHandler<pcl::PCLPointCloud2>
544 {
545 public:
547 using PointCloudPtr = PointCloud::Ptr;
548 using PointCloudConstPtr = PointCloud::ConstPtr;
549
550 using Ptr = shared_ptr<PointCloudColorHandler<PointCloud> >;
551 using ConstPtr = shared_ptr<const PointCloudColorHandler<PointCloud> >;
552
553 /** \brief Constructor. */
554 PointCloudColorHandler (const PointCloudConstPtr &cloud) :
555 cloud_ (cloud), capable_ (false), field_idx_ ()
556 {}
557
558 /** \brief Destructor. */
559 virtual ~PointCloudColorHandler () {}
560
561 /** \brief Return whether this handler is capable of handling the input data or not. */
562 inline bool
563 isCapable () const { return (capable_); }
564
565 /** \brief Abstract getName method. */
566 virtual std::string
567 getName () const = 0;
568
569 /** \brief Abstract getFieldName method. */
570 virtual std::string
571 getFieldName () const = 0;
572
573 /** Obtain the actual color for the input dataset as a VTK data array.
574 * Deriving handlers should override this method. The default implementation is
575 * provided only for backwards compatibility with handlers that were written
576 * before PCL 1.10.0 and will be removed in future.
577 * \return smart pointer to VTK array if the operation was successful (the
578 * handler is capable and the input cloud was given), a null pointer otherwise */
579 virtual vtkSmartPointer<vtkDataArray>
580 getColor() const = 0;
581
582 /** \brief Set the input cloud to be used.
583 * \param[in] cloud the input cloud to be used by the handler
584 */
585 void
586 setInputCloud (const PointCloudConstPtr &cloud)
587 {
588 cloud_ = cloud;
589 }
590
591 protected:
592 /** \brief A pointer to the input dataset. */
593 PointCloudConstPtr cloud_;
594
595 /** \brief True if this handler is capable of handling the input data, false
596 * otherwise.
597 */
598 bool capable_;
599
600 /** \brief The index of the field holding the data that represents the color. */
601 int field_idx_;
602 };
603
604 //////////////////////////////////////////////////////////////////////////////////////
605 /** \brief Handler for random PointCloud colors (i.e., R, G, B will be randomly chosen)
606 * \author Radu B. Rusu
607 * \ingroup visualization
608 */
609 template <>
610 class PCL_EXPORTS PointCloudColorHandlerRandom<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
611 {
613 using PointCloudPtr = PointCloud::Ptr;
614 using PointCloudConstPtr = PointCloud::ConstPtr;
615
616 public:
617 using Ptr = shared_ptr<PointCloudColorHandlerRandom<PointCloud> >;
618 using ConstPtr = shared_ptr<const PointCloudColorHandlerRandom<PointCloud> >;
619
620 /** \brief Constructor. */
621 PointCloudColorHandlerRandom (const PointCloudConstPtr &cloud) :
623 {
624 capable_ = true;
625 }
626
627 /** \brief Empty destructor */
629
630 /** \brief Get the name of the class. */
631 virtual std::string
632 getName () const { return ("PointCloudColorHandlerRandom"); }
633
634 /** \brief Get the name of the field used. */
635 virtual std::string
636 getFieldName () const { return ("[random]"); }
637
639 getColor () const override;
640 };
641
642 //////////////////////////////////////////////////////////////////////////////////////
643 /** \brief Handler for predefined user colors. The color at each point will be drawn
644 * as the use given R, G, B values.
645 * \author Radu B. Rusu
646 * \ingroup visualization
647 */
648 template <>
649 class PCL_EXPORTS PointCloudColorHandlerCustom<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
650 {
652 using PointCloudPtr = PointCloud::Ptr;
653 using PointCloudConstPtr = PointCloud::ConstPtr;
654
655 public:
656 /** \brief Constructor. */
657 PointCloudColorHandlerCustom (const PointCloudConstPtr &cloud,
658 double r, double g, double b) :
660 r_ (r), g_ (g), b_ (b)
661 {
662 capable_ = true;
663 }
664
665 /** \brief Empty destructor */
667
668 /** \brief Get the name of the class. */
669 virtual std::string
670 getName () const { return ("PointCloudColorHandlerCustom"); }
671
672 /** \brief Get the name of the field used. */
673 virtual std::string
674 getFieldName () const { return (""); }
675
677 getColor () const override;
678
679 protected:
680 /** \brief Internal R, G, B holding the values given by the user. */
681 double r_, g_, b_;
682 };
683
684 //////////////////////////////////////////////////////////////////////////////////////
685 /** \brief RGB handler class for colors. Uses the data present in the "rgb" or "rgba"
686 * fields as the color at each point.
687 * \author Radu B. Rusu
688 * \ingroup visualization
689 */
690 template <>
691 class PCL_EXPORTS PointCloudColorHandlerRGBField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
692 {
694 using PointCloudPtr = PointCloud::Ptr;
695 using PointCloudConstPtr = PointCloud::ConstPtr;
696
697 public:
698 using Ptr = shared_ptr<PointCloudColorHandlerRGBField<PointCloud> >;
699 using ConstPtr = shared_ptr<const PointCloudColorHandlerRGBField<PointCloud> >;
700
701 /** \brief Constructor. */
702 PointCloudColorHandlerRGBField (const PointCloudConstPtr &cloud);
703
704 /** \brief Empty destructor */
706
708 getColor () const override;
709
710 protected:
711 /** \brief Get the name of the class. */
712 virtual std::string
713 getName () const { return ("PointCloudColorHandlerRGBField"); }
714
715 /** \brief Get the name of the field used. */
716 virtual std::string
717 getFieldName () const { return ("rgb"); }
718 };
719
720 //////////////////////////////////////////////////////////////////////////////////////
721 /** \brief HSV handler class for colors. Uses the data present in the "h", "s", "v"
722 * fields as the color at each point.
723 * \ingroup visualization
724 */
725 template <>
726 class PCL_EXPORTS PointCloudColorHandlerHSVField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
727 {
729 using PointCloudPtr = PointCloud::Ptr;
730 using PointCloudConstPtr = PointCloud::ConstPtr;
731
732 public:
733 using Ptr = shared_ptr<PointCloudColorHandlerHSVField<PointCloud> >;
734 using ConstPtr = shared_ptr<const PointCloudColorHandlerHSVField<PointCloud> >;
735
736 /** \brief Constructor. */
737 PointCloudColorHandlerHSVField (const PointCloudConstPtr &cloud);
738
739 /** \brief Empty destructor */
741
743 getColor () const override;
744
745 protected:
746 /** \brief Get the name of the class. */
747 virtual std::string
748 getName () const { return ("PointCloudColorHandlerHSVField"); }
749
750 /** \brief Get the name of the field used. */
751 virtual std::string
752 getFieldName () const { return ("hsv"); }
753
754 /** \brief The field index for "S". */
756
757 /** \brief The field index for "V". */
759 };
760
761 //////////////////////////////////////////////////////////////////////////////////////
762 /** \brief Generic field handler class for colors. Uses an user given field to extract
763 * 1D data and display the color at each point using a min-max lookup table.
764 * \author Radu B. Rusu
765 * \ingroup visualization
766 */
767 template <>
768 class PCL_EXPORTS PointCloudColorHandlerGenericField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
769 {
771 using PointCloudPtr = PointCloud::Ptr;
772 using PointCloudConstPtr = PointCloud::ConstPtr;
773
774 public:
775 using Ptr = shared_ptr<PointCloudColorHandlerGenericField<PointCloud> >;
776 using ConstPtr = shared_ptr<const PointCloudColorHandlerGenericField<PointCloud> >;
777
778 /** \brief Constructor. */
779 PointCloudColorHandlerGenericField (const PointCloudConstPtr &cloud,
780 const std::string &field_name);
781
782 /** \brief Empty destructor */
784
786 getColor () const override;
787
788 protected:
789 /** \brief Get the name of the class. */
790 virtual std::string
791 getName () const { return ("PointCloudColorHandlerGenericField"); }
792
793 /** \brief Get the name of the field used. */
794 virtual std::string
795 getFieldName () const { return (field_name_); }
796
797 private:
798 /** \brief Name of the field used to create the color handler. */
799 std::string field_name_;
800 };
801
802 //////////////////////////////////////////////////////////////////////////////////////
803 /** \brief RGBA handler class for colors. Uses the data present in the "rgba" field as
804 * the color at each point. Transparency is handled.
805 * \author Nizar Sallem
806 * \ingroup visualization
807 */
808 template <>
809 class PCL_EXPORTS PointCloudColorHandlerRGBAField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
810 {
812 using PointCloudPtr = PointCloud::Ptr;
813 using PointCloudConstPtr = PointCloud::ConstPtr;
814
815 public:
816 using Ptr = shared_ptr<PointCloudColorHandlerRGBAField<PointCloud> >;
817 using ConstPtr = shared_ptr<const PointCloudColorHandlerRGBAField<PointCloud> >;
818
819 /** \brief Constructor. */
820 PointCloudColorHandlerRGBAField (const PointCloudConstPtr &cloud);
821
822 /** \brief Empty destructor */
824
826 getColor () const override;
827
828 protected:
829 /** \brief Get the name of the class. */
830 virtual std::string
831 getName () const { return ("PointCloudColorHandlerRGBAField"); }
832
833 /** \brief Get the name of the field used. */
834 virtual std::string
835 getFieldName () const { return ("rgba"); }
836 };
837
838 //////////////////////////////////////////////////////////////////////////////////////
839 /** \brief Label field handler class for colors. Paints the points according to their
840 * labels, assigning a unique color from a predefined color lookup table to each label.
841 * \author Sergey Alexandrov
842 * \ingroup visualization
843 */
844 template <>
845 class PCL_EXPORTS PointCloudColorHandlerLabelField<pcl::PCLPointCloud2> : public PointCloudColorHandler<pcl::PCLPointCloud2>
846 {
848 using PointCloudPtr = PointCloud::Ptr;
849 using PointCloudConstPtr = PointCloud::ConstPtr;
850
851 public:
852 using Ptr = shared_ptr<PointCloudColorHandlerLabelField<PointCloud> >;
853 using ConstPtr = shared_ptr<const PointCloudColorHandlerLabelField<PointCloud> >;
854
855 /** \brief Constructor.
856 * \param[in] static_mapping Use a static colormapping from label_id to color (default true) */
857 PointCloudColorHandlerLabelField (const PointCloudConstPtr &cloud,
858 const bool static_mapping = true);
859
860 /** \brief Empty destructor */
862
864 getColor () const override;
865
866 protected:
867 /** \brief Get the name of the class. */
868 virtual std::string
869 getName () const { return ("PointCloudColorHandlerLabelField"); }
870
871 /** \brief Get the name of the field used. */
872 virtual std::string
873 getFieldName () const { return ("label"); }
874 private:
875 bool static_mapping_;
876 };
877
878 }
879}
880
881#include <pcl/visualization/impl/point_cloud_color_handlers.hpp>
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
virtual std::string getFieldName() const
Get the name of the field used.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
double r_
Internal R, G, B holding the values given by the user.
PointCloudColorHandlerCustom(const PointCloudConstPtr &cloud, double r, double g, double b)
Constructor.
virtual std::string getFieldName() const
Get the name of the field used.
double r_
Internal R, G, B holding the values given by the user.
shared_ptr< const PointCloudColorHandlerCustom< PointT > > ConstPtr
PointCloudColorHandlerCustom(const PointCloudConstPtr &cloud, double r, double g, double b)
Constructor.
PointCloudColorHandlerCustom(double r, double g, double b)
Constructor.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
virtual std::string getName() const
Abstract getName method.
shared_ptr< PointCloudColorHandlerCustom< PointT > > Ptr
PointCloudColorHandlerGenericField(const PointCloudConstPtr &cloud, const std::string &field_name)
Constructor.
shared_ptr< PointCloudColorHandlerGenericField< PointCloud > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerGenericField< PointCloud > > ConstPtr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
shared_ptr< PointCloudColorHandlerGenericField< PointT > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
PointCloudColorHandlerGenericField(const PointCloudConstPtr &cloud, const std::string &field_name)
Constructor.
virtual std::string getName() const
Class getName method.
PointCloudColorHandlerGenericField(const std::string &field_name)
Constructor.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
shared_ptr< const PointCloudColorHandlerGenericField< PointT > > ConstPtr
virtual std::string getFieldName() const
Get the name of the field used.
PointCloudColorHandlerHSVField(const PointCloudConstPtr &cloud)
Constructor.
shared_ptr< const PointCloudColorHandlerHSVField< PointCloud > > ConstPtr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
PointCloudColorHandlerHSVField(const PointCloudConstPtr &cloud)
Constructor.
shared_ptr< PointCloudColorHandlerHSVField< PointT > > Ptr
virtual std::string getName() const
Class getName method.
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerHSVField< PointT > > ConstPtr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
Base Handler class for PointCloud colors.
shared_ptr< const PointCloudColorHandler< PointT > > ConstPtr
virtual vtkSmartPointer< vtkDataArray > getColor() const =0
Obtain the actual color for the input dataset as a VTK data array.
bool isCapable() const
Check if this handler is capable of handling the input data or not.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual std::string getName() const =0
Abstract getName method.
std::vector< pcl::PCLPointField > fields_
PointCloudColorHandler(const PointCloudConstPtr &cloud)
Constructor.
shared_ptr< PointCloudColorHandler< PointT > > Ptr
virtual std::string getFieldName() const =0
Abstract getFieldName method.
shared_ptr< PointCloudColorHandlerLabelField< PointCloud > > Ptr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
PointCloudColorHandlerLabelField(const PointCloudConstPtr &cloud, const bool static_mapping=true)
Constructor.
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerLabelField< PointCloud > > ConstPtr
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual std::string getName() const
Class getName method.
PointCloudColorHandlerLabelField(const PointCloudConstPtr &cloud, const bool static_mapping=true)
Constructor.
shared_ptr< PointCloudColorHandlerLabelField< PointT > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerLabelField< PointT > > ConstPtr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
PointCloudColorHandlerLabelField(const bool static_mapping=true)
Constructor.
shared_ptr< const PointCloudColorHandlerRGBAField< PointCloud > > ConstPtr
shared_ptr< PointCloudColorHandlerRGBAField< PointCloud > > Ptr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
virtual std::string getFieldName() const
Get the name of the field used.
PointCloudColorHandlerRGBAField(const PointCloudConstPtr &cloud)
Constructor.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
PointCloudColorHandlerRGBAField(const PointCloudConstPtr &cloud)
Constructor.
shared_ptr< PointCloudColorHandlerRGBAField< PointT > > Ptr
virtual std::string getName() const
Class getName method.
shared_ptr< const PointCloudColorHandlerRGBAField< PointT > > ConstPtr
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerRGBField< PointCloud > > ConstPtr
virtual std::string getFieldName() const
Get the name of the field used.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
PointCloudColorHandlerRGBField(const PointCloudConstPtr &cloud)
Constructor.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
shared_ptr< PointCloudColorHandlerRGBField< PointT > > Ptr
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerRGBField< PointT > > ConstPtr
PointCloudColorHandlerRGBField(const PointCloudConstPtr &cloud)
Constructor.
virtual std::string getName() const
Class getName method.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< const PointCloudColorHandlerRandom< PointCloud > > ConstPtr
shared_ptr< const PointCloudColorHandlerRandom< PointT > > ConstPtr
virtual std::string getName() const
Abstract getName method.
virtual std::string getFieldName() const
Get the name of the field used.
shared_ptr< PointCloudColorHandlerRandom< PointT > > Ptr
vtkSmartPointer< vtkDataArray > getColor() const override
Obtain the actual color for the input dataset as a VTK data array.
PointCloudColorHandlerRandom(const PointCloudConstPtr &cloud)
Constructor.
Defines all the PCL and non-PCL macros used.