From 7efc964a35f06931803745f115ef675440f7e94b Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 30 Jun 2015 09:36:11 +0000 Subject: clang requires include fstream (Persistent_cohomology.h) clang build fails if include guard macro are not correctly defined + goole style fix (Skeleton_blockers_simplices_iterators.h) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@665 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4bbc74ac4726af768816c322bf77e104a1dcf1e6 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index b0d68f09..8bd265d8 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -37,6 +37,7 @@ #include #include #include +#include // std::ofstream namespace Gudhi { -- cgit v1.2.3 From 91c03d57fa9a674a177199c759476209a81707e4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 8 Jul 2015 08:45:28 +0000 Subject: Clang boost test segmentation fault fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@697 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ddfc6fe41d7112fd6b6c68eadf45e468f2c8904b --- src/Bottleneck/test/bottleneck_unit_test.cpp | 6 +++--- .../test/persistent_cohomology_unit_test.cpp | 11 +++++------ .../test/persistent_cohomology_unit_test_multi_field.cpp | 11 +++++------ src/Simplex_tree/test/simplex_tree_unit_test.cpp | 11 ++++------- 4 files changed, 17 insertions(+), 22 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Bottleneck/test/bottleneck_unit_test.cpp b/src/Bottleneck/test/bottleneck_unit_test.cpp index 068b8690..c60f5d8a 100644 --- a/src/Bottleneck/test/bottleneck_unit_test.cpp +++ b/src/Bottleneck/test/bottleneck_unit_test.cpp @@ -1,6 +1,6 @@ -#define BOOST_TEST_MODULE bottleneck test - -#include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "bottleneck" +#include #include "gudhi/Graph_matching.h" #include diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp index 55bc7066..194b3e74 100644 --- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp +++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp @@ -1,15 +1,14 @@ -#define BOOST_TEST_MODULE persistent_cohomology test -#include -#include -#include #include #include - +#include #include // std::pair, std::make_pair - #include // float comparison #include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "persistent_cohomology" +#include + #include "gudhi/graph_simplicial_complex.h" #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp index 18a4725e..703682e1 100644 --- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp +++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp @@ -1,15 +1,14 @@ -#define BOOST_TEST_MODULE persistent_cohomology_multi_field test -#include -#include -#include #include #include - +#include #include // std::pair, std::make_pair - #include // float comparison #include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "persistent_cohomology_multi_field" +#include + #include "gudhi/graph_simplicial_complex.h" #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 7f2172a2..6f6e9bb1 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -1,17 +1,14 @@ -#define BOOST_TEST_MODULE simplex_tree test -#include -#include -#include -#include #include #include #include - #include // std::pair, std::make_pair - #include // float comparison #include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "simplex_tree" +#include + #include "gudhi/graph_simplicial_complex.h" #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" -- cgit v1.2.3 From 16ff459809374b1d8616a81dda2340c7f3942912 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 11 Jul 2015 14:35:23 +0000 Subject: Clean-ups Use vector instead of list. Use emplace more. Use std::max. Some const. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@701 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 275156e94b4c9900c0af43ed7b74c7bff40bd7fd --- .../include/gudhi/Persistent_cohomology.h | 32 ++++++++++---------- src/Simplex_tree/include/gudhi/Simplex_tree.h | 35 +++++++--------------- .../gudhi/Simplex_tree/Simplex_tree_siblings.h | 11 ++++--- 3 files changed, 31 insertions(+), 47 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 8bd265d8..896a7a9f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -336,18 +336,18 @@ class Persistent_cohomology { if (ds_parent_[key] == key // root of its tree && zero_cocycles_.find(key) == zero_cocycles_.end()) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(key), cpx_->null_simplex(), coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(key), cpx_->null_simplex(), coeff_field_.characteristic()); } } for (auto zero_idx : zero_cocycles_) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(zero_idx.second), cpx_->null_simplex(), coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(zero_idx.second), cpx_->null_simplex(), coeff_field_.characteristic()); } // Compute infinite interval of dimension > 0 for (auto cocycle : transverse_idx_) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(cocycle.first), cpx_->null_simplex(), cocycle.second.characteristics_)); + persistent_pairs_.emplace_back( + cpx_->simplex(cocycle.first), cpx_->null_simplex(), cocycle.second.characteristics_); } } @@ -387,8 +387,8 @@ class Persistent_cohomology { if (cpx_->filtration(cpx_->simplex(idx_coc_u)) < cpx_->filtration(cpx_->simplex(idx_coc_v))) { // Kill cocycle [idx_coc_v], which is younger. if (interval_length_policy(cpx_->simplex(idx_coc_v), sigma)) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(idx_coc_v), sigma, coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(idx_coc_v), sigma, coeff_field_.characteristic()); } // Maintain the index of the 0-cocycle alive. if (kv != idx_coc_v) { @@ -402,8 +402,8 @@ class Persistent_cohomology { } } else { // Kill cocycle [idx_coc_u], which is younger. if (interval_length_policy(cpx_->simplex(idx_coc_u), sigma)) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(idx_coc_u), sigma, coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(idx_coc_u), sigma, coeff_field_.characteristic()); } // Maintain the index of the 0-cocycle alive. if (ku != idx_coc_u) { @@ -553,9 +553,9 @@ class Persistent_cohomology { Arith_element charac) { // Create a finite persistent interval for which the interval exists if (interval_length_policy(cpx_->simplex(death_key), sigma)) { - persistent_pairs_.push_back(Persistent_interval(cpx_->simplex(death_key) // creator - , sigma // destructor - , charac)); // fields + persistent_pairs_.emplace_back(cpx_->simplex(death_key) // creator + , sigma // destructor + , charac); // fields } auto death_key_row = transverse_idx_.find(death_key); // Find the beginning of the row. @@ -695,7 +695,7 @@ class Persistent_cohomology { void output_diagram(std::ostream& ostream = std::cout) { cmp_intervals_by_length cmp(cpx_); - persistent_pairs_.sort(cmp); + std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp); bool has_infinity = std::numeric_limits::has_infinity; for (auto pair : persistent_pairs_) { // Special case on windows, inf is "1.#INF" (cf. unitary tests and R package TDA) @@ -714,7 +714,7 @@ class Persistent_cohomology { { std::ofstream diagram_out(diagram_name.c_str()); cmp_intervals_by_length cmp( cpx_ ); - persistent_pairs_.sort( cmp ); + std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp); for(auto pair : persistent_pairs_) { diagram_out << cpx_->dimension(get<0>(pair)) << " " @@ -761,7 +761,7 @@ class Persistent_cohomology { /* Key -> row. */ std::map transverse_idx_; /* Persistent intervals. */ - std::list persistent_pairs_; + std::vector persistent_pairs_; length_interval interval_length_policy; boost::object_pool column_pool_; diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 61e07f84..2916ca97 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -881,40 +881,25 @@ class Simplex_tree { static void intersection(std::vector >& intersection, Dictionary_it begin1, Dictionary_it end1, Dictionary_it begin2, Dictionary_it end2, - Filtration_value filtration) { + Filtration_value filtration_) { if (begin1 == end1 || begin2 == end2) return; // ----->> while (true) { if (begin1->first == begin2->first) { - intersection.push_back(std::pair(begin1->first, - Node(NULL, - maximum(begin1->second.filtration(), - begin2->second.filtration(), filtration)))); - ++begin1; - ++begin2; - if (begin1 == end1 || begin2 == end2) + Filtration_value filt = (std::max)({begin1->second.filtration(), begin2->second.filtration(), filtration_}); + intersection.push_back(std::pair(begin1->first, Node(NULL, filt))); + if (++begin1 == end1 || ++begin2 == end2) + return; // ----->> + } else if (begin1->first < begin2->first) { + if (++begin1 == end1) + return; + } else /* begin1->first > begin2->first */ { + if (++begin2 == end2) return; // ----->> - } else { - if (begin1->first < begin2->first) { - ++begin1; - if (begin1 == end1) - return; - } else { - ++begin2; - if (begin2 == end2) - return; // ----->> - } } } } - /** Maximum over 3 values.*/ - static Filtration_value maximum(Filtration_value a, Filtration_value b, - Filtration_value c) { - Filtration_value max = (a < b) ? b : a; - return ((max < c) ? c : max); - } - public: /** \brief Write the hasse diagram of the simplicial complex in os. * diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h index 977fafa1..d6cbacaa 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h @@ -77,8 +77,8 @@ class Simplex_tree_siblings { parent_(parent), members_(boost::container::ordered_unique_range, members.begin(), members.end()) { - for (auto map_it = members_.begin(); map_it != members_.end(); map_it++) { - map_it->second.assign_children(this); + for (auto& map_el : members_) { + map_el.second.assign_children(this); } } @@ -96,8 +96,7 @@ class Simplex_tree_siblings { return; } if (sh == members_.end()) { - members_.insert( - std::pair(v, Node(this, filtration_value))); + members_.emplace(v, Node(this, filtration_value)); return; } } @@ -110,7 +109,7 @@ class Simplex_tree_siblings { return oncles_; } - Vertex_handle parent() { + Vertex_handle parent() const { return parent_; } @@ -118,7 +117,7 @@ class Simplex_tree_siblings { return members_; } - size_t size() { + size_t size() const { return members_.size(); } -- cgit v1.2.3 From 8e75cf8acd691c22ca972a5c0c5bf12580af2e78 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 11 Jul 2015 15:43:50 +0000 Subject: Clean-ups Avoid duplicate search with find+insert. No need to store 0 and 1 and return them by reference. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@702 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 28403136284a9fe2044b9d51bc2f10861b3a09e7 --- .../include/gudhi/Persistent_cohomology/Field_Zp.h | 18 +++++++----------- .../include/gudhi/Persistent_cohomology/Multi_field.h | 6 +++--- .../include/gudhi/Simplex_tree/Simplex_tree_siblings.h | 14 ++++---------- 3 files changed, 14 insertions(+), 24 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h index 2a4c8692..a12019f8 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h @@ -41,9 +41,7 @@ class Field_Zp { Field_Zp() : Prime(0), - inverse_(), - mult_id_all(1), - add_id_all(0) { + inverse_() { } void init(int charac) { @@ -81,14 +79,14 @@ class Field_Zp { } /** \brief Returns the additive idendity \f$0_{\Bbbk}\f$ of the field.*/ - const Element& additive_identity() const { - return add_id_all; + Element additive_identity() const { + return 0; } /** \brief Returns the multiplicative identity \f$1_{\Bbbk}\f$ of the field.*/ - const Element& multiplicative_identity(Element = 0) const { - return mult_id_all; + Element multiplicative_identity(Element = 0) const { + return 1; } - /** Returns the inverse in the field. Modifies P.*/ + /** Returns the inverse in the field. Modifies P. ??? */ std::pair inverse(Element x, Element P) { return std::pair(inverse_[x], P); } // <------ return the product of field characteristic for which x is invertible @@ -101,7 +99,7 @@ class Field_Zp { } /** \brief Returns the characteristic \f$p\f$ of the field.*/ - const int& characteristic() const { + int characteristic() const { return Prime; } @@ -109,8 +107,6 @@ class Field_Zp { int Prime; /** Property map Element -> Element, which associate to an element its inverse in the field.*/ std::vector inverse_; - const Element mult_id_all; - const Element add_id_all; }; } // namespace persistent_cohomology diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h index c6fd5282..555d696f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -142,7 +142,7 @@ class Multi_field { return prod_characteristics_; } - /** Returns the inverse in the field. Modifies P.*/ + /** Returns the inverse in the field. Modifies P. ??? */ std::pair inverse(Element x, Element QS) { Element QR; mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t()); // QR <- gcd(x,QS) @@ -153,12 +153,12 @@ class Multi_field { mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t()); assert(prod_characteristics_ > 0); // division by zero + non negative values - return std::pair( - (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT); + return { (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT }; } /** Returns -x * y.*/ Element times_minus(const Element& x, const Element& y) { assert(prod_characteristics_ > 0); // division by zero + non negative values + /* This assumes that (x*y)%pc cannot be zero, but Field_Zp has specific code for the 0 case ??? */ return prod_characteristics_ - ((x * y) % prod_characteristics_); } diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h index d6cbacaa..de350f2d 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h @@ -90,18 +90,12 @@ class Simplex_tree_siblings { * present in the node. */ void insert(Vertex_handle v, Filtration_value filtration_value) { - typename Dictionary::iterator sh = members_.find(v); - if (sh != members_.end() && sh->second.filtration() > filtration_value) { - sh->second.assign_filtration(filtration_value); - return; - } - if (sh == members_.end()) { - members_.emplace(v, Node(this, filtration_value)); - return; - } + auto ins = members_.emplace(v, Node(this, filtration_value)); + if (!ins.second && filtration(ins.first) > filtration_value) + ins.first->second.assign_filtration(filtration_value); } - typename Dictionary::iterator find(Vertex_handle v) { + Dictionary_it find(Vertex_handle v) { return members_.find(v); } -- cgit v1.2.3 From 0d427fd713cceddd8335e6e6bbac74db18e5dd7c Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 19 Aug 2015 13:41:40 +0000 Subject: num_simplices computation instead of increment/set methods. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/num_simplices@743 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 42bad5e259ea540b5ec020f293b2dff86c83101f --- .../example/alpha_shapes_persistence.cpp | 1 - src/Simplex_tree/example/simple_simplex_tree.cpp | 81 ++-------- src/Simplex_tree/include/gudhi/Simplex_tree.h | 53 +++--- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 179 ++++++--------------- 4 files changed, 94 insertions(+), 220 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp index 3a50c84c..1e907040 100644 --- a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp @@ -263,7 +263,6 @@ int main (int argc, char * const argv[]) std::cout << "This shall not happen" << std::endl; } simplex_tree.set_filtration(filtration_max); - simplex_tree.set_num_simplices(count_vertices + count_edges + count_facets + count_cells); simplex_tree.set_dimension(dim_max); #ifdef DEBUG_TRACES diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index 6d20e43e..a2e1f0e9 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -21,7 +21,6 @@ */ #include -#include #include "gudhi/graph_simplicial_complex.h" #include "gudhi/Simplex_tree.h" @@ -35,10 +34,6 @@ int main(int argc, char * const argv[]) { const Filtration_value SECOND_FILTRATION_VALUE = 0.2; const Filtration_value THIRD_FILTRATION_VALUE = 0.3; const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; - Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle) 0; - Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; - Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; - Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; @@ -55,173 +50,132 @@ int main(int argc, char * const argv[]) { // ++ FIRST std::cout << " * INSERT 0" << std::endl; - typeVectorVertex firstSimplexVector; - firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex firstSimplexVector = { 0 }; typePairSimplexBool returnValue = simplexTree.insert_simplex(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 0 INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - 0 NOT INSERTED" << std::endl; } // ++ SECOND std::cout << " * INSERT 1" << std::endl; - typeVectorVertex secondSimplexVector; - secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex secondSimplexVector = { 1 }; returnValue = simplexTree.insert_simplex(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 1 INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - 1 NOT INSERTED" << std::endl; } // ++ THIRD std::cout << " * INSERT (0,1)" << std::endl; - typeVectorVertex thirdSimplexVector; - thirdSimplexVector.push_back(FIRST_VERTEX_HANDLE); - thirdSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex thirdSimplexVector = { 0, 1 }; returnValue = simplexTree.insert_simplex(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (0,1) INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - (0,1) NOT INSERTED" << std::endl; } // ++ FOURTH std::cout << " * INSERT 2" << std::endl; - typeVectorVertex fourthSimplexVector; - fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); + typeVectorVertex fourthSimplexVector = { 2 }; returnValue = simplexTree.insert_simplex(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 2 INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - 2 NOT INSERTED" << std::endl; } // ++ FIFTH std::cout << " * INSERT (2,0)" << std::endl; - typeVectorVertex fifthSimplexVector; - fifthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - fifthSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex fifthSimplexVector = { 2, 0 }; returnValue = simplexTree.insert_simplex(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,0) INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - (2,0) NOT INSERTED" << std::endl; } // ++ SIXTH std::cout << " * INSERT (2,1)" << std::endl; - typeVectorVertex sixthSimplexVector; - sixthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - sixthSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex sixthSimplexVector = { 2, 1 }; returnValue = simplexTree.insert_simplex(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,1) INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - (2,1) NOT INSERTED" << std::endl; } // ++ SEVENTH std::cout << " * INSERT (2,1,0)" << std::endl; - typeVectorVertex seventhSimplexVector; - seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex seventhSimplexVector = { 2, 1, 0 }; returnValue = simplexTree.insert_simplex(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,1,0) INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - (2,1,0) NOT INSERTED" << std::endl; } // ++ EIGHTH std::cout << " * INSERT 3" << std::endl; - typeVectorVertex eighthSimplexVector; - eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); + typeVectorVertex eighthSimplexVector = { 3 }; returnValue = simplexTree.insert_simplex(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 3 INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - 3 NOT INSERTED" << std::endl; } // ++ NINETH std::cout << " * INSERT (3,0)" << std::endl; - typeVectorVertex ninethSimplexVector; - ninethSimplexVector.push_back(FOURTH_VERTEX_HANDLE); - ninethSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex ninethSimplexVector = { 3, 0 }; returnValue = simplexTree.insert_simplex(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (3,0) INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - (3,0) NOT INSERTED" << std::endl; } // ++ TENTH std::cout << " * INSERT 0 (already inserted)" << std::endl; - typeVectorVertex tenthSimplexVector; - tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex tenthSimplexVector = { 0 }; returnValue = simplexTree.insert_simplex(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value if (returnValue.second == true) { std::cout << " + 0 INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - 0 NOT INSERTED" << std::endl; } // ++ ELEVENTH std::cout << " * INSERT (2,1,0) (already inserted)" << std::endl; - typeVectorVertex eleventhSimplexVector; - eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex eleventhSimplexVector = { 2, 1, 0 }; returnValue = simplexTree.insert_simplex(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + (2,1,0) INSERTED" << std::endl; - int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); } else { std::cout << " - (2,1,0) NOT INSERTED" << std::endl; } @@ -262,9 +216,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - Vertex_handle UNKNOWN_VERTEX_HANDLE = (Vertex_handle) 15; - typeVectorVertex unknownSimplexVector; - unknownSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); + typeVectorVertex unknownSimplexVector = { 15 }; simplexFound = simplexTree.find(unknownSimplexVector); std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) @@ -279,9 +231,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - typeVectorVertex otherSimplexVector; - otherSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); - otherSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex otherSimplexVector = { 1, 15 }; simplexFound = simplexTree.find(otherSimplexVector); std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) @@ -289,10 +239,7 @@ int main(int argc, char * const argv[]) { else std::cout << "***- NO IT ISN'T\n"; - typeVectorVertex invSimplexVector; - invSimplexVector.push_back(SECOND_VERTEX_HANDLE); - invSimplexVector.push_back(THIRD_VERTEX_HANDLE); - invSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex invSimplexVector = { 1, 2, 0 }; simplexFound = simplexTree.find(invSimplexVector); std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; if (simplexFound != simplexTree.null_simplex()) diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 153401d6..db5de0b8 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -280,7 +280,6 @@ class Simplex_tree { Simplex_tree() : null_vertex_(-1), threshold_(0), - num_simplices_(0), root_(NULL, null_vertex_), filtration_vect_(), dimension_(-1) { } @@ -361,13 +360,35 @@ class Simplex_tree { return root_.members_.size(); } - /** \brief Returns the number of simplices in the complex. - * - * Does not count the empty simplex. */ - unsigned int num_simplices() const { - return num_simplices_; + public: + /** \brief returns the number of simplices in the simplex_tree. */ + long long int num_simplices() { + auto sib_begin = root_.members().begin(); + auto sib_end = root_.members().end(); + long long int simplices_number = sib_end - sib_begin; + for (auto sh = sib_begin; sh != sib_end; ++sh) { + if (has_children(sh)) { + simplices_number += rec_num_simplices(sh->second.children()); + } + } + return simplices_number; } + private: + /** \brief returns the number of simplices in the simplex_tree. */ + long long int rec_num_simplices(Siblings * sib = nullptr) { + auto sib_begin = sib->members().begin(); + auto sib_end = sib->members().end(); + long long int simplices_number = sib_end - sib_begin; + for (auto sh = sib_begin; sh != sib_end; ++sh) { + if (has_children(sh)) { + simplices_number += rec_num_simplices(sh->second.children()); + } + } + return simplices_number; + } + + public: /** \brief Returns the dimension of a simplex. * * Must be different from null_simplex().*/ @@ -510,15 +531,9 @@ class Simplex_tree { } // N-Simplex insert std::pair returned = insert_simplex(Nsimplex, filtration); - if (returned.second == true) { - num_simplices_++; - } } else if (Nsimplex.size() == 1) { // 1-Simplex insert - End of recursivity std::pair returned = insert_simplex(Nsimplex, filtration); - if (returned.second == true) { - num_simplices_++; - } } else { // Nothing to insert - empty vector } @@ -569,11 +584,6 @@ class Simplex_tree { threshold_ = fil; } - /** Set a number of simplices for the simplicial complex. */ - void set_num_simplices(unsigned int num_simplices) { - num_simplices_ = num_simplices; - } - /** Set a dimension for the simplicial complex. */ void set_dimension(int dimension) { dimension_ = dimension; @@ -770,8 +780,6 @@ class Simplex_tree { dimension_ = 1; } - num_simplices_ = boost::num_vertices(skel_graph) - + boost::num_edges(skel_graph); root_.members_.reserve(boost::num_vertices(skel_graph)); typename boost::graph_traits::vertex_iterator v_it, @@ -850,7 +858,6 @@ class Simplex_tree { root_sh->second.children()->members().end(), s_h->second.filtration()); if (inter.size() != 0) { - this->num_simplices_ += inter.size(); Siblings * new_sib = new Siblings(siblings, // oncles s_h->first, // parent inter); // boost::container::ordered_unique_range_t @@ -913,7 +920,6 @@ class Simplex_tree { /** \brief Upper bound on the filtration values of the simplices.*/ Filtration_value threshold_; /** \brief Total number of simplices in the complex, without the empty simplex.*/ - unsigned int num_simplices_; /** \brief Set of simplex tree Nodes representing the vertices.*/ Siblings root_; /** \brief Simplices ordered according to a filtration.*/ @@ -938,17 +944,13 @@ std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { template std::istream& operator>>(std::istream & is, Simplex_tree & st) { - // assert(st.num_simplices() == 0); - typedef Simplex_tree ST; std::vector simplex; typename ST::Filtration_value fil; typename ST::Filtration_value max_fil = 0; int max_dim = -1; - size_t num_simplices = 0; while (read_simplex(is, simplex, fil)) { // read all simplices in the file as a list of vertices - ++num_simplices; // Warning : simplex_size needs to be casted in int - Can be 0 int dim = static_cast (simplex.size() - 1); if (max_dim < dim) { @@ -961,7 +963,6 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { st.insert_simplex(simplex, fil); simplex.clear(); } - st.set_num_simplices(num_simplices); st.set_dimension(max_dim); st.set_filtration(max_fil); diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 566d6d90..20403e2a 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -157,12 +157,17 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons std::cout << " set_and_test_simplex_tree_dim_fil - max_fil=" << max_fil << std::endl; } - unsigned int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); - + BOOST_CHECK(simplexTree.dimension() == dim_max); BOOST_CHECK(AreAlmostTheSame(simplexTree.filtration(), max_fil)); - BOOST_CHECK(simplexTree.num_simplices() == nb_simplices); + + // Another way to count simplices: + long long int num_simp = 0; + for (auto f_simplex : simplexTree.complex_simplex_range()) { + num_simp++; + } + + BOOST_CHECK(simplexTree.num_simplices() == num_simp); } void test_cofaces(typeST& st, std::vector v, int dim, std::vector res) { @@ -186,10 +191,6 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { const Filtration_value SECOND_FILTRATION_VALUE = 0.2; const Filtration_value THIRD_FILTRATION_VALUE = 0.3; const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; - Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle) 0; - Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; - Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; - Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; @@ -198,13 +199,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ FIRST std::cout << " - INSERT 0" << std::endl; - typeVectorVertex firstSimplexVector; - firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex firstSimplexVector { 0 }; BOOST_CHECK(firstSimplexVector.size() == 1); - typeSimplex firstSimplex = std::make_pair( - firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - typePairSimplexBool returnValue = st.insert_simplex(firstSimplex.first, - firstSimplex.second); + typeSimplex firstSimplex = std::make_pair(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + typePairSimplexBool returnValue = st.insert_simplex(firstSimplex.first, firstSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, firstSimplexVector.size(), firstSimplex.second); @@ -212,13 +210,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ SECOND std::cout << " - INSERT 1" << std::endl; - typeVectorVertex secondSimplexVector; - secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex secondSimplexVector { 1 }; BOOST_CHECK(secondSimplexVector.size() == 1); - typeSimplex secondSimplex = std::make_pair( - secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(secondSimplex.first, secondSimplex.second); + typeSimplex secondSimplex = std::make_pair(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = st.insert_simplex(secondSimplex.first, secondSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, secondSimplexVector.size(), secondSimplex.second); @@ -226,14 +221,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ THIRD std::cout << " - INSERT (0,1)" << std::endl; - typeVectorVertex thirdSimplexVector; - thirdSimplexVector.push_back(FIRST_VERTEX_HANDLE); - thirdSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex thirdSimplexVector { 0, 1 }; BOOST_CHECK(thirdSimplexVector.size() == 2); - typeSimplex thirdSimplex = std::make_pair( - thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(thirdSimplex.first, thirdSimplex.second); + typeSimplex thirdSimplex = std::make_pair(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = st.insert_simplex(thirdSimplex.first, thirdSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, thirdSimplexVector.size(), thirdSimplex.second); @@ -241,13 +232,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ FOURTH std::cout << " - INSERT 2" << std::endl; - typeVectorVertex fourthSimplexVector; - fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); + typeVectorVertex fourthSimplexVector { 2 }; BOOST_CHECK(fourthSimplexVector.size() == 1); - typeSimplex fourthSimplex = std::make_pair( - fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(fourthSimplex.first, fourthSimplex.second); + typeSimplex fourthSimplex = std::make_pair(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = st.insert_simplex(fourthSimplex.first, fourthSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, fourthSimplexVector.size(), fourthSimplex.second); @@ -255,14 +243,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ FIFTH std::cout << " - INSERT (2,0)" << std::endl; - typeVectorVertex fifthSimplexVector; - fifthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - fifthSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex fifthSimplexVector { 2, 0 }; BOOST_CHECK(fifthSimplexVector.size() == 2); - typeSimplex fifthSimplex = std::make_pair( - fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(fifthSimplex.first, fifthSimplex.second); + typeSimplex fifthSimplex = std::make_pair(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = st.insert_simplex(fifthSimplex.first, fifthSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, fifthSimplexVector.size(), fifthSimplex.second); @@ -270,14 +254,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ SIXTH std::cout << " - INSERT (2,1)" << std::endl; - typeVectorVertex sixthSimplexVector; - sixthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - sixthSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex sixthSimplexVector { 2, 1 }; BOOST_CHECK(sixthSimplexVector.size() == 2); - typeSimplex sixthSimplex = std::make_pair( - sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(sixthSimplex.first, sixthSimplex.second); + typeSimplex sixthSimplex = std::make_pair(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = st.insert_simplex(sixthSimplex.first, sixthSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, sixthSimplexVector.size(), sixthSimplex.second); @@ -285,15 +265,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ SEVENTH std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex seventhSimplexVector; - seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex seventhSimplexVector { 2, 1, 0 }; BOOST_CHECK(seventhSimplexVector.size() == 3); - typeSimplex seventhSimplex = std::make_pair( - seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(seventhSimplex.first, seventhSimplex.second); + typeSimplex seventhSimplex = std::make_pair(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); + returnValue = st.insert_simplex(seventhSimplex.first, seventhSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, seventhSimplexVector.size(), seventhSimplex.second); @@ -301,13 +276,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ EIGHTH std::cout << " - INSERT 3" << std::endl; - typeVectorVertex eighthSimplexVector; - eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); + typeVectorVertex eighthSimplexVector { 3 }; BOOST_CHECK(eighthSimplexVector.size() == 1); - typeSimplex eighthSimplex = std::make_pair( - eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(eighthSimplex.first, eighthSimplex.second); + typeSimplex eighthSimplex = std::make_pair(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = st.insert_simplex(eighthSimplex.first, eighthSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, eighthSimplexVector.size(), eighthSimplex.second); @@ -315,14 +287,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ NINETH std::cout << " - INSERT (3,0)" << std::endl; - typeVectorVertex ninethSimplexVector; - ninethSimplexVector.push_back(FOURTH_VERTEX_HANDLE); - ninethSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex ninethSimplexVector { 3, 0 }; BOOST_CHECK(ninethSimplexVector.size() == 2); - typeSimplex ninethSimplex = std::make_pair( - ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(ninethSimplex.first, ninethSimplex.second); + typeSimplex ninethSimplex = std::make_pair(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = st.insert_simplex(ninethSimplex.first, ninethSimplex.second); test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, ninethSimplexVector.size(), ninethSimplex.second); @@ -330,13 +298,11 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ TENTH std::cout << " - INSERT 0 (already inserted)" << std::endl; - typeVectorVertex tenthSimplexVector; - tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex tenthSimplexVector { 0 }; BOOST_CHECK(tenthSimplexVector.size() == 1); - typeSimplex tenthSimplex = std::make_pair( - tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value - returnValue = - st.insert_simplex(tenthSimplex.first, tenthSimplex.second); + // With a different filtration value + typeSimplex tenthSimplex = std::make_pair(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); + returnValue = st.insert_simplex(tenthSimplex.first, tenthSimplex.second); BOOST_CHECK(returnValue.second == false); typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator @@ -347,15 +313,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { // ++ ELEVENTH std::cout << " - INSERT (2,1,0) (already inserted)" << std::endl; - typeVectorVertex eleventhSimplexVector; - eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex eleventhSimplexVector { 2, 1, 0 }; BOOST_CHECK(eleventhSimplexVector.size() == 3); - typeSimplex eleventhSimplex = std::make_pair( - eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); - returnValue = - st.insert_simplex(eleventhSimplex.first, eleventhSimplex.second); + typeSimplex eleventhSimplex = std::make_pair(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); + returnValue = st.insert_simplex(eleventhSimplex.first, eleventhSimplex.second); BOOST_CHECK(returnValue.second == false); shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator @@ -415,15 +376,6 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { } BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { - Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle) 0; - Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; - Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; - Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; - Vertex_handle FIFTH_VERTEX_HANDLE = (Vertex_handle) 4; - Vertex_handle SIXTH_VERTEX_HANDLE = (Vertex_handle) 5; - Vertex_handle SEVENTH_VERTEX_HANDLE = (Vertex_handle) 6; - Vertex_handle EIGHTH_VERTEX_HANDLE = (Vertex_handle) 7; - // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF INSERTION" << std::endl; @@ -431,10 +383,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ++ FIRST std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex SimplexVector1; - SimplexVector1.push_back(THIRD_VERTEX_HANDLE); - SimplexVector1.push_back(SECOND_VERTEX_HANDLE); - SimplexVector1.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex SimplexVector1 { 2, 1, 0 }; BOOST_CHECK(SimplexVector1.size() == 3); st.insert_simplex_and_subfaces(SimplexVector1); @@ -442,8 +391,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ++ SECOND std::cout << " - INSERT 3" << std::endl; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(FOURTH_VERTEX_HANDLE); + typeVectorVertex SimplexVector2 { 3 }; BOOST_CHECK(SimplexVector2.size() == 1); st.insert_simplex_and_subfaces(SimplexVector2); @@ -451,9 +399,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ++ THIRD std::cout << " - INSERT (0,3)" << std::endl; - typeVectorVertex SimplexVector3; - SimplexVector3.push_back(FOURTH_VERTEX_HANDLE); - SimplexVector3.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex SimplexVector3 { 3, 0 }; BOOST_CHECK(SimplexVector3.size() == 2); st.insert_simplex_and_subfaces(SimplexVector3); @@ -461,9 +407,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ++ FOURTH std::cout << " - INSERT (1,0) (already inserted)" << std::endl; - typeVectorVertex SimplexVector4; - SimplexVector4.push_back(SECOND_VERTEX_HANDLE); - SimplexVector4.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex SimplexVector4 { 1, 0 }; BOOST_CHECK(SimplexVector4.size() == 2); st.insert_simplex_and_subfaces(SimplexVector4); @@ -471,10 +415,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ++ FIFTH std::cout << " - INSERT (3,4,5)" << std::endl; - typeVectorVertex SimplexVector5; - SimplexVector5.push_back(FOURTH_VERTEX_HANDLE); - SimplexVector5.push_back(FIFTH_VERTEX_HANDLE); - SimplexVector5.push_back(SIXTH_VERTEX_HANDLE); + typeVectorVertex SimplexVector5 { 3, 4, 5 }; BOOST_CHECK(SimplexVector5.size() == 3); st.insert_simplex_and_subfaces(SimplexVector5); @@ -482,11 +423,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ++ SIXTH std::cout << " - INSERT (0,1,6,7)" << std::endl; - typeVectorVertex SimplexVector6; - SimplexVector6.push_back(FIRST_VERTEX_HANDLE); - SimplexVector6.push_back(SECOND_VERTEX_HANDLE); - SimplexVector6.push_back(SEVENTH_VERTEX_HANDLE); - SimplexVector6.push_back(EIGHTH_VERTEX_HANDLE); + typeVectorVertex SimplexVector6 { 0, 1, 6, 7 }; BOOST_CHECK(SimplexVector6.size() == 4); st.insert_simplex_and_subfaces(SimplexVector6); @@ -523,8 +460,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // ------------------------------------------------------------------------------------------------------------------ // Find in the simplex_tree // ------------------------------------------------------------------------------------------------------------------ - typeVectorVertex simpleSimplexVector; - simpleSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex simpleSimplexVector { 1 }; Simplex_tree<>::Simplex_handle simplexFound = st.find(simpleSimplexVector); std::cout << "**************IS THE SIMPLEX {1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != st.null_simplex()) @@ -534,9 +470,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is found BOOST_CHECK(simplexFound != st.null_simplex()); - Vertex_handle UNKNOWN_VERTEX_HANDLE = (Vertex_handle) 15; - typeVectorVertex unknownSimplexVector; - unknownSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); + typeVectorVertex unknownSimplexVector { 15 }; simplexFound = st.find(unknownSimplexVector); std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; if (simplexFound != st.null_simplex()) @@ -555,9 +489,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is found BOOST_CHECK(simplexFound != st.null_simplex()); - typeVectorVertex otherSimplexVector; - otherSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); - otherSimplexVector.push_back(SECOND_VERTEX_HANDLE); + typeVectorVertex otherSimplexVector { 1, 15 }; simplexFound = st.find(otherSimplexVector); std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != st.null_simplex()) @@ -567,10 +499,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is NOT found BOOST_CHECK(simplexFound == st.null_simplex()); - typeVectorVertex invSimplexVector; - invSimplexVector.push_back(SECOND_VERTEX_HANDLE); - invSimplexVector.push_back(THIRD_VERTEX_HANDLE); - invSimplexVector.push_back(FIRST_VERTEX_HANDLE); + typeVectorVertex invSimplexVector { 1, 2, 0 }; simplexFound = st.find(invSimplexVector); std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; if (simplexFound != st.null_simplex()) @@ -580,8 +509,6 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is found BOOST_CHECK(simplexFound != st.null_simplex()); - - // Display the Simplex_tree - Can not be done in the middle of 2 inserts std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; -- cgit v1.2.3 From 8cdad0d3febc1de445c6581d457137b429591756 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 20 Aug 2015 14:19:16 +0000 Subject: Store num_simplices in persistent_cohomology to avoid to call the function 3 times. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/num_simplices@748 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 868c69508bd6307c805cfc1a0cab00631c79c000 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 896a7a9f..4c818ffa 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -230,9 +230,10 @@ class Persistent_cohomology { : cpx_(&cpx), dim_max_(cpx.dimension()), // upper bound on the dimension of the simplices coeff_field_(), // initialize the field coefficient structure. - ds_rank_(cpx_->num_simplices()), // union-find - ds_parent_(cpx_->num_simplices()), // union-find - ds_repr_(cpx_->num_simplices(), NULL), // union-find -> annotation vectors + num_simplices_(cpx_->num_simplices()), // num_simplices save to avoid to call thrice the function + ds_rank_(num_simplices_), // union-find + ds_parent_(num_simplices_), // union-find + ds_repr_(num_simplices_, NULL), // union-find -> annotation vectors dsets_(&ds_rank_[0], &ds_parent_[0]), // union-find cam_(), // collection of annotation vectors zero_cocycles_(), // union-find -> Simplex_key of creator for 0-homology @@ -743,6 +744,7 @@ class Persistent_cohomology { Complex_ds * cpx_; int dim_max_; CoefficientField coeff_field_; + size_t num_simplices_; /* Disjoint sets data structure to link the model of FilteredComplex * with the compressed annotation matrix. -- cgit v1.2.3 From 2cb6a5648f6c4a21f83a41faad6b598bd0a02832 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 16 Sep 2015 14:30:58 +0000 Subject: Filtration_simplex_iterator's reference type does not have to be a reference, and Simplex_handle has to be cheap anyway. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@789 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a3fbf340b9ab3d2186616f14f4b96d3188dafd14 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 4c818ffa..c6593cc4 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -243,7 +243,7 @@ class Persistent_cohomology { column_pool_(), // memory pools for the CAM cell_pool_() { Simplex_key idx_fil = 0; - for (auto & sh : cpx_->filtration_simplex_range()) { + for (auto sh : cpx_->filtration_simplex_range()) { cpx_->assign_key(sh, idx_fil); ++idx_fil; dsets_.make_set(cpx_->key(sh)); -- cgit v1.2.3 From a9bdb5e1fdb6741dbd62eb3f0404a354cc216460 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 26 Sep 2015 07:37:43 +0000 Subject: Replace boost::object_pool by a simpler, more scalable version. Not ready for trunk, it causes a memory leak, visible for instance with valgrind on PersistentCohomologyMultiFieldUT. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/pool@797 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 20a8296db22f253d49c10edd565557123fdc7c6f --- .../include/gudhi/Persistent_cohomology.h | 6 +- src/common/include/gudhi/Simple_object_pool.h | 64 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/common/include/gudhi/Simple_object_pool.h (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index c6593cc4..b38e4f13 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -25,12 +25,12 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -766,8 +766,8 @@ class Persistent_cohomology { std::vector persistent_pairs_; length_interval interval_length_policy; - boost::object_pool column_pool_; - boost::object_pool cell_pool_; + Simple_object_pool column_pool_; + Simple_object_pool cell_pool_; }; /** @} */ // end defgroup persistent_cohomology diff --git a/src/common/include/gudhi/Simple_object_pool.h b/src/common/include/gudhi/Simple_object_pool.h new file mode 100644 index 00000000..fffcb2ef --- /dev/null +++ b/src/common/include/gudhi/Simple_object_pool.h @@ -0,0 +1,64 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Marc Glisse + * + * Copyright (C) 2015 INRIA Saclay - Ile de France + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +namespace Gudhi { + /** \private + * This is a simpler version of boost::object_pool, that requires + * that users explicitly destroy all objects. This lets the + * performance scale much better, see + * https://svn.boost.org/trac/boost/ticket/3789 . + */ +template +class Simple_object_pool : protected boost::pool +{ + protected: + typedef boost::pool Base; + typedef T* pointer; + Base& base(){return *this;} + Base const& base()const{return *this;} + public: + typedef T element_type; + typedef boost::default_user_allocator_malloc_free user_allocator; + typedef typename Base::size_type size_type; + typedef typename Base::difference_type difference_type; + template + Simple_object_pool(U&&...u) : Base(sizeof(T), std::forward(u)...) {} + template + pointer construct(U&&...u){ + void* p=base().malloc BOOST_PREVENT_MACRO_SUBSTITUTION(); + assert(p); + try { new(p) T(std::forward(u)...); } + catch(...) { + base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p); + throw; + } + return static_cast(p); + } + void destroy(pointer p){ + p->~T(); + base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p); + } +}; +} -- cgit v1.2.3 From 4eb67582fc0aec86d56c5839ddcb5b0bf72e95b5 Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 28 Sep 2015 09:11:54 +0000 Subject: Minor clean-ups (const, for-range, etc). git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@798 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: de10cc12d852eab34e258bbfb98ff0aef864e453 --- .../include/gudhi/Persistent_cohomology.h | 9 ++++----- .../Persistent_cohomology/Persistent_cohomology_column.h | 14 ++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index c6593cc4..05f70c39 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -572,9 +572,8 @@ class Persistent_cohomology { Column * curr_col = row_cell_it->self_col_; ++row_cell_it; // Disconnect the column from the rows in the CAM. - for (auto col_cell_it = curr_col->col_.begin(); - col_cell_it != curr_col->col_.end(); ++col_cell_it) { - col_cell_it->base_hook_cam_h::unlink(); + for (auto& col_cell : curr_col->col_) { + col_cell.base_hook_cam_h::unlink(); } // Remove the column from the CAM before modifying its value @@ -589,9 +588,9 @@ class Persistent_cohomology { // Find whether the column obtained is already in the CAM result_insert_cam = cam_.insert(*curr_col); if (result_insert_cam.second) { // If it was not in the CAM before: insertion has succeeded - for (auto col_cell_it = curr_col->col_.begin(); col_cell_it != curr_col->col_.end(); ++col_cell_it) { + for (auto& col_cell : curr_col->col_) { // re-establish the row links - transverse_idx_[col_cell_it->key_].row_->push_front(*col_cell_it); + transverse_idx_[col_cell.key_].row_->push_front(col_cell); } } else { // There is already an identical column in the CAM: // merge two disjoint sets. diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h index fcec819a..5ffd1776 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h @@ -93,27 +93,25 @@ class Persistent_cohomology_column : public boost::intrusive::set_base_hook< boost::intrusive::base_hook > Col_type; /** \brief Creates an empty column.*/ - explicit Persistent_cohomology_column(SimplexKey key) { - class_key_ = key; - col_ = Col_type(); - } + explicit Persistent_cohomology_column(SimplexKey key) + : col_(), + class_key_(key) {} public: /** Copy constructor.*/ Persistent_cohomology_column(Persistent_cohomology_column const &other) : col_(), class_key_(other.class_key_) { - if (!other.col_.empty()) - std::cerr << "Copying a non-empty column.\n"; + assert(other.col_.empty()); } /** \brief Returns true iff the column is null.*/ - bool is_null() { + bool is_null() const { return col_.empty(); } /** \brief Returns the key of the representative simplex of * the set of simplices having this column as annotation vector * in the compressed annotation matrix.*/ - SimplexKey class_key() { + SimplexKey class_key() const { return class_key_; } -- cgit v1.2.3 From 69fa48ea8bf9fd9e49363ab405d3e55306be848b Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 28 Sep 2015 16:41:20 +0000 Subject: Release CAM cells. There are a lot of intrusive containers in there, and I believe that most could be replaced with regular containers. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@800 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7246d7db0511ac6bffee2f645c006416a986629d --- CMakeLists.txt | 4 ++-- .../include/gudhi/Persistent_cohomology.h | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bea06e2..047079bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ if(MSVC) # Turn off some VC++ warnings SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wno-sign-compare") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") endif() @@ -76,7 +76,7 @@ else() add_subdirectory(src/Bottleneck/test) # GudhUI - add_subdirectory(src/GudhUI) + #add_subdirectory(src/GudhUI) # data points generator add_subdirectory(data/points/generator) diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 05f70c39..efe20151 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -266,13 +266,10 @@ class Persistent_cohomology { } ~Persistent_cohomology() { -// Clean the remaining columns in the matrix. - for (auto & cam_ref : cam_) { - cam_ref.col_.clear(); - } -// Clean the transversal lists + // Clean the transversal lists for (auto & transverse_ref : transverse_idx_) { - transverse_ref.second.row_->clear(); + // Release all the cells + transverse_ref.second.row_->clear_and_dispose([&](Cell*p){cell_pool_.destroy(p);}); delete transverse_ref.second.row_; } } @@ -600,6 +597,8 @@ class Persistent_cohomology { Simplex_key key_tmp = dsets_.find_set(curr_col->class_key_); ds_repr_[key_tmp] = &(*(result_insert_cam.first)); result_insert_cam.first->class_key_ = key_tmp; + // intrusive containers don't own their elements, we have to release them manually + curr_col->col_.clear_and_dispose([&](Cell*p){cell_pool_.destroy(p);}); column_pool_.destroy(curr_col); // delete curr_col; } } -- cgit v1.2.3 From 5dcc9dd4b14705b655c0129cf390c35a51b57dfe Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 28 Sep 2015 17:00:07 +0000 Subject: Minor optimization: no need to return memory to the dying pool. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/pool@803 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5ea7edddd00890a060d4a77302d239e9e8ef0c85 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 390d47dd..5f399f1a 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -268,8 +268,8 @@ class Persistent_cohomology { ~Persistent_cohomology() { // Clean the transversal lists for (auto & transverse_ref : transverse_idx_) { - // Release all the cells - transverse_ref.second.row_->clear_and_dispose([&](Cell*p){cell_pool_.destroy(p);}); + // Destruct all the cells + transverse_ref.second.row_->clear_and_dispose([&](Cell*p){p->~Cell();}); delete transverse_ref.second.row_; } } -- cgit v1.2.3 From a19368075090f5409dc12081df944f90353eb5df Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 2 Oct 2015 16:00:28 +0000 Subject: Doxygen to be made from user version. Hypergenerator fix. Add definitions for debug traces. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@821 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5625aaab792264df86d7d442a2e6ff9886cf5d24 --- data/points/generator/CMakeLists.txt | 2 +- data/points/generator/hypergenerator.cpp | 9 ++- scripts/generate_version.sh | 20 +++---- src/Doxyfile | 8 +-- src/GudhUI/CMakeLists.txt | 17 ++++-- src/Persistent_cohomology/example/CMakeLists.txt | 7 ++- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 74 ++++++++++++++++++++++-- 7 files changed, 108 insertions(+), 29 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/data/points/generator/CMakeLists.txt b/data/points/generator/CMakeLists.txt index 0f2674c4..0d045450 100644 --- a/data/points/generator/CMakeLists.txt +++ b/data/points/generator/CMakeLists.txt @@ -21,6 +21,6 @@ if(CGAL_FOUND) add_test(hypergenerator_in_cube_50000_2 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator in cube inCube.off 50000 3) endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile hypergenerator. Version 4.6.0 is required.") endif () endif() diff --git a/data/points/generator/hypergenerator.cpp b/data/points/generator/hypergenerator.cpp index f4ea6b07..32ef450d 100644 --- a/data/points/generator/hypergenerator.cpp +++ b/data/points/generator/hypergenerator.cpp @@ -86,8 +86,13 @@ int main(int argc, char **argv) { } std::ofstream diagram_out(argv[3]); - diagram_out << "OFF" << std::endl; - diagram_out << points_number << " 0 0" << std::endl; + if (dimension == 3) { + diagram_out << "OFF" << std::endl; + diagram_out << points_number << " 0 0" << std::endl; + } else { + diagram_out << "nOFF" << std::endl; + diagram_out << dimension << " " << points_number << " 0 0" << std::endl; + } if (diagram_out.is_open()) { // Instanciate a random point generator diff --git a/scripts/generate_version.sh b/scripts/generate_version.sh index 4d28cf53..e7575282 100755 --- a/scripts/generate_version.sh +++ b/scripts/generate_version.sh @@ -2,6 +2,8 @@ #usage bash generate_version.sh : dont generate if svn st non empty #usage bash generate_version.sh -f : generate even if svn is empty #usage bash generate_version.sh -f DIR : generate even if svn is empty and save library in dir +# +# 23/06/2015 - Remove source, add biblio, and doc # VERSION CHECK ROOT_DIR=.. VERSION_FILE="$ROOT_DIR/Version.txt" @@ -48,11 +50,13 @@ cp $ROOT_DIR/COPYING $VERSION_DIR cp -R $ROOT_DIR/data $VERSION_DIR cp $ROOT_DIR/src/CMakeLists.txt $VERSION_DIR cp $ROOT_DIR/src/Doxyfile $VERSION_DIR +cp -R $ROOT_DIR/biblio $VERSION_DIR # PACKAGE LEVEL COPY PACKAGE_INC_DIR="/include" -PACKAGE_SRC_DIR="/source" +#PACKAGE_SRC_DIR="/source" PACKAGE_EX_DIR="/example" +PACKAGE_DOC_DIR="/doc" for package in `ls $ROOT_DIR/src/` do echo $package @@ -77,20 +81,16 @@ do fi cp -R $ROOT_DIR/src/$package$PACKAGE_INC_DIR/* $VERSION_DIR$PACKAGE_INC_DIR/ fi - if [ -d "$ROOT_DIR/src/$package$PACKAGE_SRC_DIR" ] - then - if [ ! -d "$VERSION_DIR$PACKAGE_SRC_DIR" ] - then - # MUST CREATE DIRECTORY ON FIRST LOOP - mkdir $VERSION_DIR$PACKAGE_INC_DIR - fi - cp -R $ROOT_DIR/src/$package$PACKAGE_SRC_DIR/* $VERSION_DIR$PACKAGE_SRC_DIR/ - fi if [ -d "$ROOT_DIR/src/$package$PACKAGE_EX_DIR" ] then mkdir -p $VERSION_DIR$PACKAGE_EX_DIR/$package cp -R $ROOT_DIR/src/$package$PACKAGE_EX_DIR/* $VERSION_DIR$PACKAGE_EX_DIR/$package fi + if [ -d "$ROOT_DIR/src/$package$PACKAGE_DOC_DIR" ] + then + mkdir -p $VERSION_DIR$PACKAGE_DOC_DIR/$package + cp -R $ROOT_DIR/src/$package$PACKAGE_DOC_DIR/* $VERSION_DIR$PACKAGE_DOC_DIR/$package + fi fi fi done diff --git a/src/Doxyfile b/src/Doxyfile index 62412627..85c496a8 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -672,7 +672,7 @@ LAYOUT_FILE = # search path. Do not use file names with spaces, bibtex cannot handle them. See # also \cite for info how to create references. -CITE_BIB_FILES = ../biblio/bibliography.bib +CITE_BIB_FILES = biblio/bibliography.bib #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages @@ -831,9 +831,9 @@ EXAMPLE_RECURSIVE = NO # that contain images that are to be included in the documentation (see the # \image command). -IMAGE_PATH = Skeleton_blocker/doc/ \ - common/doc/ \ - Contraction/doc/ +IMAGE_PATH = doc/Skeleton_blocker/ \ + doc/common/ \ + doc/Contraction/ # The INPUT_FILTER tag can be used to specify a program that doxygen should diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index 9348868a..e896f42c 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -6,10 +6,6 @@ find_package(Qt4) find_package(QGLViewer) find_package(OpenGL) -message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") -message("CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}") -message("CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") - if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) set( QT_USE_QTXML TRUE ) set( QT_USE_QTMAIN TRUE ) @@ -23,6 +19,19 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) include(${QT_USE_FILE}) include(${CGAL_USE_FILE}) + +if(MSVC) + # Turn off some VC++ warnings + SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") +endif() + +message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") +message("CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}") +message("CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories(.) diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 9487cce6..3276989d 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -28,8 +28,11 @@ if (NOT MSVC) target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) if(CGAL_FOUND) - # uncomment to display debug traces - # add_definitions(-DDEBUG_TRACES) + if (CMAKE_BUILD_TYPE MATCHES Debug) + # For programs to be more verbose + add_definitions(-DDEBUG_TRACES) + endif() + add_executable(alpha_shapes_persistence alpha_shapes_persistence.cpp) target_link_libraries(alpha_shapes_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY}) add_test(alpha_shapes_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 2 0.5) diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 5733dda1..1539ad2b 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -359,59 +359,121 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { } +bool sort_in_decr_order (Vertex_handle i,Vertex_handle j) { return (i>j); } + BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF RECURSIVE INSERTION" << std::endl; typeST st; + typePairSimplexBool returnValue; + int position = 0; // ++ FIRST std::cout << " - INSERT (2,1,0)" << std::endl; typeVectorVertex SimplexVector1{2, 1, 0}; BOOST_CHECK(SimplexVector1.size() == 3); - st.insert_simplex_and_subfaces(SimplexVector1); + returnValue = st.insert_simplex_and_subfaces(SimplexVector1); BOOST_CHECK(st.num_vertices() == (size_t) 3); // +3 (2, 1 and 0 are not existing) + // Check it is well inserted + BOOST_CHECK(true == returnValue.second); + position = 0; + std::sort(SimplexVector1.begin(), SimplexVector1.end(), sort_in_decr_order); + for (auto vertex : st.simplex_vertex_range(returnValue.first)) { + // Check returned Simplex_handle + std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector1[position] << std::endl; + BOOST_CHECK(vertex == SimplexVector1[position]); + position++; + } + // ++ SECOND std::cout << " - INSERT 3" << std::endl; typeVectorVertex SimplexVector2{3}; BOOST_CHECK(SimplexVector2.size() == 1); - st.insert_simplex_and_subfaces(SimplexVector2); + returnValue = st.insert_simplex_and_subfaces(SimplexVector2); BOOST_CHECK(st.num_vertices() == (size_t) 4); // +1 (3 is not existing) + // Check it is well inserted + BOOST_CHECK(true == returnValue.second); + position = 0; + std::sort(SimplexVector2.begin(), SimplexVector2.end(), sort_in_decr_order); + for (auto vertex : st.simplex_vertex_range(returnValue.first)) { + // Check returned Simplex_handle + std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector2[position] << std::endl; + BOOST_CHECK(vertex == SimplexVector2[position]); + position++; + } + // ++ THIRD std::cout << " - INSERT (0,3)" << std::endl; typeVectorVertex SimplexVector3{3, 0}; BOOST_CHECK(SimplexVector3.size() == 2); - st.insert_simplex_and_subfaces(SimplexVector3); + returnValue = st.insert_simplex_and_subfaces(SimplexVector3); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented (all are existing) + // Check it is well inserted + BOOST_CHECK(true == returnValue.second); + position = 0; + std::sort(SimplexVector3.begin(), SimplexVector3.end(), sort_in_decr_order); + for (auto vertex : st.simplex_vertex_range(returnValue.first)) { + // Check returned Simplex_handle + std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector3[position] << std::endl; + BOOST_CHECK(vertex == SimplexVector3[position]); + position++; + } + // ++ FOURTH std::cout << " - INSERT (1,0) (already inserted)" << std::endl; typeVectorVertex SimplexVector4{1, 0}; BOOST_CHECK(SimplexVector4.size() == 2); - st.insert_simplex_and_subfaces(SimplexVector4); + returnValue = st.insert_simplex_and_subfaces(SimplexVector4); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented (all are existing) + // Check it was not inserted (already there from {2,1,0} insertion) + BOOST_CHECK(false == returnValue.second); + // ++ FIFTH std::cout << " - INSERT (3,4,5)" << std::endl; typeVectorVertex SimplexVector5{3, 4, 5}; BOOST_CHECK(SimplexVector5.size() == 3); - st.insert_simplex_and_subfaces(SimplexVector5); + returnValue = st.insert_simplex_and_subfaces(SimplexVector5); BOOST_CHECK(st.num_vertices() == (size_t) 6); + // Check it is well inserted + BOOST_CHECK(true == returnValue.second); + position = 0; + std::sort(SimplexVector5.begin(), SimplexVector5.end(), sort_in_decr_order); + for (auto vertex : st.simplex_vertex_range(returnValue.first)) { + // Check returned Simplex_handle + std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector5[position] << std::endl; + BOOST_CHECK(vertex == SimplexVector5[position]); + position++; + } + // ++ SIXTH std::cout << " - INSERT (0,1,6,7)" << std::endl; typeVectorVertex SimplexVector6{0, 1, 6, 7}; BOOST_CHECK(SimplexVector6.size() == 4); - st.insert_simplex_and_subfaces(SimplexVector6); + returnValue = st.insert_simplex_and_subfaces(SimplexVector6); BOOST_CHECK(st.num_vertices() == (size_t) 8); // +2 (6 and 7 are not existing - 0 and 1 are already existing) + // Check it is well inserted + BOOST_CHECK(true == returnValue.second); + position = 0; + std::sort(SimplexVector6.begin(), SimplexVector6.end(), sort_in_decr_order); + for (auto vertex : st.simplex_vertex_range(returnValue.first)) { + // Check returned Simplex_handle + std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector6[position] << std::endl; + BOOST_CHECK(vertex == SimplexVector6[position]); + position++; + } + /* Inserted simplex: */ /* 1 6 */ /* o---o */ -- cgit v1.2.3 From b813fb206a8c03e6f2e278e734d11d4acd5922ad Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 5 Oct 2015 14:48:35 +0000 Subject: cpplint fixes - simplex_tree_from_file.cpp renamed simplex_tree_from_cliques_of_graph.cpp - #include "" vs #include <> for skeleton blockers git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@826 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1bd1ad535e4283bce35eeb31fa8d7896b9de474b --- src/CMakeLists.txt | 7 + src/GudhUI/utils/UI_utils.h | 13 +- .../Persistent_cohomology_column.h | 8 +- src/Simplex_tree/example/CMakeLists.txt | 6 +- .../example/simplex_tree_from_cliques_of_graph.cpp | 114 +++++ .../example/simplex_tree_from_file.cpp | 114 ----- .../gudhi/Simplex_tree/Simplex_tree_siblings.h | 7 +- .../include/gudhi/Skeleton_blocker.h | 29 +- .../Skeleton_blocker_complex_visitor.h | 10 +- .../Skeleton_blocker_link_superior.h | 8 +- .../Skeleton_blocker/Skeleton_blocker_off_io.h | 10 +- .../Skeleton_blocker_simple_geometric_traits.h | 10 +- .../Skeleton_blocker_simple_traits.h | 9 +- .../Skeleton_blocker/Skeleton_blocker_simplex.h | 7 +- .../Skeleton_blocker_sub_complex.h | 15 +- .../gudhi/Skeleton_blocker/internal/Top_faces.h | 105 ++--- .../include/gudhi/Skeleton_blocker/internal/Trie.h | 464 ++++++++++----------- .../Skeleton_blockers_blockers_iterators.h | 221 +++++----- .../iterators/Skeleton_blockers_edges_iterators.h | 277 ++++++------ .../iterators/Skeleton_blockers_iterators.h | 19 +- .../Skeleton_blockers_simplices_iterators.h | 23 +- .../Skeleton_blockers_triangles_iterators.h | 407 +++++++++--------- .../Skeleton_blockers_vertices_iterators.h | 318 +++++++------- .../include/gudhi/Skeleton_blocker_complex.h | 37 +- .../gudhi/Skeleton_blocker_geometric_complex.h | 12 +- .../include/gudhi/Skeleton_blocker_link_complex.h | 10 +- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 8 +- src/common/include/gudhi/reader_utils.h | 10 +- 28 files changed, 1111 insertions(+), 1167 deletions(-) create mode 100644 src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp delete mode 100644 src/Simplex_tree/example/simplex_tree_from_file.cpp (limited to 'src/Persistent_cohomology') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 545b0b58..fbc3119d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,11 @@ cmake_minimum_required(VERSION 2.6) project(GUDHI) +# Do not forget to version number. +set (GUDHI_MAJOR_VERSION 1) +set (GUDHI_MINOR_VERSION 2) +set (GUDHI_PATCH_VERSION 0) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(Boost REQUIRED COMPONENTS system filesystem program_options chrono timer REQUIRED) @@ -51,4 +56,6 @@ else() # data points generator add_subdirectory(data/points/generator) + install (FILES include/* DESTINATION include) + endif() diff --git a/src/GudhUI/utils/UI_utils.h b/src/GudhUI/utils/UI_utils.h index a7c0689f..4ade4b98 100644 --- a/src/GudhUI/utils/UI_utils.h +++ b/src/GudhUI/utils/UI_utils.h @@ -8,21 +8,18 @@ #ifndef UI_UTILS_H_ #define UI_UTILS_H_ -#define PRINT(a) std::cerr << #a << ": " << (a) << " (DISP)"< "; for(auto x:a) std::cerr<< x << ","; std::cerr< +#include +#include +#include -#include "boost/tuple/tuple.hpp" -#include "boost/intrusive/set.hpp" -#include "boost/intrusive/list.hpp" +#include namespace Gudhi { diff --git a/src/Simplex_tree/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt index 2f924490..c70cfe35 100644 --- a/src/Simplex_tree/example/CMakeLists.txt +++ b/src/Simplex_tree/example/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 2.6) project(GUDHISimplexTreeFromFile) -add_executable ( simplex_tree_from_file simplex_tree_from_file.cpp ) -add_test(simplex_tree_from_file_2 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_file ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 2) -add_test(simplex_tree_from_file_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_file ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 3) +add_executable ( simplex_tree_from_cliques_of_graph simplex_tree_from_cliques_of_graph.cpp ) +add_test(simplex_tree_from_cliques_of_graph_2 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_cliques_of_graph ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 2) +add_test(simplex_tree_from_cliques_of_graph_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_cliques_of_graph ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 3) add_executable ( simple_simplex_tree simple_simplex_tree.cpp ) add_test(simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/simple_simplex_tree) diff --git a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp new file mode 100644 index 00000000..58085014 --- /dev/null +++ b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp @@ -0,0 +1,114 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include +#include +#include + +using namespace Gudhi; + +int main(int argc, char * const argv[]) { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] + << " path_to_file_graph max_dim \n"; + return 0; + } + std::string filegraph = argv[1]; + int max_dim = atoi(argv[2]); + + clock_t start, end; + // Construct the Simplex Tree + Simplex_tree<> st; + + start = clock(); + auto g = read_graph(filegraph); + // insert the graph in the simplex tree as 1-skeleton + st.insert_graph(g); + end = clock(); + std::cout << "Insert the 1-skeleton in the simplex tree in " + << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; + + start = clock(); + // expand the 1-skeleton until dimension max_dim + st.expansion(max_dim); + end = clock(); + std::cout << "max_dim = " << max_dim << "\n"; + std::cout << "Expand the simplex tree in " + << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << st.num_vertices() << " "; + std::cout << " Number of simplices = " << st.num_simplices() << std::endl; + std::cout << std::endl << std::endl; + + std::cout << "Iterator on vertices: "; + for (auto vertex : st.complex_vertex_range()) { + std::cout << vertex << " "; + } + + std::cout << std::endl; + + std::cout << std::endl << std::endl; + + std::cout << "Iterator on simplices: " << std::endl; + for (auto simplex : st.complex_simplex_range()) { + std::cout << " "; + for (auto vertex : st.simplex_vertex_range(simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } + + std::cout << std::endl << std::endl; + + std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + for (auto f_simplex : st.filtration_simplex_range()) { + std::cout << " " << "[" << st.filtration(f_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } + + std::cout << std::endl << std::endl; + + std::cout << "Iterator on Simplices in the filtration, and their boundary simplices:" << std::endl; + for (auto f_simplex : st.filtration_simplex_range()) { + std::cout << " " << "[" << st.filtration(f_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + + for (auto b_simplex : st.boundary_simplex_range(f_simplex)) { + std::cout << " " << "[" << st.filtration(b_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(b_simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } + } + return 0; +} diff --git a/src/Simplex_tree/example/simplex_tree_from_file.cpp b/src/Simplex_tree/example/simplex_tree_from_file.cpp deleted file mode 100644 index 58085014..00000000 --- a/src/Simplex_tree/example/simplex_tree_from_file.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include -#include -#include - -using namespace Gudhi; - -int main(int argc, char * const argv[]) { - if (argc != 3) { - std::cerr << "Usage: " << argv[0] - << " path_to_file_graph max_dim \n"; - return 0; - } - std::string filegraph = argv[1]; - int max_dim = atoi(argv[2]); - - clock_t start, end; - // Construct the Simplex Tree - Simplex_tree<> st; - - start = clock(); - auto g = read_graph(filegraph); - // insert the graph in the simplex tree as 1-skeleton - st.insert_graph(g); - end = clock(); - std::cout << "Insert the 1-skeleton in the simplex tree in " - << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; - - start = clock(); - // expand the 1-skeleton until dimension max_dim - st.expansion(max_dim); - end = clock(); - std::cout << "max_dim = " << max_dim << "\n"; - std::cout << "Expand the simplex tree in " - << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << st.num_vertices() << " "; - std::cout << " Number of simplices = " << st.num_simplices() << std::endl; - std::cout << std::endl << std::endl; - - std::cout << "Iterator on vertices: "; - for (auto vertex : st.complex_vertex_range()) { - std::cout << vertex << " "; - } - - std::cout << std::endl; - - std::cout << std::endl << std::endl; - - std::cout << "Iterator on simplices: " << std::endl; - for (auto simplex : st.complex_simplex_range()) { - std::cout << " "; - for (auto vertex : st.simplex_vertex_range(simplex)) { - std::cout << vertex << " "; - } - std::cout << std::endl; - } - - std::cout << std::endl << std::endl; - - std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for (auto f_simplex : st.filtration_simplex_range()) { - std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for (auto vertex : st.simplex_vertex_range(f_simplex)) { - std::cout << vertex << " "; - } - std::cout << std::endl; - } - - std::cout << std::endl << std::endl; - - std::cout << "Iterator on Simplices in the filtration, and their boundary simplices:" << std::endl; - for (auto f_simplex : st.filtration_simplex_range()) { - std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for (auto vertex : st.simplex_vertex_range(f_simplex)) { - std::cout << vertex << " "; - } - std::cout << std::endl; - - for (auto b_simplex : st.boundary_simplex_range(f_simplex)) { - std::cout << " " << "[" << st.filtration(b_simplex) << "] "; - for (auto vertex : st.simplex_vertex_range(b_simplex)) { - std::cout << vertex << " "; - } - std::cout << std::endl; - } - } - return 0; -} diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h index 52eeaaea..9cdda967 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h @@ -23,12 +23,13 @@ #ifndef SIMPLEX_TREE_SIBLINGS_H_ #define SIMPLEX_TREE_SIBLINGS_H_ +#include + +#include + #include #include -#include "boost/container/flat_map.hpp" -#include "Simplex_tree_node_explicit_storage.h" - namespace Gudhi { /* \addtogroup simplex_tree diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h index 289819b5..792a7994 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h @@ -19,23 +19,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_H_ -#include "gudhi/Skeleton_blocker_complex.h" -#include "gudhi/Skeleton_blocker_geometric_complex.h" -#include "gudhi/Skeleton_blocker_simplifiable_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h" +#ifndef SKELETON_BLOCKER_H_ +#define SKELETON_BLOCKER_H_ -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h" +#include +#include +#include +#include +#include +#include -#include "gudhi/Utils.h" // xxx - +#include // xxx namespace Gudhi { + namespace skbl { + /** \defgroup skbl Skeleton-Blocker \author David Salinas @@ -243,11 +244,9 @@ their collaboration to write the two initial papers \verbatim Contact: David Salinas, david.salinas@inria.fr \endverbatim */ /** @} */ // end defgroup -} // namespace skbl -} // namespace Gudhi - - -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_H_ +} // namespace skbl +} // namespace Gudhi +#endif // SKELETON_BLOCKER_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h index 829ab1e8..72bdf4c9 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h @@ -19,10 +19,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h" +#include namespace Gudhi { @@ -59,7 +59,7 @@ class Skeleton_blocker_complex_visitor { * remove_edge(b,x) */ virtual void on_swaped_edge(Vertex_handle a, Vertex_handle b, - Vertex_handle x)=0; + Vertex_handle x) = 0; virtual void on_add_blocker( const Skeleton_blocker_simplex&) = 0; virtual void on_delete_blocker( @@ -132,4 +132,4 @@ class Print_complex_visitor : public Skeleton_blocker_complex_visitor< } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h index 17d58956..d39fa9f3 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h @@ -19,10 +19,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ -#include "gudhi/Skeleton_blocker_link_complex.h" +#include namespace Gudhi { @@ -74,4 +74,4 @@ class Skeleton_blocker_link_superior : public Skeleton_blocker_link_complex< } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h index 6ad1fdd3..ec000986 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h @@ -19,15 +19,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ + +#include #include #include #include -#include "gudhi/Off_reader.h" - namespace Gudhi { namespace skbl { @@ -197,4 +197,4 @@ class Skeleton_blocker_off_writer { } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h index d3a5b9d8..8508d9a5 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h @@ -19,14 +19,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ + +#include #include #include -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h" - namespace Gudhi { namespace skbl { @@ -91,4 +91,4 @@ struct Skeleton_blocker_simple_geometric_traits : } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h index 52e454ea..10d552ec 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h @@ -19,12 +19,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ + +#include #include #include -#include "Skeleton_blocker_simplex.h" namespace Gudhi { @@ -77,7 +78,7 @@ struct Skeleton_blocker_simple_traits { : vertex(val) { } - operator int() const { return (int)vertex; } + operator int() const { return static_cast(vertex); } boost_vertex_handle vertex; diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h index 0a2fcb9a..0d838d50 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ #include #include @@ -371,5 +371,4 @@ class Skeleton_blocker_simplex { } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ - +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h index 40e26c68..b33b9606 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h @@ -20,16 +20,16 @@ * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ + +#include +#include +#include #include #include -#include "gudhi/Skeleton_blocker_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h" -#include "gudhi/Utils.h" - namespace Gudhi { namespace skbl { @@ -75,7 +75,6 @@ class Skeleton_blocker_sub_complex : public ComplexType { typedef typename ComplexType::Root_simplex_handle Root_simplex_handle; protected: - /** * @brief Determines whether all proper faces of simplex 'sigma' belong to 'link1' \cup 'link2' * where 'link1' and 'link2' are subcomplexes of the same complex of type ComplexType @@ -287,5 +286,5 @@ bool proper_faces_in_union( } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h index 32538f38..eb970195 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h @@ -1,67 +1,70 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef TOP_FACES_H_ -#define TOP_FACES_H_ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_ +#define SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_ #include #include #include +namespace Gudhi { + +namespace skbl { + template -std::list subfaces(SimplexHandle top_face){ - std::list res; - if(top_face.dimension()==-1) return res; - if(top_face.dimension()==0) { - res.push_back(top_face); - return res; - } - else{ - auto first_vertex = top_face.first_vertex(); - top_face.remove_vertex(first_vertex); - res = subfaces(top_face); - std::list copy = res; - for(auto& simplex : copy){ - simplex.add_vertex(first_vertex); - } - res.push_back(SimplexHandle(first_vertex)); - res.splice(res.end(),copy); - return res; - } +std::list subfaces(SimplexHandle top_face) { + std::list res; + if (top_face.dimension() == -1) return res; + if (top_face.dimension() == 0) { + res.push_back(top_face); + return res; + } else { + auto first_vertex = top_face.first_vertex(); + top_face.remove_vertex(first_vertex); + res = subfaces(top_face); + std::list copy = res; + for (auto& simplex : copy) { + simplex.add_vertex(first_vertex); + } + res.push_back(SimplexHandle(first_vertex)); + res.splice(res.end(), copy); + return res; + } } /** * add all faces of top_face in simplices_per_dimension */ template -void register_faces( - std::vector< std::set >& simplices_per_dimension, - const SimplexHandle& top_face){ - std::list subfaces_list = subfaces(top_face); - for(auto& simplex : subfaces_list ){ - simplices_per_dimension[simplex.dimension()].insert(simplex); - } +void register_faces(std::vector< std::set >& simplices_per_dimension, + const SimplexHandle& top_face) { + std::list subfaces_list = subfaces(top_face); + for (auto& simplex : subfaces_list) { + simplices_per_dimension[simplex.dimension()].insert(simplex); + } } +} // namespace skbl +} // namespace Gudhi - -#endif /* TOP_FACES_H_ */ +#endif // SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h index f2a443dc..aa0416ef 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h @@ -1,13 +1,10 @@ -/* - * Trie.h - * Created on: Jan 29, 2015 - * This file is part of the Gudhi Library. The Gudhi library +/* This file is part of the Gudhi Library. The Gudhi library * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * * Author(s): David Salinas * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,8 +22,8 @@ */ -#ifndef TRIE_H_ -#define TRIE_H_ +#ifndef SKELETON_BLOCKER_INTERNAL_TRIE_H_ +#define SKELETON_BLOCKER_INTERNAL_TRIE_H_ #include #include @@ -35,242 +32,237 @@ namespace Gudhi { - namespace skbl { - template -struct Trie{ - typedef SimplexHandle Simplex_handle; - typedef typename SimplexHandle::Vertex_handle Vertex_handle; - - Vertex_handle v; - std::vector > childs; - //std::vector > childs; -> use of deleted function -private: - const Trie* parent_; -public: - Trie():parent_(0){} - Trie(Vertex_handle v_):v(v_),parent_(0){} - - Trie(Vertex_handle v_,Trie* parent):v(v_),parent_(parent){} - - - bool operator==(const Trie& other) const{ - return (v == other.v) ; - } - - void add_child(Trie* child){ - if(child){ - std::shared_ptr ptr_to_add(child); - childs.push_back(ptr_to_add); - child->parent_ = this; - } - } - - typedef typename Simplex_handle::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; - - - Trie* make_trie(Simplex_vertex_const_iterator s_it,Simplex_vertex_const_iterator s_end){ - if(s_it == s_end) return 0; - else{ - Trie* res = new Trie(*s_it); - Trie* child = make_trie(++s_it,s_end); - res->add_child(child); - return res; - } - } -private: - //go down recursively in the tree while advancing the simplex iterator. - //when it reaches a leaf, it inserts the remaining that is not present - void add_simplex_helper(Simplex_vertex_const_iterator s_it,Simplex_vertex_const_iterator s_end){ - assert(*s_it == v); - ++s_it; - if(s_it==s_end) return ; - if(!is_leaf()){ - for(auto child : childs){ - if(child->v == *s_it) - return child->add_simplex_helper(s_it,s_end); - } - //s_it is not found and needs to be inserted - } - //not leaf -> remaining of s needs to be inserted - Trie* son_with_what_remains_of_s(make_trie(s_it,s_end)); - add_child(son_with_what_remains_of_s); - return; - } - - void maximal_faces_helper(std::vector& res) const{ - if(is_leaf()) res.push_back(simplex()); - else - for(auto child : childs) - child->maximal_faces_helper(res); - } - -public: - /** - * adds the simplex to the trie - */ - void add_simplex(const Simplex_handle& s){ - if(s.empty()) return; - assert(v==s.first_vertex()); - add_simplex_helper(s.begin(),s.end()); - } - - std::vector maximal_faces() const{ - std::vector res; - maximal_faces_helper(res); - return res; - } - - /** - * Goes to the root in the trie to consitute simplex - */ - void add_vertices_up_to_the_root(Simplex_handle& res) const{ - res.add_vertex(v); - if(parent_) - parent_->add_vertices_up_to_the_root(res); - } - - Simplex_handle simplex() const{ - Simplex_handle res; - add_vertices_up_to_the_root(res); - return res; - } - - bool is_leaf() const{ - return childs.empty(); - } - - bool is_root() const{ - return parent_==0; - } - - const Trie* parent() { - return parent_; - } - - void remove_leaf() { - assert(is_leaf); - if(!is_root()) - parent_->childs.erase(this); - } - - /** - * true iff the simplex corresponds to one node in the trie - */ - bool contains(const Simplex_handle& s) const{ - Trie const* current = this; - if(s.empty()) return true; - if(current->v != s.first_vertex()) return false; - auto s_pos = s.begin(); - ++s_pos; - while(s_pos != s.end() && current != 0){ - bool found = false; - for(const auto child : current->childs){ - if(child->v == *s_pos) { - ++s_pos; - current = child.get(); - found = true; - break; - } - } - if(!found) return false; - } - return current!=0; - } - - Trie* go_bottom_left(){ - if(is_leaf()) - return this; - else - return (*childs.begin())->go_bottom_left(); - } - - friend std::ostream& operator<<(std::ostream& stream, const Trie& trie){ - stream<< "T( "<< trie.v<< " "; - for(auto t : trie.childs) - stream << *t ; - stream<<")"; - return stream; - } +struct Trie { + typedef SimplexHandle Simplex_handle; + typedef typename SimplexHandle::Vertex_handle Vertex_handle; + + Vertex_handle v; + std::vector > childs; + // std::vector > childs; -> use of deleted function + private: + const Trie* parent_; + + public: + Trie() : parent_(0) { } + + Trie(Vertex_handle v_) : v(v_), parent_(0) { } + + Trie(Vertex_handle v_, Trie* parent) : v(v_), parent_(parent) { } + + bool operator==(const Trie& other) const { + return (v == other.v); + } + + void add_child(Trie* child) { + if (child) { + std::shared_ptr ptr_to_add(child); + childs.push_back(ptr_to_add); + child->parent_ = this; + } + } + + typedef typename Simplex_handle::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; + + Trie* make_trie(Simplex_vertex_const_iterator s_it, Simplex_vertex_const_iterator s_end) { + if (s_it == s_end) { + return 0; + } else { + Trie* res = new Trie(*s_it); + Trie* child = make_trie(++s_it, s_end); + res->add_child(child); + return res; + } + } + + private: + // go down recursively in the tree while advancing the simplex iterator. + // when it reaches a leaf, it inserts the remaining that is not present + void add_simplex_helper(Simplex_vertex_const_iterator s_it, Simplex_vertex_const_iterator s_end) { + assert(*s_it == v); + ++s_it; + if (s_it == s_end) return; + if (!is_leaf()) { + for (auto child : childs) { + if (child->v == *s_it) + return child->add_simplex_helper(s_it, s_end); + } + // s_it is not found and needs to be inserted + } + // not leaf -> remaining of s needs to be inserted + Trie * son_with_what_remains_of_s(make_trie(s_it, s_end)); + add_child(son_with_what_remains_of_s); + return; + } + + void maximal_faces_helper(std::vector& res) const { + if (is_leaf()) res.push_back(simplex()); + else + for (auto child : childs) + child->maximal_faces_helper(res); + } + + public: + /** + * adds the simplex to the trie + */ + void add_simplex(const Simplex_handle& s) { + if (s.empty()) return; + assert(v == s.first_vertex()); + add_simplex_helper(s.begin(), s.end()); + } + + std::vector maximal_faces() const { + std::vector res; + maximal_faces_helper(res); + return res; + } + + /** + * Goes to the root in the trie to consitute simplex + */ + void add_vertices_up_to_the_root(Simplex_handle& res) const { + res.add_vertex(v); + if (parent_) + parent_->add_vertices_up_to_the_root(res); + } + + Simplex_handle simplex() const { + Simplex_handle res; + add_vertices_up_to_the_root(res); + return res; + } + + bool is_leaf() const { + return childs.empty(); + } + + bool is_root() const { + return parent_ == 0; + } + + const Trie* parent() { + return parent_; + } + + void remove_leaf() { + assert(is_leaf); + if (!is_root()) + parent_->childs.erase(this); + } + + /** + * true iff the simplex corresponds to one node in the trie + */ + bool contains(const Simplex_handle& s) const { + Trie const* current = this; + if (s.empty()) return true; + if (current->v != s.first_vertex()) return false; + auto s_pos = s.begin(); + ++s_pos; + while (s_pos != s.end() && current != 0) { + bool found = false; + for (const auto child : current->childs) { + if (child->v == *s_pos) { + ++s_pos; + current = child.get(); + found = true; + break; + } + } + if (!found) return false; + } + return current != 0; + } + + Trie* go_bottom_left() { + if (is_leaf()) + return this; + else + return (*childs.begin())->go_bottom_left(); + } + + friend std::ostream& operator<<(std::ostream& stream, const Trie& trie) { + stream << "T( " << trie.v << " "; + for (auto t : trie.childs) + stream << *t; + stream << ")"; + return stream; + } }; - template -struct Tries{ - typedef typename SimplexHandle::Vertex_handle Vertex_handle; - typedef SimplexHandle Simplex_handle; - - typedef Trie STrie; - - - template - Tries(unsigned num_vertices,SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end): - cofaces_(num_vertices,0){ - for (auto i = 0u; i < num_vertices; ++i) - cofaces_[i] = new STrie(Vertex_handle(i)); - for (auto s_it = simplex_begin; s_it != simplex_end; ++s_it) { - if (s_it->dimension() >= 1) - cofaces_[s_it->first_vertex()]->add_simplex(*s_it); - } - } - - ~Tries(){ - for(STrie* t : cofaces_) - delete t; - } - - //return a simplex that consists in all u such uv is an edge and u>v - Simplex_handle positive_neighbors(Vertex_handle v) const{ - Simplex_handle res; - for(auto child : cofaces_[v]->childs) - res.add_vertex(child->v); - return res; - } - - bool contains(const Simplex_handle& s) const{ - auto first_v = s.first_vertex(); - return cofaces_[first_v]->contains(s); - } - - friend std::ostream& operator<<(std::ostream& stream, const Tries& tries){ - for(auto trie : tries.cofaces_) - stream<<*trie< next_dimension_simplices() const{ - std::vector res; - while(!to_see_.empty() && to_see_.front()->simplex().dimension()==current_dimension_){ - res.emplace_back(to_see_.front()->simplex()); - for(auto child : to_see_.front()->childs) - to_see_.push_back(child.get()); - to_see_.pop_front(); - } - ++current_dimension_; - return res; - } - - void init_next_dimension() const{ - for(auto trie : cofaces_) - to_see_.push_back(trie); - } - -private: - mutable std::deque to_see_; - mutable unsigned current_dimension_=0; - - - std::vector cofaces_; - +struct Tries { + typedef typename SimplexHandle::Vertex_handle Vertex_handle; + typedef SimplexHandle Simplex_handle; + + typedef Trie STrie; + + template + Tries(unsigned num_vertices, SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) : + cofaces_(num_vertices, 0) { + for (auto i = 0u; i < num_vertices; ++i) + cofaces_[i] = new STrie(Vertex_handle(i)); + for (auto s_it = simplex_begin; s_it != simplex_end; ++s_it) { + if (s_it->dimension() >= 1) + cofaces_[s_it->first_vertex()]->add_simplex(*s_it); + } + } + + ~Tries() { + for (STrie* t : cofaces_) + delete t; + } + + // return a simplex that consists in all u such uv is an edge and u>v + + Simplex_handle positive_neighbors(Vertex_handle v) const { + Simplex_handle res; + for (auto child : cofaces_[v]->childs) + res.add_vertex(child->v); + return res; + } + + bool contains(const Simplex_handle& s) const { + auto first_v = s.first_vertex(); + return cofaces_[first_v]->contains(s); + } + + friend std::ostream& operator<<(std::ostream& stream, const Tries& tries) { + for (auto trie : tries.cofaces_) + stream << *trie << std::endl; + return stream; + } + + // init_next_dimension must be called first + + std::vector next_dimension_simplices() const { + std::vector res; + while (!to_see_.empty() && to_see_.front()->simplex().dimension() == current_dimension_) { + res.emplace_back(to_see_.front()->simplex()); + for (auto child : to_see_.front()->childs) + to_see_.push_back(child.get()); + to_see_.pop_front(); + } + ++current_dimension_; + return res; + } + + void init_next_dimension() const { + for (auto trie : cofaces_) + to_see_.push_back(trie); + } + + private: + mutable std::deque to_see_; + mutable unsigned current_dimension_ = 0; + std::vector cofaces_; }; +} // namespace skbl +} // namespace Gudhi -} - -} - -#endif /* TRIE_H_ */ +#endif // SKELETON_BLOCKER_INTERNAL_TRIE_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h index f6f2c955..56a20a24 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h @@ -1,134 +1,131 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ - -#include "boost/iterator/iterator_facade.hpp" - -namespace Gudhi{ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ + +#include + +namespace Gudhi { namespace skbl { /** * @brief Iterator through the blockers of a vertex. - */ + */ // ReturnType = const Simplex_handle* or Simplex_handle* // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator + template class Blocker_iterator_internal : public boost::iterator_facade< - Blocker_iterator_internal, - ReturnType, - boost::forward_traversal_tag, - ReturnType - >{ -private: - MapIteratorType current_position; - MapIteratorType end_of_map; -public: - - Blocker_iterator_internal():current_position(){} - - Blocker_iterator_internal(MapIteratorType position,MapIteratorType end_of_map_ ): - current_position(position), end_of_map(end_of_map_) - { } - - bool equal(const Blocker_iterator_internal& other) const{ - return current_position == other.current_position; - } - - void increment(){ - goto_next_blocker(); - } - - ReturnType dereference() const { - return(current_position->second); - } - -private: - /** - * Let the current pair be (v,sigma) where v is a vertex and sigma is a blocker. - * If v is not the first vertex of sigma then we already have seen sigma as a blocker - * and we look for the next one. - */ - void goto_next_blocker(){ - do { - ++current_position; - } while (!(current_position == end_of_map) && !first_time_blocker_is_seen()); - } - - bool first_time_blocker_is_seen() const{ - return current_position->first == current_position->second->first_vertex(); - } +Blocker_iterator_internal, +ReturnType, +boost::forward_traversal_tag, +ReturnType +> { + private: + MapIteratorType current_position; + MapIteratorType end_of_map; + + public: + Blocker_iterator_internal() : current_position() { } + + Blocker_iterator_internal(MapIteratorType position, MapIteratorType end_of_map_) : + current_position(position), end_of_map(end_of_map_) { } + + bool equal(const Blocker_iterator_internal& other) const { + return current_position == other.current_position; + } + + void increment() { + goto_next_blocker(); + } + + ReturnType dereference() const { + return (current_position->second); + } + + private: + /** + * Let the current pair be (v,sigma) where v is a vertex and sigma is a blocker. + * If v is not the first vertex of sigma then we already have seen sigma as a blocker + * and we look for the next one. + */ + void goto_next_blocker() { + do { + ++current_position; + } while (!(current_position == end_of_map) && !first_time_blocker_is_seen()); + } + + bool first_time_blocker_is_seen() const { + return current_position->first == current_position->second->first_vertex(); + } }; - - /** * @brief Iterator through the blockers of a vertex */ // ReturnType = const Simplex_handle* or Simplex_handle* // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator + template class Blocker_iterator_around_vertex_internal : public boost::iterator_facade< - Blocker_iterator_around_vertex_internal, - ReturnType, - boost::forward_traversal_tag, - ReturnType ->{ -private: - MapIteratorType current_position_; -public: - - Blocker_iterator_around_vertex_internal():current_position_(){} - - Blocker_iterator_around_vertex_internal(MapIteratorType position): - current_position_(position) - {} - - Blocker_iterator_around_vertex_internal& operator=(Blocker_iterator_around_vertex_internal other){ - this->current_position_ = other.current_position_; - return *this; - } - - bool equal(const Blocker_iterator_around_vertex_internal& other) const{ - return current_position_ == other.current_position_; - } - - void increment(){ - current_position_++; - } - - ReturnType dereference() const{ - return(current_position_->second); - } - - - MapIteratorType current_position(){ - return this->current_position_; - } +Blocker_iterator_around_vertex_internal, +ReturnType, +boost::forward_traversal_tag, +ReturnType +> { + private: + MapIteratorType current_position_; + + public: + Blocker_iterator_around_vertex_internal() : current_position_() { } + + Blocker_iterator_around_vertex_internal(MapIteratorType position) : + current_position_(position) { } + + Blocker_iterator_around_vertex_internal& operator=(Blocker_iterator_around_vertex_internal other) { + this->current_position_ = other.current_position_; + return *this; + } + + bool equal(const Blocker_iterator_around_vertex_internal& other) const { + return current_position_ == other.current_position_; + } + + void increment() { + current_position_++; + } + + ReturnType dereference() const { + return (current_position_->second); + } + + MapIteratorType current_position() { + return this->current_position_; + } }; -} +} // namespace skbl -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h index 0be6c74d..ef4c7970 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h @@ -1,167 +1,144 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ -#define GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ - -#include "boost/iterator/iterator_facade.hpp" - - -namespace Gudhi{ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_ + +#include +#include + +#include // for pair<> + +namespace Gudhi { namespace skbl { template -class Edge_around_vertex_iterator : - public boost::iterator_facade < Edge_around_vertex_iterator - , typename SkeletonBlockerComplex::Edge_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Edge_handle const - > -{ - friend class boost::iterator_core_access; - - typedef SkeletonBlockerComplex Complex; - typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; - typedef typename Complex::Vertex_handle Vertex_handle; - typedef typename Complex::Edge_handle Edge_handle; - -private: - - const Complex* complex; - Vertex_handle v; - - boost_adjacency_iterator current_; - boost_adjacency_iterator end_; - -public: - - Edge_around_vertex_iterator():complex(NULL){ - } - - Edge_around_vertex_iterator(const Complex* complex_,Vertex_handle v_): - complex(complex_), - v(v_) - { - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - } - - /** - * returns an iterator to the end - */ - Edge_around_vertex_iterator(const Complex* complex_,Vertex_handle v_,int end): - complex(complex_), - v(v_) - { - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - set_end(); - } - - bool equal(const Edge_around_vertex_iterator& other) const{ - return (complex== other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); - } - - void increment(){ - if(current_ != end_) - ++current_; - } - - Edge_handle dereference() const{ - return *(*complex)[std::make_pair(v,static_cast(*current_))]; - } - -private: - //remove this ugly hack - void set_end(){ - current_ = end_; - } +class Edge_around_vertex_iterator : public boost::iterator_facade +, typename SkeletonBlockerComplex::Edge_handle const, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Edge_handle const> { + friend class boost::iterator_core_access; + + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; + typedef typename Complex::Vertex_handle Vertex_handle; + typedef typename Complex::Edge_handle Edge_handle; + + private: + const Complex* complex; + Vertex_handle v; + + boost_adjacency_iterator current_; + boost_adjacency_iterator end_; + + public: + Edge_around_vertex_iterator() : complex(NULL) { } + + Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + } + + /** + * returns an iterator to the end + */ + Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_, int end) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + set_end(); + } + + bool equal(const Edge_around_vertex_iterator& other) const { + return (complex == other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); + } + + void increment() { + if (current_ != end_) + ++current_; + } + + Edge_handle dereference() const { + return *(*complex)[std::make_pair(v, static_cast (*current_))]; + } + + private: + // remove this ugly hack + void set_end() { + current_ = end_; + } }; - - /** *@brief Iterator on the edges of a simplicial complex. * */ template -class Edge_iterator : -public boost::iterator_facade < Edge_iterator +class Edge_iterator : public boost::iterator_facade , typename SkeletonBlockerComplex::Edge_handle const , boost::forward_traversal_tag -, typename SkeletonBlockerComplex::Edge_handle const -> - -{ - friend class boost::iterator_core_access; -public: - typedef SkeletonBlockerComplex Complex; - typedef typename Complex::boost_edge_iterator boost_edge_iterator; - typedef typename Complex::Edge_handle Edge_handle; - - - const Complex* complex; - std::pair edge_iterator ; - - Edge_iterator():complex(NULL){ - } - - Edge_iterator(const SkeletonBlockerComplex* complex_): - complex(complex_), - edge_iterator(boost::edges(complex_->skeleton)) - { - } - - /** - * return an iterator to the end - */ - Edge_iterator(const SkeletonBlockerComplex* complex_,int end): - complex(complex_), - edge_iterator(boost::edges(complex_->skeleton)) - { - edge_iterator.first = edge_iterator.second; - } - - - bool equal(const Edge_iterator& other) const{ - return (complex == other.complex) && (edge_iterator == other.edge_iterator); - } - - void increment(){ - if(edge_iterator.first != edge_iterator.second){ - ++(edge_iterator.first); - } - } - - Edge_handle dereference() const{ - return(*(edge_iterator.first)); - } +, typename SkeletonBlockerComplex::Edge_handle const> { + friend class boost::iterator_core_access; + + public: + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::boost_edge_iterator boost_edge_iterator; + typedef typename Complex::Edge_handle Edge_handle; + + const Complex* complex; + std::pair edge_iterator; + + Edge_iterator() : complex(NULL) { } + + Edge_iterator(const SkeletonBlockerComplex* complex_) : + complex(complex_), + edge_iterator(boost::edges(complex_->skeleton)) { } + + /** + * return an iterator to the end + */ + Edge_iterator(const SkeletonBlockerComplex* complex_, int end) : + complex(complex_), + edge_iterator(boost::edges(complex_->skeleton)) { + edge_iterator.first = edge_iterator.second; + } + + bool equal(const Edge_iterator& other) const { + return (complex == other.complex) && (edge_iterator == other.edge_iterator); + } + + void increment() { + if (edge_iterator.first != edge_iterator.second) { + ++(edge_iterator.first); + } + } + + Edge_handle dereference() const { + return (*(edge_iterator.first)); + } }; +} // namespace skbl +} // namespace Gudhi -} - -} // namespace GUDHI - - -#endif /* GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ */ - - +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h index 20a94734..cc3ed276 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h @@ -19,17 +19,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef GUDHI_SKELETON_BLOCKERS_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_ITERATORS_H_ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_ITERATORS_H_ -#include "Skeleton_blockers_vertices_iterators.h" -#include "Skeleton_blockers_edges_iterators.h" -#include "Skeleton_blockers_blockers_iterators.h" -#include "Skeleton_blockers_triangles_iterators.h" -#include "Skeleton_blockers_simplices_iterators.h" +#include +#include +#include +#include +#include - - - -#endif /* GUDHI_SKELETON_BLOCKERS_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h index f9d4d072..4d71b3f5 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h @@ -19,20 +19,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ -#include "boost/iterator/iterator_facade.hpp" +#include +#include +#include +#include + +#include #include #include #include -#include "gudhi/Skeleton_blocker_link_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h" -#include "gudhi/Skeleton_blocker/internal/Trie.h" -#include "gudhi/Utils.h" - namespace Gudhi { namespace skbl { @@ -68,7 +68,7 @@ public boost::iterator_facade < Simplex_around_vertex_iterator link_v; std::shared_ptr trie; - std::list nodes_to_be_seen; // todo deque + std::list nodes_to_be_seen; // todo deque public: Simplex_around_vertex_iterator() : complex(0) {} @@ -159,7 +159,7 @@ public boost::iterator_facade < Simplex_around_vertex_iteratorchilds) { nodes_to_be_seen.push_back(childs.get()); } - } Simplex_handle dereference() const { @@ -309,4 +308,4 @@ public boost::iterator_facade < Simplex_iterator } // namespace Gudhi -#endif // GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h index e137d1ea..28f5805d 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h @@ -1,117 +1,108 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef GUDHI_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ - -#include "boost/iterator/iterator_facade.hpp" +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ + +#include #include -namespace Gudhi{ +namespace Gudhi { namespace skbl { -////////////////////////////////////////////////////////////////////// /** * \brief Iterator over the triangles that are * adjacent to a vertex of the simplicial complex. * \remark Will be removed soon -> dont look */ -template +template class Triangle_around_vertex_iterator : public boost::iterator_facade -< Triangle_around_vertex_iterator +< Triangle_around_vertex_iterator , typename Complex::Simplex_handle const , boost::forward_traversal_tag -, typename Complex::Simplex_handle const -> -{ - friend class boost::iterator_core_access; - template friend class Triangle_iterator; -private: - typedef typename LinkType::Vertex_handle Vertex_handle; - typedef typename LinkType::Root_vertex_handle Root_vertex_handle; - typedef typename LinkType::Simplex_handle Simplex_handle; - typedef typename Complex::Complex_edge_iterator Complex_edge_iterator_; - - const Complex* complex_; - Vertex_handle v_; - std::shared_ptr link_; - Complex_edge_iterator_ current_edge_; - bool is_end_; -public: - Triangle_around_vertex_iterator(const Complex* complex,Vertex_handle v): - complex_(complex),v_(v),link_(new LinkType(*complex,v_)), - current_edge_(link_->edge_range().begin()), - is_end_(current_edge_ == link_->edge_range().end()){ - } - - /** - * @brief ugly hack to get an iterator to the end - */ - Triangle_around_vertex_iterator(const Complex* complex,Vertex_handle v,bool is_end): - complex_(complex),v_(v),link_(0),is_end_(true){ - } - - /** - * @brief ugly hack to get an iterator to the end - */ - Triangle_around_vertex_iterator(): - complex_(0),v_(-1),link_(0),is_end_(true){ - } - - - Triangle_around_vertex_iterator(const Triangle_around_vertex_iterator& other){ - v_ = other.v_; - complex_ = other.complex_; - is_end_ = other.is_end_; - - if(!is_end_){ - link_ = other.link_; - current_edge_= other.current_edge_; - } - } - - bool equal(const Triangle_around_vertex_iterator& other) const{ - return (complex_==other.complex_) && ((finished() &&other.finished()) || current_edge_ == other.current_edge_); - } - - Simplex_handle dereference() const{ - Root_vertex_handle v1 = (*link_)[*current_edge_].first(); - Root_vertex_handle v2 = (*link_)[*current_edge_].second(); - return Simplex_handle(v_,*(complex_->get_address(v1)),*(complex_->get_address(v2))); - } - - void increment(){ - ++current_edge_; - } - -private: - bool finished() const{ - return is_end_ || (current_edge_ == link_->edge_range().end()); - } - +, typename Complex::Simplex_handle const> { + friend class boost::iterator_core_access; + template friend class Triangle_iterator; + private: + typedef typename LinkType::Vertex_handle Vertex_handle; + typedef typename LinkType::Root_vertex_handle Root_vertex_handle; + typedef typename LinkType::Simplex_handle Simplex_handle; + typedef typename Complex::Complex_edge_iterator Complex_edge_iterator_; + + const Complex* complex_; + Vertex_handle v_; + std::shared_ptr link_; + Complex_edge_iterator_ current_edge_; + bool is_end_; + + public: + Triangle_around_vertex_iterator(const Complex* complex, Vertex_handle v) : + complex_(complex), v_(v), link_(new LinkType(*complex, v_)), + current_edge_(link_->edge_range().begin()), + is_end_(current_edge_ == link_->edge_range().end()) { } + + /** + * @brief ugly hack to get an iterator to the end + */ + Triangle_around_vertex_iterator(const Complex* complex, Vertex_handle v, bool is_end) : + complex_(complex), v_(v), link_(0), is_end_(true) { } + + /** + * @brief ugly hack to get an iterator to the end + */ + Triangle_around_vertex_iterator() : + complex_(0), v_(-1), link_(0), is_end_(true) { } + + Triangle_around_vertex_iterator(const Triangle_around_vertex_iterator& other) { + v_ = other.v_; + complex_ = other.complex_; + is_end_ = other.is_end_; + + if (!is_end_) { + link_ = other.link_; + current_edge_ = other.current_edge_; + } + } + + bool equal(const Triangle_around_vertex_iterator& other) const { + return (complex_ == other.complex_) && ((finished() && other.finished()) || current_edge_ == other.current_edge_); + } + + Simplex_handle dereference() const { + Root_vertex_handle v1 = (*link_)[*current_edge_].first(); + Root_vertex_handle v2 = (*link_)[*current_edge_].second(); + return Simplex_handle(v_, *(complex_->get_address(v1)), *(complex_->get_address(v2))); + } + + void increment() { + ++current_edge_; + } + + private: + bool finished() const { + return is_end_ || (current_edge_ == link_->edge_range().end()); + } }; - - /** * \brief Iterator over the triangles of the * simplicial complex. @@ -119,121 +110,111 @@ private: * */ template -class Triangle_iterator : - public boost::iterator_facade< - Triangle_iterator , - typename SkeletonBlockerComplex::Simplex_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Simplex_handle const - > -{ - friend class boost::iterator_core_access; -private: - typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; - typedef typename SkeletonBlockerComplex::Root_vertex_handle Root_vertex_handle; - typedef typename SkeletonBlockerComplex::Simplex_handle Simplex_handle; - typedef typename SkeletonBlockerComplex::Superior_triangle_around_vertex_iterator STAVI; - typedef typename SkeletonBlockerComplex::Complex_vertex_iterator Complex_vertex_iterator; - - const SkeletonBlockerComplex* complex_; - Complex_vertex_iterator current_vertex_; - STAVI current_triangle_; - bool is_end_; -public: - - /* - * @remark assume that the complex is non-empty - */ - Triangle_iterator(const SkeletonBlockerComplex* complex): - complex_(complex), - current_vertex_(complex->vertex_range().begin()), - current_triangle_(complex,*current_vertex_), // xxx this line is problematic is the complex is empty - is_end_(false){ - - assert(!complex->empty()); - gotoFirstTriangle(); - } - -private: - //goto to the first triangle or to the end if none - void gotoFirstTriangle(){ - if(!is_finished() && current_triangle_.finished()){ - goto_next_vertex(); - } - } -public: - - /** - * @brief ugly hack to get an iterator to the end - * @remark assume that the complex is non-empty - */ - Triangle_iterator(const SkeletonBlockerComplex* complex,bool is_end): - complex_(complex), - current_vertex_(complex->vertex_range().end()), - current_triangle_(), // xxx this line is problematic is the complex is empty - is_end_(true){ - } - - - Triangle_iterator& operator=(const Triangle_iterator & other){ - complex_ = other.complex_; - Complex_vertex_iterator current_vertex_; - STAVI current_triangle_; - return *this; - } - - - bool equal(const Triangle_iterator& other) const{ - bool both_are_finished = is_finished() && other.is_finished(); - bool both_arent_finished = !is_finished() && !other.is_finished(); - // if the two iterators are not finished, they must have the same state - return (complex_==other.complex_) && - (both_are_finished || - ( (both_arent_finished) && current_vertex_ == other.current_vertex_ && current_triangle_ == other.current_triangle_)); - - } - - Simplex_handle dereference() const{ - return *current_triangle_; - } - -private: - - // goto the next vertex that has a triangle pending or the - // end vertex iterator if none exists - void goto_next_vertex(){ - assert(current_triangle_.finished()); //we mush have consume all triangles passing through the vertex - assert(!is_finished()); // we must not be done - - ++current_vertex_; - - if(!is_finished()){ - current_triangle_ = STAVI(complex_, *current_vertex_); - if(current_triangle_.finished()) - goto_next_vertex(); - } - } -public: - void increment(){ - if(!current_triangle_.finished()){ - ++current_triangle_; // problem here - if(current_triangle_.finished()) - goto_next_vertex(); - } - else{ - assert(!is_finished()); - goto_next_vertex(); - } - } - -private: - bool is_finished() const{ - return is_end_ || current_vertex_ == complex_->vertex_range().end(); - } +class Triangle_iterator : public boost::iterator_facade< +Triangle_iterator , +typename SkeletonBlockerComplex::Simplex_handle const +, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Simplex_handle const> { + friend class boost::iterator_core_access; + private: + typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; + typedef typename SkeletonBlockerComplex::Root_vertex_handle Root_vertex_handle; + typedef typename SkeletonBlockerComplex::Simplex_handle Simplex_handle; + typedef typename SkeletonBlockerComplex::Superior_triangle_around_vertex_iterator STAVI; + typedef typename SkeletonBlockerComplex::Complex_vertex_iterator Complex_vertex_iterator; + + const SkeletonBlockerComplex* complex_; + Complex_vertex_iterator current_vertex_; + STAVI current_triangle_; + bool is_end_; + + public: + /* + * @remark assume that the complex is non-empty + */ + Triangle_iterator(const SkeletonBlockerComplex* complex) : + complex_(complex), + current_vertex_(complex->vertex_range().begin()), + current_triangle_(complex, *current_vertex_), // xxx this line is problematic is the complex is empty + is_end_(false) { + assert(!complex->empty()); + gotoFirstTriangle(); + } + + private: + // goto to the first triangle or to the end if none + void gotoFirstTriangle() { + if (!is_finished() && current_triangle_.finished()) { + goto_next_vertex(); + } + } + + public: + /** + * @brief ugly hack to get an iterator to the end + * @remark assume that the complex is non-empty + */ + Triangle_iterator(const SkeletonBlockerComplex* complex, bool is_end) : + complex_(complex), + current_vertex_(complex->vertex_range().end()), + current_triangle_(), // xxx this line is problematic is the complex is empty + is_end_(true) { } + + Triangle_iterator& operator=(const Triangle_iterator & other) { + complex_ = other.complex_; + Complex_vertex_iterator current_vertex_; + STAVI current_triangle_; + return *this; + } + + bool equal(const Triangle_iterator& other) const { + bool both_are_finished = is_finished() && other.is_finished(); + bool both_arent_finished = !is_finished() && !other.is_finished(); + // if the two iterators are not finished, they must have the same state + return (complex_ == other.complex_) && (both_are_finished || ((both_arent_finished) && + current_vertex_ == other.current_vertex_ && current_triangle_ == other.current_triangle_)); + } + + Simplex_handle dereference() const { + return *current_triangle_; + } + + private: + // goto the next vertex that has a triangle pending or the + // end vertex iterator if none exists + void goto_next_vertex() { + assert(current_triangle_.finished()); // we mush have consume all triangles passing through the vertex + assert(!is_finished()); // we must not be done + + ++current_vertex_; + + if (!is_finished()) { + current_triangle_ = STAVI(complex_, *current_vertex_); + if (current_triangle_.finished()) + goto_next_vertex(); + } + } + + public: + void increment() { + if (!current_triangle_.finished()) { + ++current_triangle_; // problem here + if (current_triangle_.finished()) + goto_next_vertex(); + } else { + assert(!is_finished()); + goto_next_vertex(); + } + } + + private: + bool is_finished() const { + return is_end_ || current_vertex_ == complex_->vertex_range().end(); + } }; -} +} // namespace skbl -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h index a9d4e373..14ae136a 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h @@ -1,31 +1,32 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ - -#include "boost/iterator/iterator_facade.hpp" - - -namespace Gudhi{ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ + +#include + +#include // for pair<> + +namespace Gudhi { namespace skbl { @@ -35,148 +36,137 @@ namespace skbl { *@remark Incrementation increases Vertex_handle. */ template -class Vertex_iterator : public boost::iterator_facade -< Vertex_iterator - , typename SkeletonBlockerComplex::Vertex_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Vertex_handle const - > -{ - friend class boost::iterator_core_access; - - typedef typename SkeletonBlockerComplex::boost_vertex_iterator boost_vertex_iterator; - typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; -private: - const SkeletonBlockerComplex* complex; - std::pair vertexIterator; - - -public: - Vertex_iterator():complex(NULL){ - } - - Vertex_iterator(const SkeletonBlockerComplex* complex_): - complex(complex_), - vertexIterator(vertices(complex_->skeleton)){ - if(!finished() && !is_active()) { - goto_next_valid(); - } - } - - /** - * return an iterator to the end. - */ - Vertex_iterator(const SkeletonBlockerComplex* complex_,int end): - complex(complex_),vertexIterator(vertices(complex_->skeleton)){ - vertexIterator.first = vertexIterator.second ; - } - -public: - void increment () {goto_next_valid();} - Vertex_handle dereference() const { - return(Vertex_handle(*(vertexIterator.first))); - } - - bool equal(const Vertex_iterator& other) const{ - return vertexIterator == other.vertexIterator && complex == other.complex; - } - - bool operator<(const Vertex_iterator& other) const{ - return dereference() +, typename SkeletonBlockerComplex::Vertex_handle const +, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Vertex_handle const> { + friend class boost::iterator_core_access; + + typedef typename SkeletonBlockerComplex::boost_vertex_iterator boost_vertex_iterator; + typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; + private: + const SkeletonBlockerComplex* complex; + std::pair vertexIterator; + + + public: + Vertex_iterator() : complex(NULL) { } + + Vertex_iterator(const SkeletonBlockerComplex* complex_) : + complex(complex_), + vertexIterator(vertices(complex_->skeleton)) { + if (!finished() && !is_active()) { + goto_next_valid(); + } + } + + /** + * return an iterator to the end. + */ + Vertex_iterator(const SkeletonBlockerComplex* complex_, int end) : + complex(complex_), vertexIterator(vertices(complex_->skeleton)) { + vertexIterator.first = vertexIterator.second; + } + + public: + void increment() { + goto_next_valid(); + } + + Vertex_handle dereference() const { + return (Vertex_handle(*(vertexIterator.first))); + } + + bool equal(const Vertex_iterator& other) const { + return vertexIterator == other.vertexIterator && complex == other.complex; + } + + bool operator<(const Vertex_iterator& other) const { + return dereference() < other.dereference(); + } + + private: + bool finished() const { + return vertexIterator.first == vertexIterator.second; + } + + void goto_next_valid() { + ++vertexIterator.first; + if (!finished() && !is_active()) { + goto_next_valid(); + } + } + + bool is_active() const { + return ((*complex)[Vertex_handle(*vertexIterator.first)]).is_active(); + } }; - - - template -class Neighbors_vertices_iterator -: public boost::iterator_facade < Neighbors_vertices_iterator - , typename SkeletonBlockerComplex::Vertex_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Vertex_handle const - > -{ - friend class boost::iterator_core_access; - - typedef SkeletonBlockerComplex Complex; - typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; - typedef typename Complex::Vertex_handle Vertex_handle; - typedef typename Complex::Edge_handle Edge_handle; - -private: - - const Complex* complex; - Vertex_handle v; - - boost_adjacency_iterator current_; - boost_adjacency_iterator end_; - -public: - // boost_adjacency_iterator ai, ai_end; - // for (tie(ai, ai_end) = adjacent_vertices(v.vertex, skeleton); ai != ai_end; ++ai){ - - Neighbors_vertices_iterator():complex(NULL){ - } - - Neighbors_vertices_iterator(const Complex* complex_,Vertex_handle v_): - complex(complex_), - v(v_){ - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - } - - /** - * returns an iterator to the end - */ - Neighbors_vertices_iterator(const Complex* complex_,Vertex_handle v_,int end): - complex(complex_), - v(v_){ - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - set_end(); - } - - - void increment () { - if(current_ != end_) - ++current_; - } - - Vertex_handle dereference() const { - return(Vertex_handle(*current_)); - } - - bool equal(const Neighbors_vertices_iterator& other) const{ - return (complex== other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); - } - -private: - //todo remove this ugly hack - void set_end(){ - current_ = end_; - } +class Neighbors_vertices_iterator: public boost::iterator_facade < Neighbors_vertices_iterator +, typename SkeletonBlockerComplex::Vertex_handle const +, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Vertex_handle const> { + friend class boost::iterator_core_access; + + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; + typedef typename Complex::Vertex_handle Vertex_handle; + typedef typename Complex::Edge_handle Edge_handle; + + private: + const Complex* complex; + Vertex_handle v; + + boost_adjacency_iterator current_; + boost_adjacency_iterator end_; + + public: + // boost_adjacency_iterator ai, ai_end; + // for (tie(ai, ai_end) = adjacent_vertices(v.vertex, skeleton); ai != ai_end; ++ai) { + + Neighbors_vertices_iterator() : complex(NULL) { } + + Neighbors_vertices_iterator(const Complex* complex_, Vertex_handle v_) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + } + + /** + * returns an iterator to the end + */ + Neighbors_vertices_iterator(const Complex* complex_, Vertex_handle v_, int end) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + set_end(); + } + + void increment() { + if (current_ != end_) + ++current_; + } + + Vertex_handle dereference() const { + return (Vertex_handle(*current_)); + } + + bool equal(const Neighbors_vertices_iterator& other) const { + return (complex == other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); + } + + private: + // todo remove this ugly hack + void set_end() { + current_ = end_; + } }; -} +} // namespace skbl -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index 700830f2..07f371a2 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -20,8 +20,20 @@ * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_COMPLEX_H_ +#define SKELETON_BLOCKER_COMPLEX_H_ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include #include #include @@ -40,18 +52,6 @@ #include #include -#include "gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h" -#include "gudhi/Skeleton_blocker_link_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h" - -#include "gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h" -#include "gudhi/Skeleton_blocker/internal/Top_faces.h" -#include "gudhi/Skeleton_blocker/internal/Trie.h" - -#include "gudhi/Utils.h" - namespace Gudhi { namespace skbl { @@ -1406,7 +1406,8 @@ class Skeleton_blocker_complex { Const_complex_blocker_around_vertex_iterator; typedef boost::iterator_range Complex_blocker_around_vertex_range; - typedef boost::iterator_range Const_complex_blocker_around_vertex_range; + typedef boost::iterator_range + Const_complex_blocker_around_vertex_range; public: /** @@ -1514,7 +1515,7 @@ class Skeleton_blocker_complex { * return the total number of simplices */ template -Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, +Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, bool is_flag_complex = false) { typedef typename Complex::Simplex_handle Simplex_handle; std::vector simplices; @@ -1531,6 +1532,4 @@ Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, Simplex #include "Skeleton_blocker_simplifiable_complex.h" - -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_COMPLEX_H_ - +#endif // SKELETON_BLOCKER_COMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h index 3eff1ba3..b8395251 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h @@ -19,12 +19,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ +#define SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ -#include "gudhi/Utils.h" -#include "gudhi/Skeleton_blocker_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h" +#include +#include +#include namespace Gudhi { @@ -221,4 +221,4 @@ SkeletonBlockerGeometricComplex make_complex_from_top_faces( } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ +#endif // SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h index 725ecce5..95d8fa97 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h @@ -19,11 +19,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_LINK_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_LINK_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_LINK_COMPLEX_H_ +#define SKELETON_BLOCKER_LINK_COMPLEX_H_ -#include "gudhi/Utils.h" -#include "gudhi/Skeleton_blocker_complex.h" +#include +#include namespace Gudhi { @@ -297,4 +297,4 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_LINK_COMPLEX_H_ +#endif // SKELETON_BLOCKER_LINK_COMPLEX_H_ 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 57e1daf0..705c78bb 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -19,14 +19,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#define SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ #include #include #include -#include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h" +#include namespace Gudhi { @@ -447,4 +447,4 @@ Skeleton_blocker_complex::notify_changed_edges(Vertex_handle } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#endif // SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index b824e0d4..e05714c7 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -23,10 +23,16 @@ #ifndef READER_UTILS_H_ #define READER_UTILS_H_ +#include + +#include + #include #include -#include -#include "gudhi/graph_simplicial_complex.h" +#include +#include // for numeric_limits<> +#include +#include /** * \brief Read a set of points to turn it -- cgit v1.2.3 From 17d191b4990aa182c7e2c9daa53e513e3ebc045f Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 5 Oct 2015 17:38:35 +0000 Subject: No need for Persistent_cohomology_column to have everything private. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@828 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9eea246613f29f78d88e8f1b25cf341c05e5098c --- .../include/gudhi/Persistent_cohomology.h | 4 ++-- .../Persistent_cohomology/Persistent_cohomology_column.h | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 5f399f1a..8c614e96 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -524,8 +524,8 @@ class Persistent_cohomology { Arith_element charac) { Simplex_key key = cpx_->key(sigma); // Create a column containing only one cell, - Column * new_col = column_pool_.construct(Column(key)); - Cell * new_cell = cell_pool_.construct(Cell(key, x, new_col)); + Column * new_col = column_pool_.construct(key); + Cell * new_cell = cell_pool_.construct(key, x, new_col); new_col->col_.push_back(*new_cell); // and insert it in the matrix, in constant time thanks to the hint cam_.end(). // Indeed *new_col has the biggest lexicographic value because key is the diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h index 5d48969d..568f24df 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h @@ -80,13 +80,15 @@ class Persistent_cohomology_cell : public base_hook_cam_h, * The non-zero coefficients of the column are stored in a * boost::intrusive::list. Contains a hook to be stored in a * boost::intrusive::set. + * + * Movable but not Copyable. */ template class Persistent_cohomology_column : public boost::intrusive::set_base_hook< boost::intrusive::link_mode > { - private: template friend class Persistent_cohomology; + public: typedef Persistent_cohomology_cell Cell; typedef boost::intrusive::list, @@ -96,13 +98,6 @@ class Persistent_cohomology_column : public boost::intrusive::set_base_hook< explicit Persistent_cohomology_column(SimplexKey key) : col_(), class_key_(key) {} - public: - /** Copy constructor.*/ - Persistent_cohomology_column(Persistent_cohomology_column const &other) - : col_(), - class_key_(other.class_key_) { - assert(other.col_.empty()); - } /** \brief Returns true iff the column is null.*/ bool is_null() const { -- cgit v1.2.3 From 58e633f51ffa06aa219231cd1c08eab59457a12f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 8 Oct 2015 15:24:27 +0000 Subject: Fix cpplint on examples. Bug fix on persistence_from_simple_simplex_tree. Add persistence examples tests. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@843 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9b7b73abb4a5d6bb110376deb689247bfdae035c --- src/Contraction/example/Garland_heckbert.cpp | 36 ++- .../example/Garland_heckbert/Error_quadric.h | 324 +++++++++++---------- src/Contraction/example/Rips_contraction.cpp | 99 ++++--- src/Persistent_cohomology/example/CMakeLists.txt | 1 + .../example/alpha_shapes_persistence.cpp | 230 +++++++-------- .../example/performance_rips_persistence.cpp | 168 +++++------ .../example/persistence_from_file.cpp | 239 +++++++-------- .../persistence_from_simple_simplex_tree.cpp | 135 ++++----- .../example/rips_multifield_persistence.cpp | 234 +++++++-------- .../example/rips_persistence.cpp | 222 +++++++------- src/Skeleton_blocker/example/CMakeLists.txt | 6 +- .../example/Skeleton_blocker_from_simplices.cpp | 112 ++++--- .../example/Skeleton_blocker_iteration.cpp | 131 +++++---- .../example/Skeleton_blocker_link.cpp | 92 +++--- .../Skeleton_blocker_simple_traits.h | 2 +- 15 files changed, 1008 insertions(+), 1023 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index a41f65aa..70f29b6a 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -1,7 +1,4 @@ -/* - * Garland_heckbert.h - * Created on: Feb 10, 2015 - * This file is part of the Gudhi Library. The Gudhi library +/* This file is part of the Gudhi Library. The Gudhi library * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * @@ -28,12 +25,13 @@ #ifndef GARLAND_HECKBERT_H_ #define GARLAND_HECKBERT_H_ +#include +#include +#include +#include + #include #include -#include "gudhi/Point.h" -#include "gudhi/Edge_contraction.h" -#include "gudhi/Skeleton_blocker.h" -#include "gudhi/Off_reader.h" #include "Garland_heckbert/Error_quadric.h" @@ -51,7 +49,6 @@ struct Geometry_trait { */ struct Garland_heckbert_traits : public Skeleton_blocker_simple_geometric_traits { public: - struct Garland_heckbert_vertex : public Simple_geometric_vertex { Error_quadric quadric; }; @@ -68,6 +65,7 @@ typedef Skeleton_blocker_contractor Complex_contractor; */ class GH_placement : public Gudhi::contraction::Placement_policy { Complex& complex_; + public: typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; @@ -91,8 +89,8 @@ class GH_placement : public Gudhi::contraction::Placement_policy { */ class GH_cost : public Gudhi::contraction::Cost_policy { Complex& complex_; - public: + public: typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; GH_cost(Complex& complex) : complex_(complex) { } @@ -115,13 +113,13 @@ class GH_cost : public Gudhi::contraction::Cost_policy { */ class GH_visitor : public Gudhi::contraction::Contraction_visitor { Complex& complex_; - public: + public: GH_visitor(Complex& complex) : complex_(complex) { } - //Compute quadrics for every vertex v - //The quadric of v consists in the sum of quadric - //of every triangles passing through v weighted by its area + // Compute quadrics for every vertex v + // The quadric of v consists in the sum of quadric + // of every triangles passing through v weighted by its area void on_started(Complex & complex) override { for (auto v : complex.vertex_range()) { @@ -147,7 +145,8 @@ 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; } @@ -172,8 +171,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); @@ -183,7 +181,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; @@ -191,4 +189,4 @@ int main(int argc, char *argv[]) { -#endif /* GARLAND_HECKBERT_H_ */ +#endif // GARLAND_HECKBERT_H_ diff --git a/src/Contraction/example/Garland_heckbert/Error_quadric.h b/src/Contraction/example/Garland_heckbert/Error_quadric.h index 72134c9d..a033aa00 100644 --- a/src/Contraction/example/Garland_heckbert/Error_quadric.h +++ b/src/Contraction/example/Garland_heckbert/Error_quadric.h @@ -1,164 +1,182 @@ -/* - * Error_quadric.h +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: 24 janv. 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-M�diterran�e (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * */ #ifndef ERROR_QUADRIC_H_ #define ERROR_QUADRIC_H_ -#include -#include #include +#include +#include -template class Error_quadric{ -private : - double coeff[10]; - -public : - Error_quadric(){ - clear(); - } - - /** - * Quadric corresponding to the L2 distance to the plane. - * - * According to the notation of Garland Heckbert, they - * denote a quadric symetric matrix as : - * Q = [ q11 q12 q13 q14] - * [ q12 q22 q23 q24] - * [ q13 q23 q33 q34] - * [ q14 q24 q34 q44] - * - * which is represented by a vector with 10 elts that - * are denoted ci for clarity with : - * Q = [ c0 c1 c2 c3 ] - * [ c1 c4 c5 c6 ] - * [ c2 c5 c7 c8 ] - * [ c3 c6 c8 c9 ] - * - * The constructor return the quadrics that represents - * the squared distance to the plane defined by triangle p0,p1,p2 - * times the area of triangle p0,p1,p2. - */ - Error_quadric(const Point & p0,const Point & p1,const Point & p2){ - - Point normal(unit_normal(p0,p1,p2)); - double a=normal[0]; - double b=normal[1]; - double c=normal[2]; - double d= -a*p0[0]-b*p0[1]-c*p0[2]; - coeff[0] = a*a ; - coeff[1] = a*b ; - coeff[2] = a*c ; - coeff[3] = a*d ; - coeff[4] = b*b ; - coeff[5] = b*c ; - coeff[6] = b*d ; - coeff[7] = c*c ; - coeff[8] = c*d ; - coeff[9] = d*d ; - - double area_p0p1p2 = std::sqrt(squared_area(p0,p1,p2)); - for(auto& x : coeff) - x*= area_p0p1p2; - } - - - inline double squared_area(const Point& p0,const Point& p1,const Point& p2) { - //if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 - //then the squared area is = (u^2+v^2+w^2)/4 - //with: u = x2 * y3 - x3 * y2; - // v = x3 * y1 - x1 * y3; - // w = x1 * y2 - x2 * y1; - Point p0p1(p1-p0); - Point p0p2(p2-p0); - double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; - double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; - double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; - return 1./4. * (A*A+B*B+C*C); - } - - - void clear(){ - for(auto& x:coeff) - x=0; - } - - Error_quadric& operator+=(const Error_quadric& other){ - if(this!=&other) - for(int i = 0 ; i < 10; ++i) - coeff[i] += other.coeff[i]; - return *this; - } - - /** - * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert - */ - inline double cost(const Point& point) const{ - double cost = - coeff[0]*point.x()*point.x()+coeff[4]*point.y()*point.y()+coeff[7]*point.z()*point.z() - +2*(coeff[1]*point.x()*point.y()+coeff[5]*point.y()*point.z()+coeff[2]*point.z()*point.x()) - +2*(coeff[3]*point.x()+coeff[6]*point.y()+coeff[8]*point.z()) - +coeff[9]; - if(cost<0) return 0; - else { - return cost; - } - } - - inline double grad_determinant() const{ - return - coeff[0] * coeff[4] * coeff[7] - - coeff[0] * coeff[5] * coeff[5] - - coeff[1] * coeff[1] * coeff[7] - +2*coeff[1] * coeff[5] * coeff[2] - - coeff[4] * coeff[2] * coeff[2]; - } - - /** - * Return the point such that it minimizes the gradient of the quadric. - * Det must be passed with the determinant value of the gradient (should be non zero). - */ - inline Point solve_linear_gradient(double det) const{ - return Point({ - (-coeff[1]*coeff[5]*coeff[8]+coeff[1]*coeff[7]*coeff[6]+coeff[2]*coeff[8]*coeff[4]-coeff[2]*coeff[5]*coeff[6]-coeff[3]*coeff[4]*coeff[7]+coeff[3]*coeff[5]*coeff[5])/ det, - (coeff[0]*coeff[5]*coeff[8]-coeff[0]*coeff[7]*coeff[6]-coeff[5]*coeff[2]*coeff[3]-coeff[1]*coeff[2]*coeff[8]+coeff[6]*coeff[2]*coeff[2]+coeff[1]*coeff[3]*coeff[7])/det, - (-coeff[8]*coeff[0]*coeff[4]+coeff[8]*coeff[1]*coeff[1]+coeff[2]*coeff[3]*coeff[4]+coeff[5]*coeff[0]*coeff[6]-coeff[5]*coeff[1]*coeff[3]-coeff[1]*coeff[2]*coeff[6])/det - }); - } - - - /** - * returns the point that minimizes the quadric. - * It inverses the quadric if its determinant is higher that a given threshold . - * If the determinant is lower than this value the returned value is uninitialized. - */ - boost::optional min_cost(double scale=1) const{ - // const double min_determinant = 1e-4 * scale*scale; - const double min_determinant = 1e-5; - boost::optional pt_res; - double det = grad_determinant(); - if (std::abs(det)>min_determinant) - pt_res = solve_linear_gradient(det); - return pt_res; - } - - friend std::ostream& operator<< (std::ostream& stream, const Error_quadric& quadric) { - stream << "\n[ "< class Error_quadric { + private: + double coeff[10]; + + public: + Error_quadric() { + clear(); + } + + /** + * Quadric corresponding to the L2 distance to the plane. + * + * According to the notation of Garland Heckbert, they + * denote a quadric symetric matrix as : + * Q = [ q11 q12 q13 q14] + * [ q12 q22 q23 q24] + * [ q13 q23 q33 q34] + * [ q14 q24 q34 q44] + * + * which is represented by a vector with 10 elts that + * are denoted ci for clarity with : + * Q = [ c0 c1 c2 c3 ] + * [ c1 c4 c5 c6 ] + * [ c2 c5 c7 c8 ] + * [ c3 c6 c8 c9 ] + * + * The constructor return the quadrics that represents + * the squared distance to the plane defined by triangle p0,p1,p2 + * times the area of triangle p0,p1,p2. + */ + Error_quadric(const Point & p0, const Point & p1, const Point & p2) { + Point normal(unit_normal(p0, p1, p2)); + double a = normal[0]; + double b = normal[1]; + double c = normal[2]; + double d = -a * p0[0] - b * p0[1] - c * p0[2]; + coeff[0] = a*a; + coeff[1] = a*b; + coeff[2] = a*c; + coeff[3] = a*d; + coeff[4] = b*b; + coeff[5] = b*c; + coeff[6] = b*d; + coeff[7] = c*c; + coeff[8] = c*d; + coeff[9] = d*d; + + double area_p0p1p2 = std::sqrt(squared_area(p0, p1, p2)); + for (auto& x : coeff) + x *= area_p0p1p2; + } + + inline double squared_area(const Point& p0, const Point& p1, const Point& p2) { + // if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 + // then the squared area is = (u^2+v^2+w^2)/4 + // with: u = x2 * y3 - x3 * y2; + // v = x3 * y1 - x1 * y3; + // w = x1 * y2 - x2 * y1; + Point p0p1(p1 - p0); + Point p0p2(p2 - p0); + double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; + double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; + double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; + return 1. / 4. * (A * A + B * B + C * C); + } + + void clear() { + for (auto& x : coeff) + x = 0; + } + + Error_quadric& operator+=(const Error_quadric& other) { + if (this != &other) { + for (int i = 0; i < 10; ++i) + coeff[i] += other.coeff[i]; + } + return *this; + } + + /** + * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert + */ + inline double cost(const Point& point) const { + double cost = + coeff[0] * point.x() * point.x() + coeff[4] * point.y() * point.y() + coeff[7] * point.z() * point.z() + + 2 * (coeff[1] * point.x() * point.y() + coeff[5] * point.y() * point.z() + coeff[2] * point.z() * point.x()) + + 2 * (coeff[3] * point.x() + coeff[6] * point.y() + coeff[8] * point.z()) + + coeff[9]; + if (cost < 0) { + return 0; + } else { + return cost; + } + } + + inline double grad_determinant() const { + return + coeff[0] * coeff[4] * coeff[7] + - coeff[0] * coeff[5] * coeff[5] + - coeff[1] * coeff[1] * coeff[7] + + 2 * coeff[1] * coeff[5] * coeff[2] + - coeff[4] * coeff[2] * coeff[2]; + } + + /** + * Return the point such that it minimizes the gradient of the quadric. + * Det must be passed with the determinant value of the gradient (should be non zero). + */ + inline Point solve_linear_gradient(double det) const { + return Point({ + (-coeff[1] * coeff[5] * coeff[8] + coeff[1] * coeff[7] * coeff[6] + coeff[2] * coeff[8] * coeff[4] - + coeff[2] * coeff[5] * coeff[6] - coeff[3] * coeff[4] * coeff[7] + coeff[3] * coeff[5] * coeff[5]) + / det, + (coeff[0] * coeff[5] * coeff[8] - coeff[0] * coeff[7] * coeff[6] - coeff[5] * coeff[2] * coeff[3] - + coeff[1] * coeff[2] * coeff[8] + coeff[6] * coeff[2] * coeff[2] + coeff[1] * coeff[3] * coeff[7]) + / det, + (-coeff[8] * coeff[0] * coeff[4] + coeff[8] * coeff[1] * coeff[1] + coeff[2] * coeff[3] * coeff[4] + + coeff[5] * coeff[0] * coeff[6] - coeff[5] * coeff[1] * coeff[3] - coeff[1] * coeff[2] * coeff[6]) + / det + }); + } + + /** + * returns the point that minimizes the quadric. + * It inverses the quadric if its determinant is higher that a given threshold . + * If the determinant is lower than this value the returned value is uninitialized. + */ + boost::optional min_cost(double scale = 1) const { + // const double min_determinant = 1e-4 * scale*scale; + const double min_determinant = 1e-5; + boost::optional pt_res; + double det = grad_determinant(); + if (std::abs(det) > min_determinant) + pt_res = solve_linear_gradient(det); + return pt_res; + } + + friend std::ostream& operator<<(std::ostream& stream, const Error_quadric& quadric) { + stream << "\n[ " << quadric.coeff[0] << "," << quadric.coeff[1] << "," << quadric.coeff[2] << "," << + quadric.coeff[3] << ";\n"; + stream << " " << quadric.coeff[1] << "," << quadric.coeff[4] << "," << quadric.coeff[5] << "," << + quadric.coeff[6] << ";\n"; + stream << " " << quadric.coeff[2] << "," << quadric.coeff[5] << "," << quadric.coeff[7] << "," << + quadric.coeff[8] << ";\n"; + stream << " " << quadric.coeff[3] << "," << quadric.coeff[6] << "," << quadric.coeff[8] << "," << + quadric.coeff[9] << "]"; + return stream; + } }; - - - -#endif /* ERROR_QUADRIC_H_ */ - +#endif // ERROR_QUADRIC_H_ diff --git a/src/Contraction/example/Rips_contraction.cpp b/src/Contraction/example/Rips_contraction.cpp index bd0a8b8c..d21246ed 100644 --- a/src/Contraction/example/Rips_contraction.cpp +++ b/src/Contraction/example/Rips_contraction.cpp @@ -19,24 +19,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include +#include +#include +#include + #include #include -#include "gudhi/Edge_contraction.h" -#include "gudhi/Skeleton_blocker.h" -#include "gudhi/Off_reader.h" -#include "gudhi/Point.h" using namespace std; using namespace Gudhi; using namespace skbl; using namespace contraction; - -struct Geometry_trait{ - typedef Point_d Point; +struct Geometry_trait { + typedef Point_d Point; }; - typedef Geometry_trait::Point Point; typedef Skeleton_blocker_simple_geometric_traits Complex_geometric_traits; typedef Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex; @@ -44,62 +43,62 @@ typedef Edge_profile Profile; typedef Skeleton_blocker_contractor Complex_contractor; template -void build_rips(ComplexType& complex, double offset){ - if (offset<=0) return; - auto vertices = complex.vertex_range(); - 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); - } +void build_rips(ComplexType& complex, double offset) { + if (offset <= 0) return; + auto vertices = complex.vertex_range(); + 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); + } } -int main (int argc, char *argv[]) -{ - if (argc!=3){ - std::cerr << "Usage "< off_reader(argv[1],complex,true); - if(!off_reader.is_valid()){ - std::cerr << "Unable to read file:"< off_reader(argv[1], complex, true); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file:" << argv[1] << std::endl; + return EXIT_FAILURE; + } - std::cout << "Build the Rips complex with "<, - contraction::make_first_vertex_placement(), - contraction::make_link_valid_contraction(), - contraction::make_remove_popable_blockers_visitor()); - contractor.contract_edges(); + Complex_contractor contractor(complex, + new Edge_length_cost, + contraction::make_first_vertex_placement(), + contraction::make_link_valid_contraction(), + contraction::make_remove_popable_blockers_visitor()); + contractor.contract_edges(); - std::cout << "Counting final number of simplices \n"; - unsigned num_simplices = std::distance(complex.simplex_range().begin(),complex.simplex_range().end()); + std::cout << "Counting final number of simplices \n"; + unsigned num_simplices = std::distance(complex.simplex_range().begin(), complex.simplex_range().end()); - std::cout << "Final complex has "<< - complex.num_vertices()<<" vertices, "<< - complex.num_edges()<<" edges, "<< - complex.num_blockers()<<" blockers and "<< - num_simplices<<" simplices"<. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include #include #include @@ -27,36 +32,37 @@ #include #include - -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include +#include +#include +#include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; // Alpha_shape_3 templates type definitions typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef CGAL::Alpha_shape_vertex_base_3 Vb; -typedef CGAL::Alpha_shape_cell_base_3 Fb; -typedef CGAL::Triangulation_data_structure_3 Tds; -typedef CGAL::Delaunay_triangulation_3 Triangulation_3; -typedef CGAL::Alpha_shape_3 Alpha_shape_3; +typedef CGAL::Alpha_shape_vertex_base_3 Vb; +typedef CGAL::Alpha_shape_cell_base_3 Fb; +typedef CGAL::Triangulation_data_structure_3 Tds; +typedef CGAL::Delaunay_triangulation_3 Triangulation_3; +typedef CGAL::Alpha_shape_3 Alpha_shape_3; // From file type definition -typedef Kernel::Point_3 Point_3; +typedef Kernel::Point_3 Point_3; // filtration with alpha values needed type definition typedef Alpha_shape_3::FT Alpha_value_type; -typedef CGAL::Object Object; +typedef CGAL::Object Object; typedef CGAL::Dispatch_output_iterator< - CGAL::cpp11::tuple, - CGAL::cpp11::tuple >, std::back_insert_iterator< std::vector > - > > Dispatch; -typedef Alpha_shape_3::Cell_handle Cell_handle; -typedef Alpha_shape_3::Facet Facet; -typedef Alpha_shape_3::Edge Edge_3; +CGAL::cpp11::tuple, +CGAL::cpp11::tuple >, + std::back_insert_iterator< std::vector > > > Dispatch; +typedef Alpha_shape_3::Cell_handle Cell_handle; +typedef Alpha_shape_3::Facet Facet; +typedef Alpha_shape_3::Edge Edge_3; typedef std::list Vertex_list; // gudhi type definition @@ -65,70 +71,60 @@ typedef std::map Alpha_shape typedef std::pair Alpha_shape_simplex_tree_pair; typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; -//#define DEBUG_TRACES - -Vertex_list from (const Cell_handle& ch) -{ +Vertex_list from(const Cell_handle& ch) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { + for (auto i = 0; i < 4; i++) { #ifdef DEBUG_TRACES std::cout << "from cell[" << i << "]=" << ch->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(ch->vertex(i)); } return the_list; } -Vertex_list from (const Facet& fct) -{ + +Vertex_list from(const Facet& fct) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if (fct.second != i) - { + for (auto i = 0; i < 4; i++) { + if (fct.second != i) { #ifdef DEBUG_TRACES std::cout << "from facet=[" << i << "]" << fct.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(fct.first->vertex(i)); } } return the_list; } -Vertex_list from (const Edge_3& edg) -{ + +Vertex_list from(const Edge_3& edg) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if ((edg.second == i) ||(edg.third == i)) - { + for (auto i = 0; i < 4; i++) { + if ((edg.second == i) || (edg.third == i)) { #ifdef DEBUG_TRACES std::cout << "from edge[" << i << "]=" << edg.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(edg.first->vertex(i)); } } return the_list; } -Vertex_list from (const Alpha_shape_3::Vertex_handle& vh) -{ + +Vertex_list from(const Alpha_shape_3::Vertex_handle& vh) { Vertex_list the_list; #ifdef DEBUG_TRACES std::cout << "from vertex=" << vh->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(vh); return the_list; } -void usage(char * const progName) -{ - std::cerr << "Usage: " << progName << " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); // ----- >> +void usage(char * const progName) { + std::cerr << "Usage: " << progName << + " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; + exit(-1); } -int main (int argc, char * const argv[]) -{ - - int coeff_field_characteristic=0; +int main(int argc, char * const argv[]) { + int coeff_field_characteristic = 0; int returnedScanValue = sscanf(argv[2], "%d", &coeff_field_characteristic); if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { std::cerr << "Error: " << argv[2] << " is not correct\n"; @@ -149,102 +145,96 @@ int main (int argc, char * const argv[]) } // Read points from file - std::string filegraph = argv[1]; + std::string filegraph = argv[1]; std::list lp; std::ifstream is(filegraph.c_str()); int n; is >> n; #ifdef DEBUG_TRACES std::cout << "Reading " << n << " points " << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES Point_3 p; - for( ; n>0 ; n--) { + for (; n > 0; n--) { is >> p; lp.push_back(p); } // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(lp.begin(),lp.end(),0,Alpha_shape_3::GENERAL); + Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); #ifdef DEBUG_TRACES std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES // filtration with alpha values from alpha shape std::vector the_objects; std::vector the_alpha_values; - Dispatch disp = CGAL::dispatch_output( std::back_inserter(the_objects), std::back_inserter(the_alpha_values)); + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); as.filtration_with_alpha_values(disp); #ifdef DEBUG_TRACES std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; // Loop on objects vector Vertex_list vertex_list; Simplex_tree<> simplex_tree; Alpha_shape_simplex_tree_map map_cgal_simplex_tree; std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max=0; - Filtration_value filtration_max=0.0; - for(auto object_iterator: the_objects) - { + int dim_max = 0; + Filtration_value filtration_max = 0.0; + for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle* cell = CGAL::object_cast(&object_iterator)) - { + if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { vertex_list = from(*cell); count_cells++; if (dim_max < 3) { - dim_max=3; // Cell is of dim 3 + // Cell is of dim 3 + dim_max = 3; } - } - else if (const Facet* facet = CGAL::object_cast(&object_iterator)) - { + } else if (const Facet * facet = CGAL::object_cast(&object_iterator)) { vertex_list = from(*facet); count_facets++; if (dim_max < 2) { - dim_max=2; // Facet is of dim 2 + // Facet is of dim 2 + dim_max = 2; } - } - else if (const Edge_3* edge = CGAL::object_cast(&object_iterator)) - { + } else if (const Edge_3 * edge = CGAL::object_cast(&object_iterator)) { vertex_list = from(*edge); count_edges++; if (dim_max < 1) { - dim_max=1; // Edge_3 is of dim 1 + // Edge_3 is of dim 1 + dim_max = 1; } - } - else if (const Alpha_shape_3::Vertex_handle* vertex = CGAL::object_cast(&object_iterator)) - { + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast(&object_iterator)) { count_vertices++; vertex_list = from(*vertex); } // Construction of the vector of simplex_tree vertex from list of alpha_shapes vertex Simplex_tree_vector_vertex the_simplex_tree; - for (auto the_alpha_shape_vertex:vertex_list) - { + for (auto the_alpha_shape_vertex : vertex_list) { Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) - { + if (the_map_iterator == map_cgal_simplex_tree.end()) { // alpha shape not found Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); #ifdef DEBUG_TRACES std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex,vertex)); - } else - { + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { // alpha shape found Simplex_tree_vertex vertex = the_map_iterator->second; #ifdef DEBUG_TRACES std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); } } @@ -252,7 +242,7 @@ int main (int argc, char * const argv[]) Filtration_value filtr = std::sqrt(*the_alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES if (filtr > filtration_max) { filtration_max = filtr; } @@ -267,9 +257,9 @@ int main (int argc, char * const argv[]) #ifdef DEBUG_TRACES std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; std::cout << "Information of the Simplex Tree: " << std::endl; @@ -277,23 +267,25 @@ int main (int argc, char * const argv[]) std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; std::cout << " Dimension = " << simplex_tree.dimension() << " "; std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES #ifdef DEBUG_TRACES std::cout << "Iterator on vertices: " << std::endl; - for( auto vertex : simplex_tree.complex_vertex_range() ) - { std::cout << vertex << " "; } -#endif // DEBUG_TRACES + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh( simplex_tree ); - pcoh.init_coefficients( coeff_field_characteristic ); //initializes the coefficient field for homology + Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); - pcoh.compute_persistent_cohomology( min_persistence ); + pcoh.compute_persistent_cohomology(min_persistence); pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp index 077c2b07..0e912d57 100644 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp @@ -1,49 +1,51 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include "gudhi/Persistent_cohomology/Multi_field.h" -#include "gudhi/Hasse_complex.h" +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include #include +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; /* Compute the persistent homology of the complex cpx with coefficients in Z/pZ. */ template< typename FilteredComplex> -void timing_persistence( FilteredComplex & cpx - , int p ); +void timing_persistence(FilteredComplex & cpx + , int p); /* Compute multi-field persistent homology of the complex cpx with coefficients in * Z/rZ for all prime number r in [p;q].*/ template< typename FilteredComplex> -void timing_persistence( FilteredComplex & cpx - , int p - , int q ); +void timing_persistence(FilteredComplex & cpx + , int p + , int q); /* Timings for the computation of persistent homology with different * representations of a Rips complex and different coefficient fields. The @@ -59,111 +61,111 @@ void timing_persistence( FilteredComplex & cpx * We present also timings for the computation of multi-field persistent * homology in all fields Z/rZ for r prime between 2 and 1223. */ -int main (int argc, char * argv[]) -{ +int main(int argc, char * argv[]) { std::chrono::time_point start, end; int enlapsed_sec; - std::string filepoints = "../examples/Kl.txt"; - Filtration_value threshold = 0.3; - int dim_max = 3; - int p = 2; - int q = 1223; + std::string filepoints = "../examples/Kl.txt"; + Filtration_value threshold = 0.3; + int dim_max = 3; + int p = 2; + int q = 1223; -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points + // Compute the proximity graph of the points start = std::chrono::system_clock::now(); - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips graph in " << enlapsed_sec << " sec.\n"; -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; start = std::chrono::system_clock::now(); - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips complex in " << enlapsed_sec << " sec.\n"; std::cout << " - dimension = " << st.dimension() << std::endl; std::cout << " - number of simplices = " << st.num_simplices() << std::endl; -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration start = std::chrono::system_clock::now(); st.initialize_filtration(); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Order the simplices of the filtration in " << enlapsed_sec << " sec.\n"; -// Convert the simplex tree into a hasse diagram + // Convert the simplex tree into a hasse diagram start = std::chrono::system_clock::now(); Hasse_complex<> hcpx(st); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Convert the simplex tree into a Hasse diagram in " << enlapsed_sec << " sec.\n"; std::cout << "Timings when using a simplex tree: \n"; - timing_persistence(st,p); - timing_persistence(st,q); - timing_persistence(st,p,q); + timing_persistence(st, p); + timing_persistence(st, q); + timing_persistence(st, p, q); std::cout << "Timings when using a Hasse complex: \n"; - timing_persistence(hcpx,p); - timing_persistence(hcpx,q); - timing_persistence(hcpx,p,q); + timing_persistence(hcpx, p); + timing_persistence(hcpx, q); + timing_persistence(hcpx, p, q); return 0; } - template< typename FilteredComplex> void -timing_persistence( FilteredComplex & cpx - , int p ) -{ +timing_persistence(FilteredComplex & cpx + , int p) { std::chrono::time_point start, end; int enlapsed_sec; - Persistent_cohomology< FilteredComplex, Field_Zp > pcoh (cpx); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - + Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + start = std::chrono::system_clock::now(); - - pcoh.compute_persistent_cohomology( INFINITY ); - + + pcoh.compute_persistent_cohomology(INFINITY); + end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); - std::cout << " Compute persistent homology in Z/"<(end - start).count(); + std::cout << " Compute persistent homology in Z/" << p << "Z in " << enlapsed_sec << " sec.\n"; } template< typename FilteredComplex> void -timing_persistence( FilteredComplex & cpx - , int p - , int q ) -{ +timing_persistence(FilteredComplex & cpx + , int p + , int q) { std::chrono::time_point start, end; int enlapsed_sec; - Persistent_cohomology< FilteredComplex, Multi_field > pcoh (cpx); - pcoh.init_coefficients( p, q ); //initilizes the coefficient field for homology + Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p, q); // compute persistent homology, disgarding persistent features of life shorter than min_persistence start = std::chrono::system_clock::now(); - pcoh.compute_persistent_cohomology( INFINITY ); + pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in ["<. - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include #include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; -typedef double Filtration_value; - -void program_options( int argc, char * argv[] - , std::string & simplex_tree_file - , std::string & output_file - , int & p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string simplex_tree_file; - std::string output_file ; - int p ; - Filtration_value min_persistence; - - program_options(argc,argv,simplex_tree_file,output_file,p,min_persistence); - - std::cout << "Simplex_tree from file=" << simplex_tree_file.c_str() << " - output_file=" << output_file.c_str() << std::endl; - std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; - - // Construct the Rips complex in a Simplex Tree - Simplex_tree<> simplex_tree; - - std::ifstream simplex_tree_stream(simplex_tree_file); - simplex_tree_stream >> simplex_tree; - - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << simplex_tree.dimension() << " - filtration " << simplex_tree.filtration() << std::endl; - - /* - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for( auto f_simplex : simplex_tree.filtration_simplex_range() ) - { std::cout << " " << "[" << simplex_tree.filtration(f_simplex) << "] "; - for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) ) - { std::cout << vertex << " "; } - std::cout << std::endl; - }*/ - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh( simplex_tree ); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - - pcoh.compute_persistent_cohomology( min_persistence ); - - // Output the diagram in output_file - if(output_file.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(output_file); - pcoh.output_diagram(out); - out.close(); } +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & simplex_tree_file + , std::string & output_file + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string simplex_tree_file; + std::string output_file; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, simplex_tree_file, output_file, p, min_persistence); + + std::cout << "Simplex_tree from file=" << simplex_tree_file.c_str() << " - output_file=" << output_file.c_str() + << std::endl; + std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; + + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> simplex_tree; + + std::ifstream simplex_tree_stream(simplex_tree_file); + simplex_tree_stream >> simplex_tree; + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << simplex_tree.dimension() << " - filtration " << simplex_tree.filtration() + << std::endl; + + /* + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + for( auto f_simplex : simplex_tree.filtration_simplex_range() ) + { std::cout << " " << "[" << simplex_tree.filtration(f_simplex) << "] "; + for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) ) + { std::cout << vertex << " "; } + std::cout << std::endl; + }*/ + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in output_file + if (output_file.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(output_file); + pcoh.output_diagram(out); + out.close(); + } - return 0; + return 0; } - - -void program_options( int argc, char * argv[] - , std::string & simplex_tree_file - , std::string & output_file - , int & p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & simplex_tree_file + , std::string & output_file + , int & p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&simplex_tree_file), - "Name of file containing a simplex set. Format is one simplex per line (cf. reader_utils.h - read_simplex): Dim1 X11 X12 ... X1d Fil1 "); - + ("input-file", po::value(&simplex_tree_file), + "Name of file containing a simplex set. Format is one simplex per line (cf. reader_utils.h - read_simplex): Dim1 X11 X12 ... X1d Fil1 "); + po::options_description visible("Allowed options", 100); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&output_file)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value(&output_file)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); po::notify(vm); - if (vm.count("help") || !vm.count("input-file")) - { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); } } diff --git a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp index ba82e4e6..ba772f04 100644 --- a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp +++ b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp @@ -20,11 +20,14 @@ * along with this program. If not, see . */ +#include +#include +#include + #include #include -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; @@ -34,15 +37,19 @@ typedef std::pair typeSimplex; typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; typedef Simplex_tree<> typeST; -void usage(char * const progName) -{ +void usage(char * const progName) { std::cerr << "Usage: " << progName << " coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); // ----- >> + exit(-1); } -int main (int argc, char * const argv[]) -{ - int coeff_field_characteristic=0; +int main(int argc, char * const argv[]) { + // program args management + if (argc != 3) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = 0; int returnedScanValue = sscanf(argv[1], "%d", &coeff_field_characteristic); if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { std::cerr << "Error: " << argv[1] << " is not correct\n"; @@ -56,101 +63,65 @@ int main (int argc, char * const argv[]) usage(argv[0]); } - // program args management - if (argc != 3) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF INSERTION" << std::endl; typeST st; // ++ FIRST - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex SimplexVector1; - SimplexVector1.push_back(2); - SimplexVector1.push_back(1); - SimplexVector1.push_back(0); - st.insert_simplex_and_subfaces ( SimplexVector1, 0.3); + std::cout << " - INSERT (0,1,2)" << std::endl; + typeVectorVertex SimplexVector = {0, 1, 2}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); // ++ SECOND std::cout << " - INSERT 3" << std::endl; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(3); - st.insert_simplex_and_subfaces ( SimplexVector2, 0.1); + SimplexVector = {3}; + st.insert_simplex_and_subfaces(SimplexVector, 0.1); // ++ THIRD std::cout << " - INSERT (0,3)" << std::endl; - typeVectorVertex SimplexVector3; - SimplexVector3.push_back(3); - SimplexVector3.push_back(0); - st.insert_simplex_and_subfaces ( SimplexVector3, 0.2); + SimplexVector = {0, 3}; + st.insert_simplex_and_subfaces(SimplexVector, 0.2); // ++ FOURTH - std::cout << " - INSERT (1,0) (already inserted)" << std::endl; - typeVectorVertex SimplexVector4; - SimplexVector4.push_back(1); - SimplexVector4.push_back(0); - st.insert_simplex_and_subfaces ( SimplexVector4, 0.2); + std::cout << " - INSERT (0,1) (already inserted)" << std::endl; + SimplexVector = {0, 1}; + st.insert_simplex_and_subfaces(SimplexVector, 0.2); // ++ FIFTH std::cout << " - INSERT (3,4,5)" << std::endl; - typeVectorVertex SimplexVector5; - SimplexVector5.push_back(3); - SimplexVector5.push_back(4); - SimplexVector5.push_back(5); - st.insert_simplex_and_subfaces ( SimplexVector5, 0.3); + SimplexVector = {3, 4, 5}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); // ++ SIXTH std::cout << " - INSERT (0,1,6,7)" << std::endl; - typeVectorVertex SimplexVector6; - SimplexVector6.push_back(0); - SimplexVector6.push_back(1); - SimplexVector6.push_back(6); - SimplexVector6.push_back(7); - st.insert_simplex_and_subfaces ( SimplexVector6, 0.4); + SimplexVector = {0, 1, 6, 7}; + st.insert_simplex_and_subfaces(SimplexVector, 0.4); // ++ SEVENTH std::cout << " - INSERT (4,5,8,9)" << std::endl; - typeVectorVertex SimplexVector7; - SimplexVector7.push_back(4); - SimplexVector7.push_back(5); - SimplexVector7.push_back(8); - SimplexVector7.push_back(9); - st.insert_simplex_and_subfaces ( SimplexVector7, 0.4); + SimplexVector = {4, 5, 8, 9}; + st.insert_simplex_and_subfaces(SimplexVector, 0.4); // ++ EIGHTH std::cout << " - INSERT (9,10,11)" << std::endl; - typeVectorVertex SimplexVector8; - SimplexVector8.push_back(9); - SimplexVector8.push_back(10); - SimplexVector8.push_back(11); - st.insert_simplex_and_subfaces ( SimplexVector8, 0.3); - + SimplexVector = {9, 10, 11}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); + // ++ NINETH std::cout << " - INSERT (2,10,12)" << std::endl; - typeVectorVertex SimplexVector9; - SimplexVector9.push_back(2); - SimplexVector9.push_back(10); - SimplexVector9.push_back(12); - st.insert_simplex_and_subfaces ( SimplexVector9, 0.3); - + SimplexVector = {2, 10, 12}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); + // ++ TENTH std::cout << " - INSERT (11,6)" << std::endl; - typeVectorVertex SimplexVector10; - SimplexVector10.push_back(11); - SimplexVector10.push_back(6); - st.insert_simplex_and_subfaces ( SimplexVector10, 0.2); + SimplexVector = {6, 11}; + st.insert_simplex_and_subfaces(SimplexVector, 0.2); // ++ ELEVENTH std::cout << " - INSERT (13,14,15)" << std::endl; - typeVectorVertex SimplexVector11; - SimplexVector11.push_back(13); - SimplexVector11.push_back(14); - SimplexVector11.push_back(15); - st.insert_simplex_and_subfaces ( SimplexVector11, 0.25); + SimplexVector = {13, 14, 15}; + st.insert_simplex_and_subfaces(SimplexVector, 0.25); /* Inserted simplex: */ /* 1 6 */ @@ -175,33 +146,31 @@ int main (int argc, char * const argv[]) st.set_dimension(2); st.set_filtration(0.4); - std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " << std::endl; + std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " + << std::endl; std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" + << std::endl; std::cout << "**************************************************************" << std::endl; std::cout << "strict graph G { " << std::endl; - for( auto f_simplex : st.filtration_simplex_range() ) - { + for (auto f_simplex : st.filtration_simplex_range()) { std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - std::cout << (int)vertex << " -- "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << static_cast(vertex) << " -- "; } std::cout << ";" << std::endl; } std::cout << "}" << std::endl; - //std::cout << "**************************************************************" << std::endl; - //st.print_hasse(std::cout); std::cout << "**************************************************************" << std::endl; - // Compute the persistence diagram of the complex persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); - pcoh.init_coefficients( coeff_field_characteristic ); //initiliazes the coefficient field for homology + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); - pcoh.compute_persistent_cohomology( min_persistence ); + pcoh.compute_persistent_cohomology(min_persistence); // Output the diagram in filediag pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index 297a8f98..5277bf7a 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -1,153 +1,157 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include "gudhi/Persistent_cohomology/Multi_field.h" +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include #include +#include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; +typedef int Vertex_handle; typedef double Filtration_value; -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & min_p - , int & max_p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string filepoints; - std::string filediag; +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & min_p + , int & max_p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; Filtration_value threshold; - int dim_max; - int min_p; - int max_p; + int dim_max; + int min_p; + int max_p; Filtration_value min_persistence; - program_options(argc,argv,filepoints,filediag,threshold,dim_max,min_p,max_p,min_persistence); + program_options(argc, argv, filepoints, filediag, threshold, dim_max, min_p, max_p, min_persistence); -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration st.initialize_filtration(); -// Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh( st ); - pcoh.init_coefficients( min_p, max_p ); //initilizes the coefficient field for homology + // Compute the persistence diagram of the complex + Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh(st); + // initializes the coefficient field for homology + pcoh.init_coefficients(min_p, max_p); // compute persistent homology, disgarding persistent features of life shorter than min_persistence - pcoh.compute_persistent_cohomology( min_persistence ); - -// Output the diagram in filediag - if(filediag.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); } + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } return 0; } - - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & min_p - , int & max_p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & min_p + , int & max_p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); - + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); + po::options_description visible("Allowed options"); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", po::value(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("min-field-charac,p", po::value(&min_p)->default_value(2), - "Minimal characteristic p of the coefficient field Z/pZ.") - ("max-field-charac,q", po::value(&max_p)->default_value(1223), - "Minimial characteristic q of the coefficient field Z/pZ.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("min-field-charac,p", po::value(&min_p)->default_value(2), + "Minimal characteristic p of the coefficient field Z/pZ.") + ("max-field-charac,q", po::value(&max_p)->default_value(1223), + "Minimial characteristic q of the coefficient field Z/pZ.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); po::notify(vm); - if (vm.count("help") || !vm.count("input-file")) - { - std::cout << std::endl; - std::cout << "Compute the persistent homology with various coefficient fields \n"; - std::cout << "of a Rips complex defined on a set of input points. The coefficient \n"; - std::cout << "fields are all the Z/rZ for a prime number r contained in the \n"; - std::cout << "specified range [p,q]\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p1*...*pr dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p1*...*pr is the product of prime numbers pi such that the homology \n"; - std::cout << "feature exists in homology with Z/piZ coefficients."<< std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with various coefficient fields \n"; + std::cout << "of a Rips complex defined on a set of input points. The coefficient \n"; + std::cout << "fields are all the Z/rZ for a prime number r contained in the \n"; + std::cout << "specified range [p,q]\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p1*...*pr dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p1*...*pr is the product of prime numbers pi such that the homology \n"; + std::cout << "feature exists in homology with Z/piZ coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); } } diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index 4253def9..9b1ef42f 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -1,147 +1,151 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include #include +#include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; -typedef double Filtration_value; - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string filepoints; - std::string filediag ; - Filtration_value threshold ; - int dim_max ; - int p ; +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; Filtration_value min_persistence; - program_options(argc,argv,filepoints,filediag,threshold,dim_max,p,min_persistence); + program_options(argc, argv, filepoints, filediag, threshold, dim_max, p, min_persistence); -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); std::cout << "The complex contains " << st.num_simplices() << " simplices \n"; std::cout << " and has dimension " << st.dimension() << " \n"; -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration st.initialize_filtration(); -// Compute the persistence diagram of the complex + // Compute the persistence diagram of the complex persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - - pcoh.compute_persistent_cohomology( min_persistence ); - -// Output the diagram in filediag - if(filediag.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); } + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } return 0; } - - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); - + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + po::options_description visible("Allowed options", 100); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", po::value(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); po::notify(vm); - if (vm.count("help") || !vm.count("input-file")) - { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); } } diff --git a/src/Skeleton_blocker/example/CMakeLists.txt b/src/Skeleton_blocker/example/CMakeLists.txt index d1228526..de0c7bba 100644 --- a/src/Skeleton_blocker/example/CMakeLists.txt +++ b/src/Skeleton_blocker/example/CMakeLists.txt @@ -1,10 +1,12 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIskbl) - add_executable(SkeletonBlockerFromSimplices Skeleton_blocker_from_simplices.cpp) add_executable(SkeletonBlockerIteration Skeleton_blocker_iteration.cpp) add_executable(SkeletonBlockerLink Skeleton_blocker_link.cpp) +target_link_libraries(SkeletonBlockerIteration ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) -target_link_libraries(SkeletonBlockerIteration ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) +add_test(SkeletonBlockerFromSimplices ${CMAKE_CURRENT_BINARY_DIR}/SkeletonBlockerFromSimplices) +add_test(SkeletonBlockerIteration ${CMAKE_CURRENT_BINARY_DIR}/SkeletonBlockerIteration) +add_test(SkeletonBlockerLink ${CMAKE_CURRENT_BINARY_DIR}/SkeletonBlockerLink) diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp index 9f9b3d52..2738c01c 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp @@ -1,34 +1,33 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include #include #include #include #include #include - - -#include "gudhi/Skeleton_blocker.h" +#include using namespace std; using namespace Gudhi; @@ -39,45 +38,44 @@ typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Simplex_handle Simplex_handle; typedef Complex::Simplex_handle Simplex; -int main (int argc, char *argv[]){ - std::vector simplices; +int main(int argc, char *argv[]) { + std::vector simplices; - //add 4 triangles of a tetrahedron 0123 - simplices.push_back(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(0),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(0),Vertex_handle(1))); + // add 4 triangles of a tetrahedron 0123 + simplices.push_back(Simplex_handle(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); + simplices.push_back(Simplex_handle(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); + simplices.push_back(Simplex_handle(Vertex_handle(3), Vertex_handle(0), Vertex_handle(2))); + simplices.push_back(Simplex_handle(Vertex_handle(3), Vertex_handle(0), Vertex_handle(1))); - //get complex from top faces - Complex complex(make_complex_from_top_faces(simplices.begin(),simplices.end())); + // get complex from top faces + Complex complex(make_complex_from_top_faces(simplices.begin(), simplices.end())); - std::cout << "Simplices:"<. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include #include @@ -29,8 +31,6 @@ #include -#include "gudhi/Skeleton_blocker.h" - using namespace std; using namespace Gudhi; using namespace skbl; @@ -39,54 +39,53 @@ typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Simplex_handle Simplex; - -Complex build_complete_complex(int n){ - // build a full complex with n vertices and 2^n-1 simplices - Complex complex; - for(int i=0;i. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include #include #include @@ -27,9 +28,6 @@ #include #include - -#include "gudhi/Skeleton_blocker.h" - using namespace std; using namespace Gudhi; using namespace skbl; @@ -39,33 +37,31 @@ typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Root_vertex_handle Root_vertex_handle; typedef Complex::Simplex_handle Simplex; +int main(int argc, char *argv[]) { + // build a full complex with 4 vertices and 2^4-1 simplices + // Initial vertices are (0,1,2,3,4) + Simplex tetrahedron(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + Complex complex; + complex.add_simplex(tetrahedron); -int main (int argc, char *argv[]){ - // build a full complex with 4 vertices and 2^4-1 simplices - // Initial vertices are (0,1,2,3,4) - Simplex tetrahedron(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2),Vertex_handle(3)); - Complex complex; - complex.add_simplex(tetrahedron); + cout << "complex:" << complex.to_string() << endl; - cout<<"complex:"< Date: Thu, 8 Oct 2015 21:48:10 +0000 Subject: cpplint fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@845 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8b15f0805527b494f3a57625de5c69d836b287dd --- .../CGAL_queue/Modifiable_priority_queue.h | 6 +++--- .../gudhi/Contraction/policies/Edge_length_cost.h | 6 +++--- src/GudhUI/utils/Edge_collapsor.h | 6 +++--- src/GudhUI/utils/Edge_contractor.h | 2 +- src/GudhUI/utils/Is_manifold.h | 4 ++-- src/GudhUI/utils/Vertex_collapsor.h | 2 ++ src/GudhUI/view/Viewer.h | 6 +++--- src/GudhUI/view/Viewer_instructor.h | 6 +++--- src/Hasse_complex/include/gudhi/Hasse_complex.h | 9 +++++---- .../include/gudhi/Persistent_cohomology.h | 20 +++++++++++--------- .../include/gudhi/Persistent_cohomology/Field_Zp.h | 6 +++--- .../gudhi/Persistent_cohomology/Multi_field.h | 6 +++--- .../Persistent_cohomology_column.h | 6 +++--- src/Simplex_tree/include/gudhi/Simplex_tree.h | 13 ++++++++----- .../gudhi/Simplex_tree/Simplex_tree_iterators.h | 6 +++--- .../Simplex_tree_node_explicit_storage.h | 6 +++--- .../gudhi/Simplex_tree/Simplex_tree_siblings.h | 6 +++--- .../include/gudhi/Simplex_tree/indexing_tag.h | 6 +++--- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 6 +++--- src/common/include/gudhi/graph_simplicial_complex.h | 6 +++++- 20 files changed, 73 insertions(+), 61 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h index 28ae535d..5a55c513 100644 --- a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h +++ b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h @@ -16,8 +16,8 @@ // // Author(s) : Fernando Cacciola // -#ifndef CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H -#define CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H +#ifndef CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_ +#define CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_ #define CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP @@ -98,4 +98,4 @@ class Modifiable_priority_queue { } // namespace CGAL -#endif // CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H +#endif // CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h b/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h index e4beb220..dac2d448 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ -#define CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ +#ifndef CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ +#define CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ #include @@ -53,4 +53,4 @@ class Edge_length_cost : public Cost_policy { } // namespace Gudhi -#endif // CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ +#endif // CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ diff --git a/src/GudhUI/utils/Edge_collapsor.h b/src/GudhUI/utils/Edge_collapsor.h index fcf2a248..151e9b01 100644 --- a/src/GudhUI/utils/Edge_collapsor.h +++ b/src/GudhUI/utils/Edge_collapsor.h @@ -21,8 +21,8 @@ * */ -#ifndef UTILS_COLLAPSOR_H_ -#define UTILS_COLLAPSOR_H_ +#ifndef UTILS_EDGE_COLLAPSOR_H_ +#define UTILS_EDGE_COLLAPSOR_H_ #include #include "utils/Edge_contractor.h" @@ -94,4 +94,4 @@ template class Edge_collapsor { } }; -#endif // UTILS_COLLAPSOR_H_ +#endif // UTILS_EDGE_COLLAPSOR_H_ diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h index 053aac04..45079a40 100644 --- a/src/GudhUI/utils/Edge_contractor.h +++ b/src/GudhUI/utils/Edge_contractor.h @@ -94,4 +94,4 @@ template class Edge_contractor { } }; -#endif /* EDGE_CONTRACTOR_H_ */ +#endif // UTILS_EDGE_CONTRACTOR_H_ diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index 1b25df34..b6b19ee0 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -56,7 +56,7 @@ template class Is_manifold { dim = local_dimension(v); break; } - //check that the link of every vertex is a dim-1 sphere + // check that the link of every vertex is a dim-1 sphere for (auto v : input_complex_.vertex_range()) { if (!is_k_sphere(v, dim - 1)) { res = false; @@ -90,7 +90,7 @@ template class Is_manifold { if (complex.empty()) return -1; if (complex.num_blockers() != 1) return -2; - //necessary and sufficient condition : there exists a unique blocker that passes through all vertices + // necessary and sufficient condition : there exists a unique blocker that passes through all vertices auto first_blocker = *(complex.const_blocker_range().begin()); if (first_blocker->dimension() + 1 != complex.num_vertices()) diff --git a/src/GudhUI/utils/Vertex_collapsor.h b/src/GudhUI/utils/Vertex_collapsor.h index be03c765..2b36cb3a 100644 --- a/src/GudhUI/utils/Vertex_collapsor.h +++ b/src/GudhUI/utils/Vertex_collapsor.h @@ -24,6 +24,8 @@ #ifndef UTILS_VERTEX_COLLAPSOR_H_ #define UTILS_VERTEX_COLLAPSOR_H_ +#include + #include "utils/Edge_contractor.h" #include "utils/Furthest_point_epsilon_net.h" #include "utils/UI_utils.h" diff --git a/src/GudhUI/view/Viewer.h b/src/GudhUI/view/Viewer.h index 99bd63e4..276ccd3c 100644 --- a/src/GudhUI/view/Viewer.h +++ b/src/GudhUI/view/Viewer.h @@ -21,8 +21,8 @@ * */ -#ifndef VIEW_VIEWER_H -#define VIEW_VIEWER_H +#ifndef VIEW_VIEWER_H_ +#define VIEW_VIEWER_H_ // Workaround for moc-qt4 not parsing boost headers #include @@ -117,4 +117,4 @@ class Viewer : public QGLViewer { void click(const Point_3& position); }; -#endif // VIEW_VIEWER_H +#endif // VIEW_VIEWER_H_ diff --git a/src/GudhUI/view/Viewer_instructor.h b/src/GudhUI/view/Viewer_instructor.h index e1c6af8b..31a1d273 100644 --- a/src/GudhUI/view/Viewer_instructor.h +++ b/src/GudhUI/view/Viewer_instructor.h @@ -21,8 +21,8 @@ * */ -#ifndef VIEW_VIEWER_INSTRUCTOR_H -#define VIEW_VIEWER_INSTRUCTOR_H +#ifndef VIEW_VIEWER_INSTRUCTOR_H_ +#define VIEW_VIEWER_INSTRUCTOR_H_ // todo do a viewer instructor that have directely a pointer to a QGLviewer and buffer ot not triangles @@ -114,4 +114,4 @@ class Viewer_instructor : public QWidget { void change_light(); }; -#endif // VIEW_VIEWER_INSTRUCTOR_H +#endif // VIEW_VIEWER_INSTRUCTOR_H_ diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h index c3a84c02..67079687 100644 --- a/src/Hasse_complex/include/gudhi/Hasse_complex.h +++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h @@ -26,6 +26,8 @@ #include #include +#include // for pair +#include namespace Gudhi { @@ -71,11 +73,10 @@ template < typename FiltrationValue = double > class Hasse_complex { public: - typedef Hasse_simplex Hasse_simp; typedef FiltrationValue Filtration_value; typedef SimplexKey Simplex_key; - typedef int Simplex_handle; //index in vector complex_ + typedef int Simplex_handle; // index in vector complex_ typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator; typedef boost::iterator_range Filtration_simplex_range; @@ -214,8 +215,8 @@ std::istream& operator>>(std::istream & is typename Hasse_complex::Filtration_value max_fil = 0; int max_dim = -1; int key = 0; - while (read_hasse_simplex(is, boundary, fil)) //read all simplices in the file as a list of vertices - { + // read all simplices in the file as a list of vertices + while (read_hasse_simplex(is, boundary, fil)) { // insert every simplex in the simplex tree hcpx.complex_.push_back(Hasse_simplex< Hasse_complex >(key, fil, boundary)); diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 8c614e96..d096792f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_H_ +#ifndef PERSISTENT_COHOMOLOGY_H_ +#define PERSISTENT_COHOMOLOGY_H_ #include #include @@ -38,6 +38,10 @@ #include #include #include // std::ofstream +#include // for numeric_limits<> +#include +#include +#include namespace Gudhi { @@ -709,13 +713,11 @@ class Persistent_cohomology { } } - void write_output_diagram(std::string diagram_name) - { - std::ofstream diagram_out(diagram_name.c_str()); - cmp_intervals_by_length cmp( cpx_ ); + void write_output_diagram(std::string diagram_name) { + std::ofstream diagram_out(diagram_name.c_str()); + cmp_intervals_by_length cmp(cpx_); std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp); - for(auto pair : persistent_pairs_) - { + for (auto pair : persistent_pairs_) { diagram_out << cpx_->dimension(get<0>(pair)) << " " << cpx_->filtration(get<0>(pair)) << " " << cpx_->filtration(get<1>(pair)) << std::endl; @@ -774,4 +776,4 @@ class Persistent_cohomology { } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_H_ +#endif // PERSISTENT_COHOMOLOGY_H_ diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h index a12019f8..6db16e69 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ +#ifndef PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ +#define PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ #include #include @@ -113,4 +113,4 @@ class Field_Zp { } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ +#endif // PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h index 555d696f..0591fc95 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ +#ifndef PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ +#define PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ #include @@ -183,4 +183,4 @@ class Multi_field { } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ +#endif // PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h index 568f24df..612658e6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ +#ifndef PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ +#define PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ #include #include @@ -138,4 +138,4 @@ class Persistent_cohomology_column : public boost::intrusive::set_base_hook< } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ +#endif // PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 96565ff1..6e51d107 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -120,7 +120,9 @@ class Simplex_tree { /* Type of node in the simplex tree. */ typedef Simplex_tree_node_explicit_storage Node; /* Type of dictionary Vertex_handle -> Node for traversing the simplex tree. */ - // Note: this wastes space when Vertex_handle is 32 bits and Node is aligned on 64 bits. It would be better to use a flat_set (with our own comparator) where we can control the layout of the struct (put Vertex_handle and Simplex_key next to each other). + // Note: this wastes space when Vertex_handle is 32 bits and Node is aligned on 64 bits. It would be better to use a + // flat_set (with our own comparator) where we can control the layout of the struct (put Vertex_handle and + // Simplex_key next to each other). typedef typename boost::container::flat_map Dictionary; /* \brief Set of nodes sharing a same parent in the simplex tree. */ @@ -131,7 +133,7 @@ class Simplex_tree { Key_simplex_base_real() : key_(-1) {} void assign_key(Simplex_key k) { key_ = k; } Simplex_key key() const { return key_; } - private: + private: Simplex_key key_; }; struct Key_simplex_base_dummy { @@ -145,7 +147,7 @@ class Simplex_tree { Filtration_simplex_base_real() : filt_(0) {} void assign_filtration(Filtration_value f) { filt_ = f; } Filtration_value filtration() const { return filt_; } - private: + private: Filtration_value filt_; }; struct Filtration_simplex_base_dummy { @@ -153,7 +155,8 @@ class Simplex_tree { void assign_filtration(Filtration_value f) { assert(f == 0); } Filtration_value filtration() const { return 0; } }; - typedef typename std::conditional::type Filtration_simplex_base; + typedef typename std::conditional::type Filtration_simplex_base; public: /** \brief Handle type to a simplex contained in the simplicial complex represented @@ -271,7 +274,7 @@ class Simplex_tree { * The filtration must be valid. If the filtration has not been initialized yet, the * method initializes it (i.e. order the simplices). If the complex has changed since the last time the filtration * was initialized, please call `initialize_filtration()` to recompute it. */ - Filtration_simplex_range const& filtration_simplex_range(Indexing_tag=Indexing_tag()) { + Filtration_simplex_range const& filtration_simplex_range(Indexing_tag = Indexing_tag()) { if (filtration_vect_.empty()) { initialize_filtration(); } diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index f83f5ea8..372ef329 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_ITERATORS_H_ -#define SIMPLEX_TREE_ITERATORS_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ #include #include @@ -315,4 +315,4 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_ITERATORS_H_ +#endif // SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h index 7f735b7e..25d4888a 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ -#define SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ #include @@ -69,4 +69,4 @@ struct Simplex_tree_node_explicit_storage : SimplexTree::Filtration_simplex_base /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#endif // SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h index 9cdda967..158ee1f7 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_SIBLINGS_H_ -#define SIMPLEX_TREE_SIBLINGS_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ #include @@ -124,4 +124,4 @@ class Simplex_tree_siblings { /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_SIBLINGS_H_ +#endif // SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h b/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h index a00dac27..0adeb46d 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef INDEXING_TAG_H_ -#define INDEXING_TAG_H_ +#ifndef SIMPLEX_TREE_INDEXING_TAG_H_ +#define SIMPLEX_TREE_INDEXING_TAG_H_ namespace Gudhi { @@ -36,4 +36,4 @@ struct linear_indexing_tag { // struct zigzag_indexing_tag {}; } // namespace Gudhi -#endif // INDEXING_TAG_H_ +#endif // SIMPLEX_TREE_INDEXING_TAG_H_ 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 705c78bb..17a237a7 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -22,12 +22,12 @@ #ifndef SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ #define SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#include + #include #include #include -#include - namespace Gudhi { namespace skbl { @@ -340,7 +340,7 @@ Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vert assert(this->contains_vertex(a)); assert(this->contains_vertex(b)); - if(this->contains_edge(a, b)) + if (this->contains_edge(a, b)) this->add_edge(a, b); // if some blockers passes through 'ab', we need to remove them. diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h index 859504b2..042ef516 100644 --- a/src/common/include/gudhi/graph_simplicial_complex.h +++ b/src/common/include/gudhi/graph_simplicial_complex.h @@ -25,6 +25,10 @@ #include +#include // for pair<> +#include +#include + /* Edge tag for Boost PropertyGraph. */ struct edge_filtration_t { typedef boost::edge_property_tag kind; @@ -79,7 +83,7 @@ Graph_t compute_proximity_graph(PointCloud &points Graph_t skel_graph(edges.begin() , edges.end() , edges_fil.begin() - , idx_u); //number of points labeled from 0 to idx_u-1 + , idx_u); // number of points labeled from 0 to idx_u-1 auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); -- cgit v1.2.3 From 6fd64ffb734f09eeb40aade1efa2e03666eb65b9 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 12 Oct 2015 14:57:19 +0000 Subject: Fix program_options issue with MSVC git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@850 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b2a90b0c494f0eae1da67e23527946733d501643 --- src/Persistent_cohomology/example/CMakeLists.txt | 66 ++++++++++++------------ 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 435d2f58..ea69352e 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -2,43 +2,43 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIExPersCohom) # problem with Visual Studio link on Boost program_options -if (NOT MSVC) - add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) - target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) - add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) +add_definitions( -DBOOST_ALL_NO_LIB ) +add_definitions( -DBOOST_ALL_DYN_LINK ) - add_executable(rips_persistence rips_persistence.cpp) - target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - - add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 3 -m 100) - - add_executable(persistence_from_file persistence_from_file.cpp) - target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0) - add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) - - if(GMPXX_FOUND AND GMP_FOUND) - message("GMPXX_LIBRARIES = ${GMPXX_LIBRARIES}") - message("GMP_LIBRARIES = ${GMP_LIBRARIES}") +add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) +target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) +add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) + +add_executable(rips_persistence rips_persistence.cpp) +target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) - target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) - add_test(rips_multifield_persistence_2_71 ${CMAKE_CURRENT_BINARY_DIR}/rips_multifield_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 2 -q 71 -m 100) +add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 3 -m 100) - add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) - target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) +add_executable(persistence_from_file persistence_from_file.cpp) +target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) +add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0) +add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) - if(CGAL_FOUND) - if (CMAKE_BUILD_TYPE MATCHES Debug) - # For programs to be more verbose - add_definitions(-DDEBUG_TRACES) - endif() +if(GMPXX_FOUND AND GMP_FOUND) + message("GMPXX_LIBRARIES = ${GMPXX_LIBRARIES}") + message("GMP_LIBRARIES = ${GMP_LIBRARIES}") - add_executable(alpha_shapes_persistence alpha_shapes_persistence.cpp) - target_link_libraries(alpha_shapes_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY}) - add_test(alpha_shapes_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 2 0.5) - #add_test(alpha_shapes_persistence_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) - endif() - + add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) + target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + add_test(rips_multifield_persistence_2_71 ${CMAKE_CURRENT_BINARY_DIR}/rips_multifield_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 2 -q 71 -m 100) + + add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) + target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + + if(CGAL_FOUND) + if (CMAKE_BUILD_TYPE MATCHES Debug) + # For programs to be more verbose + add_definitions(-DDEBUG_TRACES) + endif() + add_executable(alpha_shapes_persistence alpha_shapes_persistence.cpp) + target_link_libraries(alpha_shapes_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY}) + add_test(alpha_shapes_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 2 0.5) + #add_test(alpha_shapes_persistence_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) endif() + endif() -- cgit v1.2.3 From f0b88dfb3523ad6e39b60c6cc56b18ec1fa3cd9f Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 18 Oct 2015 08:20:14 +0000 Subject: Update performance_rips_persistence, which hasn't been working for a long time. We might want to run it in the testsuite with a smaller parameter so it doesn't take too long. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@863 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1fd91395f855297cf4815d64e94b06a8c400c99b --- .../example/performance_rips_persistence.cpp | 81 +++++++++++++++++----- 1 file changed, 62 insertions(+), 19 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp index 0e912d57..fc48d6b1 100644 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp @@ -63,10 +63,11 @@ void timing_persistence(FilteredComplex & cpx */ int main(int argc, char * argv[]) { std::chrono::time_point start, end; - int enlapsed_sec; + int elapsed_sec; + { - std::string filepoints = "../examples/Kl.txt"; - Filtration_value threshold = 0.3; + std::string filepoints = "../../../data/points/Kl.txt"; + Filtration_value threshold = 0.27; int dim_max = 3; int p = 2; int q = 1223; @@ -81,8 +82,8 @@ int main(int argc, char * argv[]) { Graph_t prox_graph = compute_proximity_graph(points, threshold , euclidean_distance); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Compute Rips graph in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Compute Rips graph in " << elapsed_sec << " ms.\n"; // Construct the Rips complex in a Simplex Tree Simplex_tree<> st; @@ -94,8 +95,8 @@ int main(int argc, char * argv[]) { st.expansion(dim_max); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Compute Rips complex in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Compute Rips complex in " << elapsed_sec << " ms.\n"; std::cout << " - dimension = " << st.dimension() << std::endl; std::cout << " - number of simplices = " << st.num_simplices() << std::endl; @@ -103,15 +104,26 @@ int main(int argc, char * argv[]) { start = std::chrono::system_clock::now(); st.initialize_filtration(); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Order the simplices of the filtration in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Order the simplices of the filtration in " << elapsed_sec << " ms.\n"; + + // Copy the keys inside the simplices + start = std::chrono::system_clock::now(); + { + int count = 0; + for (auto sh : st.filtration_simplex_range()) + st.assign_key(sh, count++); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Copied the keys inside the simplices in " << elapsed_sec << " ms.\n"; // Convert the simplex tree into a hasse diagram start = std::chrono::system_clock::now(); Hasse_complex<> hcpx(st); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << "Convert the simplex tree into a Hasse diagram in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Convert the simplex tree into a Hasse diagram in " << elapsed_sec << " ms.\n"; std::cout << "Timings when using a simplex tree: \n"; @@ -124,6 +136,11 @@ int main(int argc, char * argv[]) { timing_persistence(hcpx, q); timing_persistence(hcpx, p, q); + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << "Running the complex destructors in " << elapsed_sec << " ms.\n"; return 0; } @@ -132,19 +149,32 @@ void timing_persistence(FilteredComplex & cpx , int p) { std::chrono::time_point start, end; - int enlapsed_sec; - + int elapsed_sec; + { + start = std::chrono::system_clock::now(); Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n"; // initializes the coefficient field for homology + start = std::chrono::system_clock::now(); pcoh.init_coefficients(p); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; start = std::chrono::system_clock::now(); pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); - std::cout << " Compute persistent homology in Z/" << p << "Z in " << enlapsed_sec << " sec.\n"; + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Compute persistent homology in Z/" << p << "Z in " << elapsed_sec << " ms.\n"; + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; } template< typename FilteredComplex> @@ -153,11 +183,19 @@ timing_persistence(FilteredComplex & cpx , int p , int q) { std::chrono::time_point start, end; - int enlapsed_sec; - + int elapsed_sec; + { + start = std::chrono::system_clock::now(); Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize pcoh in " << elapsed_sec << " ms.\n"; // initializes the coefficient field for homology + start = std::chrono::system_clock::now(); pcoh.init_coefficients(p, q); + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Initialize the coefficient field in " << elapsed_sec << " ms.\n"; // compute persistent homology, disgarding persistent features of life shorter than min_persistence start = std::chrono::system_clock::now(); @@ -165,7 +203,12 @@ timing_persistence(FilteredComplex & cpx pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end - start).count(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in [" << p << ";" << q << "] in " << enlapsed_sec << " sec.\n"; + << "with p in [" << p << ";" << q << "] in " << elapsed_sec << " ms.\n"; + start = std::chrono::system_clock::now(); + } + end = std::chrono::system_clock::now(); + elapsed_sec = std::chrono::duration_cast(end - start).count(); + std::cout << " Run the persistence destructors in " << elapsed_sec << " ms.\n"; } -- cgit v1.2.3 From da56757d861e0e543b71454615b7266f3f9b84e5 Mon Sep 17 00:00:00 2001 From: glisse Date: Thu, 29 Oct 2015 13:23:25 +0000 Subject: Add an example that computes (non-persistent) homology. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@880 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 21606fab3356681780ad446e73d5da56b29ec31d --- src/Persistent_cohomology/example/CMakeLists.txt | 4 ++ .../example/plain_homology.cpp | 80 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/Persistent_cohomology/example/plain_homology.cpp (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index ea69352e..50d10025 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -5,6 +5,10 @@ project(GUDHIExPersCohom) add_definitions( -DBOOST_ALL_NO_LIB ) add_definitions( -DBOOST_ALL_DYN_LINK ) +add_executable(plain_homology plain_homology.cpp) +target_link_libraries(plain_homology ${Boost_SYSTEM_LIBRARY}) +add_test(plain_homology ${CMAKE_CURRENT_BINARY_DIR}/plain_homology) + add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) diff --git a/src/Persistent_cohomology/example/plain_homology.cpp b/src/Persistent_cohomology/example/plain_homology.cpp new file mode 100644 index 00000000..e293e013 --- /dev/null +++ b/src/Persistent_cohomology/example/plain_homology.cpp @@ -0,0 +1,80 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Marc Glisse + * + * Copyright (C) 2015 INRIA Saclay - Ile-de-France (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include + +using namespace Gudhi; + +struct MyOptions : Simplex_tree_options_full_featured { + // Implicitly use 0 as filtration value for all simplices + static const bool store_filtration = false; + // The persistence algorithm needs this + static const bool store_key = true; + // I have few vertices + typedef short Vertex_handle; +}; +typedef Simplex_tree ST; + +int main() { + ST st; + + /* Complex to build. */ + /* 1 3 */ + /* o---o */ + /* /X\ / */ + /* o---o o */ + /* 2 0 4 */ + + const short triangle012[] = {0, 1, 2}; + const short edge03[] = {0, 3}; + const short edge13[] = {1, 3}; + const short vertex4[] = {4}; + st.insert_simplex_and_subfaces(triangle012); + st.insert_simplex_and_subfaces(edge03); + st.insert_simplex(edge13); + st.insert_simplex(vertex4); + // FIXME: Remove this line + st.set_dimension(2); + + // Sort the simplices in the order of the filtration + st.initialize_filtration(); + + // Class for homology computation + persistent_cohomology::Persistent_cohomology pcoh(st); + + // Initialize the coefficient field Z/2Z for homology + pcoh.init_coefficients(2); + + // Compute the persistence diagram of the complex + pcoh.compute_persistent_cohomology(); + + // Print the result. The format is, on each line: 2 dim 0 inf + // where 2 represents the field, dim the dimension of the feature. + // 2 0 0 inf + // 2 0 0 inf + // 2 1 0 inf + // means that in Z/2Z-homology, the Betti numbers are b0=2 and b1=1. + pcoh.output_diagram(); +} -- cgit v1.2.3 From 6f73317041162da6dcc8bc5f52ca62a560b12ec4 Mon Sep 17 00:00:00 2001 From: glisse Date: Tue, 10 Nov 2015 16:37:17 +0000 Subject: Update a comment in plain_homology. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@901 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9a04cd581e4b4a2ea26c474ec0928a67b990dc98 --- src/Persistent_cohomology/example/plain_homology.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/example/plain_homology.cpp b/src/Persistent_cohomology/example/plain_homology.cpp index e293e013..0a692717 100644 --- a/src/Persistent_cohomology/example/plain_homology.cpp +++ b/src/Persistent_cohomology/example/plain_homology.cpp @@ -27,6 +27,10 @@ using namespace Gudhi; +/* We could perfectly well use the default Simplex_tree<> (which uses + * Simplex_tree_options_full_featured), the following simply demonstrates + * how to save on storage by not storing a filtration value. */ + struct MyOptions : Simplex_tree_options_full_featured { // Implicitly use 0 as filtration value for all simplices static const bool store_filtration = false; -- cgit v1.2.3 From 340944d185b9c02f93400e2ff6bf764a5c027e91 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 21:20:28 +0000 Subject: Make annotations_in_boundary a vector, sorted once after construction, with entries sharing the same annotation accumulated as we go. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@907 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 68351e5d61b1e3eb0b2d6c3623d7d213da9371d4 --- .../include/gudhi/Persistent_cohomology.h | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index d096792f..3875afc6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,9 +431,13 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity, in a map. - std::map annotations_in_boundary; - std::pair::iterator, bool> result_insert_bound; + // with multiplicity. +#if 0 + std::vector> annotations_in_boundary; +#else + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); +#endif int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -445,22 +449,29 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - result_insert_bound = annotations_in_boundary.insert(std::pair(curr_col, sign)); - if (!(result_insert_bound.second)) { - result_insert_bound.first->second += sign; - } + annotations_in_boundary.emplace_back(curr_col, sign); } } sign = -sign; } + std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - for (auto ann_ref : annotations_in_boundary) { - if (ann_ref.second != coeff_field_.additive_identity()) { // For all columns in the boundary, - for (auto cell_ref : ann_ref.first->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, ann_ref.second); // coefficient * multiplicity + auto ann_it = annotations_in_boundary.begin(); + while (ann_it != annotations_in_boundary.end()) { + auto col = ann_it->first; + int coef = ann_it->second; + for (;;) { + if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) + break; + coef += ann_it->second; + } + // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. + if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, + for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From 484f3f7f57946d0a82b18c78f954a836dc4e1d57 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 21:24:18 +0000 Subject: Revert the last commit, this was supposed to go to a branch. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@908 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 66d468165b97b852fbe897bea212c85ac9fb0e14 --- .../include/gudhi/Persistent_cohomology.h | 33 ++++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 3875afc6..d096792f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,13 +431,9 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity. -#if 0 - std::vector> annotations_in_boundary; -#else - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); -#endif + // with multiplicity, in a map. + std::map annotations_in_boundary; + std::pair::iterator, bool> result_insert_bound; int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -449,29 +445,22 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - annotations_in_boundary.emplace_back(curr_col, sign); + result_insert_bound = annotations_in_boundary.insert(std::pair(curr_col, sign)); + if (!(result_insert_bound.second)) { + result_insert_bound.first->second += sign; + } } } sign = -sign; } - std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - auto ann_it = annotations_in_boundary.begin(); - while (ann_it != annotations_in_boundary.end()) { - auto col = ann_it->first; - int coef = ann_it->second; - for (;;) { - if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) - break; - coef += ann_it->second; - } - // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. - if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, - for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity + for (auto ann_ref : annotations_in_boundary) { + if (ann_ref.second != coeff_field_.additive_identity()) { // For all columns in the boundary, + for (auto cell_ref : ann_ref.first->col_) { // insert every cell in map_a_ds with multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, ann_ref.second); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From fc91de9f736c13f38d096fc1da78c688e7992fe7 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 21:25:38 +0000 Subject: Make annotations_in_boundary a vector, sorted once after construction, with entries sharing the same annotation accumulated as we go. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@909 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 34b2ae74dc017c18a90e08caee6f707b6b0d4cc2 --- .../include/gudhi/Persistent_cohomology.h | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index d096792f..3875afc6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,9 +431,13 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity, in a map. - std::map annotations_in_boundary; - std::pair::iterator, bool> result_insert_bound; + // with multiplicity. +#if 0 + std::vector> annotations_in_boundary; +#else + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); +#endif int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -445,22 +449,29 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - result_insert_bound = annotations_in_boundary.insert(std::pair(curr_col, sign)); - if (!(result_insert_bound.second)) { - result_insert_bound.first->second += sign; - } + annotations_in_boundary.emplace_back(curr_col, sign); } } sign = -sign; } + std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - for (auto ann_ref : annotations_in_boundary) { - if (ann_ref.second != coeff_field_.additive_identity()) { // For all columns in the boundary, - for (auto cell_ref : ann_ref.first->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, ann_ref.second); // coefficient * multiplicity + auto ann_it = annotations_in_boundary.begin(); + while (ann_it != annotations_in_boundary.end()) { + auto col = ann_it->first; + int coef = ann_it->second; + for (;;) { + if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) + break; + coef += ann_it->second; + } + // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. + if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, + for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From ccf7f9e5b8840f57c68dec83e2153c3cc5804b61 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:07:20 +0000 Subject: Clean-up. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@912 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5652acf2ed5eb6f11428d2907963b5d1a1359be --- .../include/gudhi/Persistent_cohomology.h | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 3875afc6..2d6a85c1 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,13 +431,14 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity. -#if 0 - std::vector> annotations_in_boundary; -#else - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); -#endif + // with multiplicity. We used to sum the coefficients directly in + // annotations_in_boundary by using a map, we now do it later. + typedef std::pair annotation_t; + std::vector annotations_in_boundary; + /* A small speed boost is possible with the following non-thread-safe: + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); + */ int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -454,18 +455,18 @@ class Persistent_cohomology { } sign = -sign; } - std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - auto ann_it = annotations_in_boundary.begin(); - while (ann_it != annotations_in_boundary.end()) { - auto col = ann_it->first; + for (auto ann_it = annotations_in_boundary.begin(); ann_it != annotations_in_boundary.end(); /**/) { + Column* col = ann_it->first; int coef = ann_it->second; - for (;;) { - if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) - break; + while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) { coef += ann_it->second; } // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. -- cgit v1.2.3 From 32a6d46672102e17f7ae09fe130382aa7e487884 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:14:03 +0000 Subject: Rename variable. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@913 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0afbcbee5739c1649d1c9b968d9f0748c7d1d219 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 2d6a85c1..1d8c2ca2 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -465,14 +465,14 @@ class Persistent_cohomology { for (auto ann_it = annotations_in_boundary.begin(); ann_it != annotations_in_boundary.end(); /**/) { Column* col = ann_it->first; - int coef = ann_it->second; + int mult = ann_it->second; while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) { - coef += ann_it->second; + mult += ann_it->second; } // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. - if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, + if (mult != coeff_field_.additive_identity()) { // For all columns in the boundary, for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, mult); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From bdb1e5517822d935da93d83c8950cbbd11560698 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:27:56 +0000 Subject: Using a static variable really helps. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@914 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 695a6f642399c2646e5a26fac20173fbd57fe160 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 1d8c2ca2..609f40a2 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -434,11 +434,9 @@ class Persistent_cohomology { // with multiplicity. We used to sum the coefficients directly in // annotations_in_boundary by using a map, we now do it later. typedef std::pair annotation_t; - std::vector annotations_in_boundary; - /* A small speed boost is possible with the following non-thread-safe: - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); - */ + // Danger: not thread-safe! + static std::vector annotations_in_boundary; + annotations_in_boundary.clear(); int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; -- cgit v1.2.3 From fe40846f6cbdf355a2b7c1f2624c5c0e023fa8bb Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:47:42 +0000 Subject: Unobfuscate a multiplication. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@915 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 771fd96e47209ceee8ffa05519134f0c8069b1cf --- .../include/gudhi/Persistent_cohomology/Multi_field.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h index 0591fc95..38bc08d1 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -81,8 +81,7 @@ class Multi_field { // set m to primorial(bound_prime) prod_characteristics_ = 1; for (auto p : primes_) { - mpz_mul_ui(prod_characteristics_.get_mpz_t(), - prod_characteristics_.get_mpz_t(), p); + prod_characteristics_ *= p; } // Uvect_ -- cgit v1.2.3 From b15b9c7f6f5dd232dee897c96d65f5f77e215314 Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 15 Nov 2015 10:04:32 +0000 Subject: Fix for older libstdc++. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@922 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d370bbf81488ef6b07a17d63ad43ba2b813e2210 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 609f40a2..2a405830 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -455,7 +455,7 @@ class Persistent_cohomology { } // Place identical annotations consecutively so we can easily sum their multiplicities. std::sort(annotations_in_boundary.begin(), annotations_in_boundary.end(), - [](annotation_t& a, annotation_t& b) { return a.first < b.first; }); + [](annotation_t const& a, annotation_t const& b) { return a.first < b.first; }); // Sum the annotations with multiplicity, using a map // to represent a sparse vector. -- cgit v1.2.3