Gudhi  1.1.0
 All Classes Functions 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 GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_
23 #define GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_
24 
25 #include "boost/iterator/iterator_facade.hpp"
26 
27 
28 namespace Gudhi{
29 
30 namespace skbl {
31 
32 template<typename SkeletonBlockerComplex>
33 class Complex_edge_around_vertex_iterator :
34  public boost::iterator_facade < Complex_edge_around_vertex_iterator<SkeletonBlockerComplex>
35  , typename SkeletonBlockerComplex::Edge_handle const
36  , boost::forward_traversal_tag
37  , typename SkeletonBlockerComplex::Edge_handle const
38  >
39 {
40  friend class boost::iterator_core_access;
41 
42  typedef SkeletonBlockerComplex Complex;
43  typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator;
44  typedef typename Complex::Vertex_handle Vertex_handle;
45  typedef typename Complex::Edge_handle Edge_handle;
46 
47 private:
48 
49  const Complex* complex;
50  Vertex_handle v;
51 
52  boost_adjacency_iterator current_;
53  boost_adjacency_iterator end_;
54 
55 public:
56 
57  Complex_edge_around_vertex_iterator():complex(NULL){
58  }
59 
60  Complex_edge_around_vertex_iterator(const Complex* complex_,Vertex_handle v_):
61  complex(complex_),
62  v(v_)
63  {
64  tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton);
65  }
66 
70  Complex_edge_around_vertex_iterator(const Complex* complex_,Vertex_handle v_,int end):
71  complex(complex_),
72  v(v_)
73  {
74  tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton);
75  set_end();
76  }
77 
78  bool equal(const Complex_edge_around_vertex_iterator& other) const{
79  return (complex== other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_);
80  }
81 
82  void increment(){
83  if(current_ != end_)
84  ++current_;
85  }
86 
87  Edge_handle dereference() const{
88  return *(*complex)[std::make_pair(v,*current_)];
89  }
90 
91 private:
92  //remove this ugly hack
93  void set_end(){
94  current_ = end_;
95  }
96 };
97 
98 
99 
104 template<typename SkeletonBlockerComplex>
106 public boost::iterator_facade < Complex_edge_iterator<SkeletonBlockerComplex>
107 , typename SkeletonBlockerComplex::Edge_handle const
108 , boost::forward_traversal_tag
109 , typename SkeletonBlockerComplex::Edge_handle const
110 >
111 
112 {
113  friend class boost::iterator_core_access;
114 public:
115  typedef SkeletonBlockerComplex Complex;
116  typedef typename Complex::boost_edge_iterator boost_edge_iterator;
117  typedef typename Complex::Edge_handle Edge_handle;
118 
119 
120  const Complex* complex;
121  std::pair<boost_edge_iterator,boost_edge_iterator> edge_iterator ;
122 
123  Complex_edge_iterator():complex(NULL){
124  }
125 
126  Complex_edge_iterator(const SkeletonBlockerComplex* complex_):
127  complex(complex_),
128  edge_iterator(boost::edges(complex_->skeleton))
129  {
130  }
131 
135  Complex_edge_iterator(const SkeletonBlockerComplex* complex_,int end):
136  complex(complex_),
137  edge_iterator(boost::edges(complex_->skeleton))
138  {
139  edge_iterator.first = edge_iterator.second;
140  }
141 
142 
143  bool equal(const Complex_edge_iterator& other) const{
144  return (complex == other.complex) && (edge_iterator == other.edge_iterator);
145  }
146 
147  void increment(){
148  if(edge_iterator.first != edge_iterator.second){
149  ++(edge_iterator.first);
150  }
151  }
152 
153  Edge_handle dereference() const{
154  return(*(edge_iterator.first));
155  }
156 };
157 
158 
159 
160 }
161 
162 } // namespace GUDHI
163 
164 
165 #endif /* GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ */
166 
167 
Iterator on the edges of a simplicial complex.
Definition: Skeleton_blockers_edges_iterators.h:105
Complex_edge_iterator(const SkeletonBlockerComplex *complex_, int end)
Definition: Skeleton_blockers_edges_iterators.h:135