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