Point Cloud Library (PCL)  1.12.0-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/PointIndices.h>
44 #include <pcl/pcl_macros.h>
45 #include <pcl/point_cloud.h>
46 #include <pcl/point_types.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 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 
174 protected:
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
197  getClassName() const
198  {
199  return ("gpu::EuclideanLabeledClusterExtraction");
200  }
201 };
202 /** \brief Sort clusters method (for std::sort).
203  * \ingroup segmentation
204  */
205 inline bool
207 {
208  return (a.indices.size() < b.indices.size());
209 }
210 } // namespace gpu
211 } // namespace pcl
pcl_macros.h
Defines all the PCL and non-PCL macros used.
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:185
pcl
Definition: convolution.h:46
point_types.h
pcl::gpu::EuclideanLabeledClusterExtraction::tree_
GPUTreePtr tree_
A pointer to the spatial search object.
Definition: gpu_extract_labeled_clusters.h:182
pcl::gpu::Octree::PointCloud
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition: octree.hpp:75
pcl::gpu::EuclideanLabeledClusterExtraction::input_
CloudDevice input_
the input cloud on the GPU
Definition: gpu_extract_labeled_clusters.h:176
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:193
pcl::gpu::EuclideanLabeledClusterExtraction::EuclideanLabeledClusterExtraction
EuclideanLabeledClusterExtraction()=default
Empty constructor.
pcl::PointIndices::indices
Indices indices
Definition: PointIndices.h:21
pcl::gpu::Octree
Octree implementation on GPU.
Definition: octree.hpp:57
pcl::gpu::EuclideanLabeledClusterExtraction::host_cloud_
PointCloudHostPtr host_cloud_
the original cloud the Host
Definition: gpu_extract_labeled_clusters.h:179
pcl::gpu::EuclideanLabeledClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition: gpu_extract_labeled_clusters.h:73
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:133
pcl::gpu::EuclideanLabeledClusterExtraction::getSearchMethod
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: gpu_extract_labeled_clusters.h:98
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHostPtr
typename PointCloudHost::Ptr PointCloudHostPtr
Definition: gpu_extract_labeled_clusters.h:70
pcl::gpu::EuclideanLabeledClusterExtraction::PointCloudHostConstPtr
typename PointCloudHost::ConstPtr PointCloudHostConstPtr
Definition: gpu_extract_labeled_clusters.h:71
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:125
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:14
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:346
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:151
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:115
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:189
pcl::gpu::DeviceArray< PointType >
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::PointIndices
Definition: PointIndices.h:11
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:13
pcl::gpu::EuclideanLabeledClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: gpu_extract_labeled_clusters.h:74
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
pcl::gpu::EuclideanLabeledClusterExtraction::setInput
void setInput(CloudDevice input)
Definition: gpu_extract_labeled_clusters.h:157
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:206
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
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:107
pcl::gpu::Octree::Ptr
shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:68
pcl::gpu::EuclideanLabeledClusterExtraction::GPUTreePtr
pcl::gpu::Octree::Ptr GPUTreePtr
Definition: gpu_extract_labeled_clusters.h:77
pcl::gpu::EuclideanLabeledClusterExtraction::setSearchMethod
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
Definition: gpu_extract_labeled_clusters.h:89
pcl::gpu::EuclideanLabeledClusterExtraction::setHostCloud
void setHostCloud(PointCloudHostPtr host_cloud)
Definition: gpu_extract_labeled_clusters.h:163
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:143
pcl::gpu::EuclideanLabeledClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition: gpu_extract_labeled_clusters.h:197
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
EuclideanLabeledClusterExtraction represents a segmentation class for cluster extraction in an Euclid...
Definition: gpu_extract_labeled_clusters.h:66