diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_sizing_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_sizing_example.cpp index bbb86c89692..e0564d27178 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_sizing_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/isotropic_remeshing_with_sizing_example.cpp @@ -28,7 +28,7 @@ int main(int argc, char* argv[]) const double tol = 0.001; const std::pair edge_min_max{0.001, 0.5}; - PMP::Adaptive_sizing_field sizing_field(tol, edge_min_max, mesh); + PMP::Adaptive_sizing_field sizing_field(tol, edge_min_max, faces(mesh), mesh); unsigned int nb_iter = 5; PMP::isotropic_remeshing( diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Adaptive_sizing_field.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Adaptive_sizing_field.h index 071bc761414..dc14ae91d11 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Adaptive_sizing_field.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Adaptive_sizing_field.h @@ -43,8 +43,10 @@ public: typedef typename boost::property_map::type Vertex_sizing_map; + template Adaptive_sizing_field(const double tol , const std::pair& edge_len_min_max + , const FaceRange& face_range , PolygonMesh& pmesh) : tol(tol) , m_short(edge_len_min_max.first) @@ -52,31 +54,7 @@ public: , m_pmesh(pmesh) { m_vertex_sizing_map = get(Vertex_property_tag(), m_pmesh); - } -private: - FT sqlength(const vertex_descriptor va, - const vertex_descriptor vb) const - { - typename boost::property_map::const_type - vpmap = get(CGAL::vertex_point, m_pmesh); - return FT(CGAL::squared_distance(get(vpmap, va), get(vpmap, vb))); - } - - FT sqlength(const halfedge_descriptor& h) const - { - return sqlength(target(h, m_pmesh), source(h, m_pmesh)); - } - -public: - FT get_sizing(const vertex_descriptor v) const { - CGAL_assertion(get(m_vertex_sizing_map, v)); - return get(m_vertex_sizing_map, v); - } - - template - void calc_sizing_map(const FaceRange& face_range) - { if (face_range.size() == faces(m_pmesh).size()) { // calculate curvature from the whole mesh @@ -97,6 +75,7 @@ public: } } +private: template void calc_sizing_map(FaceGraph& face_graph) { @@ -151,6 +130,48 @@ public: #endif } + FT sqlength(const vertex_descriptor va, + const vertex_descriptor vb) const + { + typename boost::property_map::const_type + vpmap = get(CGAL::vertex_point, m_pmesh); + return FT(CGAL::squared_distance(get(vpmap, va), get(vpmap, vb))); + } + + FT sqlength(const halfedge_descriptor& h) const + { + return sqlength(target(h, m_pmesh), source(h, m_pmesh)); + } + +public: + FT get_sizing(const vertex_descriptor v) const { + CGAL_assertion(get(m_vertex_sizing_map, v)); + return get(m_vertex_sizing_map, v); + } + + template + void calc_sizing_map(const FaceRange& face_range) + { + if (face_range.size() == faces(m_pmesh).size()) + { + // calculate curvature from the whole mesh + calc_sizing_map(m_pmesh); + } + else + { + // expand face selection and calculate curvature from it + std::vector selection(face_range.begin(), face_range.end()); + auto is_selected = get(CGAL::dynamic_face_property_t(), m_pmesh); + for (face_descriptor f : faces(m_pmesh)) put(is_selected, f, false); + for (face_descriptor f : face_range) put(is_selected, f, true); + CGAL::expand_face_selection(selection, m_pmesh, 1 + , is_selected, std::back_inserter(selection)); + CGAL::Face_filtered_graph ffg(m_pmesh, selection); + + calc_sizing_map(ffg); + } + } + boost::optional is_too_long(const halfedge_descriptor h) const { const FT sqlen = sqlength(h); diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h index aec9ca3b5d9..0e772b47cb5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h @@ -553,7 +553,7 @@ namespace internal { halfedge_added(hnew_opp, status(opposite(he, mesh_))); //todo ip-add: already updating sizing here because of is_too_long checks below - if constexpr (!std::is_same>::value) + if constexpr (!std::is_same_v>) sizing.update_sizing_map(vnew); //check sub-edges diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h index 0ea55b8bb59..ec443f179e5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/remesh.h @@ -334,18 +334,12 @@ void isotropic_remeshing(const FaceRange& faces t.reset(); t.start(); #endif - //todo ip: move calc_sizing_map to the sizing function constructor - if constexpr (!std::is_same>::value) - sizing.calc_sizing_map(faces); - for (unsigned int i = 0; i < nb_iterations; ++i) { #ifdef CGAL_PMP_REMESHING_VERBOSE std::cout << " * Iteration " << (i + 1) << " *" << std::endl; #endif -// if (i < 2) -// sizing.calc_sizing_map(); if(do_split) remesher.split_long_edges(sizing); if(do_collapse) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp index 813434a4c6c..679d2518666 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Isotropic_remeshing_plugin.cpp @@ -491,6 +491,7 @@ public Q_SLOTS: std::pair edge_min_max{min_length, max_length}; PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol , edge_min_max + , faces(*selection_item->polyhedron()) , *selection_item->polyhedron()); if (fpmap_valid) CGAL::Polygon_mesh_processing::isotropic_remeshing(faces(*selection_item->polyhedron()) @@ -573,6 +574,7 @@ public Q_SLOTS: std::pair edge_min_max{min_length, max_length}; PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol , edge_min_max + , faces(*selection_item->polyhedron()) , *selection_item->polyhedron()); if (fpmap_valid) CGAL::Polygon_mesh_processing::isotropic_remeshing(selection_item->selected_facets @@ -732,6 +734,7 @@ public Q_SLOTS: std::pair edge_min_max{min_length, max_length}; PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol , edge_min_max + , faces(*poly_item->polyhedron()) , *poly_item->polyhedron()); if (fpmap_valid) CGAL::Polygon_mesh_processing::isotropic_remeshing( @@ -985,6 +988,7 @@ private: std::pair edge_min_max{min_length_, max_length_}; PMP::Adaptive_sizing_field adaptive_sizing_field(error_tol_ , edge_min_max + , faces(*poly_item->polyhedron()) , *poly_item->polyhedron()); CGAL::Polygon_mesh_processing::isotropic_remeshing( faces(*poly_item->polyhedron())