Delaunator
2D Delaunay Triangulation in C++ with Python wrapper.
 All Classes Namespaces Functions
vertex_iterators.h
1 #ifndef DELAUNATOR_VERTEX_ITERATORS_H_INCLUDED
2 #define DELAUNATOR_VERTEX_ITERATORS_H_INCLUDED
3 
4 
5 
6 /*
7  * LIBRARIES
8  */
9 // LOCAL MODULES
10 #include "commons.h"
11 #include "vertex.h"
12 #include "face.h"
13 #include "edge.h"
14 #include "iterators.h"
15 
16 
17 /*
18  * DEFINES
19  */
20 
21 
22 
23 
24 /*
25  * PREDECLARATIONS
26  */
27 // NB: iterators defined next() function for portability to Python's wraps,
28 // or other language where ++ unary operator don't exist.
29 // So, next() and operator++ are equivalent.
30 
31 
32 
33 /******************************************************************
34  * ITERATORS ON VERTICES
35  ******************************************************************/
37  public:
38  // CONSTRUCTOR
39  IteratorOnVertices(std::vector<Vertex*>* v) : vertices(v) {
40  // ignore the vertices that are not asked by user
41  this->it = this->vertices->begin()+4;
42  }
43  // PUBLIC METHODS
44  IteratorOnVertices& next() {
45  this->it++;
46  return *this;
47  }
48  // OPERATORS
49  bool operator!=(const IteratorOnVertices& othr) const {
50  return this->it != othr.it;
51  }
52  bool operator!=(const std::vector<Vertex*>::iterator& ot) const{
53  return this->it != ot;
54  }
55  IteratorOnVertices& operator++(int) { return this->next(); }
56  Vertex* operator*() { // pointer dereferences
57  return *(this->it);
58  }
59  // ACCESSORS
60  std::vector<Vertex*>::iterator begin() const { return this->vertices->begin(); }
61  std::vector<Vertex*>::iterator end() const { return this->vertices->end(); }
62  std::vector<Vertex*>* getVertices() const { return this->vertices; }
63  protected:
64  // ATTRIBUTES
65  std::vector<Vertex*>* vertices;
66  std::vector<Vertex*>::const_iterator it;
67  // PRIVATE METHODS
68 };
70  public:
71  // CONSTRUCTOR
72  IteratorOnVertices_read(const std::vector<Vertex*>* const v) : vertices(v) {
73  // ignore the vertices that are not asked by user
74  this->it = this->vertices->begin()+4;
75  }
76  // PUBLIC METHODS
77  IteratorOnVertices_read& next() {
78  this->it++;
79  return *this;
80  }
81  // OPERATORS
82  bool operator!=(const IteratorOnVertices_read& othr) const {
83  return this->it != othr.it;
84  }
85  bool operator!=(const std::vector<Vertex*>::const_iterator& ot) const {
86  return this->it != ot;
87  }
88  IteratorOnVertices_read& operator++(int) { return this->next(); }
89  Vertex* operator*() { // pointer dereferences
90  return *(this->it);
91  }
92  // ACCESSORS
93  std::vector<Vertex*>::const_iterator begin() const { return this->vertices->begin(); }
94  std::vector<Vertex*>::const_iterator end() const { return this->vertices->end(); }
95  const std::vector<Vertex*>* const getVertices() const { return this->vertices; }
96  protected:
97  // ATTRIBUTES
98  const std::vector<Vertex*>* const vertices;
99  std::vector<Vertex*>::const_iterator it;
100  // PRIVATE METHODS
101 };
102 
103 
104 
105 
106 
107 
108 
109 
110 /******************************************************************
111  * ITERATORS ON ALL VERTICES
112  ******************************************************************/
114  public:
115  // CONSTRUCTOR
116  IteratorOnAllVertices(std::vector<Vertex*>* v) : vertices(v) {
117  this->it = this->vertices->begin();
118  }
119  // PUBLIC METHODS
120  IteratorOnAllVertices& next() {
121  this->it++;
122  return *this;
123  }
124  // OPERATORS
125  bool operator!=(const IteratorOnAllVertices& othr) const {
126  return this->it != othr.it;
127  }
128  bool operator!=(const std::vector<Vertex*>::iterator& ot) const{
129  return this->it != ot;
130  }
131  IteratorOnAllVertices& operator++(int) { return this->next(); }
132  Vertex* operator*() { // pointer dereferences
133  return *(this->it);
134  }
135  // ACCESSORS
136  std::vector<Vertex*>::iterator begin() const { return this->vertices->begin(); }
137  std::vector<Vertex*>::iterator end() const { return this->vertices->end(); }
138  std::vector<Vertex*>* getVertices() const { return this->vertices; }
139  protected:
140  // ATTRIBUTES
141  std::vector<Vertex*>* vertices;
142  std::vector<Vertex*>::const_iterator it;
143  // PRIVATE METHODS
144 };
146  public:
147  // CONSTRUCTOR
148  IteratorOnAllVertices_read(const std::vector<Vertex*>* const v) : vertices(v) {
149  this->it = this->vertices->begin();
150  }
151  // PUBLIC METHODS
152  IteratorOnAllVertices_read& next() {
153  this->it++;
154  return *this;
155  }
156  // OPERATORS
157  bool operator!=(const IteratorOnAllVertices_read& othr) const {
158  return this->it != othr.it;
159  }
160  bool operator!=(const std::vector<Vertex*>::const_iterator& ot) const {
161  return this->it != ot;
162  }
163  IteratorOnAllVertices_read& operator++(int) { return this->next(); }
164  Vertex* operator*() { // pointer dereferences
165  return *(this->it);
166  }
167  // ACCESSORS
168  std::vector<Vertex*>::const_iterator begin() const { return this->vertices->begin(); }
169  std::vector<Vertex*>::const_iterator end() const { return this->vertices->end(); }
170  const std::vector<Vertex*>* const getVertices() const { return this->vertices; }
171  protected:
172  // ATTRIBUTES
173  const std::vector<Vertex*>* const vertices;
174  std::vector<Vertex*>::const_iterator it;
175  // PRIVATE METHODS
176 };
177 
178 
179 
180 
181 
182 /******************************************************************
183  * ITERATORS VERTEX TO NEIGHBOUR VERTICES
184  ******************************************************************/
186  public:
187  // CONSTRUCTOR
189  this->ref = it;
190  }
191  // PUBLIC METHODS
192  // OPERATORS
194  this->it = this->it->rotLeftEdge();
195  if(this->it == this->ref) this->it = NULL;
196  return *this;
197  }
198  bool operator!=(const IteratorVertexToNeighbourVertices& othr) const {
199  return this->it != othr.it;
200  }
201  bool operator==(const IteratorVertexToNeighbourVertices& othr) const {
202  return this->it == othr.it;
203  }
204  bool operator!=(const Edge* ot) const {
205  return this->it != ot;
206  }
207  bool operator==(const Edge* ot) const {
208  return this->it == ot;
209  }
210  IteratorVertexToNeighbourVertices& operator++(int) { return this->next(); }
211  Vertex* operator*() { //pointer dereferences
212  return this->getItem();
213  }
214  // ACCESSORS
215  Edge* end() const { return NULL; }
216  Vertex* getItem() const { return this->it->destinVertex(); }
217  protected:
218  // ATTRIBUTES
219  Edge *it, *ref;
220  // PRIVATE METHODS
221 };
222 
223 
224 
225 
226 
227 
228 /******************************************************************
229  * ITERATORS VERTEX TO NEIGHBOUR EDGES
230  ******************************************************************/
232  public:
233  // CONSTRUCTOR
235  this->ref = it;
236  }
237  // PUBLIC METHODS
238  // OPERATORS
240  this->it = this->it->rotLeftEdge();
241  if(this->it == this->ref) this->it = NULL;
242  return *this;
243  }
244  bool operator!=(const IteratorVertexToNeighbourEdges& othr) const {
245  return this->it != othr.it;
246  }
247  bool operator==(const IteratorVertexToNeighbourEdges& othr) const {
248  return this->it == othr.it;
249  }
250  bool operator!=(const Edge* ot) const {
251  return this->it != ot;
252  }
253  bool operator==(const Edge* ot) const {
254  return this->it == ot;
255  }
256  IteratorVertexToNeighbourEdges& operator++(int) { return this->next(); }
257  Edge* operator*() { //pointer dereferences
258  return this->getItem();
259  }
260  // ACCESSORS
261  Edge* end() const { return NULL; }
262  Edge* getItem() const { return this->it; }
263  protected:
264  // ATTRIBUTES
265  Edge *it, *ref;
266  // PRIVATE METHODS
267 };
268 
269 
270 
271 
272 
273 #endif