Blender V4.3
ViewMapAdvancedIterators.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
13#include "ViewMap.h"
14#include "ViewMapIterators.h"
15
16#include "../system/Iterator.h" //soc
17
18namespace Freestyle {
19
20/**********************************/
21/* */
22/* */
23/* ViewMap */
24/* */
25/* */
26/**********************************/
27
28/**********************************/
29/* */
30/* */
31/* ViewVertex */
32/* */
33/* */
34/**********************************/
35
36namespace ViewVertexInternal {
37
38class edge_const_traits : public Const_traits<ViewVertex::directedViewEdge> {
39 public:
40 typedef vector<ViewVertex::directedViewEdge> edges_container;
41 typedef edges_container::const_iterator edges_container_iterator;
42 typedef vector<ViewVertex::directedViewEdge *> edge_pointers_container;
43 typedef edge_pointers_container::const_iterator edge_pointers_container_iterator;
44};
45
46class edge_nonconst_traits : public Nonconst_traits<ViewVertex::directedViewEdge> {
47 public:
48 typedef vector<ViewVertex::directedViewEdge> edges_container;
49 typedef edges_container::iterator edges_container_iterator;
50 typedef vector<ViewVertex::directedViewEdge *> edge_pointers_container;
51 typedef edge_pointers_container::iterator edge_pointers_container_iterator;
52};
53
54template<class Traits>
55class edge_iterator_base : public IteratorBase<Traits, InputIteratorTag_Traits> {
56 public:
57 typedef typename Traits::value_type value_type;
58 typedef typename Traits::difference_type difference_type;
59 typedef typename Traits::pointer pointer;
60 typedef typename Traits::reference reference;
62 typedef typename Traits::edges_container_iterator edges_container_iterator;
63 typedef typename Traits::edge_pointers_container_iterator edge_pointers_container_iterator;
66
67 public:
68 friend class ViewVertex;
69 friend class TVertex;
70 friend class NonTVertex;
71 friend class ViewEdge;
72 friend class edge_iterator;
73
74 protected:
75 Nature::VertexNature _Nature; // the nature of the underlying vertex
76 // T vertex attributes
80
81#if 0
83 value_type _feA;
84 value_type _feB;
85 value_type _beA;
86 value_type _beB;
87#endif
88
89 // Non TVertex attributes
93
95
96 public:
98
100 {
101 _Nature = iNature;
102 }
103
105 : parent_class(iBrother)
106 {
107 _Nature = iBrother._Nature;
109#if 0
110 _feA = iBrother._feA;
111 _feB = iBrother._feB;
112 _beA = iBrother._beA;
113 _beB = iBrother._beB;
114 _tvertex_iter = iBrother._tvertex_iter;
115#endif
116 _tbegin = iBrother._tbegin;
117 _tend = iBrother._tend;
118 _tvertex_iter = iBrother._tvertex_iter;
119 }
120 else {
121 _begin = iBrother._begin;
122 _end = iBrother._end;
124 }
125 }
126
128 : parent_class(iBrother)
129 {
130 _Nature = iBrother._Nature;
132#if 0
133 _feA = iBrother._feA;
134 _feB = iBrother._feB;
135 _beA = iBrother._beA;
136 _beB = iBrother._beB;
137 _tvertex_iter = iBrother._tvertex_iter;
138#endif
139 _tbegin = iBrother._tbegin;
140 _tend = iBrother._tend;
141 _tvertex_iter = iBrother._tvertex_iter;
142 }
143 else {
144 _begin = iBrother._begin;
145 _end = iBrother._end;
147 }
148 }
149
151
152 // protected://FIXME
153 public:
154#if 0
155 inline edge_iterator_base(
156 value_type ifeA, value_type ifeB, value_type ibeA, value_type ibeB, value_type iter)
157 : parent_class()
158 {
160 _feA = ifeA;
161 _feB = ifeB;
162 _beA = ibeA;
163 _beB = ibeB;
164 _tvertex_iter = iter;
165 }
166#endif
167
178
189
190 public:
191 virtual bool begin() const
192 {
194 return (_tvertex_iter == _tbegin);
195 // return (_tvertex_iter == _feA);
196 }
197 else {
198 return (_nontvertex_iter == _begin);
199 }
200 }
201
202 virtual bool end() const
203 {
205 // return (_tvertex_iter.first == 0);
206 return (_tvertex_iter == _tend);
207 }
208 else {
209 return (_nontvertex_iter == _end);
210 }
211 }
212
213 // operators
214 // operator corresponding to ++i
215 virtual Self &operator++()
216 {
217 increment();
218 return *this;
219 }
220
221 // operator corresponding to i++, i.e. which returns the value *and then* increments it.
222 // That's why we store the value in a temp.
223 virtual Self operator++(int)
224 {
225 Self tmp = *this;
226 increment();
227 return tmp;
228 }
229
230 // comparibility
231 virtual bool operator!=(const Self &b) const
232 {
234 return (_tvertex_iter != b._tvertex_iter);
235 }
236 else {
237 return (_nontvertex_iter != b._nontvertex_iter);
238 }
239 }
240
241 virtual bool operator==(const Self &b) const
242 {
243 return !(*this != b);
244 }
245
246 // dereferencing
247 virtual reference operator*() const
248 {
250 // return _tvertex_iter;
251 return **_tvertex_iter;
252 }
253 else {
254 return (*_nontvertex_iter);
255 }
256 }
257
258 virtual pointer operator->() const
259 {
260 return &(operator*());
261 }
262
263 protected:
264 inline void increment()
265 {
267 value_type tmp = (**_tvertex_iter);
269 value_type tmp2 = (**_tvertex_iter);
270 if (tmp2.first == tmp.first) {
272 }
273#if 0
274 // Hack to deal with cusp. the result of a cusp is a TVertex having two identical viewedges.
275 // In order to iterate properly, we chose to skip these last ones.
276 if (_feB.first == _beA.first) {
277 if (_feA.first == _beB.first) {
278 _tvertex_iter.first = 0;
279 return;
280 }
281
282 if (_tvertex_iter.first == _feA.first) {
283 _tvertex_iter.first = _beB.first;
284 }
285 else if (_tvertex_iter.first == _beB.first) {
286 _tvertex_iter.first = 0;
287 }
288 else {
289 _tvertex_iter.first = _feA.first;
290 }
291 return;
292 }
293 if (_feA.first == _beB.first) {
294 if (_feB.first == _beA.first) {
295 _tvertex_iter.first = 0;
296 return;
297 }
298
299 if (_tvertex_iter.first == _feB.first) {
300 _tvertex_iter.first = _beA.first;
301 }
302 else if (_tvertex_iter.first == _beA.first) {
303 _tvertex_iter.first = 0;
304 }
305 else {
306 _tvertex_iter.first = _feB.first;
307 }
308 return;
309 }
310 // End of hack
311
312 if (_tvertex_iter.first == _feA.first) {
313 // we return bea or beb
314 // choose one of them
315 _tvertex_iter.first = _feB.first;
316 return;
317 }
318 if (_tvertex_iter.first == _feB.first) {
319 _tvertex_iter.first = _beA.first;
320 return;
321 }
322 if (_tvertex_iter.first == _beA.first) {
323 _tvertex_iter.first = _beB.first;
324 return;
325 }
326 if (_tvertex_iter.first == _beB.first) {
327 _tvertex_iter.first = 0;
328 return;
329 }
330#endif
331 }
332 else {
334 }
335 }
336};
337
338} // namespace ViewVertexInternal
339
340/**********************************/
341/* */
342/* */
343/* ViewEdge */
344/* */
345/* */
346/**********************************/
347
348namespace ViewEdgeInternal {
349
353template<class Traits>
354class edge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
355 public:
356 typedef typename Traits::value_type value_type;
357 typedef typename Traits::difference_type difference_type;
358 typedef typename Traits::pointer pointer;
359 typedef typename Traits::reference reference;
361
362 public:
364 // friend class edge_iterator_base<Nonconst_traits<ViewEdge*> >;
365 // friend class edge_iterator_base<Const_traits<ViewEdge*> >;
369
370 public:
371 friend class ViewEdge;
373 {
374 _orientation = true;
375 _first = 0;
376 }
377
379 : parent_class()
380 {
381 _ViewEdge = iBrother._ViewEdge;
382 _first = iBrother._first;
383 _orientation = iBrother._orientation;
384 }
385
387 : parent_class()
388 {
389 _ViewEdge = iBrother._ViewEdge;
390 _first = iBrother._first;
391 _orientation = iBrother._orientation;
392 }
393
394 // protected://FIXME
395 public:
397 {
398 _ViewEdge = iEdge;
399 _first = iEdge;
401 }
402
403 public:
404 virtual Self *clone() const
405 {
406 return new edge_iterator_base(*this);
407 }
408
410
411 public:
412 virtual bool orientation()
413 {
414 return _orientation;
415 }
416
417 virtual void set_edge(value_type iVE)
418 {
419 _ViewEdge = iVE;
420 }
421
422 virtual void set_orientation(bool iOrientation)
423 {
424 _orientation = iOrientation;
425 }
426
427 virtual void change_orientation()
428 {
430 }
431
432 // operators
433 // operator corresponding to ++i
434 inline Self &operator++()
435 {
436 //++_ViewEdge->getTimeStamp();
437 increment();
438 return *this;
439 }
440
441 // operator corresponding to i++, i.e. which returns the value *and then* increments it.
442 // That's why we store the value in a temp.
443 inline Self operator++(int)
444 {
445 //++_ViewEdge->getTimeStamp();
446 Self tmp = *this;
447 increment();
448 return tmp;
449 }
450
451 // operator corresponding to --i
452 inline Self &operator--()
453 {
454 //++_ViewEdge->getTimeStamp();
455 decrement();
456 return *this;
457 }
458
459 // operator corresponding to i--, i.e. which returns the value *and then* increments it.
460 // That's why we store the value in a temp.
461 inline Self operator--(int)
462 {
463 //++_ViewEdge->getTimeStamp();
464 Self tmp = *this;
465 decrement();
466 return tmp;
467 }
468
469 // comparibility
470 virtual bool operator!=(const Self &b) const
471 {
472 return (_ViewEdge != b._ViewEdge);
473 }
474
475 virtual bool operator==(const Self &b) const
476 {
477 return !(*this != b);
478 }
479
480 // dereferencing
481 virtual reference operator*() const
482 {
483 return _ViewEdge;
484 }
485
486 virtual pointer operator->() const
487 {
488 return &(operator*());
489 }
490
491 public:
492 virtual bool begin() const
493 {
494 return (_ViewEdge == _first) ? true : false;
495 }
496
497 virtual bool end() const
498 {
499 return (_ViewEdge == 0) ? true : false;
500 }
501
502 protected:
503 virtual void increment() {}
504 virtual void decrement() {}
505};
506
507template<class Traits>
508class fedge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
509 public:
510 typedef typename Traits::value_type value_type;
511 typedef typename Traits::difference_type difference_type;
512 typedef typename Traits::pointer pointer;
513 typedef typename Traits::reference reference;
515
516 public:
520 value_type _FEdgeB; // last fedge of the view edge
521
522 public:
523 friend class ViewEdge;
524 friend class fedge_iterator;
525
527
529 : parent_class()
530 {
531 _FEdge = iBrother._FEdge;
532 _first = iBrother._first;
533 _FEdgeB = iBrother._FEdgeB;
534 }
535
537 : parent_class()
538 {
539 _FEdge = iBrother._FEdge;
540 _first = iBrother._first;
541 _FEdgeB = iBrother._FEdgeB;
542 }
543
544 // protected://FIXME
545 public:
547 {
548 _FEdge = iEdge;
549 _first = iEdge;
550 _FEdgeB = iFEdgeB;
551 }
552
553 public:
555
556 // operators
557 // operator corresponding to ++i.
558 inline Self &operator++()
559 {
560 increment();
561 return *this;
562 }
563
564 // operator corresponding to i++, i.e. which returns the value *and then* increments it.
565 // That's why we store the value in a temp.
566 inline Self operator++(int)
567 {
568 Self tmp = *this;
569 increment();
570 return tmp;
571 }
572
573 // operator corresponding to --i
574 inline Self &operator--()
575 {
576 decrement();
577 return *this;
578 }
579
580 // operator corresponding to i--, i.e. which returns the value *and then* increments it.
581 // That's why we store the value in a temp.
582 inline Self operator--(int)
583 {
584 Self tmp = *this;
585 decrement();
586 return tmp;
587 }
588
589 // comparibility
590 virtual bool operator!=(const Self &b) const
591 {
592 return (_FEdge != b._FEdge);
593 }
594
595 virtual bool operator==(const Self &b) const
596 {
597 return !(*this != b);
598 }
599
600 // dereferencing
601 virtual reference operator*() const
602 {
603 return _FEdge;
604 }
605
606 virtual pointer operator->() const
607 {
608 return &(operator*());
609 }
610
611 public:
612 virtual bool begin() const
613 {
614 return (_FEdge == _first) ? true : false;
615 }
616
617 virtual bool end() const
618 {
619 return (_FEdge == 0) ? true : false;
620 }
621
622 protected:
623 virtual void increment()
624 {
625 _FEdge = _FEdge->nextEdge(); // we don't change or
626 }
627
628 virtual void decrement()
629 {
630 if (0 == _FEdge) {
631 _FEdge = _FEdgeB;
632 return;
633 }
634 _FEdge = _FEdge->previousEdge(); // we don't change or
635 }
636};
637
638template<class Traits>
639class vertex_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
640 public:
641 typedef typename Traits::value_type value_type;
642 typedef typename Traits::difference_type difference_type;
643 typedef typename Traits::pointer pointer;
644 typedef typename Traits::reference reference;
646
647 protected:
649
650 public:
654
655 public:
656 friend class ViewEdge;
657 friend class vertex_iterator;
658
660
662 : parent_class()
663 {
664 _SVertex = iBrother._SVertex;
665 _NextFEdge = iBrother._NextFEdge;
666 _PreviousFEdge = iBrother._PreviousFEdge;
667 }
668
670 : parent_class()
671 {
672 _SVertex = iBrother._SVertex;
673 _NextFEdge = iBrother._NextFEdge;
674 _PreviousFEdge = iBrother._PreviousFEdge;
675 }
676
677 // protected://FIXME
678 public:
679 inline vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge)
680 : parent_class()
681 {
682 _SVertex = iVertex;
683 _NextFEdge = iNextFEdge;
684 _PreviousFEdge = iPreviousFEdge;
685 }
686
687 public:
689
690 virtual bool begin() const
691 {
692 return (_PreviousFEdge == 0) ? true : false;
693 }
694
695 virtual bool end() const
696 {
697 return (_SVertex == 0) ? true : false;
698 }
699
700 // operators
701 // operator corresponding to ++i
702 inline Self &operator++()
703 {
704 increment();
705 return *this;
706 }
707
708 // operator corresponding to i++, i.e. which returns the value *and then* increments it.
709 // That's why we store the value in a temp.
710 inline Self operator++(int)
711 {
712 Self tmp = *this;
713 increment();
714 return tmp;
715 }
716
717 // operator corresponding to --i
718 inline Self &operator--()
719 {
720 decrement();
721 return *this;
722 }
723
724 // operator corresponding to --i, i.e. which returns the value *and then* increments it.
725 // That's why we store the value in a temp.
726 inline Self operator--(int)
727 {
728 Self tmp = *this;
729 decrement();
730 return tmp;
731 }
732
733 // comparibility
734 virtual bool operator!=(const Self &b) const
735 {
736 return (_SVertex != b._SVertex);
737 }
738
739 virtual bool operator==(const Self &b) const
740 {
741 return !(*this != b);
742 }
743
744 // dereferencing
745 virtual reference operator*() const
746 {
747 return _SVertex;
748 }
749
750 virtual pointer operator->() const
751 {
752 return &(operator*());
753 }
754
755 protected:
756 virtual void increment()
757 {
758 if (!_NextFEdge) {
759 _SVertex = nullptr;
760 return;
761 }
765 }
766
767 virtual void decrement()
768 {
769#if 0
770 if (!_SVertex) {
772 return;
773 }
774#endif
775 if (!_PreviousFEdge) {
776 _SVertex = nullptr;
777 return;
778 }
782 }
783};
784
785} // end of namespace ViewEdgeInternal
786
787} /* namespace Freestyle */
Iterators used to iterate over the various elements of the ViewMap.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
FEdge * nextEdge()
Definition Silhouette.h:623
SVertex * vertexA()
Definition Silhouette.h:597
SVertex * vertexB()
Definition Silhouette.h:603
FEdge * previousEdge()
Definition Silhouette.h:631
IteratorBase< Traits, BidirectionalIteratorTag_Traits > parent_class
edge_iterator_base(const edge_iterator_base< Nonconst_traits< ViewEdge * > > &iBrother)
edge_iterator_base(const edge_iterator_base< Const_traits< ViewEdge * > > &iBrother)
edge_iterator_base(value_type iEdge, bool orientation=true)
fedge_iterator_base(value_type iEdge, value_type iFEdgeB)
IteratorBase< Traits, BidirectionalIteratorTag_Traits > parent_class
fedge_iterator_base(const fedge_iterator_base< Const_traits< FEdge * > > &iBrother)
fedge_iterator_base(const fedge_iterator_base< Nonconst_traits< FEdge * > > &iBrother)
vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge)
vertex_iterator_base(const vertex_iterator_base< Const_traits< SVertex * > > &iBrother)
IteratorBase< Traits, BidirectionalIteratorTag_Traits > parent_class
vertex_iterator_base(const vertex_iterator_base< Nonconst_traits< SVertex * > > &iBrother)
edge_pointers_container::const_iterator edge_pointers_container_iterator
vector< ViewVertex::directedViewEdge > edges_container
vector< ViewVertex::directedViewEdge * > edge_pointers_container
edge_iterator_base< edge_const_traits > const_iterator
IteratorBase< Traits, InputIteratorTag_Traits > parent_class
edge_iterator_base(edge_pointers_container_iterator begin, edge_pointers_container_iterator end, edge_pointers_container_iterator iter)
edge_iterator_base(edges_container_iterator begin, edges_container_iterator end, edges_container_iterator iter)
edge_iterator_base(const edge_iterator_base< edge_nonconst_traits > &iBrother)
edge_iterator_base(const edge_iterator_base< edge_const_traits > &iBrother)
edge_iterator_base< edge_nonconst_traits > iterator
Traits::edge_pointers_container_iterator edge_pointers_container_iterator
vector< ViewVertex::directedViewEdge > edges_container
edge_pointers_container::iterator edge_pointers_container_iterator
vector< ViewVertex::directedViewEdge * > edge_pointers_container
local_group_size(16, 16) .push_constant(Type b
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