Point Cloud Library (PCL)  1.9.1
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 #ifndef PCL_GPU_EXTRACT_CLUSTERS_H_
41 #define PCL_GPU_EXTRACT_CLUSTERS_H_
42 
43 #include <pcl/point_types.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/PointIndices.h>
46 #include <pcl/pcl_macros.h>
47 #include <pcl/gpu/octree/octree.hpp>
48 #include <pcl/gpu/containers/device_array.h>
49 
50 namespace pcl
51 {
52  namespace gpu
53  {
54  void
55  extractEuclideanClusters (const boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> > &host_cloud_,
56  const pcl::gpu::Octree::Ptr &tree,
57  float tolerance,
58  std::vector<PointIndices> &clusters,
59  unsigned int min_pts_per_cluster,
60  unsigned int max_pts_per_cluster);
61 
62  /** \brief @b EuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sense, depending on pcl::gpu::octree
63  * \author Koen Buys, Radu Bogdan Rusu
64  * \ingroup segmentation
65  */
67  {
68  public:
73 
76 
79 
81 
82  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83  /** \brief Empty constructor. */
85  {};
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 setSearchMethod (GPUTreePtr &tree) { tree_ = tree; }
97 
98  /** \brief Get a pointer to the search method used.
99  * @todo fix this for a generic search tree
100  */
101  inline GPUTreePtr getSearchMethod () { return (tree_); }
102 
103  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
104  * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
105  */
106  inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
107 
108  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
109  inline double getClusterTolerance () { return (cluster_tolerance_); }
110 
111  /** \brief Set the minimum number of points that a cluster needs to contain in order to be considered valid.
112  * \param min_cluster_size the minimum cluster size
113  */
114  inline void setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; }
115 
116  /** \brief Get the minimum number of points that a cluster needs to contain in order to be considered valid. */
117  inline int getMinClusterSize () { return (min_pts_per_cluster_); }
118 
119  /** \brief Set the maximum number of points that a cluster needs to contain in order to be considered valid.
120  * \param max_cluster_size the maximum cluster size
121  */
122  inline void setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; }
123 
124  /** \brief Get the maximum number of points that a cluster needs to contain in order to be considered valid. */
125  inline int getMaxClusterSize () { return (max_pts_per_cluster_); }
126 
127  inline void setInput (CloudDevice input) {input_ = input;}
128 
129  inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;}
130 
131  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
132  * \param clusters the resultant point clusters
133  */
134  void extract (std::vector<pcl::PointIndices> &clusters);
135 
136  protected:
137  /** \brief the input cloud on the GPU */
139 
140  /** \brief the original cloud the Host */
142 
143  /** \brief A pointer to the spatial search object. */
145 
146  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
148 
149  /** \brief The minimum number of points that a cluster needs to contain in order to be considered valid (default = 1). */
151 
152  /** \brief The maximum number of points that a cluster needs to contain in order to be considered valid (default = MAXINT). */
154 
155  /** \brief Class getName method. */
156  virtual std::string getClassName () const { return ("gpu::EuclideanClusterExtraction"); }
157  };
158  /** \brief Sort clusters method (for std::sort).
159  * \ingroup segmentation
160  */
161  inline bool
163  {
164  return (a.indices.size () < b.indices.size ());
165  }
166  }
167 }
168 
169 #endif //PCL_GPU_EXTRACT_CLUSTERS_H_
170 
171 
172 
173 
pcl::gpu::EuclideanClusterExtraction::getMinClusterSize
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid.
Definition: gpu_extract_clusters.h:117
pcl::gpu::EuclideanClusterExtraction::PointType
pcl::PointXYZ PointType
Definition: gpu_extract_clusters.h:69
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
point_types.h
pcl::PointCloud< pcl::PointXYZ >::Ptr
boost::shared_ptr< PointCloud< pcl::PointXYZ > > Ptr
Definition: point_cloud.h:428
pcl::gpu::EuclideanClusterExtraction::tree_
GPUTreePtr tree_
A pointer to the spatial search object.
Definition: gpu_extract_clusters.h:144
pcl::gpu::EuclideanClusterExtraction::input_
CloudDevice input_
the input cloud on the GPU
Definition: gpu_extract_clusters.h:138
pcl::gpu::EuclideanClusterExtraction::getMaxClusterSize
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid.
Definition: gpu_extract_clusters.h:125
pcl::gpu::extractEuclideanClusters
void extractEuclideanClusters(const boost::shared_ptr< pcl::PointCloud< pcl::PointXYZ > > &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_clusters.hpp:45
pcl::gpu::EuclideanClusterExtraction::cluster_tolerance_
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition: gpu_extract_clusters.h:147
pcl::gpu::Octree
Octree implementation on GPU.
Definition: octree.hpp:56
pcl::gpu::EuclideanClusterExtraction::setClusterTolerance
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition: gpu_extract_clusters.h:106
pcl::gpu::EuclideanClusterExtraction::PointCloudHost
pcl::PointCloud< pcl::PointXYZ > PointCloudHost
Definition: gpu_extract_clusters.h:70
pcl::gpu::EuclideanClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition: gpu_extract_clusters.h:156
pcl::PointCloud< pcl::PointXYZ >
pcl::gpu::EuclideanClusterExtraction::PointCloudHostPtr
PointCloudHost::Ptr PointCloudHostPtr
Definition: gpu_extract_clusters.h:71
pcl::gpu::EuclideanClusterExtraction::PointCloudHostConstPtr
PointCloudHost::ConstPtr PointCloudHostConstPtr
Definition: gpu_extract_clusters.h:72
pcl::gpu::EuclideanClusterExtraction
EuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sen...
Definition: gpu_extract_clusters.h:66
pcl::PointIndices::Ptr
boost::shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:22
pcl::gpu::EuclideanClusterExtraction::getSearchMethod
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: gpu_extract_clusters.h:101
pcl::gpu::comparePointClusters
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
Definition: gpu_extract_clusters.h:162
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:287
pcl::gpu::EuclideanClusterExtraction::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: gpu_extract_clusters.h:75
pcl::gpu::EuclideanClusterExtraction::CloudDevice
pcl::gpu::Octree::PointCloud CloudDevice
Definition: gpu_extract_clusters.h:80
pcl::gpu::EuclideanClusterExtraction::setInput
void setInput(CloudDevice input)
Definition: gpu_extract_clusters.h:127
pcl::gpu::DeviceArray< PointType >
pcl::gpu::EuclideanClusterExtraction::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_clusters.h:122
pcl::PointIndices::indices
std::vector< int > indices
Definition: PointIndices.h:19
pcl::gpu::EuclideanClusterExtraction::setHostCloud
void setHostCloud(PointCloudHostPtr host_cloud)
Definition: gpu_extract_clusters.h:129
pcl::PointIndices
Definition: PointIndices.h:12
pcl::gpu::EuclideanClusterExtraction::host_cloud_
PointCloudHostPtr host_cloud_
the original cloud the Host
Definition: gpu_extract_clusters.h:141
pcl::gpu::EuclideanClusterExtraction::GPUTreePtr
pcl::gpu::Octree::Ptr GPUTreePtr
Definition: gpu_extract_clusters.h:78
pcl::PointIndices::ConstPtr
boost::shared_ptr< ::pcl::PointIndices const > ConstPtr
Definition: PointIndices.h:23
pcl::gpu::EuclideanClusterExtraction::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_clusters.h:114
std
Definition: multi_grid_octree_data.hpp:45
pcl::PointCloud< pcl::PointXYZ >::ConstPtr
boost::shared_ptr< const PointCloud< pcl::PointXYZ > > ConstPtr
Definition: point_cloud.h:429
pcl::gpu::EuclideanClusterExtraction::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition: gpu_extract_clusters.h:74
pcl::gpu::EuclideanClusterExtraction::getClusterTolerance
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
Definition: gpu_extract_clusters.h:109
pcl::gpu::Octree::Ptr
boost::shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:67
pcl::gpu::EuclideanClusterExtraction::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_clusters.h:150
pcl::gpu::EuclideanClusterExtraction::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_clusters.h:153
pcl::gpu::EuclideanClusterExtraction::setSearchMethod
void setSearchMethod(GPUTreePtr &tree)
the destructor
Definition: gpu_extract_clusters.h:96
pcl::gpu::EuclideanClusterExtraction::EuclideanClusterExtraction
EuclideanClusterExtraction()
Empty constructor.
Definition: gpu_extract_clusters.h:84
pcl::gpu::EuclideanClusterExtraction::extract
void extract(std::vector< pcl::PointIndices > &clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
Definition: gpu_extract_clusters.hpp:180
pcl::gpu::EuclideanClusterExtraction::GPUTree
pcl::gpu::Octree GPUTree
Definition: gpu_extract_clusters.h:77