20
20
template <typename PointT> void
21
21
pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
22
22
{
23
- const std::size_t size = input_ ->size ();
23
+ const std::size_t size = indices_ ->size ();
24
24
// if requested number of point is equal to the point cloud size, copy original cloud
25
25
if (sample_size_ == size)
26
26
{
@@ -41,22 +41,25 @@ pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
41
41
std::mt19937 random_gen (seed_);
42
42
std::uniform_int_distribution<index_t > dis (0 , size -1 );
43
43
44
+ // lambda to map filter indices back to pointcloud indices for increased readability
45
+ auto toCloudIndex = [this ](const auto idx){return (*indices_)[idx];};
46
+
44
47
// pick the first point at random
45
48
index_t max_index = dis (random_gen);
46
49
distances_to_selected_points[max_index] = -1.0 ;
47
- indices.push_back (max_index);
50
+ indices.push_back (toCloudIndex ( max_index) );
48
51
49
52
for (std::size_t j = 1 ; j < sample_size_; ++j)
50
53
{
51
54
index_t next_max_index = 0 ;
52
55
53
- const PointT& max_index_point = (*input_)[max_index];
56
+ const PointT& max_index_point = (*input_)[toCloudIndex ( max_index) ];
54
57
// recompute distances
55
58
for (std::size_t i = 0 ; i < size; ++i)
56
59
{
57
60
if (distances_to_selected_points[i] == -1.0 )
58
61
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));
60
63
if (distances_to_selected_points[i] > distances_to_selected_points[next_max_index])
61
64
next_max_index = i;
62
65
}
@@ -66,7 +69,7 @@ pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
66
69
// elements are guaranteed to not be selected
67
70
max_index = next_max_index;
68
71
distances_to_selected_points[max_index] = -1.0 ;
69
- indices.push_back (max_index);
72
+ indices.push_back (toCloudIndex ( max_index) );
70
73
// set distance to -1 to ignore during max element search
71
74
}
72
75
@@ -75,7 +78,7 @@ pcl::FarthestPointSampling<PointT>::applyFilter (Indices &indices)
75
78
for (std::size_t k = 0 ; k < distances_to_selected_points.size (); ++k)
76
79
{
77
80
if (distances_to_selected_points[k] != -1.0 )
78
- (*removed_indices_).push_back (k );
81
+ (*removed_indices_).push_back (toCloudIndex (k) );
79
82
}
80
83
}
81
84
}
0 commit comments