37 #ifndef PCL_SEGMENTATION_IMPL_EXTRACT_LABELED_CLUSTERS_H_
38 #define PCL_SEGMENTATION_IMPL_EXTRACT_LABELED_CLUSTERS_H_
40 #include <pcl/segmentation/extract_labeled_clusters.h>
43 template <
typename Po
intT>
void
47 std::vector<std::vector<PointIndices> > &labeled_clusters,
48 unsigned int min_pts_per_cluster,
49 unsigned int max_pts_per_cluster,
52 if (tree->getInputCloud ()->points.size () != cloud.
points.size ())
54 PCL_ERROR (
"[pcl::extractLabeledEuclideanClusters] Tree built for a different point cloud dataset (%lu) than the input cloud (%lu)!\n", tree->getInputCloud ()->points.size (), cloud.
points.size ());
58 std::vector<bool> processed (cloud.
points.size (),
false);
60 std::vector<int> nn_indices;
61 std::vector<float> nn_distances;
64 for (
int i = 0; i < static_cast<int> (cloud.
points.size ()); ++i)
69 std::vector<int> seed_queue;
71 seed_queue.push_back (i);
75 while (sq_idx < static_cast<int> (seed_queue.size ()))
78 int ret = tree->radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances, std::numeric_limits<int>::max());
80 PCL_ERROR(
"radiusSearch on tree came back with error -1");
87 for (
size_t j = 1; j < nn_indices.size (); ++j)
89 if (processed[nn_indices[j]])
91 if (cloud.
points[i].label == cloud.
points[nn_indices[j]].label)
94 seed_queue.push_back (nn_indices[j]);
95 processed[nn_indices[j]] =
true;
103 if (seed_queue.size () >= min_pts_per_cluster && seed_queue.size () <= max_pts_per_cluster)
106 r.
indices.resize (seed_queue.size ());
107 for (
size_t j = 0; j < seed_queue.size (); ++j)
114 labeled_clusters[cloud.
points[i].label].push_back (r);
122 template <
typename Po
intT>
void
125 if (!initCompute () ||
126 (input_ != 0 && input_->points.empty ()) ||
127 (indices_ != 0 && indices_->empty ()))
129 labeled_clusters.clear ();
136 if (input_->isOrganized ())
143 tree_->setInputCloud (input_);
144 extractLabeledEuclideanClusters (*input_, tree_, static_cast<float> (cluster_tolerance_), labeled_clusters, min_pts_per_cluster_, max_pts_per_cluster_, max_label_);
147 for (
int i = 0; i < static_cast<int> (labeled_clusters.size ()); i++)
153 #define PCL_INSTANTIATE_LabeledEuclideanClusterExtraction(T) template class PCL_EXPORTS pcl::LabeledEuclideanClusterExtraction<T>;
154 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters(T) template void PCL_EXPORTS pcl::extractLabeledEuclideanClusters<T>(const pcl::PointCloud<T> &, const boost::shared_ptr<pcl::search::Search<T> > &, float , std::vector<std::vector<pcl::PointIndices> > &, unsigned int, unsigned int, unsigned int);
156 #endif // PCL_EXTRACT_CLUSTERS_IMPL_H_
std::vector< int > indices
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
OrganizedNeighbor is a class for optimized nearest neigbhor search in organized point clouds...
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< unsigned int >::max(), unsigned int max_label=std::numeric_limits< unsigned int >::max())
Decompose a region of space into clusters based on the Euclidean distance between points...
pcl::PCLHeader header
The point cloud header.