From 4b5f5c47e681a92f85d390cc5763f39a033ba354 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 28 Jun 2019 16:11:49 +0200 Subject: We can now roll back rec_insert_simplex_and_subfaces_sorted and dimension computation --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 28 +++++++++------------------ 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 9d6e50c6..f1697955 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -782,18 +782,19 @@ class Simplex_tree { for (Vertex_handle v : copy) GUDHI_CHECK(v != null_vertex(), "cannot use the dummy null_vertex() as a real vertex"); ) + // Update dimension if needed. We could wait to see if the insertion succeeds, but I doubt there is much to gain. + dimension_ = (std::max)(dimension_, static_cast(std::distance(copy.begin(), copy.end())) - 1); - return rec_insert_simplex_and_subfaces_sorted(root(), copy.begin(), copy.end(), filtration, 0); + return rec_insert_simplex_and_subfaces_sorted(root(), copy.begin(), copy.end(), filtration); } private: // To insert {1,2,3,4}, we insert {2,3,4} twice, once at the root, and once below 1. template std::pair rec_insert_simplex_and_subfaces_sorted(Siblings* sib, - ForwardVertexIterator first, - ForwardVertexIterator last, - Filtration_value filt, - int dimension) { + ForwardVertexIterator first, + ForwardVertexIterator last, + Filtration_value filt) { // An alternative strategy would be: // - try to find the complete simplex, if found (and low filtration) exit // - insert all the vertices at once in sib @@ -811,24 +812,13 @@ class Simplex_tree { insertion_result.first = null_simplex(); } } - // Next iteration to avoid consecutive equal values - while ((first < last) && (vertex_one == *first)) { - ++first; - } - // End of insertion - if (first == last) { - dimension_ = (std::max)(dimension_, dimension); - return insertion_result; - } + if (++first == last) return insertion_result; if (!has_children(simplex_one)) // TODO: have special code here, we know we are building the whole subtree from scratch. simplex_one->second.assign_children(new Siblings(sib, vertex_one)); - ++dimension; - auto res = rec_insert_simplex_and_subfaces_sorted(simplex_one->second.children(), first, last, filt, dimension); + auto res = rec_insert_simplex_and_subfaces_sorted(simplex_one->second.children(), first, last, filt); // No need to continue if the full simplex was already there with a low enough filtration value. - if (res.first != null_simplex()) { - rec_insert_simplex_and_subfaces_sorted(sib, first, last, filt, dimension); - } + if (res.first != null_simplex()) rec_insert_simplex_and_subfaces_sorted(sib, first, last, filt); return res; } -- cgit v1.2.3