Blender  V2.93
ViewMapIterators.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 
24 #include "ViewMap.h"
25 
26 #include "../system/Iterator.h" //soc
27 
28 namespace Freestyle {
29 
30 /**********************************/
31 /* */
32 /* */
33 /* ViewMap */
34 /* */
35 /* */
36 /**********************************/
37 
38 /**********************************/
39 /* */
40 /* */
41 /* ViewVertex */
42 /* */
43 /* */
44 /**********************************/
45 
46 namespace ViewVertexInternal {
47 
53  public:
54  friend class ViewVertex;
55  friend class TVertex;
56  friend class NonTVertex;
57  friend class ViewEdge;
58 
59  // FIXME
62 
63  protected:
64  Nature::VertexNature _Nature; // the nature of the underlying vertex
65  // T vertex attributes
66  edge_pointers_container::iterator _tbegin;
67  edge_pointers_container::iterator _tend;
68  edge_pointers_container::iterator _tvertex_iter;
69 
70  // Non TVertex attributes
71  edges_container::iterator _begin;
72  edges_container::iterator _end;
73  edges_container::iterator _nontvertex_iter;
74 
75  public:
78  {
79  }
80 
82  {
83  _Nature = iNature;
84  }
85 
88  {
89  _Nature = iBrother._Nature;
90  if (_Nature & Nature::T_VERTEX) {
91  _tbegin = iBrother._tbegin;
92  _tend = iBrother._tend;
93  _tvertex_iter = iBrother._tvertex_iter;
94  }
95  else {
96  _begin = iBrother._begin;
97  _end = iBrother._end;
99  }
100  }
101 
103  {
104  }
105 
106  public:
107  inline orientedViewEdgeIterator(edge_pointers_container::iterator begin,
108  edge_pointers_container::iterator end,
109  edge_pointers_container::iterator iter)
110  {
112  _tbegin = begin;
113  _tend = end;
114  _tvertex_iter = iter;
115  }
116 
117  inline orientedViewEdgeIterator(edges_container::iterator begin,
118  edges_container::iterator end,
119  edges_container::iterator iter)
120  {
122  _begin = begin;
123  _end = end;
124  _nontvertex_iter = iter;
125  }
126 
127  public:
130  virtual bool isBegin() const
131  {
132  if (_Nature & Nature::T_VERTEX) {
133  return (_tvertex_iter == _tbegin);
134  }
135  else {
136  return (_nontvertex_iter == _begin);
137  }
138  }
139 
142  virtual bool isEnd() const
143  {
144  if (_Nature & Nature::T_VERTEX) {
145  return (_tvertex_iter == _tend);
146  }
147  else {
148  return (_nontvertex_iter == _end);
149  }
150  }
151 
152  // operators
154  // operator corresponding to ++i
156  {
157  increment();
158  return *this;
159  }
160 
161  // operator corresponding to i++, i.e. which returns the value *and then* increments.
162  // That's why we store the value in a temp.
164  {
165  orientedViewEdgeIterator tmp = *this;
166  increment();
167  return tmp;
168  }
169 
170  // comparibility
172  virtual bool operator!=(const orientedViewEdgeIterator &b) const
173  {
174  if (_Nature & Nature::T_VERTEX) {
175  return (_tvertex_iter != b._tvertex_iter);
176  }
177  else {
178  return (_nontvertex_iter != b._nontvertex_iter);
179  }
180  }
181 
183  virtual bool operator==(const orientedViewEdgeIterator &b) const
184  {
185  return !(*this != b);
186  }
187 
188  // dereferencing
193  {
194  if (_Nature & Nature::T_VERTEX) {
195  // return _tvertex_iter;
196  return **_tvertex_iter;
197  }
198  else {
199  return (*_nontvertex_iter);
200  }
201  }
206  {
207  return &(operator*());
208  }
209 
210  public:
212  virtual inline int increment()
213  {
214  if (_Nature & Nature::T_VERTEX) {
215  ViewVertex::directedViewEdge tmp = (**_tvertex_iter);
216  ++_tvertex_iter;
217  if (_tvertex_iter != _tend) {
218  // FIXME : pquoi deja ?
219  ViewVertex::directedViewEdge tmp2 = (**_tvertex_iter);
220  if (tmp2.first == tmp.first) {
221  ++_tvertex_iter;
222  }
223  }
224  }
225  else {
227  }
228  return 0;
229  }
230 
231 #ifdef WITH_CXX_GUARDEDALLOC
232  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:orientedViewEdgeIterator")
233 #endif
234 };
235 
236 } // namespace ViewVertexInternal
237 
238 /**********************************/
239 /* */
240 /* */
241 /* ViewEdge */
242 /* */
243 /* */
244 /**********************************/
245 
246 namespace ViewEdgeInternal {
247 
248 //
249 // SVertexIterator
250 //
252 
254  public:
256  {
257  _vertex = NULL;
258  _begin = NULL;
259  _previous_edge = NULL;
260  _next_edge = NULL;
261  _t = 0;
262  }
263 
265  {
266  _vertex = vi._vertex;
267  _begin = vi._begin;
268  _previous_edge = vi._previous_edge;
269  _next_edge = vi._next_edge;
270  _t = vi._t;
271  }
272 
273  SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t)
274  {
275  _vertex = v;
276  _begin = begin;
277  _previous_edge = prev;
278  _next_edge = next;
279  _t = t;
280  }
281 
283  {
284  _vertex = vi._vertex;
285  _begin = vi._begin;
286  _previous_edge = vi._previous_edge;
287  _next_edge = vi._next_edge;
288  _t = vi._t;
289  return *this;
290  }
291 
293  {
294  }
295 
296  virtual string getExactTypeName() const
297  {
298  return "SVertexIterator";
299  }
300 
301  virtual SVertex &operator*()
302  {
303  return *_vertex;
304  }
305 
306  virtual SVertex *operator->()
307  {
308  return &(operator*());
309  }
310 
312  {
313  increment();
314  return *this;
315  }
316 
318  {
319  SVertexIterator ret(*this);
320  increment();
321  return ret;
322  }
323 
325  {
326  decrement();
327  return *this;
328  }
329 
331  {
332  SVertexIterator ret(*this);
333  decrement();
334  return ret;
335  }
336 
337  virtual int increment()
338  {
339  if (!_next_edge) {
340  _vertex = NULL;
341  return 0;
342  }
343  _t += (float)_next_edge->getLength2D();
344  _vertex = _next_edge->vertexB();
345  _previous_edge = _next_edge;
346  _next_edge = _next_edge->nextEdge();
347  return 0;
348  }
349 
350  virtual int decrement()
351  {
352  if (!_previous_edge) {
353  _vertex = NULL;
354  return 0;
355  }
356  if ((!_next_edge) && (!_vertex)) {
357  _vertex = _previous_edge->vertexB();
358  return 0;
359  }
360  _t -= (float)_previous_edge->getLength2D();
361  _vertex = _previous_edge->vertexA();
362  _next_edge = _previous_edge;
363  _previous_edge = _previous_edge->previousEdge();
364  return 0;
365  }
366 
367  virtual bool isBegin() const
368  {
369  return _vertex == _begin;
370  }
371 
372  virtual bool isEnd() const
373  {
374  return (!_vertex) || (_vertex == _begin && _previous_edge);
375  }
376 
377  virtual float t() const
378  {
379  return _t;
380  }
381 
382  virtual float u() const
383  {
384  return _t / (float)_next_edge->viewedge()->getLength2D();
385  }
386 
387  virtual bool operator==(const Interface0DIteratorNested &it) const
388  {
389  const SVertexIterator *it_exact = dynamic_cast<const SVertexIterator *>(&it);
390  if (!it_exact) {
391  return false;
392  }
393  return (_vertex == it_exact->_vertex);
394  }
395 
396  virtual SVertexIterator *copy() const
397  {
398  return new SVertexIterator(*this);
399  }
400 
401  private:
402  SVertex *_vertex;
403  SVertex *_begin;
404  FEdge *_previous_edge;
405  FEdge *_next_edge;
406  float _t; // curvilinear abscissa
407 
408 #ifdef WITH_CXX_GUARDEDALLOC
409  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SVertexIterator")
410 #endif
411 };
412 
413 //
414 // ViewEdgeIterator (base class)
415 //
417 
423 class ViewEdgeIterator : public Iterator {
424  public:
433  ViewEdgeIterator(ViewEdge *begin = NULL, bool orientation = true)
434  {
435  _orientation = orientation;
436  _edge = begin;
437  _begin = begin;
438  }
439 
442  {
444  _edge = it._edge;
445  _begin = it._begin;
446  }
447 
449  {
450  }
451 
453  virtual string getExactTypeName() const
454  {
455  return "ViewEdgeIterator";
456  }
457 
460  {
461  return _edge;
462  }
463 
466  {
467  _edge = edge;
468  }
469 
472  {
473  return _begin;
474  }
475 
477  void setBegin(ViewEdge *begin)
478  {
479  _begin = begin;
480  }
481 
483  bool getOrientation() const
484  {
485  return _orientation;
486  }
487 
489  void setOrientation(bool orientation)
490  {
491  _orientation = orientation;
492  }
493 
496  {
498  }
499 
501  virtual ViewEdge *operator*()
502  {
503  return _edge;
504  }
505 
506  virtual ViewEdge *operator->()
507  {
508  return operator*();
509  }
510 
513  {
514  increment();
515  return *this;
516  }
517 
520  {
521  ViewEdgeIterator tmp(*this);
522  increment();
523  return tmp;
524  }
525 
527  virtual int increment()
528  {
529  cerr << "Warning: method increment() not implemented" << endl;
530  return 0;
531  }
532 
535  {
536  decrement();
537  return *this;
538  }
539 
542  {
543  ViewEdgeIterator tmp(*this);
544  decrement();
545  return tmp;
546  }
547 
549  virtual int decrement()
550  {
551  cerr << "Warning: method decrement() not implemented" << endl;
552  return 0;
553  }
554 
556  virtual bool isBegin() const
557  {
558  return _edge == _begin;
559  }
560 
562  virtual bool isEnd() const
563  {
564  return !_edge;
565  }
566 
568  virtual bool operator==(ViewEdgeIterator &it) const
569  {
570  return _edge == it._edge;
571  }
572 
574  virtual bool operator!=(ViewEdgeIterator &it) const
575  {
576  return !(*this == it);
577  }
578 
579  protected:
583 
584 #ifdef WITH_CXX_GUARDEDALLOC
585  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewEdgeIterator")
586 #endif
587 };
588 
589 } // end of namespace ViewEdgeInternal
590 
591 } /* namespace Freestyle */
typedef float(TangentPoint)[2]
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SVertex * vertexA()
Definition: Silhouette.h:611
ViewEdge * viewedge() const
Definition: Silhouette.h:672
FEdge * previousEdge()
Definition: Silhouette.h:645
SVertex * vertexB()
Definition: Silhouette.h:617
virtual real getLength2D() const
Definition: Silhouette.h:488
FEdge * nextEdge()
Definition: Silhouette.h:637
vector< directedViewEdge > edges_container
Definition: ViewMap.h:674
vector< directedViewEdge * > edge_pointers_container
Definition: ViewMap.h:395
virtual bool operator==(const Interface0DIteratorNested &it) const
virtual SVertexIterator * copy() const
SVertexIterator & operator=(const SVertexIterator &vi)
SVertexIterator(SVertex *v, SVertex *begin, FEdge *prev, FEdge *next, float t)
ViewEdgeIterator(ViewEdge *begin=NULL, bool orientation=true)
virtual bool operator!=(ViewEdgeIterator &it) const
virtual bool operator==(ViewEdgeIterator &it) const
real getLength2D() const
Definition: ViewMap.cpp:664
virtual orientedViewEdgeIterator operator++(int)
virtual ViewVertex::directedViewEdge & operator*() const
virtual bool operator!=(const orientedViewEdgeIterator &b) const
TVertex::edge_pointers_container edge_pointers_container
orientedViewEdgeIterator(edges_container::iterator begin, edges_container::iterator end, edges_container::iterator iter)
orientedViewEdgeIterator(const orientedViewEdgeIterator &iBrother)
orientedViewEdgeIterator(edge_pointers_container::iterator begin, edge_pointers_container::iterator end, edge_pointers_container::iterator iter)
virtual ViewVertex::directedViewEdge * operator->() const
virtual bool operator==(const orientedViewEdgeIterator &b) const
pair< ViewEdge *, bool > directedViewEdge
Definition: ViewMap.h:280
static ulong * next
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
return ret