From ff6ad8b959f6c20380f3d68ebb1bbbf1224adcfd Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 13 Oct 2015 15:34:28 +0000 Subject: Manual merge of skb_simplex_insertion after last trunk big modifications on Skbl git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@855 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d7f7721e2963de439a28040196423d4c0df07d3f --- src/Contraction/example/Rips_contraction.cpp | 4 ++-- src/Contraction/include/gudhi/Edge_contraction.h | 4 ++-- src/Contraction/include/gudhi/Skeleton_blocker_contractor.h | 11 +++-------- 3 files changed, 7 insertions(+), 12 deletions(-) (limited to 'src/Contraction') diff --git a/src/Contraction/example/Rips_contraction.cpp b/src/Contraction/example/Rips_contraction.cpp index d21246ed..f80cc2dc 100644 --- a/src/Contraction/example/Rips_contraction.cpp +++ b/src/Contraction/example/Rips_contraction.cpp @@ -49,7 +49,7 @@ void build_rips(ComplexType& complex, double offset) { for (auto p = vertices.begin(); p != vertices.end(); ++p) for (auto q = p; ++q != vertices.end(); /**/) { if (squared_dist(complex.point(*p), complex.point(*q)) < 4 * offset * offset) - complex.add_edge(*p, *q); + complex.add_edge_without_blockers(*p, *q); } } @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { contractor.contract_edges(); std::cout << "Counting final number of simplices \n"; - unsigned num_simplices = std::distance(complex.simplex_range().begin(), complex.simplex_range().end()); + unsigned num_simplices = std::distance(complex.complex_simplex_range().begin(), complex.complex_simplex_range().end()); std::cout << "Final complex has " << complex.num_vertices() << " vertices, " << diff --git a/src/Contraction/include/gudhi/Edge_contraction.h b/src/Contraction/include/gudhi/Edge_contraction.h index dfce8d1b..b996d9fb 100644 --- a/src/Contraction/include/gudhi/Edge_contraction.h +++ b/src/Contraction/include/gudhi/Edge_contraction.h @@ -158,7 +158,7 @@ void build_rips(ComplexType& complex, double offset){ for (auto p = vertices.begin(); p != vertices.end(); ++p) for (auto q = p; ++q != vertices.end(); ) if (eucl_distance(complex.point(*p), complex.point(*q)) < 2 * offset) - complex.add_edge(*p,*q); + complex.add_edge_without_blockers(*p,*q); } int main (int argc, char *argv[]) @@ -194,7 +194,7 @@ int main (int argc, char *argv[]) contractor.contract_edges(); std::cout << "Counting final number of simplices \n"; - unsigned num_simplices = std::distance(complex.simplex_range().begin(),complex.simplex_range().end()); + unsigned num_simplices = std::distance(complex.star_simplex_range().begin(),complex.star_simplex_range().end()); std::cout << "Final complex has "<< complex.num_vertices()<<" vertices, "<< diff --git a/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h b/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h index 2759b540..d6350a2c 100644 --- a/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h +++ b/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h @@ -107,13 +107,8 @@ typename GeometricSimplifiableComplex::Vertex_handle> { public: typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex; typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle; - typedef typename GeometricSimplifiableComplex::Simplex_handle Simplex_handle; - typedef typename GeometricSimplifiableComplex::Simplex_handle_iterator Simplex_handle_iterator; - - - + typedef typename GeometricSimplifiableComplex::Simplex Simplex; typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle; - typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge; typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle; typedef typename GeometricSimplifiableComplex::Point Point; @@ -535,14 +530,14 @@ typename GeometricSimplifiableComplex::Vertex_handle> { * All the edges that passes through the blocker may be edge-contractible * again and are thus reinserted in the heap. */ - void on_delete_blocker(const Simplex_handle * blocker) override { + void on_delete_blocker(const Simplex * blocker) override { // we go for all pairs xy that belongs to the blocker // note that such pairs xy are necessarily edges of the complex // by definition of a blocker // todo uniqument utile pour la link condition // laisser a l'utilisateur ? booleen update_heap_on_removed_blocker? - Simplex_handle blocker_copy(*blocker); + Simplex blocker_copy(*blocker); for (auto x = blocker_copy.begin(); x != blocker_copy.end(); ++x) { for (auto y = x; ++y != blocker_copy.end();) { auto edge_descr(complex_[std::make_pair(*x, *y)]); -- cgit v1.2.3 From 20cb0d7a919005ba20d0a76cca38a73d3a119480 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sun, 18 Oct 2015 10:44:55 +0000 Subject: GH: dim3 restriction, skbl: num_simplices methods git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@865 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e7f9d48c4e6af222b6f158e906a3a592027d39b8 --- src/Contraction/example/Garland_heckbert.cpp | 23 ++++++++++------ .../include/gudhi/Skeleton_blocker_complex.h | 31 ++++++++++++++++++---- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 4 +-- .../test/TestSkeletonBlockerComplex.cpp | 22 +++++++++++++-- 4 files changed, 62 insertions(+), 18 deletions(-) (limited to 'src/Contraction') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 70f29b6a..681426e0 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -145,13 +145,13 @@ class GH_visitor : public Gudhi::contraction::Contraction_visitor { int main(int argc, char *argv[]) { if (argc != 4) { - std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save " - << "the result to output.off.\n"; + std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; return EXIT_FAILURE; } Complex complex; - + typedef typename Complex::Vertex_handle Vertex_handle; + // load the points Skeleton_blocker_off_reader off_reader(argv[1], complex); if (!off_reader.is_valid()) { @@ -159,8 +159,12 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; + if(!complex.empty() && !complex.point(Vertex_handle(0)).dimension()==3) { + std::cerr << "Only points of dimension 3 are supported." << std::endl; + return EXIT_FAILURE; + } + std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; int num_contractions = atoi(argv[3]); @@ -171,22 +175,25 @@ int main(int argc, char *argv[]) { new GH_cost(complex), new GH_placement(complex), contraction::make_link_valid_contraction(), - new GH_visitor(complex)); + new GH_visitor(complex) + ); std::cout << "Contract " << num_contractions << " edges" << std::endl; contractor.contract_edges(num_contractions); std::cout << "Final complex has " << complex.num_vertices() << " vertices, " << - complex.num_edges() << " edges and" << + complex.num_edges() << " edges and " << complex.num_triangles() << " triangles." << std::endl; - // write simplified complex + //write simplified complex Skeleton_blocker_off_writer off_writer(argv[2], complex); return EXIT_SUCCESS; } +#endif // GARLAND_HECKBERT_H_ + + -#endif // GARLAND_HECKBERT_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index 78384abf..b1995783 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -134,8 +134,8 @@ class Skeleton_blocker_complex { typedef typename std::multimap::const_iterator BlockerMapConstIterator; protected: - int num_vertices_; - int num_blockers_; + size_t num_vertices_; + size_t num_blockers_; typedef Skeleton_blocker_complex_visitor Visitor; // typedef Visitor* Visitor_ptr; @@ -164,10 +164,10 @@ class Skeleton_blocker_complex { /** *@brief constructs a simplicial complex with a given number of vertices and a visitor. */ - explicit Skeleton_blocker_complex(int num_vertices_ = 0, Visitor* visitor_ = NULL) + explicit Skeleton_blocker_complex(size_t num_vertices_ = 0, Visitor* visitor_ = NULL) : visitor(visitor_) { clear(); - for (int i = 0; i < num_vertices_; ++i) { + for (size_t i = 0; i < num_vertices_; ++i) { add_vertex(); } } @@ -998,10 +998,31 @@ class Skeleton_blocker_complex { return std::distance(triangles.begin(), triangles.end()); } + + /* + * @brief returns the number of simplices of a given dimension in the complex. + */ + size_t num_simplices() const { + auto simplices = complex_simplex_range(); + return std::distance(simplices.begin(), simplices.end()); + } + + /* + * @brief returns the number of simplices of a given dimension in the complex. + */ + size_t num_simplices(unsigned dimension) const { + //todo iterator on k-simplices + size_t res = 0; + for(const auto& s: complex_simplex_range()) + if(s.dimension() == dimension) + ++res; + return res; + } + /* * @brief returns the number of blockers in the complex. */ - int num_blockers() const { + size_t num_blockers() const { return num_blockers_; } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 49a1ea8b..79a7ed79 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -45,9 +45,7 @@ bool Skeleton_blocker_complex::is_popable_blocker(Blocker_han assert(this->contains_blocker(*sigma)); Skeleton_blocker_link_complex link_blocker_sigma; build_link_of_blocker(*this, *sigma, link_blocker_sigma); - - bool res = link_blocker_sigma.is_contractible() == CONTRACTIBLE; - return res; + return link_blocker_sigma.is_contractible() == CONTRACTIBLE; } /** diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 418638e8..69abd279 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -104,6 +104,23 @@ bool test_simplex() { return simplex.dimension() == 3; } +bool test_num_simplices() { + int n = 4; + Complex complex; + build_complete(n, complex); + size_t sum = 0; + for (int i = 0; i < n; i++) { + PRINT(complex.num_simplices(i)); + sum += complex.num_simplices(i); + } + return + complex.num_vertices() == n && + complex.num_edges() == 6 && + sum == 15 && + complex.num_simplices() == 15; +} + + bool test_iterator_vertices1() { int n = 10; Complex complex(10); @@ -118,7 +135,7 @@ bool test_iterator_vertices1() { bool test_iterator_vertices2() { int n = 10; - Complex complex(10); + Complex complex; build_complete(10, complex); cerr << "complex.num_vertices():" << complex.num_vertices() << endl; cerr << "complex.num_edges():" << complex.num_edges() << endl; @@ -348,7 +365,7 @@ bool test_iterator_simplices4() { } bool test_iterator_coboundary() { - Complex c(4); + Complex c; build_complete(4, c); c.remove_edge(Vertex_handle(0), Vertex_handle(2)); PRINT(c.to_string()); @@ -892,6 +909,7 @@ bool test_constructor8() { int main(int argc, char *argv[]) { Tests tests_complex; tests_complex.add("test simplex", test_simplex); + tests_complex.add("test_num_simplices", test_num_simplices); tests_complex.add("test_link0", test_link0); tests_complex.add("test_link1", test_link1); tests_complex.add("test_link2", test_link2); -- cgit v1.2.3 From c6c91153dde643af2c5b9c78a1b1b9b65349c292 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 16 Nov 2015 10:09:38 +0000 Subject: cpplint fixes before merge git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@923 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: de9fc0770d273730de876a6ed54646847362bc7d --- src/Contraction/example/Garland_heckbert.cpp | 14 +++--- .../example/Skeleton_blocker_link.cpp | 5 +- .../include/gudhi/Skeleton_blocker_complex.h | 58 +++++++++++----------- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 29 ++++++----- 4 files changed, 53 insertions(+), 53 deletions(-) (limited to 'src/Contraction') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 681426e0..3ba9501b 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -145,13 +145,14 @@ class GH_visitor : public Gudhi::contraction::Contraction_visitor { int main(int argc, char *argv[]) { if (argc != 4) { - std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; + std::cerr << "Usage " << argv[0] << + " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; return EXIT_FAILURE; } Complex complex; typedef typename Complex::Vertex_handle Vertex_handle; - + // load the points Skeleton_blocker_off_reader off_reader(argv[1], complex); if (!off_reader.is_valid()) { @@ -159,9 +160,9 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(!complex.empty() && !complex.point(Vertex_handle(0)).dimension()==3) { + if (!complex.empty() && !(complex.point(Vertex_handle(0)).dimension() == 3)) { std::cerr << "Only points of dimension 3 are supported." << std::endl; - return EXIT_FAILURE; + return EXIT_FAILURE; } std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; @@ -175,8 +176,7 @@ int main(int argc, char *argv[]) { new GH_cost(complex), new GH_placement(complex), contraction::make_link_valid_contraction(), - new GH_visitor(complex) - ); + new GH_visitor(complex)); std::cout << "Contract " << num_contractions << " edges" << std::endl; contractor.contract_edges(num_contractions); @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) { complex.num_edges() << " edges and " << complex.num_triangles() << " triangles." << std::endl; - //write simplified complex + // write simplified complex Skeleton_blocker_off_writer off_writer(argv[2], complex); return EXIT_SUCCESS; diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp index 5e429728..698a8106 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp @@ -39,7 +39,7 @@ typedef Complex::Simplex Simplex; int main(int argc, char *argv[]) { // build a full complex with 4 vertices and 2^4-1 simplices - + // Create a complex with four vertices (0,1,2,3) Complex complex; @@ -64,7 +64,8 @@ int main(int argc, char *argv[]) { // To access to the initial vertices eg (0,1,2,3,4), Root_vertex_handle must be used. // For instance, to test if the link contains the vertex that was labeled i: for (int i = 0; i < 5; ++i) - cout << "link.contains_vertex(Root_vertex_handle(" << i << ")):" << link.contains_vertex(Root_vertex_handle(i)) << endl; + cout << "link.contains_vertex(Root_vertex_handle(" << i << ")):" << + link.contains_vertex(Root_vertex_handle(i)) << endl; return EXIT_SUCCESS; } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index cf156a58..6612722e 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -23,18 +23,6 @@ #ifndef SKELETON_BLOCKER_COMPLEX_H_ #define SKELETON_BLOCKER_COMPLEX_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include @@ -50,6 +38,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace Gudhi { namespace skbl { @@ -550,13 +550,13 @@ class Skeleton_blocker_complex { * the edges 01, 12, 20 but not the triangle 012 (and hence this complex * will contains a blocker 012). */ - Edge_handle add_edge(Vertex_handle a, Vertex_handle b) { - //if the edge is already there we musnt go further - //as we may add blockers that should not be here - if(contains_edge(a,b)) - return *((*this)[std::make_pair(a,b)]); - auto res = add_edge_without_blockers(a,b); - add_blockers_after_simplex_insertion(Simplex(a,b)); + Edge_handle add_edge(Vertex_handle a, Vertex_handle b) { + // if the edge is already there we musnt go further + // as we may add blockers that should not be here + if (contains_edge(a, b)) + return *((*this)[std::make_pair(a, b)]); + auto res = add_edge_without_blockers(a, b); + add_blockers_after_simplex_insertion(Simplex(a, b)); return res; } @@ -564,9 +564,9 @@ class Skeleton_blocker_complex { * @brief Adds all edges of s in the complex. */ void add_edge(const Simplex& s) { - for(auto i = s.begin(); i != s.end(); ++i) - for(auto j = i; ++j != s.end(); /**/) - add_edge(*i,*j); + for (auto i = s.begin(); i != s.end(); ++i) + for (auto j = i; ++j != s.end(); /**/) + add_edge(*i, *j); } /** @@ -596,9 +596,9 @@ class Skeleton_blocker_complex { * @brief Adds all edges of s in the complex without adding blockers. */ void add_edge_without_blockers(Simplex s) { - for(auto i = s.begin(); i != s.end(); ++i){ - for(auto j = i; ++j != s.end(); /**/) - add_edge_without_blockers(*i,*j); + for (auto i = s.begin(); i != s.end(); ++i) { + for (auto j = i; ++j != s.end(); /**/) + add_edge_without_blockers(*i, *j); } } @@ -1014,10 +1014,10 @@ class Skeleton_blocker_complex { * @brief returns the number of simplices of a given dimension in the complex. */ size_t num_simplices(unsigned dimension) const { - //todo iterator on k-simplices + // TODO(DS): iterator on k-simplices size_t res = 0; - for(const auto& s: complex_simplex_range()) - if(s.dimension() == dimension) + for (const auto& s : complex_simplex_range()) + if (s.dimension() == dimension) ++res; return res; } @@ -1585,7 +1585,7 @@ class Skeleton_blocker_complex { template Complex make_complex_from_top_faces(SimplexHandleIterator simplices_begin, SimplexHandleIterator simplices_end, bool is_flag_complex = false) { - //todo use add_simplex instead! should be more efficient and more elegant :) + // TODO(DS): use add_simplex instead! should be more efficient and more elegant :) typedef typename Complex::Simplex Simplex; std::vector simplices; for (auto top_face = simplices_begin; top_face != simplices_end; ++top_face) { diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 1b7d58ff..94a125c1 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -218,7 +218,7 @@ void Skeleton_blocker_complex::add_simplex(const Simplex& sig this->add_vertex(); } assert(contains_vertices(sigma)); - if(!contains_edges(sigma)) + if (!contains_edges(sigma)) add_edge(sigma); remove_blocker_include_in_simplex(sigma); add_blockers_after_simplex_insertion(sigma); @@ -227,10 +227,10 @@ void Skeleton_blocker_complex::add_simplex(const Simplex& sig template -void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma){ - if(sigma.dimension() < 1) return; +void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma) { + if (sigma.dimension() < 1) return; - for(auto s : coboundary_range(sigma)) { + for (auto s : coboundary_range(sigma)) { this->add_blocker(s); } } @@ -254,10 +254,10 @@ void Skeleton_blocker_complex::remove_blocker_containing_simp */ template void Skeleton_blocker_complex::remove_blocker_include_in_simplex(const Simplex& sigma) { - //todo write efficiently by using only superior blockers - //eg for all s, check blockers whose vertices are all greater than s + // TODO(DS): write efficiently by using only superior blockers + // eg for all s, check blockers whose vertices are all greater than s std::set blockers_to_remove; - for(auto s : sigma) { + for (auto s : sigma) { for (auto blocker : this->blocker_range(s)) { if (sigma.contains(*blocker)) blockers_to_remove.insert(blocker); @@ -266,11 +266,11 @@ void Skeleton_blocker_complex::remove_blocker_include_in_simp for (auto blocker_to_update : blockers_to_remove) { auto s = *blocker_to_update; this->delete_blocker(blocker_to_update); - //now if there is a vertex v in the link of s - //and v is not included in sigma then v.s is a blocker - //(all faces of v.s are there since v belongs to the link of s) - for(const auto& b : coboundary_range(s)) - if(!sigma.contains(b)) + // now if there is a vertex v in the link of s + // and v is not included in sigma then v.s is a blocker + // (all faces of v.s are there since v belongs to the link of s) + for (const auto& b : coboundary_range(s)) + if (!sigma.contains(b)) this->add_blocker(b); } } @@ -384,9 +384,8 @@ Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vert } template -void -Skeleton_blocker_complex::get_blockers_to_be_added_after_contraction(Vertex_handle a, Vertex_handle b, - std::set& blockers_to_add) { +void Skeleton_blocker_complex::get_blockers_to_be_added_after_contraction(Vertex_handle a, + Vertex_handle b, std::set& blockers_to_add) { blockers_to_add.clear(); typedef Skeleton_blocker_link_complex > LinkComplexType; -- cgit v1.2.3