Point Cloud Library (PCL)  1.8.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 #ifndef PCL_GPU_EXTRACT_LABELED_CLUSTERS_H_
41 #define PCL_GPU_EXTRACT_LABELED_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/impl/device_array.hpp>
49 
50 namespace pcl
51 {
52  namespace gpu
53  {
54  template <typename PointT> void
55  extractLabeledEuclideanClusters (const boost::shared_ptr<pcl::PointCloud<PointT> > &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 EuclideanLabeledClusterExtraction 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  */
66  template <typename PointT>
68  {
69  public:
74 
77 
80 
82 
83  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84  /** \brief Empty constructor. */
86  {};
87 
88  /** \brief Provide a pointer to the search object.
89  * \param tree a pointer to the spatial search object.
90  */
91  inline void setSearchMethod (const GPUTreePtr &tree) { tree_ = tree; }
92 
93  /** \brief Get a pointer to the search method used.
94  * @todo fix this for a generic search tree
95  */
96  inline GPUTreePtr getSearchMethod () { return (tree_); }
97 
98  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
99  * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
100  */
101  inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
102 
103  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
104  inline double getClusterTolerance () { return (cluster_tolerance_); }
105 
106  /** \brief Set the minimum number of points that a cluster needs to contain in order to be considered valid.
107  * \param min_cluster_size the minimum cluster size
108  */
109  inline void setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; }
110 
111  /** \brief Get the minimum number of points that a cluster needs to contain in order to be considered valid. */
112  inline int getMinClusterSize () { return (min_pts_per_cluster_); }
113 
114  /** \brief Set the maximum number of points that a cluster needs to contain in order to be considered valid.
115  * \param max_cluster_size the maximum cluster size
116  */
117  inline void setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; }
118 
119  /** \brief Get the maximum number of points that a cluster needs to contain in order to be considered valid. */
120  inline int getMaxClusterSize () { return (max_pts_per_cluster_); }
121 
122  inline void setInput (CloudDevice input) {input_ = input;}
123 
124  inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;}
125 
126  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
127  * \param clusters the resultant point clusters
128  */
129  void extract (std::vector<PointIndices> &clusters);
130 
131  protected:
132  /** \brief the input cloud on the GPU */
134 
135  /** \brief the original cloud the Host */
137 
138  /** \brief A pointer to the spatial search object. */
140 
141  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
143 
144  /** \brief The minimum number of points that a cluster needs to contain in order to be considered valid (default = 1). */
146 
147  /** \brief The maximum number of points that a cluster needs to contain in order to be considered valid (default = MAXINT). */
149 
150  /** \brief Class getName method. */
151  virtual std::string getClassName () const { return ("gpu::EuclideanLabeledClusterExtraction"); }
152  };
153  /** \brief Sort clusters method (for std::sort).
154  * \ingroup segmentation
155  */
156  inline bool
158  {
159  return (a.indices.size () < b.indices.size ());
160  }
161  }
162 }
163 
164 #endif //PCL_GPU_EXTRACT_LABELED_CLUSTERS_H_
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid...
EuclideanLabeledClusterExtraction represents a segmentation class for cluster extraction in an Euclid...
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
boost::shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:67
void setMaxClusterSize(int max_cluster_size)
Set the maximum number of points that a cluster needs to contain in order to be considered valid...
std::vector< int > indices
Definition: PointIndices.h:19
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
Octree implementation on GPU.
Definition: octree.hpp:56
void extractLabeledEuclideanClusters(const boost::shared_ptr< pcl::PointCloud< PointT > > &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)
void setMinClusterSize(int min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid...
bool compareLabeledPointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
A point structure representing Euclidean xyz coordinates.
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
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...
boost::shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:22
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid...
void extract(std::vector< PointIndices > &clusters)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
PointCloudHostPtr host_cloud_
the original cloud the Host
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
CloudDevice input_
the input cloud on the GPU
int max_pts_per_cluster_
The maximum number of points that a cluster needs to contain in order to be considered valid (default...
boost::shared_ptr< ::pcl::PointIndices const > ConstPtr
Definition: PointIndices.h:23
GPUTreePtr tree_
A pointer to the spatial search object.