42 #include <pcl/console/print.h>
43 #include <pcl/pcl_base.h>
45 #include <pcl/search/search.h>
46 #include <pcl/search/kdtree.h>
61 template <
typename Po
intT>
void
64 float tolerance, std::vector<PointIndices> &clusters,
65 unsigned int min_pts_per_cluster = 1,
unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ());
79 template <
typename Po
intT>
void
83 unsigned int min_pts_per_cluster = 1,
unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ());
102 template <
typename Po
intT,
typename Normal>
void
106 std::vector<PointIndices> &clusters,
double eps_angle,
107 unsigned int min_pts_per_cluster = 1,
108 unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ())
112 PCL_ERROR(
"[pcl::extractEuclideanClusters] Tree built for a different point "
113 "cloud dataset (%zu) than the input cloud (%zu)!\n",
115 static_cast<std::size_t
>(cloud.
size()));
118 if (cloud.
size () != normals.
size ())
120 PCL_ERROR(
"[pcl::extractEuclideanClusters] Number of points in the input point "
121 "cloud (%zu) different than normals (%zu)!\n",
122 static_cast<std::size_t
>(cloud.
size()),
123 static_cast<std::size_t
>(normals.
size()));
126 const double cos_eps_angle = std::cos (eps_angle);
129 std::vector<bool> processed (cloud.
size (),
false);
132 std::vector<float> nn_distances;
134 for (std::size_t i = 0; i < cloud.
size (); ++i)
141 seed_queue.push_back (
static_cast<index_t> (i));
145 while (sq_idx <
static_cast<int> (seed_queue.size ()))
148 if (!tree->
radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances))
154 for (std::size_t j = 1; j < nn_indices.size (); ++j)
156 if (processed[nn_indices[j]])
161 double dot_p = normals[seed_queue[sq_idx]].normal[0] * normals[nn_indices[j]].normal[0] +
162 normals[seed_queue[sq_idx]].normal[1] * normals[nn_indices[j]].normal[1] +
163 normals[seed_queue[sq_idx]].normal[2] * normals[nn_indices[j]].normal[2];
164 if ( std::abs (dot_p) > cos_eps_angle )
166 processed[nn_indices[j]] =
true;
175 if (seed_queue.size () >= min_pts_per_cluster && seed_queue.size () <= max_pts_per_cluster)
178 r.
indices.resize (seed_queue.size ());
179 for (std::size_t j = 0; j < seed_queue.size (); ++j)
187 clusters.push_back (r);
211 template <
typename Po
intT,
typename Normal>
215 float tolerance, std::vector<PointIndices> &clusters,
double eps_angle,
216 unsigned int min_pts_per_cluster = 1,
217 unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ())
222 PCL_ERROR(
"[pcl::extractEuclideanClusters] Tree built for a different point "
223 "cloud dataset (%zu) than the input cloud (%zu)!\n",
225 static_cast<std::size_t
>(cloud.
size()));
228 if (tree->
getIndices()->size() != indices.size()) {
229 PCL_ERROR(
"[pcl::extractEuclideanClusters] Tree built for a different set of "
230 "indices (%zu) than the input set (%zu)!\n",
231 static_cast<std::size_t
>(tree->
getIndices()->size()),
235 if (cloud.
size() != normals.
size()) {
236 PCL_ERROR(
"[pcl::extractEuclideanClusters] Number of points in the input point "
237 "cloud (%zu) different than normals (%zu)!\n",
238 static_cast<std::size_t
>(cloud.
size()),
239 static_cast<std::size_t
>(normals.
size()));
242 const double cos_eps_angle = std::cos (eps_angle);
244 std::vector<bool> processed (cloud.
size (),
false);
247 std::vector<float> nn_distances;
249 for (std::size_t i = 0; i < indices.size (); ++i)
251 if (processed[indices[i]])
256 seed_queue.push_back (indices[i]);
258 processed[indices[i]] =
true;
260 while (sq_idx <
static_cast<int> (seed_queue.size ()))
263 if (!tree->
radiusSearch (cloud[seed_queue[sq_idx]], tolerance, nn_indices, nn_distances))
269 for (std::size_t j = 1; j < nn_indices.size (); ++j)
271 if (processed[nn_indices[j]])
276 double dot_p = normals[seed_queue[sq_idx]].normal[0] * normals[nn_indices[j]].normal[0] +
277 normals[seed_queue[sq_idx]].normal[1] * normals[nn_indices[j]].normal[1] +
278 normals[seed_queue[sq_idx]].normal[2] * normals[nn_indices[j]].normal[2];
279 if ( std::abs (dot_p) > cos_eps_angle )
281 processed[nn_indices[j]] =
true;
290 if (seed_queue.size () >= min_pts_per_cluster && seed_queue.size () <= max_pts_per_cluster)
293 r.
indices.resize (seed_queue.size ());
294 for (std::size_t j = 0; j < seed_queue.size (); ++j)
302 clusters.push_back (r);
314 template <
typename Po
intT>
408 extract (std::vector<PointIndices> &clusters);
430 virtual std::string
getClassName ()
const {
return (
"EuclideanClusterExtraction"); }
444 #ifdef PCL_NO_PRECOMPILE
445 #include <pcl/segmentation/impl/extract_clusters.hpp>