Blender  V3.3
ViewMapIterators.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include "ViewMap.h"
11 
12 #include "../system/Iterator.h" //soc
13 
14 namespace Freestyle {
15 
16 /**********************************/
17 /* */
18 /* */
19 /* ViewMap */
20 /* */
21 /* */
22 /**********************************/
23 
24 /**********************************/
25 /* */
26 /* */
27 /* ViewVertex */
28 /* */
29 /* */
30 /**********************************/
31 
32 namespace ViewVertexInternal {
33 
39  public:
40  friend class ViewVertex;
41  friend class TVertex;
42  friend class NonTVertex;
43  friend class ViewEdge;
44 
45  // FIXME
48 
49  protected:
50  Nature::VertexNature _Nature; // the nature of the underlying vertex
51  // T vertex attributes
52  edge_pointers_container::iterator _tbegin;
53  edge_pointers_container::iterator _tend;
54  edge_pointers_container::iterator _tvertex_iter;
55 
56  // Non TVertex attributes
57  edges_container::iterator _begin;
58  edges_container::iterator _end;
59  edges_container::iterator _nontvertex_iter;
60 
61  public:
64  {
65  }
66 
68  {
69  _Nature = iNature;
70  }
71 
74  {
75  _Nature = iBrother._Nature;
76  if (_Nature & Nature::T_VERTEX) {
77  _tbegin = iBrother._tbegin;
78  _tend = iBrother._tend;
79  _tvertex_iter = iBrother._tvertex_iter;
80  }
81  else {
82  _begin = iBrother._begin;
83  _end = iBrother._end;
85  }
86  }
87 
89  {
90  }
91 
92  public:
93  inline orientedViewEdgeIterator(edge_pointers_container::iterator begin,
94  edge_pointers_container::iterator end,
95  edge_pointers_container::iterator iter)
96  {
98  _tbegin = begin;
99  _tend = end;
100  _tvertex_iter = iter;
101  }
102 
103  inline orientedViewEdgeIterator(edges_container::iterator begin,
104  edges_container::iterator end,
105  edges_container::iterator iter)
106  {
108  _begin = begin;
109  _end = end;
110  _nontvertex_iter = iter;
111  }
112 
113  public:
116  virtual bool isBegin() const
117  {
118  if (_Nature & Nature::T_VERTEX) {
119  return (_tvertex_iter == _tbegin);
120  }
121  else {
122  return (_nontvertex_iter == _begin);
123  }
124  }
125 
128  virtual bool isEnd() const
129  {
130  if (_Nature & Nature::T_VERTEX) {
131  return (_tvertex_iter == _tend);
132  }
133  else {
134  return (_nontvertex_iter == _end);
135  }
136  }
137 
138  // operators
140  // operator corresponding to ++i
142  {
143  increment();
144  return *this;
145  }
146 
147  // operator corresponding to i++, i.e. which returns the value *and then* increments.
148  // That's why we store the value in a temp.
150  {
151  orientedViewEdgeIterator tmp = *this;
152  increment();
153  return tmp;
154  }
155 
156  // comparibility
158  virtual bool operator!=(const orientedViewEdgeIterator &b) const
159  {
160  if (_Nature & Nature::T_VERTEX) {
161  return (_tvertex_iter != b._tvertex_iter);
162  }
163  else {
164  return (_nontvertex_iter != b._nontvertex_iter);
165  }
166  }
167 
169  virtual bool operator==(const orientedViewEdgeIterator &b) const
170  {
171  return !(*this != b);
172  }
173 
174  // dereferencing
179  {
180  if (_Nature & Nature::T_VERTEX) {
181  // return _tvertex_iter;
182  return **_tvertex_iter;
183  }
184  else {
185  return (*_nontvertex_iter);
186  }
187  }
192  {
193  return &(operator*());
194  }
195 
196  public:
198  virtual inline int increment()
199  {
200  if (_Nature & Nature::T_VERTEX) {
201  ViewVertex::directedViewEdge tmp = (**_tvertex_iter);
202  ++_tvertex_iter;
203  if (_tvertex_iter != _tend) {
204  // FIXME : pquoi deja ?
205  ViewVertex::directedViewEdge tmp2 = (**_tvertex_iter);
206  if (tmp2.first == tmp.first) {
207  ++_tvertex_iter;
208  }
209  }
210  }
211  else {
213  }
214  return 0;
215  }
216 
217 #ifdef WITH_CXX_GUARDEDALLOC
218  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:orientedViewEdgeIterator")
219 #endif
220 };
221 
222 } // namespace ViewVertexInternal
223 
224 /**********************************/
225 /* */
226 /* */
227 /* ViewEdge */
228 /* */
229 /* */
230 /**********************************/
231 
232 namespace ViewEdgeInternal {
233 
234 //
235 // SVertexIterator
236 //
238 
240  public:
242  {
243  _vertex = NULL;
244  _begin = NULL;
245  _previous_edge = NULL;
246  _next_edge = NULL;
247  _t = 0;
248  }
249 
251  {
252  _vertex = vi._vertex;
253  _begin = vi._begin;
254  _previous_edge = vi._previous_edge;
255  _next_edge = vi._next_edge;
256  _t = vi._t;
257  }
258 
260  {
261  _vertex = v;
262  _begin = begin;
263  _previous_edge = prev;
264  _next_edge = next;
265  _t = t;
266  }
267 
269  {
270  _vertex = vi._vertex;
271  _begin = vi._begin;
272  _previous_edge = vi._previous_edge;
273  _next_edge = vi._next_edge;
274  _t = vi._t;
275  return *this;
276  }
277 
279  {
280  }
281 
282  virtual string getExactTypeName() const
283  {
284  return "SVertexIterator";
285  }
286 
287  virtual SVertex &operator*()
288  {
289  return *_vertex;
290  }
291 
292  virtual SVertex *operator->()
293  {
294  return &(operator*());
295  }
296 
298  {
299  increment();
300  return *this;
301  }
302 
304  {
305  SVertexIterator ret(*this);
306  increment();
307  return ret;
308  }
309 
311  {
312  decrement();
313  return *this;
314  }
315 
317  {
318  SVertexIterator ret(*this);
319  decrement();
320  return ret;
321  }
322 
323  virtual int increment()
324  {
325  if (!_next_edge) {
326  _vertex = NULL;
327  return 0;
328  }
329  _t += (float)_next_edge->getLength2D();
330  _vertex = _next_edge->vertexB();
331  _previous_edge = _next_edge;
332  _next_edge = _next_edge->nextEdge();
333  return 0;
334  }
335 
336  virtual int decrement()
337  {
338  if (!_previous_edge) {
339  _vertex = NULL;
340  return 0;
341  }
342  if ((!_next_edge) && (!_vertex)) {
343  _vertex = _previous_edge->vertexB();
344  return 0;
345  }
346  _t -= (float)_previous_edge->getLength2D();
347  _vertex = _previous_edge->vertexA();
348  _next_edge = _previous_edge;
349  _previous_edge = _previous_edge->previousEdge();
350  return 0;
351  }
352 
353  virtual bool isBegin() const
354  {
355  return _vertex == _begin;
356  }
357 
358  virtual bool isEnd() const
359  {
360  return (!_vertex) || (_vertex == _begin && _previous_edge);
361  }
362 
363  virtual float t() const
364  {
365  return _t;
366  }
367 
368  virtual float u() const
369  {
370  return _t / (float)_next_edge->viewedge()->getLength2D();
371  }
372 
373  virtual bool operator==(const Interface0DIteratorNested &it) const
374  {
375  const SVertexIterator *it_exact = dynamic_cast<const SVertexIterator *>(&it);
376  if (!it_exact) {
377  return false;
378  }
379  return (_vertex == it_exact->_vertex);
380  }
381 
382  virtual SVertexIterator *copy() const
383  {
384  return new SVertexIterator(*this);
385  }
386 
387  private:
388  SVertex *_vertex;
389  SVertex *_begin;
390  FEdge *_previous_edge;
391  FEdge *_next_edge;
392  float _t; // curvilinear abscissa
393 
394 #ifdef WITH_CXX_GUARDEDALLOC
395  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertexIterator")
396 #endif
397 };
398 
399 //
400 // ViewEdgeIterator (base class)
401 //
403 
409 class ViewEdgeIterator : public Iterator {
410  public:
419  ViewEdgeIterator(ViewEdge *begin = NULL, bool orientation = true)
420  {
421  _orientation = orientation;
422  _edge = begin;
423  _begin = begin;
424  }
425 
428  {
430  _edge = it._edge;
431  _begin = it._begin;
432  }
433 
435  {
436  }
437 
439  virtual string getExactTypeName() const
440  {
441  return "ViewEdgeIterator";
442  }
443 
446  {
447  return _edge;
448  }
449 
452  {
453  _edge = edge;
454  }
455 
458  {
459  return _begin;
460  }
461 
463  void setBegin(ViewEdge *begin)
464  {
465  _begin = begin;
466  }
467 
469  bool getOrientation() const
470  {
471  return _orientation;
472  }
473 
475  void setOrientation(bool orientation)
476  {
477  _orientation = orientation;
478  }
479 
482  {
484  }
485 
487  virtual ViewEdge *operator*()
488  {
489  return _edge;
490  }
491 
492  virtual ViewEdge *operator->()
493  {
494  return operator*();
495  }
496 
499  {
500  increment();
501  return *this;
502  }
503 
506  {
507  ViewEdgeIterator tmp(*this);
508  increment();
509  return tmp;
510  }
511 
513  virtual int increment()
514  {
515  cerr << "Warning: method increment() not implemented" << endl;
516  return 0;
517  }
518 
521  {
522  decrement();
523  return *this;
524  }
525 
528  {
529  ViewEdgeIterator tmp(*this);
530  decrement();
531  return tmp;
532  }
533 
535  virtual int decrement()
536  {
537  cerr << "Warning: method decrement() not implemented" << endl;
538  return 0;
539  }
540 
542  virtual bool isBegin() const
543  {
544  return _edge == _begin;
545  }
546 
548  virtual bool isEnd() const
549  {
550  return !_edge;
551  }
552 
554  virtual bool operator==(ViewEdgeIterator &it) const
555  {
556  return _edge == it._edge;
557  }
558 
560  virtual bool operator!=(ViewEdgeIterator &it) const
561  {
562  return !(*this == it);
563  }
564 
565  protected:
569 
570 #ifdef WITH_CXX_GUARDEDALLOC
571  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeIterator")
572 #endif
573 };
574 
575 } // end of namespace ViewEdgeInternal
576 
577 } /* namespace Freestyle */
typedef float(TangentPoint)[2]
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SVertex * vertexA()
Definition: Silhouette.h:597
ViewEdge * viewedge() const
Definition: Silhouette.h:658
FEdge * previousEdge()
Definition: Silhouette.h:631
SVertex * vertexB()
Definition: Silhouette.h:603
virtual real getLength2D() const
Definition: Silhouette.h:474
FEdge * nextEdge()
Definition: Silhouette.h:623
vector< directedViewEdge > edges_container
Definition: ViewMap.h:664
vector< directedViewEdge * > edge_pointers_container
Definition: ViewMap.h:381
virtual bool operator==(const Interface0DIteratorNested &it) const
virtual SVertexIterator * copy() const
SVertexIterator & operator=(const SVertexIterator &vi)
SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t)
ViewEdgeIterator(ViewEdge *begin=NULL, bool orientation=true)
virtual bool operator!=(ViewEdgeIterator &it) const
virtual bool operator==(ViewEdgeIterator &it) const
real getLength2D() const
Definition: ViewMap.cpp:650
virtual orientedViewEdgeIterator operator++(int)
virtual ViewVertex::directedViewEdge & operator*() const
virtual bool operator!=(const orientedViewEdgeIterator &b) const
TVertex::edge_pointers_container edge_pointers_container
orientedViewEdgeIterator(edges_container::iterator begin, edges_container::iterator end, edges_container::iterator iter)
orientedViewEdgeIterator(const orientedViewEdgeIterator &iBrother)
orientedViewEdgeIterator(edge_pointers_container::iterator begin, edge_pointers_container::iterator end, edge_pointers_container::iterator iter)
virtual ViewVertex::directedViewEdge * operator->() const
virtual bool operator==(const orientedViewEdgeIterator &b) const
pair< ViewEdge *, bool > directedViewEdge
Definition: ViewMap.h:266
static ulong * next
unsigned short VertexNature
Definition: Nature.h:18
static const VertexNature T_VERTEX
Definition: Nature.h:28
static const VertexNature NON_T_VERTEX
Definition: Nature.h:26
inherits from class Rep
Definition: AppCanvas.cpp:18
SymEdge< T > * prev(const SymEdge< T > *se)
Definition: delaunay_2d.cc:105
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
return ret