diff --git a/Surface_mesh_topology/examples/Surface_mesh_topology/path_homotopy_with_symbols_2.cpp b/Surface_mesh_topology/examples/Surface_mesh_topology/path_homotopy_with_symbols_2.cpp index 5c8ef1f09fc..2d6fef267f5 100644 --- a/Surface_mesh_topology/examples/Surface_mesh_topology/path_homotopy_with_symbols_2.cpp +++ b/Surface_mesh_topology/examples/Surface_mesh_topology/path_homotopy_with_symbols_2.cpp @@ -13,12 +13,12 @@ int main() ps.add_facet("a b -a c"); // First facet, giving directly its sequence of edges ps.add_facet("d -c e -b"); // Second facet - ps.begin_facet(); // Third facet + ps.init_facet(); // Third facet ps.add_edges_to_facet("f"); // Here, each edge is added one at a time ps.add_edges_to_facet("-d"); ps.add_edges_to_facet("-f"); ps.add_edges_to_facet("-e"); - ps.end_facet(); + ps.finish_facet(); ps.perforate_facet("f"); diff --git a/Surface_mesh_topology/include/CGAL/Path_on_surface.h b/Surface_mesh_topology/include/CGAL/Path_on_surface.h index 24fa8a946c7..cd21fd2d13c 100644 --- a/Surface_mesh_topology/include/CGAL/Path_on_surface.h +++ b/Surface_mesh_topology/include/CGAL/Path_on_surface.h @@ -37,13 +37,16 @@ #include // A Path_on_surface contains two vectors of equal length n -// The first one is a vector of darts called m_path and the second one a vector of booleans called m_flip -// If n = 0, the path represented by those vectors is the empty path +// The first one is a vector of darts called m_path and the second one a vector +// of booleans called m_flip. +// If n = 0, the path represented by those vectors is the empty path. // Else, it is the path represented by the n-1 first elements of both vectors, -// at the one we add the m_path[n-1] dart if m_flip[n-1] is false and the opposite of this dart if m_flip[n-1] is true -// i.e. if m_flip[i] is true means that the i-th dart m_path[i] has to be flipped -// We use flips because sometimes opposite darts doesn't exist on surfaces with boundaries -// But if m_flip[i] is true doesn't necesary mean that m_path[i] is 2-free +// at the one we add the m_path[n-1] dart if m_flip[n-1] is false and the +// opposite of this dart if m_flip[n-1] is true i.e. if m_flip[i] is true means +// that the i-th dart m_path[i] has to be flipped. +// We use flips because sometimes opposite darts doesn't exist on surfaces with +// boundaries. But if m_flip[i] is true doesn't necesary mean that +// m_path[i] is 2-free namespace CGAL { namespace Surface_mesh_topology { @@ -722,13 +725,19 @@ public: /// If this face does not exist (if it is a boundary) then replace the edge /// by the face on the other side. Problem of complexity when used many times /// (like in update_path_randomly). - void push_around_face(std::size_t i, bool update_isclosed=true) + bool push_around_face(std::size_t i, bool update_isclosed=true) { CGAL_assertion(i(get_ith_dart(i)); do { @@ -748,16 +757,20 @@ public: while(dh!=get_ith_dart(i)); } + // 2) We copy the end of the path. p2.m_path.reserve(p2.length()+length()-i); for (std::size_t j=i+1; j #include #include +#include +#include #include #include #include #include #include +#include namespace CGAL { namespace Surface_mesh_topology { @@ -223,7 +226,7 @@ namespace Surface_mesh_topology { } /// Start a new facet. - void begin_facet() + void init_facet() { if (facet_started) { @@ -291,9 +294,9 @@ namespace Surface_mesh_topology { <<" but the previous facet is not yet ended."< - bool is_free(const std::string& s) const - { - auto ite=edge_label_to_dart.find(s); - if (ite==edge_label_to_dart.end()) - {// maybe there is no need to put an error message - std::cerr<<"Polygonal_schema ERROR: " - <<"you ask if label "<(ite->second); - } - - /// Non templated versions - bool is_free(const std::string& s, unsigned int i) const - { - auto ite=edge_label_to_dart.find(s); - if (ite==edge_label_to_dart.end()) - {// maybe there is no need to put an error message - std::cerr<<"Polygonal_schema ERROR: " - <<"you ask if label "<second, i); - } - void display_perforated_darts() const { std::cout<<"labels is_free<2> is_perforated"< edge_label_to_dart; std::size_t mark_perforated; // mark for perforated facets. @@ -485,6 +455,7 @@ namespace Surface_mesh_topology { bool facet_started; }; + /// Polygonal schema with combinatorial map. template > @@ -545,6 +516,7 @@ namespace Surface_mesh_topology { {} }; + /// Polygonal schema with generalized map. template > @@ -605,6 +577,53 @@ namespace Surface_mesh_topology { {} }; + /// Generate a random polygonal schema ps. + /// @param nb_labels the number of labels used to generate ps. + /// @param seed the seed used for random + /// @param max_dart_per_face maximal number of darts per face + /// @param closed if true generates a closed polygonal schema. + /// @param percentage_of_perforated percentage of perforated faces. If 0 + /// no perforated faces. + template + void generate_random_polygonal_schema(PS& ps, std::size_t nb_labels, + unsigned int seed + =static_cast(std::time(nullptr)), + std::size_t max_dart_per_face=30, + bool closed=true, + std::size_t percentage_of_perforated=20) + { + CGAL::Random random(seed); + std::vector all_labels(nb_labels*2); + for (std::size_t i=0; i(i)+1); + all_labels[(2*i)+1]=std::to_string(-(static_cast(i)+1)); + } + + std::shuffle(all_labels.begin(), all_labels.end(), + std::default_random_engine(seed)); + + std::size_t endlabel=all_labels.size(); + if (!closed) + { endlabel-=(all_labels.size()/10); } // We remove 10% of labels. + + for (std::size_t i=0; i + (random.get_int(1, static_cast(max_dart_per_face))); + i(it)) + else if (Original_dart_const_handle(it)< + get_original_map().template beta<2>(it)) { d1=get_reduced_map().create_dart(); d2=get_reduced_map().create_dart(); diff --git a/Surface_mesh_topology/test/Surface_mesh_topology/test_homotopy_with_polygonal_schema.cpp b/Surface_mesh_topology/test/Surface_mesh_topology/test_homotopy_with_polygonal_schema.cpp index be36118bb48..612a7273db0 100644 --- a/Surface_mesh_topology/test/Surface_mesh_topology/test_homotopy_with_polygonal_schema.cpp +++ b/Surface_mesh_topology/test/Surface_mesh_topology/test_homotopy_with_polygonal_schema.cpp @@ -2,8 +2,6 @@ #include #include #include -#include -#include #include #include @@ -14,55 +12,21 @@ using namespace CGAL::Surface_mesh_topology; static unsigned int starting_seed; -/////////////////////////////////////////////////////////////////////////////// -int myrandom (int i) { return std::rand()%i;} -//----------------------------------------------------------------------------- -void generate_random_map(PS& ps, std::size_t nb_labels, - std::size_t max_dart_per_face=30, - bool closed=true, - std::size_t percentage_of_perforated=20) // 0 => no perforated faces -{ - std::vector all_labels(nb_labels*2); - for (std::size_t i=0; i(i)+1); - all_labels[(2*i)+1]=std::to_string(-(static_cast(i)+1)); - } - - std::random_shuffle(all_labels.begin(), all_labels.end(), myrandom); - - std::size_t endlabel=all_labels.size(); - if (!closed) - { endlabel-=(all_labels.size()/10); } // We remove 10% of labels. - - for (std::size_t i=0; i(rand())%max_dart_per_face); - i& cst, unsigned int nbtests, - unsigned int lmin=5, - unsigned int lmax=20) + unsigned int& seed, + int lmin=5, + int lmax=20) { CGAL_assertion(lmin>0 && lmin p1(ps), p2(ps); - internal::generate_random_closed_path(p1, random.get_int(lmin, lmax), random); + internal::generate_random_closed_path(p1, + static_cast + (random.get_int(lmin, lmax)), + random); p2=p1; p2.update_path_randomly(100, random); @@ -72,8 +36,8 @@ bool test_two_random_paths(const PS& ps, if (!cst.are_freely_homotopic(p1, p2)) { res=false; - std::cout<<"ERROR for path number "<& cst, - unsigned int lmin=5, - unsigned int lmax=20) + unsigned int& seed, + int lmin=5, + int lmax=20) { static std::size_t nbtest=0; - std::cout<<"Test "< cst1(ps1); - Curves_on_surface_topology cst2(ps2); - Curves_on_surface_topology cst3(ps3); - Curves_on_surface_topology cst4(ps4); - + bool closed=true; + std::size_t percent=0; bool res=true; - //res&=run_n_random_paths_tests(ps1, 20, cst1); - //res&=run_n_random_paths_tests(ps2, 20, cst2); - //res&=run_n_random_paths_tests(ps3, 20, cst3); - res&=run_n_random_paths_tests(ps4, 20, cst4); + for (int i=0; i<3; ++i) + { + for (int j=0; j<5; ++j) + { // 5 tests for the same "type" of polygonal schema + // (open/closed; with or without perforated) + PS ps; + Curves_on_surface_topology cst(ps); + generate_random_polygonal_schema(ps, 5000, starting_seed++, 30, closed, percent); // Closed, no perforated faces + res&=run_n_random_paths_tests(ps, 20, cst, starting_seed); + } + switch(i) + { + case 0: closed=true; percent=15; break; + case 1: closed=false; percent=0; break; + case 2: closed=false; percent=15; break; + } + } if (res) { std::cout<<"test_homotopy_with_polygonal_schema ALL TESTS OK."<