1 /*
2  * Software License Agreement (BSD License)
3  *
4  *  Point Cloud Library (PCL) - www.pointclouds.org
5  *  Copyright (c) 2009-2012, Willow Garage, Inc.
6  *  Copyright (c) 2012-, Open Perception, Inc.
7  *  Copyright (c) 2014, RadiantBlue Technologies, Inc.
8  *
9  *  All rights reserved.
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *   * Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *   * Redistributions in binary form must reproduce the above
18  *     copyright notice, this list of conditions and the following
19  *     disclaimer in the documentation and/or other materials provided
20  *     with the distribution.
21  *   * Neither the name of the copyright holder(s) nor the names of its
22  *     contributors may be used to endorse or promote products derived
23  *     from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  *  POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #pragma once
40 
41 #include <pcl/pcl_base.h>
42 #include <pcl/search/search.h>
43 #include <pcl/point_cloud.h>
44 #include <pcl/point_types.h>
45 
46 namespace pcl
47 {
48   /** \brief
49     * Implements the Progressive Morphological Filter for segmentation of ground points.
50     * Description can be found in the article
51     * "A Progressive Morphological Filter for Removing Nonground Measurements from
52     * Airborne LIDAR Data"
53     * by K. Zhang, S. Chen, D. Whitman, M. Shyu, J. Yan, and C. Zhang.
54     */
55   template <typename PointT>
56   class PCL_EXPORTS ApproximateProgressiveMorphologicalFilter : public pcl::PCLBase<PointT>
57   {
58     public:
59 
60       using PointCloud = pcl::PointCloud<PointT>;
61 
62       using PCLBase <PointT>::input_;
63       using PCLBase <PointT>::indices_;
64       using PCLBase <PointT>::initCompute;
65       using PCLBase <PointT>::deinitCompute;
66 
67     public:
68 
69       /** \brief Constructor that sets default values for member variables. */
70       ApproximateProgressiveMorphologicalFilter ();
71 
72 
73       ~ApproximateProgressiveMorphologicalFilter ();
74 
75       /** \brief Get the maximum window size to be used in filtering ground returns. */
76       inline int
getMaxWindowSize()77       getMaxWindowSize () const { return (max_window_size_); }
78 
79       /** \brief Set the maximum window size to be used in filtering ground returns. */
80       inline void
setMaxWindowSize(int max_window_size)81       setMaxWindowSize (int max_window_size) { max_window_size_ = max_window_size; }
82 
83       /** \brief Get the slope value to be used in computing the height threshold. */
84       inline float
getSlope()85       getSlope () const { return (slope_); }
86 
87       /** \brief Set the slope value to be used in computing the height threshold. */
88       inline void
setSlope(float slope)89       setSlope (float slope) { slope_ = slope; }
90 
91       /** \brief Get the maximum height above the parameterized ground surface to be considered a ground return. */
92       inline float
getMaxDistance()93       getMaxDistance () const { return (max_distance_); }
94 
95       /** \brief Set the maximum height above the parameterized ground surface to be considered a ground return. */
96       inline void
setMaxDistance(float max_distance)97       setMaxDistance (float max_distance) { max_distance_ = max_distance; }
98 
99       /** \brief Get the initial height above the parameterized ground surface to be considered a ground return. */
100       inline float
getInitialDistance()101       getInitialDistance () const { return (initial_distance_); }
102 
103       /** \brief Set the initial height above the parameterized ground surface to be considered a ground return. */
104       inline void
setInitialDistance(float initial_distance)105       setInitialDistance (float initial_distance) { initial_distance_ = initial_distance; }
106 
107       /** \brief Get the cell size. */
108       inline float
getCellSize()109       getCellSize () const { return (cell_size_); }
110 
111       /** \brief Set the cell size. */
112       inline void
setCellSize(float cell_size)113       setCellSize (float cell_size) { cell_size_ = cell_size; }
114 
115       /** \brief Get the base to be used in computing progressive window sizes. */
116       inline float
getBase()117       getBase () const { return (base_); }
118 
119       /** \brief Set the base to be used in computing progressive window sizes. */
120       inline void
setBase(float base)121       setBase (float base) { base_ = base; }
122 
123       /** \brief Get flag indicating whether or not to exponentially grow window sizes? */
124       inline bool
getExponential()125       getExponential () const { return (exponential_); }
126 
127       /** \brief Set flag indicating whether or not to exponentially grow window sizes? */
128       inline void
setExponential(bool exponential)129       setExponential (bool exponential) { exponential_ = exponential; }
130 
131       /** \brief Initialize the scheduler and set the number of threads to use.
132         * \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
133         */
134       inline void
135       setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
136 
137       /** \brief This method launches the segmentation algorithm and returns indices of
138         * points determined to be ground returns.
139         * \param[out] ground indices of points determined to be ground returns.
140         */
141       virtual void
142       extract (Indices& ground);
143 
144     protected:
145 
146       /** \brief Maximum window size to be used in filtering ground returns. */
147       int max_window_size_;
148 
149       /** \brief Slope value to be used in computing the height threshold. */
150       float slope_;
151 
152       /** \brief Maximum height above the parameterized ground surface to be considered a ground return. */
153       float max_distance_;
154 
155       /** \brief Initial height above the parameterized ground surface to be considered a ground return. */
156       float initial_distance_;
157 
158       /** \brief Cell size. */
159       float cell_size_;
160 
161       /** \brief Base to be used in computing progressive window sizes. */
162       float base_;
163 
164       /** \brief Exponentially grow window sizes? */
165       bool exponential_;
166 
167       /** \brief Number of threads to be used. */
168       unsigned int threads_;
169   };
170 }
171 
172 #ifdef PCL_NO_PRECOMPILE
173 #include <pcl/segmentation/impl/approximate_progressive_morphological_filter.hpp>
174 #endif
175