Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 */ 00035 00036 #ifndef PCL_EXTRACT_LABELED_CLUSTERS_H_ 00037 #define PCL_EXTRACT_LABELED_CLUSTERS_H_ 00038 00039 #include <pcl/pcl_base.h> 00040 #include "pcl/search/pcl_search.h" 00041 00042 namespace pcl 00043 { 00045 00055 template <typename PointT> void extractLabeledEuclideanClusters (const PointCloud<PointT> &cloud, const boost::shared_ptr<search::Search<PointT> > &tree, float tolerance, std::vector<std::vector<PointIndices> > &labeled_clusters, unsigned int min_pts_per_cluster = 1, unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) (), unsigned int max_label = (std::numeric_limits<int>::max)); 00056 00060 00064 template <typename PointT> 00065 class LabeledEuclideanClusterExtraction: public PCLBase<PointT> 00066 { 00067 typedef PCLBase<PointT> BasePCLBase; 00068 00069 public: 00070 typedef pcl::PointCloud<PointT> PointCloud; 00071 typedef typename PointCloud::Ptr PointCloudPtr; 00072 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00073 00074 typedef typename pcl::search::Search<PointT> KdTree; 00075 typedef typename pcl::search::Search<PointT>::Ptr KdTreePtr; 00076 00077 typedef PointIndices::Ptr PointIndicesPtr; 00078 typedef PointIndices::ConstPtr PointIndicesConstPtr; 00079 00081 00082 LabeledEuclideanClusterExtraction () : tree_ (), min_pts_per_cluster_ (1), 00083 max_pts_per_cluster_ (std::numeric_limits<int>::max ()), 00084 max_label_ (std::numeric_limits<int>::max ()) 00085 {}; 00086 00090 inline void setSearchMethod (const KdTreePtr &tree) { tree_ = tree; } 00091 00093 inline KdTreePtr getSearchMethod () { return (tree_); } 00094 00098 inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; } 00099 00101 inline double getClusterTolerance () { return (cluster_tolerance_); } 00102 00106 inline void setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; } 00107 00109 inline int getMinClusterSize () { return (min_pts_per_cluster_); } 00110 00114 inline void setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; } 00115 00117 inline int getMaxClusterSize () { return (max_pts_per_cluster_); } 00118 00122 inline void setMaxLabels (unsigned int max_label) { max_label_ = max_label; } 00123 00125 inline unsigned int getMaxLabels () { return (max_label_); } 00126 00130 void extract (std::vector<std::vector<PointIndices> > &labeled_clusters); 00131 00132 protected: 00133 // Members derived from the base class 00134 using BasePCLBase::input_; 00135 using BasePCLBase::indices_; 00136 using BasePCLBase::initCompute; 00137 using BasePCLBase::deinitCompute; 00138 00140 KdTreePtr tree_; 00141 00143 double cluster_tolerance_; 00144 00146 int min_pts_per_cluster_; 00147 00149 int max_pts_per_cluster_; 00150 00152 unsigned int max_label_; 00153 00155 virtual std::string getClassName () const { return ("LabeledEuclideanClusterExtraction"); } 00156 00157 }; 00158 00162 inline bool 00163 compareLabeledPointClusters (const pcl::PointIndices &a, const pcl::PointIndices &b) 00164 { 00165 return (a.indices.size () < b.indices.size ()); 00166 } 00167 } 00168 00169 #endif //#ifndef PCL_EXTRACT_LABELED_CLUSTERS_H_