Point Cloud Library (PCL)  1.14.1-dev
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 PointT>
51 void
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 PointT>
67 public:
72 
75 
78 
80 
81  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82  /** \brief Empty constructor. */
84 
85  /** \brief Default virtual destructor. */
87 
88  /** \brief Provide a pointer to the search object.
89  * \param tree a pointer to the spatial search object.
90  */
91  inline void
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
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
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
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
155  {
156  return (max_pts_per_cluster_);
157  }
158 
159  inline void
161  {
162  input_ = input;
163  }
164 
165  inline void
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 */
180 
181  /** \brief the original cloud the Host */
183 
184  /** \brief A pointer to the spatial search object. */
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). */
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
210 {
211  return (a.indices.size() < b.indices.size());
212 }
213 } // namespace gpu
214 } // 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 ~EuclideanLabeledClusterExtraction()=default
Default virtual destructor.
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: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 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.