summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h49
-rw-r--r--src/Simplex_tree/test/simplex_tree_unit_test.cpp40
2 files changed, 61 insertions, 28 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 92f4576d..ac5fbe79 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -1179,33 +1179,30 @@ class Simplex_tree {
* call `initialize_filtration()` to recompute it.
*/
void prune_above_filtration(Filtration_value filtration) {
- // No action if filtration is not stored
- if (Options::store_filtration) {
- // Initialize filtration_vect_ if required
- if (filtration_vect_.empty()) {
- initialize_filtration();
- }
-
- std::vector<std::vector<Vertex_handle>> simplex_list_to_removed;
- // Loop in reverse mode until threshold is reached
- // Do not erase while looping, because removing is shifting data in a flat_map
- for (auto f_simplex = filtration_vect_.rbegin();
- (f_simplex != filtration_vect_.rend()) && ((*f_simplex)->second.filtration() > filtration);
- f_simplex++) {
- std::vector<Vertex_handle> simplex_to_remove;
- for (auto vertex : simplex_vertex_range(*f_simplex))
- simplex_to_remove.insert(simplex_to_remove.begin(), vertex);
- simplex_list_to_removed.push_back(simplex_to_remove);
- }
- for (auto simplex_to_remove : simplex_list_to_removed) {
- Simplex_handle sh = find_simplex(simplex_to_remove);
- if (sh != null_simplex())
- remove_maximal_simplex(sh);
- }
- // Re-initialize filtration_vect_ if dta were removed, because removing is shifting data in a flat_map
- if (simplex_list_to_removed.size() > 0)
- initialize_filtration();
+ // Initialize filtration_vect_ if required
+ if (filtration_vect_.empty()) {
+ initialize_filtration();
+ }
+
+ std::vector<std::vector<Vertex_handle>> simplex_list_to_removed;
+ // Loop in reverse mode until threshold is reached
+ // Do not erase while looping, because removing is shifting data in a flat_map
+ for (auto f_simplex = filtration_vect_.rbegin();
+ (f_simplex != filtration_vect_.rend()) && ((*f_simplex)->second.filtration() > filtration);
+ f_simplex++) {
+ std::vector<Vertex_handle> simplex_to_remove;
+ for (auto vertex : simplex_vertex_range(*f_simplex))
+ simplex_to_remove.insert(simplex_to_remove.begin(), vertex);
+ simplex_list_to_removed.push_back(simplex_to_remove);
}
+ for (auto simplex_to_remove : simplex_list_to_removed) {
+ Simplex_handle sh = find_simplex(simplex_to_remove);
+ if (sh != null_simplex())
+ remove_maximal_simplex(sh);
+ }
+ // Re-initialize filtration_vect_ if dta were removed, because removing is shifting data in a flat_map
+ if (simplex_list_to_removed.size() > 0)
+ initialize_filtration();
}
/** \brief Remove a maximal simplex.
diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
index ff8993b3..b8c1cc35 100644
--- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp
+++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
@@ -985,7 +985,6 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
st.insert_simplex_and_subfaces({0, 1, 6, 7}, 1.0);
st.insert_simplex_and_subfaces({3, 4, 5}, 2.0);
- st.set_filtration(6.0);
// Constructs a copy at this state for further test purpose
typeST st_pruned = st;
@@ -1053,7 +1052,6 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
BOOST_CHECK(st == st_pruned);
typeST st_empty;
- st_empty.set_filtration(6.0); // For equality reason
// FIXME
st_empty.set_dimension(3);
st.prune_above_filtration(0.0);
@@ -1068,3 +1066,41 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
st.prune_above_filtration(-1.0);
BOOST_CHECK(st == st_empty);
}
+
+BOOST_AUTO_TEST_CASE(mini_prune_above_filtration) {
+ std::cout << "********************************************************************" << std::endl;
+ std::cout << "MINI PRUNE ABOVE FILTRATION" << std::endl;
+ typedef Simplex_tree<MyOptions> typeST;
+ typeST st;
+
+ // FIXME
+ st.set_dimension(3);
+
+ st.insert_simplex_and_subfaces({0, 1, 6, 7});
+ st.insert_simplex_and_subfaces({3, 4, 5});
+ st.insert_simplex_and_subfaces({3, 0});
+ st.insert_simplex_and_subfaces({2, 1, 0});
+
+ // st:
+ // 1 6
+ // o---o
+ // /X\7/
+ // o---o---o---o
+ // 2 0 3\X/4
+ // o
+ // 5
+
+ st.initialize_filtration();
+
+ // Display the Simplex_tree
+ std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl;
+ BOOST_CHECK(st.num_simplices() == 27);
+
+ // Test case to the limit
+ st.prune_above_filtration(-1.0);
+
+ // Display the Simplex_tree
+ std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl;
+ BOOST_CHECK(st.num_simplices() == 0);
+
+} \ No newline at end of file