From c587df44a61e34e554f322ffd3bdf0115e012dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 24 Feb 2023 14:45:01 +0100 Subject: [PATCH] fix correspondance between faces --- .../CGAL/boost/graph/internal/helpers.h | 1 - .../remesh_planar_patches.h | 82 ++++++++++++++----- .../PMP/Remesh_planar_patches_plugin.cpp | 22 ++++- 3 files changed, 79 insertions(+), 26 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/internal/helpers.h b/BGL/include/CGAL/boost/graph/internal/helpers.h index 4da0e59a63c..2a143e0b5cd 100644 --- a/BGL/include/CGAL/boost/graph/internal/helpers.h +++ b/BGL/include/CGAL/boost/graph/internal/helpers.h @@ -222,7 +222,6 @@ namespace impl { put(map, pair.first, pair.second); } - }; template 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 adaeb496759..c386b2abdf9 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 @@ -37,6 +37,48 @@ namespace Polygon_mesh_processing { namespace Planar_segmentation{ +template +struct Face_map +{ + typedef typename boost::property_traits::value_type key_type; + typedef typename boost::property_traits::key_type value_type; + typedef value_type reference; + typedef boost::writable_property_map_tag category; + + Face_map(PM pm, const std::vector& triangle_ids) + : pm(pm) + , triangle_ids(triangle_ids) + {} + + friend + void put(Face_map m, key_type k, value_type v) + { + put(m.pm, v, m.triangle_ids[k]); + } + + PM pm; + const std::vector& triangle_ids; +}; + +template +struct Vertex_map +{ + typedef typename boost::property_traits::value_type key_type; + typedef typename boost::property_traits::key_type value_type; + typedef value_type reference; + typedef boost::writable_property_map_tag category; + + Vertex_map(PM pm) : pm(pm) {} + + friend + void put(Vertex_map m, key_type k, value_type v) + { + put(m.pm, v, k); + } + + PM pm; +}; + template struct Default_visitor { @@ -49,29 +91,26 @@ struct Triangle_index_tracker_base typedef boost::graph_traits GT; Triangle_index_tracker_base(VertexCornerMapOut vertex_corner_map) - : vertex_corner_map(vertex_corner_map) + : m_v2v2_map(vertex_corner_map) {} - decltype(auto) - v2v_oi() + Vertex_map v2v_map() { - auto l = [this](const std::pair& p) - { - put(vertex_corner_map, p.second, p.first); - }; - return boost::make_function_output_iterator(l); + return m_v2v2_map; } - VertexCornerMapOut vertex_corner_map; + Vertex_map m_v2v2_map; }; template struct Triangle_index_tracker_base { typedef boost::graph_traits GT; + using Vmap = Constant_property_map::vertex_descriptor>; Triangle_index_tracker_base(internal_np::Param_not_found) {} - Emptyset_iterator v2v_oi() { return Emptyset_iterator(); } + Vmap v2v_map() { return Vmap(); } }; template @@ -82,7 +121,7 @@ struct Triangle_index_tracker Triangle_index_tracker(VertexCornerMapOut vertex_corner_map, FacePatchMapOut face_patch_map) : Triangle_index_tracker_base(vertex_corner_map) - , face_patch_map(face_patch_map) + , m_f2f_map(face_patch_map, triangle_ids) {} std::vector triangle_ids; @@ -96,17 +135,13 @@ struct Triangle_index_tracker triangle_ids.resize(triangle_ids.size()+nb_triangles, i); } - decltype(auto) - f2f_oi() + Face_map + f2f_map() { - auto l = [this](const std::pair& p) - { - put(face_patch_map, p.second, triangle_ids[p.first]); - }; - return boost::make_function_output_iterator(l); + return m_f2f_map; } - FacePatchMapOut face_patch_map; + Face_map m_f2f_map; }; @@ -114,6 +149,9 @@ template struct Triangle_index_tracker : public Triangle_index_tracker_base { + using Fmap = Constant_property_map::face_descriptor>; + Triangle_index_tracker(VertexCornerMapOut vertex_corner_map,internal_np::Param_not_found) : Triangle_index_tracker_base(vertex_corner_map) {} @@ -121,7 +159,7 @@ struct Triangle_index_tracker >::type Patch_id_pmap; + Scene_surface_mesh_item* new_item=new Scene_surface_mesh_item(); + Mesh& out = *new_item->polyhedron(); + + + Patch_id_pmap in_fpmap = get(CGAL::face_patch_id_t(), pmesh); + Patch_id_pmap out_fpmap = get(CGAL::face_patch_id_t(), out); + CGAL::Polygon_mesh_processing::remesh_planar_patches(pmesh, out, - CGAL::parameters::cosinus_threshold(cos_threshold)); + CGAL::parameters::cosinus_threshold(cos_threshold).face_patch_map(in_fpmap), + CGAL::parameters::face_patch_map(out_fpmap)); - Scene_surface_mesh_item* new_item=new Scene_surface_mesh_item(out); new_item->setName(tr("%1_remeshed").arg(poly_item->name())); scene->setSelectedItem( scene->addItem(new_item) ); + + new_item->setItemIsMulticolor(true); + new_item->computeItemColorVectorAutomatically(true); + new_item->invalidateOpenGLBuffers(); + Q_EMIT new_item->itemChanged(); + poly_item->setItemIsMulticolor(true); + poly_item->computeItemColorVectorAutomatically(true); + poly_item->invalidateOpenGLBuffers(); + Q_EMIT poly_item->itemChanged(); } else {