#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/boost/graph/properties_Polyhedron_3.h>
#include <CGAL/Surface_mesh_deformation.h>
#include <fstream>
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
int main()
{
Polyhedron mesh;
std::ifstream input("data/plane.off");
if ( !input || !(input >> mesh) || mesh.empty() ) {
std::cerr<< "Cannot open data/plane.off" << std::endl;
return 1;
}
Surface_mesh_deformation deform_mesh(mesh);
vertex_iterator vb,ve;
boost::tie(vb, ve) = vertices(mesh);
deform_mesh.insert_roi_vertices(vb, ve);
deform_mesh.insert_control_vertex(control_1);
deform_mesh.insert_control_vertex(control_2);
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;
}
Surface_mesh_deformation::Point constrained_pos_1(-0.35, 0.40, 0.60);
deform_mesh.set_target_position(control_1, constrained_pos_1);
deform_mesh.deform();
deform_mesh.deform();
Surface_mesh_deformation::Point constrained_pos_2(0.55, -0.30, 0.70);
deform_mesh.set_target_position(control_2, constrained_pos_2);
deform_mesh.deform(10, 0.0);
std::ofstream output("deform_1.off");
output << mesh;
output.close();
deform_mesh.insert_control_vertex(control_3);
if(!deform_mesh.preprocess()){
std::cerr << "Error in preprocessing, check documentation of preprocess()" << std::endl;
return 1;
}
Surface_mesh_deformation::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);
output.open("deform_2.off");
output << mesh;
}