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 #if BOOST_VERSION >= 105600 19 # include <boost/container/static_vector.hpp> 35 template<
class SimplexTree>
36 class Simplex_tree_simplex_vertex_iterator :
public boost::iterator_facade<
37 Simplex_tree_simplex_vertex_iterator<SimplexTree>,
38 typename SimplexTree::Vertex_handle const, boost::forward_traversal_tag,
39 typename SimplexTree::Vertex_handle const> {
42 typedef typename SimplexTree::Siblings Siblings;
45 explicit Simplex_tree_simplex_vertex_iterator(
SimplexTree * st)
48 v_(st->null_vertex()) {
51 Simplex_tree_simplex_vertex_iterator(
SimplexTree * st, Simplex_handle sh)
52 : sib_(st->self_siblings(sh)),
57 friend class boost::iterator_core_access;
59 bool equal(Simplex_tree_simplex_vertex_iterator
const &other)
const {
60 return sib_ == other.sib_ && v_ == other.v_;
63 Vertex_handle
const& dereference()
const {
69 sib_ = sib_->oncles();
81 template<
class SimplexTree>
82 class Simplex_tree_boundary_simplex_iterator :
public boost::iterator_facade<
83 Simplex_tree_boundary_simplex_iterator<SimplexTree>,
84 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
88 typedef typename SimplexTree::Siblings Siblings;
91 explicit Simplex_tree_boundary_simplex_iterator(
SimplexTree * st)
92 : last_(st->null_vertex()),
93 next_(st->null_vertex()),
95 sh_(st->null_simplex()),
99 template<
class SimplexHandle>
100 Simplex_tree_boundary_simplex_iterator(
SimplexTree * st, SimplexHandle sh)
102 next_(st->null_vertex()),
104 sh_(st->null_simplex()),
108 GUDHI_CHECK(st_->contiguous_vertices(),
"The set of vertices is not { 0, ..., n } without holes");
110 next_ = sib->parent();
111 sib_ = sib->oncles();
112 if (sib_ !=
nullptr) {
115 sh_ = sib_->members_.begin()+next_;
117 sh_ = sib_->find(next_);
122 friend class boost::iterator_core_access;
124 bool equal(Simplex_tree_boundary_simplex_iterator
const& other)
const {
125 return sh_ == other.sh_;
128 Simplex_handle
const& dereference()
const {
129 assert(sh_ != st_->null_simplex());
134 if (sib_ ==
nullptr) {
135 sh_ = st_->null_simplex();
139 Siblings * for_sib = sib_;
140 Siblings * new_sib = sib_->oncles();
141 auto rit = suffix_.rbegin();
144 if (rit == suffix_.rend()) {
146 sh_ = for_sib->members_.begin()+last_;
151 sh_ = for_sib->members_.begin()+*rit;
152 for_sib = sh_->second.children();
156 for (; rit != suffix_.rend(); ++rit) {
157 sh_ = for_sib->find(*rit);
158 for_sib = sh_->second.children();
160 sh_ = for_sib->find(last_);
161 suffix_.push_back(next_);
162 next_ = sib_->parent();
169 #if BOOST_VERSION >= 105600 172 boost::container::static_vector<Vertex_handle, 40> suffix_;
176 std::vector<Vertex_handle> suffix_;
186 template<
class SimplexTree>
187 class 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();
260 template<
class SimplexTree>
261 class 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();
342 #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:123
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:60
Siblings * self_siblings(SimplexHandle sh)
Definition: Simplex_tree.h:830
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:29
Definition: SimplicialComplexForAlpha.h:14
Siblings * root()
Definition: Simplex_tree.h:839
bool has_children(SimplexHandle sh) const
Returns true if the node in the simplex tree pointed by sh has children.
Definition: Simplex_tree.h:571
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15