Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
segmentation
include
pcl
gpu
segmentation
gpu_extract_labeled_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
*
38
*/
39
40
#pragma once
41
42
#include <pcl/gpu/octree/octree.hpp>
43
#include <
pcl/pcl_macros.h
>
44
#include <pcl/point_cloud.h>
45
#include <
pcl/point_types.h
>
46
#include <pcl/PointIndices.h>
47
48
namespace
pcl
{
49
namespace
gpu
{
50
template
<
typename
Po
int
T>
51
void
52
extractLabeledEuclideanClusters
(
53
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 EuclideanLabeledClusterExtraction represents a segmentation class for
61
* cluster 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
EuclideanLabeledClusterExtraction
{
67
public
:
68
using
PointType
=
pcl::PointXYZ
;
69
using
PointCloudHost
=
pcl::PointCloud<PointT>
;
70
using
PointCloudHostPtr
=
typename
PointCloudHost::Ptr
;
71
using
PointCloudHostConstPtr
=
typename
PointCloudHost::ConstPtr
;
72
73
using
PointIndicesPtr
=
PointIndices::Ptr
;
74
using
PointIndicesConstPtr
=
PointIndices::ConstPtr
;
75
76
using
GPUTree
=
pcl::gpu::Octree
;
77
using
GPUTreePtr
=
pcl::gpu::Octree::Ptr
;
78
79
using
CloudDevice
=
pcl::gpu::Octree::PointCloud
;
80
81
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82
/** \brief Empty constructor. */
83
EuclideanLabeledClusterExtraction
() =
default
;
84
85
/** \brief Default virtual destructor. */
86
virtual
~EuclideanLabeledClusterExtraction
() =
default
;
87
88
/** \brief Provide a pointer to the search object.
89
* \param tree a pointer to the spatial search object.
90
*/
91
inline
void
92
setSearchMethod
(
const
GPUTreePtr
& tree)
93
{
94
tree_
= tree;
95
}
96
97
/** \brief Get a pointer to the search method used.
98
* @todo fix this for a generic search tree
99
*/
100
inline
GPUTreePtr
101
getSearchMethod
()
102
{
103
return
(
tree_
);
104
}
105
106
/** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
107
* \param tolerance the spatial cluster tolerance measured by L2 distance
108
*/
109
inline
void
110
setClusterTolerance
(
double
tolerance)
111
{
112
cluster_tolerance_
= tolerance;
113
}
114
115
/** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
116
*/
117
inline
double
118
getClusterTolerance
()
119
{
120
return
(
cluster_tolerance_
);
121
}
122
123
/** \brief Set the minimum number of points that a cluster needs to contain in order
124
* to be considered valid.
125
* \param min_cluster_size the minimum cluster size
126
*/
127
inline
void
128
setMinClusterSize
(
int
min_cluster_size)
129
{
130
min_pts_per_cluster_
= min_cluster_size;
131
}
132
133
/** \brief Get the minimum number of points that a cluster needs to contain in order
134
* to be considered valid. */
135
inline
int
136
getMinClusterSize
()
137
{
138
return
(
min_pts_per_cluster_
);
139
}
140
141
/** \brief Set the maximum number of points that a cluster needs to contain in order
142
* to be considered valid.
143
* \param max_cluster_size the maximum cluster size
144
*/
145
inline
void
146
setMaxClusterSize
(
int
max_cluster_size)
147
{
148
max_pts_per_cluster_
= max_cluster_size;
149
}
150
151
/** \brief Get the maximum number of points that a cluster needs to contain in order
152
* to be considered valid. */
153
inline
int
154
getMaxClusterSize
()
155
{
156
return
(
max_pts_per_cluster_
);
157
}
158
159
inline
void
160
setInput
(
CloudDevice
input)
161
{
162
input_
= input;
163
}
164
165
inline
void
166
setHostCloud
(
PointCloudHostPtr
host_cloud)
167
{
168
host_cloud_
= host_cloud;
169
}
170
171
/** \brief extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
172
* \param clusters the resultant point clusters
173
*/
174
void
175
extract
(std::vector<PointIndices>& clusters);
176
177
protected
:
178
/** \brief the input cloud on the GPU */
179
CloudDevice
input_
;
180
181
/** \brief the original cloud the Host */
182
PointCloudHostPtr
host_cloud_
;
183
184
/** \brief A pointer to the spatial search object. */
185
GPUTreePtr
tree_
;
186
187
/** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
188
double
cluster_tolerance_
{0.0};
189
190
/** \brief The minimum number of points that a cluster needs to contain in order to be
191
* considered valid (default = 1). */
192
int
min_pts_per_cluster_
{1};
193
194
/** \brief The maximum number of points that a cluster needs to contain in order to be
195
* considered valid (default = MAXINT). */
196
int
max_pts_per_cluster_
{std::numeric_limits<int>::max()};
197
198
/** \brief Class getName method. */
199
virtual
std::string
200
getClassName
()
const
201
{
202
return
(
"gpu::EuclideanLabeledClusterExtraction"
);
203
}
204
};
205
/** \brief Sort clusters method (for std::sort).
206
* \ingroup segmentation
207
*/
208
inline
bool
209
compareLabeledPointClusters
(
const
pcl::PointIndices
& a,
const
pcl::PointIndices
& b)
210
{
211
return
(a.
indices
.size() < b.
indices
.size());
212
}
213
}
// namespace gpu
214
}
// namespace pcl
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::gpu::EuclideanLabeledClusterExtraction::input_
CloudDevice input_
the input cloud on the GPU
Definition
gpu_extract_labeled_clusters.h:179
pcl::gpu::EuclideanLabeledClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
gpu_extract_labeled_clusters.h:110
pcl::gpu::EuclideanLabeledClusterExtraction::tree_
GPUTreePtr tree_
A pointer to the spatial search object.
Definition
gpu_extract_labeled_clusters.h:185
pcl::gpu::EuclideanLabeledClusterExtraction::~EuclideanLabeledClusterExtraction
virtual ~EuclideanLabeledClusterExtraction()=default
Default virtual destructor.
pcl::gpu::EuclideanLabeledClusterExtraction::GPUTree
pcl::gpu::Octree GPUTree
Definition
gpu_extract_labeled_clusters.h:76
pcl::gpu::EuclideanLabeledClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition
gpu_extract_labeled_clusters.h:74
pcl::gpu::EuclideanLabeledClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition
gpu_extract_labeled_clusters.h:200
pcl::gpu::EuclideanLabeledClusterExtraction::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_labeled_clusters.h:192
pcl::gpu::EuclideanLabeledClusterExtraction::getSearchMethod
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition
gpu_extract_labeled_clusters.h:101
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHost
pcl::PointCloud< PointT > PointCloudHost
Definition
gpu_extract_labeled_clusters.h:69
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHostConstPtr
typename PointCloudHost::ConstPtr PointCloudHostConstPtr
Definition
gpu_extract_labeled_clusters.h:71
pcl::gpu::EuclideanLabeledClusterExtraction::extract
void extract(std::vector< PointIndices > &clusters)
extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
Definition
gpu_extract_labeled_clusters.hpp:152
pcl::gpu::EuclideanLabeledClusterExtraction::setHostCloud
void setHostCloud(PointCloudHostPtr host_cloud)
Definition
gpu_extract_labeled_clusters.h:166
pcl::gpu::EuclideanLabeledClusterExtraction::setSearchMethod
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
Definition
gpu_extract_labeled_clusters.h:92
pcl::gpu::EuclideanLabeledClusterExtraction::getMinClusterSize
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition
gpu_extract_labeled_clusters.h:136
pcl::gpu::EuclideanLabeledClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition
gpu_extract_labeled_clusters.h:73
pcl::gpu::EuclideanLabeledClusterExtraction::cluster_tolerance_
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
gpu_extract_labeled_clusters.h:188
pcl::gpu::EuclideanLabeledClusterExtraction::host_cloud_
PointCloudHostPtr host_cloud_
the original cloud the Host
Definition
gpu_extract_labeled_clusters.h:182
pcl::gpu::EuclideanLabeledClusterExtraction::setInput
void setInput(CloudDevice input)
Definition
gpu_extract_labeled_clusters.h:160
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHostPtr
typename PointCloudHost::Ptr PointCloudHostPtr
Definition
gpu_extract_labeled_clusters.h:70
pcl::gpu::EuclideanLabeledClusterExtraction::GPUTreePtr
pcl::gpu::Octree::Ptr GPUTreePtr
Definition
gpu_extract_labeled_clusters.h:77
pcl::gpu::EuclideanLabeledClusterExtraction::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_labeled_clusters.h:146
pcl::gpu::EuclideanLabeledClusterExtraction::CloudDevice
pcl::gpu::Octree::PointCloud CloudDevice
Definition
gpu_extract_labeled_clusters.h:79
pcl::gpu::EuclideanLabeledClusterExtraction::PointType
pcl::PointXYZ PointType
Definition
gpu_extract_labeled_clusters.h:68
pcl::gpu::EuclideanLabeledClusterExtraction::EuclideanLabeledClusterExtraction
EuclideanLabeledClusterExtraction()=default
Empty constructor.
pcl::gpu::EuclideanLabeledClusterExtraction::getMaxClusterSize
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition
gpu_extract_labeled_clusters.h:154
pcl::gpu::EuclideanLabeledClusterExtraction::getClusterTolerance
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition
gpu_extract_labeled_clusters.h:118
pcl::gpu::EuclideanLabeledClusterExtraction::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_labeled_clusters.h:196
pcl::gpu::EuclideanLabeledClusterExtraction::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_labeled_clusters.h:128
pcl::gpu::Octree
Octree implementation on GPU.
Definition
octree.hpp:59
pcl::gpu::Octree::Ptr
shared_ptr< Octree > Ptr
Types.
Definition
octree.hpp:69
pcl::gpu::Octree::PointCloud
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition
octree.hpp:76
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl::gpu::compareLabeledPointClusters
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
Definition
gpu_extract_labeled_clusters.h:209
pcl::gpu
Definition
device_array.h:45
pcl::gpu::extractLabeledEuclideanClusters
void extractLabeledEuclideanClusters(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_labeled_clusters.hpp:45
pcl
Definition
convolution.h:46
pcl_macros.h
Defines all the PCL and non-PCL macros used.
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
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition
point_types.hpp:322