clean Simple_parameterization.cpp

This commit is contained in:
Andreas Fabri 2016-01-20 18:31:02 +01:00 committed by Mael Rouxel-Labbé
parent 7997925bf8
commit b7c5d49689
3 changed files with 76 additions and 95 deletions

View File

@ -1,109 +1,73 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Parameterization_polyhedron_adaptor_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/parameterize.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <iostream>
#include <fstream>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
// ----------------------------------------------------------------------------
// Private types
// ----------------------------------------------------------------------------
namespace PMP = CGAL::Polygon_mesh_processing;
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> 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<Mesh>::null_halfedge()){
std::cout << "mesh has no border" << std::endl;
return(EXIT_FAILURE);
}
Mesh::Property_map<vertex_descriptor,Point_2> uv_pm;
uv_pm = sm.add_property_map<vertex_descriptor,Point_2>("v:uv").first;
Mesh::Property_map<vertex_descriptor,bool> parameterized_pm;
parameterized_pm = sm.add_property_map<vertex_descriptor,bool>("v:parameterized",false).first;
typedef CGAL::Parameterizer_traits_3<Mesh> 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<Polyhedron>
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<Parameterization_polyhedron_adaptor>
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;
}

View File

@ -10,7 +10,6 @@
#include <CGAL/Barycentric_mapping_parameterizer_3.h>
#include <CGAL/Mean_value_coordinates_parameterizer_3.h>
#include <CGAL/LSCM_parameterizer_3.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <boost/foreach.hpp>
#include <iostream>
#include <cstdlib>

View File

@ -113,6 +113,24 @@ parameterize(TriangleMesh& mesh,
return parameterizer.parameterize(mesh, bhd, uvm, boost::make_assoc_property_map(indices), vpm);
}
template <class TriangleMesh, class HD, class VertexUVmap, typename VertexIndexMap, typename VertexParameterizedMap>
typename Parameterizer_traits_3<TriangleMesh>::Error_code
parameterize(TriangleMesh& mesh,
HD bhd,
VertexUVmap uvm,
VertexIndexMap vimap,
VertexParameterizedMap vpm)
{
typedef typename boost::graph_traits<TriangleMesh>::vertex_descriptor vertex_descriptor;
typedef std::map<vertex_descriptor,int> Indices;
Indices indices;
CGAL::Polygon_mesh_processing::connected_component(face(opposite(bhd,mesh),mesh),
mesh,
boost::make_function_output_iterator(Parameterization::Vertices<TriangleMesh,Indices>(mesh,indices)));
Mean_value_coordinates_parameterizer_3<TriangleMesh> parameterizer;
return parameterizer.parameterize(mesh, bhd, uvm, boost::make_assoc_property_map(indices), vpm);
}
template <class TM>
class Seam_mesh;