diff --git a/Surface_mesh_topology/examples/Surface_mesh_topology/edgewidth_surface_mesh.cpp b/Surface_mesh_topology/examples/Surface_mesh_topology/edgewidth_surface_mesh.cpp index 67cc9734b96..acc2ea22dd9 100644 --- a/Surface_mesh_topology/examples/Surface_mesh_topology/edgewidth_surface_mesh.cpp +++ b/Surface_mesh_topology/examples/Surface_mesh_topology/edgewidth_surface_mesh.cpp @@ -25,22 +25,28 @@ using SNC = CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle 1) ? argv[1] : "data/3torus-smooth.off"); - in >> sm; + std::ifstream inp ((argc > 1) ? argv[1] : "../../examples/Surface_mesh_topology/data/3torus-smooth.off"); + if (inp.fail()) { + std::cout << "Cannot read file. Exiting program\n"; + return EXIT_FAILURE; + } + inp >> sm; std::cout << "File loaded. Running the main program...\n"; - Weight_functor wf(sm); - SNC snc(sm, wf); - SNC::Path cycle; - SNC::Distance_type x; + + Weight_functor wf(sm); + SNC snc(sm, wf); + SNC::Path cycle; + SNC::Distance_type cycle_length; + std::cout << "Finding edge-width of the mesh...\n"; - snc.edge_width(cycle, &x); + snc.edge_width(cycle, &cycle_length); if (cycle.size() == 0) { std::cout << " Cannot find edge-width. Stop.\n"; return 0; } std::cout << " Number of edges in cycle: " << cycle.size() << std::endl; - std::cout << " Cycle length: " << x << std::endl; + std::cout << " Cycle length: " << cycle_length << std::endl; std::cout << " Root: " << sm.point(sm.vertex(sm.edge(cycle[0]), 0)) << std::endl; return EXIT_SUCCESS; diff --git a/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_through_a_vertex.cpp b/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_through_a_vertex.cpp index cfcdea3836d..fee97d71cfe 100644 --- a/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_through_a_vertex.cpp +++ b/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_through_a_vertex.cpp @@ -9,23 +9,8 @@ #include #define CGAL_USE_BASIC_VIEWER 1 - -struct Myitem -{ - template - struct Dart_wrapper - { - typedef CGAL::Cell_attribute_with_point Vertex_attribute; - typedef CGAL::Cell_attribute_with_point Edge_attribute; - typedef CGAL::cpp11::tuple Attributes; - }; -}; - -using Traits = CGAL::Linear_cell_complex_traits<3>; -using LCC_3 = CGAL::Linear_cell_complex_for_generalized_map<2, 3, Traits, Myitem>; -using Dart_handle = LCC_3::Dart_handle; +using LCC_3 = CGAL::Linear_cell_complex_for_generalized_map<2, 3>; using Dart_const_handle = LCC_3::Dart_const_handle; -using Dart_container = std::vector; struct Weight_functor { Weight_functor(const LCC_3& lcc) : m_lcc(lcc) { } @@ -43,71 +28,33 @@ using SNC = CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle - bool colored_vertex(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return alcc.template info<0>(dh) != CGAL::Color();} - - template - CGAL::Color vertex_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return alcc.template info<0>(dh);} - - template - bool colored_edge(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return true; } - - template - CGAL::Color edge_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return alcc.template info<1>(dh);} - - template - bool colored_face(const LCC& alcc, typename LCC::Dart_const_handle dh) const {return true;} - - template - CGAL::Color face_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return CGAL::Color(211, 211, 211);} - - template - bool colored_volume(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return false; } -}; - -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ std::cout << "Program shortest_noncontractible_cycle_through_a_vertex started.\n"; std::ifstream inp; if (argc == 1) inp = std::ifstream("../../examples/Surface_mesh_topology/data/3torus.off"); else inp = std::ifstream(argv[1]); - CGAL::load_off(lcc, inp); - for (auto it = lcc.darts().begin(), itend = lcc.darts().end(); it != itend; ++it) { - lcc.set_attribute<1>(it, lcc.create_attribute<1>()); - lcc.set_attribute<0>(it, lcc.create_attribute<0>()); + if (inp.fail()) { + std::cout << "Cannot load file. Exiting program...\n"; + return EXIT_FAILURE; } + CGAL::load_off(lcc, inp); std::cout << "File loaded. Running the main program...\n"; - Draw_functor df; - Weight_functor wf(lcc); - SNC snc(lcc, wf); - SNC::Path cycle; - SNC::Distance_type x; - /// CHANGE THE VALUE OF `root` TO TEST THE ALGORITHM AT ANOTHER VERTEX + + Weight_functor wf(lcc); + SNC snc(lcc, wf); + SNC::Path cycle; + SNC::Distance_type cycle_length; + + /// Change the value of `root` to test the algorithm at another vertex auto root = lcc.darts().begin(); std::cout << "Finding the shortest noncontractible cycle...\n"; - snc.find_cycle(root, cycle, &x); + snc.find_cycle(root, cycle, &cycle_length); if (cycle.size() == 0) { std::cout << " Cannot find such cycle. Stop.\n"; return 0; } - LCC_3::size_type m = lcc.get_new_mark(); - for (auto e : cycle) { - lcc.mark_cell<1>(e, m); - } - lcc.info<0>(root) = CGAL::Color(255, 0, 0); - for (auto dh = lcc.one_dart_per_cell<1>().begin(), dhend = lcc.one_dart_per_cell<1>().end(); dh != dhend; ++dh) - if (lcc.is_marked(dh, m)) { - lcc.info<1>(dh) = CGAL::Color(0, 0, 255); - } - lcc.free_mark(m); std::cout << " Number of edges in cycle: " << cycle.size() << std::endl; - std::cout << " Cycle length: " << x << std::endl; + std::cout << " Cycle length: " << cycle_length << std::endl; std::cout << " Root: " << lcc.point_of_vertex_attribute(lcc.vertex_attribute(root)) << std::endl; - CGAL::draw(lcc, "Hello", false, df); } diff --git a/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_using_BFS.cpp b/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_using_BFS.cpp index 313ed045111..dc19da49873 100644 --- a/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_using_BFS.cpp +++ b/Surface_mesh_topology/examples/Surface_mesh_topology/shortest_noncontractible_cycle_using_BFS.cpp @@ -10,72 +10,36 @@ #define CGAL_USE_BASIC_VIEWER 1 using LCC_3 = CGAL::Linear_cell_complex_for_combinatorial_map<2, 3>; -using size_type = LCC_3::size_type; using SNC = CGAL::Surface_mesh_topology::Shortest_noncontractible_cycle; LCC_3 lcc; -struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC { - Draw_functor(size_type edge_mark, size_type vertex_mark) : m_edge_mark(edge_mark), m_vertex_mark(vertex_mark) {} - - template - bool colored_vertex(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return alcc.is_marked(dh, m_vertex_mark);} - - template - CGAL::Color vertex_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return CGAL::Color(255, 0, 0);} - - template - bool colored_edge(const LCC& alcc, typename LCC::Dart_const_handle dh) const - { return alcc.is_marked(dh, m_edge_mark); } - - template - CGAL::Color edge_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return CGAL::Color(0, 0, 255);} - - template - bool colored_face(const LCC& alcc, typename LCC::Dart_const_handle dh) const {return true;} - - template - CGAL::Color face_color(const LCC& alcc, typename LCC::Dart_const_handle dh) const - {return CGAL::Color(211, 211, 211);} - - template - bool colored_volume(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return false; } - -private: - size_type m_edge_mark, m_vertex_mark; -}; - -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ std::cout << "Program shortest_noncontractible_cycle_using_BFS started.\n"; std::ifstream inp; - if (argc == 1) inp = std::ifstream("data/3torus-smooth.off"); + if (argc == 1) inp = std::ifstream("../../examples/Surface_mesh_topology/data/3torus-smooth.off"); else inp = std::ifstream(argv[1]); + if (inp.fail()) { + std::cout << "Cannot read file. Exiting program\n"; + return EXIT_FAILURE; + } CGAL::load_off(lcc, inp); std::cout << "File loaded. Running the main program...\n"; - SNC snc(lcc); - SNC::Path cycle; - SNC::Distance_type x; + SNC snc(lcc); + SNC::Path cycle; + SNC::Distance_type cycle_length; + + /// Change the value of `root` to test the algorithm at another vertex auto root = lcc.darts().begin(); std::cout << "Finding the shortest noncontractible cycle...\n"; - snc.find_cycle(root, cycle, &x); + snc.find_cycle(root, cycle, &cycle_length); if (cycle.size() == 0) { std::cout << " Cannot find such cycle. Stop.\n"; return 0; } - size_type m = lcc.get_new_mark(), is_root = lcc.get_new_mark(); - for (auto e : cycle) { - lcc.mark_cell<1>(e, m); - } - lcc.mark_cell<0>(root, is_root); std::cout << " Number of edges in cycle: " << cycle.size() << std::endl; - std::cout << " Cycle length: " << x << std::endl; + std::cout << " Cycle length: " << cycle_length << std::endl; std::cout << " Root: " << lcc.point_of_vertex_attribute(lcc.vertex_attribute(root)) << std::endl; - Draw_functor df(m, is_root); - CGAL::draw(lcc, "Hello", false, df); - lcc.free_mark(m); - lcc.free_mark(is_root); }