11#ifndef SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_
12#define SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_
14#include <gudhi/Debug_utils.h>
16#include <boost/iterator/iterator_facade.hpp>
17#include <boost/version.hpp>
18#include <boost/container/static_vector.hpp>
33template<
class SimplexTree>
34class Simplex_tree_simplex_vertex_iterator :
public boost::iterator_facade<
35 Simplex_tree_simplex_vertex_iterator<SimplexTree>,
36 typename SimplexTree::Vertex_handle const, boost::forward_traversal_tag,
37 typename SimplexTree::Vertex_handle const> {
40 typedef typename SimplexTree::Siblings Siblings;
43 explicit Simplex_tree_simplex_vertex_iterator(
SimplexTree const* st)
46 v_(st->null_vertex()) {
49 Simplex_tree_simplex_vertex_iterator(
SimplexTree const* st, Simplex_handle sh)
50 : sib_(st->self_siblings(sh)),
55 friend class boost::iterator_core_access;
57 bool equal(Simplex_tree_simplex_vertex_iterator
const &other)
const {
58 return sib_ == other.sib_ && v_ == other.v_;
67 sib_ = sib_->oncles();
79template<
class SimplexTree>
80class Simplex_tree_boundary_simplex_iterator :
public boost::iterator_facade<
81 Simplex_tree_boundary_simplex_iterator<SimplexTree>,
82 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
86 typedef typename SimplexTree::Siblings Siblings;
89 Simplex_tree_boundary_simplex_iterator()
95 explicit Simplex_tree_boundary_simplex_iterator(
SimplexTree * st)
96 : last_(st->null_vertex()),
97 next_(st->null_vertex()),
99 sh_(st->null_simplex()),
103 template<
class SimplexHandle>
104 Simplex_tree_boundary_simplex_iterator(
SimplexTree * st, SimplexHandle sh)
106 next_(st->null_vertex()),
108 sh_(st->null_simplex()),
112 GUDHI_CHECK(st_->contiguous_vertices(),
"The set of vertices is not { 0, ..., n } without holes");
114 next_ = sib->parent();
115 sib_ = sib->oncles();
116 if (sib_ !=
nullptr) {
119 sh_ = sib_->members_.begin()+next_;
121 sh_ = sib_->find(next_);
126 friend class boost::iterator_core_access;
128 bool equal(Simplex_tree_boundary_simplex_iterator
const& other)
const {
129 return sh_ == other.sh_;
132 Simplex_handle
const& dereference()
const {
133 assert(sh_ != st_->null_simplex());
138 if (sib_ ==
nullptr) {
139 sh_ = st_->null_simplex();
143 Siblings * for_sib = sib_;
144 Siblings * new_sib = sib_->oncles();
145 auto rit = suffix_.rbegin();
148 if (rit == suffix_.rend()) {
150 sh_ = for_sib->members_.begin()+last_;
155 sh_ = for_sib->members_.begin()+*rit;
156 for_sib = sh_->second.children();
160 for (; rit != suffix_.rend(); ++rit) {
161 sh_ = for_sib->find(*rit);
162 for_sib = sh_->second.children();
164 sh_ = for_sib->find(last_);
165 suffix_.push_back(next_);
166 next_ = sib_->parent();
175 boost::container::static_vector<Vertex_handle, 40> suffix_;
186template<
class SimplexTree>
187class Simplex_tree_complex_simplex_iterator :
public boost::iterator_facade<
188 Simplex_tree_complex_simplex_iterator<SimplexTree>,
189 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
192 typedef typename SimplexTree::Siblings Siblings;
196 Simplex_tree_complex_simplex_iterator()
201 explicit Simplex_tree_complex_simplex_iterator(
SimplexTree * st)
204 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
207 sh_ = st->
root()->members().begin();
210 sib_ = sh_->second.children();
211 sh_ = sib_->members().begin();
216 friend class boost::iterator_core_access;
219 bool equal(Simplex_tree_complex_simplex_iterator
const& other)
const {
220 if (other.st_ ==
nullptr) {
221 return (st_ ==
nullptr);
223 if (st_ ==
nullptr) {
226 return (&(sh_->second) == &(other.sh_->second));
229 Simplex_handle
const& dereference()
const {
236 if (sh_ == sib_->members().end()) {
237 if (sib_->oncles() ==
nullptr) {
241 sh_ = sib_->oncles()->members().find(sib_->parent());
242 sib_ = sib_->oncles();
245 while (st_->has_children(sh_)) {
246 sib_ = sh_->second.children();
247 sh_ = sib_->members().begin();
260template<
class SimplexTree>
261class Simplex_tree_skeleton_simplex_iterator :
public boost::iterator_facade<
262 Simplex_tree_skeleton_simplex_iterator<SimplexTree>,
263 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
266 typedef typename SimplexTree::Siblings Siblings;
270 Simplex_tree_skeleton_simplex_iterator()
277 Simplex_tree_skeleton_simplex_iterator(
SimplexTree * st,
int dim_skel)
282 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
285 sh_ = st->
root()->members().begin();
287 while (st->
has_children(sh_) && curr_dim_ < dim_skel_) {
288 sib_ = sh_->second.children();
289 sh_ = sib_->members().begin();
295 friend class boost::iterator_core_access;
298 bool equal(Simplex_tree_skeleton_simplex_iterator
const& other)
const {
299 if (other.st_ ==
nullptr) {
300 return (st_ ==
nullptr);
302 if (st_ ==
nullptr) {
305 return (&(sh_->second) == &(other.sh_->second));
308 Simplex_handle
const& dereference()
const {
315 if (sh_ == sib_->members().end()) {
316 if (sib_->oncles() ==
nullptr) {
320 sh_ = sib_->oncles()->members().find(sib_->parent());
321 sib_ = sib_->oncles();
325 while (st_->has_children(sh_) && curr_dim_ < dim_skel_) {
326 sib_ = sh_->second.children();
327 sh_ = sib_->members().begin();
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:75
static Siblings * self_siblings(SimplexHandle sh)
Definition: Simplex_tree.h:856
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree.
Definition: Simplex_tree.h:149
bool has_children(SimplexHandle sh) const
Returns true if the node in the simplex tree pointed by sh has children.
Definition: Simplex_tree.h:602
Siblings * root()
Definition: Simplex_tree.h:865
static constexpr bool contiguous_vertices
If true, the list of vertices present in the complex must always be 0, ..., num_vertices-1,...
Definition: SimplexTreeOptions.h:29
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15