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>
49 std::vector<std::vector<PointIndices>>& labeled_clusters,
50 unsigned int min_pts_per_cluster,
51 unsigned int max_pts_per_cluster)
54 PCL_ERROR(
"[pcl::extractLabeledEuclideanClusters] Tree built for a different point "
55 "cloud dataset (%lu) than the input cloud (%lu)!\n",
63 std::vector<bool> processed(cloud.
size(),
false);
66 std::vector<float> nn_distances;
69 for (
index_t i = 0; i < static_cast<index_t>(cloud.
size()); ++i) {
75 seed_queue.push_back(i);
79 while (sq_idx < static_cast<int>(seed_queue.size())) {
85 std::numeric_limits<int>::max());
87 PCL_ERROR(
"radiusSearch on tree came back with error -1");
93 for (std::size_t j = nn_start_idx; j < nn_indices.size(); ++j)
95 if (processed[nn_indices[j]])
97 if (cloud[i].label == cloud[nn_indices[j]].label) {
99 seed_queue.push_back(nn_indices[j]);
100 processed[nn_indices[j]] =
true;
108 if (seed_queue.size() >= min_pts_per_cluster &&
109 seed_queue.size() <= max_pts_per_cluster) {
111 r.
indices.resize(seed_queue.size());
112 for (std::size_t j = 0; j < seed_queue.size(); ++j)
118 labeled_clusters[cloud[i].label].push_back(
127 template <
typename Po
intT>
130 std::vector<std::vector<PointIndices>>& labeled_clusters)
132 if (!initCompute() || (input_ && input_->empty()) ||
133 (indices_ && indices_->empty())) {
134 labeled_clusters.clear();
140 if (input_->isOrganized())
147 tree_->setInputCloud(input_);
150 static_cast<float>(cluster_tolerance_),
152 min_pts_per_cluster_,
153 max_pts_per_cluster_);
156 for (
auto& labeled_cluster : labeled_clusters)
162 #define PCL_INSTANTIATE_LabeledEuclideanClusterExtraction(T) \
163 template class PCL_EXPORTS pcl::LabeledEuclideanClusterExtraction<T>;
164 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters(T) \
165 template void PCL_EXPORTS pcl::extractLabeledEuclideanClusters<T>( \
166 const pcl::PointCloud<T>&, \
167 const typename pcl::search::Search<T>::Ptr&, \
169 std::vector<std::vector<pcl::PointIndices>>&, \
173 #endif // PCL_EXTRACT_CLUSTERS_IMPL_H_
virtual bool getSortedResults()
Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results ma...
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.
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())
Decompose a region of space into clusters based on the Euclidean distance between points...
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
virtual PointCloudConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
IndicesAllocator<> Indices
Type used for indices in PCL.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
pcl::PCLHeader header
The point cloud header.
OrganizedNeighbor is a class for optimized nearest neighbor search in organized projectable point clo...
shared_ptr< pcl::search::Search< PointT > > Ptr