From 8cb0b53a28b9d4cf6b97abcffbb527b51e322a22 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 3 Feb 2016 10:15:31 +0000 Subject: make_filtration_non_decreasing and rec_make_filtration_non_decreasing must go through the tree in reverse mode (starting from the right part) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@997 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0c8f8aeabd7dcba26971381c425ef7b0b417138c --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 33 +++++++++++----------- .../gudhi/Simplex_tree/Simplex_tree_iterators.h | 3 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 3911f497..0d12e9b7 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -35,6 +35,7 @@ #include #include #include +#include #ifdef GUDHI_USE_TBB #include @@ -307,8 +308,8 @@ class Simplex_tree { * of the simplex. * * @param[in] sh Simplex for which the boundary is computed. */ - template - Boundary_simplex_range boundary_simplex_range(DictionaryIterator sh) { + template + Boundary_simplex_range boundary_simplex_range(SimplexHandle sh) { return Boundary_simplex_range(Boundary_simplex_iterator(this, sh), Boundary_simplex_iterator(this)); } @@ -529,11 +530,8 @@ class Simplex_tree { /** \brief Returns true if the node in the simplex tree pointed by * sh has children.*/ - /*bool has_children(Simplex_handle sh) const { - return (sh->second.children()->parent() == sh->first); - }*/ - template - bool has_children(DictionaryIterator sh) const { + template + bool has_children(SimplexHandle sh) const { return (sh->second.children()->parent() == sh->first); } @@ -765,7 +763,8 @@ class Simplex_tree { } /** Returns the Siblings containing a simplex.*/ - Siblings * self_siblings(Simplex_handle sh) { + template + Siblings* self_siblings(SimplexHandle sh) { if (sh->second.children()->parent() == sh->first) return sh->second.children()->oncles(); else @@ -1133,9 +1132,9 @@ class Simplex_tree { bool make_filtration_non_decreasing() { bool modified = false; // Loop must be from the end to the beginning, as higher dimension simplex are always on the left part of the tree - for (auto sh = root_.members().rbegin(); sh != root_.members().rend(); ++sh) { - if (has_children(sh)) { - modified |= rec_make_filtration_non_decreasing(sh->second.children()); + for (auto& sh : boost::adaptors::reverse(root_.members())) { + if (has_children(&sh)) { + modified |= rec_make_filtration_non_decreasing(sh.second.children()); } } return modified; @@ -1150,22 +1149,22 @@ class Simplex_tree { bool modified = false; // Loop must be from the end to the beginning, as higher dimension simplex are always on the left part of the tree - for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh) { + for (auto& sh : boost::adaptors::reverse(sib->members())) { // Find the maximum filtration value in the border - Boundary_simplex_range boundary = boundary_simplex_range(sh); + Boundary_simplex_range boundary = boundary_simplex_range(&sh); Boundary_simplex_iterator max_border = std::max_element(std::begin(boundary), std::end(boundary), [](Simplex_handle sh1, Simplex_handle sh2) { return filtration(sh1) < filtration(sh2); } ); Filtration_value max_filt_border_value = filtration(*max_border); - if (sh->second.filtration() < max_filt_border_value) { + if (sh.second.filtration() < max_filt_border_value) { // Store the filtration modification information modified = true; - sh->second.assign_filtration(max_filt_border_value); + sh.second.assign_filtration(max_filt_border_value); } - if (has_children(sh)) { - modified |= rec_make_filtration_non_decreasing(sh->second.children()); + if (has_children(&sh)) { + modified |= rec_make_filtration_non_decreasing(sh.second.children()); } } // Make the modified information to be traced by upper call 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 936b7a1f..7e0a454d 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 @@ -104,7 +104,8 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< st_(st) { } - Simplex_tree_boundary_simplex_iterator(SimplexTree * st, Simplex_handle sh) + template + Simplex_tree_boundary_simplex_iterator(SimplexTree * st, SimplexHandle sh) : last_(sh->first), sib_(nullptr), st_(st) { -- cgit v1.2.3