From 99a3b99283fb93b7532c9819b03387d8a93418b7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 3 Dec 2015 17:59:29 +0100 Subject: [PATCH] make connecteced_component work for Seam_mesh --- BGL/include/CGAL/boost/graph/Seam_mesh.h | 10 +++++ .../CGAL/boost/graph/graph_traits_Seam_mesh.h | 34 ++++++++-------- .../Surface_mesh_parameterization/blob.cpp | 15 +++++-- .../CGAL/Fixed_border_parameterizer_3.h | 6 --- .../include/CGAL/parameterize.h | 39 +++++++++++++++++-- 5 files changed, 76 insertions(+), 28 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/Seam_mesh.h b/BGL/include/CGAL/boost/graph/Seam_mesh.h index 09aab4d912d..165d14e1b2c 100644 --- a/BGL/include/CGAL/boost/graph/Seam_mesh.h +++ b/BGL/include/CGAL/boost/graph/Seam_mesh.h @@ -200,6 +200,16 @@ typedef typename boost::graph_traits::face_descriptor face_descriptor; } }; + + struct edge_descriptor { + halfedge_descriptor hd; + + edge_descriptor(const halfedge_descriptor& hd) + : hd(hd) + {} + + }; + const TM& tm; std::set seam_edges; std::set seam_vertices; diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Seam_mesh.h b/BGL/include/CGAL/boost/graph/graph_traits_Seam_mesh.h index ac6ee83b97f..4432573b874 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Seam_mesh.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Seam_mesh.h @@ -52,21 +52,22 @@ private: public: // Graph - typedef typename SM::vertex_descriptor vertex_descriptor; - typedef typename SM::face_descriptor face_descriptor; + typedef typename SM::vertex_descriptor vertex_descriptor; /* typedef typename SM::Point vertex_property_type; - typedef typename SM::Edge_index edge_descriptor; */ + + typedef typename SM::edge_descriptor edge_descriptor; + typedef boost::undirected_tag directed_category; typedef boost::disallow_parallel_edge_tag edge_parallel_category; typedef SM_graph_traversal_category traversal_category; // HalfedgeGraph - typedef typename SM::halfedge_descriptor halfedge_descriptor; + typedef typename SM::halfedge_descriptor halfedge_descriptor; // FaceGraph - //typedef typename SM::face_index face_descriptor; + typedef typename SM::face_descriptor face_descriptor; // VertexListGraph typedef typename SM::vertex_iterator vertex_iterator; @@ -92,9 +93,9 @@ public: //typedef CGAL::Out_edge_iterator out_edge_iterator; // nulls - //static vertex_descriptor null_vertex() { return vertex_descriptor(); } - //static face_descriptor null_face() { return face_descriptor(); } - //static halfedge_descriptor null_halfedge() { return halfedge_descriptor(); } + static vertex_descriptor null_vertex() { return vertex_descriptor(); } + static face_descriptor null_face() { return face_descriptor(); } + static halfedge_descriptor null_halfedge() { return halfedge_descriptor(); } }; template @@ -269,13 +270,13 @@ opposite(typename boost::graph_traits >::halfedge_descriptor return sm.m_opposite(h); } -#if 0 + template typename boost::graph_traits >::edge_descriptor edge(typename boost::graph_traits >::halfedge_descriptor h, const CGAL::Seam_mesh

& sm) { - return sm.m_edge(h); + return h; } template @@ -283,10 +284,10 @@ typename boost::graph_traits >::halfedge_descriptor halfedge(typename boost::graph_traits >::edge_descriptor e, const CGAL::Seam_mesh

& sm) { - return sm.m_halfedge(e); + return e.hd; } -#endif + template typename boost::graph_traits >::halfedge_descriptor @@ -348,17 +349,18 @@ halfedge(typename boost::graph_traits >::face_descriptor f, return halfedge(f, sm.mesh()); } -#if 0 + template typename boost::graph_traits >::face_descriptor face(typename boost::graph_traits >::halfedge_descriptor h, const CGAL::Seam_mesh

& sm) { - return sm.face(h); + if(h.seam){ + return boost::graph_traits >::null_face(); + } + return face(h, sm.mesh()); } -#endif - // // FaceListGraph diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp index 591cfdbff5c..110622e1166 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp @@ -98,8 +98,17 @@ int main(int argc, char * argv[]) Mesh mesh(sm, seam, smhd,vipm); halfedge_descriptor bhd(smhd); - bhd = opposite(bhd,mesh); // a halfedge on the virtual hole +#if 0 + std::vector faces; + CGAL::Polygon_mesh_processing::connected_component(face(bhd,mesh), + mesh, + std::back_inserter(faces)); + std::cerr << faces.size() << std::endl; + return 0; +#endif + + bhd = opposite(bhd,mesh); // a halfedge on the virtual hole Parameterizer::Error_code err = CGAL::parameterize(mesh, Parameterizer(), bhd, uvpm, vipm, vpapm); @@ -119,7 +128,7 @@ int main(int argc, char * argv[]) break; }; - +#if 0 BOOST_FOREACH(face_descriptor fd, faces(mesh)){ halfedge_descriptor hd = halfedge(fd,mesh); std::cout << "4 " << uvm[target(hd,mesh)].x() << " " << uvm[target(hd,mesh)].y() << " 0 "; @@ -129,6 +138,6 @@ int main(int argc, char * argv[]) } std::cout << std::endl; } - +#endif return EXIT_SUCCESS; } diff --git a/Surface_mesh_parameterization/include/CGAL/Fixed_border_parameterizer_3.h b/Surface_mesh_parameterization/include/CGAL/Fixed_border_parameterizer_3.h index ea9579ada9c..d059ab44851 100644 --- a/Surface_mesh_parameterization/include/CGAL/Fixed_border_parameterizer_3.h +++ b/Surface_mesh_parameterization/include/CGAL/Fixed_border_parameterizer_3.h @@ -409,12 +409,6 @@ parameterize(TriangleMesh& mesh, halfedge_descriptor bhd, VertexUVmap uvmap, Ver int index = get(vimap,v); put(uvmap,v,Point_2(Xu[index],Xv[index])); put(vpm,v,true); - /* - BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_target(v,mesh)){ - int index = get(vimap,hd); - put(uvmap,hd,Point_2(Xu[index],Xv[index])); - } - */ } } #ifdef DEBUG_TRACE diff --git a/Surface_mesh_parameterization/include/CGAL/parameterize.h b/Surface_mesh_parameterization/include/CGAL/parameterize.h index 04370b126d2..e63aa7f17dc 100644 --- a/Surface_mesh_parameterization/include/CGAL/parameterize.h +++ b/Surface_mesh_parameterization/include/CGAL/parameterize.h @@ -25,6 +25,9 @@ #include +#include +#include +#include /// \file parameterize.h @@ -52,6 +55,31 @@ parameterize(ParameterizationMesh_3& mesh) ///< 3D mesh, model of Parameterizat } + namespace Parameterization { + + template + struct Vertices { + + Vertices(const Mesh& mesh, Map& map) + : mesh(mesh), map(&map), index(0) + {} + + void operator()(const typename boost::graph_traits::face_descriptor& fd) + { + BOOST_FOREACH(typename boost::graph_traits::vertex_descriptor vd, vertices_around_face(halfedge(fd,mesh),mesh)){ + if(map->find(vd) == map->end()){ + (*map)[vd] = index++; + } + } + } + + const Mesh& mesh; + mutable Map* map; + int index; + }; + } + + /// \ingroup PkgSurfaceParameterizationMainFunction /// /// Compute a one-to-one mapping from a 3D triangle surface `mesh` to a @@ -66,7 +94,7 @@ parameterize(ParameterizationMesh_3& mesh) ///< 3D mesh, model of Parameterizat /// \pre `mesh` must be a triangular mesh. /// \pre The mesh border must be mapped onto a convex polygon /// (for fixed border parameterizations). -/// + template typename Parameterizer_traits_3::Error_code parameterize(TriangleMesh& mesh, @@ -76,7 +104,13 @@ parameterize(TriangleMesh& mesh, VertexIndexMap vimap, VertexParameterizedMap vpm) { - return parameterizer.parameterize(mesh, bhd, uvm, vimap, vpm); + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef std::map Indices; + Indices indices; + CGAL::Polygon_mesh_processing::connected_component(face(opposite(bhd,mesh),mesh), + mesh, + boost::make_function_output_iterator(Parameterization::Vertices(mesh,indices))); + return parameterizer.parameterize(mesh, bhd, uvm, boost::make_assoc_property_map(indices), vpm); } @@ -93,7 +127,6 @@ parameterize(Seam_mesh& mesh, VertexIndexMap vimap, VertexParameterizedMap vpm) { - std::cerr << "treat Seam_mesh"<< std::endl; Seam_mesh_uv_map putter(mesh,uvm); return parameterizer.parameterize(mesh, bhd, putter, vimap, vpm); }