Blender  V2.93
ViewMapAdvancedIterators.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
25 #include "ViewMap.h"
26 #include "ViewMapIterators.h"
27 
28 #include "../system/Iterator.h" //soc
29 
30 namespace Freestyle {
31 
32 /**********************************/
33 /* */
34 /* */
35 /* ViewMap */
36 /* */
37 /* */
38 /**********************************/
39 
40 /**********************************/
41 /* */
42 /* */
43 /* ViewVertex */
44 /* */
45 /* */
46 /**********************************/
47 
48 namespace ViewVertexInternal {
49 
50 class edge_const_traits : public Const_traits<ViewVertex::directedViewEdge> {
51  public:
52  typedef vector<ViewVertex::directedViewEdge> edges_container;
53  typedef edges_container::const_iterator edges_container_iterator;
54  typedef vector<ViewVertex::directedViewEdge *> edge_pointers_container;
55  typedef edge_pointers_container::const_iterator edge_pointers_container_iterator;
56 };
57 
58 class edge_nonconst_traits : public Nonconst_traits<ViewVertex::directedViewEdge> {
59  public:
60  typedef vector<ViewVertex::directedViewEdge> edges_container;
61  typedef edges_container::iterator edges_container_iterator;
62  typedef vector<ViewVertex::directedViewEdge *> edge_pointers_container;
63  typedef edge_pointers_container::iterator edge_pointers_container_iterator;
64 };
65 
66 template<class Traits>
67 class edge_iterator_base : public IteratorBase<Traits, InputIteratorTag_Traits> {
68  public:
69  typedef typename Traits::value_type value_type;
70  typedef typename Traits::difference_type difference_type;
71  typedef typename Traits::pointer pointer;
72  typedef typename Traits::reference reference;
74  typedef typename Traits::edges_container_iterator edges_container_iterator;
75  typedef typename Traits::edge_pointers_container_iterator edge_pointers_container_iterator;
78 
79  public:
80  friend class ViewVertex;
81  friend class TVertex;
82  friend class NonTVertex;
83  friend class ViewEdge;
84  friend class edge_iterator;
85 
86  protected:
87  Nature::VertexNature _Nature; // the nature of the underlying vertex
88  // T vertex attributes
92 
93 #if 0
94  mutable value_type _tvertex_iter;
95  value_type _feA;
96  value_type _feB;
97  value_type _beA;
98  value_type _beB;
99 #endif
100 
101  // Non TVertex attributes
105 
107 
108  public:
110  {
111  }
112 
114  {
115  _Nature = iNature;
116  }
117 
119  : parent_class(iBrother)
120  {
121  _Nature = iBrother._Nature;
122  if (_Nature & Nature::T_VERTEX) {
123 #if 0
124  _feA = iBrother._feA;
125  _feB = iBrother._feB;
126  _beA = iBrother._beA;
127  _beB = iBrother._beB;
128  _tvertex_iter = iBrother._tvertex_iter;
129 #endif
130  _tbegin = iBrother._tbegin;
131  _tend = iBrother._tend;
132  _tvertex_iter = iBrother._tvertex_iter;
133  }
134  else {
135  _begin = iBrother._begin;
136  _end = iBrother._end;
138  }
139  }
140 
142  : parent_class(iBrother)
143  {
144  _Nature = iBrother._Nature;
145  if (_Nature & Nature::T_VERTEX) {
146 #if 0
147  _feA = iBrother._feA;
148  _feB = iBrother._feB;
149  _beA = iBrother._beA;
150  _beB = iBrother._beB;
151  _tvertex_iter = iBrother._tvertex_iter;
152 #endif
153  _tbegin = iBrother._tbegin;
154  _tend = iBrother._tend;
155  _tvertex_iter = iBrother._tvertex_iter;
156  }
157  else {
158  _begin = iBrother._begin;
159  _end = iBrother._end;
161  }
162  }
163 
165  {
166  }
167 
168  // protected://FIXME
169  public:
170 #if 0
171  inline edge_iterator_base(
172  value_type ifeA, value_type ifeB, value_type ibeA, value_type ibeB, value_type iter)
173  : parent_class()
174  {
176  _feA = ifeA;
177  _feB = ifeB;
178  _beA = ibeA;
179  _beB = ibeB;
180  _tvertex_iter = iter;
181  }
182 #endif
183 
187  : parent_class()
188  {
190  _tbegin = begin;
191  _tend = end;
192  _tvertex_iter = iter;
193  }
194 
198  : parent_class()
199  {
201  _begin = begin;
202  _end = end;
203  _nontvertex_iter = iter;
204  }
205 
206  public:
207  virtual bool begin() const
208  {
209  if (_Nature & Nature::T_VERTEX) {
210  return (_tvertex_iter == _tbegin);
211  // return (_tvertex_iter == _feA);
212  }
213  else {
214  return (_nontvertex_iter == _begin);
215  }
216  }
217 
218  virtual bool end() const
219  {
220  if (_Nature & Nature::T_VERTEX) {
221  // return (_tvertex_iter.first == 0);
222  return (_tvertex_iter == _tend);
223  }
224  else {
225  return (_nontvertex_iter == _end);
226  }
227  }
228 
229  // operators
230  // operator corresponding to ++i
231  virtual Self &operator++()
232  {
233  increment();
234  return *this;
235  }
236 
237  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
238  // That's why we store the value in a temp.
239  virtual Self operator++(int)
240  {
241  Self tmp = *this;
242  increment();
243  return tmp;
244  }
245 
246  // comparibility
247  virtual bool operator!=(const Self &b) const
248  {
249  if (_Nature & Nature::T_VERTEX) {
250  return (_tvertex_iter != b._tvertex_iter);
251  }
252  else {
253  return (_nontvertex_iter != b._nontvertex_iter);
254  }
255  }
256 
257  virtual bool operator==(const Self &b) const
258  {
259  return !(*this != b);
260  }
261 
262  // dereferencing
263  virtual reference operator*() const
264  {
265  if (_Nature & Nature::T_VERTEX) {
266  // return _tvertex_iter;
267  return **_tvertex_iter;
268  }
269  else {
270  return (*_nontvertex_iter);
271  }
272  }
273 
274  virtual pointer operator->() const
275  {
276  return &(operator*());
277  }
278 
279  protected:
280  inline void increment()
281  {
282  if (_Nature & Nature::T_VERTEX) {
283  value_type tmp = (**_tvertex_iter);
284  ++_tvertex_iter;
285  value_type tmp2 = (**_tvertex_iter);
286  if (tmp2.first == tmp.first) {
287  ++_tvertex_iter;
288  }
289 #if 0
290  // Hack to deal with cusp. the result of a cusp is a TVertex having two identical viewedges.
291  // In order to iterate properly, we chose to skip these last ones.
292  if (_feB.first == _beA.first) {
293  if (_feA.first == _beB.first) {
294  _tvertex_iter.first = 0;
295  return;
296  }
297 
298  if (_tvertex_iter.first == _feA.first) {
299  _tvertex_iter.first = _beB.first;
300  }
301  else if (_tvertex_iter.first == _beB.first) {
302  _tvertex_iter.first = 0;
303  }
304  else {
305  _tvertex_iter.first = _feA.first;
306  }
307  return;
308  }
309  if (_feA.first == _beB.first) {
310  if (_feB.first == _beA.first) {
311  _tvertex_iter.first = 0;
312  return;
313  }
314 
315  if (_tvertex_iter.first == _feB.first) {
316  _tvertex_iter.first = _beA.first;
317  }
318  else if (_tvertex_iter.first == _beA.first) {
319  _tvertex_iter.first = 0;
320  }
321  else {
322  _tvertex_iter.first = _feB.first;
323  }
324  return;
325  }
326  // End of hack
327 
328  if (_tvertex_iter.first == _feA.first) {
329  // we return bea or beb
330  // choose one of them
331  _tvertex_iter.first = _feB.first;
332  return;
333  }
334  if (_tvertex_iter.first == _feB.first) {
335  _tvertex_iter.first = _beA.first;
336  return;
337  }
338  if (_tvertex_iter.first == _beA.first) {
339  _tvertex_iter.first = _beB.first;
340  return;
341  }
342  if (_tvertex_iter.first == _beB.first) {
343  _tvertex_iter.first = 0;
344  return;
345  }
346 #endif
347  }
348  else {
350  }
351  }
352 };
353 
354 } // namespace ViewVertexInternal
355 
356 /**********************************/
357 /* */
358 /* */
359 /* ViewEdge */
360 /* */
361 /* */
362 /**********************************/
363 
364 namespace ViewEdgeInternal {
365 
369 template<class Traits>
370 class edge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
371  public:
372  typedef typename Traits::value_type value_type;
373  typedef typename Traits::difference_type difference_type;
374  typedef typename Traits::pointer pointer;
375  typedef typename Traits::reference reference;
377 
378  public:
380  // friend class edge_iterator_base<Nonconst_traits<ViewEdge*> >;
381  // friend class edge_iterator_base<Const_traits<ViewEdge*> >;
385 
386  public:
387  friend class ViewEdge;
389  {
390  _orientation = true;
391  _first = 0;
392  }
393 
395  : parent_class()
396  {
397  _ViewEdge = iBrother._ViewEdge;
398  _first = iBrother._first;
399  _orientation = iBrother._orientation;
400  }
401 
403  : parent_class()
404  {
405  _ViewEdge = iBrother._ViewEdge;
406  _first = iBrother._first;
407  _orientation = iBrother._orientation;
408  }
409 
410  // protected://FIXME
411  public:
412  inline edge_iterator_base(value_type iEdge, bool orientation = true) : parent_class()
413  {
414  _ViewEdge = iEdge;
415  _first = iEdge;
417  }
418 
419  public:
420  virtual Self *clone() const
421  {
422  return new edge_iterator_base(*this);
423  }
424 
426  {
427  }
428 
429  public:
430  virtual bool orientation()
431  {
432  return _orientation;
433  }
434 
435  virtual void set_edge(value_type iVE)
436  {
437  _ViewEdge = iVE;
438  }
439 
440  virtual void set_orientation(bool iOrientation)
441  {
442  _orientation = iOrientation;
443  }
444 
445  virtual void change_orientation()
446  {
448  }
449 
450  // operators
451  // operator corresponding to ++i
452  inline Self &operator++()
453  {
454  //++_ViewEdge->getTimeStamp();
455  increment();
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  increment();
466  return tmp;
467  }
468 
469  // operator corresponding to --i
470  inline Self &operator--()
471  {
472  //++_ViewEdge->getTimeStamp();
473  decrement();
474  return *this;
475  }
476 
477  // operator corresponding to i--, i.e. which returns the value *and then* increments it.
478  // That's why we store the value in a temp.
479  inline Self operator--(int)
480  {
481  //++_ViewEdge->getTimeStamp();
482  Self tmp = *this;
483  decrement();
484  return tmp;
485  }
486 
487  // comparibility
488  virtual bool operator!=(const Self &b) const
489  {
490  return (_ViewEdge != b._ViewEdge);
491  }
492 
493  virtual bool operator==(const Self &b) const
494  {
495  return !(*this != b);
496  }
497 
498  // dereferencing
499  virtual reference operator*() const
500  {
501  return _ViewEdge;
502  }
503 
504  virtual pointer operator->() const
505  {
506  return &(operator*());
507  }
508 
509  public:
510  virtual bool begin() const
511  {
512  return (_ViewEdge == _first) ? true : false;
513  }
514 
515  virtual bool end() const
516  {
517  return (_ViewEdge == 0) ? true : false;
518  }
519 
520  protected:
521  virtual void increment()
522  {
523  }
524  virtual void decrement()
525  {
526  }
527 };
528 
529 template<class Traits>
530 class fedge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
531  public:
532  typedef typename Traits::value_type value_type;
533  typedef typename Traits::difference_type difference_type;
534  typedef typename Traits::pointer pointer;
535  typedef typename Traits::reference reference;
537 
538  public:
542  value_type _FEdgeB; // last fedge of the view edge
543 
544  public:
545  friend class ViewEdge;
546  friend class fedge_iterator;
547 
549  {
550  }
551 
553  : parent_class()
554  {
555  _FEdge = iBrother._FEdge;
556  _first = iBrother._first;
557  _FEdgeB = iBrother._FEdgeB;
558  }
559 
561  : parent_class()
562  {
563  _FEdge = iBrother._FEdge;
564  _first = iBrother._first;
565  _FEdgeB = iBrother._FEdgeB;
566  }
567 
568  // protected://FIXME
569  public:
571  {
572  _FEdge = iEdge;
573  _first = iEdge;
574  _FEdgeB = iFEdgeB;
575  }
576 
577  public:
579  {
580  }
581 
582  // operators
583  // operator corresponding to ++i.
584  inline Self &operator++()
585  {
586  increment();
587  return *this;
588  }
589 
590  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
591  // That's why we store the value in a temp.
592  inline Self operator++(int)
593  {
594  Self tmp = *this;
595  increment();
596  return tmp;
597  }
598 
599  // operator corresponding to --i
600  inline Self &operator--()
601  {
602  decrement();
603  return *this;
604  }
605 
606  // operator corresponding to i--, i.e. which returns the value *and then* increments it.
607  // That's why we store the value in a temp.
608  inline Self operator--(int)
609  {
610  Self tmp = *this;
611  decrement();
612  return tmp;
613  }
614 
615  // comparibility
616  virtual bool operator!=(const Self &b) const
617  {
618  return (_FEdge != b._FEdge);
619  }
620 
621  virtual bool operator==(const Self &b) const
622  {
623  return !(*this != b);
624  }
625 
626  // dereferencing
627  virtual reference operator*() const
628  {
629  return _FEdge;
630  }
631 
632  virtual pointer operator->() const
633  {
634  return &(operator*());
635  }
636 
637  public:
638  virtual bool begin() const
639  {
640  return (_FEdge == _first) ? true : false;
641  }
642 
643  virtual bool end() const
644  {
645  return (_FEdge == 0) ? true : false;
646  }
647 
648  protected:
649  virtual void increment()
650  {
651  _FEdge = _FEdge->nextEdge(); // we don't change or
652  }
653 
654  virtual void decrement()
655  {
656  if (0 == _FEdge) {
657  _FEdge = _FEdgeB;
658  return;
659  }
660  _FEdge = _FEdge->previousEdge(); // we don't change or
661  }
662 };
663 
664 template<class Traits>
665 class vertex_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
666  public:
667  typedef typename Traits::value_type value_type;
668  typedef typename Traits::difference_type difference_type;
669  typedef typename Traits::pointer pointer;
670  typedef typename Traits::reference reference;
672 
673  protected:
675 
676  public:
680 
681  public:
682  friend class ViewEdge;
683  friend class vertex_iterator;
684 
686  {
687  }
688 
690  : parent_class()
691  {
692  _SVertex = iBrother._SVertex;
693  _NextFEdge = iBrother._NextFEdge;
694  _PreviousFEdge = iBrother._PreviousFEdge;
695  }
696 
698  : parent_class()
699  {
700  _SVertex = iBrother._SVertex;
701  _NextFEdge = iBrother._NextFEdge;
702  _PreviousFEdge = iBrother._PreviousFEdge;
703  }
704 
705  // protected://FIXME
706  public:
707  inline vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge)
708  : parent_class()
709  {
710  _SVertex = iVertex;
711  _NextFEdge = iNextFEdge;
712  _PreviousFEdge = iPreviousFEdge;
713  }
714 
715  public:
717  {
718  }
719 
720  virtual bool begin() const
721  {
722  return (_PreviousFEdge == 0) ? true : false;
723  }
724 
725  virtual bool end() const
726  {
727  return (_SVertex == 0) ? true : false;
728  }
729 
730  // operators
731  // operator corresponding to ++i
732  inline Self &operator++()
733  {
734  increment();
735  return *this;
736  }
737 
738  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
739  // That's why we store the value in a temp.
740  inline Self operator++(int)
741  {
742  Self tmp = *this;
743  increment();
744  return tmp;
745  }
746 
747  // operator corresponding to --i
748  inline Self &operator--()
749  {
750  decrement();
751  return *this;
752  }
753 
754  // operator corresponding to --i, i.e. which returns the value *and then* increments it.
755  // That's why we store the value in a temp.
756  inline Self operator--(int)
757  {
758  Self tmp = *this;
759  decrement();
760  return tmp;
761  }
762 
763  // comparibility
764  virtual bool operator!=(const Self &b) const
765  {
766  return (_SVertex != b._SVertex);
767  }
768 
769  virtual bool operator==(const Self &b) const
770  {
771  return !(*this != b);
772  }
773 
774  // dereferencing
775  virtual reference operator*() const
776  {
777  return _SVertex;
778  }
779 
780  virtual pointer operator->() const
781  {
782  return &(operator*());
783  }
784 
785  protected:
786  virtual void increment()
787  {
788  if (!_NextFEdge) {
789  _SVertex = NULL;
790  return;
791  }
795  }
796 
797  virtual void decrement()
798  {
799 #if 0
800  if (!_SVertex) {
802  return;
803  }
804 #endif
805  if (!_PreviousFEdge) {
806  _SVertex = NULL;
807  return;
808  }
812  }
813 };
814 
815 } // end of namespace ViewEdgeInternal
816 
817 } /* 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:611
FEdge * previousEdge()
Definition: Silhouette.h:645
SVertex * vertexB()
Definition: Silhouette.h:617
FEdge * nextEdge()
Definition: Silhouette.h:637
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:32
static const VertexNature T_VERTEX
Definition: Nature.h:42
static const VertexNature NON_T_VERTEX
Definition: Nature.h:40
inherits from class Rep
Definition: AppCanvas.cpp:32