From 80f673fa246284f97a0038b21e8d1e1df8032504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 9 Dec 2016 12:03:42 +0100 Subject: [PATCH] Improved cone locating functions --- .../Surface_mesh_parameterization/orbital.cpp | 10 +- .../Orbital_Tutte_parameterizer_3.h | 2 +- .../internal/orbital_cone_helper.h | 92 +++++++++++-------- 3 files changed, 61 insertions(+), 43 deletions(-) diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/orbital.cpp b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/orbital.cpp index 2605ee15521..8e5157693a1 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/orbital.cpp +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/orbital.cpp @@ -79,8 +79,8 @@ int main(int argc, char * argv[]) // Read the cones and find the corresponding vertex_descriptor in the underlying mesh 'sm' typedef std::vector Cones_in_smesh_container; - Cones_in_smesh_container cone_vds_in_sm; - SMP::internal::read_cones(sm, cone_filename, cone_vds_in_sm); + Cones_in_smesh_container cone_sm_vds; + SMP::internal::read_cones(sm, cone_filename, cone_sm_vds); // Two property maps to store the seam edges and vertices Seam_edge_pmap seam_edge_pm = sm.add_property_map("e:on_seam", false).first; @@ -94,7 +94,7 @@ int main(int argc, char * argv[]) if(smhd == SM_halfedge_descriptor() ) { std::cout << "No seams were given in input, computing shortest paths between cones" << std::endl; std::list seam_edges; - SMP::internal::compute_shortest_paths_between_cones(sm, cone_vds_in_sm, seam_edges); + SMP::internal::compute_shortest_paths_between_cones(sm, cone_sm_vds, seam_edges); // Add the seams to the seam mesh BOOST_FOREACH(SM_edge_descriptor e, seam_edges) { @@ -117,9 +117,9 @@ int main(int argc, char * argv[]) // Mark the cones in the seam mesh typedef boost::unordered_map Cones; Cones cmap; - SMP::internal::locate_cones(mesh, cone_vds_in_sm, cmap); + Cones>(mesh, cone_sm_vds, cmap); // The 2D points of the uv parametrisation will be written into this map // Note that this is a halfedge property map, and that uv values diff --git a/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/Orbital_Tutte_parameterizer_3.h b/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/Orbital_Tutte_parameterizer_3.h index 130dc644667..6713dfcb756 100644 --- a/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/Orbital_Tutte_parameterizer_3.h +++ b/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/Orbital_Tutte_parameterizer_3.h @@ -292,7 +292,7 @@ private: // Initialize some variables used in the seam walk int start_cone_index = -1; // index of the beginning of the seam vertex_descriptor start_cone; - find_start_cone(cmap, vimap, start_cone, start_cone_index); + internal::find_start_cone(cmap, vimap, start_cone, start_cone_index); CGAL_postcondition(start_cone != vertex_descriptor() && start_cone_index != -1); // parameterize the initial cone diff --git a/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/internal/orbital_cone_helper.h b/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/internal/orbital_cone_helper.h index ad3062087b1..62e850d89ff 100644 --- a/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/internal/orbital_cone_helper.h +++ b/Surface_mesh_parameterization/include/CGAL/Surface_mesh_parameterization/internal/orbital_cone_helper.h @@ -166,43 +166,68 @@ Error_code read_cones(const Polygon_mesh& pm, const char* filename, return OK; } +template +void find_start_cone(const ConeMap& cmap, + VertexIndexMap vimap, + vertex_descriptor& cone, + int& cone_index) +{ + CGAL_precondition(!cmap.empty()); + + typename ConeMap::const_iterator cmit = cmap.begin(), cend = cmap.end(); + for(; cmit!=cend; ++cmit) { + if(cmit->second != First_unique_cone) + continue; + + cone = cmit->first; + cone_index = get(vimap, cone); + + return; + } + + std::cerr << "Error: did not find first cone" << std::endl; + CGAL_postcondition(false); +} + /// Locate the cones on the seam mesh (find the corresponding seam mesh /// vertex_descriptor) and mark them with a tag that indicates whether it is a /// simple cone or a duplicated cone. /// /// The cones are ordered: the first and last cones are the extremetities of the seam. /// -/// \tparam Mesh is a seam mesh -/// \tparam BaseMesh is the underlying mesh of `Mesh` +/// \tparam SeamMesh is a seam mesh /// \tparam ConeMap a map vertex_descriptor --> Cone_type -template -void locate_cones(const Mesh& mesh, - const Cones_in_pmesh_vector& cone_vds_in_sm, +void locate_cones(const SeamMesh& mesh, + const Cones_in_pmesh_vector& cone_tm_vds, ConeMap& cones) { CGAL_precondition(cones.empty()); - typedef typename boost::graph_traits::vertex_descriptor BM_vertex_descriptor; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename SeamMesh::TriangleMesh TriangleMesh; - // property map to go from BM_vertex_descriptor to Point_3 - typedef typename Kernel_traits::PPM PM_PPM; + typedef typename boost::graph_traits::vertex_descriptor TM_vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + + // property map to go from TM_vertex_descriptor to Point_3 + typedef typename Kernel_traits::PPM PM_PPM; const PM_PPM pm_ppmap = get(boost::vertex_point, mesh.mesh()); // property map to go from vertex_descriptor to Point_3 - typedef typename Kernel_traits::PPM PPM; + typedef typename Kernel_traits::PPM PPM; const PPM ppmap = get(boost::vertex_point, mesh); // the cones in the underlying mesh - std::size_t cvdss = cone_vds_in_sm.size(); + std::size_t cvdss = cone_tm_vds.size(); std::cout << cvdss << " cones to locate" << std::endl; for(std::size_t i=0; i Cone_type -template Cone_type +template -void locate_unordered_cones(const Mesh& mesh, - const Cones_in_pmesh_set& cone_vds_in_sm, +void locate_unordered_cones(const SeamMesh& mesh, + const Cones_in_pmesh_set& cone_tm_vds, ConeMap& cones) { CGAL_precondition(cones.empty()); - typedef typename boost::graph_traits::vertex_descriptor BM_vertex_descriptor; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename SeamMesh::TriangleMesh TriangleMesh; + + typedef typename boost::graph_traits::vertex_descriptor TM_vertex_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; // find a vertex on the seam vertex_descriptor vertex_on_seam; @@ -259,12 +281,12 @@ void locate_unordered_cones(const Mesh& mesh, CGAL_assertion(vertex_on_seam != vertex_descriptor()); - // property map to go from BM_vertex_descriptor to Point_3 - typedef typename Kernel_traits::PPM PM_PPM; + // property map to go from TM_vertex_descriptor to Point_3 + typedef typename Kernel_traits::PPM PM_PPM; const PM_PPM pm_ppmap = get(boost::vertex_point, mesh.mesh()); // property map to go from vertex_descriptor to Point_3 - typedef typename Kernel_traits::PPM PPM; + typedef typename Kernel_traits::PPM PPM; const PPM ppmap = get(boost::vertex_point, mesh); bool first_cone_met = false; @@ -272,7 +294,7 @@ void locate_unordered_cones(const Mesh& mesh, // walk on the seam and mark if we encounter a cone vertex_descriptor end = vertex_on_seam; do { - BOOST_FOREACH(BM_vertex_descriptor smvd, cone_vds_in_sm) { + BOOST_FOREACH(TM_vertex_descriptor smvd, cone_tm_vds) { if(get(ppmap, vertex_on_seam) == get(pm_ppmap, smvd)) { // the seam mesh vertex is a cone // we have encountered a cone. Must check if the cone is a Unique_cone @@ -314,11 +336,7 @@ void locate_unordered_cones(const Mesh& mesh, } while(vertex_on_seam != end); - CGAL_postcondition((cone_vds_in_sm.size() == 3 && cones.size() == 4) || - (cone_vds_in_sm.size() == 4 && cones.size() == 6)); - - std::cout << cone_vds_in_sm.size() << " cones in sm" << std::endl; - std::cout << cones.size() << " cones in mesh" << std::endl; + check_seam_validity(mesh, cones, cone_tm_vds); } } // namespace internal