diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp index e4d8ca6a92e..4f40efa2463 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp @@ -1,6 +1,3 @@ -#include -#include - #include #include @@ -12,10 +9,12 @@ #include #include -typedef OpenMesh::PolyMesh_ArrayKernelT Surface_mesh; +#include +#include -typedef boost::graph_traits::edge_descriptor edge_descriptor; -typedef boost::graph_traits::edge_iterator edge_iterator; +typedef OpenMesh::PolyMesh_ArrayKernelT Surface_mesh; + +typedef boost::graph_traits::edge_descriptor edge_descriptor; class Constrained_edge_map { @@ -33,10 +32,10 @@ public: inline friend reference get(const Constrained_edge_map& em, key_type e) { - bool b = em.sm_.property(em.constraint,em.sm_.edge_handle(e.idx())); + bool b = em.sm_.property(em.constraint,em.sm_.edge_handle(e.idx())); return b; } - + inline friend void put(const Constrained_edge_map& em, key_type e, value_type b) { em.sm_.property(em.constraint,em.sm_.edge_handle(e.idx())) = b; @@ -47,14 +46,13 @@ private: OpenMesh::EPropHandleT constraint; }; - - namespace SMS = CGAL::Surface_mesh_simplification; -int main(int argc, char** argv) +int main(int argc, char** argv) { Surface_mesh surface_mesh; Constrained_edge_map constraints_map(surface_mesh); + if(argc==2) OpenMesh::IO::read_mesh(surface_mesh, argv[1]); else @@ -66,11 +64,10 @@ int main(int argc, char** argv) } // For the pupose of the example we mark 10 edges as constrained edges - edge_iterator b,e; int count=0; - for(boost::tie(b,e) = edges(surface_mesh); b!= e; ++b){ - put(constraints_map,*b,(count++ <100)); - } + for(edge_descriptor e : edges(surface_mesh)) + put(constraints_map, e, (count++ < 100)); + // This is a stop predicate (defines when the algorithm terminates). // In this example, the simplification stops when the number of undirected edges // left in the surface mesh drops below the specified number (1000) @@ -79,19 +76,16 @@ int main(int argc, char** argv) // This the actual call to the simplification algorithm. // The surface mesh and stop conditions are mandatory arguments. - int r = SMS::edge_collapse - (surface_mesh - ,stop - ,CGAL::parameters::halfedge_index_map (get(CGAL::halfedge_index ,surface_mesh)) - .vertex_point_map(get(boost::vertex_point, surface_mesh)) - .edge_is_constrained_map(constraints_map) - ); - + int r = SMS::edge_collapse(surface_mesh, stop, + CGAL::parameters::halfedge_index_map(get(CGAL::halfedge_index,surface_mesh)) + .vertex_point_map(get(boost::vertex_point, surface_mesh)) + .edge_is_constrained_map(constraints_map)); + surface_mesh.garbage_collection(); - std::cout << "\nFinished...\n" << r << " edges removed.\n" + std::cout << "\nFinished...\n" << r << " edges removed.\n" << num_edges(surface_mesh) << " final edges.\n"; - - OpenMesh::IO::write_mesh(surface_mesh, "out.off"); - + + OpenMesh::IO::write_mesh(surface_mesh, "out.off"); + return EXIT_SUCCESS; } diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_enriched_polyhedron.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_enriched_polyhedron.cpp index 3d7ec912846..2cafb14788e 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_enriched_polyhedron.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_enriched_polyhedron.cpp @@ -9,65 +9,60 @@ #include #include - -typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point; +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; // Setup an enriched polyhedron type which stores an id() field in the items -typedef CGAL::Polyhedron_3 Surface_mesh; +typedef CGAL::Polyhedron_3 Surface_mesh; -typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; -typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; namespace SMS = CGAL::Surface_mesh_simplification; -int main(int argc, char** argv) +int main(int argc, char** argv) { - Surface_mesh surface_mesh; - + Surface_mesh surface_mesh; + std::ifstream is(argv[1]); is >> surface_mesh; - if(!CGAL::is_triangle_mesh(surface_mesh)){ + if(!CGAL::is_triangle_mesh(surface_mesh)) + { std::cerr << "Input geometry is not triangulated." << std::endl; return EXIT_FAILURE; } - // The items in this polyhedron have an "id()" field + // The items in this polyhedron have an "id()" field // which the default index maps used in the algorithm // need to get the index of a vertex/edge. // However, the Polyhedron_3 class doesn't assign any value to // this id(), so we must do it here: int index = 0; - - for(halfedge_descriptor hd : halfedges(surface_mesh)){ + for(halfedge_descriptor hd : halfedges(surface_mesh)) hd->id() = index++; -} index = 0; - - for(vertex_descriptor vd : vertices(surface_mesh)){ + + for(vertex_descriptor vd : vertices(surface_mesh)) vd->id() = index++; -} - + // In this example, the simplification stops when the number of undirected edges // drops below 10% of the initial count SMS::Count_ratio_stop_predicate stop(0.1); - - + // The index maps are not explicitelty passed as in the previous // example because the surface mesh items have a proper id() field. // On the other hand, we pass here explicit cost and placement // function which differ from the default policies, ommited in // the previous example. int r = SMS::edge_collapse(surface_mesh, stop); - - std::cout << "\nFinished...\n" << r << " edges removed.\n" + + std::cout << "\nFinished...\n" << r << " edges removed.\n" << (surface_mesh.size_of_halfedges()/2) << " final edges.\n"; - + std::ofstream os(argc > 2 ? argv[2] : "out.off"); os.precision(17); os << surface_mesh; - - return EXIT_SUCCESS; -} + return EXIT_SUCCESS; +} diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp index 100367bd225..f6cc957b801 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp @@ -3,18 +3,10 @@ #include #include - -#include -#include - #include #include #include -// @tmp only required for STL reading -#include -#include - #include #include #include @@ -27,53 +19,20 @@ typedef CGAL::Surface_mesh Surface_mesh; namespace SMS = CGAL::Surface_mesh_simplification; -template -void read_mesh(const char* filename, - Mesh& sm) -{ - typedef typename K::Point_3 Point; - - std::ifstream in(filename, std::ios::binary); - if(!in.good()) - { - std::cerr << "Error: can't read file: " << filename << std::endl; - std::exit(1); - } - - std::string fn(filename); - if(fn.substr(fn.find_last_of(".") + 1) == "stl") - { - std::vector points; - std::vector > faces; - CGAL::read_STL(in, points, faces); - - if(!CGAL::Polygon_mesh_processing::orient_polygon_soup(points, faces)) - std::cerr << "W: File does not describe a polygon mesh" << std::endl; - - CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, faces, sm); - } - else if(fn.substr(fn.find_last_of(".") + 1) == "off") - { - if(!in || !(in >> sm)) - { - std::cerr << "Error: cannot OFF open mesh\n"; - return; - } - } - else - { - std::cerr << "Unknown file type" << std::endl; - return; - } -} - int main(int argc, char** argv) { Surface_mesh surface_mesh; const char* filename = argv[1]; - read_mesh(filename, surface_mesh); + std::ifstream is(argv[1]); + if(!is) + { + std::cerr << "Filename provided is invalid\n"; + return EXIT_FAILURE; + } + + is >> surface_mesh; if(!CGAL::is_triangle_mesh(surface_mesh)) { std::cerr << "Input geometry is not triangulated." << std::endl; diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_linear_cell_complex.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_linear_cell_complex.cpp index 5e58e5ef4b2..c0353240ec4 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_linear_cell_complex.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_linear_cell_complex.cpp @@ -1,55 +1,56 @@ -#include -#include #include + // Simplification function #include + // Stop-condition policy #include #include #include -typedef CGAL::Simple_cartesian Kernel; -typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; -typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper - <2, 3, MyTraits>::type LCC; +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; +typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper<2, 3, MyTraits>::type LCC; + namespace SMS = CGAL::Surface_mesh_simplification; int main(int argc, char** argv) { - if(argc<2 || argc>3) + if(argc < 2 || argc > 3) { - std::cout<<"Usage: simplification_Linear_cell_complex inofffile [outofffile]"<()) - .get_placement(SMS::Midpoint_placement()) - ); + int r = SMS::edge_collapse(lcc, stop, + CGAL::parameters::halfedge_index_map(get(CGAL::halfedge_index, lcc)) + .vertex_index_map(get(boost::vertex_index, lcc)) + .get_cost(SMS::Edge_length_cost()) + .get_placement(SMS::Midpoint_placement())); std::cout << "\nFinished...\n" << r << " edges removed.\n" << (lcc.number_of_darts()/2) << " final edges.\n"; - lcc.display_characteristics(std::cout)<<", is_valid="< -#include - #include #include @@ -10,19 +7,22 @@ // Stop-condition policy #include +#include +#include -typedef CGAL::Simple_cartesian Kernel; -typedef CGAL::Polyhedron_3 Surface_mesh; +typedef CGAL::Simple_cartesian Kernel; +typedef CGAL::Polyhedron_3 Surface_mesh; namespace SMS = CGAL::Surface_mesh_simplification; -int main(int argc, char** argv) +int main(int argc, char** argv) { Surface_mesh surface_mesh; - + std::ifstream is(argv[1]); is >> surface_mesh; - if(!CGAL::is_triangle_mesh(surface_mesh)){ + if(!CGAL::is_triangle_mesh(surface_mesh)) + { std::cerr << "Input geometry is not triangulated." << std::endl; return EXIT_FAILURE; } @@ -31,24 +31,21 @@ int main(int argc, char** argv) // In this example, the simplification stops when the number of undirected edges // left in the surface mesh drops below the specified number (1000) SMS::Count_stop_predicate stop(1000); - + // This the actual call to the simplification algorithm. // The surface mesh and stop conditions are mandatory arguments. // The index maps are needed because the vertices and edges // of this surface mesh lack an "id()" field. - int r = SMS::edge_collapse - (surface_mesh - ,stop - ,CGAL::parameters::vertex_index_map(get(CGAL::vertex_external_index, surface_mesh)) - .halfedge_index_map (get(CGAL::halfedge_external_index, surface_mesh)) - ); - - std::cout << "\nFinished...\n" << r << " edges removed.\n" + int r = SMS::edge_collapse(surface_mesh, stop, + CGAL::parameters::vertex_index_map(get(CGAL::vertex_external_index, surface_mesh)) + .halfedge_index_map(get(CGAL::halfedge_external_index, surface_mesh))); + + std::cout << "\nFinished...\n" << r << " edges removed.\n" << (surface_mesh.size_of_halfedges()/2) << " final edges.\n"; - + std::ofstream os(argc > 2 ? argv[2] : "out.off"); os.precision(17); os << surface_mesh; - - return EXIT_SUCCESS; + + return EXIT_SUCCESS; } diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_surface_mesh.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_surface_mesh.cpp index a10e30d9324..f5fe4ebbddf 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_surface_mesh.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_surface_mesh.cpp @@ -1,20 +1,16 @@ -#include -#include -#include - #include #include + #include #include -#include -#include -#include -#include +#include +#include +#include -typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point_3; -typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Surface_mesh Surface_mesh; namespace SMS = CGAL::Surface_mesh_simplification; @@ -31,47 +27,9 @@ void read_mesh(const char* filename, std::exit(1); } - std::string fn(filename); - if(fn.substr(fn.find_last_of(".") + 1) == "stl") + if(!in || !(in >> sm)) { - std::vector points; - std::vector > faces; - CGAL::read_STL(in, points, faces); - - if(!CGAL::Polygon_mesh_processing::orient_polygon_soup(points, faces)) - std::cerr << "W: File does not describe a polygon mesh" << std::endl; - - CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, faces, sm); - } - else if(fn.substr(fn.find_last_of(".") + 1) == "off") - { - if(!in || !(in >> sm)) - { - std::cerr << "Error: cannot OFF open mesh\n"; - return; - } - } - else if(fn.substr(fn.find_last_of(".") + 1) == "ply") - { - std::vector points; - std::vector > polygons; - std::vector fcolors; - std::vector vcolors; - - if(!(CGAL::read_PLY(in, points, polygons, fcolors, vcolors))) - { - std::cerr << "Error: cannot open PLY mesh\n"; - return; - } - - if(!CGAL::Polygon_mesh_processing::orient_polygon_soup(points, polygons)) - std::cerr << "W: File does not describe a polygon mesh" << std::endl; - - CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, polygons, sm); - } - else - { - std::cerr << "Unknown file type" << std::endl; + std::cerr << "Error: cannot read OFF mesh\n"; return; } } @@ -83,9 +41,7 @@ int main(int argc, char** argv) const char* filename = argv[1]; read_mesh(filename, surface_mesh); - std::chrono::steady_clock::time_point start_time - = std::chrono::steady_clock::now(); - + std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now(); // In this example, the simplification stops when the number of undirected edges // drops below 10% of the initial count @@ -93,20 +49,14 @@ int main(int argc, char** argv) int r = SMS::edge_collapse(surface_mesh, stop); - std::chrono::steady_clock::time_point end_time - = std::chrono::steady_clock::now(); - - - - std::cout << "Time elapsed: " - << std::chrono::duration_cast( - end_time - start_time - ).count() << "ms" << std::endl; - + std::chrono::steady_clock::time_point end_time = std::chrono::steady_clock::now(); std::cout << "\nFinished...\n" << r << " edges removed.\n" << surface_mesh.number_of_edges() << " final edges.\n"; + std::cout << "Time elapsed: " + << std::chrono::duration_cast(end_time - start_time).count() << "ms" << std::endl; + std::ofstream os(argc > 2 ? argv[2] : "out.off"); os.precision(17); os << surface_mesh; diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_visitor_surface_mesh.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_visitor_surface_mesh.cpp index fdf64920e03..a3e3a2dc6be 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_visitor_surface_mesh.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_visitor_surface_mesh.cpp @@ -1,6 +1,3 @@ -#include -#include - #include #include @@ -13,6 +10,9 @@ // Stop-condition policy #include +#include +#include + typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3;