From b7c5d49689f2f1a2efc28a3fc76ae49dc6ebe17e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 20 Jan 2016 18:31:02 +0100 Subject: [PATCH] clean Simple_parameterization.cpp --- .../Simple_parameterization.cpp | 152 +++++++----------- .../Surface_mesh_parameterization/blob.cpp | 1 - .../include/CGAL/parameterize.h | 18 +++ 3 files changed, 76 insertions(+), 95 deletions(-) diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/Simple_parameterization.cpp b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/Simple_parameterization.cpp index 6c6be40a556..bcee9d52592 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/Simple_parameterization.cpp +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/Simple_parameterization.cpp @@ -1,109 +1,73 @@ #include -#include -#include -#include -#include +#include #include +#include #include #include +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_2 Point_2; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; +typedef boost::graph_traits::face_descriptor face_descriptor; -// ---------------------------------------------------------------------------- -// Private types -// ---------------------------------------------------------------------------- +namespace PMP = CGAL::Polygon_mesh_processing; -typedef CGAL::Simple_cartesian Kernel; -typedef CGAL::Polyhedron_3 Polyhedron; - - -// ---------------------------------------------------------------------------- -// main() -// ---------------------------------------------------------------------------- int main(int argc, char * argv[]) { - std::cerr << "PARAMETERIZATION" << std::endl; - std::cerr << " Floater parameterization" << std::endl; - std::cerr << " Circle border" << std::endl; + std::cerr << "Floater parameterization on the border of a circle" << std::endl; - //*************************************** - // decode parameters - //*************************************** + std::ifstream in((argc>1)?argv[1]:"data/nefertiti.off"); - if (argc-1 != 1) - { - std::cerr << "Usage: " << argv[0] << " input_file.off" << std::endl; - return(EXIT_FAILURE); + Mesh sm; + in >> sm; + + halfedge_descriptor hd = PMP::longest_border(sm).first; + if(hd == boost::graph_traits::null_halfedge()){ + std::cout << "mesh has no border" << std::endl; + return(EXIT_FAILURE); + } + + Mesh::Property_map uv_pm; + uv_pm = sm.add_property_map("v:uv").first; + Mesh::Property_map parameterized_pm; + parameterized_pm = sm.add_property_map("v:parameterized",false).first; + typedef CGAL::Parameterizer_traits_3 Parameterizer; + Parameterizer::Error_code err = CGAL::parameterize(sm, + hd, + uv_pm, + get(boost::vertex_index_t(),sm), + parameterized_pm); + switch(err) { + case Parameterizer::OK: // Success + break; + case Parameterizer::ERROR_EMPTY_MESH: // Input mesh not supported + case Parameterizer::ERROR_NON_TRIANGULAR_MESH: + case Parameterizer::ERROR_NO_TOPOLOGICAL_DISC: + case Parameterizer::ERROR_BORDER_TOO_SHORT: + std::cerr << "Input mesh not supported: " + << Parameterizer::get_error_message(err) << std::endl; + return EXIT_FAILURE; + break; + default: // Error + std::cerr << "Error: " << Parameterizer::get_error_message(err) << std::endl; + return EXIT_FAILURE; + break; + }; + + // Write the result in the polyline format + BOOST_FOREACH(face_descriptor fd, faces(sm)){ + halfedge_descriptor hd = halfedge(fd,sm); + std::cout << "4 " << uv_pm[target(hd,sm)].x() << " " << uv_pm[target(hd,sm)].y() << " 0 "; + hd = next(hd,sm); + BOOST_FOREACH(vertex_descriptor vd, vertices_around_face(hd,sm)){ + std::cout << uv_pm[vd].x() << " " << uv_pm[vd].y() << " 0 "; } - - // File name is: - const char* input_filename = argv[1]; - - //*************************************** - // Read the mesh - //*************************************** - - // Read the mesh - std::ifstream stream(input_filename); - Polyhedron mesh; - stream >> mesh; - if(!stream || !mesh.is_valid() || mesh.empty()) - { - std::cerr << "Error: cannot read OFF file " << input_filename << std::endl; - return EXIT_FAILURE; - } - - //*************************************** - // Create Polyhedron adaptor - // Note: no cutting => we support only - // meshes that are topological disks - //*************************************** - - typedef CGAL::Parameterization_polyhedron_adaptor_3 - Parameterization_polyhedron_adaptor; - Parameterization_polyhedron_adaptor mesh_adaptor(mesh); - - //*************************************** - // Floater Mean Value Coordinates parameterization - // (defaults are circular border and Eigen solver) - //*************************************** - - typedef CGAL::Parameterizer_traits_3 - Parameterizer; // Type that defines the error codes - - Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor); - switch(err) { - case Parameterizer::OK: // Success - break; - case Parameterizer::ERROR_EMPTY_MESH: // Input mesh not supported - case Parameterizer::ERROR_NON_TRIANGULAR_MESH: - case Parameterizer::ERROR_NO_TOPOLOGICAL_DISC: - case Parameterizer::ERROR_BORDER_TOO_SHORT: - std::cerr << "Input mesh not supported: " << Parameterizer::get_error_message(err) << std::endl; - return EXIT_FAILURE; - break; - default: // Error - std::cerr << "Error: " << Parameterizer::get_error_message(err) << std::endl; - return EXIT_FAILURE; - break; - }; - - //*************************************** - // Output - //*************************************** - - // Raw output: dump (u,v) pairs - Polyhedron::Vertex_iterator pVertex; - for (pVertex = mesh.vertices_begin(); - pVertex != mesh.vertices_end(); - pVertex++) - { - // (u,v) pair is stored in any halfedge - double u = mesh_adaptor.info(pVertex->halfedge())->uv().x(); - double v = mesh_adaptor.info(pVertex->halfedge())->uv().y(); - std::cout << "(u,v) = (" << u << "," << v << ")" << std::endl; - } - - return EXIT_SUCCESS; + std::cout << std::endl; + } + return EXIT_SUCCESS; } diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp index 25b83c9fd75..a05278844fd 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/blob.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/Surface_mesh_parameterization/include/CGAL/parameterize.h b/Surface_mesh_parameterization/include/CGAL/parameterize.h index d92d5176520..1755a7e039a 100644 --- a/Surface_mesh_parameterization/include/CGAL/parameterize.h +++ b/Surface_mesh_parameterization/include/CGAL/parameterize.h @@ -113,6 +113,24 @@ parameterize(TriangleMesh& mesh, return parameterizer.parameterize(mesh, bhd, uvm, boost::make_assoc_property_map(indices), vpm); } + +template +typename Parameterizer_traits_3::Error_code +parameterize(TriangleMesh& mesh, + HD bhd, + VertexUVmap uvm, + VertexIndexMap vimap, + VertexParameterizedMap 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))); + Mean_value_coordinates_parameterizer_3 parameterizer; + return parameterizer.parameterize(mesh, bhd, uvm, boost::make_assoc_property_map(indices), vpm); +} template class Seam_mesh;