Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
Skeleton_blockers_vertices_iterators.h
1  /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): David Salinas
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 #ifndef GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_
23 #define GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_
24 
25 #include "boost/iterator/iterator_facade.hpp"
26 
27 
28 namespace Gudhi{
29 
30 namespace skbl {
31 
37 template<typename SkeletonBlockerComplex>
38 class Complex_vertex_iterator : public boost::iterator_facade
39 < Complex_vertex_iterator <SkeletonBlockerComplex>
40  , typename SkeletonBlockerComplex::Vertex_handle const
41  , boost::forward_traversal_tag
42  , typename SkeletonBlockerComplex::Vertex_handle const
43  >
44 {
45  friend class boost::iterator_core_access;
46 
47  typedef typename SkeletonBlockerComplex::boost_vertex_iterator boost_vertex_iterator;
48  typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle;
49 private:
50  const SkeletonBlockerComplex* complex;
51  std::pair<boost_vertex_iterator,boost_vertex_iterator> vertexIterator;
52 
53 
54 public:
55  Complex_vertex_iterator():complex(NULL){
56  }
57 
58  Complex_vertex_iterator(const SkeletonBlockerComplex* complex_):
59  complex(complex_),
60  vertexIterator(vertices(complex_->skeleton)){
61  if(!finished() && !is_active()) {
62  goto_next_valid();
63  }
64  }
65 
69  Complex_vertex_iterator(const SkeletonBlockerComplex* complex_,int end):
70  complex(complex_),vertexIterator(vertices(complex_->skeleton)){
71  vertexIterator.first = vertexIterator.second ;
72  }
73 
74 public:
75  void increment () {goto_next_valid();}
76  Vertex_handle dereference() const {
77  return(Vertex_handle(*(vertexIterator.first)));
78  }
79 
80  bool equal(const Complex_vertex_iterator& other) const{
81  return vertexIterator == other.vertexIterator && complex == other.complex;
82  }
83 
84  bool operator<(const Complex_vertex_iterator& other) const{
85  return dereference()<other.dereference();
86  }
87 
88 private:
89  bool finished() const{
90  return vertexIterator.first == vertexIterator.second;
91  }
92 
93  void goto_next_valid(){
94  ++vertexIterator.first;
95  if(!finished() && !is_active()){
96  goto_next_valid();
97  }
98  }
99 
100  bool is_active() const{
101  return ((*complex)[Vertex_handle(*vertexIterator.first)]).is_active();
102  }
103 
104 };
105 
106 
107 
108 
109 template<typename SkeletonBlockerComplex>
110 class Complex_neighbors_vertices_iterator
111 : public boost::iterator_facade < Complex_neighbors_vertices_iterator<SkeletonBlockerComplex>
112  , typename SkeletonBlockerComplex::Vertex_handle const
113  , boost::forward_traversal_tag
114  , typename SkeletonBlockerComplex::Vertex_handle const
115  >
116 {
117  friend class boost::iterator_core_access;
118 
119  typedef SkeletonBlockerComplex Complex;
120  typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator;
121  typedef typename Complex::Vertex_handle Vertex_handle;
122  typedef typename Complex::Edge_handle Edge_handle;
123 
124 private:
125 
126  const Complex* complex;
127  Vertex_handle v;
128 
129  boost_adjacency_iterator current_;
130  boost_adjacency_iterator end_;
131 
132 public:
133  // boost_adjacency_iterator ai, ai_end;
134  // for (tie(ai, ai_end) = adjacent_vertices(v.vertex, skeleton); ai != ai_end; ++ai){
135 
136  Complex_neighbors_vertices_iterator():complex(NULL){
137  }
138 
139  Complex_neighbors_vertices_iterator(const Complex* complex_,Vertex_handle v_):
140  complex(complex_),
141  v(v_){
142  tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton);
143  }
144 
148  Complex_neighbors_vertices_iterator(const Complex* complex_,Vertex_handle v_,int end):
149  complex(complex_),
150  v(v_){
151  tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton);
152  set_end();
153  }
154 
155 
156  void increment () {
157  if(current_ != end_)
158  ++current_;
159  }
160 
161  Vertex_handle dereference() const {
162  return(Vertex_handle(*current_));
163  }
164 
165  bool equal(const Complex_neighbors_vertices_iterator& other) const{
166  return (complex== other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_);
167  }
168 
169 private:
170  //todo remove this ugly hack
171  void set_end(){
172  current_ = end_;
173  }
174 };
175 
176 }
177 
178 } // namespace GUDHI
179 
180 #endif /* GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ */
181 
182 
Iterator on the vertices of a simplicial complex.
Definition: Skeleton_blockers_vertices_iterators.h:38
Complex_vertex_iterator(const SkeletonBlockerComplex *complex_, int end)
Definition: Skeleton_blockers_vertices_iterators.h:69