Blender  V3.3
ChainingIterators.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <iostream>
11 
12 #include "Predicates1D.h"
13 
14 #include "../system/Iterator.h"
15 
16 #include "../view_map/ViewMap.h"
17 #include "../view_map/ViewMapAdvancedIterators.h"
18 #include "../view_map/ViewMapIterators.h"
19 
20 // using namespace ViewEdgeInternal;
21 
22 namespace Freestyle {
23 
24 //
25 // Adjacency iterator used in the chaining process
26 //
28 class AdjacencyIterator : public Iterator {
29  protected:
33 
34  public:
36  {
37  _restrictToSelection = true;
38  _restrictToUnvisited = true;
39  }
40 
42  bool iRestrictToSelection = true,
43  bool iRestrictToUnvisited = true)
44  {
45  _restrictToSelection = iRestrictToSelection;
46  _restrictToUnvisited = iRestrictToUnvisited;
47  _internalIterator = iVertex->edgesBegin();
48  while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) {
50  }
51  }
52 
54  {
58  }
59 
61  {
65  return *this;
66  }
67 
69  {
70  }
71 
72  virtual string getExactTypeName() const
73  {
74  return "AdjacencyIterator";
75  }
76 
77  virtual inline bool isEnd() const
78  {
79  return _internalIterator.isEnd();
80  }
81 
82  virtual inline bool isBegin() const
83  {
84  return _internalIterator.isBegin();
85  }
86 
89  bool isIncoming() const;
90 
92  virtual ViewEdge *operator*();
93 
94  virtual ViewEdge *operator->()
95  {
96  return operator*();
97  }
98 
100  {
101  increment();
102  return *this;
103  }
104 
106  {
107  AdjacencyIterator tmp(*this);
108  increment();
109  return tmp;
110  }
111 
112  virtual int increment();
113 
114  virtual int decrement()
115  {
116  cerr << "Warning: method decrement() not implemented" << endl;
117  return 0;
118  }
119 
120  protected:
121  bool isValid(ViewEdge *edge);
122 };
123 
124 //
125 // Base class for Chaining Iterators
126 //
128 
139  protected:
142  bool _increment; // true if we're currently incrementing, false when decrementing
143 
144  public:
146  void *py_c_it;
147 
160  ChainingIterator(bool iRestrictToSelection = true,
161  bool iRestrictToUnvisited = true,
162  ViewEdge *begin = NULL,
163  bool orientation = true)
164  : ViewEdgeIterator(begin, orientation)
165  {
166  _restrictToSelection = iRestrictToSelection;
167  _restrictToUnvisited = iRestrictToUnvisited;
168  _increment = true;
169  py_c_it = NULL;
170  }
171 
174  {
177  _increment = brother._increment;
178  py_c_it = brother.py_c_it;
179  }
180 
182  virtual string getExactTypeName() const
183  {
184  return "ChainingIterator";
185  }
186 
191  virtual int init();
192 
200  virtual int traverse(const AdjacencyIterator &it);
201 
202  /* accessors */
205  // inline bool getOrientation() const {}
206 
209  {
210  if (_increment) {
211  if (_orientation) {
212  return _edge->B();
213  }
214  else {
215  return _edge->A();
216  }
217  }
218  else {
219  if (_orientation) {
220  return _edge->A();
221  }
222  else {
223  return _edge->B();
224  }
225  }
226  }
227 
229  inline bool isIncrementing() const
230  {
231  return _increment;
232  }
233 
234  /* Increments. */
235  virtual int increment();
236  virtual int decrement();
237 };
238 
239 //
240 // Chaining iterators definitions
241 //
243 
251  public:
264  ChainSilhouetteIterator(bool iRestrictToSelection = true,
265  ViewEdge *begin = NULL,
266  bool orientation = true)
267  : ChainingIterator(iRestrictToSelection, true, begin, orientation)
268  {
269  }
270 
273  {
274  }
275 
277  virtual string getExactTypeName() const
278  {
279  return "ChainSilhouetteIterator";
280  }
281 
286  virtual int traverse(const AdjacencyIterator &it);
287 
289  virtual int init()
290  {
291  return 0;
292  }
293 };
294 
295 //
296 // ChainPredicateIterator
297 //
299 
310  protected:
312  *_binary_predicate; // the caller is responsible for the deletion of this object
313  UnaryPredicate1D *_unary_predicate; // the caller is responsible for the deletion of this object
314 
315  public:
329  ChainPredicateIterator(bool iRestrictToSelection = true,
330  bool iRestrictToUnvisited = true,
331  ViewEdge *begin = NULL,
332  bool orientation = true)
333  : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation)
334  {
335  _binary_predicate = 0;
336  _unary_predicate = 0;
337  }
338 
359  BinaryPredicate1D &bpred,
360  bool iRestrictToSelection = true,
361  bool iRestrictToUnvisited = true,
362  ViewEdge *begin = NULL,
363  bool orientation = true)
364  : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation)
365  {
366  _unary_predicate = &upred;
367  _binary_predicate = &bpred;
368  }
369 
372  {
375  }
376 
379  {
380  _unary_predicate = 0;
381  _binary_predicate = 0;
382  }
383 
385  virtual string getExactTypeName() const
386  {
387  return "ChainPredicateIterator";
388  }
389 
393  virtual int traverse(const AdjacencyIterator &it);
394 
396  virtual int init()
397  {
398  return 0;
399  }
400 };
401 
402 } /* namespace Freestyle */
Class gathering stroke creation algorithms.
virtual AdjacencyIterator operator++(int)
AdjacencyIterator(const AdjacencyIterator &iBrother)
ViewVertexInternal::orientedViewEdgeIterator _internalIterator
AdjacencyIterator(ViewVertex *iVertex, bool iRestrictToSelection=true, bool iRestrictToUnvisited=true)
AdjacencyIterator & operator=(const AdjacencyIterator &iBrother)
virtual ViewEdge * operator->()
virtual string getExactTypeName() const
virtual ViewEdge * operator*()
virtual bool isBegin() const
virtual AdjacencyIterator & operator++()
virtual bool isEnd() const
ChainPredicateIterator(bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=NULL, bool orientation=true)
ChainPredicateIterator(UnaryPredicate1D &upred, BinaryPredicate1D &bpred, bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=NULL, bool orientation=true)
ChainPredicateIterator(const ChainPredicateIterator &brother)
virtual string getExactTypeName() const
virtual int traverse(const AdjacencyIterator &it)
ChainSilhouetteIterator(const ChainSilhouetteIterator &brother)
ChainSilhouetteIterator(bool iRestrictToSelection=true, ViewEdge *begin=NULL, bool orientation=true)
virtual int traverse(const AdjacencyIterator &it)
virtual string getExactTypeName() const
ChainingIterator(const ChainingIterator &brother)
virtual int traverse(const AdjacencyIterator &it)
ChainingIterator(bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=NULL, bool orientation=true)
virtual string getExactTypeName() const
ViewEdgeIterator(ViewEdge *begin=NULL, bool orientation=true)
ViewVertex * B()
Definition: ViewMap.h:1073
ViewVertex * A()
Definition: ViewMap.h:1067
virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin()=0
inherits from class Rep
Definition: AppCanvas.cpp:18