2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* ***** END GPL LICENSE BLOCK *****
21
#ifndef __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__
22
#define __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__
24
/** \file blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h
26
* \brief Iterators used to iterate over the various elements of the ViewMap.
27
* These iterators can't be exported to python.
28
* \author Stephane Grabli
34
#include "../system/Iterator.h" //soc
38
/**********************************/
44
/**********************************/
46
/**********************************/
52
/**********************************/
54
namespace ViewVertexInternal {
56
class edge_const_traits : public Const_traits< ::ViewVertex::directedViewEdge>
59
typedef vector< ::ViewVertex::directedViewEdge> edges_container;
60
typedef edges_container::const_iterator edges_container_iterator;
61
typedef vector< ::ViewVertex::directedViewEdge*> edge_pointers_container;
62
typedef edge_pointers_container::const_iterator edge_pointers_container_iterator;
65
class edge_nonconst_traits : public Nonconst_traits< ::ViewVertex::directedViewEdge>
68
typedef vector< ::ViewVertex::directedViewEdge> edges_container;
69
typedef edges_container::iterator edges_container_iterator;
70
typedef vector< ::ViewVertex::directedViewEdge*> edge_pointers_container;
71
typedef edge_pointers_container::iterator edge_pointers_container_iterator;
74
template<class Traits>
75
class edge_iterator_base : public IteratorBase<Traits, InputIteratorTag_Traits>
78
typedef typename Traits::value_type value_type;
79
typedef typename Traits::difference_type difference_type;
80
typedef typename Traits::pointer pointer;
81
typedef typename Traits::reference reference;
82
typedef edge_iterator_base<Traits> Self;
83
typedef typename Traits::edges_container_iterator edges_container_iterator;
84
typedef typename Traits::edge_pointers_container_iterator edge_pointers_container_iterator;
85
typedef edge_iterator_base<edge_nonconst_traits> iterator;
86
typedef edge_iterator_base<edge_const_traits> const_iterator;
89
friend class ViewVertex;
91
friend class NonTVertex;
92
friend class ViewEdge;
93
friend class edge_iterator;
96
Nature::VertexNature _Nature; // the nature of the underlying vertex
97
// T vertex attributes
98
edge_pointers_container_iterator _tbegin;
99
edge_pointers_container_iterator _tend;
100
edge_pointers_container_iterator _tvertex_iter;
103
mutable value_type _tvertex_iter;
110
// Non TVertex attributes
111
edges_container_iterator _begin;
112
edges_container_iterator _end;
113
edges_container_iterator _nontvertex_iter;
115
typedef IteratorBase<Traits, InputIteratorTag_Traits> parent_class;
118
inline edge_iterator_base() : parent_class() {}
120
inline edge_iterator_base(Nature::VertexNature iNature) : parent_class()
125
edge_iterator_base(const edge_iterator_base<edge_nonconst_traits>& iBrother) : parent_class(iBrother)
127
_Nature = iBrother._Nature;
128
if (_Nature & Nature::T_VERTEX) {
130
_feA = iBrother._feA;
131
_feB = iBrother._feB;
132
_beA = iBrother._beA;
133
_beB = iBrother._beB;
134
_tvertex_iter = iBrother._tvertex_iter;
136
_tbegin = iBrother._tbegin;
137
_tend = iBrother._tend;
138
_tvertex_iter = iBrother._tvertex_iter;
141
_begin = iBrother._begin;
142
_end = iBrother._end;
143
_nontvertex_iter = iBrother._nontvertex_iter;
147
edge_iterator_base(const edge_iterator_base<edge_const_traits>& iBrother) : parent_class(iBrother)
149
_Nature = iBrother._Nature;
150
if (_Nature & Nature::T_VERTEX) {
152
_feA = iBrother._feA;
153
_feB = iBrother._feB;
154
_beA = iBrother._beA;
155
_beB = iBrother._beB;
156
_tvertex_iter = iBrother._tvertex_iter;
158
_tbegin = iBrother._tbegin;
159
_tend = iBrother._tend;
160
_tvertex_iter = iBrother._tvertex_iter;
163
_begin = iBrother._begin;
164
_end = iBrother._end;
165
_nontvertex_iter = iBrother._nontvertex_iter;
169
virtual ~edge_iterator_base() {}
174
inline edge_iterator_base(value_type ifeA, value_type ifeB, value_type ibeA, value_type ibeB, value_type iter)
177
_Nature = Nature::T_VERTEX;
182
_tvertex_iter = iter;
186
inline edge_iterator_base(edge_pointers_container_iterator begin, edge_pointers_container_iterator end,
187
edge_pointers_container_iterator iter)
190
_Nature = Nature::T_VERTEX;
193
_tvertex_iter = iter;
196
inline edge_iterator_base(edges_container_iterator begin, edges_container_iterator end,
197
edges_container_iterator iter)
200
_Nature = Nature::NON_T_VERTEX;
203
_nontvertex_iter = iter;
207
virtual bool begin() const
209
if (_Nature & Nature::T_VERTEX)
210
return (_tvertex_iter == _tbegin);
211
//return (_tvertex_iter == _feA);
213
return (_nontvertex_iter == _begin);
216
virtual bool end() const
218
if (_Nature & Nature::T_VERTEX)
219
//return (_tvertex_iter.first == 0);
220
return (_tvertex_iter == _tend);
222
return (_nontvertex_iter == _end);
226
// operator corresponding to ++i
227
virtual Self& operator++()
233
// operator corresponding to i++, i.e. which returns the value *and then* increments it.
234
// That's why we store the value in a temp.
235
virtual Self operator++(int) // opérateur correspondant à i++
243
virtual bool operator!=(const Self& b) const
245
if (_Nature & Nature::T_VERTEX)
246
return (_tvertex_iter != b._tvertex_iter);
248
return (_nontvertex_iter != b._nontvertex_iter);
251
virtual bool operator==(const Self& b) const
253
return !(*this != b);
257
virtual reference operator*() const
259
if (_Nature & Nature::T_VERTEX)
260
//return _tvertex_iter;
261
return **_tvertex_iter;
263
return (*_nontvertex_iter);
266
virtual pointer operator->() const
268
return &(operator*());
272
inline void increment()
274
if (_Nature & Nature::T_VERTEX) {
275
value_type tmp = (**_tvertex_iter);
277
value_type tmp2 = (**_tvertex_iter);
278
if (tmp2.first == tmp.first)
281
// Hack to deal with cusp. the result of a cusp is a TVertex having two identical viewedges.
282
// In order to iterate properly, we chose to to skip these last ones.
283
if (_feB.first == _beA.first) {
284
if (_feA.first == _beB.first) {
285
_tvertex_iter.first = 0;
289
if (_tvertex_iter.first == _feA.first)
290
_tvertex_iter.first = _beB.first;
291
else if (_tvertex_iter.first == _beB.first)
292
_tvertex_iter.first = 0;
294
_tvertex_iter.first = _feA.first;
297
if (_feA.first == _beB.first) {
298
if (_feB.first == _beA.first) {
299
_tvertex_iter.first = 0;
303
if (_tvertex_iter.first == _feB.first)
304
_tvertex_iter.first = _beA.first;
305
else if (_tvertex_iter.first == _beA.first)
306
_tvertex_iter.first = 0;
308
_tvertex_iter.first = _feB.first;
313
if (_tvertex_iter.first == _feA.first) {
314
// we return bea or beb
315
// choose one of them
316
_tvertex_iter.first = _feB.first;
319
if (_tvertex_iter.first == _feB.first) {
320
_tvertex_iter.first = _beA.first;
323
if (_tvertex_iter.first == _beA.first) {
324
_tvertex_iter.first = _beB.first;
327
if (_tvertex_iter.first == _beB.first) {
328
_tvertex_iter.first = 0;
339
} // ViewVertexInternal namespace
341
/**********************************/
347
/**********************************/
349
namespace ViewEdgeInternal {
351
/*!----------------------*/
352
/*! Iterators definition */
353
/*!----------------------*/
354
template<class Traits>
355
class edge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits>
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;
362
typedef edge_iterator_base<Traits> Self;
365
mutable value_type _ViewEdge;
366
//friend class edge_iterator_base<Nonconst_traits<ViewEdge*> >;
367
//friend class edge_iterator_base<Const_traits<ViewEdge*> >;
370
typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;
373
friend class ViewEdge;
374
inline edge_iterator_base() : parent_class()
380
inline edge_iterator_base(const edge_iterator_base<Nonconst_traits< ::ViewEdge*> >& iBrother) : parent_class()
382
_ViewEdge = iBrother._ViewEdge;
383
_first = iBrother._first;
384
_orientation = iBrother._orientation;
387
inline edge_iterator_base(const edge_iterator_base<Const_traits< ::ViewEdge*> >& iBrother) : parent_class()
389
_ViewEdge = iBrother._ViewEdge;
390
_first = iBrother._first;
391
_orientation = iBrother._orientation;
396
inline edge_iterator_base(value_type iEdge, bool orientation = true) : parent_class()
400
_orientation = orientation;
404
virtual Self *clone() const
406
return new edge_iterator_base(*this);
409
virtual ~edge_iterator_base() {}
412
virtual bool orientation()
417
virtual void set_edge(value_type iVE)
422
virtual void set_orientation(bool iOrientation)
424
_orientation = iOrientation;
427
virtual void change_orientation()
429
_orientation = !_orientation;
433
// operator corresponding to ++i
434
inline Self& operator++()
436
//++_ViewEdge->getTimeStamp();
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)
445
//++_ViewEdge->getTimeStamp();
451
// operator corresponding to --i
452
inline Self& operator--()
454
//++_ViewEdge->getTimeStamp();
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)
463
//++_ViewEdge->getTimeStamp();
470
virtual bool operator!=(const Self& b) const
472
return (_ViewEdge != b._ViewEdge);
475
virtual bool operator==(const Self& b) const
477
return !(*this != b);
481
virtual reference operator*() const
486
virtual pointer operator->() const
488
return &(operator*());
492
virtual bool begin() const
494
return (_ViewEdge == _first) ? true : false;
497
virtual bool end() const
499
return (_ViewEdge == 0) ? true : false;
503
virtual void increment() {}
504
virtual void decrement() {}
507
template<class Traits>
508
class fedge_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits>
511
typedef typename Traits::value_type value_type;
512
typedef typename Traits::difference_type difference_type;
513
typedef typename Traits::pointer pointer;
514
typedef typename Traits::reference reference;
515
typedef fedge_iterator_base<Traits> Self;
518
typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;
519
mutable value_type _FEdge;
521
value_type _FEdgeB; // last fedge of the view edge
524
friend class ::ViewEdge;
525
friend class fedge_iterator;
527
inline fedge_iterator_base() : parent_class() {}
529
inline fedge_iterator_base(const fedge_iterator_base<Nonconst_traits<FEdge*> >& iBrother) : parent_class()
531
_FEdge = iBrother._FEdge;
532
_first = iBrother._first;
533
_FEdgeB = iBrother._FEdgeB;
536
inline fedge_iterator_base(const fedge_iterator_base<Const_traits<FEdge*> >& iBrother) : parent_class()
538
_FEdge = iBrother._FEdge;
539
_first = iBrother._first;
540
_FEdgeB = iBrother._FEdgeB;
545
inline fedge_iterator_base(value_type iEdge, value_type iFEdgeB) : parent_class()
553
virtual ~fedge_iterator_base() {}
556
// operator corresponding to ++i.
557
inline Self& operator++()
563
// operator corresponding to i++, i.e. which returns the value *and then* increments it.
564
// That's why we store the value in a temp.
565
inline Self operator++(int)
572
// operator corresponding to --i
573
inline Self& operator--()
579
// operator corresponding to i--, i.e. which returns the value *and then* increments it.
580
// That's why we store the value in a temp.
581
inline Self operator--(int)
589
virtual bool operator!=(const Self& b) const
591
return (_FEdge != b._FEdge);
594
virtual bool operator==(const Self& b) const
596
return !(*this != b);
600
virtual reference operator*() const
605
virtual pointer operator->() const
607
return &(operator*());
611
virtual bool begin() const
613
return (_FEdge == _first) ? true : false;
616
virtual bool end() const
618
return (_FEdge == 0) ? true : false;
622
virtual void increment()
624
_FEdge = _FEdge->nextEdge(); // we don't change or
627
virtual void decrement()
633
_FEdge = _FEdge->previousEdge(); // we don't change or
637
template<class Traits>
638
class vertex_iterator_base : public IteratorBase<Traits, BidirectionalIteratorTag_Traits>
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;
645
typedef vertex_iterator_base<Traits> Self;
648
typedef IteratorBase<Traits, BidirectionalIteratorTag_Traits> parent_class;
651
mutable value_type _SVertex;
653
FEdge *_PreviousFEdge;
656
friend class ViewEdge;
657
friend class vertex_iterator;
659
inline vertex_iterator_base() : parent_class() {}
661
inline vertex_iterator_base(const vertex_iterator_base<Const_traits<SVertex*> >& iBrother) : parent_class()
663
_SVertex = iBrother._SVertex;
664
_NextFEdge = iBrother._NextFEdge;
665
_PreviousFEdge = iBrother._PreviousFEdge;
668
inline vertex_iterator_base(const vertex_iterator_base<Nonconst_traits<SVertex*> >& iBrother) : parent_class()
670
_SVertex = iBrother._SVertex;
671
_NextFEdge = iBrother._NextFEdge;
672
_PreviousFEdge = iBrother._PreviousFEdge;
677
inline vertex_iterator_base(value_type iVertex, FEdge *iPreviousFEdge, FEdge *iNextFEdge) : parent_class()
680
_NextFEdge = iNextFEdge;
681
_PreviousFEdge = iPreviousFEdge;
685
virtual ~vertex_iterator_base() {}
687
virtual bool begin() const
689
return (_PreviousFEdge == 0) ? true : false;
692
virtual bool end() const
694
return (_SVertex == 0) ? true : false;
698
// operator corresponding to ++i
699
inline Self& operator++()
705
// operator corresponding to i++, i.e. which returns the value *and then* increments it.
706
// That's why we store the value in a temp.
707
inline Self operator++(int)
714
// operator corresponding to --i
715
inline Self& operator--()
721
// operator corresponding to --i, i.e. which returns the value *and then* increments it.
722
// That's why we store the value in a temp.
723
inline Self operator--(int)
731
virtual bool operator!=(const Self& b) const
733
return (_SVertex != b._SVertex);
736
virtual bool operator==(const Self& b) const
738
return !(*this != b);
742
virtual reference operator*() const
747
virtual pointer operator->() const
749
return &(operator*());
753
virtual void increment()
759
_SVertex = _NextFEdge->vertexB();
760
_PreviousFEdge = _NextFEdge;
761
_NextFEdge = _NextFEdge->nextEdge();
764
virtual void decrement()
768
_SVertex = _PreviousFEdge->vertexB();
772
if (!_PreviousFEdge) {
776
_SVertex = _PreviousFEdge->vertexA();
777
_NextFEdge = _PreviousFEdge;
778
_PreviousFEdge = _PreviousFEdge->previousEdge();
782
} // end of namespace ViewEdgeInternal
784
} /* namespace Freestyle */
786
#endif // __FREESTYLE_VIEW_MAP_ADVANCED_ITERATORS_H__