diff --git a/BGL/examples/BGL_surface_mesh/data/cube.off b/BGL/examples/BGL_surface_mesh/data/cube.off new file mode 100644 index 00000000000..da9ee71038c --- /dev/null +++ b/BGL/examples/BGL_surface_mesh/data/cube.off @@ -0,0 +1,24 @@ +OFF +11 7 0 +# vertices + -1 -1 1 + -1 1 1 + 1 1 1 + 1 -1 1 + -1 -1 -1 + -1 1 -1 + 1 1 -1 + 1 -1 -1 + 2 2 2 + 3 2 2 + 3 3 3 + +# facets + 3 3 2 1 + 3 3 1 0 + 4 0 1 5 4 + 4 6 5 1 2 + 4 3 7 6 2 + 4 4 7 3 0 + 4 4 5 6 7 + 3 8 9 10 diff --git a/BGL/examples/BGL_surface_mesh/data/flatten.selection.txt b/BGL/examples/BGL_surface_mesh/data/flatten.selection.txt new file mode 100644 index 00000000000..fa126d49a3b --- /dev/null +++ b/BGL/examples/BGL_surface_mesh/data/flatten.selection.txt @@ -0,0 +1,3 @@ + + +1 5 1 0 1 3 2 1 diff --git a/BGL/examples/BGL_surface_mesh/data/hole.selection.txt b/BGL/examples/BGL_surface_mesh/data/hole.selection.txt new file mode 100644 index 00000000000..d94ec43b900 --- /dev/null +++ b/BGL/examples/BGL_surface_mesh/data/hole.selection.txt @@ -0,0 +1,3 @@ + + +2 1 1 0 diff --git a/BGL/examples/BGL_surface_mesh/data/two_connected_components.selection.txt b/BGL/examples/BGL_surface_mesh/data/two_connected_components.selection.txt new file mode 100644 index 00000000000..bef0aadc4f5 --- /dev/null +++ b/BGL/examples/BGL_surface_mesh/data/two_connected_components.selection.txt @@ -0,0 +1,3 @@ + + +1 5 5 4 4 7 3 7 1 3 diff --git a/BGL/examples/BGL_surface_mesh/seam_mesh.cpp b/BGL/examples/BGL_surface_mesh/seam_mesh.cpp index cbd7292c24c..1852388fccc 100644 --- a/BGL/examples/BGL_surface_mesh/seam_mesh.cpp +++ b/BGL/examples/BGL_surface_mesh/seam_mesh.cpp @@ -12,121 +12,138 @@ typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point; typedef CGAL::Surface_mesh Mesh; -typedef CGAL::Seam_mesh Seam_mesh; -typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; -typedef boost::graph_traits::edge_descriptor edge_descriptor; -typedef boost::graph_traits::face_descriptor face_descriptor; +typedef boost::graph_traits::vertex_descriptor SM_vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor SM_halfedge_descriptor; +typedef boost::graph_traits::edge_descriptor SM_edge_descriptor; +typedef boost::graph_traits::face_descriptor SM_face_descriptor; + +typedef Mesh::Property_map Seam_edge_pmap; +typedef Mesh::Property_map Seam_vertex_pmap; +typedef CGAL::Seam_mesh Seam_mesh; + +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; +typedef boost::graph_traits::edge_descriptor edge_descriptor; +typedef boost::graph_traits::face_descriptor face_descriptor; -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) { Mesh sm; - std::ifstream in((argc>1)?argv[1]:"data/cube.off"); + std::ifstream in((argc>1) ? argv[1] : "data/cube.off"); in >> sm; - std::vector seam; + Seam_edge_pmap seam_edge_pm = + sm.add_property_map("e:on_seam", false).first; + Seam_vertex_pmap seam_vertex_pm = + sm.add_property_map("v:on_seam",false).first; - // split cube in two connected components - BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_face(*halfedges(sm).first,sm)){ - seam.push_back(edge(hd,sm)); + Seam_mesh mesh(sm, seam_edge_pm, seam_vertex_pm); + + // Add the seams +#if 1 + // Split the cube in two connected components + SM_halfedge_descriptor smhd = mesh.add_seams("data/two_connected_components.selection.txt"); +#else + // Seams are all edges incident to a vertex + SM_halfedge_descriptor smhd = mesh.add_seams("data/flatten.selection.txt"); +#endif + assert(smhd != SM_halfedge_descriptor()); + + std::cout << "Added: " << mesh.number_of_seam_edges() << " seam edges" << std::endl; + + halfedge_descriptor bhd(smhd); + std::cout << "First seam halfedge: " << smhd << std::endl; + std::cout << "source = " << source(smhd, mesh) + << " (pointing to vertex: " << source(smhd, sm) << ")" << std::endl; + std::cout << "target = " << target(smhd, mesh) + << " (pointing to vertex: " << target(smhd, sm) << ")" << std::endl; + + std::cout << "prev of seam halfedge in (base) mesh: " << prev(smhd, sm) << std::endl; + std::cout << "prev of seam halfedge in seam mesh: " << prev(bhd, mesh) << std::endl; + + std::cout << "next of seam halfedge in (base) mesh: " << next(smhd, sm) << std::endl; + std::cout << "next of seam halfedge in seam mesh: " << next(bhd, mesh) << std::endl; + + std::cout << "opposite of seam halfedge in (base) mesh: " << opposite(smhd, sm) << std::endl; + std::cout << "opposite of seam halfedge in seam mesh: " << opposite(bhd, mesh) << std::endl; + + std::cout << "vertices on one of the seams" << std::endl; + BOOST_FOREACH(halfedge_descriptor hd, + halfedges_around_face(opposite(bhd, mesh), mesh)){ + std::cout << target(hd.tmhd, sm) << " "; } + std::cout << std::endl; -#if 0 - //cube - halfedge_descriptor hd = * halfedges(sm).first; - std::cout << "center = " << target(hd,sm) << std::endl; - int count=0; - BOOST_FOREACH(hd, halfedges_around_target(hd,sm)){ - std::cout << "v = " << source(hd,sm) << std::endl; - if(count==0 || count==2){ - seam.push_back(edge(hd,sm)); + std::cout << "vertices around " << target(smhd , sm) << " in (base) mesh" << std::endl; + BOOST_FOREACH(SM_halfedge_descriptor hd, halfedges_around_target(smhd, sm)){ + std::cout << source(hd, sm) << " "; + } + std::cout << std::endl; + + std::cout << "vertices around " << target(bhd , mesh) << " in seam mesh" << std::endl; + BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_target(bhd, mesh)){ + std::cout << source(hd.tmhd, sm) << " "; + } + std::cout << std::endl; + + std::cout << "vertices around " << source(smhd , sm) << " in (base) mesh" << std::endl; + BOOST_FOREACH(SM_halfedge_descriptor hd, + halfedges_around_source(source(smhd, sm), sm)){ + std::cout << target(hd, sm) << " "; + } + std::cout << std::endl; + + std::cout << "vertices around " << source(bhd , mesh) << " in seam mesh" << std::endl; + BOOST_FOREACH(halfedge_descriptor hd, + halfedges_around_source(source(bhd, mesh), mesh)){ + std::cout << target(hd.tmhd, sm) << " "; + } + std::cout << std::endl; + + std::cout << "vertices around vertices in seam mesh" << std::endl; + BOOST_FOREACH(vertex_descriptor vd, vertices(mesh)){ + halfedge_descriptor hd = halfedge(vd, mesh); + std::cout << " " << vd << " has incident vertices:" << std::endl; + BOOST_FOREACH(halfedge_descriptor hd2, halfedges_around_target(hd, mesh)){ + std::cout << " " << hd2; } - if(seam.size() == 2) - break; - count++; + std::cout << std::endl; } -#endif - -#if 0 - //cube-ouvert - BOOST_FOREACH(halfedge_descriptor hd, halfedges(sm)){ - if(is_border(hd,sm)){ - seam.push_back(edge(next(opposite(hd,sm),sm),sm)); - break; - } + std::cout << "done" << std::endl; + + std::cout << "the (base) mesh has: " << num_halfedges(sm) << " halfedges" << std::endl; + std::cout << "the seam mesh has: " << num_halfedges(mesh) << " halfedges" << std::endl; + std::cout << "halfedges in (base) mesh" << std::endl; + BOOST_FOREACH(SM_halfedge_descriptor hd, halfedges(sm)){ + std::cout << hd << " "; } -#endif + std::cout << std::endl; - typedef std::map H_vertex_index_map; - typedef boost::associative_property_map H_vertex_index_pmap; - H_vertex_index_map hvim; H_vertex_index_pmap hvipm(hvim); + std::cout << "halfedges in seam mesh" << std::endl; + BOOST_FOREACH(halfedge_descriptor hd, halfedges(mesh)){ + std::cout << hd << " "; + } + std::cout << std::endl; - halfedge_descriptor mhd = halfedge(seam.front(),sm); - Seam_mesh ssm(sm, seam); + std::cout << "faces of the base and seam meshes" << std::endl; + BOOST_FOREACH(face_descriptor fd, faces(mesh)){ + std::cout << fd << " "; + } + std::cout << std::endl; std::vector faces; - boost::graph_traits::halfedge_descriptor shd(halfedge(seam.front(),sm)); - CGAL::Polygon_mesh_processing::connected_component(face(shd,ssm), - ssm, + CGAL::Polygon_mesh_processing::connected_component(face(bhd, mesh), + mesh, std::back_inserter(faces)); - std::cerr << faces.size() << std::endl; - faces.clear(); - shd = opposite(halfedge(seam.front(),sm),sm); - CGAL::Polygon_mesh_processing::connected_component(face(shd,ssm), - ssm, - std::back_inserter(faces)); - std::cerr << faces.size() << std::endl; - - return 0; - - BOOST_FOREACH(Seam_mesh::vertex_descriptor vd, vertices(ssm)){ - halfedge_descriptor hd = vd; - std::cerr << vd << " has incident halfedges:" << std::endl; - BOOST_FOREACH(Seam_mesh::halfedge_descriptor hd2, halfedges_around_target(vd,ssm)){ - std::cerr << hd2 << std::endl; - } - } - std::cerr << "done"<< std::endl; - - - Seam_mesh::halfedge_descriptor smhd(mhd), smhd2(opposite(mhd,sm)); - std::cout << "target = " << target(smhd,ssm) << std::endl; - - std::cout << "vertices on seam" << std::endl; - BOOST_FOREACH(Seam_mesh::halfedge_descriptor hd, halfedges_around_face(opposite(smhd,ssm),ssm)){ - std::cout << target(hd.tmhd,sm) << std::endl; - } - - std::cout << "vertices around target in mesh" << std::endl; - BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_target(mhd,sm)){ - std::cout << source(hd,sm) << std::endl; - } - - std::cout << "vertices around target in seam mesh" << std::endl; - BOOST_FOREACH(Seam_mesh::halfedge_descriptor hd, halfedges_around_target(smhd,ssm)){ - std::cout << source(hd.tmhd,sm) << std::endl; - } - - std::cout << "vertices around source in seam mesh" << std::endl; - BOOST_FOREACH(Seam_mesh::halfedge_descriptor hd, halfedges_around_source(opposite(smhd,ssm),ssm)){ - std::cout << target(hd.tmhd,sm) << std::endl; - } - std::cout << "vertices around source in seam mesh" << std::endl; - BOOST_FOREACH(Seam_mesh::halfedge_descriptor hd, halfedges_around_source(smhd2,ssm)){ - std::cout << target(hd.tmhd,sm) << std::endl; - } - std::cout << "vertices around target in seam mesh" << std::endl; - BOOST_FOREACH(Seam_mesh::halfedge_descriptor hd, halfedges_around_target(opposite(smhd2,ssm),ssm)){ - std::cout << source(hd.tmhd,sm) << std::endl; - } - - - boost::property_map::type vpm = get(CGAL::vertex_point,ssm); - //std::cout << get(vpm, source(hd,ssm)) << std::endl; - + std::cout << "the connected component (in the seam mesh) given by halfedge: " << smhd; + std::cout << " has " << faces.size() << " faces." << std::endl; + std::cout << "accessing coordinates of the source of halfedge " << smhd << ": "; + boost::property_map::type vpm = + get(CGAL::vertex_point, mesh); + std::cout << get(vpm, source(smhd, mesh)) << std::endl; return 0; } diff --git a/BGL/include/CGAL/boost/graph/Seam_mesh.h b/BGL/include/CGAL/boost/graph/Seam_mesh.h index 919a8286f5f..79674bed7d7 100644 --- a/BGL/include/CGAL/boost/graph/Seam_mesh.h +++ b/BGL/include/CGAL/boost/graph/Seam_mesh.h @@ -827,6 +827,11 @@ public: return tmhd; } + void set_seam_number(const edges_size_type sn) const + { + number_of_seams = sn; + } + /// Constructs a seam mesh for a triangle mesh and an edge and vertex property map /// \param tm the adapted mesh /// \param sem the edge property map with value `true` for seam edges diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_plugin.cpp index 465eb32afbd..20ed300fb1b 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_plugin.cpp @@ -499,11 +499,13 @@ void Polyhedron_demo_parameterization_plugin::parameterize(const Parameterizatio } } } + Seam_mesh *sMesh = new Seam_mesh(tMesh, seam_edge_pm, seam_vertex_pm); + sMesh->set_seam_number(seam_edges.size()); + UV_uhm uv_uhm; UV_pmap uv_pm(uv_uhm); - QString new_item_name; //determine the different connected_components boost::property_map::type fim diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/lscm.cpp b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/lscm.cpp index 27a959416f5..44cfd1c1103 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/lscm.cpp +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/lscm.cpp @@ -58,7 +58,6 @@ struct Face2Polyline int main(int argc, char * argv[]) { SurfaceMesh sm; - std::vector seam; std::ifstream in_mesh((argc>1)?argv[1]:"data/lion.off"); in_mesh >> sm; @@ -67,7 +66,9 @@ int main(int argc, char * argv[]) Seam_edge_pmap seam_edge_pm = sm.add_property_map("e:on_seam", false).first; Seam_vertex_pmap seam_vertex_pm = sm.add_property_map("v:on_seam",false).first; - std::ifstream in((argc>2)?argv[2]:"data/lion.selection.txt"); + const char* filename = (argc>2) ? argv[2] : "data/lion.selection.txt"; + + std::ifstream in(filename); std::string vertices; std::getline(in,vertices); std::istringstream iss(vertices); @@ -77,22 +78,9 @@ int main(int argc, char * argv[]) two_vertices_given = true; } - int s,t; - SM_halfedge_descriptor smhd; - while(in >> s >> t){ - SM_vertex_descriptor svd(s), tvd(t); - SM_edge_descriptor ed = edge(svd, tvd, sm).first; - if(! is_border(ed, sm)){ - put(seam_edge_pm, ed, true); - put(seam_vertex_pm, svd, true); - put(seam_vertex_pm, tvd, true); - if(smhd == boost::graph_traits::null_halfedge()){ - smhd = halfedge(edge(svd, tvd, sm).first, sm); - } - } - } - Mesh mesh(sm, seam_edge_pm, seam_vertex_pm); + SM_halfedge_descriptor smhd = mesh.add_seams(filename); + assert(smhd != SM_halfedge_descriptor()); // The 2D points of the uv parametrisation will be written into this map // Note that this is a halfedge property map, and that the uv diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/parameterization_tests.cpp b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/parameterization_tests.cpp index a70931b813b..336b4038c33 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/parameterization_tests.cpp +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/parameterization_tests.cpp @@ -3,13 +3,13 @@ #include #include +#include +#include + #include #include #include -#include -#include - #include #include #include @@ -30,56 +30,79 @@ typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_2 Point_2; typedef Kernel::Point_3 Point_3; -#define POLY_MESH +#define POLY_MESH // Polyhedron mesh #ifdef POLY_MESH #define MVC_POLY_MESH #define BARY_POLY_MESH #define ARAP_POLY_MESH #endif -#define SURF_MESH +#define SURF_MESH // Surface_mesh #ifdef SURF_MESH #define ARAP_SURF_MESH #endif -//#define SEAM_MESH -#ifdef SEAM_MESH +#define PM_SEAM_MESH // Polyhedron-based seam mesh +#ifdef PM_SEAM_MESH +#define POLY_MESH +#define ARAP_PM_SEAM_MESH +#endif + +#define SM_SEAM_MESH // Surface_mesh-based seam mesh +#ifdef SM_SEAM_MESH #define SURF_MESH -#define ARAP_SEMESH +#define ARAP_SM_SEAM_MESH #endif // #define REDIRECT_OUTPUT #ifdef POLY_MESH - typedef CGAL::Polyhedron_3 PMesh; +typedef CGAL::Polyhedron_3 PMesh; - typedef boost::graph_traits::vertex_descriptor vertex_descriptor; - typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef boost::graph_traits::face_descriptor face_descriptor; +typedef boost::graph_traits::vertex_descriptor PM_vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor PM_halfedge_descriptor; - typedef CGAL::Parameterizer_traits_3::Error_code Error_code; +typedef CGAL::Unique_hash_map PM_UV_hmap; +typedef boost::associative_property_map PM_UV_pmap; + +typedef CGAL::Parameterizer_traits_3::Error_code Error_code; #endif #ifdef SURF_MESH - typedef CGAL::Surface_mesh SMesh; +typedef CGAL::Surface_mesh SMesh; -typedef boost::graph_traits::vertex_descriptor SM_vertex_descriptor; -typedef boost::graph_traits::halfedge_descriptor SM_halfedge_descriptor; -typedef boost::graph_traits::face_descriptor SM_face_descriptor; +typedef boost::graph_traits::vertex_descriptor SM_vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor SM_halfedge_descriptor; + +typedef SMesh::Property_map SM_UV_pmap; #endif -#ifdef SEAM_MESH +#ifdef SM_SEAM_MESH typedef boost::graph_traits::edge_descriptor SM_edge_descriptor; -typedef SMesh::Property_map UV_pmap; -typedef SMesh::Property_map Seam_edge_pmap; -typedef SMesh::Property_map Seam_vertex_pmap; +typedef SMesh::Property_map SM_seam_edge_pmap; +typedef SMesh::Property_map SM_seam_vertex_pmap; -typedef CGAL::Seam_mesh TMesh; +typedef CGAL::Seam_mesh + SM_Seam_mesh; -typedef boost::graph_traits::vertex_descriptor TM_vertex_descriptor; -typedef boost::graph_traits::halfedge_descriptor TM_halfedge_descriptor; -typedef boost::graph_traits::face_descriptor TM_face_descriptor; +typedef boost::graph_traits::vertex_descriptor SM_SE_vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor SM_SE_halfedge_descriptor; +#endif + +#ifdef PM_SEAM_MESH +typedef boost::graph_traits::edge_descriptor PM_edge_descriptor; + +typedef CGAL::Unique_hash_map PM_seam_edge_hmap; +typedef boost::associative_property_map PM_seam_edge_pmap; +typedef CGAL::Unique_hash_map PM_seam_vertex_hmap; +typedef boost::associative_property_map PM_seam_vertex_pmap; + +typedef CGAL::Seam_mesh + PM_Seam_mesh; + +typedef boost::graph_traits::vertex_descriptor PM_SE_vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor PM_SE_halfedge_descriptor; #endif int main(int argc, char * argv[]) @@ -91,18 +114,19 @@ int main(int argc, char * argv[]) std::freopen("/home/mrouxell/POLY_MESH.txt", "w", stdout); #endif -// std::ifstream in((argc>1)?argv[1]:"../data/tiny_nef.off"); + std::ifstream in((argc>1)?argv[1]:"../data/tiny_nef.off"); // std::ifstream in((argc>1)?argv[1]:"../data/nefertiti.off"); // std::ifstream in((argc>1)?argv[1]:"../data/lion.off"); // std::ifstream in((argc>1)?argv[1]:"../data/blob.off"); - std::ifstream in((argc>1)?argv[1]:"/home/mrouxell/Data/OFF/mushroom.off"); +// std::ifstream in((argc>1)?argv[1]:"/home/mrouxell/Data/OFF/mushroom.off"); // std::ifstream in((argc>1)?argv[1]:"/home/mrouxell/Data/OFF/lion-head.off"); // std::ifstream in((argc>1)?argv[1]:"../data/three_peaks.off"); // std::ifstream in((argc>1)?argv[1]:"/home/mrouxell/Data/OFF/three_peaks_dense.off"); // std::ifstream in((argc>1)?argv[1]:"../data/cow_with_hole.off"); // std::ifstream in((argc>1)?argv[1]:"../data/cow_dense.off"); // std::ifstream in((argc>1)?argv[1]:"../data/cow_densified.off"); -// std::ifstream in((argc>1)?argv[1]:"../data/mushroom_hole_2.off"); +// std::ifstream in((argc>1)?argv[1]:"../data/mushroom_big_hole.off"); +// std::ifstream in((argc>1)?argv[1]:"../data/mushroom_hole_1.off"); if(!in){ std::cerr << "Problem loading the input data" << std::endl; @@ -118,13 +142,13 @@ int main(int argc, char * argv[]) PMesh pm; in >> pm; - halfedge_descriptor hd = CGAL::Polygon_mesh_processing::longest_border(pm).first; + PM_halfedge_descriptor hd = CGAL::Polygon_mesh_processing::longest_border(pm).first; - CGAL::Unique_hash_map > uvhm; + CGAL::Unique_hash_map > uvhm; boost::associative_property_map< - CGAL::Unique_hash_map > > uvpm(uvhm); + CGAL::Unique_hash_map > > uvpm(uvhm); // Go to default (aka Mean values) CGAL::parameterize(pm, hd, uvpm); @@ -141,16 +165,16 @@ int main(int argc, char * argv[]) PMesh pm; in >> pm; - halfedge_descriptor hd = CGAL::Polygon_mesh_processing::longest_border(pm).first; + PM_halfedge_descriptor hd = CGAL::Polygon_mesh_processing::longest_border(pm).first; // UV map - CGAL::Unique_hash_map > uvhm; + CGAL::Unique_hash_map > uvhm; boost::associative_property_map< - CGAL::Unique_hash_map > > uvpm(uvhm); + CGAL::Unique_hash_map > > uvpm(uvhm); // Indices map - typedef boost::unordered_map Indices; + typedef boost::unordered_map Indices; Indices indices; CGAL::Polygon_mesh_processing::connected_component(face(opposite(hd, pm), pm), pm, @@ -158,8 +182,8 @@ int main(int argc, char * argv[]) CGAL::Parameterization::Vertices(pm, indices))); // Vertex parameterized map - boost::unordered_set vs; - CGAL::internal::Bool_property_map > vpm(vs); + boost::unordered_set vs; + CGAL::internal::Bool_property_map > vpm(vs); typename CGAL::Barycentric_mapping_parameterizer_3 parameterizer; parameterizer.parameterize(pm, hd, uvpm, boost::make_assoc_property_map(indices), vpm); @@ -177,17 +201,17 @@ int main(int argc, char * argv[]) PMesh pm; in >> pm; - halfedge_descriptor hd = CGAL::Polygon_mesh_processing::longest_border(pm).first; + PM_halfedge_descriptor hd = CGAL::Polygon_mesh_processing::longest_border(pm).first; // UV map - CGAL::Unique_hash_map > uvhm; + CGAL::Unique_hash_map > uvhm; boost::associative_property_map< - CGAL::Unique_hash_map > > uvpm(uvhm); + CGAL::Unique_hash_map > > uvpm(uvhm); // Indices map - typedef boost::unordered_map Indices; + typedef boost::unordered_map Indices; Indices indices; CGAL::Polygon_mesh_processing::connected_component( face(opposite(hd, pm), pm), @@ -198,8 +222,8 @@ int main(int argc, char * argv[]) boost::associative_property_map vipm(indices); // Vertex parameterized map - boost::unordered_set vs; - CGAL::internal::Bool_property_map > vpm(vs); + boost::unordered_set vs; + CGAL::internal::Bool_property_map > vpm(vs); // Parameterizer typename CGAL::ARAP_parameterizer_3 parameterizer; @@ -257,68 +281,96 @@ int main(int argc, char * argv[]) #endif // *************************************************************************** - // ARAP WITH SEAM_MESH + // ARAP WITH SEAM_MESH (SM) // *************************************************************************** -#ifdef ARAP_SEMESH +#ifdef ARAP_SM_SEAM_MESH { SMesh sm; in.clear(); in.seekg(0, std::ios::beg); in >> sm; - Seam_edge_pmap seam_edge_pm = + SM_seam_edge_pmap seam_edge_pm = sm.add_property_map("e:on_seam", false).first; - Seam_vertex_pmap seam_vertex_pm = + SM_seam_vertex_pmap seam_vertex_pm = sm.add_property_map("v:on_seam",false).first; - std::ifstream in((argc>2) ? argv[2] : "../data/lion.selection.txt"); - std::string vertices; - std::getline(in,vertices); - std::istringstream iss(vertices); - int p1, p2; - bool two_vertices_given = false; - if(iss >> p1 >> p2){ - two_vertices_given = true; - } - - int s, t; - SM_halfedge_descriptor smhd; - while(in >> s >> t){ - SM_vertex_descriptor svd(s), tvd(t); - SM_edge_descriptor ed = edge(svd, tvd, sm).first; - if(! is_border(ed, sm)){ - put(seam_edge_pm, ed, true); - put(seam_vertex_pm, svd, true); - put(seam_vertex_pm, tvd, true); - if(smhd == boost::graph_traits::null_halfedge()){ - smhd = halfedge(edge(svd, tvd, sm).first, sm); - } - } - } - - TMesh mesh(sm, seam_edge_pm, seam_vertex_pm); + SM_Seam_mesh mesh(sm, seam_edge_pm, seam_vertex_pm); + SM_halfedge_descriptor smhd = mesh.add_seams("../data/lion.selection.txt"); // The 2D points of the uv parametrisation will be written into this map // Note that this is a halfedge property map, and that the uv // is only stored for the canonical halfedges representing a vertex - UV_pmap uv_pm = sm.add_property_map("h:uv").first; - TM_halfedge_descriptor bhd(smhd); + SM_SE_halfedge_descriptor bhd(smhd); bhd = opposite(bhd, mesh); // a halfedge on the virtual border // Indices - typedef boost::unordered_map Vertex_index_map; - Vertex_index_map vim; - boost::associative_property_map vipm(vim); - mesh.initialize_vertex_index_map(bhd, vipm); + typedef boost::unordered_map Indices; + Indices indices; + CGAL::Polygon_mesh_processing::connected_component( + face(opposite(bhd, mesh), mesh), + mesh, + boost::make_function_output_iterator( + CGAL::Parameterization::Vertices(mesh, indices))); + boost::associative_property_map vipm(indices); // Parameterized - boost::unordered_set vs; - CGAL::internal::Bool_property_map > vpm(vs); + boost::unordered_set vs; + CGAL::internal::Bool_property_map > vpm(vs); - typename CGAL::ARAP_parameterizer_3 parameterizer; + typename CGAL::ARAP_parameterizer_3 parameterizer; + parameterizer.parameterize(mesh, bhd, uv_pm, vipm, vpm); + + } +#endif + + // *************************************************************************** + // ARAP WITH SEAM_MESH (POLY) + // *************************************************************************** + +#ifdef ARAP_PM_SEAM_MESH + { + PMesh pm; + in.clear(); + in.seekg(0, std::ios::beg); + in >> pm; + + PM_seam_edge_hmap seam_edge_hm(false); + PM_seam_edge_pmap seam_edge_pm(seam_edge_hm); + PM_seam_vertex_hmap seam_vertex_hm(false); + PM_seam_vertex_pmap seam_vertex_pm(seam_vertex_hm); + + PM_Seam_mesh mesh(pm, seam_edge_pm, seam_vertex_pm); + PM_halfedge_descriptor pmhd = mesh.add_seams("../data/lion.selection.txt"); + + // The 2D points of the uv parametrisation will be written into this map + // Note that this is a halfedge property map, and that the uv + // is only stored for the canonical halfedges representing a vertex + PM_UV_hmap uv_hm; + PM_UV_pmap uv_pm(uv_hm); + + PM_SE_halfedge_descriptor bhd(pmhd); + bhd = opposite(bhd, mesh); // a halfedge on the virtual border + + // Indices + typedef boost::unordered_map Indices; + Indices indices; + CGAL::Polygon_mesh_processing::connected_component( + face(opposite(bhd, mesh), mesh), + mesh, + boost::make_function_output_iterator( + CGAL::Parameterization::Vertices(mesh, indices))); + boost::associative_property_map vipm(indices); + + // Parameterized + boost::unordered_set vs; + CGAL::internal::Bool_property_map > vpm(vs); + + typename CGAL::ARAP_parameterizer_3 parameterizer; parameterizer.parameterize(mesh, bhd, uv_pm, vipm, vpm); } #endif diff --git a/Surface_mesh_parameterization/include/CGAL/parameterize.h b/Surface_mesh_parameterization/include/CGAL/parameterize.h index 97c30a20fcd..591aefdc45c 100644 --- a/Surface_mesh_parameterization/include/CGAL/parameterize.h +++ b/Surface_mesh_parameterization/include/CGAL/parameterize.h @@ -207,10 +207,14 @@ parameterize(Seam_mesh& mesh, boost::unordered_set vs; internal::Bool_property_map< boost::unordered_set > vpm(vs); - typedef boost::unordered_map Vertex_index_map; - Vertex_index_map vim; - boost::associative_property_map vipm(vim); - mesh.initialize_vertex_index_map(bhd,vipm); + typedef boost::unordered_map Indices; + Indices indices; + CGAL::Polygon_mesh_processing::connected_component( + face(opposite(bhd, mesh), mesh), + mesh, + boost::make_function_output_iterator( + Parameterization::Vertices, Indices>(mesh, indices))); + boost::associative_property_map vipm(indices); Mean_value_coordinates_parameterizer_3 > parameterizer; return parameterizer.parameterize(mesh, bhd, uvm, vipm, vpm); @@ -229,10 +233,14 @@ parameterize(Seam_mesh& mesh, boost::unordered_set vs; internal::Bool_property_map< boost::unordered_set > vpm(vs); - typedef boost::unordered_map Vertex_index_map; - Vertex_index_map vim; - boost::associative_property_map vipm(vim); - mesh.initialize_vertex_index_map(bhd,vipm); + typedef boost::unordered_map Indices; + Indices indices; + CGAL::Polygon_mesh_processing::connected_component( + face(opposite(bhd, mesh), mesh), + mesh, + boost::make_function_output_iterator( + Parameterization::Vertices, Indices>(mesh, indices))); + boost::associative_property_map vipm(indices); return parameterizer.parameterize(mesh, bhd, uvm, vipm, vpm); }