From 452c18710c8b353f470fcd308e65d83c83d876f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 24 Feb 2023 16:19:37 +0100 Subject: [PATCH] add test for corner and face patch maps + fix not a corner value --- .../remesh_planar_patches.h | 16 +++- .../test_decimation_of_planar_patches.cpp | 86 +++++++++++++++++++ 2 files changed, 98 insertions(+), 4 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 c386b2abdf9..97829194d88 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 @@ -165,12 +165,12 @@ struct Triangle_index_tracker @@ -313,6 +313,14 @@ mark_corner_vertices( typedef boost::graph_traits graph_traits; std::size_t corner_id = 0; for(typename graph_traits::edge_descriptor e : edges(tm)) + { + if (get(edge_is_constrained, e)) + { + put(vertex_corner_id, source(e, tm), init_id()); + put(vertex_corner_id, target(e, tm), init_id()); + } + } + for(typename graph_traits::edge_descriptor e : edges(tm)) { if (!get(edge_is_constrained, e)) continue; typename graph_traits::halfedge_descriptor h = halfedge(e, tm); @@ -1364,7 +1372,7 @@ void remesh_planar_patches(const TriangleMeshIn& tm_in, dynamic_face_property_t(), tm_in); for(edge_descriptor e : edges(tm_in)) put(edge_is_constrained, e, false); - for(vertex_descriptor v : vertices(tm_in)) put(vertex_corner_id, v, Planar_segmentation::init_id()); + for(vertex_descriptor v : vertices(tm_in)) put(vertex_corner_id, v, Planar_segmentation::default_id()); for(face_descriptor f : faces(tm_in)) put(face_cc_ids, f, -1); VPM_in vpm_in = choose_parameter(get_parameter(np_in, internal_np::vertex_point), diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_decimation_of_planar_patches.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_decimation_of_planar_patches.cpp index ba60e5222c3..ccc95628e00 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_decimation_of_planar_patches.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_decimation_of_planar_patches.cpp @@ -226,6 +226,92 @@ int main() for (int i=0; i> in; + assert(vertices(in).size()!=0); + auto fmap_in = in.add_property_map("f:pid").first; + auto fmap_out = out.add_property_map("f:pid").first; + auto vmap_in = in.add_property_map("v:pid").first; + auto vmap_out = out.add_property_map("v:pid").first; + PMP::remesh_planar_patches(in, out, + CGAL::parameters::face_patch_map(fmap_in), + CGAL::parameters::face_patch_map(fmap_out)); + + auto get_id = [](Surface_mesh::Face_index f, Surface_mesh& sm) + { + auto h = halfedge(f, sm); + Point_3 p=sm.point(source(h, sm)), q=sm.point(target(h, sm)), r=sm.point(target(next(h, sm), sm)); + if (p.x()==-1 && q.x()==-1 && r.x()==-1) return 0; + if (p.x()== 1 && q.x()== 1 && r.x()== 1) return 1; + if (p.y()==-1 && q.y()==-1 && r.y()==-1) return 2; + if (p.y()== 1 && q.y()== 1 && r.y()== 1) return 3; + if (p.z()==-1 && q.z()==-1 && r.z()==-1) return 4; + assert(p.z()==1 && q.z()==1 && r.z()==1); + return 5; + }; + + std::array pids; // xi, Xi, yi, Yi, zi, Zi; + for (auto f : faces(out)) pids[get_id(f, out)]=get(fmap_out, f); + for (auto f : faces(in)) assert(pids[get_id(f, in)]==get(fmap_in, f)); + //------------------------------------------------------ + std::cout << " face and vertex maps\n"; + out.clear_without_removing_property_maps(); + PMP::remesh_planar_patches(in, out, + CGAL::parameters::face_patch_map(fmap_in).vertex_corner_map(vmap_in), + CGAL::parameters::face_patch_map(fmap_out).vertex_corner_map(vmap_out)); + + auto check_corner_ids = [&]() + { + std::vector id2pt(vertices(out).size()); + for (auto v : vertices(out)) + id2pt[get(vmap_out, v)]=out.point(v); + for (auto v : vertices(in)) + { + + if (!( get(vmap_in, v)==std::size_t(-1) || id2pt[get(vmap_in, v)]==in.point(v) )) + std::cout << get(vmap_in, v) << " vs " << std::size_t(-1) << " vs " << std::size_t(-2) << "\n"; + assert( get(vmap_in, v)==std::size_t(-1) || id2pt[get(vmap_in, v)]==in.point(v) ); + } + + }; + check_corner_ids(); + for (auto f : faces(out)) pids[get_id(f, out)]=get(fmap_out, f); + for (auto f : faces(in)) assert(pids[get_id(f, in)]==get(fmap_in, f)); + //------------------------------------------------------ + std::cout << " vertex map alone\n"; + out.clear_without_removing_property_maps(); + PMP::remesh_planar_patches(in, out, + CGAL::parameters::vertex_corner_map(vmap_in), + CGAL::parameters::vertex_corner_map(vmap_out)); + check_corner_ids(); + //------------------------------------------------------ + std::cout << " no simplification face+vertex maps\n"; + out.clear_without_removing_property_maps(); + in.clear_without_removing_property_maps(); + std::ifstream(CGAL::data_file_path("meshes/sphere.off")) >> in; + assert(vertices(in).size()!=0); + PMP::remesh_planar_patches(in, out, + CGAL::parameters::face_patch_map(fmap_in).vertex_corner_map(vmap_in), + CGAL::parameters::face_patch_map(fmap_out).vertex_corner_map(vmap_out)); + check_corner_ids(); + std::map, std::size_t> pids_map; + auto get_pt_sorted_array = [](Surface_mesh::Face_index f, Surface_mesh& sm) + { + auto h = halfedge(f, sm); + std::array pts = CGAL::make_array(sm.point(source(h, sm)), + sm.point(target(h, sm)), + sm.point(target(next(h, sm), sm))); + std::sort(pts.begin(), pts.end()); + return pts; + }; + for (auto f : faces(out)) pids_map[get_pt_sorted_array(f, out)]=get(fmap_out, f); + for (auto f : faces(in)) assert(pids_map[get_pt_sorted_array(f, in)]==get(fmap_in, f)); + } + #if 0 // tests to be re-enable when using region growing // testing decimate function with almost coplanar/collinear tests using PCA for (int i=1; i<=nb_meshes; ++i)