summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-03-14 13:42:22 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-03-14 13:42:22 +0000
commit07fe71e2301f95fd0008bfc91e72f07b4f0d9bb6 (patch)
tree1e70fe39894edd07c1c6b9c801f5f86c5ed5962e /src
parent558d908404cdc2e1f5111fd9ee236cd55ab7790a (diff)
No more use of threshold_ for prune_above_filtration because threshold may be not up to date
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@1043 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b17d8ef63bc173b4c4b6b0bde31f97d85672a754
Diffstat (limited to 'src')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h48
-rw-r--r--src/Simplex_tree/test/simplex_tree_unit_test.cpp35
2 files changed, 32 insertions, 51 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 813e7924..92f4576d 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -1174,7 +1174,6 @@ class Simplex_tree {
public:
/** \brief Prune above filtration value given as parameter.
* @param[in] filtration Maximum threshold value.
- * \warning threshold_ is set from filtration given as parameter.
* \warning 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.
@@ -1182,33 +1181,30 @@ class Simplex_tree {
void prune_above_filtration(Filtration_value filtration) {
// No action if filtration is not stored
if (Options::store_filtration) {
- if (filtration < threshold_) {
- threshold_ = filtration;
- // Initialize filtration_vect_ if required
- if (filtration_vect_.empty()) {
- 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() > threshold_);
- 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();
+ 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();
}
}
diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
index cd6746a6..ff8993b3 100644
--- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp
+++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
@@ -989,7 +989,7 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
// Constructs a copy at this state for further test purpose
typeST st_pruned = st;
- st_pruned.initialize_filtration(); // reset
+ st_pruned.initialize_filtration(); // reset
st.insert_simplex_and_subfaces({3, 0}, 3.0);
st.insert_simplex_and_subfaces({2, 1, 0}, 4.0);
@@ -1021,12 +1021,11 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
st.prune_above_filtration(6.0);
BOOST_CHECK(st == st_complete);
// lower than initial filtration value, but still greater than the maximum filtration value
- st_complete.set_filtration(5.0);
st.prune_above_filtration(5.0);
BOOST_CHECK(st == st_complete);
// Display the Simplex_tree
- std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl;
+ std::cout << "The complex contains " << st.num_simplices() << " simplices";
std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl;
for (auto f_simplex : st.filtration_simplex_range()) {
@@ -1039,47 +1038,33 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
// Check the pruned cases
// Set the st_pruned filtration for operator==
- st_pruned.set_filtration(2.5);
st.prune_above_filtration(2.5);
BOOST_CHECK(st == st_pruned);
// Display the Simplex_tree
- std::cout << "The complex pruned at 2.5 contains " << st.num_simplices() << " simplices" << std::endl;
+ std::cout << "The complex pruned at 2.5 contains " << st.num_simplices() << " simplices";
std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << 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 << (int) vertex << " ";
- }
- std::cout << std::endl;
- }
- st_pruned.set_filtration(2.0);
st.prune_above_filtration(2.0);
+
+ std::cout << "The complex pruned at 2.0 contains " << st.num_simplices() << " simplices";
+ std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
+
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);
- // Display the Simplex_tree
- std::cout << "The complex pruned at 0.0 contains " << st.num_simplices() << " simplices" << std::endl;
+ // Display the Simplex_tree
+ std::cout << "The complex pruned at 0.0 contains " << st.num_simplices() << " simplices";
std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << 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 << (int) vertex << " ";
- }
- std::cout << std::endl;
- }
BOOST_CHECK(st == st_empty);
// Test case to the limit
st.prune_above_filtration(-1.0);
- st_empty.set_filtration(-1.0);
BOOST_CHECK(st == st_empty);
}