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>
33 template<
class SimplexTree>
34 class 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();
79 template<
class SimplexTree>
80 class 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 explicit Simplex_tree_boundary_simplex_iterator(
SimplexTree * st)
90 : last_(st->null_vertex()),
91 next_(st->null_vertex()),
93 sh_(st->null_simplex()),
97 template<
class SimplexHandle>
98 Simplex_tree_boundary_simplex_iterator(
SimplexTree * st, SimplexHandle sh)
100 next_(st->null_vertex()),
102 sh_(st->null_simplex()),
106 GUDHI_CHECK(st_->contiguous_vertices(),
"The set of vertices is not { 0, ..., n } without holes");
108 next_ = sib->parent();
109 sib_ = sib->oncles();
110 if (sib_ !=
nullptr) {
113 sh_ = sib_->members_.begin()+next_;
115 sh_ = sib_->find(next_);
120 friend class boost::iterator_core_access;
122 bool equal(Simplex_tree_boundary_simplex_iterator
const& other)
const {
123 return sh_ == other.sh_;
126 Simplex_handle
const& dereference()
const {
127 assert(sh_ != st_->null_simplex());
132 if (sib_ ==
nullptr) {
133 sh_ = st_->null_simplex();
137 Siblings * for_sib = sib_;
138 Siblings * new_sib = sib_->oncles();
139 auto rit = suffix_.rbegin();
142 if (rit == suffix_.rend()) {
144 sh_ = for_sib->members_.begin()+last_;
149 sh_ = for_sib->members_.begin()+*rit;
150 for_sib = sh_->second.children();
154 for (; rit != suffix_.rend(); ++rit) {
155 sh_ = for_sib->find(*rit);
156 for_sib = sh_->second.children();
158 sh_ = for_sib->find(last_);
159 suffix_.push_back(next_);
160 next_ = sib_->parent();
169 boost::container::static_vector<Vertex_handle, 40> suffix_;
180 template<
class SimplexTree>
181 class Simplex_tree_complex_simplex_iterator :
public boost::iterator_facade<
182 Simplex_tree_complex_simplex_iterator<SimplexTree>,
183 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
186 typedef typename SimplexTree::Siblings Siblings;
190 Simplex_tree_complex_simplex_iterator()
195 explicit Simplex_tree_complex_simplex_iterator(
SimplexTree * st)
198 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
201 sh_ = st->
root()->members().begin();
204 sib_ = sh_->second.children();
205 sh_ = sib_->members().begin();
210 friend class boost::iterator_core_access;
213 bool equal(Simplex_tree_complex_simplex_iterator
const& other)
const {
214 if (other.st_ ==
nullptr) {
215 return (st_ ==
nullptr);
217 if (st_ ==
nullptr) {
220 return (&(sh_->second) == &(other.sh_->second));
223 Simplex_handle
const& dereference()
const {
230 if (sh_ == sib_->members().end()) {
231 if (sib_->oncles() ==
nullptr) {
235 sh_ = sib_->oncles()->members().find(sib_->parent());
236 sib_ = sib_->oncles();
239 while (st_->has_children(sh_)) {
240 sib_ = sh_->second.children();
241 sh_ = sib_->members().begin();
254 template<
class SimplexTree>
255 class Simplex_tree_skeleton_simplex_iterator :
public boost::iterator_facade<
256 Simplex_tree_skeleton_simplex_iterator<SimplexTree>,
257 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
260 typedef typename SimplexTree::Siblings Siblings;
264 Simplex_tree_skeleton_simplex_iterator()
271 Simplex_tree_skeleton_simplex_iterator(
SimplexTree * st,
int dim_skel)
276 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
279 sh_ = st->
root()->members().begin();
281 while (st->
has_children(sh_) && curr_dim_ < dim_skel_) {
282 sib_ = sh_->second.children();
283 sh_ = sib_->members().begin();
289 friend class boost::iterator_core_access;
292 bool equal(Simplex_tree_skeleton_simplex_iterator
const& other)
const {
293 if (other.st_ ==
nullptr) {
294 return (st_ ==
nullptr);
296 if (st_ ==
nullptr) {
299 return (&(sh_->second) == &(other.sh_->second));
302 Simplex_handle
const& dereference()
const {
309 if (sh_ == sib_->members().end()) {
310 if (sib_->oncles() ==
nullptr) {
314 sh_ = sib_->oncles()->members().find(sib_->parent());
315 sib_ = sib_->oncles();
319 while (st_->has_children(sh_) && curr_dim_ < dim_skel_) {
320 sib_ = sh_->second.children();
321 sh_ = sib_->members().begin();
336 #endif // SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_