Merge pull request #6130 from cjamin/patch-1

Bug fix: `remove_outliers` was removing ALL points when no outliers were found
This commit is contained in:
Laurent Rineau 2021-11-25 17:28:39 +01:00
commit 17a7d8cfbc
1 changed files with 26 additions and 22 deletions

View File

@ -247,33 +247,37 @@ remove_outliers(
if (threshold_distance != FT(0)) if (threshold_distance != FT(0))
f2r = std::partition (sorted_points.begin(), sorted_points.end(), f2r = std::partition (sorted_points.begin(), sorted_points.end(),
[&threshold_distance](const std::pair<FT, value_type>& p) -> bool [sq_threshold_distance = CGAL::square(threshold_distance)](const std::pair<FT, value_type>& p) -> bool
{ {
return p.first < threshold_distance * threshold_distance; return p.first < sq_threshold_distance;
}); });
if (static_cast<std::size_t>(std::distance (sorted_points.begin(), f2r)) < first_index_to_remove) iterator out = points.end();
{
std::nth_element (f2r,
sorted_points.begin() + first_index_to_remove,
sorted_points.end(),
[](const std::pair<FT, value_type>& v1, const std::pair<FT, value_type>& v2)
{
return v1.first<v2.first;
});
f2r = sorted_points.begin() + first_index_to_remove;
}
// Replaces [points.begin(), points.end()) range by the sorted content. if (f2r != sorted_points.end())
iterator pit = points.begin();
iterator out = points.begin();
for (auto sit = sorted_points.begin(); sit != sorted_points.end(); ++ sit)
{ {
*pit = sit->second; if (static_cast<std::size_t>(std::distance (sorted_points.begin(), f2r)) < first_index_to_remove)
if (sit == f2r) {
out = pit; std::nth_element (f2r,
++ pit; sorted_points.begin() + first_index_to_remove,
sorted_points.end(),
[](const std::pair<FT, value_type>& v1, const std::pair<FT, value_type>& v2)
{
return v1.first<v2.first;
});
f2r = sorted_points.begin() + first_index_to_remove;
}
// Replaces [points.begin(), points.end()) range by the sorted content.
iterator pit = points.begin();
for (auto sit = sorted_points.begin(); sit != sorted_points.end(); ++ sit)
{
*pit = sit->second;
if (sit == f2r)
out = pit;
++ pit;
}
} }
callback_wrapper.join(); callback_wrapper.join();