1 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 2 #include <CGAL/Surface_mesh.h> 3 4 #include <CGAL/Polygon_mesh_processing/smooth_shape.h> 5 #include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h> 6 7 #include <iostream> 8 #include <fstream> 9 10 typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 11 typedef CGAL::Surface_mesh<K::Point_3> Mesh; 12 13 namespace PMP = CGAL::Polygon_mesh_processing; 14 main(int argc,char * argv[])15int main(int argc, char* argv[]) 16 { 17 const char* filename = (argc > 1) ? argv[1] : "data/pig.off"; 18 19 Mesh mesh; 20 if(!PMP::IO::read_polygon_mesh(filename, mesh)) 21 { 22 std::cerr << "Invalid input." << std::endl; 23 return 1; 24 } 25 26 const unsigned int nb_iterations = (argc > 2) ? std::atoi(argv[2]) : 10; 27 const double time = (argc > 3) ? std::atof(argv[3]) : 0.0001; 28 29 std::set<Mesh::Vertex_index> constrained_vertices; 30 for(Mesh::Vertex_index v : vertices(mesh)) 31 { 32 if(is_border(v, mesh)) 33 constrained_vertices.insert(v); 34 } 35 36 std::cout << "Constraining: " << constrained_vertices.size() << " border vertices" << std::endl; 37 CGAL::Boolean_property_map<std::set<Mesh::Vertex_index> > vcmap(constrained_vertices); 38 39 std::cout << "Smoothing shape... (" << nb_iterations << " iterations)" << std::endl; 40 PMP::smooth_shape(mesh, time, PMP::parameters::number_of_iterations(nb_iterations) 41 .vertex_is_constrained_map(vcmap)); 42 43 CGAL::IO::write_polygon_mesh("mesh_shape_smoothed.off", mesh, CGAL::parameters::stream_precision(17)); 44 45 std::cout << "Done!" << std::endl; 46 return EXIT_SUCCESS; 47 } 48