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::extractLabeledEuclideanClusters<PointT>(cloud,
62 template <
typename Po
intT>
68 std::vector<std::vector<PointIndices>>& labeled_clusters,
69 unsigned int min_pts_per_cluster,
70 unsigned int max_pts_per_cluster)
73 PCL_ERROR(
"[pcl::extractLabeledEuclideanClusters] Tree built for a different point "
74 "cloud dataset (%lu) than the input cloud (%lu)!\n",
80 std::vector<bool> processed(cloud.
size(),
false);
83 std::vector<float> nn_distances;
86 for (
index_t i = 0; i < static_cast<index_t>(cloud.
size()); ++i) {
92 seed_queue.push_back(i);
96 while (sq_idx <
static_cast<int>(seed_queue.size())) {
102 std::numeric_limits<int>::max());
104 PCL_ERROR(
"radiusSearch on tree came back with error -1");
110 for (std::size_t j = 1; j < nn_indices.size();
113 if (processed[nn_indices[j]])
115 if (cloud[i].label == cloud[nn_indices[j]].label) {
117 seed_queue.push_back(nn_indices[j]);
118 processed[nn_indices[j]] =
true;
126 if (seed_queue.size() >= min_pts_per_cluster &&
127 seed_queue.size() <= max_pts_per_cluster) {
129 r.
indices.resize(seed_queue.size());
130 for (std::size_t j = 0; j < seed_queue.size(); ++j)
137 labeled_clusters[cloud[i].label].push_back(
146 template <
typename Po
intT>
149 std::vector<std::vector<PointIndices>>& labeled_clusters)
151 if (!initCompute() || (input_ && input_->empty()) ||
152 (indices_ && indices_->empty())) {
153 labeled_clusters.clear();
159 if (input_->isOrganized())
166 tree_->setInputCloud(input_);
169 static_cast<float>(cluster_tolerance_),
171 min_pts_per_cluster_,
172 max_pts_per_cluster_);
175 for (
auto& labeled_cluster : labeled_clusters)
181 #define PCL_INSTANTIATE_LabeledEuclideanClusterExtraction(T) \
182 template class PCL_EXPORTS pcl::LabeledEuclideanClusterExtraction<T>;
183 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters_deprecated(T) \
184 template void PCL_EXPORTS pcl::extractLabeledEuclideanClusters<T>( \
185 const pcl::PointCloud<T>&, \
186 const typename pcl::search::Search<T>::Ptr&, \
188 std::vector<std::vector<pcl::PointIndices>>&, \
192 #define PCL_INSTANTIATE_extractLabeledEuclideanClusters(T) \
193 template void PCL_EXPORTS pcl::extractLabeledEuclideanClusters<T>( \
194 const pcl::PointCloud<T>&, \
195 const typename pcl::search::Search<T>::Ptr&, \
197 std::vector<std::vector<pcl::PointIndices>>&, \
201 #endif // PCL_EXTRACT_CLUSTERS_IMPL_H_