Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
segmentation
impl
progressive_morphological_filter.hpp
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
#ifndef PCL_SEGMENTATION_PROGRESSIVE_MORPHOLOGICAL_FILTER_HPP_
40
#define PCL_SEGMENTATION_PROGRESSIVE_MORPHOLOGICAL_FILTER_HPP_
41
42
#include <
pcl/common/common.h
>
43
#include <pcl/common/io.h>
44
#include <pcl/filters/morphological_filter.h>
45
#include <pcl/segmentation/progressive_morphological_filter.h>
46
#include <pcl/point_cloud.h>
47
#include <
pcl/point_types.h
>
48
49
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50
template
<
typename
Po
int
T>
51
pcl::ProgressiveMorphologicalFilter<PointT>::ProgressiveMorphologicalFilter
() =
default
;
52
53
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54
template
<
typename
Po
int
T>
55
pcl::ProgressiveMorphologicalFilter<PointT>::~ProgressiveMorphologicalFilter
() =
default
;
56
57
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
template
<
typename
Po
int
T>
void
59
pcl::ProgressiveMorphologicalFilter<PointT>::extract
(
Indices
& ground)
60
{
61
bool
segmentation_is_possible =
initCompute
();
62
if
(!segmentation_is_possible)
63
{
64
deinitCompute
();
65
return
;
66
}
67
68
// Compute the series of window sizes and height thresholds
69
std::vector<float> height_thresholds;
70
std::vector<float> window_sizes;
71
int
iteration = 0;
72
float
window_size = 0.0f;
73
float
height_threshold = 0.0f;
74
75
while
(window_size <
max_window_size_
)
76
{
77
// Determine the initial window size.
78
if
(
exponential_
)
79
window_size =
cell_size_
* (2.0f * std::pow (
base_
, iteration) + 1.0f);
80
else
81
window_size =
cell_size_
* (2.0f * (iteration+1) *
base_
+ 1.0f);
82
83
// Calculate the height threshold to be used in the next iteration.
84
if
(iteration == 0)
85
height_threshold =
initial_distance_
;
86
else
87
height_threshold =
slope_
* (window_size - window_sizes[iteration-1]) *
cell_size_
+
initial_distance_
;
88
89
// Enforce max distance on height threshold
90
if
(height_threshold >
max_distance_
)
91
height_threshold =
max_distance_
;
92
93
window_sizes.push_back (window_size);
94
height_thresholds.push_back (height_threshold);
95
96
iteration++;
97
}
98
99
// Ground indices are initially limited to those points in the input cloud we
100
// wish to process
101
ground = *
indices_
;
102
103
// Progressively filter ground returns using morphological open
104
for
(std::size_t i = 0; i < window_sizes.size (); ++i)
105
{
106
PCL_DEBUG (
" Iteration %d (height threshold = %f, window size = %f)..."
,
107
i, height_thresholds[i], window_sizes[i]);
108
109
// Limit filtering to those points currently considered ground returns
110
typename
pcl::PointCloud<PointT>::Ptr
cloud (
new
pcl::PointCloud<PointT>
);
111
pcl::copyPointCloud<PointT>
(*
input_
, ground, *cloud);
112
113
// Create new cloud to hold the filtered results. Apply the morphological
114
// opening operation at the current window size.
115
typename
pcl::PointCloud<PointT>::Ptr
cloud_f (
new
pcl::PointCloud<PointT>
);
116
pcl::applyMorphologicalOperator<PointT>
(cloud, window_sizes[i],
MORPH_OPEN
, *cloud_f);
117
118
// Find indices of the points whose difference between the source and
119
// filtered point clouds is less than the current height threshold.
120
Indices
pt_indices;
121
for
(std::size_t p_idx = 0; p_idx < ground.size (); ++p_idx)
122
{
123
float
diff = (*cloud)[p_idx].z - (*cloud_f)[p_idx].z;
124
if
(diff < height_thresholds[i])
125
pt_indices.push_back (ground[p_idx]);
126
}
127
128
// Ground is now limited to pt_indices
129
ground.swap (pt_indices);
130
131
PCL_DEBUG (
"ground now has %d points\n"
, ground.size ());
132
}
133
134
deinitCompute
();
135
}
136
137
#define PCL_INSTANTIATE_ProgressiveMorphologicalFilter(T) template class PCL_EXPORTS pcl::ProgressiveMorphologicalFilter<T>;
138
139
#endif
// PCL_SEGMENTATION_PROGRESSIVE_MORPHOLOGICAL_FILTER_HPP_
140
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition
pcl_base.h:147
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition
pcl_base.h:150
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition
pcl_base.hpp:138
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition
pcl_base.hpp:175
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition
point_cloud.h:174
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition
point_cloud.h:414
pcl::ProgressiveMorphologicalFilter::extract
virtual void extract(Indices &ground)
This method launches the segmentation algorithm and returns indices of points determined to be ground...
Definition
progressive_morphological_filter.hpp:59
pcl::ProgressiveMorphologicalFilter::slope_
float slope_
Slope value to be used in computing the height threshold.
Definition
progressive_morphological_filter.h:143
pcl::ProgressiveMorphologicalFilter::base_
float base_
Base to be used in computing progressive window sizes.
Definition
progressive_morphological_filter.h:155
pcl::ProgressiveMorphologicalFilter::max_distance_
float max_distance_
Maximum height above the parameterized ground surface to be considered a ground return.
Definition
progressive_morphological_filter.h:146
pcl::ProgressiveMorphologicalFilter::initial_distance_
float initial_distance_
Initial height above the parameterized ground surface to be considered a ground return.
Definition
progressive_morphological_filter.h:149
pcl::ProgressiveMorphologicalFilter::exponential_
bool exponential_
Exponentially grow window sizes?
Definition
progressive_morphological_filter.h:158
pcl::ProgressiveMorphologicalFilter::ProgressiveMorphologicalFilter
ProgressiveMorphologicalFilter()
Constructor that sets default values for member variables.
pcl::ProgressiveMorphologicalFilter::max_window_size_
int max_window_size_
Maximum window size to be used in filtering ground returns.
Definition
progressive_morphological_filter.h:140
pcl::ProgressiveMorphologicalFilter::~ProgressiveMorphologicalFilter
~ProgressiveMorphologicalFilter() override
pcl::ProgressiveMorphologicalFilter::cell_size_
float cell_size_
Cell size.
Definition
progressive_morphological_filter.h:152
common.h
Define standard C methods and C++ classes that are common to all methods.
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl::copyPointCloud
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
Definition
io.hpp:142
pcl::applyMorphologicalOperator
void applyMorphologicalOperator(const typename pcl::PointCloud< PointT >::ConstPtr &cloud_in, float resolution, const int morphological_operator, pcl::PointCloud< PointT > &cloud_out)
Apply morphological operator to the z dimension of the input point cloud.
Definition
morphological_filter.hpp:57
pcl::MORPH_OPEN
@ MORPH_OPEN
Definition
morphological_filter.h:51
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition
types.h:133