From 2d1a77cd67523a00cc1ba2d528232c9aaaec76ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 13 May 2025 14:49:46 +0200 Subject: [PATCH] be more permissive and allow duplicated points --- .../polygon_soup_self_intersections.h | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_self_intersections.h index d9a2f779991..3c3f37cfa5c 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/polygon_soup_self_intersections.h @@ -19,6 +19,9 @@ #include #include +#include + +#include namespace CGAL::Polygon_mesh_processing { @@ -27,16 +30,28 @@ template bool does_polygon_soup_self_intersect(const PointRange& points, - const PolygonRange& polygons, + PolygonRange polygons, const CGAL_NP_CLASS& np = parameters::default_values()) { + //let's be a bit more permissive and allow duplicated vertices + auto pm = parameters::choose_parameter::const_type>(parameters::get_parameter(np, internal_np::point_map)); + using Point_3 = typename boost::property_traits::value_type; + using PointRange_const_iterator = typename PointRange::const_iterator; + using PointRange_value_type = typename std::iterator_traits::value_type; + auto to_point =[pm](const PointRange_value_type& v) { return get(pm, v); }; + + std::vector unique_points(boost::make_transform_iterator(points.begin(), to_point), + boost::make_transform_iterator(points.end(), to_point)); + + merge_duplicate_points_in_polygon_soup(unique_points, polygons); + bool is_pure_triangles = std::all_of(polygons.begin(), polygons.end(), [](const auto&f) { return f.size() == 3; }); if(is_pure_triangles) { // if the polygon soup is pure triangles, // we can use the triangle soup self-intersection function - return does_triangle_soup_self_intersect(points, polygons, np); + return does_triangle_soup_self_intersect(unique_points, polygons); } // otherwise, we need to triangulate the polygons beforehand @@ -53,7 +68,7 @@ bool does_polygon_soup_self_intersect(const PointRange& points, if (!OK) return false; - return does_triangle_soup_self_intersect(points, triangles, np); + return does_triangle_soup_self_intersect(unique_points, triangles, np); } } // namespace CGAL::Polygon_mesh_processing