38 #ifndef PCL_SEGMENTATION_IMPL_EXTRACT_CLUSTERS_H_
39 #define PCL_SEGMENTATION_IMPL_EXTRACT_CLUSTERS_H_
44 template <
typename Po
intT>
void
47 float tolerance, std::vector<PointIndices> &clusters,
48 unsigned int min_pts_per_cluster,
49 unsigned int max_pts_per_cluster)
51 if (tree->getInputCloud ()->points.size () != cloud.
points.size ())
53 PCL_ERROR (
"[pcl::extractEuclideanClusters] Tree built for a different point cloud dataset (%zu) than the input cloud (%zu)!\n", tree->getInputCloud ()->points.size (), cloud.
points.size ());
57 std::vector<bool> processed (cloud.
points.size (),
false);
59 std::vector<int> nn_indices;
60 std::vector<float> nn_distances;
62 for (
int i = 0; i < static_cast<int> (cloud.
points.size ()); ++i)
67 std::vector<int> seed_queue;
69 seed_queue.push_back (i);
73 while (sq_idx < static_cast<int> (seed_queue.size ()))
76 if (!tree->radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances))
82 for (
size_t j = 1; j < nn_indices.size (); ++j)
84 if (nn_indices[j] == -1 || processed[nn_indices[j]])
88 seed_queue.push_back (nn_indices[j]);
89 processed[nn_indices[j]] =
true;
96 if (seed_queue.size () >= min_pts_per_cluster && seed_queue.size () <= max_pts_per_cluster)
99 r.
indices.resize (seed_queue.size ());
100 for (
size_t j = 0; j < seed_queue.size (); ++j)
108 clusters.push_back (r);
115 template <
typename Po
intT>
void
117 const std::vector<int> &indices,
119 float tolerance, std::vector<PointIndices> &clusters,
120 unsigned int min_pts_per_cluster,
121 unsigned int max_pts_per_cluster)
125 if (tree->getInputCloud ()->points.size () != cloud.
points.size ())
127 PCL_ERROR (
"[pcl::extractEuclideanClusters] Tree built for a different point cloud dataset (%zu) than the input cloud (%zu)!\n", tree->getInputCloud ()->points.size (), cloud.
points.size ());
130 if (tree->getIndices ()->size () != indices.size ())
132 PCL_ERROR (
"[pcl::extractEuclideanClusters] Tree built for a different set of indices (%zu) than the input set (%zu)!\n", tree->getIndices ()->size (), indices.size ());
137 std::vector<bool> processed (cloud.
points.size (),
false);
139 std::vector<int> nn_indices;
140 std::vector<float> nn_distances;
142 for (
int i = 0; i < static_cast<int> (indices.size ()); ++i)
144 if (processed[indices[i]])
147 std::vector<int> seed_queue;
149 seed_queue.push_back (indices[i]);
151 processed[indices[i]] =
true;
153 while (sq_idx < static_cast<int> (seed_queue.size ()))
156 int ret = tree->radiusSearch (cloud.
points[seed_queue[sq_idx]], tolerance, nn_indices, nn_distances);
159 PCL_ERROR(
"[pcl::extractEuclideanClusters] Received error code -1 from radiusSearch\n");
168 for (
size_t j = 1; j < nn_indices.size (); ++j)
170 if (nn_indices[j] == -1 || processed[nn_indices[j]])
174 seed_queue.push_back (nn_indices[j]);
175 processed[nn_indices[j]] =
true;
182 if (seed_queue.size () >= min_pts_per_cluster && seed_queue.size () <= max_pts_per_cluster)
185 r.
indices.resize (seed_queue.size ());
186 for (
size_t j = 0; j < seed_queue.size (); ++j)
196 clusters.push_back (r);
205 template <
typename Po
intT>
void
208 if (!initCompute () ||
209 (input_ != 0 && input_->points.empty ()) ||
210 (indices_ != 0 && indices_->empty ()))
219 if (input_->isOrganized ())
226 tree_->setInputCloud (input_, indices_);
227 extractEuclideanClusters (*input_, *indices_, tree_, static_cast<float> (cluster_tolerance_), clusters, min_pts_per_cluster_, max_pts_per_cluster_);
238 #define PCL_INSTANTIATE_EuclideanClusterExtraction(T) template class PCL_EXPORTS pcl::EuclideanClusterExtraction<T>;
239 #define PCL_INSTANTIATE_extractEuclideanClusters(T) template void PCL_EXPORTS pcl::extractEuclideanClusters<T>(const pcl::PointCloud<T> &, const boost::shared_ptr<pcl::search::Search<T> > &, float , std::vector<pcl::PointIndices> &, unsigned int, unsigned int);
240 #define PCL_INSTANTIATE_extractEuclideanClusters_indices(T) template void PCL_EXPORTS pcl::extractEuclideanClusters<T>(const pcl::PointCloud<T> &, const std::vector<int> &, const boost::shared_ptr<pcl::search::Search<T> > &, float , std::vector<pcl::PointIndices> &, unsigned int, unsigned int);
242 #endif // PCL_EXTRACT_CLUSTERS_IMPL_H_