Point Cloud Library (PCL)  1.7.1
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 
89  /** \brief Destructor. */
91 
92  /** \brief Obtain the image from the given cloud.
93  * \param[in] cloud organized point cloud to extract image from
94  * \param[out] image the output image
95  * \return true if the operation was successful, false otherwise
96  */
97  virtual bool
98  extract (const PointCloud& cloud, pcl::PCLImage& image) const = 0;
99  };
100 
101  //////////////////////////////////////////////////////////////////////////////////////
102  /** \brief Image Extractor extension which provides functionality to apply scaling to
103  * the values extracted from a field.
104  * \author Sergey Alexandrov
105  * \ingroup io
106  */
107  template <typename PointT>
109  {
111 
112  public:
113  typedef boost::shared_ptr<PointCloudImageExtractorWithScaling<PointT> > Ptr;
114  typedef boost::shared_ptr<const PointCloudImageExtractorWithScaling<PointT> > ConstPtr;
115 
116  /** \brief Different scaling methods.
117  * <ul>
118  * <li><b>SCALING_NO</b> - no scaling.</li>
119  * <li><b>SCALING_FULL_RANGE</b> - scales to full range of the output value.</li>
120  * <li><b>SCASING_FIXED_FACTOR</b> - scales by a given fixed factor.</li>
121  * </ul>
122  */
124  {
128  };
129 
130  /** \brief Constructor. */
131  PointCloudImageExtractorWithScaling (const std::string& field_name, const ScalingMethod scaling_method)
132  : field_name_ (field_name)
133  , scaling_method_ (scaling_method)
134  , scaling_factor_ (1.0f)
135  {
136  }
137 
138  /** \brief Constructor. */
139  PointCloudImageExtractorWithScaling (const std::string& field_name, const float scaling_factor)
140  : field_name_ (field_name)
142  , scaling_factor_ (scaling_factor)
143  {
144  }
145 
146  /** \brief Destructor. */
148 
149  /** \brief Obtain the image from the given cloud.
150  * \param[in] cloud organized point cloud to extract image from
151  * \param[out] image the output image
152  * \return true if the operation was successful, false otherwise
153  */
154  virtual bool
155  extract (const PointCloud& cloud, pcl::PCLImage& image) const;
156 
157  /** \brief Set scaling method. */
158  inline void
159  setScalingMethod (const ScalingMethod scaling_method)
160  {
161  scaling_method_ = scaling_method;
162  }
163 
164  /** \brief Set fixed scaling factor. */
165  inline void
166  setScalingFactor (const float scaling_factor)
167  {
168  scaling_factor_ = scaling_factor;
169  }
170 
171  protected:
172 
173  std::string field_name_;
176  };
177 
178  //////////////////////////////////////////////////////////////////////////////////////
179  /** \brief Image Extractor which uses the data present in the "normal" field. Normal
180  * vector components (x, y, z) are mapped to color channels (r, g, b respectively).
181  * \author Sergey Alexandrov
182  * \ingroup io
183  */
184  template <typename PointT>
186  {
188 
189  public:
190  typedef boost::shared_ptr<PointCloudImageExtractorFromNormalField<PointT> > Ptr;
191  typedef boost::shared_ptr<const PointCloudImageExtractorFromNormalField<PointT> > ConstPtr;
192 
193  /** \brief Constructor. */
195 
196  /** \brief Destructor. */
198 
199  /** \brief Obtain the color image from the given cloud.
200  * The cloud should contain "normal" field.
201  * \param[in] cloud organized point cloud to extract image from
202  * \param[out] image the output image
203  * \return true if the operation was successful, false otherwise
204  */
205  virtual bool
206  extract (const PointCloud& cloud, pcl::PCLImage& img) const;
207  };
208 
209  //////////////////////////////////////////////////////////////////////////////////////
210  /** \brief Image Extractor which uses the data present in the "rgb" or "rgba" fields
211  * to produce a color image with rgb8 encoding.
212  * \author Sergey Alexandrov
213  * \ingroup io
214  */
215  template <typename PointT>
217  {
219 
220  public:
221  typedef boost::shared_ptr<PointCloudImageExtractorFromRGBField<PointT> > Ptr;
222  typedef boost::shared_ptr<const PointCloudImageExtractorFromRGBField<PointT> > ConstPtr;
223 
224  /** \brief Constructor. */
226 
227  /** \brief Destructor. */
229 
230  /** \brief Obtain the color image from the given cloud.
231  * The cloud should contain either "rgb" or "rgba" field.
232  * \param[in] cloud organized point cloud to extract image from
233  * \param[out] image the output image
234  * \return true if the operation was successful, false otherwise
235  */
236  virtual bool
237  extract (const PointCloud& cloud, pcl::PCLImage& img) const;
238  };
239 
240  //////////////////////////////////////////////////////////////////////////////////////
241  /** \brief Image Extractor which uses the data present in the "label" field to produce
242  * either monochrome or RGB image where different labels correspond to different
243  * colors. In the monochrome case colors are shades of gray, in the RGB case the
244  * colors are generated randomly.
245  * \author Sergey Alexandrov
246  * \ingroup io
247  */
248  template <typename PointT>
250  {
252 
253  public:
254  typedef boost::shared_ptr<PointCloudImageExtractorFromLabelField<PointT> > Ptr;
255  typedef boost::shared_ptr<const PointCloudImageExtractorFromLabelField<PointT> > ConstPtr;
256 
257  /** \brief Different modes for color mapping.
258  * <ul>
259  * <li><b>COLORS_MONO</b> - shades of gray (according to label id).</li>
260  * <li><b>COLORS_RGB_RANDOM</b> - randomly generated RGB colors.</li>
261  * </ul>
262  */
264  {
267  };
268 
269  /** \brief Constructor. */
271  : color_mode_ (color_mode)
272  {
273  }
274 
275  /** \brief Destructor. */
277 
278  /** \brief Obtain the label image from the given cloud.
279  * The cloud should contain "label" field.
280  * \note Labels using more than 16 bits will cause problems in COLORS_MONO mode.
281  * \param[in] cloud organized point cloud to extract image from
282  * \param[out] image the output image
283  * \return true if the operation was successful, false otherwise
284  */
285  virtual bool
286  extract (const PointCloud& cloud, pcl::PCLImage& img) const;
287 
288  /** \brief Set color mapping mode. */
289  inline void
290  setColorMode (const ColorMode color_mode)
291  {
292  color_mode_ = color_mode;
293  }
294 
295  private:
296 
297  ColorMode color_mode_;
298  };
299 
300  //////////////////////////////////////////////////////////////////////////////////////
301  /** \brief Image Extractor which uses the data present in the "z" field to produce a
302  * depth map (as a monochrome image with mono16 encoding).
303  * \author Sergey Alexandrov
304  * \ingroup io
305  */
306  template <typename PointT>
308  {
311 
312  public:
313  typedef boost::shared_ptr<PointCloudImageExtractorFromZField<PointT> > Ptr;
314  typedef boost::shared_ptr<const PointCloudImageExtractorFromZField<PointT> > ConstPtr;
315 
316  /** \brief Constructor.
317  * \param[i] scaling_factor a scaling factor to apply to each depth value (default 10000)
318  */
319  PointCloudImageExtractorFromZField (const float scaling_factor = 10000)
320  : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_factor)
321  {
322  }
323 
324  /** \brief Constructor.
325  * \param[i] scaling_method a scaling method to use
326  */
328  : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_method)
329  {
330  }
331 
332  /** \brief Destructor. */
334 
335  protected:
336  // Members derived from the base class
340  };
341 
342  //////////////////////////////////////////////////////////////////////////////////////
343  /** \brief Image Extractor which uses the data present in the "curvature" field to
344  * produce a curvature map (as a monochrome image with mono16 encoding).
345  * \author Sergey Alexandrov
346  * \ingroup io
347  */
348  template <typename PointT>
350  {
353 
354  public:
355  typedef boost::shared_ptr<PointCloudImageExtractorFromCurvatureField<PointT> > Ptr;
356  typedef boost::shared_ptr<const PointCloudImageExtractorFromCurvatureField<PointT> > ConstPtr;
357 
358  /** \brief Constructor.
359  * \param[i] scaling_method a scaling method to use (default SCALING_FULL_RANGE)
360  */
362  : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_method)
363  {
364  }
365 
366  /** \brief Constructor.
367  * \param[i] scaling_factor a scaling factor to apply to each curvature value
368  */
369  PointCloudImageExtractorFromCurvatureField (const float scaling_factor)
370  : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_factor)
371  {
372  }
373 
374  /** \brief Destructor. */
376 
377  protected:
378  // Members derived from the base class
382  };
383 
384  //////////////////////////////////////////////////////////////////////////////////////
385  /** \brief Image Extractor which uses the data present in the "intensity" field to produce a
386  * monochrome intensity image (with mono16 encoding).
387  * \author Sergey Alexandrov
388  * \ingroup io
389  */
390  template <typename PointT>
392  {
395 
396  public:
397  typedef boost::shared_ptr<PointCloudImageExtractorFromIntensityField<PointT> > Ptr;
398  typedef boost::shared_ptr<const PointCloudImageExtractorFromIntensityField<PointT> > ConstPtr;
399 
400  /** \brief Constructor.
401  * \param[i] scaling_method a scaling method to use (default SCALING_NO)
402  */
404  : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_method)
405  {
406  }
407 
408  /** \brief Constructor.
409  * \param[i] scaling_factor a scaling factor to apply to each intensity value
410  */
411  PointCloudImageExtractorFromIntensityField (const float scaling_factor)
412  : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_factor)
413  {
414  }
415 
416  /** \brief Destructor. */
418 
419  protected:
420  // Members derived from the base class
424  };
425 
426  }
427 }
428 
429 #include <pcl/io/impl/point_cloud_image_extractors.hpp>
430 
431 #endif //#ifndef PCL_POINT_CLOUD_IMAGE_EXTRACTORS_H_
Image Extractor which uses the data present in the "rgb" or "rgba" fields to produce a color image wi...
PointCloudImageExtractorFromCurvatureField(const float scaling_factor)
Constructor.
PointCloudImageExtractorFromIntensityField(const ScalingMethod scaling_method=PointCloudImageExtractorWithScaling< PointT >::SCALING_NO)
Constructor.
boost::shared_ptr< const PointCloudImageExtractorFromZField< PointT > > ConstPtr
PointCloudImageExtractorFromLabelField(const ColorMode color_mode=COLORS_MONO)
Constructor.
Image Extractor which uses the data present in the "intensity" field to produce a monochrome intensit...
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &img) const
Obtain the label image from the given cloud.
boost::shared_ptr< const PointCloudImageExtractorFromRGBField< PointT > > ConstPtr
boost::shared_ptr< PointCloudImageExtractorFromNormalField< PointT > > Ptr
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &image) const =0
Obtain the image from the given cloud.
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &img) const
Obtain the color image from the given cloud.
Image Extractor which uses the data present in the "curvature" field to produce a curvature map (as a...
boost::shared_ptr< const PointCloudImageExtractorWithScaling< PointT > > ConstPtr
Image Extractor which uses the data present in the "normal" field.
void setScalingFactor(const float scaling_factor)
Set fixed scaling factor.
boost::shared_ptr< PointCloudImageExtractorFromIntensityField< PointT > > Ptr
boost::shared_ptr< PointCloudImageExtractor< PointT > > Ptr
boost::shared_ptr< const PointCloudImageExtractorFromNormalField< PointT > > ConstPtr
boost::shared_ptr< const PointCloudImageExtractorFromIntensityField< PointT > > ConstPtr
PointCloudImageExtractorFromZField(const ScalingMethod scaling_method)
Constructor.
boost::shared_ptr< PointCloudImageExtractorFromRGBField< PointT > > Ptr
PointCloudImageExtractorFromZField(const float scaling_factor=10000)
Constructor.
PointCloudImageExtractorWithScaling(const std::string &field_name, const ScalingMethod scaling_method)
Constructor.
Base Image Extractor class for organized point clouds.
void setColorMode(const ColorMode color_mode)
Set color mapping mode.
PointCloudImageExtractorFromCurvatureField(const ScalingMethod scaling_method=PointCloudImageExtractorWithScaling< PointT >::SCALING_FULL_RANGE)
Constructor.
boost::shared_ptr< const PointCloudImageExtractorFromLabelField< PointT > > ConstPtr
boost::shared_ptr< const PointCloudImageExtractor< PointT > > ConstPtr
Image Extractor which uses the data present in the "label" field to produce either monochrome or RGB ...
void setScalingMethod(const ScalingMethod scaling_method)
Set scaling method.
boost::shared_ptr< PointCloudImageExtractorFromCurvatureField< PointT > > Ptr
PointCloudImageExtractorFromIntensityField(const float scaling_factor)
Constructor.
boost::shared_ptr< PointCloudImageExtractorFromZField< PointT > > Ptr
Image Extractor which uses the data present in the "z" field to produce a depth map (as a monochrome ...
boost::shared_ptr< PointCloudImageExtractorFromLabelField< PointT > > Ptr
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &img) const
Obtain the color image from the given cloud.
PointCloudImageExtractorWithScaling(const std::string &field_name, const float scaling_factor)
Constructor.
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &image) const
Obtain the image from the given cloud.
boost::shared_ptr< PointCloudImageExtractorWithScaling< PointT > > Ptr
boost::shared_ptr< const PointCloudImageExtractorFromCurvatureField< PointT > > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.
Image Extractor extension which provides functionality to apply scaling to the values extracted from ...