Blender  V2.93
ChainingIterators.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 <iostream>
25 
26 #include "Predicates1D.h"
27 
28 #include "../system/Iterator.h"
29 
30 #include "../view_map/ViewMap.h"
31 #include "../view_map/ViewMapAdvancedIterators.h"
32 #include "../view_map/ViewMapIterators.h"
33 
34 // using namespace ViewEdgeInternal;
35 
36 namespace Freestyle {
37 
38 //
39 // Adjacency iterator used in the chaining process
40 //
42 class AdjacencyIterator : public Iterator {
43  protected:
47 
48  public:
50  {
51  _restrictToSelection = true;
52  _restrictToUnvisited = true;
53  }
54 
56  bool iRestrictToSelection = true,
57  bool iRestrictToUnvisited = true)
58  {
59  _restrictToSelection = iRestrictToSelection;
60  _restrictToUnvisited = iRestrictToUnvisited;
61  _internalIterator = iVertex->edgesBegin();
62  while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) {
64  }
65  }
66 
68  {
72  }
73 
75  {
79  return *this;
80  }
81 
83  {
84  }
85 
86  virtual string getExactTypeName() const
87  {
88  return "AdjacencyIterator";
89  }
90 
91  virtual inline bool isEnd() const
92  {
93  return _internalIterator.isEnd();
94  }
95 
96  virtual inline bool isBegin() const
97  {
98  return _internalIterator.isBegin();
99  }
100 
103  bool isIncoming() const;
104 
106  virtual ViewEdge *operator*();
107 
108  virtual ViewEdge *operator->()
109  {
110  return operator*();
111  }
112 
114  {
115  increment();
116  return *this;
117  }
118 
120  {
121  AdjacencyIterator tmp(*this);
122  increment();
123  return tmp;
124  }
125 
126  virtual int increment();
127 
128  virtual int decrement()
129  {
130  cerr << "Warning: method decrement() not implemented" << endl;
131  return 0;
132  }
133 
134  protected:
135  bool isValid(ViewEdge *edge);
136 };
137 
138 //
139 // Base class for Chaining Iterators
140 //
142 
153  protected:
156  bool _increment; // true if we're currently incrementing, false when decrementing
157 
158  public:
160  void *py_c_it;
161 
174  ChainingIterator(bool iRestrictToSelection = true,
175  bool iRestrictToUnvisited = true,
176  ViewEdge *begin = NULL,
177  bool orientation = true)
178  : ViewEdgeIterator(begin, orientation)
179  {
180  _restrictToSelection = iRestrictToSelection;
181  _restrictToUnvisited = iRestrictToUnvisited;
182  _increment = true;
183  py_c_it = NULL;
184  }
185 
188  {
191  _increment = brother._increment;
192  py_c_it = brother.py_c_it;
193  }
194 
196  virtual string getExactTypeName() const
197  {
198  return "ChainingIterator";
199  }
200 
205  virtual int init();
206 
214  virtual int traverse(const AdjacencyIterator &it);
215 
216  /* accessors */
219  // inline bool getOrientation() const {}
220 
223  {
224  if (_increment) {
225  if (_orientation) {
226  return _edge->B();
227  }
228  else {
229  return _edge->A();
230  }
231  }
232  else {
233  if (_orientation) {
234  return _edge->A();
235  }
236  else {
237  return _edge->B();
238  }
239  }
240  }
241 
243  inline bool isIncrementing() const
244  {
245  return _increment;
246  }
247 
248  /* increments.*/
249  virtual int increment();
250  virtual int decrement();
251 };
252 
253 //
254 // Chaining iterators definitions
255 //
257 
265  public:
278  ChainSilhouetteIterator(bool iRestrictToSelection = true,
279  ViewEdge *begin = NULL,
280  bool orientation = true)
281  : ChainingIterator(iRestrictToSelection, true, begin, orientation)
282  {
283  }
284 
287  {
288  }
289 
291  virtual string getExactTypeName() const
292  {
293  return "ChainSilhouetteIterator";
294  }
295 
300  virtual int traverse(const AdjacencyIterator &it);
301 
303  virtual int init()
304  {
305  return 0;
306  }
307 };
308 
309 //
310 // ChainPredicateIterator
311 //
313 
324  protected:
326  *_binary_predicate; // the caller is responsible for the deletion of this object
327  UnaryPredicate1D *_unary_predicate; // the caller is responsible for the deletion of this object
328 
329  public:
343  ChainPredicateIterator(bool iRestrictToSelection = true,
344  bool iRestrictToUnvisited = true,
345  ViewEdge *begin = NULL,
346  bool orientation = true)
347  : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation)
348  {
349  _binary_predicate = 0;
350  _unary_predicate = 0;
351  }
352 
373  BinaryPredicate1D &bpred,
374  bool iRestrictToSelection = true,
375  bool iRestrictToUnvisited = true,
376  ViewEdge *begin = NULL,
377  bool orientation = true)
378  : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation)
379  {
380  _unary_predicate = &upred;
381  _binary_predicate = &bpred;
382  }
383 
386  {
389  }
390 
393  {
394  _unary_predicate = 0;
395  _binary_predicate = 0;
396  }
397 
399  virtual string getExactTypeName() const
400  {
401  return "ChainPredicateIterator";
402  }
403 
407  virtual int traverse(const AdjacencyIterator &it);
408 
410  virtual int init()
411  {
412  return 0;
413  }
414 };
415 
416 } /* 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:1083
ViewVertex * A()
Definition: ViewMap.h:1077
virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin()=0
inherits from class Rep
Definition: AppCanvas.cpp:32