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)
105 sh_(st->null_simplex()),
109 template<
class SimplexHandle>
110 Simplex_tree_boundary_simplex_iterator(
SimplexTree * st, SimplexHandle sh)
116 GUDHI_CHECK(st_->contiguous_vertices(),
"The set of vertices is not { 0, ..., n } without holes");
118 next_ = sib->parent();
119 sib_ = sib->oncles();
120 if (sib_ !=
nullptr) {
123 sh_ = sib_->members_.begin()+next_;
125 sh_ = sib_->find(next_);
132 friend class boost::iterator_core_access;
134 bool equal(Simplex_tree_boundary_simplex_iterator
const& other)
const {
135 return sh_ == other.sh_;
138 Simplex_handle
const& dereference()
const {
139 assert(sh_ != st_->null_simplex());
144 if (sib_ ==
nullptr) {
145 sh_ = st_->null_simplex();
149 Siblings * for_sib = sib_;
150 Siblings * new_sib = sib_->oncles();
151 auto rit = suffix_.rbegin();
154 if (rit == suffix_.rend()) {
156 sh_ = for_sib->members_.begin()+last_;
161 sh_ = for_sib->members_.begin()+*rit;
162 for_sib = sh_->second.children();
166 for (; rit != suffix_.rend(); ++rit) {
167 sh_ = for_sib->find(*rit);
168 for_sib = sh_->second.children();
170 sh_ = for_sib->find(last_);
171 suffix_.push_back(next_);
172 next_ = sib_->parent();
179 #if BOOST_VERSION >= 105600 182 boost::container::static_vector<Vertex_handle, 40> suffix_;
186 std::vector<Vertex_handle> suffix_;
196 template<
class SimplexTree>
197 class Simplex_tree_complex_simplex_iterator :
public boost::iterator_facade<
198 Simplex_tree_complex_simplex_iterator<SimplexTree>,
199 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
202 typedef typename SimplexTree::Siblings Siblings;
206 Simplex_tree_complex_simplex_iterator()
211 explicit Simplex_tree_complex_simplex_iterator(
SimplexTree * st)
214 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
217 sh_ = st->
root()->members().begin();
220 sib_ = sh_->second.children();
221 sh_ = sib_->members().begin();
226 friend class boost::iterator_core_access;
229 bool equal(Simplex_tree_complex_simplex_iterator
const& other)
const {
230 if (other.st_ ==
nullptr) {
231 return (st_ ==
nullptr);
233 if (st_ ==
nullptr) {
236 return (&(sh_->second) == &(other.sh_->second));
239 Simplex_handle
const& dereference()
const {
246 if (sh_ == sib_->members().end()) {
247 if (sib_->oncles() ==
nullptr) {
251 sh_ = sib_->oncles()->members().find(sib_->parent());
252 sib_ = sib_->oncles();
255 while (st_->has_children(sh_)) {
256 sib_ = sh_->second.children();
257 sh_ = sib_->members().begin();
270 template<
class SimplexTree>
271 class Simplex_tree_skeleton_simplex_iterator :
public boost::iterator_facade<
272 Simplex_tree_skeleton_simplex_iterator<SimplexTree>,
273 typename SimplexTree::Simplex_handle const, boost::forward_traversal_tag> {
276 typedef typename SimplexTree::Siblings Siblings;
280 Simplex_tree_skeleton_simplex_iterator()
287 Simplex_tree_skeleton_simplex_iterator(
SimplexTree * st,
int dim_skel)
292 if (st ==
nullptr || st->
root() ==
nullptr || st->
root()->members().empty()) {
295 sh_ = st->
root()->members().begin();
297 while (st->
has_children(sh_) && curr_dim_ < dim_skel_) {
298 sib_ = sh_->second.children();
299 sh_ = sib_->members().begin();
305 friend class boost::iterator_core_access;
308 bool equal(Simplex_tree_skeleton_simplex_iterator
const& other)
const {
309 if (other.st_ ==
nullptr) {
310 return (st_ ==
nullptr);
312 if (st_ ==
nullptr) {
315 return (&(sh_->second) == &(other.sh_->second));
318 Simplex_handle
const& dereference()
const {
325 if (sh_ == sib_->members().end()) {
326 if (sib_->oncles() ==
nullptr) {
330 sh_ = sib_->oncles()->members().find(sib_->parent());
331 sib_ = sib_->oncles();
335 while (st_->has_children(sh_) && curr_dim_ < dim_skel_) {
336 sib_ = sh_->second.children();
337 sh_ = sib_->members().begin();
352 #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:764
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
Definition: SimplicialComplexForAlpha.h:26
Siblings * root()
Definition: Simplex_tree.h:773
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