Blender V4.3
ViewMapIterators.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
12#include "ViewMap.h"
13
14#include "../system/Iterator.h" //soc
15
16namespace Freestyle {
17
18/**********************************/
19/* */
20/* */
21/* ViewMap */
22/* */
23/* */
24/**********************************/
25
26/**********************************/
27/* */
28/* */
29/* ViewVertex */
30/* */
31/* */
32/**********************************/
33
34namespace ViewVertexInternal {
35
41 public:
42 friend class ViewVertex;
43 friend class TVertex;
44 friend class NonTVertex;
45 friend class ViewEdge;
46
47 // FIXME
50
51 protected:
52 Nature::VertexNature _Nature; // the nature of the underlying vertex
53 // T vertex attributes
54 edge_pointers_container::iterator _tbegin;
55 edge_pointers_container::iterator _tend;
56 edge_pointers_container::iterator _tvertex_iter;
57
58 // Non TVertex attributes
59 edges_container::iterator _begin;
60 edges_container::iterator _end;
61 edges_container::iterator _nontvertex_iter;
62
63 public:
66
68 {
69 _Nature = iNature;
70 }
71
74 {
75 _Nature = iBrother._Nature;
77 _tbegin = iBrother._tbegin;
78 _tend = iBrother._tend;
80 }
81 else {
82 _begin = iBrother._begin;
83 _end = iBrother._end;
85 }
86 }
87
89
90 public:
91 inline orientedViewEdgeIterator(edge_pointers_container::iterator begin,
92 edge_pointers_container::iterator end,
93 edge_pointers_container::iterator iter)
94 {
96 _tbegin = begin;
97 _tend = end;
98 _tvertex_iter = iter;
99 }
100
101 inline orientedViewEdgeIterator(edges_container::iterator begin,
102 edges_container::iterator end,
103 edges_container::iterator iter)
104 {
106 _begin = begin;
107 _end = end;
108 _nontvertex_iter = iter;
109 }
110
111 public:
114 virtual bool isBegin() const
115 {
117 return (_tvertex_iter == _tbegin);
118 }
119 else {
120 return (_nontvertex_iter == _begin);
121 }
122 }
123
126 virtual bool isEnd() const
127 {
129 return (_tvertex_iter == _tend);
130 }
131 else {
132 return (_nontvertex_iter == _end);
133 }
134 }
135
136 // operators
138 // operator corresponding to ++i
140 {
141 increment();
142 return *this;
143 }
144
145 // operator corresponding to i++, i.e. which returns the value *and then* increments.
146 // That's why we store the value in a temp.
148 {
149 orientedViewEdgeIterator tmp = *this;
150 increment();
151 return tmp;
152 }
153
154 // comparibility
156 virtual bool operator!=(const orientedViewEdgeIterator &b) const
157 {
159 return (_tvertex_iter != b._tvertex_iter);
160 }
161 else {
162 return (_nontvertex_iter != b._nontvertex_iter);
163 }
164 }
165
167 virtual bool operator==(const orientedViewEdgeIterator &b) const
168 {
169 return !(*this != b);
170 }
171
172 // dereferencing
177 {
179 // return _tvertex_iter;
180 return **_tvertex_iter;
181 }
182 else {
183 return (*_nontvertex_iter);
184 }
185 }
190 {
191 return &(operator*());
192 }
193
194 public:
196 virtual inline int increment()
197 {
199 ViewVertex::directedViewEdge tmp = (**_tvertex_iter);
201 if (_tvertex_iter != _tend) {
202 // FIXME : pquoi deja ?
203 ViewVertex::directedViewEdge tmp2 = (**_tvertex_iter);
204 if (tmp2.first == tmp.first) {
206 }
207 }
208 }
209 else {
211 }
212 return 0;
213 }
214
215#ifdef WITH_CXX_GUARDEDALLOC
216 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:orientedViewEdgeIterator")
217#endif
218};
219
220} // namespace ViewVertexInternal
221
222/**********************************/
223/* */
224/* */
225/* ViewEdge */
226/* */
227/* */
228/**********************************/
229
230namespace ViewEdgeInternal {
231
232//
233// SVertexIterator
234//
236
238 public:
240 {
241 _vertex = nullptr;
242 _begin = nullptr;
243 _previous_edge = nullptr;
244 _next_edge = nullptr;
245 _t = 0;
246 }
247
249 {
250 _vertex = vi._vertex;
251 _begin = vi._begin;
252 _previous_edge = vi._previous_edge;
253 _next_edge = vi._next_edge;
254 _t = vi._t;
255 }
256
257 SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t)
258 {
259 _vertex = v;
260 _begin = begin;
261 _previous_edge = prev;
262 _next_edge = next;
263 _t = t;
264 }
265
267 {
268 _vertex = vi._vertex;
269 _begin = vi._begin;
270 _previous_edge = vi._previous_edge;
271 _next_edge = vi._next_edge;
272 _t = vi._t;
273 return *this;
274 }
275
276 virtual ~SVertexIterator() {}
277
278 virtual string getExactTypeName() const
279 {
280 return "SVertexIterator";
281 }
282
284 {
285 return *_vertex;
286 }
287
289 {
290 return &(operator*());
291 }
292
294 {
295 increment();
296 return *this;
297 }
298
300 {
301 SVertexIterator ret(*this);
302 increment();
303 return ret;
304 }
305
307 {
308 decrement();
309 return *this;
310 }
311
313 {
314 SVertexIterator ret(*this);
315 decrement();
316 return ret;
317 }
318
319 virtual int increment()
320 {
321 if (!_next_edge) {
322 _vertex = nullptr;
323 return 0;
324 }
325 _t += (float)_next_edge->getLength2D();
326 _vertex = _next_edge->vertexB();
327 _previous_edge = _next_edge;
328 _next_edge = _next_edge->nextEdge();
329 return 0;
330 }
331
332 virtual int decrement()
333 {
334 if (!_previous_edge) {
335 _vertex = nullptr;
336 return 0;
337 }
338 if ((!_next_edge) && (!_vertex)) {
339 _vertex = _previous_edge->vertexB();
340 return 0;
341 }
342 _t -= (float)_previous_edge->getLength2D();
343 _vertex = _previous_edge->vertexA();
344 _next_edge = _previous_edge;
345 _previous_edge = _previous_edge->previousEdge();
346 return 0;
347 }
348
349 virtual bool isBegin() const
350 {
351 return _vertex == _begin;
352 }
353
354 virtual bool isEnd() const
355 {
356 return (!_vertex) || (_vertex == _begin && _previous_edge);
357 }
358
359 virtual float t() const
360 {
361 return _t;
362 }
363
364 virtual float u() const
365 {
366 return _t / (float)_next_edge->viewedge()->getLength2D();
367 }
368
369 virtual bool operator==(const Interface0DIteratorNested &it) const
370 {
371 const SVertexIterator *it_exact = dynamic_cast<const SVertexIterator *>(&it);
372 if (!it_exact) {
373 return false;
374 }
375 return (_vertex == it_exact->_vertex);
376 }
377
378 virtual SVertexIterator *copy() const
379 {
380 return new SVertexIterator(*this);
381 }
382
383 private:
384 SVertex *_vertex;
385 SVertex *_begin;
386 FEdge *_previous_edge;
387 FEdge *_next_edge;
388 float _t; // curvilinear abscissa
389
390#ifdef WITH_CXX_GUARDEDALLOC
391 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertexIterator")
392#endif
393};
394
395//
396// ViewEdgeIterator (base class)
397//
399
406 public:
415 ViewEdgeIterator(ViewEdge *begin = nullptr, bool orientation = true)
416 {
417 _orientation = orientation;
418 _edge = begin;
419 _begin = begin;
420 }
421
424 {
425 _orientation = it._orientation;
426 _edge = it._edge;
427 _begin = it._begin;
428 }
429
430 virtual ~ViewEdgeIterator() {}
431
433 virtual string getExactTypeName() const
434 {
435 return "ViewEdgeIterator";
436 }
437
440 {
441 return _edge;
442 }
443
446 {
447 _edge = edge;
448 }
449
452 {
453 return _begin;
454 }
455
457 void setBegin(ViewEdge *begin)
458 {
459 _begin = begin;
460 }
461
463 bool getOrientation() const
464 {
465 return _orientation;
466 }
467
469 void setOrientation(bool orientation)
470 {
471 _orientation = orientation;
472 }
473
476 {
478 }
479
482 {
483 return _edge;
484 }
485
487 {
488 return operator*();
489 }
490
493 {
494 increment();
495 return *this;
496 }
497
500 {
501 ViewEdgeIterator tmp(*this);
502 increment();
503 return tmp;
504 }
505
507 virtual int increment()
508 {
509 cerr << "Warning: method increment() not implemented" << endl;
510 return 0;
511 }
512
515 {
516 decrement();
517 return *this;
518 }
519
522 {
523 ViewEdgeIterator tmp(*this);
524 decrement();
525 return tmp;
526 }
527
529 virtual int decrement()
530 {
531 cerr << "Warning: method decrement() not implemented" << endl;
532 return 0;
533 }
534
536 virtual bool isBegin() const
537 {
538 return _edge == _begin;
539 }
540
542 virtual bool isEnd() const
543 {
544 return !_edge;
545 }
546
548 virtual bool operator==(ViewEdgeIterator &it) const
549 {
550 return _edge == it._edge;
551 }
552
554 virtual bool operator!=(ViewEdgeIterator &it) const
555 {
556 return !(*this == it);
557 }
558
559 protected:
563
564#ifdef WITH_CXX_GUARDEDALLOC
565 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeIterator")
566#endif
567};
568
569} // end of namespace ViewEdgeInternal
570
571} /* namespace Freestyle */
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
ATTR_WARN_UNUSED_RESULT const BMVert * v
ViewEdge * viewedge() const
Definition Silhouette.h:658
FEdge * nextEdge()
Definition Silhouette.h:623
SVertex * vertexA()
Definition Silhouette.h:597
SVertex * vertexB()
Definition Silhouette.h:603
virtual real getLength2D() const
Definition Silhouette.h:476
FEdge * previousEdge()
Definition Silhouette.h:631
vector< directedViewEdge > edges_container
Definition ViewMap.h:661
vector< directedViewEdge * > edge_pointers_container
Definition ViewMap.h:378
SVertexIterator & operator=(const SVertexIterator &vi)
virtual SVertexIterator * copy() const
virtual bool operator==(const Interface0DIteratorNested &it) const
SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t)
ViewEdgeIterator(ViewEdge *begin=nullptr, bool orientation=true)
virtual bool operator!=(ViewEdgeIterator &it) const
virtual bool operator==(ViewEdgeIterator &it) const
real getLength2D() const
Definition ViewMap.cpp:667
virtual bool operator!=(const orientedViewEdgeIterator &b) const
virtual ViewVertex::directedViewEdge & operator*() const
virtual ViewVertex::directedViewEdge * operator->() const
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 bool operator==(const orientedViewEdgeIterator &b) const
pair< ViewEdge *, bool > directedViewEdge
Definition ViewMap.h:267
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
static ulong * next
ushort VertexNature
Definition Nature.h:22
static const VertexNature T_VERTEX
Definition Nature.h:32
static const VertexNature NON_T_VERTEX
Definition Nature.h:30
inherits from class Rep
Definition AppCanvas.cpp:20
return ret