23 #ifndef SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ 24 #define SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ 26 #include <gudhi/Debug_utils.h> 28 #include <boost/iterator/iterator_facade.hpp> 29 #include <boost/version.hpp> 30 #if BOOST_VERSION >= 105600 31 # include <boost/container/static_vector.hpp> 47 template<
class SimplexTree>
48 class Simplex_tree_simplex_vertex_iterator :
public boost::iterator_facade<
49 Simplex_tree_simplex_vertex_iterator<SimplexTree>,
50 typename SimplexTree::Vertex_handle const, boost::forward_traversal_tag,
51 typename SimplexTree::Vertex_handle const> {
54 typedef typename SimplexTree::Siblings Siblings;
57 explicit Simplex_tree_simplex_vertex_iterator(
SimplexTree * st)
60 v_(st->null_vertex()) {
63 Simplex_tree_simplex_vertex_iterator(
SimplexTree * st, Simplex_handle sh)
64 : sib_(st->self_siblings(sh)),
69 friend class boost::iterator_core_access;
71 bool equal(Simplex_tree_simplex_vertex_iterator
const &other)
const {
72 return sib_ == other.sib_ && v_ == other.v_;
75 Vertex_handle
const& dereference()
const {
81 sib_ = sib_->oncles();
93 template<
class SimplexTree>
94 class Simplex_tree_boundary_simplex_iterator :
public boost::iterator_facade<
95 Simplex_tree_boundary_simplex_iterator<SimplexTree>,
96 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
100 typedef typename SimplexTree::Siblings Siblings;
103 explicit Simplex_tree_boundary_simplex_iterator(
SimplexTree * st)
104 : last_(st->null_vertex()),
105 next_(st->null_vertex()),
107 sh_(st->null_simplex()),
111 template<
class SimplexHandle>
112 Simplex_tree_boundary_simplex_iterator(
SimplexTree * st, SimplexHandle sh)
114 next_(st->null_vertex()),
116 sh_(st->null_simplex()),
120 GUDHI_CHECK(st_->contiguous_vertices(),
"The set of vertices is not { 0, ..., n } without holes");
122 next_ = sib->parent();
123 sib_ = sib->oncles();
124 if (sib_ !=
nullptr) {
127 sh_ = sib_->members_.begin()+next_;
129 sh_ = sib_->find(next_);
134 friend class boost::iterator_core_access;
136 bool equal(Simplex_tree_boundary_simplex_iterator
const& other)
const {
137 return sh_ == other.sh_;
140 Simplex_handle
const& dereference()
const {
141 assert(sh_ != st_->null_simplex());
146 if (sib_ ==
nullptr) {
147 sh_ = st_->null_simplex();
151 Siblings * for_sib = sib_;
152 Siblings * new_sib = sib_->oncles();
153 auto rit = suffix_.rbegin();
156 if (rit == suffix_.rend()) {
158 sh_ = for_sib->members_.begin()+last_;
163 sh_ = for_sib->members_.begin()+*rit;
164 for_sib = sh_->second.children();
168 for (; rit != suffix_.rend(); ++rit) {
169 sh_ = for_sib->find(*rit);
170 for_sib = sh_->second.children();
172 sh_ = for_sib->find(last_);
173 suffix_.push_back(next_);
174 next_ = sib_->parent();
181 #if BOOST_VERSION >= 105600 184 boost::container::static_vector<Vertex_handle, 40> suffix_;
188 std::vector<Vertex_handle> suffix_;
198 template<
class SimplexTree>
199 class Simplex_tree_complex_simplex_iterator :
public boost::iterator_facade<
200 Simplex_tree_complex_simplex_iterator<SimplexTree>,
201 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
204 typedef typename SimplexTree::Siblings Siblings;
208 Simplex_tree_complex_simplex_iterator()
213 explicit Simplex_tree_complex_simplex_iterator(
SimplexTree * st)
216 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
219 sh_ = st->
root()->members().begin();
222 sib_ = sh_->second.children();
223 sh_ = sib_->members().begin();
228 friend class boost::iterator_core_access;
231 bool equal(Simplex_tree_complex_simplex_iterator
const& other)
const {
232 if (other.st_ ==
nullptr) {
233 return (st_ ==
nullptr);
235 if (st_ ==
nullptr) {
238 return (&(sh_->second) == &(other.sh_->second));
241 Simplex_handle
const& dereference()
const {
248 if (sh_ == sib_->members().end()) {
249 if (sib_->oncles() ==
nullptr) {
253 sh_ = sib_->oncles()->members().find(sib_->parent());
254 sib_ = sib_->oncles();
257 while (st_->has_children(sh_)) {
258 sib_ = sh_->second.children();
259 sh_ = sib_->members().begin();
272 template<
class SimplexTree>
273 class Simplex_tree_skeleton_simplex_iterator :
public boost::iterator_facade<
274 Simplex_tree_skeleton_simplex_iterator<SimplexTree>,
275 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
278 typedef typename SimplexTree::Siblings Siblings;
282 Simplex_tree_skeleton_simplex_iterator()
289 Simplex_tree_skeleton_simplex_iterator(
SimplexTree * st,
int dim_skel)
294 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
297 sh_ = st->
root()->members().begin();
299 while (st->
has_children(sh_) && curr_dim_ < dim_skel_) {
300 sib_ = sh_->second.children();
301 sh_ = sib_->members().begin();
307 friend class boost::iterator_core_access;
310 bool equal(Simplex_tree_skeleton_simplex_iterator
const& other)
const {
311 if (other.st_ ==
nullptr) {
312 return (st_ ==
nullptr);
314 if (st_ ==
nullptr) {
317 return (&(sh_->second) == &(other.sh_->second));
320 Simplex_handle
const& dereference()
const {
327 if (sh_ == sib_->members().end()) {
328 if (sib_->oncles() ==
nullptr) {
332 sh_ = sib_->oncles()->members().find(sib_->parent());
333 sib_ = sib_->oncles();
337 while (st_->has_children(sh_) && curr_dim_ < dim_skel_) {
338 sib_ = sh_->second.children();
339 sh_ = sib_->members().begin();
354 #endif // SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree...
Definition: Simplex_tree.h:135
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:72
Siblings * self_siblings(SimplexHandle sh)
Definition: Simplex_tree.h:768
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
Definition: SimplicialComplexForAlpha.h:26
Siblings * root()
Definition: Simplex_tree.h:777
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
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:27