add an example using OpenMesh

This commit is contained in:
Sébastien Loriot 2014-07-03 11:14:28 +02:00
parent 719155c2bd
commit 0a2b8d64f5
2 changed files with 94 additions and 0 deletions

View File

@ -32,6 +32,15 @@ if ( CGAL_FOUND )
create_single_source_cgal_program( "deform_polyhedron_with_custom_pmap_example.cpp" )
create_single_source_cgal_program( "k_ring_roi_translate_rotate_example.cpp" )
find_package( OpenMesh QUIET )
if ( OpenMesh_FOUND )
include( UseOpenMesh )
create_single_source_cgal_program( "all_roi_assign_example_with_OpenMesh.cpp" )
target_link_libraries( all_roi_assign_example_with_OpenMesh ${OPENMESH_LIBRARIES} )
else()
message(STATUS "Examples that use OpenMesh will not be compiled.")
endif()
else()
message(STATUS "NOTICE: These examples require the Eigen library, version 3.2 or later and will not be compiled.")
endif()

View File

@ -0,0 +1,85 @@
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
// HalfedgeGraph adapters
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
#include <CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h>
#include <CGAL/Deform_mesh.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::vertex_iterator vertex_iterator;
typedef boost::graph_traits<Mesh>::halfedge_iterator halfedge_iterator;
typedef CGAL::Deform_mesh<Mesh> Deform_mesh;
int main()
{
Mesh mesh;
OpenMesh::IO::read_mesh(mesh, "data/plane.off");
// Create a deformation object
Deform_mesh deform_mesh(mesh);
// Definition of the region of interest (use the whole mesh)
vertex_iterator vb,ve;
boost::tie(vb, ve) = vertices(mesh);
deform_mesh.insert_roi_vertices(vb, ve);
// Select two control vertices ...
vertex_descriptor control_1 = *CGAL::cpp11::next(vb, 213);
vertex_descriptor control_2 = *CGAL::cpp11::next(vb, 157);
// ... and insert them
deform_mesh.insert_control_vertex(control_1);
deform_mesh.insert_control_vertex(control_2);
// The definition of the ROI and the control vertices is done, call preprocess
bool is_matrix_factorization_OK = deform_mesh.preprocess();
if(!is_matrix_factorization_OK){
std::cerr << "Error in preprocessing, check documentation of preprocess()" << std::endl;
return 1;
}
// Use set_target_position() to set the constained position
// of control_1. control_2 remains at the last assigned positions
Deform_mesh::Point constrained_pos_1(-0.35, 0.40, 0.60);
deform_mesh.set_target_position(control_1, constrained_pos_1);
// Deform the mesh, the positions of vertices of 'mesh' are updated
deform_mesh.deform();
// The function deform() can be called several times if the convergence has not been reached yet
deform_mesh.deform();
// Set the constained position of control_2
Deform_mesh::Point constrained_pos_2(0.55, -0.30, 0.70);
deform_mesh.set_target_position(control_2, constrained_pos_2);
// Call the function deform() with one-time parameters:
// iterate 10 times and do not use energy based termination criterion
deform_mesh.deform(10, 0.0);
// Save the deformed mesh into a file
OpenMesh::IO::write_mesh(mesh,"deform_1.off");
// Add another control vertex which requires another call to preprocess
vertex_descriptor control_3 = *CGAL::cpp11::next(vb, 92);
deform_mesh.insert_control_vertex(control_3);
// The prepocessing step is again needed
if(!deform_mesh.preprocess()){
std::cerr << "Error in preprocessing, check documentation of preprocess()" << std::endl;
return 1;
}
// Deform the mesh
Deform_mesh::Point constrained_pos_3(0.55, 0.30, -0.70);
deform_mesh.set_target_position(control_3, constrained_pos_3);
deform_mesh.deform(15, 0.0);
OpenMesh::IO::write_mesh(mesh,"deform_2.off");
}