From 6727894231af3deb562cf2cca3ebec3c86ca53ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 11 Apr 2025 14:30:52 +0200 Subject: [PATCH 1/2] restrict shared vertices on the boundary --- .../remesh_planar_patches.h | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h index 71cba41b6cd..64d93cf5a59 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h @@ -1025,6 +1025,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes, MeshMap mesh_map, const TagFunction& tag_function, const std::vector& vpms, + bool shared_on_boundary_only, bool do_not_triangulate_faces) { typedef typename boost::property_traits::value_type Triangle_mesh; @@ -1092,23 +1093,37 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes, //start by detecting and marking all shared vertices mesh_id = 0; + + auto register_point = + [&vertex_shared_maps, &point_to_vertex_maps, &vpms] + (vertex_descriptor v, std::size_t mesh_id) + { + std::multimap& mesh_id_to_vertex = + point_to_vertex_maps[get(vpms[mesh_id], v)]; + if (!mesh_id_to_vertex.empty()) + put(vertex_shared_maps[mesh_id], v, true); + if (mesh_id_to_vertex.size()==1) + { + std::pair other=*mesh_id_to_vertex.begin(); + put(vertex_shared_maps[other.first], other.second, true); + } + mesh_id_to_vertex.insert( std::make_pair(mesh_id, v) ); + }; + for(Triangle_mesh* tm_ptr : mesh_ptrs) { Triangle_mesh& tm = *tm_ptr; - for(vertex_descriptor v : vertices(tm)) - { - std::multimap& mesh_id_to_vertex = - point_to_vertex_maps[get(vpms[mesh_id], v)]; - if (!mesh_id_to_vertex.empty()) - put(vertex_shared_maps[mesh_id], v, true); - if (mesh_id_to_vertex.size()==1) + if (shared_on_boundary_only) + for(halfedge_descriptor h : halfedges(tm)) { - std::pair other=*mesh_id_to_vertex.begin(); - put(vertex_shared_maps[other.first], other.second, true); + if (!is_border(h,tm)) continue; + vertex_descriptor v = target(h, tm); + register_point(v, mesh_id); } - mesh_id_to_vertex.insert( std::make_pair(mesh_id, v) ); - } + else + for(vertex_descriptor v : vertices(tm)) + register_point(v, mesh_id); ++mesh_id; } @@ -1222,7 +1237,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes, { typedef std::pair Map_pair_type; auto find_res = point_to_vertex_maps.find(corners[cid]); - assert(find_res != point_to_vertex_maps.end()); + if (find_res == point_to_vertex_maps.end()) continue; // the point is not shared for(Map_pair_type& mp : find_res->second) { std::size_t other_mesh_id = mp.first; @@ -1279,6 +1294,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes, MeshMap mesh_map, double coplanar_cos_threshold, const std::vector& vpms, + bool shared_on_boundary_only, bool do_not_triangulate_faces) { typedef typename boost::property_traits::value_type Triangle_mesh; @@ -1300,6 +1316,7 @@ bool decimate_meshes_with_common_interfaces_impl(TriangleMeshRange& meshes, mesh_map, tag_function, vpms, + shared_on_boundary_only, do_not_triangulate_faces); } From 6d1c2da4c8739b96fc4163f301304a3c4f66868c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 11 Apr 2025 16:35:20 +0200 Subject: [PATCH 2/2] update call --- .../CGAL/Polygon_mesh_processing/remesh_planar_patches.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h index 64d93cf5a59..4f61c40c81f 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh_planar_patches.h @@ -1678,7 +1678,7 @@ bool decimate_meshes_with_common_interfaces(TriangleMeshRange& meshes, double co for(Mesh_descriptor& md : meshes) vpms.push_back( get(boost::vertex_point, mesh_map[md]) ); - return Planar_segmentation::decimate_meshes_with_common_interfaces_impl(meshes, mesh_map, coplanar_cos_threshold, vpms, do_not_triangulate_faces); + return Planar_segmentation::decimate_meshes_with_common_interfaces_impl(meshes, mesh_map, coplanar_cos_threshold, vpms, true, do_not_triangulate_faces); } template