From 6cdf3f256f9bc7a010d079733d68e4f9948005d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 13 Sep 2022 11:14:33 +0200 Subject: [PATCH] Complete array-based polygon soup reparation: remove more invalid faces --- .../repair_polygon_soup.h | 72 ++++++++++++++++++- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h index 219a4925c24..184eb144521 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_polygon_soup.h @@ -345,6 +345,66 @@ std::size_t remove_invalid_polygons_in_polygon_soup(PointRange& /*points*/, return removed_polygons_n; } +// \ingroup PMP_repairing_grp +// +// Removes invalid array-based polygons, i.e. polygons which have two equal consecutive points. +// +// \tparam PointRange a model of the concept `Container` whose value type is the point type. +// \tparam PolygonRange a model of the concept `SequenceContainer` +// whose value_type is `std::array` with `N`. +// \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" +// +// \param points points of the soup of polygons. +// \param polygons a vector of polygons. Each element in the vector describes a polygon +// using the indices of the points in `points`. +// +template +std::size_t remove_invalid_polygons_in_array_polygon_soup(PointRange& points, + PolygonRange& polygons, + const Traits& traits = Traits()) +{ + typedef typename internal::Polygon_types::Polygon_3 Polygon_3; + + std::vector to_remove; + const std::size_t ini_polygons_size = polygons.size(); + for(std::size_t polygon_index=0; polygon_index!=ini_polygons_size; ++polygon_index) + { + const Polygon_3& polygon = polygons[polygon_index]; + const std::size_t N = polygon.size(), last = N-1; + CGAL_assertion(N > 2); + + for(std::size_t i=0; i 0) + std::cout << "Removed " << removed_polygons_n << " invalid polygon(s)" << std::endl; +#endif + + return removed_polygons_n; +} + } // end namespace internal /// \ingroup PMP_repairing_grp @@ -1031,15 +1091,21 @@ struct Polygon_soup_fixer > PolygonRange& polygons, const NamedParameters& np) const { - #ifdef CGAL_PMP_REPAIR_POLYGON_SOUP_VERBOSE + using parameters::get_parameter; + using parameters::choose_parameter; + + typedef typename GetPolygonGeomTraits::type Traits; + Traits traits = choose_parameter(get_parameter(np, internal_np::geom_traits), Traits()); + +#ifdef CGAL_PMP_REPAIR_POLYGON_SOUP_VERBOSE std::cout << "Repairing soup with " << points.size() << " points and " << polygons.size() << " arrays" << std::endl; - #endif +#endif merge_duplicate_points_in_polygon_soup(points, polygons, np); // skipped steps: // simplify_polygons_in_polygon_soup(points, polygons, traits); // split_pinched_polygons_in_polygon_soup(points, polygons, traits); - remove_invalid_polygons_in_polygon_soup(points, polygons); + remove_invalid_polygons_in_array_polygon_soup(points, polygons, traits); merge_duplicate_polygons_in_polygon_soup(points, polygons, np); remove_isolated_points_in_polygon_soup(points, polygons); }