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