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,
54 PCL_ERROR(
"[pcl::extractLabeledEuclideanClusters] Tree built for a different point " 55 "cloud dataset (%zu) than the input cloud (%zu)!\n",
57 static_cast<std::size_t>(cloud.
size()));
61 std::vector<bool> processed (cloud.
size (),
false);
63 std::vector<int> nn_indices;
64 std::vector<float> nn_distances;
67 for (
int i = 0; i < static_cast<int> (cloud.
size ()); ++i)
72 std::vector<int> seed_queue;
74 seed_queue.push_back (i);
78 while (sq_idx < static_cast<int> (seed_queue.size ()))
81 int ret = tree->
radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances, std::numeric_limits<int>::max());
83 PCL_ERROR(
"radiusSearch on tree came back with error -1");
90 for (std::size_t j = 1; j < nn_indices.size (); ++j)
92 if (processed[nn_indices[j]])
94 if (cloud[i].label == cloud[nn_indices[j]].label)
97 seed_queue.push_back (nn_indices[j]);
98 processed[nn_indices[j]] =
true;
106 if (seed_queue.size () >= min_pts_per_cluster && seed_queue.size () <= max_pts_per_cluster)
109 r.
indices.resize (seed_queue.size ());
110 for (std::size_t j = 0; j < seed_queue.size (); ++j)
117 labeled_clusters[cloud[i].label].push_back (r);
125 template <
typename Po
intT>
void 128 if (!initCompute () ||
129 (input_ && input_->points.empty ()) ||
130 (indices_ && indices_->empty ()))
132 labeled_clusters.clear ();
139 if (input_->isOrganized ())
146 tree_->setInputCloud (input_);
147 extractLabeledEuclideanClusters (*input_, tree_, static_cast<float> (cluster_tolerance_), labeled_clusters, min_pts_per_cluster_, max_pts_per_cluster_, max_label_);
150 for (
auto &labeled_cluster : labeled_clusters)
156 #define PCL_INSTANTIATE_LabeledEuclideanClusterExtraction(T) template class PCL_EXPORTS pcl::LabeledEuclideanClusterExtraction<T>; 157 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters(T) template void PCL_EXPORTS pcl::extractLabeledEuclideanClusters<T>(const pcl::PointCloud<T> &, const typename pcl::search::Search<T>::Ptr &, float , std::vector<std::vector<pcl::PointIndices> > &, unsigned int, unsigned int, unsigned int); 159 #endif // PCL_EXTRACT_CLUSTERS_IMPL_H_
virtual int radiusSearch(const PointT &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const =0
Search for all the nearest neighbors of the query point in a given radius.
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
void extractLabeledEuclideanClusters(const PointCloud< PointT > &cloud, const typename search::Search< PointT >::Ptr &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...
PointCloud represents the base class in PCL for storing collections of 3D points. ...
pcl::PCLHeader header
The point cloud header.
virtual PointCloudConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
OrganizedNeighbor is a class for optimized nearest neigbhor search in organized point clouds...
shared_ptr< pcl::search::Search< PointT > > Ptr