Simplex_tree.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Clément Maria
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France)
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef SIMPLEX_TREE_H_
24 #define SIMPLEX_TREE_H_
25 
26 #include <gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h>
27 #include <gudhi/Simplex_tree/Simplex_tree_siblings.h>
28 #include <gudhi/Simplex_tree/Simplex_tree_iterators.h>
29 #include <gudhi/Simplex_tree/indexing_tag.h>
30 
31 #include <gudhi/reader_utils.h>
32 #include <gudhi/graph_simplicial_complex.h>
33 #include <gudhi/Debug_utils.h>
34 
35 #include <boost/container/flat_map.hpp>
36 #include <boost/iterator/transform_iterator.hpp>
37 #include <boost/graph/adjacency_list.hpp>
38 #include <boost/range/adaptor/reversed.hpp>
39 
40 #ifdef GUDHI_USE_TBB
41 #include <tbb/parallel_sort.h>
42 #endif
43 
44 #include <utility>
45 #include <vector>
46 #include <functional> // for greater<>
47 #include <stdexcept>
48 #include <limits> // Inf
49 #include <initializer_list>
50 #include <algorithm> // for std::max
51 #include <cstdint> // for std::uint32_t
52 #include <iterator> // for std::distance
53 
54 namespace Gudhi {
55 
56 struct Simplex_tree_options_full_featured;
57 
71 template<typename SimplexTreeOptions = Simplex_tree_options_full_featured>
72 class Simplex_tree {
73  public:
75  typedef typename Options::Indexing_tag Indexing_tag;
88 
89  /* Type of node in the simplex tree. */
90  typedef Simplex_tree_node_explicit_storage<Simplex_tree> Node;
91  /* Type of dictionary Vertex_handle -> Node for traversing the simplex tree. */
92  // Note: this wastes space when Vertex_handle is 32 bits and Node is aligned on 64 bits. It would be better to use a
93  // flat_set (with our own comparator) where we can control the layout of the struct (put Vertex_handle and
94  // Simplex_key next to each other).
95  typedef typename boost::container::flat_map<Vertex_handle, Node> Dictionary;
96 
97  /* \brief Set of nodes sharing a same parent in the simplex tree. */
98  /* \brief Set of nodes sharing a same parent in the simplex tree. */
99  typedef Simplex_tree_siblings<Simplex_tree, Dictionary> Siblings;
100 
101  struct Key_simplex_base_real {
102  Key_simplex_base_real() : key_(-1) {}
103  void assign_key(Simplex_key k) { key_ = k; }
104  Simplex_key key() const { return key_; }
105  private:
106  Simplex_key key_;
107  };
108  struct Key_simplex_base_dummy {
109  Key_simplex_base_dummy() {}
110  // Undefined so it will not link
111  void assign_key(Simplex_key);
112  Simplex_key key() const;
113  };
114  typedef typename std::conditional<Options::store_key, Key_simplex_base_real, Key_simplex_base_dummy>::type
115  Key_simplex_base;
116 
117  struct Filtration_simplex_base_real {
118  Filtration_simplex_base_real() : filt_(0) {}
119  void assign_filtration(Filtration_value f) { filt_ = f; }
120  Filtration_value filtration() const { return filt_; }
121  private:
122  Filtration_value filt_;
123  };
124  struct Filtration_simplex_base_dummy {
125  Filtration_simplex_base_dummy() {}
126  void assign_filtration(Filtration_value GUDHI_CHECK_code(f)) { GUDHI_CHECK(f == 0, "filtration value specified for a complex that does not store them"); }
127  Filtration_value filtration() const { return 0; }
128  };
129  typedef typename std::conditional<Options::store_filtration, Filtration_simplex_base_real,
130  Filtration_simplex_base_dummy>::type Filtration_simplex_base;
131 
132  public:
135  typedef typename Dictionary::iterator Simplex_handle;
136 
137  private:
138  typedef typename Dictionary::iterator Dictionary_it;
139  typedef typename Dictionary_it::value_type Dit_value_t;
140 
141  struct return_first {
142  Vertex_handle operator()(const Dit_value_t& p_sh) const {
143  return p_sh.first;
144  }
145  };
146 
147  public:
159  typedef boost::transform_iterator<return_first, Dictionary_it> Complex_vertex_iterator;
161  typedef boost::iterator_range<Complex_vertex_iterator> Complex_vertex_range;
165  typedef Simplex_tree_simplex_vertex_iterator<Simplex_tree> Simplex_vertex_iterator;
167  typedef boost::iterator_range<Simplex_vertex_iterator> Simplex_vertex_range;
169  typedef std::vector<Simplex_handle> Cofaces_simplex_range;
173  typedef Simplex_tree_boundary_simplex_iterator<Simplex_tree> Boundary_simplex_iterator;
175  typedef boost::iterator_range<Boundary_simplex_iterator> Boundary_simplex_range;
179  typedef Simplex_tree_complex_simplex_iterator<Simplex_tree> Complex_simplex_iterator;
181  typedef boost::iterator_range<Complex_simplex_iterator> Complex_simplex_range;
186  typedef Simplex_tree_skeleton_simplex_iterator<Simplex_tree> Skeleton_simplex_iterator;
189  typedef boost::iterator_range<Skeleton_simplex_iterator> Skeleton_simplex_range;
191  typedef std::vector<Simplex_handle> Filtration_simplex_range;
195  typedef typename Filtration_simplex_range::const_iterator Filtration_simplex_iterator;
196 
197  /* @} */ // end name range and iterator types
203  Complex_vertex_range complex_vertex_range() {
204  return Complex_vertex_range(
205  boost::make_transform_iterator(root_.members_.begin(), return_first()),
206  boost::make_transform_iterator(root_.members_.end(), return_first()));
207  }
208 
214  Complex_simplex_range complex_simplex_range() {
217  }
218 
228  Skeleton_simplex_range skeleton_simplex_range(int dim) {
231  }
232 
248  Filtration_simplex_range const& filtration_simplex_range(Indexing_tag = Indexing_tag()) {
249  if (filtration_vect_.empty()) {
251  }
252  return filtration_vect_;
253  }
254 
261  Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) {
262  assert(sh != null_simplex()); // Empty simplex
265  }
266 
281  template<class SimplexHandle>
282  Boundary_simplex_range boundary_simplex_range(SimplexHandle sh) {
285  }
286  // end range and iterator methods
293  : null_vertex_(-1),
294  root_(nullptr, null_vertex_),
295  filtration_vect_(),
296  dimension_(-1) { }
297 
299  Simplex_tree(const Simplex_tree& simplex_source)
300  : null_vertex_(simplex_source.null_vertex_),
301  root_(nullptr, null_vertex_ , simplex_source.root_.members_),
302  filtration_vect_(),
303  dimension_(simplex_source.dimension_) {
304  auto root_source = simplex_source.root_;
305  rec_copy(&root_, &root_source);
306  }
307 
309  void rec_copy(Siblings *sib, Siblings *sib_source) {
310  for (auto sh = sib->members().begin(), sh_source = sib_source->members().begin();
311  sh != sib->members().end(); ++sh, ++sh_source) {
312  if (has_children(sh_source)) {
313  Siblings * newsib = new Siblings(sib, sh_source->first);
314  newsib->members_.reserve(sh_source->second.children()->members().size());
315  for (auto & child : sh_source->second.children()->members())
316  newsib->members_.emplace_hint(newsib->members_.end(), child.first, Node(newsib, child.second.filtration()));
317  rec_copy(newsib, sh_source->second.children());
318  sh->second.assign_children(newsib);
319  }
320  }
321  }
322 
325  : null_vertex_(std::move(old.null_vertex_)),
326  root_(std::move(old.root_)),
327  filtration_vect_(std::move(old.filtration_vect_)),
328  dimension_(std::move(old.dimension_)) {
329  old.dimension_ = -1;
330  old.root_ = Siblings(nullptr, null_vertex_);
331  }
332 
335  for (auto sh = root_.members().begin(); sh != root_.members().end(); ++sh) {
336  if (has_children(sh)) {
337  rec_delete(sh->second.children());
338  }
339  }
340  } // end constructor/destructor
342  private:
343  // Recursive deletion
344  void rec_delete(Siblings * sib) {
345  for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh) {
346  if (has_children(sh)) {
347  rec_delete(sh->second.children());
348  }
349  }
350  delete sib;
351  }
352 
353  public:
356  if ((null_vertex_ != st2.null_vertex_) ||
357  (dimension_ != st2.dimension_))
358  return false;
359  return rec_equal(&root_, &st2.root_);
360  }
361 
364  return (!(*this == st2));
365  }
366 
367  private:
369  bool rec_equal(Siblings* s1, Siblings* s2) {
370  if (s1->members().size() != s2->members().size())
371  return false;
372  for (auto sh1 = s1->members().begin(), sh2 = s2->members().begin();
373  (sh1 != s1->members().end() && sh2 != s2->members().end()); ++sh1, ++sh2) {
374  if (sh1->first != sh2->first || sh1->second.filtration() != sh2->second.filtration())
375  return false;
376  if (has_children(sh1) != has_children(sh2))
377  return false;
378  // Recursivity on children only if both have children
379  else if (has_children(sh1))
380  if (!rec_equal(sh1->second.children(), sh2->second.children()))
381  return false;
382  }
383  return true;
384  }
385 
386  public:
392  static Simplex_key key(Simplex_handle sh) {
393  return sh->second.key();
394  }
395 
401  Simplex_handle simplex(Simplex_key idx) const {
402  return filtration_vect_[idx];
403  }
404 
410  static Filtration_value filtration(Simplex_handle sh) {
411  if (sh != null_simplex()) {
412  return sh->second.filtration();
413  } else {
414  return std::numeric_limits<Filtration_value>::infinity();
415  }
416  }
417 
421  void assign_filtration(Simplex_handle sh, Filtration_value fv) {
422  GUDHI_CHECK(sh != null_simplex(),
423  std::invalid_argument("Simplex_tree::assign_filtration - cannot assign filtration on null_simplex"));
424  sh->second.assign_filtration(fv);
425  }
426 
431  static Simplex_handle null_simplex() {
432  return Dictionary_it(nullptr);
433  }
434 
437  static Simplex_key null_key() {
438  return -1;
439  }
440 
443  Vertex_handle null_vertex() const {
444  return null_vertex_;
445  }
446 
448  size_t num_vertices() const {
449  return root_.members_.size();
450  }
451 
452  public:
454  size_t num_simplices() {
455  return num_simplices(&root_);
456  }
457 
458  private:
460  size_t num_simplices(Siblings * sib) {
461  auto sib_begin = sib->members().begin();
462  auto sib_end = sib->members().end();
463  size_t simplices_number = sib_end - sib_begin;
464  for (auto sh = sib_begin; sh != sib_end; ++sh) {
465  if (has_children(sh)) {
466  simplices_number += num_simplices(sh->second.children());
467  }
468  }
469  return simplices_number;
470  }
471 
472  public:
476  int dimension(Simplex_handle sh) {
477  Siblings * curr_sib = self_siblings(sh);
478  int dim = 0;
479  while (curr_sib != nullptr) {
480  ++dim;
481  curr_sib = curr_sib->oncles();
482  }
483  return dim - 1;
484  }
485 
487  int upper_bound_dimension() const {
488  return dimension_;
489  }
490 
495  int dimension() {
496  if (dimension_to_be_lowered_)
497  lower_upper_bound_dimension();
498  return dimension_;
499  }
500 
503  template<class SimplexHandle>
504  bool has_children(SimplexHandle sh) const {
505  // Here we rely on the root using null_vertex(), which cannot match any real vertex.
506  return (sh->second.children()->parent() == sh->first);
507  }
508 
516  template<class InputVertexRange = std::initializer_list<Vertex_handle>>
517  Simplex_handle find(const InputVertexRange & s) {
518  auto first = std::begin(s);
519  auto last = std::end(s);
520 
521  if (first == last)
522  return null_simplex(); // ----->>
523 
524  // Copy before sorting
525  std::vector<Vertex_handle> copy(first, last);
526  std::sort(std::begin(copy), std::end(copy));
527  return find_simplex(copy);
528  }
529 
530  private:
532  Simplex_handle find_simplex(const std::vector<Vertex_handle> & simplex) {
533  Siblings * tmp_sib = &root_;
534  Dictionary_it tmp_dit;
535  auto vi = simplex.begin();
537  // Equivalent to the first iteration of the normal loop
538  GUDHI_CHECK(contiguous_vertices(), "non-contiguous vertices");
539  Vertex_handle v = *vi++;
540  if(v < 0 || v >= static_cast<Vertex_handle>(root_.members_.size()))
541  return null_simplex();
542  tmp_dit = root_.members_.begin() + v;
543  if (vi == simplex.end())
544  return tmp_dit;
545  if (!has_children(tmp_dit))
546  return null_simplex();
547  tmp_sib = tmp_dit->second.children();
548  }
549  for (;;) {
550  tmp_dit = tmp_sib->members_.find(*vi++);
551  if (tmp_dit == tmp_sib->members_.end())
552  return null_simplex();
553  if (vi == simplex.end())
554  return tmp_dit;
555  if (!has_children(tmp_dit))
556  return null_simplex();
557  tmp_sib = tmp_dit->second.children();
558  }
559  }
560 
563  Simplex_handle find_vertex(Vertex_handle v) {
565  assert(contiguous_vertices());
566  return root_.members_.begin() + v;
567  } else {
568  return root_.members_.find(v);
569  }
570  }
571 
572  public:
574  bool contiguous_vertices() const {
575  if (root_.members_.empty()) return true;
576  if (root_.members_.begin()->first != 0) return false;
577  if (std::prev(root_.members_.end())->first != static_cast<Vertex_handle>(root_.members_.size() - 1)) return false;
578  return true;
579  }
580 
581  private:
596  std::pair<Simplex_handle, bool> insert_vertex_vector(const std::vector<Vertex_handle>& simplex,
597  Filtration_value filtration) {
598  Siblings * curr_sib = &root_;
599  std::pair<Simplex_handle, bool> res_insert;
600  auto vi = simplex.begin();
601  for (; vi != simplex.end() - 1; ++vi) {
602  GUDHI_CHECK(*vi != null_vertex(), "cannot use the dummy null_vertex() as a real vertex");
603  res_insert = curr_sib->members_.emplace(*vi, Node(curr_sib, filtration));
604  if (!(has_children(res_insert.first))) {
605  res_insert.first->second.assign_children(new Siblings(curr_sib, *vi));
606  }
607  curr_sib = res_insert.first->second.children();
608  }
609  GUDHI_CHECK(*vi != null_vertex(), "cannot use the dummy null_vertex() as a real vertex");
610  res_insert = curr_sib->members_.emplace(*vi, Node(curr_sib, filtration));
611  if (!res_insert.second) {
612  // if already in the complex
613  if (res_insert.first->second.filtration() > filtration) {
614  // if filtration value modified
615  res_insert.first->second.assign_filtration(filtration);
616  return res_insert;
617  }
618  // if filtration value unchanged
619  return std::pair<Simplex_handle, bool>(null_simplex(), false);
620  }
621  // otherwise the insertion has succeeded - size is a size_type
622  if (static_cast<int>(simplex.size()) - 1 > dimension_) {
623  // Update dimension if needed
624  dimension_ = static_cast<int>(simplex.size()) - 1;
625  }
626  return res_insert;
627  }
628 
629  public:
653  template<class InputVertexRange = std::initializer_list<Vertex_handle>>
654  std::pair<Simplex_handle, bool> insert_simplex(const InputVertexRange & simplex,
655  Filtration_value filtration = 0) {
656  auto first = std::begin(simplex);
657  auto last = std::end(simplex);
658 
659  if (first == last)
660  return std::pair<Simplex_handle, bool>(null_simplex(), true); // ----->>
661 
662  // Copy before sorting
663  std::vector<Vertex_handle> copy(first, last);
664  std::sort(std::begin(copy), std::end(copy));
665  return insert_vertex_vector(copy, filtration);
666  }
667 
682  template<class InputVertexRange = std::initializer_list<Vertex_handle>>
683  std::pair<Simplex_handle, bool> insert_simplex_and_subfaces(const InputVertexRange& Nsimplex,
684  Filtration_value filtration = 0) {
685  auto first = std::begin(Nsimplex);
686  auto last = std::end(Nsimplex);
687 
688  if (first == last)
689  return { null_simplex(), true }; // ----->>
690 
691  // Copy before sorting
692  thread_local std::vector<Vertex_handle> copy;
693  copy.clear();
694  copy.insert(copy.end(), first, last);
695  std::sort(std::begin(copy), std::end(copy));
696  GUDHI_CHECK_code(
697  for (Vertex_handle v : copy)
698  GUDHI_CHECK(v != null_vertex(), "cannot use the dummy null_vertex() as a real vertex");
699  )
700 
701  return insert_simplex_and_subfaces_sorted(copy, filtration);
702  }
703 
704  private:
706  template<class ForwardVertexRange = std::initializer_list<Vertex_handle>>
707  std::pair<Simplex_handle, bool> insert_simplex_and_subfaces_sorted(const ForwardVertexRange& Nsimplex, Filtration_value filt = 0) {
708  auto first = std::begin(Nsimplex);
709  auto last = std::end(Nsimplex);
710  if (first == last)
711  return { null_simplex(), true }; // FIXME: false would make more sense to me.
712  GUDHI_CHECK(std::is_sorted(first, last), "simplex vertices listed in unsorted order");
713  // Update dimension if needed. We could wait to see if the insertion succeeds, but I doubt there is much to gain.
714  dimension_ = (std::max)(dimension_, static_cast<int>(std::distance(first, last)) - 1);
715  return rec_insert_simplex_and_subfaces_sorted(root(), first, last, filt);
716  }
717  // To insert {1,2,3,4}, we insert {2,3,4} twice, once at the root, and once below 1.
718  template<class ForwardVertexIterator>
719  std::pair<Simplex_handle, bool> rec_insert_simplex_and_subfaces_sorted(Siblings* sib, ForwardVertexIterator first, ForwardVertexIterator last, Filtration_value filt) {
720  // An alternative strategy would be:
721  // - try to find the complete simplex, if found (and low filtration) exit
722  // - insert all the vertices at once in sib
723  // - loop over those (new or not) simplices, with a recursive call(++first, last)
724  Vertex_handle vertex_one = *first;
725  auto&& dict = sib->members();
726  auto insertion_result = dict.emplace(vertex_one, Node(sib, filt));
727  Simplex_handle simplex_one = insertion_result.first;
728  bool one_is_new = insertion_result.second;
729  if (!one_is_new) {
730  if (filtration(simplex_one) > filt) {
731  assign_filtration(simplex_one, filt);
732  } else {
733  // FIXME: this interface makes no sense, and it doesn't seem to be tested.
734  insertion_result.first = null_simplex();
735  }
736  }
737  if (++first == last) return insertion_result;
738  if (!has_children(simplex_one))
739  // TODO: have special code here, we know we are building the whole subtree from scratch.
740  simplex_one->second.assign_children(new Siblings(sib, vertex_one));
741  auto res = rec_insert_simplex_and_subfaces_sorted(simplex_one->second.children(), first, last, filt);
742  // No need to continue if the full simplex was already there with a low enough filtration value.
743  if (res.first != null_simplex()) rec_insert_simplex_and_subfaces_sorted(sib, first, last, filt);
744  return res;
745  }
746 
747  public:
750  void assign_key(Simplex_handle sh, Simplex_key key) {
751  sh->second.assign_key(key);
752  }
753 
757  std::pair<Simplex_handle, Simplex_handle> endpoints(Simplex_handle sh) {
758  assert(dimension(sh) == 1);
759  return { find_vertex(sh->first), find_vertex(self_siblings(sh)->parent()) };
760  }
761 
763  template<class SimplexHandle>
764  Siblings* self_siblings(SimplexHandle sh) {
765  if (sh->second.children()->parent() == sh->first)
766  return sh->second.children()->oncles();
767  else
768  return sh->second.children();
769  }
770 
771  public:
773  Siblings * root() {
774  return &root_;
775  }
776 
782  dimension_to_be_lowered_ = false;
783  dimension_ = dimension;
784  }
785 
786  public:
797  filtration_vect_.clear();
798  filtration_vect_.reserve(num_simplices());
799  for (Simplex_handle sh : complex_simplex_range())
800  filtration_vect_.push_back(sh);
801 
802  /* We use stable_sort here because with libstdc++ it is faster than sort.
803  * is_before_in_filtration is now a total order, but we used to call
804  * stable_sort for the following heuristic:
805  * The use of a depth-first traversal of the simplex tree, provided by
806  * complex_simplex_range(), combined with a stable sort is meant to
807  * optimize the order of simplices with same filtration value. The
808  * heuristic consists in inserting the cofaces of a simplex as soon as
809  * possible.
810  */
811 #ifdef GUDHI_USE_TBB
812  tbb::parallel_sort(filtration_vect_.begin(), filtration_vect_.end(), is_before_in_filtration(this));
813 #else
814  std::stable_sort(filtration_vect_.begin(), filtration_vect_.end(), is_before_in_filtration(this));
815 #endif
816  }
817 
818  private:
831  void rec_coface(std::vector<Vertex_handle> &vertices, Siblings *curr_sib, int curr_nbVertices,
832  std::vector<Simplex_handle>& cofaces, bool star, int nbVertices) {
833  if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices
834  return;
835  for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) {
836  if (vertices.empty()) {
837  // If we reached the end of the vertices, and the simplex has more vertices than the given simplex
838  // => we found a coface
839 
840  // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices
841  bool addCoface = (star || curr_nbVertices == nbVertices);
842  if (addCoface)
843  cofaces.push_back(simplex);
844  if ((!addCoface || star) && has_children(simplex)) // Rec call
845  rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices);
846  } else {
847  if (simplex->first == vertices.back()) {
848  // If curr_sib matches with the top vertex
849  bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices
850  bool addCoface = vertices.size() == 1 && equalDim;
851  if (addCoface)
852  cofaces.push_back(simplex);
853  if ((!addCoface || star) && has_children(simplex)) {
854  // Rec call
855  Vertex_handle tmp = vertices.back();
856  vertices.pop_back();
857  rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices);
858  vertices.push_back(tmp);
859  }
860  } else if (simplex->first > vertices.back()) {
861  return;
862  } else {
863  // (simplex->first < vertices.back()
864  if (has_children(simplex))
865  rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices);
866  }
867  }
868  }
869  }
870 
871  public:
877  Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex) {
878  return cofaces_simplex_range(simplex, 0);
879  }
880 
888  Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension) {
889  Cofaces_simplex_range cofaces;
890  // codimension must be positive or null integer
891  assert(codimension >= 0);
892  Simplex_vertex_range rg = simplex_vertex_range(simplex);
893  std::vector<Vertex_handle> copy(rg.begin(), rg.end());
894  if (codimension + static_cast<int>(copy.size()) > dimension_ + 1 ||
895  (codimension == 0 && static_cast<int>(copy.size()) > dimension_)) // n+codimension greater than dimension_
896  return cofaces;
897  // must be sorted in decreasing order
898  assert(std::is_sorted(copy.begin(), copy.end(), std::greater<Vertex_handle>()));
899  bool star = codimension == 0;
900  rec_coface(copy, &root_, 1, cofaces, star, codimension + static_cast<int>(copy.size()));
901  return cofaces;
902  }
903 
904  private:
912  bool reverse_lexicographic_order(Simplex_handle sh1, Simplex_handle sh2) {
913  Simplex_vertex_range rg1 = simplex_vertex_range(sh1);
914  Simplex_vertex_range rg2 = simplex_vertex_range(sh2);
915  Simplex_vertex_iterator it1 = rg1.begin();
916  Simplex_vertex_iterator it2 = rg2.begin();
917  while (it1 != rg1.end() && it2 != rg2.end()) {
918  if (*it1 == *it2) {
919  ++it1;
920  ++it2;
921  } else {
922  return *it1 < *it2;
923  }
924  }
925  return ((it1 == rg1.end()) && (it2 != rg2.end()));
926  }
927 
934  struct is_before_in_filtration {
935  explicit is_before_in_filtration(Simplex_tree * st)
936  : st_(st) { }
937 
938  bool operator()(const Simplex_handle sh1, const Simplex_handle sh2) const {
939  // Not using st_->filtration(sh1) because it uselessly tests for null_simplex.
940  if (sh1->second.filtration() != sh2->second.filtration()) {
941  return sh1->second.filtration() < sh2->second.filtration();
942  }
943  // is sh1 a proper subface of sh2
944  return st_->reverse_lexicographic_order(sh1, sh2);
945  }
946 
947  Simplex_tree * st_;
948  };
949 
950  public:
973  template<class OneSkeletonGraph>
974  void insert_graph(const OneSkeletonGraph& skel_graph) {
975  // the simplex tree must be empty
976  assert(num_simplices() == 0);
977 
978  if (boost::num_vertices(skel_graph) == 0) {
979  return;
980  }
981  if (num_edges(skel_graph) == 0) {
982  dimension_ = 0;
983  } else {
984  dimension_ = 1;
985  }
986 
987  root_.members_.reserve(boost::num_vertices(skel_graph));
988 
989  typename boost::graph_traits<OneSkeletonGraph>::vertex_iterator v_it,
990  v_it_end;
991  for (std::tie(v_it, v_it_end) = boost::vertices(skel_graph); v_it != v_it_end;
992  ++v_it) {
993  root_.members_.emplace_hint(
994  root_.members_.end(), *v_it,
995  Node(&root_, boost::get(vertex_filtration_t(), skel_graph, *v_it)));
996  }
997  typename boost::graph_traits<OneSkeletonGraph>::edge_iterator e_it,
998  e_it_end;
999  for (std::tie(e_it, e_it_end) = boost::edges(skel_graph); e_it != e_it_end;
1000  ++e_it) {
1001  auto u = source(*e_it, skel_graph);
1002  auto v = target(*e_it, skel_graph);
1003  if (u == v) throw "Self-loops are not simplicial";
1004  // We cannot skip edges with the wrong orientation and expect them to
1005  // come a second time with the right orientation, that does not always
1006  // happen in practice. emplace() should be a NOP when an element with the
1007  // same key is already there, so seeing the same edge multiple times is
1008  // ok.
1009  // Should we actually forbid multiple edges? That would be consistent
1010  // with rejecting self-loops.
1011  if (v < u) std::swap(u, v);
1012  auto sh = find_vertex(u);
1013  if (!has_children(sh)) {
1014  sh->second.assign_children(new Siblings(&root_, sh->first));
1015  }
1016 
1017  sh->second.children()->members().emplace(v,
1018  Node(sh->second.children(), boost::get(edge_filtration_t(), skel_graph, *e_it)));
1019  }
1020  }
1021 
1033  void expansion(int max_dim) {
1034  dimension_ = max_dim;
1035  for (Dictionary_it root_it = root_.members_.begin();
1036  root_it != root_.members_.end(); ++root_it) {
1037  if (has_children(root_it)) {
1038  siblings_expansion(root_it->second.children(), max_dim - 1);
1039  }
1040  }
1041  dimension_ = max_dim - dimension_;
1042  }
1043 
1044  private:
1046  void siblings_expansion(Siblings * siblings, // must contain elements
1047  int k) {
1048  if (dimension_ > k) {
1049  dimension_ = k;
1050  }
1051  if (k == 0)
1052  return;
1053  Dictionary_it next = siblings->members().begin();
1054  ++next;
1055 
1056  thread_local std::vector<std::pair<Vertex_handle, Node> > inter;
1057  for (Dictionary_it s_h = siblings->members().begin();
1058  s_h != siblings->members().end(); ++s_h, ++next) {
1059  Simplex_handle root_sh = find_vertex(s_h->first);
1060  if (has_children(root_sh)) {
1061  intersection(
1062  inter, // output intersection
1063  next, // begin
1064  siblings->members().end(), // end
1065  root_sh->second.children()->members().begin(),
1066  root_sh->second.children()->members().end(),
1067  s_h->second.filtration());
1068  if (inter.size() != 0) {
1069  Siblings * new_sib = new Siblings(siblings, // oncles
1070  s_h->first, // parent
1071  inter); // boost::container::ordered_unique_range_t
1072  inter.clear();
1073  s_h->second.assign_children(new_sib);
1074  siblings_expansion(new_sib, k - 1);
1075  } else {
1076  // ensure the children property
1077  s_h->second.assign_children(siblings);
1078  inter.clear();
1079  }
1080  }
1081  }
1082  }
1083 
1086  static void intersection(std::vector<std::pair<Vertex_handle, Node> >& intersection,
1087  Dictionary_it begin1, Dictionary_it end1,
1088  Dictionary_it begin2, Dictionary_it end2,
1089  Filtration_value filtration_) {
1090  if (begin1 == end1 || begin2 == end2)
1091  return; // ----->>
1092  while (true) {
1093  if (begin1->first == begin2->first) {
1094  Filtration_value filt = (std::max)({begin1->second.filtration(), begin2->second.filtration(), filtration_});
1095  intersection.emplace_back(begin1->first, Node(nullptr, filt));
1096  if (++begin1 == end1 || ++begin2 == end2)
1097  return; // ----->>
1098  } else if (begin1->first < begin2->first) {
1099  if (++begin1 == end1)
1100  return;
1101  } else /* begin1->first > begin2->first */ {
1102  if (++begin2 == end2)
1103  return; // ----->>
1104  }
1105  }
1106  }
1107 
1108  public:
1127  template< typename Blocker >
1128  void expansion_with_blockers(int max_dim, Blocker block_simplex) {
1129  // Loop must be from the end to the beginning, as higher dimension simplex are always on the left part of the tree
1130  for (auto& simplex : boost::adaptors::reverse(root_.members())) {
1131  if (has_children(&simplex)) {
1132  siblings_expansion_with_blockers(simplex.second.children(), max_dim, max_dim - 1, block_simplex);
1133  }
1134  }
1135  }
1136 
1137  private:
1139  template< typename Blocker >
1140  void siblings_expansion_with_blockers(Siblings* siblings, int max_dim, int k, Blocker block_simplex) {
1141  if (dimension_ < max_dim - k) {
1142  dimension_ = max_dim - k;
1143  }
1144  if (k == 0)
1145  return;
1146  // No need to go deeper
1147  if (siblings->members().size() < 2)
1148  return;
1149  // Reverse loop starting before the last one for 'next' to be the last one
1150  for (auto simplex = siblings->members().rbegin() + 1; simplex != siblings->members().rend(); simplex++) {
1151  std::vector<std::pair<Vertex_handle, Node> > intersection;
1152  for(auto next = siblings->members().rbegin(); next != simplex; next++) {
1153  bool to_be_inserted = true;
1154  Filtration_value filt = simplex->second.filtration();
1155  // If all the boundaries are present, 'next' needs to be inserted
1156  for (Simplex_handle border : boundary_simplex_range(simplex)) {
1157  Simplex_handle border_child = find_child(border, next->first);
1158  if (border_child == null_simplex()) {
1159  to_be_inserted=false;
1160  break;
1161  }
1162  filt = (std::max)(filt, filtration(border_child));
1163  }
1164  if (to_be_inserted) {
1165  intersection.emplace_back(next->first, Node(nullptr, filt));
1166  }
1167  }
1168  if (intersection.size() != 0) {
1169  // Reverse the order to insert
1170  Siblings * new_sib = new Siblings(siblings, // oncles
1171  simplex->first, // parent
1172  boost::adaptors::reverse(intersection)); // boost::container::ordered_unique_range_t
1173  std::vector<Vertex_handle> blocked_new_sib_vertex_list;
1174  // As all intersections are inserted, we can call the blocker function on all new_sib members
1175  for (auto new_sib_member = new_sib->members().begin();
1176  new_sib_member != new_sib->members().end();
1177  new_sib_member++) {
1178  bool blocker_result = block_simplex(new_sib_member);
1179  // new_sib member has been blocked by the blocker function
1180  // add it to the list to be removed - do not perform it while looping on it
1181  if (blocker_result) {
1182  blocked_new_sib_vertex_list.push_back(new_sib_member->first);
1183  }
1184  }
1185  if (blocked_new_sib_vertex_list.size() == new_sib->members().size()) {
1186  // Specific case where all have to be deleted
1187  delete new_sib;
1188  // ensure the children property
1189  simplex->second.assign_children(siblings);
1190  } else {
1191  for (auto& blocked_new_sib_member : blocked_new_sib_vertex_list) {
1192  new_sib->members().erase(blocked_new_sib_member);
1193  }
1194  // ensure recursive call
1195  simplex->second.assign_children(new_sib);
1196  siblings_expansion_with_blockers(new_sib, max_dim, k - 1, block_simplex);
1197  }
1198  } else {
1199  // ensure the children property
1200  simplex->second.assign_children(siblings);
1201  }
1202  }
1203  }
1204 
1205  /* \private Returns the Simplex_handle composed of the vertex list (from the Simplex_handle), plus the given
1206  * Vertex_handle if the Vertex_handle is found in the Simplex_handle children list.
1207  * Returns null_simplex() if it does not exist
1208  */
1209  Simplex_handle find_child(Simplex_handle sh, Vertex_handle vh) const {
1210  if (!has_children(sh))
1211  return null_simplex();
1212 
1213  Simplex_handle child = sh->second.children()->find(vh);
1214  // Specific case of boost::flat_map does not find, returns boost::flat_map::end()
1215  // in simplex tree we want a null_simplex()
1216  if (child == sh->second.children()->members().end())
1217  return null_simplex();
1218 
1219  return child;
1220  }
1221 
1222  public:
1229  void print_hasse(std::ostream& os) {
1230  os << num_simplices() << " " << std::endl;
1231  for (auto sh : filtration_simplex_range()) {
1232  os << dimension(sh) << " ";
1233  for (auto b_sh : boundary_simplex_range(sh)) {
1234  os << key(b_sh) << " ";
1235  }
1236  os << filtration(sh) << " \n";
1237  }
1238  }
1239 
1240  public:
1250  bool modified = false;
1251  // Loop must be from the end to the beginning, as higher dimension simplex are always on the left part of the tree
1252  for (auto& simplex : boost::adaptors::reverse(root_.members())) {
1253  if (has_children(&simplex)) {
1254  modified |= rec_make_filtration_non_decreasing(simplex.second.children());
1255  }
1256  }
1257  return modified;
1258  }
1259 
1260  private:
1265  bool rec_make_filtration_non_decreasing(Siblings * sib) {
1266  bool modified = false;
1267 
1268  // Loop must be from the end to the beginning, as higher dimension simplex are always on the left part of the tree
1269  for (auto& simplex : boost::adaptors::reverse(sib->members())) {
1270  // Find the maximum filtration value in the border
1271  Boundary_simplex_range boundary = boundary_simplex_range(&simplex);
1272  Boundary_simplex_iterator max_border = std::max_element(std::begin(boundary), std::end(boundary),
1273  [](Simplex_handle sh1, Simplex_handle sh2) {
1274  return filtration(sh1) < filtration(sh2);
1275  });
1276 
1277  Filtration_value max_filt_border_value = filtration(*max_border);
1278  if (simplex.second.filtration() < max_filt_border_value) {
1279  // Store the filtration modification information
1280  modified = true;
1281  simplex.second.assign_filtration(max_filt_border_value);
1282  }
1283  if (has_children(&simplex)) {
1284  modified |= rec_make_filtration_non_decreasing(simplex.second.children());
1285  }
1286  }
1287  // Make the modified information to be traced by upper call
1288  return modified;
1289  }
1290 
1291  public:
1302  bool prune_above_filtration(Filtration_value filtration) {
1303  return rec_prune_above_filtration(root(), filtration);
1304  }
1305 
1306  private:
1307  bool rec_prune_above_filtration(Siblings* sib, Filtration_value filt) {
1308  auto&& list = sib->members();
1309  auto last = std::remove_if(list.begin(), list.end(), [=](Dit_value_t& simplex) {
1310  if (simplex.second.filtration() <= filt) return false;
1311  if (has_children(&simplex)) rec_delete(simplex.second.children());
1312  // dimension may need to be lowered
1313  dimension_to_be_lowered_ = true;
1314  return true;
1315  });
1316 
1317  bool modified = (last != list.end());
1318  if (last == list.begin() && sib != root()) {
1319  // Removing the whole siblings, parent becomes a leaf.
1320  sib->oncles()->members()[sib->parent()].assign_children(sib->oncles());
1321  delete sib;
1322  // dimension may need to be lowered
1323  dimension_to_be_lowered_ = true;
1324  return true;
1325  } else {
1326  // Keeping some elements of siblings. Remove the others, and recurse in the remaining ones.
1327  list.erase(last, list.end());
1328  for (auto&& simplex : list)
1329  if (has_children(&simplex))
1330  modified |= rec_prune_above_filtration(simplex.second.children(), filt);
1331  }
1332  return modified;
1333  }
1334 
1335  private:
1341  bool lower_upper_bound_dimension() {
1342  // reset automatic detection to recompute
1343  dimension_to_be_lowered_ = false;
1344  int new_dimension = -1;
1345  // Browse the tree from the left to the right as higher dimension cells are more likely on the left part of the tree
1346  for (Simplex_handle sh : complex_simplex_range()) {
1347 #ifdef DEBUG_TRACES
1348  for (auto vertex : simplex_vertex_range(sh)) {
1349  std::cout << " " << vertex;
1350  }
1351  std::cout << std::endl;
1352 #endif // DEBUG_TRACES
1353 
1354  int sh_dimension = dimension(sh);
1355  if (sh_dimension >= dimension_)
1356  // Stop browsing as soon as the dimension is reached, no need to go furter
1357  return false;
1358  new_dimension = (std::max)(new_dimension, sh_dimension);
1359  }
1360  dimension_ = new_dimension;
1361  return true;
1362  }
1363 
1364 
1365  public:
1375  void remove_maximal_simplex(Simplex_handle sh) {
1376  // Guarantee the simplex has no children
1377  GUDHI_CHECK(!has_children(sh),
1378  std::invalid_argument("Simplex_tree::remove_maximal_simplex - argument has children"));
1379 
1380  // Simplex is a leaf, it means the child is the Siblings owning the leaf
1381  Siblings* child = sh->second.children();
1382 
1383  if ((child->size() > 1) || (child == root())) {
1384  // Not alone, just remove it from members
1385  // Special case when child is the root of the simplex tree, just remove it from members
1386  child->erase(sh);
1387  } else {
1388  // Sibling is emptied : must be deleted, and its parent must point on his own Sibling
1389  child->oncles()->members().at(child->parent()).assign_children(child->oncles());
1390  delete child;
1391  // dimension may need to be lowered
1392  dimension_to_be_lowered_ = true;
1393  }
1394  }
1395 
1396  private:
1397  Vertex_handle null_vertex_;
1400  Siblings root_;
1402  std::vector<Simplex_handle> filtration_vect_;
1404  int dimension_;
1405  bool dimension_to_be_lowered_ = false;
1406 };
1407 
1408 // Print a Simplex_tree in os.
1409 template<typename...T>
1410 std::ostream& operator<<(std::ostream & os, Simplex_tree<T...> & st) {
1411  for (auto sh : st.filtration_simplex_range()) {
1412  os << st.dimension(sh) << " ";
1413  for (auto v : st.simplex_vertex_range(sh)) {
1414  os << v << " ";
1415  }
1416  os << st.filtration(sh) << "\n"; // TODO(VR): why adding the key ?? not read ?? << " " << st.key(sh) << " \n";
1417  }
1418  return os;
1419 }
1420 
1421 template<typename...T>
1422 std::istream& operator>>(std::istream & is, Simplex_tree<T...> & st) {
1423  typedef Simplex_tree<T...> ST;
1424  std::vector<typename ST::Vertex_handle> simplex;
1425  typename ST::Filtration_value fil;
1426  int max_dim = -1;
1427  while (read_simplex(is, simplex, fil)) {
1428  // read all simplices in the file as a list of vertices
1429  // Warning : simplex_size needs to be casted in int - Can be 0
1430  int dim = static_cast<int> (simplex.size() - 1);
1431  if (max_dim < dim) {
1432  max_dim = dim;
1433  }
1434  // insert every simplex in the simplex tree
1435  st.insert_simplex(simplex, fil);
1436  simplex.clear();
1437  }
1438  st.set_dimension(max_dim);
1439 
1440  return is;
1441 }
1442 
1448  typedef linear_indexing_tag Indexing_tag;
1449  typedef int Vertex_handle;
1450  typedef double Filtration_value;
1451  typedef std::uint32_t Simplex_key;
1452  static const bool store_key = true;
1453  static const bool store_filtration = true;
1454  static const bool contiguous_vertices = false;
1455 };
1456 
1464  typedef linear_indexing_tag Indexing_tag;
1465  typedef int Vertex_handle;
1466  typedef float Filtration_value;
1467  typedef std::uint32_t Simplex_key;
1468  static const bool store_key = true;
1469  static const bool store_filtration = true;
1470  static const bool contiguous_vertices = true;
1471 };
1472  // end defgroup simplex_tree
1474 
1475 } // namespace Gudhi
1476 
1477 #endif // SIMPLEX_TREE_H_
Simplex_tree_skeleton_simplex_iterator< Simplex_tree > Skeleton_simplex_iterator
Iterator over the simplices of the skeleton of the simplicial complex, for a given dimension...
Definition: Simplex_tree.h:186
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree...
Definition: Simplex_tree.h:135
bool prune_above_filtration(Filtration_value filtration)
Prune above filtration value given as parameter.
Definition: Simplex_tree.h:1302
void expansion(int max_dim)
Expands the Simplex_tree containing only its one skeleton until dimension max_dim.
Definition: Simplex_tree.h:1033
Filtration_simplex_range::const_iterator Filtration_simplex_iterator
Iterator over the simplices of the simplicial complex, ordered by the filtration. ...
Definition: Simplex_tree.h:195
Tag for a linear ordering of simplices.
Definition: indexing_tag.h:32
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:72
Siblings * self_siblings(SimplexHandle sh)
Definition: Simplex_tree.h:764
std::pair< Simplex_handle, bool > insert_simplex_and_subfaces(const InputVertexRange &Nsimplex, Filtration_value filtration=0)
Insert a N-simplex and all his subfaces, from a N-simplex represented by a range of Vertex_handles...
Definition: Simplex_tree.h:683
void assign_key(Simplex_handle sh, Simplex_key key)
Assign a value &#39;key&#39; to the key of the simplex represented by the Simplex_handle &#39;sh&#39;.
Definition: Simplex_tree.h:750
bool operator==(Simplex_tree &st2)
Checks if two simplex trees are equal.
Definition: Simplex_tree.h:355
Concept describing an indexing scheme (see FilteredComplex) for applying continuous maps to a cell co...
Definition: IndexingTag.h:30
static Simplex_key key(Simplex_handle sh)
Returns the key associated to a simplex.
Definition: Simplex_tree.h:392
static Simplex_handle null_simplex()
Returns a Simplex_handle different from all Simplex_handles associated to the simplices in the simpli...
Definition: Simplex_tree.h:431
static constexpr bool contiguous_vertices
If true, the list of vertices present in the complex must always be 0, ..., num_vertices-1, without any hole.
Definition: SimplexTreeOptions.h:41
Simplex_handle simplex(Simplex_key idx) const
Returns the simplex that has index idx in the filtration.
Definition: Simplex_tree.h:401
boost::iterator_range< Complex_vertex_iterator > Complex_vertex_range
Range over the vertices of the simplicial complex.
Definition: Simplex_tree.h:161
int upper_bound_dimension() const
Returns an upper bound on the dimension of the simplicial complex.
Definition: Simplex_tree.h:487
Simplex_tree_simplex_vertex_iterator< Simplex_tree > Simplex_vertex_iterator
Iterator over the vertices of a simplex.
Definition: Simplex_tree.h:165
Definition: SimplicialComplexForAlpha.h:26
Vertex_handle null_vertex() const
Returns a Vertex_handle different from all Vertex_handles associated to the vertices of the simplicia...
Definition: Simplex_tree.h:443
void print_hasse(std::ostream &os)
Write the hasse diagram of the simplicial complex in os.
Definition: Simplex_tree.h:1229
Key type used as simplex identifier.
Definition: SimplexKey.h:27
Siblings * root()
Definition: Simplex_tree.h:773
Simplex_tree(Simplex_tree &&old)
User-defined move constructor moves the whole tree structure.
Definition: Simplex_tree.h:324
Options::Simplex_key Simplex_key
Key associated to each simplex.
Definition: Simplex_tree.h:83
bool operator!=(Simplex_tree &st2)
Checks if two simplex trees are different.
Definition: Simplex_tree.h:363
bool make_filtration_non_decreasing()
Browse the simplex tree to ensure the filtration is not decreasing. The simplex tree is browsed start...
Definition: Simplex_tree.h:1249
std::vector< Simplex_handle > Filtration_simplex_range
Range over the simplices of the simplicial complex, ordered by the filtration.
Definition: Simplex_tree.h:191
int dimension()
Returns the dimension of the simplicial complex.
Definition: Simplex_tree.h:495
Filtration_simplex_range const & filtration_simplex_range(Indexing_tag=Indexing_tag())
Returns a range over the simplices of the simplicial complex, in the order of the filtration...
Definition: Simplex_tree.h:248
void initialize_filtration()
Initializes the filtrations, i.e. sort the simplices according to their order in the filtration and i...
Definition: Simplex_tree.h:796
Simplex_handle find(const InputVertexRange &s)
Given a range of Vertex_handles, returns the Simplex_handle of the simplex in the simplicial complex ...
Definition: Simplex_tree.h:517
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension)
Compute the cofaces of a n simplex.
Definition: Simplex_tree.h:888
Complex_simplex_range complex_simplex_range()
Returns a range over the simplices of the simplicial complex.
Definition: Simplex_tree.h:214
Concept of the template parameter for the class Gudhi::Simplex_tree<SimplexTreeOptions>.
Definition: SimplexTreeOptions.h:27
void assign_filtration(Simplex_handle sh, Filtration_value fv)
Sets the filtration value of a simplex. In debug mode, if sh is a null_simplex.
Definition: Simplex_tree.h:421
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition: Simplex_tree.h:757
Boundary_simplex_range boundary_simplex_range(SimplexHandle sh)
Returns a range over the simplices of the boundary of a simplex.
Definition: Simplex_tree.h:282
Complex_vertex_range complex_vertex_range()
Returns a range over the vertices of the simplicial complex. The order is increasing according to < o...
Definition: Simplex_tree.h:203
Simplex_vertex_range simplex_vertex_range(Simplex_handle sh)
Returns a range over the vertices of a simplex.
Definition: Simplex_tree.h:261
Options::Vertex_handle Vertex_handle
Type for the vertex handle.
Definition: Simplex_tree.h:87
Skeleton_simplex_range skeleton_simplex_range(int dim)
Returns a range over the simplices of the dim-skeleton of the simplicial complex. ...
Definition: Simplex_tree.h:228
boost::iterator_range< Boundary_simplex_iterator > Boundary_simplex_range
Range over the simplices of the boundary of a simplex.
Definition: Simplex_tree.h:175
Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex)
Compute the star of a n simplex.
Definition: Simplex_tree.h:877
void set_dimension(int dimension)
Set a dimension for the simplicial complex.
Definition: Simplex_tree.h:781
bool has_children(SimplexHandle sh) const
Returns true if the node in the simplex tree pointed by sh has children.
Definition: Simplex_tree.h:504
int dimension(Simplex_handle sh)
Returns the dimension of a simplex.
Definition: Simplex_tree.h:476
static Simplex_key null_key()
Returns a key different for all keys associated to the simplices of the simplicial complex...
Definition: Simplex_tree.h:437
static Filtration_value filtration(Simplex_handle sh)
Returns the filtration value of a simplex.
Definition: Simplex_tree.h:410
bool read_simplex(std::istream &in_, std::vector< Vertex_handle > &simplex, Filtration_value &fil)
Read a face from a file.
Definition: reader_utils.h:170
Definition: Simplex_tree.h:1463
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:27
boost::transform_iterator< return_first, Dictionary_it > Complex_vertex_iterator
Iterator over the vertices of the simplicial complex.
Definition: Simplex_tree.h:159
~Simplex_tree()
Destructor; deallocates the whole tree structure.
Definition: Simplex_tree.h:334
size_t num_vertices() const
Returns the number of vertices in the complex.
Definition: Simplex_tree.h:448
void remove_maximal_simplex(Simplex_handle sh)
Remove a maximal simplex.
Definition: Simplex_tree.h:1375
static const bool store_filtration
If true, each simplex has extra storage for one Filtration_value, and this value is propagated by ope...
Definition: SimplexTreeOptions.h:39
size_t num_simplices()
returns the number of simplices in the simplex_tree.
Definition: Simplex_tree.h:454
boost::iterator_range< Complex_simplex_iterator > Complex_simplex_range
Range over the simplices of the simplicial complex.
Definition: Simplex_tree.h:181
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition: Simplex_tree.h:79
Simplex_tree()
Constructs an empty simplex tree.
Definition: Simplex_tree.h:292
Simplex_tree_boundary_simplex_iterator< Simplex_tree > Boundary_simplex_iterator
Iterator over the simplices of the boundary of a simplex.
Definition: Simplex_tree.h:173
boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range
Range over the simplices of the skeleton of the simplicial complex, for a given dimension.
Definition: Simplex_tree.h:189
Simplex_tree_complex_simplex_iterator< Simplex_tree > Complex_simplex_iterator
Iterator over the simplices of the simplicial complex.
Definition: Simplex_tree.h:179
void insert_graph(const OneSkeletonGraph &skel_graph)
Inserts a 1-skeleton in an empty Simplex_tree.
Definition: Simplex_tree.h:974
Simplex_tree(const Simplex_tree &simplex_source)
User-defined copy constructor reproduces the whole tree structure.
Definition: Simplex_tree.h:299
This file includes common file reader for GUDHI.
boost::iterator_range< Simplex_vertex_iterator > Simplex_vertex_range
Range over the vertices of a simplex.
Definition: Simplex_tree.h:167
std::pair< Simplex_handle, bool > insert_simplex(const InputVertexRange &simplex, Filtration_value filtration=0)
Insert a simplex, represented by a range of Vertex_handles, in the simplicial complex.
Definition: Simplex_tree.h:654
void expansion_with_blockers(int max_dim, Blocker block_simplex)
Expands a simplex tree containing only a graph. Simplices corresponding to cliques in the graph are a...
Definition: Simplex_tree.h:1128
void rec_copy(Siblings *sib, Siblings *sib_source)
depth first search, inserts simplices when reaching a leaf.
Definition: Simplex_tree.h:309
std::vector< Simplex_handle > Cofaces_simplex_range
Range over the cofaces of a simplex.
Definition: Simplex_tree.h:169
GUDHI  Version 2.1.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Wed Jan 31 2018 09:40:55 for GUDHI by Doxygen 1.8.11