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_);
69 const int nn_start_idx = searcher_->getSortedResults () ? 1 : 0;
73 std::vector<float> nn_distances;
77 std::vector<bool> processed (input_->size (),
false);
80 for (
const auto& iindex : (*indices_))
83 if (iindex == UNAVAILABLE || processed[iindex])
91 current_cluster.push_back (iindex);
92 processed[iindex] =
true;
95 while (cii <
static_cast<int> (current_cluster.size ()))
98 if (searcher_->radiusSearch ((*input_)[current_cluster[cii]], cluster_tolerance_, nn_indices, nn_distances) < 1)
105 for (
int nii = nn_start_idx; nii < static_cast<int> (nn_indices.size ()); ++nii)
108 if (nn_indices[nii] == UNAVAILABLE || processed[nn_indices[nii]])
112 if (condition_function_ ((*input_)[current_cluster[cii]], (*input_)[nn_indices[nii]], nn_distances[nii]))
115 current_cluster.push_back (nn_indices[nii]);
116 processed[nn_indices[nii]] =
true;
123 if (extract_removed_clusters_ ||
124 (
static_cast<int> (current_cluster.size ()) >= min_cluster_size_ &&
125 static_cast<int> (current_cluster.size ()) <= max_cluster_size_))
128 pi.
header = input_->header;
129 pi.
indices.resize (current_cluster.size ());
130 for (
int ii = 0; ii < static_cast<int> (current_cluster.size ()); ++ii)
131 pi.
indices[ii] = current_cluster[ii];
133 if (extract_removed_clusters_ &&
static_cast<int> (current_cluster.size ()) < min_cluster_size_)
134 small_clusters_->push_back (pi);
135 else if (extract_removed_clusters_ &&
static_cast<int> (current_cluster.size ()) > max_cluster_size_)
136 large_clusters_->push_back (pi);
138 clusters.push_back (pi);
145 #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 projectable point clo...
IndicesAllocator<> Indices
Type used for indices in PCL.
std::vector< pcl::PointIndices > IndicesClusters