summaryrefslogtreecommitdiff
path: root/src/Simplex_tree
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-01-12 16:07:10 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-01-12 16:07:10 +0000
commit11b195d4e26d48cdc56883957cbad16e298e43ca (patch)
tree0cbe94cf64b53ed9a84050689db0811795fdba51 /src/Simplex_tree
parentf9b5b9b3306f3f00f5bfa2724cbfa087d5161fcb (diff)
Fix alpha complex remarks and bugs
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@957 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fa837fd1a4373c2322db16353d98767907f34c79
Diffstat (limited to 'src/Simplex_tree')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h81
-rw-r--r--src/Simplex_tree/test/simplex_tree_unit_test.cpp56
2 files changed, 51 insertions, 86 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 4b04e75a..d4f9aeae 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -1160,43 +1160,28 @@ std::cout << "prune_above_filtration - filtration=" << filtration << std::endl;
threshold_ = filtration;
// Initialize filtration_vect_ if required
if (filtration_vect_.empty()) {
-std::cout << "prune_above_filtration - initialize_filtration" << std::endl;
initialize_filtration();
}
-
-std::cout << "prune_above_filtration - after initialize_filtration ";
-for(auto sh : filtration_vect_) {
-for (auto vertex : simplex_vertex_range(sh)) {
-std::cout << (int) vertex << ", ";
-}
-std::cout << " - filtration=" << sh->second.filtration() << " - " << &(sh->second) << std::endl;
-}
-
+ std::vector<std::vector<Vertex_handle>> simplex_list_to_removed;
// Loop in reverse mode until threshold is reached
- auto f_simplex = filtration_vect_.rbegin();
- for (; (f_simplex != filtration_vect_.rend()) && ((*f_simplex)->second.filtration() > threshold_); f_simplex++) {
-
-std::cout << "prune_above_filtration - remove ";
-for (auto vertex : simplex_vertex_range(*f_simplex)) {
-std::cout << (int) vertex << ", ";
-}
-std::cout << " - " << &((*f_simplex)->second) << std::endl;
-
- remove_maximal_simplex(*f_simplex);
+ // 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);
}
-std::cout << "prune_above_filtration - remove STOPPED ON ";
-for (auto vertex : simplex_vertex_range(*f_simplex)) {
-std::cout << (int) vertex << ", ";
-}
-std::cout << " - filtration=" << (*f_simplex)->second.filtration() << " - " << &(*f_simplex->second) << std::endl;
- if (f_simplex != filtration_vect_.rbegin()) {
- // Do not forget to update filtration_vect_ - resize is enough
- std::size_t new_size = filtration_vect_.size() - (f_simplex - filtration_vect_.rbegin());
-std::cout << "prune_above_filtration - resize" << new_size << std::endl;
- filtration_vect_.resize(new_size);
+ 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();
}
}
}
@@ -1205,6 +1190,7 @@ std::cout << "prune_above_filtration - resize" << new_size << std::endl;
* @param[in] sh Simplex handle on the maximal simplex to remove.
* \pre Please check the simplex has no coface before removing it.
* \warning In debug mode, the exception std::invalid_argument is thrown if sh has children.
+ * \warning Be aware that removing is shifting data in a flat_map (initialize_filtration to be done).
*/
void remove_maximal_simplex(Simplex_handle sh) {
// Guarantee the simplex has no children
@@ -1213,49 +1199,18 @@ std::cout << "prune_above_filtration - resize" << new_size << std::endl;
// Simplex is a leaf, it means the child is the Siblings owning the leaf
Siblings* child = sh->second.children();
+
if ((child->size() > 1) || (child == root())) {
// Not alone, just remove it from members
// Special case when child is the root of the simplex tree, just remove it from members
-std::cout << "remove_maximal_simplex - members removal" << std::endl;
child->erase(sh->first);
} else {
// Sibling is emptied : must be deleted, and its parent must point on his own Sibling
-std::cout << "remove_maximal_simplex - members is empty" << std::endl;
child->oncles()->members().at(child->parent()).assign_children(child->oncles());
delete child;
}
}
-/***************************************************************************************************************/
- public:
- /** \brief Prints the simplex_tree hierarchically.
- * Since it prints the vertices recursively, one can watch its tree shape.
- */
- void print_tree() {
- for (auto sh = root_.members().begin(); sh != root_.members().end(); ++sh) {
- std::cout << sh->first << " ";
- if (has_children(sh)) {
- std::cout << "(";
- rec_print(sh->second.children());
- std::cout << ")";
- }
- std::cout << std::endl;
- }
- }
-
- /** \brief Recursively prints the simplex_tree, using depth first search. */
- private:
- void rec_print(Siblings * sib) {
- for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh) {
- std::cout << " " << sh->first << " ";
- if (has_children(sh)) {
- std::cout << "(";
- rec_print(sh->second.children());
- std::cout << ")";
- }
- }
- }
-/*****************************************************************************************************************/
private:
Vertex_handle null_vertex_;
/** \brief Upper bound on the filtration values of the simplices.*/
diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
index f6bd5411..0d73d347 100644
--- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp
+++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp
@@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) {
// Display the Simplex_tree - Can not be done in the middle of 2 inserts
std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl;
std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
- std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << 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)) {
@@ -549,7 +549,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) {
// Display the Simplex_tree - Can not be done in the middle of 2 inserts
std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl;
std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
- std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << 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)) {
@@ -805,7 +805,7 @@ struct MyOptions : Simplex_tree_options_full_featured {
};
typedef Simplex_tree<MyOptions> miniST;
-/*BOOST_AUTO_TEST_CASE(remove_maximal_simplex) {
+BOOST_AUTO_TEST_CASE(remove_maximal_simplex) {
std::cout << "********************************************************************" << std::endl;
std::cout << "REMOVE MAXIMAL SIMPLEX" << std::endl;
@@ -887,7 +887,7 @@ typedef Simplex_tree<MyOptions> miniST;
st.remove_maximal_simplex(st.find({7}));
BOOST_CHECK(st == st_wo_seven);
-}*/
+}
BOOST_AUTO_TEST_CASE(prune_above_filtration) {
std::cout << "********************************************************************" << std::endl;
@@ -939,10 +939,10 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
st.prune_above_filtration(5.0);
BOOST_CHECK(st == st_complete);
- // Display the Simplex_tree - Can not be done in the middle of 2 inserts
+ // Display the Simplex_tree
std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl;
std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
- std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << 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)) {
@@ -955,35 +955,45 @@ BOOST_AUTO_TEST_CASE(prune_above_filtration) {
// Set the st_pruned filtration for operator==
st_pruned.set_filtration(2.5);
st.prune_above_filtration(2.5);
- /*BOOST_CHECK(st == st_pruned);
+ 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 << " - 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);
BOOST_CHECK(st == st_pruned);
-*/
-/* std::cout << "The complex contains " << st.num_simplices() << " simplices --------------------------" << std::endl;
- std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
- st.print_tree();
- std::cout << "The pruned complex contains " << st_pruned.num_simplices() << " simplices --------------------------" << std::endl;
- std::cout << " - dimension " << st_pruned.dimension() << " - filtration " << st_pruned.filtration() << std::endl;
- st_pruned.print_tree();
-
typeST st_empty;
// FIXME
st_empty.set_dimension(3);
st.prune_above_filtration(0.0);
- */
- /*BOOST_CHECK(st == st_empty);
+
+ // Display the Simplex_tree
+ std::cout << "The complex pruned at 0.0 contains " << st.num_simplices() << " simplices" << std::endl;
+ 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);
-*/
}
-
-/*BOOST_AUTO_TEST_CASE(sanitizer) {
- int a[2] = {1, 0};
- int b=a[2];
-}*/