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 --- .../include/gudhi/Skeleton_blocker_complex.h | 31 ++++++++++++++++++---- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 4 +-- .../test/TestSkeletonBlockerComplex.cpp | 22 +++++++++++++-- 3 files changed, 47 insertions(+), 10 deletions(-) (limited to 'src/Skeleton_blocker') 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