Blender V4.3
ChainingIterators.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
12#include <iostream>
13
14#include "Predicates1D.h"
15
16#include "../system/Iterator.h"
17
18#include "../view_map/ViewMap.h"
21
22// using namespace ViewEdgeInternal;
23
24namespace Freestyle {
25
26//
27// Adjacency iterator used in the chaining process
28//
31 protected:
35
36 public:
42
44 bool iRestrictToSelection = true,
45 bool iRestrictToUnvisited = true)
46 {
47 _restrictToSelection = iRestrictToSelection;
48 _restrictToUnvisited = iRestrictToUnvisited;
49 _internalIterator = iVertex->edgesBegin();
50 while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) {
52 }
53 }
54
61
69
70 virtual ~AdjacencyIterator() {}
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 {
85 }
86
89 bool isIncoming() const;
90
92 virtual ViewEdge *operator*();
93
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 = nullptr,
163 bool orientation = true)
164 : ViewEdgeIterator(begin, orientation)
165 {
166 _restrictToSelection = iRestrictToSelection;
167 _restrictToUnvisited = iRestrictToUnvisited;
168 _increment = true;
169 py_c_it = nullptr;
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 = nullptr,
266 bool orientation = true)
267 : ChainingIterator(iRestrictToSelection, true, begin, orientation)
268 {
269 }
270
273
275 virtual string getExactTypeName() const
276 {
277 return "ChainSilhouetteIterator";
278 }
279
284 virtual int traverse(const AdjacencyIterator &it);
285
287 virtual int init()
288 {
289 return 0;
290 }
291};
292
293//
294// ChainPredicateIterator
295//
297
308 protected:
310 *_binary_predicate; // the caller is responsible for the deletion of this object
311 UnaryPredicate1D *_unary_predicate; // the caller is responsible for the deletion of this object
312
313 public:
327 ChainPredicateIterator(bool iRestrictToSelection = true,
328 bool iRestrictToUnvisited = true,
329 ViewEdge *begin = nullptr,
330 bool orientation = true)
331 : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation)
332 {
335 }
336
357 BinaryPredicate1D &bpred,
358 bool iRestrictToSelection = true,
359 bool iRestrictToUnvisited = true,
360 ViewEdge *begin = nullptr,
361 bool orientation = true)
362 : ChainingIterator(iRestrictToSelection, iRestrictToUnvisited, begin, orientation)
363 {
364 _unary_predicate = &upred;
365 _binary_predicate = &bpred;
366 }
367
374
377 {
380 }
381
383 virtual string getExactTypeName() const
384 {
385 return "ChainPredicateIterator";
386 }
387
391 virtual int traverse(const AdjacencyIterator &it);
392
394 virtual int init()
395 {
396 return 0;
397 }
398};
399
400} /* namespace Freestyle */
Class gathering stroke creation algorithms.
Iterators used to iterate over the various elements of the ViewMap. These iterators can't be exported...
Iterators used to iterate over the various elements of the ViewMap.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
virtual AdjacencyIterator operator++(int)
AdjacencyIterator(const AdjacencyIterator &iBrother)
virtual AdjacencyIterator & operator++()
AdjacencyIterator & operator=(const AdjacencyIterator &iBrother)
ViewVertexInternal::orientedViewEdgeIterator _internalIterator
AdjacencyIterator(ViewVertex *iVertex, bool iRestrictToSelection=true, bool iRestrictToUnvisited=true)
virtual ViewEdge * operator->()
virtual string getExactTypeName() const
ChainPredicateIterator(bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=nullptr, bool orientation=true)
ChainPredicateIterator(const ChainPredicateIterator &brother)
ChainPredicateIterator(UnaryPredicate1D &upred, BinaryPredicate1D &bpred, bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=nullptr, bool orientation=true)
virtual string getExactTypeName() const
virtual int traverse(const AdjacencyIterator &it)
ChainSilhouetteIterator(const ChainSilhouetteIterator &brother)
virtual int traverse(const AdjacencyIterator &it)
virtual string getExactTypeName() const
ChainSilhouetteIterator(bool iRestrictToSelection=true, ViewEdge *begin=nullptr, bool orientation=true)
ChainingIterator(bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=nullptr, bool orientation=true)
ChainingIterator(const ChainingIterator &brother)
virtual int traverse(const AdjacencyIterator &it)
virtual string getExactTypeName() const
ViewEdgeIterator(ViewEdge *begin=nullptr, bool orientation=true)
ViewVertex * B()
Definition ViewMap.h:1069
ViewVertex * A()
Definition ViewMap.h:1063
virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin()=0
inherits from class Rep
Definition AppCanvas.cpp:20