Point Cloud Library (PCL)  1.11.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/point_types.h>
43 #include <pcl/point_cloud.h>
44 #include <pcl/PointIndices.h>
45 #include <pcl/pcl_macros.h>
46 #include <pcl/gpu/octree/octree.hpp>
47 
48 namespace pcl
49 {
50  namespace gpu
51  {
52  template <typename PointT> void
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 cluster extraction in an Euclidean sense, depending on pcl::gpu::octree
61  * \author Koen Buys, Radu Bogdan Rusu
62  * \ingroup segmentation
63  */
64  template <typename PointT>
66  {
67  public:
72 
75 
78 
80 
81  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82  /** \brief Empty constructor. */
84  {};
85 
86  /** \brief Provide a pointer to the search object.
87  * \param tree a pointer to the spatial search object.
88  */
89  inline void setSearchMethod (const GPUTreePtr &tree) { tree_ = tree; }
90 
91  /** \brief Get a pointer to the search method used.
92  * @todo fix this for a generic search tree
93  */
94  inline GPUTreePtr getSearchMethod () { return (tree_); }
95 
96  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
97  * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
98  */
99  inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
100 
101  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
102  inline double getClusterTolerance () { return (cluster_tolerance_); }
103 
104  /** \brief Set the minimum number of points that a cluster needs to contain in order to be considered valid.
105  * \param min_cluster_size the minimum cluster size
106  */
107  inline void setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; }
108 
109  /** \brief Get the minimum number of points that a cluster needs to contain in order to be considered valid. */
110  inline int getMinClusterSize () { return (min_pts_per_cluster_); }
111 
112  /** \brief Set the maximum number of points that a cluster needs to contain in order to be considered valid.
113  * \param max_cluster_size the maximum cluster size
114  */
115  inline void setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; }
116 
117  /** \brief Get the maximum number of points that a cluster needs to contain in order to be considered valid. */
118  inline int getMaxClusterSize () { return (max_pts_per_cluster_); }
119 
120  inline void setInput (CloudDevice input) {input_ = input;}
121 
122  inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;}
123 
124  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
125  * \param clusters the resultant point clusters
126  */
127  void extract (std::vector<PointIndices> &clusters);
128 
129  protected:
130  /** \brief the input cloud on the GPU */
132 
133  /** \brief the original cloud the Host */
135 
136  /** \brief A pointer to the spatial search object. */
138 
139  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
141 
142  /** \brief The minimum number of points that a cluster needs to contain in order to be considered valid (default = 1). */
144 
145  /** \brief The maximum number of points that a cluster needs to contain in order to be considered valid (default = MAXINT). */
147 
148  /** \brief Class getName method. */
149  virtual std::string getClassName () const { return ("gpu::EuclideanLabeledClusterExtraction"); }
150  };
151  /** \brief Sort clusters method (for std::sort).
152  * \ingroup segmentation
153  */
154  inline bool
156  {
157  return (a.indices.size () < b.indices.size ());
158  }
159  }
160 }
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:140
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:137
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:131
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:146
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:134
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:110
pcl::gpu::EuclideanLabeledClusterExtraction::getSearchMethod
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: gpu_extract_labeled_clusters.h:94
pcl::gpu::EuclideanLabeledClusterExtraction::EuclideanLabeledClusterExtraction
EuclideanLabeledClusterExtraction()
Empty constructor.
Definition: gpu_extract_labeled_clusters.h:83
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:107
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:300
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:118
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:102
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:143
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:406
pcl::gpu::EuclideanLabeledClusterExtraction::setInput
void setInput(CloudDevice input)
Definition: gpu_extract_labeled_clusters.h:120
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:155
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:407
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:99
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:122
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:115
pcl::gpu::EuclideanLabeledClusterExtraction::getClassName
virtual std::string getClassName() const
Class getName method.
Definition: gpu_extract_labeled_clusters.h:149
pcl::gpu::EuclideanLabeledClusterExtraction::extract
void extract(std::vector< PointIndices > &clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
Definition: gpu_extract_labeled_clusters.hpp:150
pcl::gpu::EuclideanLabeledClusterExtraction
EuclideanLabeledClusterExtraction represents a segmentation class for cluster extraction in an Euclid...
Definition: gpu_extract_labeled_clusters.h:65