Point Cloud Library (PCL) 1.12.0
pyramid.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2012-, Open Perception.
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 * $Id$
37 *
38 */
39
40#pragma once
41
42#include <pcl/memory.h>
43#include <pcl/pcl_macros.h>
44#include <pcl/point_cloud.h>
45#include <pcl/pcl_config.h>
46
47namespace pcl
48{
49 namespace filters
50 {
51 /** Pyramid constructs a multi-scale representation of an organised point cloud.
52 * It is an iterative smoothing subsampling algorithm.
53 * The subsampling is fixed to 2. Two smoothing kernels may be used:
54 * - [1/16 1/4 3/8 1/4 1/16] slower but produces finer result;
55 * - [1/4 1/2 1/2] the more conventional binomial kernel which is faster.
56 * We use a memory efficient algorithm so the convolving and subsampling are combined in a
57 * single step.
58 *
59 * \author Nizar Sallem
60 */
61 template <typename PointT>
62 class Pyramid
63 {
64 public:
67 using Ptr = shared_ptr< Pyramid<PointT> >;
68 using ConstPtr = shared_ptr< const Pyramid<PointT> >;
69
70 Pyramid (int levels = 4)
71 : levels_ (levels)
72 , large_ (false)
73 , threshold_ (0.01)
74 , threads_ (0)
75 {
76 name_ = "Pyramid";
77 }
78
79 /** \brief Provide a pointer to the input dataset
80 * \param cloud the const boost shared pointer to a PointCloud message
81 */
82 inline void
83 setInputCloud (const PointCloudConstPtr &cloud) { input_ = cloud; }
84
85 /** \brief Get a pointer to the input point cloud dataset. */
86 inline PointCloudConstPtr const
87 getInputCloud () { return (input_); }
88
89 /** \brief Set the number of pyramid levels
90 * \param levels desired number of pyramid levels
91 */
92 inline void
93 setNumberOfLevels (int levels) { levels_ = levels; }
94
95 /// \brief \return the number of pyramid levels
96 inline int
97 getNumberOfLevels () const { return (levels_); }
98
99 /** \brief Initialize the scheduler and set the number of threads to use.
100 * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic).
101 */
102 inline void
103 setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
104
105 /** \brief Choose a larger smoothing kernel for enhanced smoothing.
106 * \param large if true large smoothng kernel will be used.
107 */
108 inline void
109 setLargeSmoothingKernel (bool large) { large_ = large; }
110
111 /** Only points such us distance (center,point) < threshold are accounted for to prevent
112 * ghost points.
113 * Default value is 0.01, to disable set to std::numeric<float>::infinity ().
114 * \param[in] threshold maximum allowed distance between center and neighbor.
115 */
116 inline void
117 setDistanceThreshold (float threshold) { threshold_ = threshold; }
118
119 /// \return the distance threshold
120 inline float
121 getDistanceThreshold () const { return (threshold_); }
122
123 /** \brief compute the pyramid levels.
124 * \param[out] output the constructed pyramid. It is resized to the number of levels.
125 * \remark input_ is copied to output[0] for consistency reasons.
126 */
127 void
128 compute (std::vector<PointCloudPtr>& output);
129
130 inline const std::string&
131 getClassName () const { return (name_); }
132
133 private:
134
135 /// \brief init computation
136 bool
137 initCompute ();
138
139 /** \brief nullify a point
140 * \param[in][out] p point to nullify
141 */
142 inline void
143 nullify (PointT& p) const
144 {
145 p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN ();
146 }
147
148 /// \brief The input point cloud dataset.
149 PointCloudConstPtr input_;
150 /// \brief number of pyramid levels
151 int levels_;
152 /// \brief use large smoothing kernel
153 bool large_;
154 /// \brief filter name
155 std::string name_;
156 /// \brief smoothing kernel
157 Eigen::MatrixXf kernel_;
158 /// Threshold distance between adjacent points
159 float threshold_;
160 /// \brief number of threads
161 unsigned int threads_;
162
163 public:
165 };
166 }
167}
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
Pyramid constructs a multi-scale representation of an organised point cloud.
Definition: pyramid.h:63
int getNumberOfLevels() const
Definition: pyramid.h:97
void setNumberOfLevels(int levels)
Set the number of pyramid levels.
Definition: pyramid.h:93
void compute(std::vector< PointCloudPtr > &output)
compute the pyramid levels.
Definition: pyramid.hpp:98
float getDistanceThreshold() const
Definition: pyramid.h:121
Pyramid(int levels=4)
Definition: pyramid.h:70
typename PointCloud< PointT >::Ptr PointCloudPtr
Definition: pyramid.h:65
PointCloudConstPtr const getInputCloud()
Get a pointer to the input point cloud dataset.
Definition: pyramid.h:87
void setDistanceThreshold(float threshold)
Only points such us distance (center,point) < threshold are accounted for to prevent ghost points.
Definition: pyramid.h:117
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: pyramid.h:103
void setLargeSmoothingKernel(bool large)
Choose a larger smoothing kernel for enhanced smoothing.
Definition: pyramid.h:109
const std::string & getClassName() const
Definition: pyramid.h:131
void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pyramid.h:83
shared_ptr< const Pyramid< PointT > > ConstPtr
Definition: pyramid.h:68
shared_ptr< Pyramid< PointT > > Ptr
Definition: pyramid.h:67
typename PointCloud< PointT >::ConstPtr PointCloudConstPtr
Definition: pyramid.h:66
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.
A point structure representing Euclidean xyz coordinates, and the RGB color.