Point Cloud Library (PCL)
1.12.1-dev
segmentation
include
pcl
gpu
segmentation
gpu_extract_clusters.h
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Point Cloud Library (PCL) - www.pointclouds.org
5
* Copyright (c) 2010-2011, Willow Garage, 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 Willow Garage, Inc. 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
* @author: Koen Buys
38
*/
39
40
#pragma once
41
42
#include <pcl/gpu/containers/device_array.h>
43
#include <pcl/gpu/octree/octree.hpp>
44
#include <pcl/PointIndices.h>
45
#include <
pcl/pcl_macros.h
>
46
#include <pcl/point_cloud.h>
47
#include <
pcl/point_types.h
>
48
49
namespace
pcl
{
50
namespace
gpu {
51
template
<
typename
Po
int
T>
52
void
53
extractEuclideanClusters
(
const
typename
pcl::PointCloud<PointT>::Ptr
& host_cloud_,
54
const
pcl::gpu::Octree::Ptr
& tree,
55
float
tolerance,
56
std::vector<PointIndices>& clusters,
57
unsigned
int
min_pts_per_cluster,
58
unsigned
int
max_pts_per_cluster);
59
60
/** \brief @b EuclideanClusterExtraction represents a segmentation class for cluster
61
* extraction in an Euclidean sense, depending on pcl::gpu::octree
62
* \author Koen Buys, Radu Bogdan Rusu
63
* \ingroup segmentation
64
*/
65
template
<
typename
Po
int
T>
66
class
EuclideanClusterExtraction
{
67
public
:
68
using
PointCloudHost
=
pcl::PointCloud<PointT>
;
69
using
PointCloudHostPtr
=
typename
PointCloudHost::Ptr
;
70
using
PointCloudHostConstPtr
=
typename
PointCloudHost::ConstPtr
;
71
72
using
PointIndicesPtr
=
PointIndices::Ptr
;
73
using
PointIndicesConstPtr
=
PointIndices::ConstPtr
;
74
75
using
GPUTree
=
pcl::gpu::Octree
;
76
using
GPUTreePtr
=
pcl::gpu::Octree::Ptr
;
77
78
using
CloudDevice
=
pcl::gpu::Octree::PointCloud
;
79
80
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81
/** \brief Empty constructor. */
82
EuclideanClusterExtraction
() =
default
;
83
84
/** \brief the destructor */
85
/* ~EuclideanClusterExtraction ()
86
{
87
tree_.clear();
88
};
89
*/
90
/** \brief Provide a pointer to the search object.
91
* \param tree a pointer to the spatial search object.
92
*/
93
inline
void
94
setSearchMethod
(
GPUTreePtr
& tree)
95
{
96
tree_
= tree;
97
}
98
99
/** \brief Get a pointer to the search method used.
100
* @todo fix this for a generic search tree
101
*/
102
inline
GPUTreePtr
103
getSearchMethod
()
104
{
105
return
(
tree_
);
106
}
107
108
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
109
* \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean
110
* space
111
*/
112
inline
void
113
setClusterTolerance
(
double
tolerance)
114
{
115
cluster_tolerance_
= tolerance;
116
}
117
118
/** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
119
*/
120
inline
double
121
getClusterTolerance
()
122
{
123
return
(
cluster_tolerance_
);
124
}
125
126
/** \brief Set the minimum number of points that a cluster needs to contain in order
127
* to be considered valid.
128
* \param 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
()
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.
146
* \param max_cluster_size the maximum cluster size
147
*/
148
inline
void
149
setMaxClusterSize
(
int
max_cluster_size)
150
{
151
max_pts_per_cluster_
= max_cluster_size;
152
}
153
154
/** \brief Get the maximum number of points that a cluster needs to contain in order
155
* to be considered valid. */
156
inline
int
157
getMaxClusterSize
()
158
{
159
return
(
max_pts_per_cluster_
);
160
}
161
162
inline
void
163
setInput
(
CloudDevice
input)
164
{
165
input_
= input;
166
}
167
168
inline
void
169
setHostCloud
(
PointCloudHostPtr
host_cloud)
170
{
171
host_cloud_
= host_cloud;
172
}
173
174
/** \brief extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
175
* \param clusters the resultant point clusters
176
*/
177
void
178
extract
(std::vector<pcl::PointIndices>& clusters);
179
180
protected
:
181
/** \brief the input cloud on the GPU */
182
CloudDevice
input_
;
183
184
/** \brief the original cloud the Host */
185
PointCloudHostPtr
host_cloud_
;
186
187
/** \brief A pointer to the spatial search object. */
188
GPUTreePtr
tree_
;
189
190
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
191
double
cluster_tolerance_
{0};
192
193
/** \brief The minimum number of points that a cluster needs to contain in order to be
194
* considered valid (default = 1). */
195
int
min_pts_per_cluster_
{1};
196
197
/** \brief The maximum number of points that a cluster needs to contain in order to be
198
* considered valid (default = MAXINT). */
199
int
max_pts_per_cluster_
{std::numeric_limits<int>::max()};
200
201
/** \brief Class getName method. */
202
virtual
std::string
203
getClassName
()
const
204
{
205
return
(
"gpu::EuclideanClusterExtraction"
);
206
}
207
};
208
/** \brief Sort clusters method (for std::sort).
209
* \ingroup segmentation
210
*/
211
inline
bool
212
comparePointClusters
(
const
pcl::PointIndices
& a,
const
pcl::PointIndices
& b)
213
{
214
return
(a.
indices
.size() < b.
indices
.size());
215
}
216
}
// namespace gpu
217
}
// namespace pcl
pcl::gpu::EuclideanClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition:
gpu_extract_clusters.h:113
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl
Definition:
convolution.h:46
pcl::gpu::EuclideanClusterExtraction::EuclideanClusterExtraction
EuclideanClusterExtraction()=default
Empty constructor.
point_types.h
pcl::gpu::EuclideanClusterExtraction::setSearchMethod
void setSearchMethod(GPUTreePtr &tree)
the destructor
Definition:
gpu_extract_clusters.h:94
pcl::gpu::EuclideanClusterExtraction::getMaxClusterSize
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition:
gpu_extract_clusters.h:157
pcl::gpu::Octree::PointCloud
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition:
octree.hpp:76
pcl::gpu::EuclideanClusterExtraction::host_cloud_
PointCloudHostPtr host_cloud_
the original cloud the Host
Definition:
gpu_extract_clusters.h:185
pcl::gpu::EuclideanClusterExtraction::PointCloudHostPtr
typename PointCloudHost::Ptr PointCloudHostPtr
Definition:
gpu_extract_clusters.h:69
pcl::gpu::EuclideanClusterExtraction::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:
gpu_extract_clusters.h:131
pcl::gpu::EuclideanClusterExtraction::PointCloudHostConstPtr
typename PointCloudHost::ConstPtr PointCloudHostConstPtr
Definition:
gpu_extract_clusters.h:70
pcl::PointIndices::indices
Indices indices
Definition:
PointIndices.h:21
pcl::gpu::Octree
Octree implementation on GPU.
Definition:
octree.hpp:58
pcl::gpu::EuclideanClusterExtraction::setInput
void setInput(CloudDevice input)
Definition:
gpu_extract_clusters.h:163
pcl::gpu::EuclideanClusterExtraction::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:
gpu_extract_clusters.h:199
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition:
distances.h:55
pcl::gpu::EuclideanClusterExtraction
EuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sen...
Definition:
gpu_extract_clusters.h:66
pcl::gpu::EuclideanClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition:
gpu_extract_clusters.h:203
pcl::gpu::comparePointClusters
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
Definition:
gpu_extract_clusters.h:212
pcl::gpu::EuclideanClusterExtraction::getClusterTolerance
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition:
gpu_extract_clusters.h:121
pcl::gpu::EuclideanClusterExtraction::GPUTreePtr
pcl::gpu::Octree::Ptr GPUTreePtr
Definition:
gpu_extract_clusters.h:76
pcl::gpu::EuclideanClusterExtraction::tree_
GPUTreePtr tree_
A pointer to the spatial search object.
Definition:
gpu_extract_clusters.h:188
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition:
PointIndices.h:14
pcl::gpu::EuclideanClusterExtraction::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:
gpu_extract_clusters.h:195
pcl::gpu::EuclideanClusterExtraction::extract
void extract(std::vector< pcl::PointIndices > &clusters)
extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
Definition:
gpu_extract_clusters.hpp:188
pcl::gpu::DeviceArray< PointType >
pcl::gpu::EuclideanClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition:
gpu_extract_clusters.h:72
pcl::gpu::EuclideanClusterExtraction::cluster_tolerance_
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition:
gpu_extract_clusters.h:191
pcl::gpu::EuclideanClusterExtraction::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:
gpu_extract_clusters.h:149
pcl::gpu::EuclideanClusterExtraction::getMinClusterSize
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition:
gpu_extract_clusters.h:139
pcl::PointIndices
Definition:
PointIndices.h:11
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition:
PointIndices.h:13
pcl::gpu::EuclideanClusterExtraction::input_
CloudDevice input_
the input cloud on the GPU
Definition:
gpu_extract_clusters.h:182
pcl::gpu::EuclideanClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition:
gpu_extract_clusters.h:73
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition:
point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition:
point_cloud.h:414
pcl::gpu::extractEuclideanClusters
void extractEuclideanClusters(const typename pcl::PointCloud< PointT >::Ptr &host_cloud_, const pcl::gpu::Octree::Ptr &tree, float tolerance, std::vector< PointIndices > &clusters, unsigned int min_pts_per_cluster, unsigned int max_pts_per_cluster)
Definition:
gpu_extract_clusters.hpp:57
pcl::gpu::EuclideanClusterExtraction::setHostCloud
void setHostCloud(PointCloudHostPtr host_cloud)
Definition:
gpu_extract_clusters.h:169
pcl::gpu::EuclideanClusterExtraction::getSearchMethod
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition:
gpu_extract_clusters.h:103
pcl::gpu::Octree::Ptr
shared_ptr< Octree > Ptr
Types.
Definition:
octree.hpp:69