From 21b1120bfa2047eca025ae759dce2d05f6c86c43 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 22 Sep 2017 05:37:51 +0000 Subject: Remove automatic_dimension_set call from remove and prune functions Make it public to be available Modify tests accordingly git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_automatic_dimension_set@2703 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2ff42d5327ae76b121390a913c4e548d6f59ea99 --- src/Alpha_complex/test/Alpha_complex_unit_test.cpp | 2 +- src/Simplex_tree/include/gudhi/Simplex_tree.h | 36 ++++------ .../test/simplex_tree_remove_unit_test.cpp | 78 ++++++++++++++-------- 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp index 166373fe..e60089c4 100644 --- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp @@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { BOOST_CHECK(simplex_tree.num_simplices() == 10); std::cout << "simplex_tree.dimension()=" << simplex_tree.dimension() << std::endl; - BOOST_CHECK(simplex_tree.dimension() == 1); + BOOST_CHECK(simplex_tree.dimension() == 3); std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl; BOOST_CHECK(simplex_tree.num_vertices() == 4); diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 5d1885b8..fd6cd72a 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -1161,13 +1161,11 @@ class Simplex_tree { * \post Some simplex tree functions require the filtration to be valid. `prune_above_filtration()` * function is not launching `initialize_filtration()` but returns the filtration modification information. If the * complex has changed , please call `initialize_filtration()` to recompute it. + * \post Be aware that `prune_above_filtration()` may change the simplex tree dimension (`automatic_dimension_set()` + * to be done). */ bool prune_above_filtration(Filtration_value filtration) { - bool modified = rec_prune_above_filtration(root(), filtration); - if (modified) { - auto_dimension_set(dimension()); - } - return modified; + return rec_prune_above_filtration(root(), filtration); } private: @@ -1195,17 +1193,16 @@ class Simplex_tree { return modified; } - private: - /** \brief Resets the Simplex_tree dimension. - * @param[in] old_dimension The former dimension value until the loop stopped when it is reached. + public: + /** \brief Deep search simplex tree dimension reset. * @return The dimension modification information. - * \pre Please check the simplex has not a too low dimension value. - * This cannot happen if set_dimension has not been performed. + * \pre Be sure the simplex tree has not a too low dimension value as the deep search stops when the former dimension + * has been reached (cf. `dimension()` and `set_dimension()` methods). */ - bool auto_dimension_set(int old_dimension) { + bool automatic_dimension_set() { int new_dimension = -1; // Browse the tree from te left to the right as higher dimension cells are more likely on the left part of the tree - for (Simplex_handle sh : skeleton_simplex_range(old_dimension)) { + for (Simplex_handle sh : skeleton_simplex_range(dimension_)) { #ifdef DEBUG_TRACES for (auto vertex : simplex_vertex_range(sh)) { std::cout << " " << vertex; @@ -1214,12 +1211,12 @@ class Simplex_tree { #endif // DEBUG_TRACES int sh_dimension = dimension(sh); - if (sh_dimension >= old_dimension) + if (sh_dimension >= dimension_) // Stop browsing as soon as the dimension is reached, no need to go furter return false; new_dimension = std::max(new_dimension, sh_dimension); } - set_dimension(new_dimension); + dimension_ = new_dimension; return true; } @@ -1229,7 +1226,8 @@ class Simplex_tree { * @param[in] sh Simplex handle on the maximal simplex to remove. * \pre Please check the simplex has no coface before removing it. * \exception std::invalid_argument In debug mode, if sh has children. - * \post Be aware that removing is shifting data in a flat_map (initialize_filtration to be done). + * \post Be aware that removing is shifting data in a flat_map (`initialize_filtration()` to be done). + * \post Be aware that removing may change the simplex tree dimension (`automatic_dimension_set()` to be done). */ void remove_maximal_simplex(Simplex_handle sh) { // Guarantee the simplex has no children @@ -1244,17 +1242,9 @@ class Simplex_tree { // Special case when child is the root of the simplex tree, just remove it from members child->erase(sh); } else { - // Keep information before remove action - int sh_dim = dimension(sh); - // Sibling is emptied : must be deleted, and its parent must point on his own Sibling child->oncles()->members().at(child->parent()).assign_children(child->oncles()); delete child; - - // No need to reset dimension in case maximal simplex is not the maximal dimension one - if (sh_dim >= dimension()) { - auto_dimension_set(sh_dim); - } } } diff --git a/src/Simplex_tree/test/simplex_tree_remove_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_remove_unit_test.cpp index 1e6cea52..87c77801 100644 --- a/src/Simplex_tree/test/simplex_tree_remove_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_remove_unit_test.cpp @@ -108,7 +108,12 @@ BOOST_AUTO_TEST_CASE(remove_maximal_simplex) { st.remove_maximal_simplex(st.find({6, 7})); std::cout << "st.remove_maximal_simplex({7})" << std::endl; st.remove_maximal_simplex(st.find({7})); - + + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 3); + + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << " | st_wo_seven.dimension()=" << st_wo_seven.dimension() << std::endl; BOOST_CHECK(st == st_wo_seven); } @@ -130,100 +135,112 @@ BOOST_AUTO_TEST_CASE(auto_dimension_set) { std::cout << "st.remove_maximal_simplex({6, 7, 8, 10})" << std::endl; st.remove_maximal_simplex(st.find({6, 7, 8, 10})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.remove_maximal_simplex({6, 7, 8, 9})" << std::endl; st.remove_maximal_simplex(st.find({6, 7, 8, 9})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.remove_maximal_simplex({1, 2, 3, 4})" << std::endl; st.remove_maximal_simplex(st.find({1, 2, 3, 4})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.remove_maximal_simplex({1, 2, 3, 5})" << std::endl; st.remove_maximal_simplex(st.find({1, 2, 3, 5})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 3); + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 2); std::cout << "st.insert_simplex_and_subfaces({1, 2, 3, 5})" << std::endl; st.insert_simplex_and_subfaces({1, 2, 3, 5}); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.insert_simplex_and_subfaces({1, 2, 3, 4})" << std::endl; st.insert_simplex_and_subfaces({1, 2, 3, 4}); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.remove_maximal_simplex({1, 2, 3, 5})" << std::endl; st.remove_maximal_simplex(st.find({1, 2, 3, 5})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.remove_maximal_simplex({1, 2, 3, 4})" << std::endl; st.remove_maximal_simplex(st.find({1, 2, 3, 4})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 3); + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 2); std::cout << "st.insert_simplex_and_subfaces({0, 1, 3, 4})" << std::endl; st.insert_simplex_and_subfaces({0, 1, 3, 4}); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.remove_maximal_simplex({0, 1, 3, 4})" << std::endl; st.remove_maximal_simplex(st.find({0, 1, 3, 4})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 3); + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 2); std::cout << "st.insert_simplex_and_subfaces({1, 2, 3, 5})" << std::endl; st.insert_simplex_and_subfaces({1, 2, 3, 5}); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); std::cout << "st.insert_simplex_and_subfaces({1, 2, 3, 4})" << std::endl; st.insert_simplex_and_subfaces({1, 2, 3, 4}); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 3); + // Check you can override the dimension // This is a limit test case - shall not happen st.set_dimension(1); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 1); - - // Here no siblings is erased - automatic dimension is not launched. - std::cout << "st.remove_maximal_simplex({1, 2, 3, 4})" << std::endl; - st.remove_maximal_simplex(st.find({1, 2, 3, 4})); + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + // check automatic_dimension_set() is not giving the rigt answer because dimension is too low BOOST_CHECK(st.dimension() == 1); - // Here sibling is erased - automatic dimension is launched. - std::cout << "st.remove_maximal_simplex({1, 2, 3, 5})" << std::endl; - st.remove_maximal_simplex(st.find({1, 2, 3, 5})); - BOOST_CHECK(st.dimension() == 2); - - std::cout << "st.insert_simplex_and_subfaces({1, 2, 3, 5})" << std::endl; - st.insert_simplex_and_subfaces({1, 2, 3, 5}); - BOOST_CHECK(st.dimension() == 3); - - std::cout << "st.insert_simplex_and_subfaces({1, 2, 3, 4})" << std::endl; - st.insert_simplex_and_subfaces({1, 2, 3, 4}); - BOOST_CHECK(st.dimension() == 3); // Check you can override the dimension // This is a limit test case - shall not happen st.set_dimension(6); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 6); + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + // check automatic_dimension_set() resets the correct dimension + BOOST_CHECK(st.dimension() == 3); - // Here no siblings is erased - automatic dimension is not launched. - std::cout << "st.remove_maximal_simplex({1, 2, 3, 5})" << std::endl; - st.remove_maximal_simplex(st.find({1, 2, 3, 5})); - BOOST_CHECK(st.dimension() == 6); - - // Here sibling is erased - automatic dimension is launched but dim is always than te one set. - std::cout << "st.remove_maximal_simplex({1, 2, 3, 4})" << std::endl; - st.remove_maximal_simplex(st.find({1, 2, 3, 4})); - BOOST_CHECK(st.dimension() == 6); // Reset with the correct value - st.set_dimension(2); - BOOST_CHECK(st.dimension() == 2); + st.set_dimension(3); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 3); std::cout << "st.insert_simplex_and_subfaces({0, 1, 2, 3, 4, 5, 6})" << std::endl; st.insert_simplex_and_subfaces({0, 1, 2, 3, 4, 5, 6}); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 6); std::cout << "st.remove_maximal_simplex({0, 1, 2, 3, 4, 5, 6})" << std::endl; st.remove_maximal_simplex(st.find({0, 1, 2, 3, 4, 5, 6})); + std::cout << "st.dimension()=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 6); + st.automatic_dimension_set(); + std::cout << "st.dimension()=" << st.dimension() << std::endl; BOOST_CHECK(st.dimension() == 5); } @@ -325,6 +342,11 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) { // Display the Simplex_tree std::cout << "The complex pruned at 0.0 contains " << st.num_simplices() << " simplices"; std::cout << " - dimension " << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == 3); + + st.automatic_dimension_set(); + std::cout << "dimension=" << st.dimension() << std::endl; + BOOST_CHECK(st.dimension() == -1); BOOST_CHECK(st == st_empty); BOOST_CHECK(simplex_is_changed); -- cgit v1.2.3