diff --git a/Point_set_processing_3/examples/Point_set_processing_3/remove_outliers_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/remove_outliers_example.cpp index 88b2b105450..1ebb0ec6355 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/remove_outliers_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/remove_outliers_example.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -28,11 +29,38 @@ int main(int argc, char*argv[]) // Removes outliers using erase-remove idiom. // The Identity_property_map property map can be omitted here as it is the default value. - const double removed_percentage = 5.0; // percentage of points to remove const int nb_neighbors = 24; // considers 24 nearest neighbor points + + // Estimate scale of the point set with average spacing + const double average_spacing = CGAL::compute_average_spacing + (points.begin(), points.end(), nb_neighbors); + + ////////////////// + // FIRST OPTION // + // I don't know the ratio of outliers present in the point set + std::vector::iterator first_to_remove + = CGAL::remove_outliers(points.begin(), points.end(), + CGAL::Identity_property_map(), + nb_neighbors, + 0., // No minimum percentage to remove + 2. * average_spacing); // Point with distance above 2*average_spacing are considered outliers + + + std::cerr << (100. * std::distance(first_to_remove, points.end()) / (double)(points.size())) + << "% of the points are considered outliers when using a distance threshold of " + << 2. * average_spacing << std::endl; + + + /////////////////// + // SECOND OPTION // + // I know the ratio of outliers present in the point set + const double removed_percentage = 5.0; // percentage of points to remove + points.erase(CGAL::remove_outliers(points.begin(), points.end(), CGAL::Identity_property_map(), - nb_neighbors, removed_percentage), + nb_neighbors, + removed_percentage, // Minimum percentage to remove + 0.), // No distance threshold (can be omitted) points.end()); // Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity