diff --git a/Surface_mesh_topology/examples/Surface_mesh_topology/CMakeLists.txt b/Surface_mesh_topology/examples/Surface_mesh_topology/CMakeLists.txt index 6645467bd19..cba549eed31 100644 --- a/Surface_mesh_topology/examples/Surface_mesh_topology/CMakeLists.txt +++ b/Surface_mesh_topology/examples/Surface_mesh_topology/CMakeLists.txt @@ -27,17 +27,17 @@ endif() set(SOURCE_FILES basic_example_surface_mesh_topology.cpp basic_example_torus.cpp + edgewidth_surface_mesh.cpp + facewidth_on_unweighted_map.cpp map_2_constructor.cpp open_path_homotopy.cpp path_homotopy.cpp path_homotopy_with_symbols.cpp path_homotopy_with_symbols_2.cpp - surface_mesh_topology_with_sm_and_polyhedron.cpp shortest_noncontractible_cycle_through_a_vertex.cpp shortest_noncontractible_cycle_using_BFS.cpp + surface_mesh_topology_with_sm_and_polyhedron.cpp unsew_edgewidth_repeatedly.cpp - edgewidth_surface_mesh.cpp - facewidth_on_unweighted_map.cpp ) foreach(cppfile ${SOURCE_FILES}) @@ -46,11 +46,10 @@ endforeach() if(CGAL_Qt5_FOUND) target_link_libraries(basic_example_surface_mesh_topology PUBLIC CGAL::CGAL_Qt5) - target_link_libraries(basic_example_torus PUBLIC CGAL::CGAL_Qt5) + target_link_libraries(basic_example_torus PUBLIC CGAL::CGAL_Qt5) + target_link_libraries(facewidth_on_unweighted_map PUBLIC CGAL::CGAL_Qt5) target_link_libraries(open_path_homotopy PUBLIC CGAL::CGAL_Qt5) target_link_libraries(path_homotopy PUBLIC CGAL::CGAL_Qt5) target_link_libraries(surface_mesh_topology_with_sm_and_polyhedron PUBLIC CGAL::CGAL_Qt5) target_link_libraries(unsew_edgewidth_repeatedly PUBLIC CGAL::CGAL_Qt5) - target_link_libraries(shortest_noncontractible_cycle_through_a_vertex PUBLIC CGAL::CGAL_Qt5) - target_link_libraries(shortest_noncontractible_cycle_using_BFS PUBLIC CGAL::CGAL_Qt5) endif() 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 a29262189f5..8a5c3ab6873 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 @@ -5,53 +5,58 @@ #include #include -using Kernel = CGAL::Simple_cartesian; -using Point = Kernel::Point_3; -using Mesh = CGAL::Surface_mesh; -using Path_on_surface = CGAL::Surface_mesh_topology::Path_on_surface; -using CST = CGAL::Surface_mesh_topology::Curves_on_surface_topology; +using Kernel =CGAL::Simple_cartesian; +using Point =Kernel::Point_3; +using Mesh =CGAL::Surface_mesh; +using Path_on_surface=CGAL::Surface_mesh_topology::Path_on_surface; +using CST =CGAL::Surface_mesh_topology::Curves_on_surface_topology; -struct Weight_functor { - using Weight_t = double; +struct Weight_functor +{ + using Weight_t=double; Weight_functor(const Mesh& mesh) : m_mesh(mesh) {} - double operator()(Mesh::Halfedge_index he) const { - Point A = m_mesh.point(m_mesh.vertex(m_mesh.edge(he), 0)); - Point B = m_mesh.point(m_mesh.vertex(m_mesh.edge(he), 1)); + double operator()(Mesh::Halfedge_index he) const + { + const Point& A=m_mesh.point(m_mesh.vertex(m_mesh.edge(he), 0)); + const Point& B=m_mesh.point(m_mesh.vertex(m_mesh.edge(he), 1)); return CGAL::sqrt(CGAL::squared_distance(A, B)); } private: - Mesh m_mesh; + const Mesh& m_mesh; }; -int main(int argc, char* argv[]) { - std::cout << "Program edgewidth_surface_mesh started.\n"; - Mesh sm; - std::ifstream inp ((argc > 1) ? argv[1] : "data/3torus.off"); - if (inp.fail()) { - std::cout << "Cannot read file. Exiting program\n"; +int main(int argc, char* argv[]) +{ + std::cout<<"Program edgewidth_surface_mesh started."<1) { filename=argv[1]; } + std::ifstream inp(filename); + if (inp.fail()) + { + std::cout<<"Cannot read file '"<> sm; - std::cout << "File loaded. Running the main program...\n"; + Mesh sm; + inp>>sm; + std::cout<<"File '"< #include #include -#define CGAL_USE_BASIC_VIEWER 1 +using LCC_3 =CGAL::Linear_cell_complex_for_combinatorial_map<2, 3>; +using CST =CGAL::Surface_mesh_topology::Curves_on_surface_topology; +using Path_on_surface=CGAL::Surface_mesh_topology::Path_on_surface; +using Dart_handle =LCC_3::Dart_handle; -using LCC_3 = CGAL::Linear_cell_complex_for_combinatorial_map<2, 3>; -using CST = CGAL::Surface_mesh_topology::Curves_on_surface_topology; -using Path_on_surface = CGAL::Surface_mesh_topology::Path_on_surface; -using Dart_handle = LCC_3::Dart_handle; - -struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC { - Draw_functor(LCC_3::size_type amark1, LCC_3::size_type amark2) : m_vertex_mark(amark1), m_face_mark(amark2) +struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC +{ + Draw_functor(LCC_3::size_type amark1, LCC_3::size_type amark2) : + m_vertex_mark(amark1), m_face_mark(amark2) {} template @@ -23,83 +23,84 @@ struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC { { return alcc.is_marked(dh, m_vertex_mark); } template - CGAL::Color vertex_color(const LCC& /* alcc */, typename LCC::Dart_const_handle /* dh */) const + CGAL::Color vertex_color(const LCC& /* alcc */, + typename LCC::Dart_const_handle /* dh */) const { return CGAL::Color(0, 255, 0); } template - bool colored_edge(const LCC& alcc, typename LCC::Dart_const_handle dh) const { return false; } + bool colored_edge(const LCC& alcc, typename LCC::Dart_const_handle dh) const + { return false; } template - CGAL::Color edge_color(const LCC& /* alcc*/, typename LCC::Dart_const_handle /* dh */) const + 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;} + 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 alcc.is_marked(dh, m_face_mark) ? CGAL::Color(255, 0, 0) : CGAL::Color(211, 211, 211); } + { return alcc.is_marked(dh, m_face_mark)?CGAL::Color(255, 0, 0) + :CGAL::Color(211, 211, 211); } template - bool colored_volume(const LCC& /* alcc */, typename LCC::Dart_const_handle /* dh */) const { return false; } + bool colored_volume(const LCC& /* alcc */, + typename LCC::Dart_const_handle /* dh */) const + { return false; } LCC_3::size_type m_vertex_mark, m_face_mark; }; -LCC_3 lcc; - int main(int argc, char* argv[]) { - std::cout << "Program facewidth_on_unweighted_map started.\n"; - std::ifstream inp; - if (argc == 1) inp = std::ifstream("data/double-torus.off"); - else inp = std::ifstream(argv[1]); - if (inp.fail()) { - std::cout << "Cannot read file. Exiting program\n"; + std::cout<<"Program facewidth_on_unweighted_map started."<1) { filename=argv[1]; } + std::ifstream inp(filename); + if (inp.fail()) + { + std::cout<<"Cannot read file '"< cycle = cst.compute_facewidth(); - std::cout << "Finding the facewidth...\n"; - if (cycle.size() == 0) { - std::cout << " Cannot find such cycle. Stop.\n"; - return 0; - } - LCC_3::size_type vertex_mark = lcc.get_new_mark(); - LCC_3::size_type face_mark = lcc.get_new_mark(); - for (int i = 0; i < cycle.size(); ++i) + if (cycle.size()==0) + { std::cout<<" Cannot find such cycle. Stop."<(cycle[i]).begin(), - dhend = lcc.darts_of_cell<0>(cycle[i]).end(); dh != dhend; ++dh) - { - if (!lcc.is_marked(dh, vertex_mark)) - lcc.mark(dh, vertex_mark); - } - } - else - { - // Color the face - for (auto dh = lcc.darts_of_cell<2>(cycle[i]).begin(), - dhend = lcc.darts_of_cell<2>(cycle[i]).end(); dh != dhend; ++dh) - { - if (!lcc.is_marked(dh, face_mark)) - lcc.mark(dh, face_mark); + if (i%2==0) + { // Color the vertex + lcc.mark_cell<0>(cycle[i], vertex_mark); + } + else + { // Color the face + lcc.mark_cell<2>(cycle[i], face_mark); } } + + Draw_functor df(vertex_mark, face_mark); + CGAL::draw(lcc, "Face width", false, df); + + lcc.free_mark(vertex_mark); + lcc.free_mark(face_mark); +#endif // CGAL_USE_BASIC_VIEWER } - - std::cout << " Number of faces: " << cycle.size()/2 << std::endl; - - Draw_functor df(vertex_mark, face_mark); - CGAL::draw(lcc, "Hello", false, df); - - lcc.free_mark(vertex_mark); - lcc.free_mark(face_mark); + + 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 deb4d5a70d8..77d55c79c9d 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 @@ -7,53 +7,62 @@ #include #include -using LCC_3 = CGAL::Linear_cell_complex_for_generalized_map<2, 3>; -using Dart_const_handle = LCC_3::Dart_const_handle; -using Path_on_surface = CGAL::Surface_mesh_topology::Path_on_surface; -using CST = CGAL::Surface_mesh_topology::Curves_on_surface_topology; +using LCC_3 =CGAL::Linear_cell_complex_for_generalized_map<2, 3>; +using Dart_const_handle=LCC_3::Dart_const_handle; +using Dart_handle=LCC_3::Dart_handle; // TODO REMOVE +using Path_on_surface =CGAL::Surface_mesh_topology::Path_on_surface; +using CST =CGAL::Surface_mesh_topology::Curves_on_surface_topology; -struct Weight_functor { +struct Weight_functor +{ Weight_functor(const LCC_3& lcc) : m_lcc(lcc) { } - using Weight_t = double; - Weight_t operator()(Dart_const_handle dh) const { - auto x = m_lcc.point_of_vertex_attribute(m_lcc.vertex_attribute(dh)); - auto y = m_lcc.point_of_vertex_attribute(m_lcc.vertex_attribute(m_lcc.template alpha<0>(dh))); + using Weight_t=double; + Weight_t operator()(Dart_const_handle dh) const + { + const LCC_3::Point& x=m_lcc.point(dh); + const LCC_3::Point& y=m_lcc.point(m_lcc.alpha<0>(dh)); return CGAL::sqrt(CGAL::squared_distance(x, y)); } private: const LCC_3& m_lcc; }; -LCC_3 lcc; - 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("data/3torus.off"); - else inp = std::ifstream(argv[1]); - if (inp.fail()) { - std::cout << "Cannot load file. Exiting program...\n"; + std::cout<<"Program shortest_noncontractible_cycle_through_a_vertex started." + <1) { filename=argv[1]; } + std::ifstream inp(filename); + if (inp.fail()) + { + std::cout<<"Cannot read file '"< #include -using LCC_3 = CGAL::Linear_cell_complex_for_combinatorial_map<2, 3>; -using CST = CGAL::Surface_mesh_topology::Curves_on_surface_topology; -using Path_on_surface = CGAL::Surface_mesh_topology::Path_on_surface; - -LCC_3 lcc; +using LCC_3 =CGAL::Linear_cell_complex_for_combinatorial_map<2, 3>; +using CST =CGAL::Surface_mesh_topology::Curves_on_surface_topology; +using Path_on_surface=CGAL::Surface_mesh_topology::Path_on_surface; 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.off"); - else inp = std::ifstream(argv[1]); - if (inp.fail()) { - std::cout << "Cannot read file. Exiting program\n"; + std::cout<<"Program shortest_noncontractible_cycle_using_BFS started." + <1) { filename=argv[1]; } + std::ifstream inp(filename); + if (inp.fail()) + { + std::cout<<"Cannot read file '"< #include #include -#define CGAL_USE_BASIC_VIEWER 1 -using LCC_3 = CGAL::Linear_cell_complex_for_generalized_map<2, 3>; -using Dart_handle = LCC_3::Dart_handle; -using Dart_const_handle = LCC_3::Dart_const_handle; -using Dart_container = std::vector; -using Point = LCC_3::Point; -using Path_on_surface = CGAL::Surface_mesh_topology::Path_on_surface; +using LCC_3 =CGAL::Linear_cell_complex_for_generalized_map<2, 3>; +using Dart_handle =LCC_3::Dart_handle; +using Dart_const_handle=LCC_3::Dart_const_handle; +using Dart_container =std::vector; +using Point =LCC_3::Point; +using Path_on_surface =CGAL::Surface_mesh_topology::Path_on_surface; +using CST =CGAL::Surface_mesh_topology::Curves_on_surface_topology; -struct Weight_functor { - Weight_functor(const LCC_3& lcc) : m_lcc(lcc) { } - using Weight_t = double; - Weight_t operator()(Dart_const_handle dh) const { - const Point& x = m_lcc.point(dh); - const Point& y = m_lcc.point(m_lcc.template alpha<0>(dh)); +struct Weight_functor +{ + Weight_functor(const LCC_3& lcc) : m_lcc(lcc) {} + using Weight_t=double; + Weight_t operator()(Dart_const_handle dh) const + { + const Point& x=m_lcc.point(dh); + const Point& y=m_lcc.point(m_lcc.template alpha<0>(dh)); return CGAL::sqrt(CGAL::squared_distance(x, y)); } private: const LCC_3& m_lcc; }; -using CST = CGAL::Surface_mesh_topology::Curves_on_surface_topology; - -struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC { +struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC +{ Draw_functor(LCC_3::size_type am1, LCC_3::size_type am2) : is_root(am1), belong_to_cycle(am2) {} @@ -42,7 +43,8 @@ struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC { { return alcc.is_marked(dh, is_root); } template - CGAL::Color vertex_color(const LCC& /* alcc */, typename LCC::Dart_const_handle /* dh */) const + CGAL::Color vertex_color(const LCC& /* alcc */, + typename LCC::Dart_const_handle /* dh */) const { return CGAL::Color(0,255,0); } template @@ -50,30 +52,42 @@ struct Draw_functor : public CGAL::DefaultDrawingFunctorLCC { { return alcc.is_marked(dh, belong_to_cycle); } template - CGAL::Color edge_color(const LCC& /* alcc*/, typename LCC::Dart_const_handle /* dh */) const + 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;} + 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 + 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; } + bool colored_volume(const LCC& /* alcc */, + typename LCC::Dart_const_handle /* dh */) const { return false; } LCC_3::size_type is_root; LCC_3::size_type belong_to_cycle; }; -int main(int argc, char* argv[]) { - std::cout << "Program unsew_edgewidth_repeatedly started.\n"; +int main(int argc, char* argv[]) +{ + std::cout<<"Program unsew_edgewidth_repeatedly started."<1) { filename=argv[1]; } + std::ifstream inp(filename); + if (inp.fail()) + { + std::cout<<"Cannot read file '"< origin_to_copy; lcccopy.copy(lccoriginal, &origin_to_copy, NULL); @@ -82,50 +96,59 @@ int main(int argc, char* argv[]) { LCC_3::size_type belong_to_cycle=lccoriginal.get_new_mark(); Draw_functor df(is_root, belong_to_cycle); - std::cout << "File loaded. Running the main program...\n"; - for (int loop = 1; ; ++loop) { - std::cout << "Finding #" << loop << " edge-width:\n"; + int loop=1; + bool cycle_exist=true; + do + { + std::cout<<"Finding #"<(cycle[0], is_root_copy); + double cycle_length=0; + for (int i=0; i(cycle[i], belong_to_cycle_copy); } + } - lcccopy.mark_cell<0>(cycle[0], is_root_copy); - double x = 0; - for (int i = 0; i < cycle.length(); ++i) { - x += wf(cycle[i]); - if (!lcccopy.is_marked(cycle[i], belong_to_cycle_copy)) - lcccopy.mark_cell<1>(cycle[i], belong_to_cycle_copy); - } + for (auto dh=lccoriginal.darts().begin(), dhend=lccoriginal.darts().end(); + dh!=dhend; ++dh) + { + if (lcccopy.is_marked(origin_to_copy[dh], is_root_copy) && + !lccoriginal.is_marked(dh, is_root)) + { lccoriginal.mark(dh, is_root); } + if (lcccopy.is_marked(origin_to_copy[dh], belong_to_cycle_copy) && + !lccoriginal.is_marked(dh, belong_to_cycle)) + { lccoriginal.mark(dh, belong_to_cycle); } + if (lcccopy.is_marked(origin_to_copy[dh], belong_to_cycle_copy) && + !lcccopy.is_free<2>(origin_to_copy[dh])) + { lcccopy.unsew<2>(origin_to_copy[dh]); } + } + lcccopy.close<2>(); - for (auto dh = lccoriginal.darts().begin(), dhend = lccoriginal.darts().end(); dh != dhend; ++dh) { - if (lcccopy.is_marked(origin_to_copy[dh], is_root_copy) && !lccoriginal.is_marked(dh, is_root)) - lccoriginal.mark(dh, is_root); - if (lcccopy.is_marked(origin_to_copy[dh], belong_to_cycle_copy) && !lccoriginal.is_marked(dh, belong_to_cycle)) - lccoriginal.mark(dh, belong_to_cycle); - if (lcccopy.is_marked(origin_to_copy[dh], belong_to_cycle_copy) && !lcccopy.is_free<2>(origin_to_copy[dh])) - lcccopy.unsew<2>(origin_to_copy[dh]); - } - lcccopy.close<2>(); - - lcccopy.free_mark(belong_to_cycle_copy); - lcccopy.free_mark(is_root_copy); + lcccopy.free_mark(belong_to_cycle_copy); + lcccopy.free_mark(is_root_copy); - std::cout << " Number of edges in cycle: " << cycle.length() << std::endl; - std::cout << " Cycle length: " << x << std::endl; - std::cout << " Root: " << lcccopy.point_of_vertex_attribute(lcccopy.vertex_attribute(cycle[0])) << std::endl; - + std::cout<<" Number of edges in cycle: "<