Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ViewMapAdvancedIterators.h « view_map « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ff46e353f348a876bd62940b302b4233859e619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__
#define __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__

/** \file
 * \ingroup freestyle
 * \brief Iterators used to iterate over the various elements of the ViewMap.
 *         These iterators can't be exported to python.
 */

#include "ViewMap.h"
#include "ViewMapIterators.h"

#include "../system/Iterator.h"  //soc

namespace Freestyle {

/**********************************/
/*                                */
/*                                */
/*             ViewMap            */
/*                                */
/*                                */
/**********************************/

/**********************************/
/*                                */
/*                                */
/*             ViewVertex         */
/*                                */
/*                                */
/**********************************/

namespace ViewVertexInternal {

class edge_const_traits : public Const_traits<ViewVertex::directedViewEdge> {
 public:
  typedef vector<ViewVertex::directedViewEdge> edges_container;
  typedef edges_container::const_iterator edges_container_iterator;
  typedef vector<ViewVertex::directedViewEdge *> edge_pointers_container;
  typedef edge_pointers_container::const_iterator edge_pointers_container_iterator;
};

class edge_nonconst_traits : public Nonconst_traits<ViewVertex::directedViewEdge> {
 public:
  typedef vector<ViewVertex::directedViewEdge> edges_container;
  typedef edges_container::iterator edges_container_iterator;
  typedef vector<ViewVertex::directedViewEdge *> edge_pointers_container;
  typedef edge_pointers_container::iterator edge_pointers_container_iterator;
};

template<class Traits>
class edge_iterator_base : public IteratorBase<Traits, InputIteratorTag_Traits> {
 public:
  typedef typename Traits::value_type value_type;
  typedef typename Traits::difference_type difference_type;
  typedef typename Traits::pointer pointer;
  typedef typename Traits::reference reference;
  typedef edge_iterator_base<Traits> Self;
  typedef typename Traits::edges_container_iterator edges_container_iterator;
  typedef typename Traits::edge_pointers_container_iterator edge_pointers_container_iterator;
  typedef edge_iterator_base<edge_nonconst_traits> iterator;
  typedef edge_iterator_base<edge_const_traits> const_iterator;

 public:
  friend class ViewVertex;
  friend class TVertex;
  friend class NonTVertex;
  friend class ViewEdge;
  friend class edge_iterator;

 protected:
  Nature::VertexNature _Nature;  // the nature of the underlying vertex
  // T vertex attributes
  edge_pointers_container_iterator _tbegin;
  edge_pointers_container_iterator _tend;
  edge_pointers_container_iterator _tvertex_iter;

#if 0
  mutable value_type _tvertex_iter;
  value_type _feA;
  value_type _feB;
  value_type _beA;
  value_type _beB;
#endif

  // Non TVertex attributes
  edges_container_iterator _begin;
  edges_container_iterator _end;
  edges_container_iterator _nontvertex_iter;

  typedef IteratorBase<Traits, InputIteratorTag_Traits> parent_class;

 public:
  inline edge_iterator_base() : parent_class()
  {
  }

  inline edge_iterator_base(Nature::VertexNature iNature) : parent_class()
  {
    _Nature = iNature;
  }

  edge_iterator_base(const edge_iterator_base<edge_nonconst_traits> &iBrother)
      : parent_class(iBrother)
  {
    _Nature = iBrother._Nature;
    if (_Nature & Nature::T_VERTEX) {
#if 0
      _feA = iBrother._feA;
      _feB = iBrother._feB;
      _beA = iBrother._beA;
      _beB = iBrother._beB;
      _tvertex_iter = iBrother._tvertex_iter;
#endif
      _tbegin = iBrother._tbegin;
      _tend = iBrother._tend;
      _tvertex_iter = iBrother._tvertex_iter;
    }
    else {
      _begin = iBrother._begin;
      _end = iBrother._end;
      _nontvertex_iter = iBrother._nontvertex_iter;
    }
  }

  edge_iterator_base(const edge_iterator_base<edge_const_traits> &iBrother)
      : parent_class(iBrother)
  {
    _Nature = iBrother._Nature;
    if (_Nature & Nature::T_VERTEX) {
#if 0
      _feA = iBrother._feA;
      _feB = iBrother._feB;
      _beA = iBrother._beA;
      _beB = iBrother._beB;
      _tvertex_iter = iBrother._tvertex_iter;
#endif
      _tbegin = iBrother._tbegin;
      _tend = iBrother._tend;
      _tvertex_iter = iBrother._tvertex_iter;
    }
    else {
      _begin = iBrother._begin;
      _end = iBrother._end;
      _nontvertex_iter = iBrother._nontvertex_iter;
    }
  }

  virtual ~edge_iterator_base()
  {
  }

  // protected://FIXME
 public:
#if 0
  inline edge_iterator_base(
      value_type ifeA, value_type ifeB, value_type ibeA, value_type ibeB, value_type iter)
      : parent_class()
  {
    _Nature = Nature::T_VERTEX;
    _feA = ifeA;
    _feB = ifeB;
    _beA = ibeA;
    _beB = ibeB;
    _tvertex_iter = iter;
  }
#endif

  inline edge_iterator_base(edge_pointers_container_iterator begin,
                            edge_pointers_container_iterator end,
                            edge_pointers_container_iterator iter)
      : parent_class()
  {
    _Nature = Nature::T_VERTEX;
    _tbegin = begin;
    _tend = end;
    _tvertex_iter = iter;
  }

  inline edge_iterator_base(edges_container_iterator begin,
                            edges_container_iterator end,
                            edges_container_iterator iter)
      : parent_class()
  {
    _Nature = Nature::NON_T_VERTEX;
    _begin = begin;
    _end = end;
    _nontvertex_iter = iter;
  }

 public:
  virtual bool begin() const
  {
    if (_Nature & Nature::T_VERTEX) {
      return (_tvertex_iter == _tbegin);
      // return (_tvertex_iter == _feA);
    }
    else {
      return (_nontvertex_iter == _begin);
    }
  }

  virtual bool end() const
  {
    if (_Nature & Nature::T_VERTEX) {
      // return (_tvertex_iter.first == 0);
      return (_tvertex_iter == _tend);
    }
    else {
      return (_nontvertex_iter == _end);
    }
  }

  // operators
  // operator corresponding to ++i
  virtual Self &operator++()
  {
    increment();
    return *this;
  }

  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  virtual Self operator++(int)
  {
    Self tmp = *this;
    increment();
    return tmp;
  }

  // comparibility
  virtual bool operator!=(const Self &b) const
  {
    if (_Nature & Nature::T_VERTEX) {
      return (_tvertex_iter != b._tvertex_iter);
    }
    else {
      return (_nontvertex_iter != b._nontvertex_iter);
    }
  }

  virtual bool operator==(const Self &b) const
  {
    return !(*this != b);
  }

  // dereferencing
  virtual reference operator*() const
  {
    if (_Nature & Nature::T_VERTEX) {
      // return _tvertex_iter;
      return **_tvertex_iter;
    }
    else {
      return (*_nontvertex_iter);
    }
  }

  virtual pointer operator->() const
  {
    return &(operator*());
  }

 protected:
  inline void increment()
  {
    if (_Nature & Nature::T_VERTEX) {
      value_type tmp = (**_tvertex_iter);
      ++_tvertex_iter;
      value_type tmp2 = (**_tvertex_iter);
      if (tmp2.first == tmp.first) {
        ++_tvertex_iter;
      }
#if 0
      // Hack to deal with cusp. the result of a cusp is a TVertex having two identical viewedges.
      // In order to iterate properly, we chose to skip these last ones.
      if (_feB.first == _beA.first) {
        if (_feA.first == _beB.first) {
          _tvertex_iter.first = 0;
          return;
        }

        if (_tvertex_iter.first == _feA.first) {
          _tvertex_iter.first = _beB.first;
        }
        else if (_tvertex_iter.first == _beB.first) {
          _tvertex_iter.first = 0;
        }
        else {
          _tvertex_iter.first = _feA.first;
        }
        return;
      }
      if (_feA.first == _beB.first) {
        if (_feB.first == _beA.first) {
          _tvertex_iter.first = 0;
          return;
        }

        if (_tvertex_iter.first == _feB.first) {
          _tvertex_iter.first = _beA.first;
        }
        else if (_tvertex_iter.first == _beA.first) {
          _tvertex_iter.first = 0;
        }
        else {
          _tvertex_iter.first = _feB.first;
        }
        return;
      }
      // End of hack

      if (_tvertex_iter.first == _feA.first) {
        // we return bea or beb
        // choose one of them
        _tvertex_iter.first = _feB.first;
        return;
      }
      if (_tvertex_iter.first == _feB.first) {
        _tvertex_iter.first = _beA.first;
        return;
      }
      if (_tvertex_iter.first == _beA.first) {
        _tvertex_iter.first = _beB.first;
        return;
      }
      if (_tvertex_iter.first == _beB.first) {
        _tvertex_iter.first = 0;
        return;
      }
#endif
    }
    else {
      ++_nontvertex_iter;
    }
  }
};

}  // namespace ViewVertexInternal

/**********************************/
/*                                */
/*                                */
/*             ViewEdge           */
/*                                */
/*                                */
/**********************************/

namespace ViewEdgeInternal {

/*!----------------------*/
/*! Iterators definition */
/*!----------------------*/
template<class Traits>
class edge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
 public:
  typedef typename Traits::value_type value_type;
  typedef typename Traits::difference_type difference_type;
  typedef typename Traits::pointer pointer;
  typedef typename Traits::reference reference;
  typedef edge_iterator_base<Traits> Self;

 public:
  mutable value_type _ViewEdge;
  // friend class edge_iterator_base<Nonconst_traits<ViewEdge*> >;
  // friend class edge_iterator_base<Const_traits<ViewEdge*> >;
  value_type _first;
  bool _orientation;
  typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;

 public:
  friend class ViewEdge;
  inline edge_iterator_base() : parent_class()
  {
    _orientation = true;
    _first = 0;
  }

  inline edge_iterator_base(const edge_iterator_base<Nonconst_traits<ViewEdge *>> &iBrother)
      : parent_class()
  {
    _ViewEdge = iBrother._ViewEdge;
    _first = iBrother._first;
    _orientation = iBrother._orientation;
  }

  inline edge_iterator_base(const edge_iterator_base<Const_traits<ViewEdge *>> &iBrother)
      : parent_class()
  {
    _ViewEdge = iBrother._ViewEdge;
    _first = iBrother._first;
    _orientation = iBrother._orientation;
  }

  // protected://FIXME
 public:
  inline edge_iterator_base(value_type iEdge, bool orientation = true) : parent_class()
  {
    _ViewEdge = iEdge;
    _first = iEdge;
    _orientation = orientation;
  }

 public:
  virtual Self *clone() const
  {
    return new edge_iterator_base(*this);
  }

  virtual ~edge_iterator_base()
  {
  }

 public:
  virtual bool orientation()
  {
    return _orientation;
  }

  virtual void set_edge(value_type iVE)
  {
    _ViewEdge = iVE;
  }

  virtual void set_orientation(bool iOrientation)
  {
    _orientation = iOrientation;
  }

  virtual void change_orientation()
  {
    _orientation = !_orientation;
  }

  // operators
  // operator corresponding to ++i
  inline Self &operator++()
  {
    //++_ViewEdge->getTimeStamp();
    increment();
    return *this;
  }

  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  inline Self operator++(int)
  {
    //++_ViewEdge->getTimeStamp();
    Self tmp = *this;
    increment();
    return tmp;
  }

  // operator corresponding to --i
  inline Self &operator--()
  {
    //++_ViewEdge->getTimeStamp();
    decrement();
    return *this;
  }

  // operator corresponding to i--, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  inline Self operator--(int)
  {
    //++_ViewEdge->getTimeStamp();
    Self tmp = *this;
    decrement();
    return tmp;
  }

  // comparibility
  virtual bool operator!=(const Self &b) const
  {
    return (_ViewEdge != b._ViewEdge);
  }

  virtual bool operator==(const Self &b) const
  {
    return !(*this != b);
  }

  // dereferencing
  virtual reference operator*() const
  {
    return (_ViewEdge);
  }

  virtual pointer operator->() const
  {
    return &(operator*());
  }

 public:
  virtual bool begin() const
  {
    return (_ViewEdge == _first) ? true : false;
  }

  virtual bool end() const
  {
    return (_ViewEdge == 0) ? true : false;
  }

 protected:
  virtual void increment()
  {
  }
  virtual void decrement()
  {
  }
};

template<class Traits>
class fedge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
 public:
  typedef typename Traits::value_type value_type;
  typedef typename Traits::difference_type difference_type;
  typedef typename Traits::pointer pointer;
  typedef typename Traits::reference reference;
  typedef fedge_iterator_base<Traits> Self;

 public:
  typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;
  mutable value_type _FEdge;
  value_type _first;
  value_type _FEdgeB;  // last fedge of the view edge

 public:
  friend class ViewEdge;
  friend class fedge_iterator;

  inline fedge_iterator_base() : parent_class()
  {
  }

  inline fedge_iterator_base(const fedge_iterator_base<Nonconst_traits<FEdge *>> &iBrother)
      : parent_class()
  {
    _FEdge = iBrother._FEdge;
    _first = iBrother._first;
    _FEdgeB = iBrother._FEdgeB;
  }

  inline fedge_iterator_base(const fedge_iterator_base<Const_traits<FEdge *>> &iBrother)
      : parent_class()
  {
    _FEdge = iBrother._FEdge;
    _first = iBrother._first;
    _FEdgeB = iBrother._FEdgeB;
  }

  // protected://FIXME
 public:
  inline fedge_iterator_base(value_type iEdge, value_type iFEdgeB) : parent_class()
  {
    _FEdge = iEdge;
    _first = iEdge;
    _FEdgeB = iFEdgeB;
  }

 public:
  virtual ~fedge_iterator_base()
  {
  }

  // operators
  // operator corresponding to ++i.
  inline Self &operator++()
  {
    increment();
    return *this;
  }

  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  inline Self operator++(int)
  {
    Self tmp = *this;
    increment();
    return tmp;
  }

  // operator corresponding to --i
  inline Self &operator--()
  {
    decrement();
    return *this;
  }

  // operator corresponding to i--, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  inline Self operator--(int)
  {
    Self tmp = *this;
    decrement();
    return tmp;
  }

  // comparibility
  virtual bool operator!=(const Self &b) const
  {
    return (_FEdge != b._FEdge);
  }

  virtual bool operator==(const Self &b) const
  {
    return !(*this != b);
  }

  // dereferencing
  virtual reference operator*() const
  {
    return (_FEdge);
  }

  virtual pointer operator->() const
  {
    return &(operator*());
  }

 public:
  virtual bool begin() const
  {
    return (_FEdge == _first) ? true : false;
  }

  virtual bool end() const
  {
    return (_FEdge == 0) ? true : false;
  }

 protected:
  virtual void increment()
  {
    _FEdge = _FEdge->nextEdge();  // we don't change or
  }

  virtual void decrement()
  {
    if (0 == _FEdge) {
      _FEdge = _FEdgeB;
      return;
    }
    _FEdge = _FEdge->previousEdge();  // we don't change or
  }
};

template<class Traits>
class vertex_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
 public:
  typedef typename Traits::value_type value_type;
  typedef typename Traits::difference_type difference_type;
  typedef typename Traits::pointer pointer;
  typedef typename Traits::reference reference;
  typedef vertex_iterator_base<Traits> Self;

 protected:
  typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;

 public:
  mutable value_type _SVertex;
  FEdge *_NextFEdge;
  FEdge *_PreviousFEdge;

 public:
  friend class ViewEdge;
  friend class vertex_iterator;

  inline vertex_iterator_base() : parent_class()
  {
  }

  inline vertex_iterator_base(const vertex_iterator_base<Const_traits<SVertex *>> &iBrother)
      : parent_class()
  {
    _SVertex = iBrother._SVertex;
    _NextFEdge = iBrother._NextFEdge;
    _PreviousFEdge = iBrother._PreviousFEdge;
  }

  inline vertex_iterator_base(const vertex_iterator_base<Nonconst_traits<SVertex *>> &iBrother)
      : parent_class()
  {
    _SVertex = iBrother._SVertex;
    _NextFEdge = iBrother._NextFEdge;
    _PreviousFEdge = iBrother._PreviousFEdge;
  }

  // protected://FIXME
 public:
  inline vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge)
      : parent_class()
  {
    _SVertex = iVertex;
    _NextFEdge = iNextFEdge;
    _PreviousFEdge = iPreviousFEdge;
  }

 public:
  virtual ~vertex_iterator_base()
  {
  }

  virtual bool begin() const
  {
    return (_PreviousFEdge == 0) ? true : false;
  }

  virtual bool end() const
  {
    return (_SVertex == 0) ? true : false;
  }

  // operators
  // operator corresponding to ++i
  inline Self &operator++()
  {
    increment();
    return *this;
  }

  // operator corresponding to i++, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  inline Self operator++(int)
  {
    Self tmp = *this;
    increment();
    return tmp;
  }

  // operator corresponding to --i
  inline Self &operator--()
  {
    decrement();
    return *this;
  }

  // operator corresponding to --i, i.e. which returns the value *and then* increments it.
  // That's why we store the value in a temp.
  inline Self operator--(int)
  {
    Self tmp = *this;
    decrement();
    return tmp;
  }

  // comparibility
  virtual bool operator!=(const Self &b) const
  {
    return (_SVertex != b._SVertex);
  }

  virtual bool operator==(const Self &b) const
  {
    return !(*this != b);
  }

  // dereferencing
  virtual reference operator*() const
  {
    return (_SVertex);
  }

  virtual pointer operator->() const
  {
    return &(operator*());
  }

 protected:
  virtual void increment()
  {
    if (!_NextFEdge) {
      _SVertex = NULL;
      return;
    }
    _SVertex = _NextFEdge->vertexB();
    _PreviousFEdge = _NextFEdge;
    _NextFEdge = _NextFEdge->nextEdge();
  }

  virtual void decrement()
  {
#if 0
    if (!_SVertex) {
      _SVertex = _PreviousFEdge->vertexB();
      return;
    }
#endif
    if (!_PreviousFEdge) {
      _SVertex = NULL;
      return;
    }
    _SVertex = _PreviousFEdge->vertexA();
    _NextFEdge = _PreviousFEdge;
    _PreviousFEdge = _PreviousFEdge->previousEdge();
  }
};

}  // end of namespace ViewEdgeInternal

} /* namespace Freestyle */

#endif  // __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__