Point Cloud Library (PCL)  1.7.2
point_cloud_image_extractors.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2013-, 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_IMAGE_EXTRACTORS_H_
38 #define PCL_POINT_CLOUD_IMAGE_EXTRACTORS_H_
39 
40 #include <pcl/point_cloud.h>
41 #include <pcl/PCLImage.h>
42 
43 namespace pcl
44 {
45  namespace io
46  {
47  //////////////////////////////////////////////////////////////////////////////////////
48  /** \brief Base Image Extractor class for organized point clouds.
49  *
50  * This is an abstract class that declares an interface for image extraction from
51  * organized point clouds. The family of its subclasses provide functionality to
52  * extract images from particular fields.
53  *
54  * The following piece of code demonstrates typical usage of a PointCloudImageExtractor
55  * subclass. Here the data are extracted from the "label" field and are saved as a
56  * PNG image file.
57  *
58  * \code
59  * // Source point cloud (needs to be filled with data of course)
60  * pcl::PointCloud<pcl::PointXYZLabel> cloud;
61  * // Target image
62  * pcl::PCLImage image;
63  * // Create PointCloudImageExtractor subclass that can handle "label" field
64  * pcl::io::PointCloudImageExtractorFromLabelField<pcl::XYZLabel> pcie;
65  * // Set it up if not happy with the defaults
66  * pcie.setColorMode(pcie.COLORS_RGB_RANDOM);
67  * // Try to extract an image
68  * bool success = pcie.extract(cloud, image);
69  * // Save to file if succeeded
70  * if (success)
71  * pcl::io::saveImage ("filename.png", image);
72  * \endcode
73  *
74  * \author Sergey Alexandrov
75  * \ingroup io
76  */
77  template <typename PointT>
79  {
80  public:
82 
83  typedef boost::shared_ptr<PointCloudImageExtractor<PointT> > Ptr;
84  typedef boost::shared_ptr<const PointCloudImageExtractor<PointT> > ConstPtr;
85 
86  /** \brief Constructor. */
88  : paint_nans_with_black_ (false)
89  {}
90 
91  /** \brief Destructor. */
93 
94  /** \brief Obtain the image from the given cloud.
95  * \param[in] cloud organized point cloud to extract image from
96  * \param[out] image the output image
97  * \return true if the operation was successful, false otherwise
98  */
99  bool
100  extract (const PointCloud& cloud, pcl::PCLImage& image) const;
101 
102  /** \brief Set a flag that controls if image pixels corresponding to
103  * NaN (infinite) points should be painted black.
104  */
105  inline void
107  {
108  paint_nans_with_black_ = flag;
109  }
110 
111  protected:
112 
113  /** \brief Implementation of the extract() function, has to be
114  * implemented in deriving classes.
115  */
116  virtual bool
117  extractImpl (const PointCloud& cloud, pcl::PCLImage& image) const = 0;
118 
119  /// A flag that controls if image pixels corresponding to NaN (infinite)
120  /// points should be painted black.
122  };
123 
124  //////////////////////////////////////////////////////////////////////////////////////
125  /** \brief Image Extractor extension which provides functionality to apply scaling to
126  * the values extracted from a field.
127  * \author Sergey Alexandrov
128  * \ingroup io
129  */
130  template <typename PointT>
132  {
134 
135  public:
136  typedef boost::shared_ptr<PointCloudImageExtractorWithScaling<PointT> > Ptr;
137  typedef boost::shared_ptr<const PointCloudImageExtractorWithScaling<PointT> > ConstPtr;
138 
139  /** \brief Different scaling methods.
140  * <ul>
141  * <li><b>SCALING_NO</b> - no scaling.</li>
142  * <li><b>SCALING_FULL_RANGE</b> - scales to full range of the output value.</li>
143  * <li><b>SCASING_FIXED_FACTOR</b> - scales by a given fixed factor.</li>
144  * </ul>
145  */
147  {
151  };
152 
153  /** \brief Constructor. */
154  PointCloudImageExtractorWithScaling (const std::string& field_name, const ScalingMethod scaling_method)
155  : field_name_ (field_name)
156  , scaling_method_ (scaling_method)
157  , scaling_factor_ (1.0f)
158  {
159  }
160 
161  /** \brief Constructor. */
162  PointCloudImageExtractorWithScaling (const std::string& field_name, const float scaling_factor)
163  : field_name_ (field_name)
165  , scaling_factor_ (scaling_factor)
166  {
167  }
168 
169  /** \brief Destructor. */
171 
172  /** \brief Set scaling method. */
173  inline void
174  setScalingMethod (const ScalingMethod scaling_method)
175  {
176  scaling_method_ = scaling_method;
177  }
178 
179  /** \brief Set fixed scaling factor. */
180  inline void
181  setScalingFactor (const float scaling_factor)
182  {
183  scaling_factor_ = scaling_factor;
184  }
185 
186  protected:
187 
188  virtual bool
189  extractImpl (const PointCloud& cloud, pcl::PCLImage& image) const;
190 
191  std::string field_name_;
194  };
195 
196  //////////////////////////////////////////////////////////////////////////////////////
197  /** \brief Image Extractor which uses the data present in the "normal" field. Normal
198  * vector components (x, y, z) are mapped to color channels (r, g, b respectively).
199  * \author Sergey Alexandrov
200  * \ingroup io
201  */
202  template <typename PointT>
204  {
206 
207  public:
208  typedef boost::shared_ptr<PointCloudImageExtractorFromNormalField<PointT> > Ptr;
209  typedef boost::shared_ptr<const PointCloudImageExtractorFromNormalField<PointT> > ConstPtr;
210 
211  /** \brief Constructor. */
213 
214  /** \brief Destructor. */
216 
217  protected:
218 
219  virtual bool
220  extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const;
221  };
222 
223  //////////////////////////////////////////////////////////////////////////////////////
224  /** \brief Image Extractor which uses the data present in the "rgb" or "rgba" fields
225  * to produce a color image with rgb8 encoding.
226  * \author Sergey Alexandrov
227  * \ingroup io
228  */
229  template <typename PointT>
231  {
233 
234  public:
235  typedef boost::shared_ptr<PointCloudImageExtractorFromRGBField<PointT> > Ptr;
236  typedef boost::shared_ptr<const PointCloudImageExtractorFromRGBField<PointT> > ConstPtr;
237 
238  /** \brief Constructor. */
240 
241  /** \brief Destructor. */
243 
244  protected:
245 
246  virtual bool
247  extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const;
248  };
249 
250  //////////////////////////////////////////////////////////////////////////////////////
251  /** \brief Image Extractor which uses the data present in the "label" field to produce
252  * either monochrome or RGB image where different labels correspond to different
253  * colors.
254  * See the documentation for ColorMode to learn about available coloring options.
255  * \author Sergey Alexandrov
256  * \ingroup io
257  */
258  template <typename PointT>
260  {
262 
263  public:
264  typedef boost::shared_ptr<PointCloudImageExtractorFromLabelField<PointT> > Ptr;
265  typedef boost::shared_ptr<const PointCloudImageExtractorFromLabelField<PointT> > ConstPtr;
266 
267  /** \brief Different modes for color mapping. */
269  {
270  /// Shades of gray (according to label id)
271  /// \note Labels using more than 16 bits will cause problems
273  /// Randomly generated RGB colors
275  /// Fixed RGB colors from the [Glasbey lookup table](http://fiji.sc/Glasbey),
276  /// assigned in the ascending order of label id
278  };
279 
280  /** \brief Constructor. */
282  : color_mode_ (color_mode)
283  {
284  }
285 
286  /** \brief Destructor. */
288 
289  /** \brief Set color mapping mode. */
290  inline void
291  setColorMode (const ColorMode color_mode)
292  {
293  color_mode_ = color_mode;
294  }
295 
296  protected:
297 
298  virtual bool
299  extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const;
300 
301  private:
302 
303  ColorMode color_mode_;
304  };
305 
306  //////////////////////////////////////////////////////////////////////////////////////
307  /** \brief Image Extractor which uses the data present in the "z" field to produce a
308  * depth map (as a monochrome image with mono16 encoding).
309  * \author Sergey Alexandrov
310  * \ingroup io
311  */
312  template <typename PointT>
314  {
317 
318  public:
319  typedef boost::shared_ptr<PointCloudImageExtractorFromZField<PointT> > Ptr;
320  typedef boost::shared_ptr<const PointCloudImageExtractorFromZField<PointT> > ConstPtr;
321 
322  /** \brief Constructor.
323  * \param[in] scaling_factor a scaling factor to apply to each depth value (default 10000)
324  */
325  PointCloudImageExtractorFromZField (const float scaling_factor = 10000)
326  : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_factor)
327  {
328  }
329 
330  /** \brief Constructor.
331  * \param[in] scaling_method a scaling method to use
332  */
334  : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_method)
335  {
336  }
337 
338  /** \brief Destructor. */
340 
341  protected:
342  // Members derived from the base class
346  };
347 
348  //////////////////////////////////////////////////////////////////////////////////////
349  /** \brief Image Extractor which uses the data present in the "curvature" field to
350  * produce a curvature map (as a monochrome image with mono16 encoding).
351  * \author Sergey Alexandrov
352  * \ingroup io
353  */
354  template <typename PointT>
356  {
359 
360  public:
361  typedef boost::shared_ptr<PointCloudImageExtractorFromCurvatureField<PointT> > Ptr;
362  typedef boost::shared_ptr<const PointCloudImageExtractorFromCurvatureField<PointT> > ConstPtr;
363 
364  /** \brief Constructor.
365  * \param[in] scaling_method a scaling method to use (default SCALING_FULL_RANGE)
366  */
368  : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_method)
369  {
370  }
371 
372  /** \brief Constructor.
373  * \param[in] scaling_factor a scaling factor to apply to each curvature value
374  */
375  PointCloudImageExtractorFromCurvatureField (const float scaling_factor)
376  : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_factor)
377  {
378  }
379 
380  /** \brief Destructor. */
382 
383  protected:
384  // Members derived from the base class
388  };
389 
390  //////////////////////////////////////////////////////////////////////////////////////
391  /** \brief Image Extractor which uses the data present in the "intensity" field to produce a
392  * monochrome intensity image (with mono16 encoding).
393  * \author Sergey Alexandrov
394  * \ingroup io
395  */
396  template <typename PointT>
398  {
401 
402  public:
403  typedef boost::shared_ptr<PointCloudImageExtractorFromIntensityField<PointT> > Ptr;
404  typedef boost::shared_ptr<const PointCloudImageExtractorFromIntensityField<PointT> > ConstPtr;
405 
406  /** \brief Constructor.
407  * \param[in] scaling_method a scaling method to use (default SCALING_NO)
408  */
410  : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_method)
411  {
412  }
413 
414  /** \brief Constructor.
415  * \param[in] scaling_factor a scaling factor to apply to each intensity value
416  */
417  PointCloudImageExtractorFromIntensityField (const float scaling_factor)
418  : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_factor)
419  {
420  }
421 
422  /** \brief Destructor. */
424 
425  protected:
426  // Members derived from the base class
430  };
431 
432  }
433 }
434 
435 #include <pcl/io/impl/point_cloud_image_extractors.hpp>
436 
437 #endif //#ifndef PCL_POINT_CLOUD_IMAGE_EXTRACTORS_H_
Image Extractor which uses the data present in the &quot;curvature&quot; field to produce a curvature map (as a...
boost::shared_ptr< PointCloudImageExtractorFromLabelField< PointT > > Ptr
boost::shared_ptr< PointCloudImageExtractorFromIntensityField< PointT > > Ptr
virtual bool extractImpl(const PointCloud &cloud, pcl::PCLImage &img) const
Implementation of the extract() function, has to be implemented in deriving classes.
virtual bool extractImpl(const PointCloud &cloud, pcl::PCLImage &img) const
Implementation of the extract() function, has to be implemented in deriving classes.
boost::shared_ptr< const PointCloudImageExtractorFromNormalField< PointT > > ConstPtr
void setScalingMethod(const ScalingMethod scaling_method)
Set scaling method.
PointCloudImageExtractorFromIntensityField(const float scaling_factor)
Constructor.
boost::shared_ptr< const PointCloudImageExtractorFromCurvatureField< PointT > > ConstPtr
boost::shared_ptr< PointCloudImageExtractorWithScaling< PointT > > Ptr
boost::shared_ptr< PointCloudImageExtractorFromNormalField< PointT > > Ptr
PointCloudImageExtractorFromCurvatureField(const float scaling_factor)
Constructor.
virtual bool extractImpl(const PointCloud &cloud, pcl::PCLImage &image) const
Implementation of the extract() function, has to be implemented in deriving classes.
Image Extractor extension which provides functionality to apply scaling to the values extracted from ...
boost::shared_ptr< PointCloudImageExtractor< PointT > > Ptr
bool extract(const PointCloud &cloud, pcl::PCLImage &image) const
Obtain the image from the given cloud.
boost::shared_ptr< const PointCloudImageExtractorFromZField< PointT > > ConstPtr
PointCloudImageExtractorFromLabelField(const ColorMode color_mode=COLORS_MONO)
Constructor.
Image Extractor which uses the data present in the &quot;rgb&quot; or &quot;rgba&quot; fields to produce a color image wi...
boost::shared_ptr< const PointCloudImageExtractorFromIntensityField< PointT > > ConstPtr
boost::shared_ptr< const PointCloudImageExtractor< PointT > > ConstPtr
Fixed RGB colors from the Glasbey lookup table, assigned in the ascending order of label id...
boost::shared_ptr< PointCloudImageExtractorFromRGBField< PointT > > Ptr
PointCloudImageExtractorWithScaling(const std::string &field_name, const float scaling_factor)
Constructor.
Image Extractor which uses the data present in the &quot;normal&quot; field.
PointCloudImageExtractorFromIntensityField(const ScalingMethod scaling_method=PointCloudImageExtractorWithScaling< PointT >::SCALING_NO)
Constructor.
virtual bool extractImpl(const PointCloud &cloud, pcl::PCLImage &img) const
Implementation of the extract() function, has to be implemented in deriving classes.
boost::shared_ptr< const PointCloudImageExtractorFromLabelField< PointT > > ConstPtr
boost::shared_ptr< PointCloudImageExtractorFromCurvatureField< PointT > > Ptr
void setPaintNaNsWithBlack(bool flag)
Set a flag that controls if image pixels corresponding to NaN (infinite) points should be painted bla...
PointCloudImageExtractorFromZField(const float scaling_factor=10000)
Constructor.
PointCloudImageExtractorFromCurvatureField(const ScalingMethod scaling_method=PointCloudImageExtractorWithScaling< PointT >::SCALING_FULL_RANGE)
Constructor.
boost::shared_ptr< const PointCloudImageExtractorFromRGBField< PointT > > ConstPtr
Image Extractor which uses the data present in the &quot;intensity&quot; field to produce a monochrome intensit...
void setColorMode(const ColorMode color_mode)
Set color mapping mode.
PointCloudImageExtractorWithScaling(const std::string &field_name, const ScalingMethod scaling_method)
Constructor.
void setScalingFactor(const float scaling_factor)
Set fixed scaling factor.
A point structure representing Euclidean xyz coordinates, and the RGB color.
PointCloudImageExtractorFromZField(const ScalingMethod scaling_method)
Constructor.
virtual bool extractImpl(const PointCloud &cloud, pcl::PCLImage &image) const =0
Implementation of the extract() function, has to be implemented in deriving classes.
boost::shared_ptr< PointCloudImageExtractorFromZField< PointT > > Ptr
bool paint_nans_with_black_
A flag that controls if image pixels corresponding to NaN (infinite) points should be painted black...
Image Extractor which uses the data present in the &quot;label&quot; field to produce either monochrome or RGB ...
Image Extractor which uses the data present in the &quot;z&quot; field to produce a depth map (as a monochrome ...
boost::shared_ptr< const PointCloudImageExtractorWithScaling< PointT > > ConstPtr
Base Image Extractor class for organized point clouds.