37 #ifndef PCL_SEGMENTATION_IMPL_CONDITIONAL_EUCLIDEAN_CLUSTERING_HPP_
38 #define PCL_SEGMENTATION_IMPL_CONDITIONAL_EUCLIDEAN_CLUSTERING_HPP_
40 #include <pcl/segmentation/conditional_euclidean_clustering.h>
41 #include <pcl/search/organized.h>
42 #include <pcl/search/kdtree.h>
44 template<
typename Po
intT>
void
49 if (extract_removed_clusters_)
51 small_clusters_->clear ();
52 large_clusters_->clear ();
56 if (!initCompute () || input_->points.empty () || indices_->empty () || !condition_function_)
62 if (input_->isOrganized ())
67 searcher_->setInputCloud (input_, indices_);
71 std::vector<float> nn_distances;
75 std::vector<bool> processed (input_->size (),
false);
78 for (
const auto& iindex : (*indices_))
81 if (iindex == UNAVAILABLE || processed[iindex])
89 current_cluster.push_back (iindex);
90 processed[iindex] =
true;
93 while (cii <
static_cast<int> (current_cluster.size ()))
96 if (searcher_->radiusSearch ((*input_)[current_cluster[cii]], cluster_tolerance_, nn_indices, nn_distances) < 1)
103 for (
int nii = 1; nii < static_cast<int> (nn_indices.size ()); ++nii)
106 if (nn_indices[nii] == UNAVAILABLE || processed[nn_indices[nii]])
110 if (condition_function_ ((*input_)[current_cluster[cii]], (*input_)[nn_indices[nii]], nn_distances[nii]))
113 current_cluster.push_back (nn_indices[nii]);
114 processed[nn_indices[nii]] =
true;
121 if (extract_removed_clusters_ ||
122 (
static_cast<int> (current_cluster.size ()) >= min_cluster_size_ &&
123 static_cast<int> (current_cluster.size ()) <= max_cluster_size_))
126 pi.
header = input_->header;
127 pi.
indices.resize (current_cluster.size ());
128 for (
int ii = 0; ii < static_cast<int> (current_cluster.size ()); ++ii)
129 pi.
indices[ii] = current_cluster[ii];
131 if (extract_removed_clusters_ &&
static_cast<int> (current_cluster.size ()) < min_cluster_size_)
132 small_clusters_->push_back (pi);
133 else if (extract_removed_clusters_ &&
static_cast<int> (current_cluster.size ()) > max_cluster_size_)
134 large_clusters_->push_back (pi);
136 clusters.push_back (pi);
143 #define PCL_INSTANTIATE_ConditionalEuclideanClustering(T) template class PCL_EXPORTS pcl::ConditionalEuclideanClustering<T>;
void segment(IndicesClusters &clusters)
Segment the input into separate clusters.
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
OrganizedNeighbor is a class for optimized nearest neighbor search in organized point clouds.
IndicesAllocator<> Indices
Type used for indices in PCL.
std::vector< pcl::PointIndices > IndicesClusters