13 #include <pcl/filters/farthest_point_sampling.h>
14 #include <pcl/point_cloud.h>
20 template<
typename Po
intT>
void
23 const std::size_t size = input_->size();
25 if (sample_size_ == size)
28 removed_indices_->clear ();
32 if (sample_size_ > size)
35 "Requested number of points is greater than point cloud size!");
38 std::vector<float> distances_to_selected_points (size, std::numeric_limits<float>::max ());
41 std::mt19937 random_gen(seed_);
42 std::uniform_int_distribution<index_t> dis(0, size -1);
45 index_t max_index = dis(random_gen);
46 distances_to_selected_points[max_index] = -1.0;
47 indices.push_back(max_index);
49 for (std::size_t j = 1; j < sample_size_; ++j)
53 const PointT& max_index_point = (*input_)[max_index];
55 for (std::size_t i = 0; i < size; ++i)
57 if (distances_to_selected_points[i] == -1.0)
59 distances_to_selected_points[i] = std::min(distances_to_selected_points[i],
geometry::distance((*input_)[i], max_index_point));
60 if (distances_to_selected_points[i] > distances_to_selected_points[next_max_index])
67 max_index = next_max_index;
68 distances_to_selected_points[max_index] = -1.0;
69 indices.push_back(max_index);
73 if (extract_removed_indices_)
75 for (std::size_t k = 0; k < distances_to_selected_points.size(); ++k)
77 if (distances_to_selected_points[k] != -1.0)
78 (*removed_indices_).push_back(k);
83 #define PCL_INSTANTIATE_FarthestPointSampling(T) template class PCL_EXPORTS pcl::FarthestPointSampling<T>;
An exception that is thrown when the arguments number or type is wrong/unhandled.
void applyFilter(pcl::Indices &indices) override
Sample of point indices.
Defines some geometrical functions and utility functions.
Defines all the PCL implemented PointT point type structures.
float distance(const PointT &p1, const PointT &p2)
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
IndicesAllocator<> Indices
Type used for indices in PCL.
A point structure representing Euclidean xyz coordinates, and the RGB color.