Gudhi  1.2.0
 All Classes Functions Variables Typedefs Friends Groups Pages
Skeleton_blockers_edges_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 SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_
23 #define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_
24 
25 #include <boost/iterator/iterator_facade.hpp>
26 #include <boost/graph/adjacency_list.hpp>
27 
28 #include <utility> // for pair<>
29 
30 namespace Gudhi {
31 
32 namespace skbl {
33 
34 template<typename SkeletonBlockerComplex>
35 class Edge_around_vertex_iterator : public boost::iterator_facade <Edge_around_vertex_iterator<SkeletonBlockerComplex>
36 , typename SkeletonBlockerComplex::Edge_handle const, boost::forward_traversal_tag
37 , typename SkeletonBlockerComplex::Edge_handle const> {
38  friend class boost::iterator_core_access;
39 
40  typedef SkeletonBlockerComplex Complex;
41  typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator;
42  typedef typename Complex::Vertex_handle Vertex_handle;
43  typedef typename Complex::Edge_handle Edge_handle;
44 
45  private:
46  const Complex* complex;
47  Vertex_handle v;
48 
49  boost_adjacency_iterator current_;
50  boost_adjacency_iterator end_;
51 
52  public:
53  Edge_around_vertex_iterator() : complex(NULL) { }
54 
55  Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_) :
56  complex(complex_),
57  v(v_) {
58  tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton);
59  }
60 
64  Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_, int end) :
65  complex(complex_),
66  v(v_) {
67  tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton);
68  set_end();
69  }
70 
71  bool equal(const Edge_around_vertex_iterator& other) const {
72  return (complex == other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_);
73  }
74 
75  void increment() {
76  if (current_ != end_)
77  ++current_;
78  }
79 
80  Edge_handle dereference() const {
81  return *(*complex)[std::make_pair(v, static_cast<Vertex_handle> (*current_))];
82  }
83 
84  private:
85  // remove this ugly hack
86  void set_end() {
87  current_ = end_;
88  }
89 };
90 
95 template<typename SkeletonBlockerComplex>
96 class Edge_iterator : public boost::iterator_facade <Edge_iterator<SkeletonBlockerComplex>
97 , typename SkeletonBlockerComplex::Edge_handle const
98 , boost::forward_traversal_tag
99 , typename SkeletonBlockerComplex::Edge_handle const> {
100  friend class boost::iterator_core_access;
101 
102  public:
103  typedef SkeletonBlockerComplex Complex;
104  typedef typename Complex::boost_edge_iterator boost_edge_iterator;
105  typedef typename Complex::Edge_handle Edge_handle;
106 
107  const Complex* complex;
108  std::pair<boost_edge_iterator, boost_edge_iterator> edge_iterator;
109 
110  Edge_iterator() : complex(NULL) { }
111 
112  Edge_iterator(const SkeletonBlockerComplex* complex_) :
113  complex(complex_),
114  edge_iterator(boost::edges(complex_->skeleton)) { }
115 
119  Edge_iterator(const SkeletonBlockerComplex* complex_, int end) :
120  complex(complex_),
121  edge_iterator(boost::edges(complex_->skeleton)) {
122  edge_iterator.first = edge_iterator.second;
123  }
124 
125  bool equal(const Edge_iterator& other) const {
126  return (complex == other.complex) && (edge_iterator == other.edge_iterator);
127  }
128 
129  void increment() {
130  if (edge_iterator.first != edge_iterator.second) {
131  ++(edge_iterator.first);
132  }
133  }
134 
135  Edge_handle dereference() const {
136  return (*(edge_iterator.first));
137  }
138 };
139 
140 } // namespace skbl
141 
142 } // namespace Gudhi
143 
144 #endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_
Edge_iterator(const SkeletonBlockerComplex *complex_, int end)
Definition: Skeleton_blockers_edges_iterators.h:119
Iterator on the edges of a simplicial complex.
Definition: Skeleton_blockers_edges_iterators.h:96
Definition: SkeletonBlockerDS.h:60