Point Cloud Library (PCL) 1.14.0
Loading...
Searching...
No Matches
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
38#pragma once
39
40#include <pcl/point_cloud.h>
41#include <pcl/PCLImage.h>
42
43namespace 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 using Ptr = shared_ptr<PointCloudImageExtractor<PointT> >;
84 using ConstPtr = shared_ptr<const PointCloudImageExtractor<PointT> >;
85
86 /** \brief Constructor. */
88
89 /** \brief Destructor. */
90 virtual ~PointCloudImageExtractor () = default;
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 bool
98 extract (const PointCloud& cloud, pcl::PCLImage& image) const;
99
100 /** \brief Set a flag that controls if image pixels corresponding to
101 * NaN (infinite) points should be painted black.
102 */
103 inline void
105 {
107 }
108
109 protected:
110
111 /** \brief Implementation of the extract() function, has to be
112 * implemented in deriving classes.
113 */
114 virtual bool
115 extractImpl (const PointCloud& cloud, pcl::PCLImage& image) const = 0;
116
117 /// A flag that controls if image pixels corresponding to NaN (infinite)
118 /// points should be painted black.
120 };
121
122 //////////////////////////////////////////////////////////////////////////////////////
123 /** \brief Image Extractor extension which provides functionality to apply scaling to
124 * the values extracted from a field.
125 * \author Sergey Alexandrov
126 * \ingroup io
127 */
128 template <typename PointT>
130 {
131 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
132
133 public:
134 using Ptr = shared_ptr<PointCloudImageExtractorWithScaling<PointT> >;
135 using ConstPtr = shared_ptr<const PointCloudImageExtractorWithScaling<PointT> >;
136
137 /** \brief Different scaling methods.
138 * <ul>
139 * <li><b>SCALING_NO</b> - no scaling.</li>
140 * <li><b>SCALING_FULL_RANGE</b> - scales to full range of the output value.</li>
141 * <li><b>SCASING_FIXED_FACTOR</b> - scales by a given fixed factor.</li>
142 * </ul>
143 */
150
151 /** \brief Constructor. */
152 PointCloudImageExtractorWithScaling (const std::string& field_name, const ScalingMethod scaling_method)
153 : field_name_ (field_name)
154 , scaling_method_ (scaling_method)
155 , scaling_factor_ (1.0f)
156 {
157 }
158
159 /** \brief Constructor. */
160 PointCloudImageExtractorWithScaling (const std::string& field_name, const float scaling_factor)
161 : field_name_ (field_name)
163 , scaling_factor_ (scaling_factor)
164 {
165 }
166
167 /** \brief Destructor. */
169
170 /** \brief Set scaling method. */
171 inline void
172 setScalingMethod (const ScalingMethod scaling_method)
173 {
174 scaling_method_ = scaling_method;
175 }
176
177 /** \brief Set fixed scaling factor. */
178 inline void
179 setScalingFactor (const float scaling_factor)
180 {
181 scaling_factor_ = scaling_factor;
182 }
183
184 protected:
185
186 bool
187 extractImpl (const PointCloud& cloud, pcl::PCLImage& image) const override;
188
189 std::string field_name_;
192 };
193
194 //////////////////////////////////////////////////////////////////////////////////////
195 /** \brief Image Extractor which uses the data present in the "normal" field. Normal
196 * vector components (x, y, z) are mapped to color channels (r, g, b respectively).
197 * \author Sergey Alexandrov
198 * \ingroup io
199 */
200 template <typename PointT>
202 {
203 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
204
205 public:
206 using Ptr = shared_ptr<PointCloudImageExtractorFromNormalField<PointT> >;
207 using ConstPtr = shared_ptr<const PointCloudImageExtractorFromNormalField<PointT> >;
208
209 /** \brief Constructor. */
211
212 /** \brief Destructor. */
214
215 protected:
216
217 bool
218 extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const override;
219 };
220
221 //////////////////////////////////////////////////////////////////////////////////////
222 /** \brief Image Extractor which uses the data present in the "rgb" or "rgba" fields
223 * to produce a color image with rgb8 encoding.
224 * \author Sergey Alexandrov
225 * \ingroup io
226 */
227 template <typename PointT>
229 {
230 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
231
232 public:
233 using Ptr = shared_ptr<PointCloudImageExtractorFromRGBField<PointT> >;
234 using ConstPtr = shared_ptr<const PointCloudImageExtractorFromRGBField<PointT> >;
235
236 /** \brief Constructor. */
238
239 /** \brief Destructor. */
241
242 protected:
243
244 bool
245 extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const override;
246 };
247
248 //////////////////////////////////////////////////////////////////////////////////////
249 /** \brief Image Extractor which uses the data present in the "label" field to produce
250 * either monochrome or RGB image where different labels correspond to different
251 * colors.
252 * See the documentation for ColorMode to learn about available coloring options.
253 * \author Sergey Alexandrov
254 * \ingroup io
255 */
256 template <typename PointT>
258 {
259 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
260
261 public:
262 using Ptr = shared_ptr<PointCloudImageExtractorFromLabelField<PointT> >;
263 using ConstPtr = shared_ptr<const PointCloudImageExtractorFromLabelField<PointT> >;
264
265 /** \brief Different modes for color mapping. */
267 {
268 /// Shades of gray (according to label id)
269 /// \note Labels using more than 16 bits will cause problems
271 /// Randomly generated RGB colors
273 /// Fixed RGB colors from the [Glasbey lookup table](http://fiji.sc/Glasbey),
274 /// assigned in the ascending order of label id
276 };
277
278 /** \brief Constructor. */
280 : color_mode_ (color_mode)
281 {
282 }
283
284 /** \brief Destructor. */
286
287 /** \brief Set color mapping mode. */
288 inline void
289 setColorMode (const ColorMode color_mode)
290 {
291 color_mode_ = color_mode;
292 }
293
294 protected:
295
296 bool
297 extractImpl (const PointCloud& cloud, pcl::PCLImage& img) const override;
298
299 // Members derived from the base class
301
302 private:
303
304 ColorMode color_mode_{COLORS_MONO};
305 };
306
307 //////////////////////////////////////////////////////////////////////////////////////
308 /** \brief Image Extractor which uses the data present in the "z" field to produce a
309 * depth map (as a monochrome image with mono16 encoding).
310 * \author Sergey Alexandrov
311 * \ingroup io
312 */
313 template <typename PointT>
315 {
316 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
318
319 public:
320 using Ptr = shared_ptr<PointCloudImageExtractorFromZField<PointT> >;
321 using ConstPtr = shared_ptr<const PointCloudImageExtractorFromZField<PointT> >;
322
323 /** \brief Constructor.
324 * \param[in] scaling_factor a scaling factor to apply to each depth value (default 10000)
325 */
326 PointCloudImageExtractorFromZField (const float scaling_factor = 10000)
327 : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_factor)
328 {
329 }
330
331 /** \brief Constructor.
332 * \param[in] scaling_method a scaling method to use
333 */
334 PointCloudImageExtractorFromZField (const ScalingMethod scaling_method)
335 : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_method)
336 {
337 }
338
339 /** \brief Destructor. */
341
342 protected:
343 // Members derived from the base class
347 };
348
349 //////////////////////////////////////////////////////////////////////////////////////
350 /** \brief Image Extractor which uses the data present in the "curvature" field to
351 * produce a curvature map (as a monochrome image with mono16 encoding).
352 * \author Sergey Alexandrov
353 * \ingroup io
354 */
355 template <typename PointT>
357 {
358 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
360
361 public:
362 using Ptr = shared_ptr<PointCloudImageExtractorFromCurvatureField<PointT> >;
363 using ConstPtr = shared_ptr<const PointCloudImageExtractorFromCurvatureField<PointT> >;
364
365 /** \brief Constructor.
366 * \param[in] scaling_method a scaling method to use (default SCALING_FULL_RANGE)
367 */
372
373 /** \brief Constructor.
374 * \param[in] scaling_factor a scaling factor to apply to each curvature value
375 */
377 : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_factor)
378 {
379 }
380
381 /** \brief Destructor. */
383
384 protected:
385 // Members derived from the base class
389 };
390
391 //////////////////////////////////////////////////////////////////////////////////////
392 /** \brief Image Extractor which uses the data present in the "intensity" field to produce a
393 * monochrome intensity image (with mono16 encoding).
394 * \author Sergey Alexandrov
395 * \ingroup io
396 */
397 template <typename PointT>
399 {
400 using PointCloud = typename PointCloudImageExtractor<PointT>::PointCloud;
402
403 public:
404 using Ptr = shared_ptr<PointCloudImageExtractorFromIntensityField<PointT> >;
405 using ConstPtr = shared_ptr<const PointCloudImageExtractorFromIntensityField<PointT> >;
406
407 /** \brief Constructor.
408 * \param[in] scaling_method a scaling method to use (default SCALING_NO)
409 */
414
415 /** \brief Constructor.
416 * \param[in] scaling_factor a scaling factor to apply to each intensity value
417 */
419 : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_factor)
420 {
421 }
422
423 /** \brief Destructor. */
425
426 protected:
427 // Members derived from the base class
431 };
432
433 }
434}
435
436#include <pcl/io/impl/point_cloud_image_extractors.hpp>
PointCloud represents the base class in PCL for storing collections of 3D points.
Image Extractor which uses the data present in the "curvature" field to produce a curvature map (as a...
shared_ptr< const PointCloudImageExtractorFromCurvatureField< PointT > > ConstPtr
PointCloudImageExtractorFromCurvatureField(const float scaling_factor)
Constructor.
~PointCloudImageExtractorFromCurvatureField() override=default
Destructor.
shared_ptr< PointCloudImageExtractorFromCurvatureField< PointT > > Ptr
PointCloudImageExtractorFromCurvatureField(const ScalingMethod scaling_method=PointCloudImageExtractorWithScaling< PointT >::SCALING_FULL_RANGE)
Constructor.
Image Extractor which uses the data present in the "intensity" field to produce a monochrome intensit...
PointCloudImageExtractorFromIntensityField(const float scaling_factor)
Constructor.
PointCloudImageExtractorFromIntensityField(const ScalingMethod scaling_method=PointCloudImageExtractorWithScaling< PointT >::SCALING_NO)
Constructor.
shared_ptr< const PointCloudImageExtractorFromIntensityField< PointT > > ConstPtr
shared_ptr< PointCloudImageExtractorFromIntensityField< PointT > > Ptr
~PointCloudImageExtractorFromIntensityField() override=default
Destructor.
Image Extractor which uses the data present in the "label" field to produce either monochrome or RGB ...
@ COLORS_RGB_GLASBEY
Fixed RGB colors from the Glasbey lookup table, assigned in the ascending order of label id.
shared_ptr< const PointCloudImageExtractorFromLabelField< PointT > > ConstPtr
void setColorMode(const ColorMode color_mode)
Set color mapping mode.
PointCloudImageExtractorFromLabelField(const ColorMode color_mode=COLORS_MONO)
Constructor.
~PointCloudImageExtractorFromLabelField() override=default
Destructor.
bool extractImpl(const PointCloud &cloud, pcl::PCLImage &img) const override
Implementation of the extract() function, has to be implemented in deriving classes.
shared_ptr< PointCloudImageExtractorFromLabelField< PointT > > Ptr
Image Extractor which uses the data present in the "normal" field.
shared_ptr< const PointCloudImageExtractorFromNormalField< PointT > > ConstPtr
shared_ptr< PointCloudImageExtractorFromNormalField< PointT > > Ptr
~PointCloudImageExtractorFromNormalField() override=default
Destructor.
bool extractImpl(const PointCloud &cloud, pcl::PCLImage &img) const override
Implementation of the extract() function, has to be implemented in deriving classes.
PointCloudImageExtractorFromNormalField()=default
Constructor.
Image Extractor which uses the data present in the "rgb" or "rgba" fields to produce a color image wi...
shared_ptr< const PointCloudImageExtractorFromRGBField< PointT > > ConstPtr
shared_ptr< PointCloudImageExtractorFromRGBField< PointT > > Ptr
bool extractImpl(const PointCloud &cloud, pcl::PCLImage &img) const override
Implementation of the extract() function, has to be implemented in deriving classes.
PointCloudImageExtractorFromRGBField()=default
Constructor.
~PointCloudImageExtractorFromRGBField() override=default
Destructor.
Image Extractor which uses the data present in the "z" field to produce a depth map (as a monochrome ...
shared_ptr< const PointCloudImageExtractorFromZField< PointT > > ConstPtr
~PointCloudImageExtractorFromZField() override=default
Destructor.
PointCloudImageExtractorFromZField(const float scaling_factor=10000)
Constructor.
shared_ptr< PointCloudImageExtractorFromZField< PointT > > Ptr
PointCloudImageExtractorFromZField(const ScalingMethod scaling_method)
Constructor.
Base Image Extractor class for organized point clouds.
shared_ptr< PointCloudImageExtractor< PointT > > Ptr
virtual bool extractImpl(const PointCloud &cloud, pcl::PCLImage &image) const =0
Implementation of the extract() function, has to be implemented in deriving classes.
bool extract(const PointCloud &cloud, pcl::PCLImage &image) const
Obtain the image from the given cloud.
shared_ptr< const PointCloudImageExtractor< PointT > > ConstPtr
void setPaintNaNsWithBlack(bool flag)
Set a flag that controls if image pixels corresponding to NaN (infinite) points should be painted bla...
bool paint_nans_with_black_
A flag that controls if image pixels corresponding to NaN (infinite) points should be painted black.
virtual ~PointCloudImageExtractor()=default
Destructor.
PointCloudImageExtractor()=default
Constructor.
Image Extractor extension which provides functionality to apply scaling to the values extracted from ...
~PointCloudImageExtractorWithScaling() override=default
Destructor.
shared_ptr< const PointCloudImageExtractorWithScaling< PointT > > ConstPtr
void setScalingMethod(const ScalingMethod scaling_method)
Set scaling method.
bool extractImpl(const PointCloud &cloud, pcl::PCLImage &image) const override
Implementation of the extract() function, has to be implemented in deriving classes.
shared_ptr< PointCloudImageExtractorWithScaling< PointT > > Ptr
void setScalingFactor(const float scaling_factor)
Set fixed scaling factor.
PointCloudImageExtractorWithScaling(const std::string &field_name, const float scaling_factor)
Constructor.
PointCloudImageExtractorWithScaling(const std::string &field_name, const ScalingMethod scaling_method)
Constructor.
A point structure representing Euclidean xyz coordinates, and the RGB color.