Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
segmentation
extract_labeled_clusters.h
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Copyright (c) 2011, Willow Garage, Inc.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above
14
* copyright notice, this list of conditions and the following
15
* disclaimer in the documentation and/or other materials provided
16
* with the distribution.
17
* * Neither the name of the copyright holder(s) nor the names of its
18
* contributors may be used to endorse or promote products derived
19
* from this software without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
* POSSIBILITY OF SUCH DAMAGE.
33
*
34
*/
35
36
#pragma once
37
38
#include <pcl/search/search.h>
39
#include <pcl/pcl_base.h>
40
41
namespace
pcl
{
42
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43
/** \brief Decompose a region of space into clusters based on the Euclidean distance
44
* between points
45
* \param[in] cloud the point cloud message
46
* \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors
47
* searching \note the tree has to be created as a spatial locator on \a cloud
48
* \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
49
* \param[out] labeled_clusters the resultant clusters containing point indices
50
* (as a vector of PointIndices)
51
* \param[in] min_pts_per_cluster minimum number of points that a cluster may contain
52
* (default: 1)
53
* \param[in] max_pts_per_cluster maximum number of points that a cluster may contain
54
* (default: max int)
55
* \ingroup segmentation
56
*/
57
template
<
typename
Po
int
T>
58
void
59
extractLabeledEuclideanClusters
(
60
const
PointCloud<PointT>
& cloud,
61
const
typename
search::Search<PointT>::Ptr
& tree,
62
float
tolerance,
63
std::vector<std::vector<PointIndices>>& labeled_clusters,
64
unsigned
int
min_pts_per_cluster = 1,
65
unsigned
int
max_pts_per_cluster = std::numeric_limits<unsigned int>::max());
66
67
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
70
/** \brief @b LabeledEuclideanClusterExtraction represents a segmentation class for
71
* cluster extraction in an Euclidean sense, with label info. \author Koen Buys
72
* \ingroup segmentation
73
*/
74
template
<
typename
Po
int
T>
75
class
LabeledEuclideanClusterExtraction
:
public
PCLBase
<PointT> {
76
using
BasePCLBase =
PCLBase<PointT>
;
77
78
public
:
79
using
PointCloud
=
pcl::PointCloud<PointT>
;
80
using
PointCloudPtr
=
typename
PointCloud::Ptr
;
81
using
PointCloudConstPtr
=
typename
PointCloud::ConstPtr
;
82
83
using
KdTree
=
pcl::search::Search<PointT>
;
84
using
KdTreePtr
=
typename
KdTree::Ptr
;
85
86
using
PointIndicesPtr
=
PointIndices::Ptr
;
87
using
PointIndicesConstPtr
=
PointIndices::ConstPtr
;
88
89
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90
/** \brief Empty constructor. */
91
LabeledEuclideanClusterExtraction
() =
default
;
92
93
/** \brief Provide a pointer to the search object.
94
* \param[in] tree a pointer to the spatial search object.
95
*/
96
inline
void
97
setSearchMethod
(
const
KdTreePtr
& tree)
98
{
99
tree_
= tree;
100
}
101
102
/** \brief Get a pointer to the search method used. */
103
inline
KdTreePtr
104
getSearchMethod
()
const
105
{
106
return
(
tree_
);
107
}
108
109
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
110
* \param[in] tolerance the spatial cluster tolerance as a measure in the L2 Euclidean
111
* space
112
*/
113
inline
void
114
setClusterTolerance
(
double
tolerance)
115
{
116
cluster_tolerance_
= tolerance;
117
}
118
119
/** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
120
*/
121
inline
double
122
getClusterTolerance
()
const
123
{
124
return
(
cluster_tolerance_
);
125
}
126
127
/** \brief Set the minimum number of points that a cluster needs to contain in order
128
* to be considered valid. \param[in] min_cluster_size the minimum cluster size
129
*/
130
inline
void
131
setMinClusterSize
(
int
min_cluster_size)
132
{
133
min_pts_per_cluster_
= min_cluster_size;
134
}
135
136
/** \brief Get the minimum number of points that a cluster needs to contain in order
137
* to be considered valid. */
138
inline
int
139
getMinClusterSize
()
const
140
{
141
return
(
min_pts_per_cluster_
);
142
}
143
144
/** \brief Set the maximum number of points that a cluster needs to contain in order
145
* to be considered valid. \param[in] max_cluster_size the maximum cluster size
146
*/
147
inline
void
148
setMaxClusterSize
(
int
max_cluster_size)
149
{
150
max_pts_per_cluster_
= max_cluster_size;
151
}
152
153
/** \brief Get the maximum number of points that a cluster needs to contain in order
154
* to be considered valid. */
155
inline
int
156
getMaxClusterSize
()
const
157
{
158
return
(
max_pts_per_cluster_
);
159
}
160
161
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices
162
* ()> \param[out] labeled_clusters the resultant point clusters
163
*/
164
void
165
extract
(std::vector<std::vector<PointIndices>>& labeled_clusters);
166
167
protected
:
168
// Members derived from the base class
169
using
BasePCLBase::deinitCompute
;
170
using
BasePCLBase::indices_
;
171
using
BasePCLBase::initCompute
;
172
using
BasePCLBase::input_
;
173
174
/** \brief A pointer to the spatial search object. */
175
KdTreePtr
tree_
{
nullptr
};
176
177
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
178
double
cluster_tolerance_
{0.0};
179
180
/** \brief The minimum number of points that a cluster needs to contain in order to be
181
* considered valid (default = 1). */
182
int
min_pts_per_cluster_
{1};
183
184
/** \brief The maximum number of points that a cluster needs to contain in order to be
185
* considered valid (default = MAXINT). */
186
int
max_pts_per_cluster_
{std::numeric_limits<int>::max()};
187
188
/** \brief The maximum number of labels we can find in this pointcloud (default =
189
* MAXINT)*/
190
PCL_DEPRECATED
(1, 18,
"this member variable is unused"
)
191
unsigned
int
max_label_
{std::numeric_limits<unsigned int>::max()};
192
193
/** \brief Class getName method. */
194
virtual
std::string
195
getClassName
()
const
196
{
197
return
(
"LabeledEuclideanClusterExtraction"
);
198
}
199
};
200
201
/** \brief Sort clusters method (for std::sort).
202
* \ingroup segmentation
203
*/
204
inline
bool
205
compareLabeledPointClusters
(
const
pcl::PointIndices
& a,
const
pcl::PointIndices
& b)
206
{
207
return
(a.
indices
.size() < b.
indices
.size());
208
}
209
}
// namespace pcl
210
211
#ifdef PCL_NO_PRECOMPILE
212
#include <pcl/segmentation/impl/extract_labeled_clusters.hpp>
213
#endif
pcl::LabeledEuclideanClusterExtraction::max_label_
unsigned int max_label_
The maximum number of labels we can find in this pointcloud (default = MAXINT).
Definition
extract_labeled_clusters.h:191
pcl::LabeledEuclideanClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
extract_labeled_clusters.h:114
pcl::LabeledEuclideanClusterExtraction::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition
extract_labeled_clusters.h:175
pcl::LabeledEuclideanClusterExtraction::cluster_tolerance_
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
extract_labeled_clusters.h:178
pcl::LabeledEuclideanClusterExtraction::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition
extract_labeled_clusters.h:84
pcl::LabeledEuclideanClusterExtraction::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition
extract_labeled_clusters.h:81
pcl::LabeledEuclideanClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition
extract_labeled_clusters.h:87
pcl::LabeledEuclideanClusterExtraction::setMinClusterSize
void setMinClusterSize(int min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition
extract_labeled_clusters.h:131
pcl::LabeledEuclideanClusterExtraction::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition
extract_labeled_clusters.h:79
pcl::LabeledEuclideanClusterExtraction::extract
void extract(std::vector< std::vector< PointIndices > > &labeled_clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>.
Definition
extract_labeled_clusters.hpp:129
pcl::LabeledEuclideanClusterExtraction::getMaxClusterSize
int getMaxClusterSize() const
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition
extract_labeled_clusters.h:156
pcl::LabeledEuclideanClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition
extract_labeled_clusters.h:86
pcl::LabeledEuclideanClusterExtraction::min_pts_per_cluster_
int min_pts_per_cluster_
The minimum number of points that a cluster needs to contain in order to be considered valid (default...
Definition
extract_labeled_clusters.h:182
pcl::LabeledEuclideanClusterExtraction::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition
extract_labeled_clusters.h:80
pcl::LabeledEuclideanClusterExtraction::getClusterTolerance
double getClusterTolerance() const
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
extract_labeled_clusters.h:122
pcl::LabeledEuclideanClusterExtraction::KdTree
pcl::search::Search< PointT > KdTree
Definition
extract_labeled_clusters.h:83
pcl::LabeledEuclideanClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition
extract_labeled_clusters.h:195
pcl::LabeledEuclideanClusterExtraction::getSearchMethod
KdTreePtr getSearchMethod() const
Get a pointer to the search method used.
Definition
extract_labeled_clusters.h:104
pcl::LabeledEuclideanClusterExtraction::getMinClusterSize
int getMinClusterSize() const
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition
extract_labeled_clusters.h:139
pcl::LabeledEuclideanClusterExtraction::max_pts_per_cluster_
int max_pts_per_cluster_
The maximum number of points that a cluster needs to contain in order to be considered valid (default...
Definition
extract_labeled_clusters.h:186
pcl::LabeledEuclideanClusterExtraction::setMaxClusterSize
void setMaxClusterSize(int max_cluster_size)
Set the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition
extract_labeled_clusters.h:148
pcl::LabeledEuclideanClusterExtraction::LabeledEuclideanClusterExtraction
LabeledEuclideanClusterExtraction()=default
Empty constructor.
pcl::LabeledEuclideanClusterExtraction::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition
extract_labeled_clusters.h:97
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::PCLBase
PCLBase()
Empty constructor.
Definition
pcl_base.hpp:46
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::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition
point_cloud.h:415
pcl::search::Search
Generic search class.
Definition
search.h:75
pcl::search::Search::Ptr
shared_ptr< pcl::search::Search< PointT > > Ptr
Definition
search.h:81
pcl::extractLabeledEuclideanClusters
void extractLabeledEuclideanClusters(const PointCloud< PointT > &cloud, const typename search::Search< PointT >::Ptr &tree, float tolerance, std::vector< std::vector< PointIndices > > &labeled_clusters, unsigned int min_pts_per_cluster=1, unsigned int max_pts_per_cluster=std::numeric_limits< unsigned int >::max())
Decompose a region of space into clusters based on the Euclidean distance between points.
Definition
extract_labeled_clusters.hpp:45
pcl::compareLabeledPointClusters
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
Definition
extract_labeled_clusters.h:205
pcl
Definition
convolution.h:46
PCL_DEPRECATED
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major....
Definition
pcl_macros.h:158
pcl::PointIndices
Definition
PointIndices.h:12
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition
PointIndices.h:13
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition
PointIndices.h:14
pcl::PointIndices::indices
Indices indices
Definition
PointIndices.h:20