summaryrefslogtreecommitdiff
path: root/src/Simplex_tree/include/gudhi
diff options
context:
space:
mode:
authoranmoreau <anmoreau@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-06-26 15:05:38 +0000
committeranmoreau <anmoreau@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-06-26 15:05:38 +0000
commit67b00eb17785cf8abb08055a83b631904b9c5746 (patch)
tree807ac1c2de47b9ce2cf49e8577ecc62cda996936 /src/Simplex_tree/include/gudhi
parentd5b0a3a37dd9df91a0036661e1ca00576c4a2880 (diff)
fix + edge_contraction + print_tree
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/copy_move@657 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2c63af50eec59e37e933e6bd7e1810de943e9b48
Diffstat (limited to 'src/Simplex_tree/include/gudhi')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h69
1 files changed, 66 insertions, 3 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 79c7cd2e..63671d63 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -314,7 +314,8 @@ class Simplex_tree {
}
/** rec_copy: DFS, inserts simplices when reaching a leaf.*/
- void rec_copy(Siblings * sib, std::vector<Vertex_handle> v)
+ template <typename RandomAccessVertexRange>
+ void rec_copy(Siblings * sib, RandomAccessVertexRange v)
{
for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh)
{
@@ -361,7 +362,40 @@ class Simplex_tree {
}
public:
+ /** \brief Prints the simplex_tree hierarchically. */
+ 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 DFS. */
+ 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 << ")";
+ }
+ }
+ }
+ public:
/** \brief Checks whether or not two simplex trees are equal. */
bool operator ==(Simplex_tree st2)
@@ -490,7 +524,7 @@ bool has_children(Simplex_handle sh) {
*/
template<class RandomAccessVertexRange>
Simplex_handle find(RandomAccessVertexRange & s) {
- std::vector<Vertex_handle> copy = s;
+ RandomAccessVertexRange copy = s;
sort(s.begin(), s.end());
return find_rec(s);
}
@@ -581,7 +615,7 @@ public:
template<class RandomAccessVertexRange>
std::pair<Simplex_handle, bool> insert_simplex(RandomAccessVertexRange & simplex,
Filtration_value filtration) {
- std::vector<Vertex_handle> copy = simplex;
+ RandomAccessVertexRange copy = simplex;
sort(copy.begin(), copy.end());
return insert_simplex_rec(copy, filtration);
}
@@ -720,6 +754,35 @@ std::pair<Simplex_handle, bool> insert_simplex(RandomAccessVertexRange & simplex
is_before_in_filtration(this));
}
+/** \brief Contracts two edges
+ \param deleted The base of the edge to be contracted
+ \param remaining The new vertex with children and variables of the former
+*/
+ void edge_contraction(Simplex_handle & deleted, Simplex_handle & remaining)
+ {
+ Siblings * sibDeleted, * sibRemaining; // We need the siblings
+ sibDeleted = (has_children(deleted) ? deleted->second.children()->oncles() : deleted->second.children());
+ sibRemaining = (has_children(remaining) ? remaining->second.children()->oncles() : remaining->second.children());
+ // Add all edges to vertex
+ if (has_children(deleted))
+ {
+ std::deque<Vertex_handle> v;
+ Vertex_handle vertex = sibRemaining->parent_;
+ Siblings * sib_tmp = sibRemaining->oncles();
+ while (vertex != -1)
+ {
+ v.push_front(vertex);
+ vertex = sib_tmp->parent_;
+ sib_tmp = sib_tmp->oncles();
+ }
+ v.push_back(remaining->first);
+ v.push_back(deleted->first);
+ rec_copy(deleted->second.children(), v);
+ }
+ // Delete the contracted edge
+ sibDeleted->members().erase(deleted->first);
+ }
+
private:
/** \brief Returns true iff the list of vertices of sh1
* is smaller than the list of vertices of sh2 w.r.t.