summaryrefslogtreecommitdiff
path: root/src/Simplex_tree/include
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-19 13:41:40 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-08-19 13:41:40 +0000
commit0d427fd713cceddd8335e6e6bbac74db18e5dd7c (patch)
treeb61d109a58fc5611923f141ccd6d63f7c3a00343 /src/Simplex_tree/include
parent16883d241da01ee3928b2214ce9fa8a44ba35d51 (diff)
num_simplices computation instead of increment/set methods.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/num_simplices@743 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 42bad5e259ea540b5ec020f293b2dff86c83101f
Diffstat (limited to 'src/Simplex_tree/include')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 153401d6..db5de0b8 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -280,7 +280,6 @@ class Simplex_tree {
Simplex_tree()
: null_vertex_(-1),
threshold_(0),
- num_simplices_(0),
root_(NULL, null_vertex_),
filtration_vect_(),
dimension_(-1) { }
@@ -361,13 +360,35 @@ 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. */
+ long long int num_simplices() {
+ auto sib_begin = root_.members().begin();
+ auto sib_end = root_.members().end();
+ long long int simplices_number = sib_end - sib_begin;
+ for (auto sh = sib_begin; sh != sib_end; ++sh) {
+ if (has_children(sh)) {
+ simplices_number += rec_num_simplices(sh->second.children());
+ }
+ }
+ return simplices_number;
}
+ private:
+ /** \brief returns the number of simplices in the simplex_tree. */
+ long long int rec_num_simplices(Siblings * sib = nullptr) {
+ auto sib_begin = sib->members().begin();
+ auto sib_end = sib->members().end();
+ long long int simplices_number = sib_end - sib_begin;
+ for (auto sh = sib_begin; sh != sib_end; ++sh) {
+ if (has_children(sh)) {
+ simplices_number += rec_num_simplices(sh->second.children());
+ }
+ }
+ return simplices_number;
+ }
+
+ public:
/** \brief Returns the dimension of a simplex.
*
* Must be different from null_simplex().*/
@@ -510,15 +531,9 @@ class Simplex_tree {
}
// N-Simplex insert
std::pair<Simplex_handle, bool> returned = insert_simplex(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(Nsimplex, filtration);
- if (returned.second == true) {
- num_simplices_++;
- }
} else {
// Nothing to insert - empty vector
}
@@ -569,11 +584,6 @@ class Simplex_tree {
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;
@@ -770,8 +780,6 @@ class Simplex_tree {
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,
@@ -850,7 +858,6 @@ class Simplex_tree {
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
@@ -913,7 +920,6 @@ class Simplex_tree {
/** \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.*/
@@ -938,17 +944,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) {
@@ -961,7 +963,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);