Skip to content

Commit c9a1750

Browse files
authored
Make FarthestPointFilter respect user supplied indices (#6286)
* changed behavior to index into user indices instead of total pointcloud * made index mapping lambda take auto parameter
1 parent 88d832b commit c9a1750

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

filters/include/pcl/filters/impl/farthest_point_sampling.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
template<typename PointT> void
2121
pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
2222
{
23-
const std::size_t size = input_->size();
23+
const std::size_t size = indices_->size();
2424
//if requested number of point is equal to the point cloud size, copy original cloud
2525
if (sample_size_ == size)
2626
{
@@ -41,22 +41,25 @@ pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
4141
std::mt19937 random_gen(seed_);
4242
std::uniform_int_distribution<index_t> dis(0, size -1);
4343

44+
//lambda to map filter indices back to pointcloud indices for increased readability
45+
auto toCloudIndex = [this](const auto idx){return (*indices_)[idx];};
46+
4447
//pick the first point at random
4548
index_t max_index = dis(random_gen);
4649
distances_to_selected_points[max_index] = -1.0;
47-
indices.push_back(max_index);
50+
indices.push_back(toCloudIndex(max_index));
4851

4952
for (std::size_t j = 1; j < sample_size_; ++j)
5053
{
5154
index_t next_max_index = 0;
5255

53-
const PointT& max_index_point = (*input_)[max_index];
56+
const PointT& max_index_point = (*input_)[toCloudIndex(max_index)];
5457
//recompute distances
5558
for (std::size_t i = 0; i < size; ++i)
5659
{
5760
if (distances_to_selected_points[i] == -1.0)
5861
continue;
59-
distances_to_selected_points[i] = std::min(distances_to_selected_points[i], geometry::distance((*input_)[i], max_index_point));
62+
distances_to_selected_points[i] = std::min(distances_to_selected_points[i], geometry::distance((*input_)[toCloudIndex(i)], max_index_point));
6063
if (distances_to_selected_points[i] > distances_to_selected_points[next_max_index])
6164
next_max_index = i;
6265
}
@@ -66,7 +69,7 @@ pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
6669
//elements are guaranteed to not be selected
6770
max_index = next_max_index;
6871
distances_to_selected_points[max_index] = -1.0;
69-
indices.push_back(max_index);
72+
indices.push_back(toCloudIndex(max_index));
7073
//set distance to -1 to ignore during max element search
7174
}
7275

@@ -75,7 +78,7 @@ pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
7578
for (std::size_t k = 0; k < distances_to_selected_points.size(); ++k)
7679
{
7780
if (distances_to_selected_points[k] != -1.0)
78-
(*removed_indices_).push_back(k);
81+
(*removed_indices_).push_back(toCloudIndex(k));
7982
}
8083
}
8184
}

0 commit comments

Comments
 (0)