summaryrefslogtreecommitdiff
path: root/src/Simplex_tree/include
diff options
context:
space:
mode:
authoranmoreau <anmoreau@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-24 12:29:38 +0000
committeranmoreau <anmoreau@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-24 12:29:38 +0000
commit3a93273f03427c1275bdb166a0d04047ee9b169d (patch)
treea23c05c27ee64207e0a1d73d5bdba837f9321eda /src/Simplex_tree/include
parent64b0284cef1f590efdeb8e50bf09dcdb6cea7947 (diff)
parent56f297d7338abf37ed788cace18e883d3dde1e7f (diff)
fix
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/copy_move@755 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 753dc7c276758bb612cf1be4ade131724716828d
Diffstat (limited to 'src/Simplex_tree/include')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h76
1 files changed, 37 insertions, 39 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 57e9b987..6b016fc3 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -281,13 +281,17 @@ class Simplex_tree {
Simplex_tree()
: null_vertex_(-1),
threshold_(0),
- num_simplices_(0),
root_(NULL, null_vertex_),
filtration_vect_(),
dimension_(-1) { }
/** \brief Copy; copy the whole tree structure. */
- Simplex_tree(Simplex_tree& copy) : null_vertex_(copy.null_vertex_), threshold_(copy.threshold_), num_simplices_(copy.num_simplices_), root_(NULL, -1, std::vector<std::pair<Vertex_handle, Node>> (copy.root_.members().begin(), copy.root_.members().end())), filtration_vect_(copy.filtration_vect_), dimension_(copy.dimension_) {
+ Simplex_tree(Simplex_tree& copy) : null_vertex_(copy.null_vertex_),
+ threshold_(copy.threshold_),
+ num_simplices_(copy.num_simplices_),
+ root_(NULL, -1, std::vector<std::pair<Vertex_handle, Node>> (copy.root_.members().begin(), copy.root_.members().end())),
+ filtration_vect_(copy.filtration_vect_),
+ dimension_(copy.dimension_) {
rec_copy(&root_, &copy.root_);
}
@@ -407,14 +411,14 @@ class Simplex_tree {
*
* The filtration must be initialized. */
static Simplex_key key(Simplex_handle sh) {
- return sh->second.key();
+ return sh->second.key();
}
/** \brief Returns the simplex associated to a key.
*
* The filtration must be initialized. */
Simplex_handle simplex(Simplex_key key) const {
- return filtration_vect_[key];
+ return filtration_vect_[key];
}
/** \brief Returns the filtration value of a simplex.
@@ -458,13 +462,27 @@ class Simplex_tree {
return root_.members_.size();
}
- /** \brief Returns the number of simplices in the complex.
- *
- * Does not count the empty simplex. */
- unsigned int num_simplices() const {
- return num_simplices_;
+ public:
+ /** \brief returns the number of simplices in the simplex_tree. */
+ size_t num_simplices() {
+ return num_simplices(&root_);
+ }
+
+ private:
+ /** \brief returns the number of simplices in the simplex_tree. */
+ size_t num_simplices(Siblings * sib) {
+ auto sib_begin = sib->members().begin();
+ auto sib_end = sib->members().end();
+ size_t simplices_number = sib_end - sib_begin;
+ for (auto sh = sib_begin; sh != sib_end; ++sh) {
+ if (has_children(sh)) {
+ simplices_number += num_simplices(sh->second.children());
+ }
+ }
+ return simplices_number;
}
+ public:
/** \brief Returns the dimension of a simplex.
*
* Must be different from null_simplex().*/
@@ -630,15 +648,9 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
}
// N-Simplex insert
std::pair<Simplex_handle, bool> returned = insert_simplex_rec(Nsimplex, filtration);
- if (returned.second == true) {
- num_simplices_++;
- }
} else if (Nsimplex.size() == 1) {
// 1-Simplex insert - End of recursivity
std::pair<Simplex_handle, bool> returned = insert_simplex_rec(Nsimplex, filtration);
- if (returned.second == true) {
- num_simplices_++;
- }
} else {
// Nothing to insert - empty vector
}
@@ -691,11 +703,6 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
threshold_ = fil;
}
- /** Set a number of simplices for the simplicial complex. */
- void set_num_simplices(unsigned int num_simplices) {
- num_simplices_ = num_simplices;
- }
-
/** Set a dimension for the simplicial complex. */
void set_dimension(int dimension) {
dimension_ = dimension;
@@ -749,18 +756,18 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
}
-/** \brief recursively insert the members of a Sibling into another, any time the key exists into the target Sibling
+/** \brief recursively insert the members of a Sibling into another, any time the replacedVertex appears into the target Sibling
\param sibInserted The sibling to be inserted
\param sibTarget The target sibling on which the other sibling is copied
- \param key The key (Vertex_handle) needed to insert the sibling
+ \param replacedVertex The replacedVertex (Vertex_handle) needed to insert the sibling
*/
- void rec_insert(Siblings * sibInserted, Siblings * sibTarget, Vertex_handle key)
+ void rec_insert(Siblings * sibInserted, Siblings * sibTarget, Vertex_handle replacedVertex)
{
for (auto sh = sibTarget->members().begin(); sh != sibTarget->members().end(); ++sh)
{
if (has_children(sh))
- rec_insert(sibInserted, sh->second.children(), key);
- if (sh->first == key)
+ rec_insert(sibInserted, sh->second.children(), replacedVertex);
+ if (sh->first == replacedVertex)
insert_members(sibTarget, sibInserted);
}
}
@@ -788,17 +795,17 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
}
}
-/** \brief Erase every occurencies of a key in a Sibling
+/** \brief Erase every occurencies of a vertex in a Sibling
\param sib The sibling on which we wan't to erase the elements
- \param key The key of the members we wan't to erase
+ \param deletedVertex The value of the members we wan't to erase
*/
- void rec_delete(Siblings * sib, Vertex_handle key)
+ void rec_delete(Siblings * sib, Vertex_handle deletedVertex)
{
for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh)
{
if (has_children(sh))
- rec_delete(sh->second.children(), key);
- if (sh->first == key)
+ rec_delete(sh->second.children(), deletedVertex);
+ if (sh->first == deletedVertex)
sib->members_.erase(sh);
}
}
@@ -967,8 +974,6 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
dimension_ = 1;
}
- num_simplices_ = boost::num_vertices(skel_graph)
- + boost::num_edges(skel_graph);
root_.members_.reserve(boost::num_vertices(skel_graph));
typename boost::graph_traits<OneSkeletonGraph>::vertex_iterator v_it,
@@ -1047,7 +1052,6 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
root_sh->second.children()->members().end(),
s_h->second.filtration());
if (inter.size() != 0) {
- this->num_simplices_ += inter.size();
Siblings * new_sib = new Siblings(siblings, // oncles
s_h->first, // parent
inter); // boost::container::ordered_unique_range_t
@@ -1110,7 +1114,6 @@ std::pair<Simplex_handle, bool> insert_simplex(const RandomAccessVertexRange & s
/** \brief Upper bound on the filtration values of the simplices.*/
Filtration_value threshold_;
/** \brief Total number of simplices in the complex, without the empty simplex.*/
- unsigned int num_simplices_;
/** \brief Set of simplex tree Nodes representing the vertices.*/
Siblings root_;
/** \brief Simplices ordered according to a filtration.*/
@@ -1135,17 +1138,13 @@ std::ostream& operator<<(std::ostream & os, Simplex_tree<T...> & st) {
template<typename...T>
std::istream& operator>>(std::istream & is, Simplex_tree<T...> & st) {
- // assert(st.num_simplices() == 0);
-
typedef Simplex_tree<T...> ST;
std::vector<typename ST::Vertex_handle> simplex;
typename ST::Filtration_value fil;
typename ST::Filtration_value max_fil = 0;
int max_dim = -1;
- size_t num_simplices = 0;
while (read_simplex(is, simplex, fil)) {
// read all simplices in the file as a list of vertices
- ++num_simplices;
// Warning : simplex_size needs to be casted in int - Can be 0
int dim = static_cast<int> (simplex.size() - 1);
if (max_dim < dim) {
@@ -1158,7 +1157,6 @@ std::istream& operator>>(std::istream & is, Simplex_tree<T...> & st) {
st.insert_simplex(simplex, fil);
simplex.clear();
}
- st.set_num_simplices(num_simplices);
st.set_dimension(max_dim);
st.set_filtration(max_fil);