Delaunator
2D Delaunay Triangulation in C++ with Python wrapper.
 All Classes Namespaces Functions
face_iterators.h
1 #ifndef DELAUNATOR_FACE_ITERATORS_H_INCLUDED
2 #define DELAUNATOR_FACE_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 /******************************************************************
35  * ITERATORS ON FACES
36  ******************************************************************/
38  public:
39  // CONSTRUCTOR
40  IteratorOnFaces(std::vector<Face*>* v) : faces(v) {
41  this->it = this->faces->begin();
42  // ignore the faces that are not visible
43  while(!(*this->it)->isVisible()) this->it++;
44  }
45  // PUBLIC METHODS
46  IteratorOnFaces& next() {
47  this->it++;
48  return *this;
49  }
50  // OPERATORS
51  bool operator!=(const IteratorOnFaces& othr) const {
52  return this->it != othr.it;
53  }
54  bool operator!=(const std::vector<Face*>::iterator& ot) const {
55  return this->it != ot;
56  }
57  IteratorOnFaces& operator++(int) { return this->next(); }
58  Face* operator*() { //pointer dereferences
59  return *(this->it);
60  }
61  // ACCESSORS
62  std::vector<Face*>::iterator begin() const { return this->faces->begin(); }
63  std::vector<Face*>::iterator end() const { return this->faces->end(); }
64  std::vector<Face*>* getFaces() const { return this->faces; }
65  protected:
66  // ATTRIBUTES
67  std::vector<Face*>* faces;
68  std::vector<Face*>::iterator it;
69  // PRIVATE METHODS
70 };
72  public:
73  // CONSTRUCTOR
74  IteratorOnFaces_read(const std::vector<Face*>* const v) : faces(v) {
75  this->it = this->faces->begin();
76  // ignore the faces that are not visible
77  while(!(*this->it)->isVisible()) this->it++;
78  }
79  // PUBLIC METHODS
80  IteratorOnFaces_read& next() {
81  this->it++;
82  return *this;
83  }
84  // OPERATORS
85  bool operator!=(const IteratorOnFaces_read& othr) const {
86  return this->it != othr.it;
87  }
88  bool operator!=(const std::vector<Face*>::const_iterator& ot) const {
89  return this->it != ot;
90  }
91  IteratorOnFaces_read& operator++(int) { return this->next(); }
92  Face* operator*() { //pointer dereferences
93  return *(this->it);
94  }
95  // ACCESSORS
96  std::vector<Face*>::const_iterator begin() const { return this->faces->begin(); }
97  std::vector<Face*>::const_iterator end() const { return this->faces->end(); }
98  const std::vector<Face*>* getFaces() const { return this->faces; }
99  protected:
100  // ATTRIBUTES
101  const std::vector<Face*>* const faces;
102  std::vector<Face*>::const_iterator it;
103  // PRIVATE METHODS
104 };
105 
106 
107 
108 
109 
110 /******************************************************************
111  * ITERATORS ON ALLĀ FACES
112  ******************************************************************/
114  public:
115  // CONSTRUCTOR
116  IteratorOnAllFaces(std::vector<Face*>* v) : faces(v) {
117  this->it = this->faces->begin();
118  }
119  // PUBLIC METHODS
120  IteratorOnAllFaces& next() {
121  this->it++;
122  return *this;
123  }
124  // OPERATORS
125  bool operator!=(const IteratorOnAllFaces& othr) const {
126  return this->it != othr.it;
127  }
128  bool operator!=(const std::vector<Face*>::iterator& ot) const {
129  return this->it != ot;
130  }
131  IteratorOnAllFaces& operator++(int) { return this->next(); }
132  Face* operator*() { //pointer dereferences
133  return *(this->it);
134  }
135  // ACCESSORS
136  std::vector<Face*>::iterator begin() const { return this->faces->begin(); }
137  std::vector<Face*>::iterator end() const { return this->faces->end(); }
138  std::vector<Face*>* getFaces() const { return this->faces; }
139  protected:
140  // ATTRIBUTES
141  std::vector<Face*>* faces;
142  std::vector<Face*>::iterator it;
143  // PRIVATE METHODS
144 };
146  public:
147  // CONSTRUCTOR
148  IteratorOnAllFaces_read(const std::vector<Face*>* const v) : faces(v) {
149  this->it = this->faces->begin();
150  }
151  // PUBLIC METHODS
152  IteratorOnAllFaces_read& next() {
153  this->it++;
154  return *this;
155  }
156  // OPERATORS
157  bool operator!=(const IteratorOnAllFaces_read& othr) const {
158  return this->it != othr.it;
159  }
160  bool operator!=(const std::vector<Face*>::const_iterator& ot) const {
161  return this->it != ot;
162  }
163  IteratorOnAllFaces_read& operator++(int) { return this->next(); }
164  Face* operator*() { //pointer dereferences
165  return *(this->it);
166  }
167  // ACCESSORS
168  std::vector<Face*>::const_iterator begin() const { return this->faces->begin(); }
169  std::vector<Face*>::const_iterator end() const { return this->faces->end(); }
170  const std::vector<Face*>* getFaces() const { return this->faces; }
171  protected:
172  // ATTRIBUTES
173  const std::vector<Face*>* const faces;
174  std::vector<Face*>::const_iterator it;
175  // PRIVATE METHODS
176 };
177 
178 
179 
180 
181 
182 
183 
184 
185 /******************************************************************
186  * ITERATORS FACE TO VERTICES
187  ******************************************************************/
189  // iterate on the three Vertices of a Face.
190  public:
191  // CONSTRUCTOR
192  IteratorFaceToVertices(const Face* const f) : edge(f->getEdge()) {
193  this->ref_edge = this->edge;
194  }
195  // PUBLIC METHODS
196  IteratorFaceToVertices& next() {
197  this->edge = this->edge->nextLeftEdge();
198  if(this->edge == this->ref_edge)
199  this->edge = NULL;
200  return *this;
201  }
202  // OPERATORS
203  bool operator!=(const IteratorFaceToVertices& othr) const {
204  return this->edge != othr.edge;
205  }
206  bool operator!=(const Edge* ot) const {
207  return this->edge != ot;
208  }
209  IteratorFaceToVertices& operator++(int) { return this->next(); }
210  Vertex* operator*() { // pointer dereferences
211  return this->edge->originVertex();
212  }
213  // ACCESSORS
214  Edge* begin() const { return this->ref_edge; }
215  Edge* end() const { return NULL; }
216  protected:
217  // ATTRIBUTES
218  Edge* edge;
219  Edge* ref_edge;
220  // PRIVATE METHODS
221 };
222 
223 
224 
225 
226 
227 
228 /******************************************************************
229  * ITERATORS FACE TO EDGES
230  ******************************************************************/
232  // iterate on the three Edges of a Face.
233  public:
234  // CONSTRUCTOR
235  IteratorFaceToEdges(const Face* const f) : edge(f->getEdge()) {
236  this->ref_edge = this->edge;
237  }
238  // PUBLIC METHODS
239  IteratorFaceToEdges& next() {
240  this->edge = this->edge->nextLeftEdge();
241  if(this->edge == this->ref_edge)
242  this->edge = NULL;
243  return *this;
244  }
245  // OPERATORS
246  bool operator!=(const IteratorFaceToEdges& othr) const {
247  return this->edge != othr.edge;
248  }
249  bool operator!=(const Edge* ot) const {
250  return this->edge != ot;
251  }
252  IteratorFaceToEdges& operator++(int) { return this->next(); }
253  Edge* operator*() { // pointer dereferences
254  return this->edge;
255  }
256  // ACCESSORS
257  Edge* begin() const { return this->ref_edge; }
258  Edge* end() const { return NULL; }
259  protected:
260  // ATTRIBUTES
261  Edge* edge;
262  Edge* ref_edge;
263  // PRIVATE METHODS
264 };
265 
266 
267 
268 
269 
270 
271 /******************************************************************
272  * ITERATORS FACE TO NEIGHBOUR FACES
273  ******************************************************************/
275  public:
276  // CONSTRUCTOR
277  IteratorFaceToNeighbourFaces(Face* v) : edge(v->getEdge()) {}
278  // PUBLIC METHODS
279  Face* next() {
280  this->edge = this->edge->nextLeftEdge();
281  return this->edge->rightFace();
282  }
283  // ACCESSORS
284  protected:
285  // ATTRIBUTES
286  Edge* edge;
287  // PRIVATE METHODS
288 };
289 
290 
291 
292 
293 
294 
295 #endif