Loading...
Searching...
No Matches
Skeleton_blockers_edges_iterators.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): David Salinas
4 *
5 * Copyright (C) 2014 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_
12#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_
13
14#include <boost/iterator/iterator_facade.hpp>
15#include <boost/graph/adjacency_list.hpp>
16
17#include <utility> // for pair<>
18
19namespace Gudhi {
20
21namespace skeleton_blocker {
22
23template<typename SkeletonBlockerComplex>
24class Edge_around_vertex_iterator : public boost::iterator_facade <Edge_around_vertex_iterator<SkeletonBlockerComplex>
25, typename SkeletonBlockerComplex::Edge_handle const, boost::forward_traversal_tag
26, typename SkeletonBlockerComplex::Edge_handle const> {
27 friend class boost::iterator_core_access;
28
29 typedef SkeletonBlockerComplex Complex;
30 typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator;
32 typedef typename Complex::Edge_handle Edge_handle;
33
34 private:
35 const Complex* complex;
37
38 boost_adjacency_iterator current_;
39 boost_adjacency_iterator end_;
40
41 public:
42 Edge_around_vertex_iterator() : complex(NULL) { }
43
44 Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_) :
45 complex(complex_),
46 v(v_) {
47 tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton);
48 }
49
53 Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_, int end) :
54 complex(complex_),
55 v(v_) {
56 tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton);
57 set_end();
58 }
59
60 bool equal(const Edge_around_vertex_iterator& other) const {
61 return (complex == other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_);
62 }
63
64 void increment() {
65 if (current_ != end_)
66 ++current_;
67 }
68
69 Edge_handle dereference() const {
70 return *(*complex)[std::make_pair(v, static_cast<Vertex_handle> (*current_))];
71 }
72
73 private:
74 // remove this ugly hack
75 void set_end() {
76 current_ = end_;
77 }
78};
79
84template<typename SkeletonBlockerComplex>
85class Edge_iterator : public boost::iterator_facade <Edge_iterator<SkeletonBlockerComplex>
86, typename SkeletonBlockerComplex::Edge_handle const
87, boost::forward_traversal_tag
88, typename SkeletonBlockerComplex::Edge_handle const> {
89 friend class boost::iterator_core_access;
90
91 public:
92 typedef SkeletonBlockerComplex Complex;
93 typedef typename Complex::boost_edge_iterator boost_edge_iterator;
94 typedef typename Complex::Edge_handle Edge_handle;
95
96 const Complex* complex;
97 std::pair<boost_edge_iterator, boost_edge_iterator> edge_iterator;
98
99 Edge_iterator() : complex(NULL) { }
100
101 Edge_iterator(const SkeletonBlockerComplex* complex_) :
102 complex(complex_),
103 edge_iterator(boost::edges(complex_->skeleton)) { }
104
108 Edge_iterator(const SkeletonBlockerComplex* complex_, int end) :
109 complex(complex_),
110 edge_iterator(boost::edges(complex_->skeleton)) {
111 edge_iterator.first = edge_iterator.second;
112 }
113
114 bool equal(const Edge_iterator& other) const {
115 return (complex == other.complex) && (edge_iterator == other.edge_iterator);
116 }
117
118 void increment() {
119 if (edge_iterator.first != edge_iterator.second) {
120 ++(edge_iterator.first);
121 }
122 }
123
124 Edge_handle dereference() const {
125 return (*(edge_iterator.first));
126 }
127};
128
129} // namespace skeleton_blocker
130
131namespace skbl = skeleton_blocker;
132
133} // namespace Gudhi
134
135#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_
Iterator on the edges of a simplicial complex.
Definition: Skeleton_blockers_edges_iterators.h:88
Edge_iterator(const SkeletonBlockerComplex *complex_, int end)
Definition: Skeleton_blockers_edges_iterators.h:108
Class that represents a geometric complex that can be simplified. The class allows access to points o...
Definition: Skeleton_blocker_geometric_complex.h:29
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15