Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
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
49namespace pcl {
50namespace gpu {
51template <typename PointT>
52void
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 */
65template <typename PointT>
67public:
69 using PointCloudHostPtr = typename PointCloudHost::Ptr;
70 using PointCloudHostConstPtr = typename PointCloudHost::ConstPtr;
71
74
77
79
80 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 /** \brief Empty constructor. */
83
84 /** \brief Default virtual destructor. */
85 virtual ~EuclideanClusterExtraction() = default;
86
87 /** \brief the destructor */
88 /* ~EuclideanClusterExtraction ()
89 {
90 tree_.clear();
91 };
92 */
93 /** \brief Provide a pointer to the search object.
94 * \param tree a pointer to the spatial search object.
95 */
96 inline void
98 {
99 tree_ = tree;
100 }
101
102 /** \brief Get a pointer to the search method used.
103 * @todo fix this for a generic search tree
104 */
105 inline GPUTreePtr
107 {
108 return (tree_);
109 }
110
111 /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
112 * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean
113 * space
114 */
115 inline void
116 setClusterTolerance(double tolerance)
117 {
118 cluster_tolerance_ = tolerance;
119 }
120
121 /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
122 */
123 inline double
125 {
126 return (cluster_tolerance_);
127 }
128
129 /** \brief Set the minimum number of points that a cluster needs to contain in order
130 * to be considered valid.
131 * \param min_cluster_size the minimum cluster size
132 */
133 inline void
134 setMinClusterSize(int min_cluster_size)
135 {
136 min_pts_per_cluster_ = min_cluster_size;
137 }
138
139 /** \brief Get the minimum number of points that a cluster needs to contain in order
140 * to be considered valid. */
141 inline int
143 {
144 return (min_pts_per_cluster_);
145 }
146
147 /** \brief Set the maximum number of points that a cluster needs to contain in order
148 * to be considered valid.
149 * \param max_cluster_size the maximum cluster size
150 */
151 inline void
152 setMaxClusterSize(int max_cluster_size)
153 {
154 max_pts_per_cluster_ = max_cluster_size;
155 }
156
157 /** \brief Get the maximum number of points that a cluster needs to contain in order
158 * to be considered valid. */
159 inline int
161 {
162 return (max_pts_per_cluster_);
163 }
164
165 inline void
167 {
168 input_ = input;
169 }
170
171 inline void
173 {
174 host_cloud_ = host_cloud;
175 }
176
177 /** \brief extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
178 * \param clusters the resultant point clusters
179 */
180 void
181 extract(std::vector<pcl::PointIndices>& clusters);
182
183protected:
184 /** \brief the input cloud on the GPU */
186
187 /** \brief the original cloud the Host */
189
190 /** \brief A pointer to the spatial search object. */
192
193 /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
195
196 /** \brief The minimum number of points that a cluster needs to contain in order to be
197 * considered valid (default = 1). */
199
200 /** \brief The maximum number of points that a cluster needs to contain in order to be
201 * considered valid (default = MAXINT). */
202 int max_pts_per_cluster_{std::numeric_limits<int>::max()};
203
204 /** \brief Class getName method. */
205 virtual std::string
207 {
208 return ("gpu::EuclideanClusterExtraction");
209 }
210};
211/** \brief Sort clusters method (for std::sort).
212 * \ingroup segmentation
213 */
214inline bool
216{
217 return (a.indices.size() < b.indices.size());
218}
219} // namespace gpu
220} // namespace pcl
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
EuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sen...
virtual std::string getClassName() const
Class getName method.
GPUTreePtr tree_
A pointer to the spatial search object.
EuclideanClusterExtraction()=default
Empty constructor.
CloudDevice input_
the input cloud on the GPU
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
typename PointCloudHost::Ptr PointCloudHostPtr
void setSearchMethod(GPUTreePtr &tree)
the destructor
typename PointCloudHost::ConstPtr PointCloudHostConstPtr
int min_pts_per_cluster_
The minimum number of points that a cluster needs to contain in order to be considered valid (default...
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
void extract(std::vector< pcl::PointIndices > &clusters)
extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
void setMinClusterSize(int min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid.
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
virtual ~EuclideanClusterExtraction()=default
Default virtual destructor.
void setMaxClusterSize(int max_cluster_size)
Set the maximum 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.
int max_pts_per_cluster_
The maximum number of points that a cluster needs to contain in order to be considered valid (default...
PointCloudHostPtr host_cloud_
the original cloud the Host
void setHostCloud(PointCloudHostPtr host_cloud)
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Octree implementation on GPU.
Definition octree.hpp:59
shared_ptr< Octree > Ptr
Types.
Definition octree.hpp:69
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition octree.hpp:76
Defines all the PCL implemented PointT point type structures.
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
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)
Defines all the PCL and non-PCL macros used.
shared_ptr< ::pcl::PointIndices > Ptr
shared_ptr< const ::pcl::PointIndices > ConstPtr