// Copyright (c) 2007-09 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Point_set_processing_3/include/CGAL/random_simplify_point_set.h $ // $Id: random_simplify_point_set.h 254d60f 2019-10-19T15:23:19+02:00 Sébastien Loriot // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Laurent Saboret #ifndef CGAL_RANDOM_SIMPLIFY_POINT_SET_H #define CGAL_RANDOM_SIMPLIFY_POINT_SET_H #include #include #include #include #include #include #include #include #include #include #include #include #include namespace CGAL { /** \ingroup PkgPointSetProcessing3Algorithms Randomly deletes a user-specified fraction of the input points. This method modifies the order of input points so as to pack all remaining points first, and returns an iterator over the first point to remove (see erase-remove idiom). For this reason it should not be called on sorted containers. \tparam PointRange is a model of `Range`. \param points input point range. \param removed_percentage percentage of points to remove. \return iterator over the first point to remove. */ template typename PointRange::iterator random_simplify_point_set( PointRange& points, double removed_percentage) { CGAL_point_set_processing_precondition(removed_percentage >= 0 && removed_percentage <= 100); // Random shuffle CGAL::cpp98::random_shuffle (points.begin(), points.end()); // Computes first iterator to remove std::size_t nb_points = std::distance(points.begin(), points.end()); std::size_t first_index_to_remove = (std::size_t)(double(nb_points) * ((100.0-removed_percentage)/100.0)); typename PointRange::iterator first_point_to_remove = points.begin(); std::advance(first_point_to_remove, first_index_to_remove); return first_point_to_remove; } } //namespace CGAL #include #endif // CGAL_RANDOM_SIMPLIFY_POINT_SET_H