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