Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extract_labeled_clusters.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #ifndef PCL_EXTRACT_LABELED_CLUSTERS_H_
37 #define PCL_EXTRACT_LABELED_CLUSTERS_H_
38 
39 #include <pcl/pcl_base.h>
40 #include <pcl/search/pcl_search.h>
41 
42 namespace pcl
43 {
45 
56  template <typename PointT> void
58  const PointCloud<PointT> &cloud, const boost::shared_ptr<search::Search<PointT> > &tree,
59  float tolerance, std::vector<std::vector<PointIndices> > &labeled_clusters,
60  unsigned int min_pts_per_cluster = 1, unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) (),
61  unsigned int max_label = (std::numeric_limits<int>::max));
62 
66 
70  template <typename PointT>
72  {
74 
75  public:
77  typedef typename PointCloud::Ptr PointCloudPtr;
79 
82 
85 
87 
89  tree_ (),
90  cluster_tolerance_ (0),
91  min_pts_per_cluster_ (1),
92  max_pts_per_cluster_ (std::numeric_limits<int>::max ()),
93  max_label_ (std::numeric_limits<int>::max ())
94  {};
95 
99  inline void
100  setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
101 
103  inline KdTreePtr
104  getSearchMethod () const { return (tree_); }
105 
109  inline void
110  setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
111 
113  inline double
114  getClusterTolerance () const { return (cluster_tolerance_); }
115 
119  inline void
120  setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; }
121 
123  inline int
124  getMinClusterSize () const { return (min_pts_per_cluster_); }
125 
129  inline void
130  setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; }
131 
133  inline int
134  getMaxClusterSize () const { return (max_pts_per_cluster_); }
135 
139  inline void
140  setMaxLabels (unsigned int max_label) { max_label_ = max_label; }
141 
143  inline unsigned int
144  getMaxLabels () const { return (max_label_); }
145 
149  void
150  extract (std::vector<std::vector<PointIndices> > &labeled_clusters);
151 
152  protected:
153  // Members derived from the base class
154  using BasePCLBase::input_;
155  using BasePCLBase::indices_;
156  using BasePCLBase::initCompute;
157  using BasePCLBase::deinitCompute;
158 
160  KdTreePtr tree_;
161 
163  double cluster_tolerance_;
164 
166  int min_pts_per_cluster_;
167 
169  int max_pts_per_cluster_;
170 
172  unsigned int max_label_;
173 
175  virtual std::string getClassName () const { return ("LabeledEuclideanClusterExtraction"); }
176 
177  };
178 
182  inline bool
184  {
185  return (a.indices.size () < b.indices.size ());
186  }
187 }
188 
189 #endif //#ifndef PCL_EXTRACT_LABELED_CLUSTERS_H_