Blender  V3.3
ChainingIterators.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 #include "../python/Director.h"
9 
10 #include "ChainingIterators.h"
11 
12 #include "../system/TimeStamp.h"
13 
14 namespace Freestyle {
15 
17 {
18  return (*_internalIterator).first;
19 }
20 
22 {
23  return (*_internalIterator).second;
24 }
25 
27 {
29  while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) {
31  }
32  return 0;
33 }
34 
36 {
38  if (edge->getTimeStamp() != TimeStamp::instance()->getTimeStamp()) {
39  return false;
40  }
41  }
43  if (edge->getChainingTimeStamp() > TimeStamp::instance()->getTimeStamp()) {
44  return false;
45  }
46  }
47  return true;
48 }
49 
51 {
53 }
54 
56 {
57  return Director_BPy_ChainingIterator_traverse(this, const_cast<AdjacencyIterator &>(it));
58 }
59 
61 {
62  _increment = true;
63  ViewVertex *vertex = getVertex();
64  if (!vertex) {
65  _edge = nullptr;
66  return 0;
67  }
69  if (it.isEnd()) {
70  _edge = nullptr;
71  return 0;
72  }
73  if (traverse(it) < 0) {
74  return -1;
75  }
76  _edge = result;
77  if (_edge == nullptr) {
78  return 0;
79  }
80  if (_edge->A() == vertex) {
81  _orientation = true;
82  }
83  else {
84  _orientation = false;
85  }
86  return 0;
87 }
88 
90 {
91  _increment = false;
92  ViewVertex *vertex = getVertex();
93  if (!vertex) {
94  _edge = nullptr;
95  return 0;
96  }
98  if (it.isEnd()) {
99  _edge = nullptr;
100  return 0;
101  }
102  if (traverse(it) < 0) {
103  return -1;
104  }
105  _edge = result;
106  if (_edge == nullptr) {
107  return 0;
108  }
109  if (_edge->B() == vertex) {
110  _orientation = true;
111  }
112  else {
113  _orientation = false;
114  }
115  return 0;
116 }
117 
118 //
119 // ChainSilhouetteIterators
120 //
122 
124 {
125  AdjacencyIterator it(ait);
126  ViewVertex *nextVertex = getVertex();
127  // we can't get a NULL nextVertex here, it was intercepted before
128  if (nextVertex->getNature() & Nature::T_VERTEX) {
129  TVertex *tvertex = (TVertex *)nextVertex;
130  ViewEdge *mate = (tvertex)->mate(getCurrentEdge());
131  while (!it.isEnd()) {
132  ViewEdge *ve = *it;
133  if (ve == mate) {
134  result = ve;
135  return 0;
136  }
137  ++it;
138  }
139  result = nullptr;
140  return 0;
141  }
142  if (nextVertex->getNature() & Nature::NON_T_VERTEX) {
143  // soc NonTVertex *nontvertex = (NonTVertex*)nextVertex;
144  ViewEdge *newEdge(nullptr);
145  // we'll try to chain the edges by keeping the same nature...
146  // the preseance order is : SILHOUETTE, BORDER, CREASE, MATERIAL_BOUNDARY, EDGE_MARK,
147  // SUGGESTIVE, VALLEY, RIDGE
148  Nature::EdgeNature natures[8] = {
157  };
158  int numNatures = ARRAY_SIZE(natures);
159  for (int i = 0; i < numNatures; ++i) {
160  if (getCurrentEdge()->getNature() & natures[i]) {
161  int n = 0;
162  while (!it.isEnd()) {
163  ViewEdge *ve = *it;
164  if (ve->getNature() & natures[i]) {
165  ++n;
166  newEdge = ve;
167  }
168  ++it;
169  }
170  if (n == 1) {
171  result = newEdge;
172  }
173  else {
174  result = nullptr;
175  }
176  return 0;
177  }
178  }
179  }
180  result = nullptr;
181  return 0;
182 }
183 
185 {
187  return -1;
188  }
189  AdjacencyIterator it(ait);
190  // Iterates over next edges to see if one of them respects the predicate:
191  while (!it.isEnd()) {
192  ViewEdge *ve = *it;
193  if (_unary_predicate->operator()(*ve) < 0) {
194  return -1;
195  }
196  if (_unary_predicate->result) {
197  if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) {
198  return -1;
199  }
200  if (_binary_predicate->result) {
201  result = ve;
202  return 0;
203  }
204  }
205  ++it;
206  }
207  result = nullptr;
208  return 0;
209 }
210 
211 } /* namespace Freestyle */
#define ARRAY_SIZE(arr)
Chaining iterators.
int Director_BPy_ChainingIterator_init(ChainingIterator *c_it)
Definition: Director.cpp:180
int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator &a_it)
Definition: Director.cpp:194
ViewVertexInternal::orientedViewEdgeIterator _internalIterator
virtual ViewEdge * operator*()
virtual bool isEnd() const
virtual int traverse(const AdjacencyIterator &it)
virtual int traverse(const AdjacencyIterator &it)
virtual int traverse(const AdjacencyIterator &it)
static TimeStamp * instance()
Definition: TimeStamp.h:18
unsigned getTimeStamp() const
Definition: TimeStamp.h:23
virtual Nature::EdgeNature getNature() const
Definition: ViewMap.h:914
ViewVertex * B()
Definition: ViewMap.h:1073
ViewVertex * A()
Definition: ViewMap.h:1067
virtual Nature::VertexNature getNature() const
Definition: ViewMap.h:317
static const EdgeNature BORDER
Definition: Nature.h:38
static const EdgeNature MATERIAL_BOUNDARY
Definition: Nature.h:48
static const EdgeNature EDGE_MARK
Definition: Nature.h:50
unsigned short EdgeNature
Definition: Nature.h:32
static const EdgeNature VALLEY
Definition: Nature.h:44
static const EdgeNature CREASE
Definition: Nature.h:40
static const VertexNature T_VERTEX
Definition: Nature.h:28
static const EdgeNature RIDGE
Definition: Nature.h:42
static const VertexNature NON_T_VERTEX
Definition: Nature.h:26
static const EdgeNature SILHOUETTE
Definition: Nature.h:36
static const EdgeNature SUGGESTIVE_CONTOUR
Definition: Nature.h:46
inherits from class Rep
Definition: AppCanvas.cpp:18