Point Cloud Library (PCL) 1.12.1
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/PointIndices.h>
44#include <pcl/pcl_macros.h>
45#include <pcl/point_cloud.h>
46#include <pcl/point_types.h>
47
48namespace pcl {
49namespace gpu {
50template <typename PointT>
51void
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 */
65template <typename PointT>
67public:
72
75
78
80
81 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 /** \brief Empty constructor. */
84
85 /** \brief Provide a pointer to the search object.
86 * \param tree a pointer to the spatial search object.
87 */
88 inline void
90 {
91 tree_ = tree;
92 }
93
94 /** \brief Get a pointer to the search method used.
95 * @todo fix this for a generic search tree
96 */
97 inline GPUTreePtr
99 {
100 return (tree_);
101 }
102
103 /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
104 * \param tolerance the spatial cluster tolerance measured by L2 distance
105 */
106 inline void
107 setClusterTolerance(double tolerance)
108 {
109 cluster_tolerance_ = tolerance;
110 }
111
112 /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
113 */
114 inline double
116 {
117 return (cluster_tolerance_);
118 }
119
120 /** \brief Set the minimum number of points that a cluster needs to contain in order
121 * to be considered valid.
122 * \param min_cluster_size the minimum cluster size
123 */
124 inline void
125 setMinClusterSize(int min_cluster_size)
126 {
127 min_pts_per_cluster_ = min_cluster_size;
128 }
129
130 /** \brief Get the minimum number of points that a cluster needs to contain in order
131 * to be considered valid. */
132 inline int
134 {
135 return (min_pts_per_cluster_);
136 }
137
138 /** \brief Set the maximum number of points that a cluster needs to contain in order
139 * to be considered valid.
140 * \param max_cluster_size the maximum cluster size
141 */
142 inline void
143 setMaxClusterSize(int max_cluster_size)
144 {
145 max_pts_per_cluster_ = max_cluster_size;
146 }
147
148 /** \brief Get the maximum number of points that a cluster needs to contain in order
149 * to be considered valid. */
150 inline int
152 {
153 return (max_pts_per_cluster_);
154 }
155
156 inline void
158 {
159 input_ = input;
160 }
161
162 inline void
164 {
165 host_cloud_ = host_cloud;
166 }
167
168 /** \brief extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
169 * \param clusters the resultant point clusters
170 */
171 void
172 extract(std::vector<PointIndices>& clusters);
173
174protected:
175 /** \brief the input cloud on the GPU */
177
178 /** \brief the original cloud the Host */
180
181 /** \brief A pointer to the spatial search object. */
183
184 /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
186
187 /** \brief The minimum number of points that a cluster needs to contain in order to be
188 * considered valid (default = 1). */
190
191 /** \brief The maximum number of points that a cluster needs to contain in order to be
192 * considered valid (default = MAXINT). */
193 int max_pts_per_cluster_{std::numeric_limits<int>::max()};
194
195 /** \brief Class getName method. */
196 virtual std::string
198 {
199 return ("gpu::EuclideanLabeledClusterExtraction");
200 }
201};
202/** \brief Sort clusters method (for std::sort).
203 * \ingroup segmentation
204 */
205inline bool
207{
208 return (a.indices.size() < b.indices.size());
209}
210} // namespace gpu
211} // namespace pcl
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
EuclideanLabeledClusterExtraction represents a segmentation class for cluster extraction in an Euclid...
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
GPUTreePtr tree_
A pointer to the spatial search object.
virtual std::string getClassName() const
Class getName method.
int min_pts_per_cluster_
The minimum number of points that a cluster needs to contain in order to be considered valid (default...
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
typename PointCloudHost::ConstPtr PointCloudHostConstPtr
void extract(std::vector< PointIndices > &clusters)
extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
PointCloudHostPtr host_cloud_
the original cloud the Host
void setMaxClusterSize(int max_cluster_size)
Set the maximum number of points that a cluster needs to contain in order to be considered valid.
EuclideanLabeledClusterExtraction()=default
Empty constructor.
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
int max_pts_per_cluster_
The maximum number of points that a cluster needs to contain in order to be considered valid (default...
void setMinClusterSize(int min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid.
Octree implementation on GPU.
Definition: octree.hpp:58
shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:68
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition: octree.hpp:75
Defines all the PCL implemented PointT point type structures.
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
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)
Defines all the PCL and non-PCL macros used.
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:13
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:14
A point structure representing Euclidean xyz coordinates.