Blender  V2.93
ChainingIterators.cpp
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 
22 #include "../python/Director.h"
23 
24 #include "ChainingIterators.h"
25 
26 #include "../system/TimeStamp.h"
27 
28 namespace Freestyle {
29 
31 {
32  return (*_internalIterator).first;
33 }
34 
36 {
37  return (*_internalIterator).second;
38 }
39 
41 {
43  while ((!_internalIterator.isEnd()) && (!isValid((*_internalIterator).first))) {
45  }
46  return 0;
47 }
48 
50 {
52  if (edge->getTimeStamp() != TimeStamp::instance()->getTimeStamp()) {
53  return false;
54  }
55  }
58  return false;
59  }
60  }
61  return true;
62 }
63 
65 {
67 }
68 
70 {
71  return Director_BPy_ChainingIterator_traverse(this, const_cast<AdjacencyIterator &>(it));
72 }
73 
75 {
76  _increment = true;
77  ViewVertex *vertex = getVertex();
78  if (!vertex) {
79  _edge = nullptr;
80  return 0;
81  }
83  if (it.isEnd()) {
84  _edge = nullptr;
85  return 0;
86  }
87  if (traverse(it) < 0) {
88  return -1;
89  }
90  _edge = result;
91  if (_edge == nullptr) {
92  return 0;
93  }
94  if (_edge->A() == vertex) {
95  _orientation = true;
96  }
97  else {
98  _orientation = false;
99  }
100  return 0;
101 }
102 
104 {
105  _increment = false;
106  ViewVertex *vertex = getVertex();
107  if (!vertex) {
108  _edge = nullptr;
109  return 0;
110  }
112  if (it.isEnd()) {
113  _edge = nullptr;
114  return 0;
115  }
116  if (traverse(it) < 0) {
117  return -1;
118  }
119  _edge = result;
120  if (_edge == nullptr) {
121  return 0;
122  }
123  if (_edge->B() == vertex) {
124  _orientation = true;
125  }
126  else {
127  _orientation = false;
128  }
129  return 0;
130 }
131 
132 //
133 // ChainSilhouetteIterators
134 //
136 
138 {
139  AdjacencyIterator it(ait);
140  ViewVertex *nextVertex = getVertex();
141  // we can't get a NULL nextVertex here, it was intercepted before
142  if (nextVertex->getNature() & Nature::T_VERTEX) {
143  TVertex *tvertex = (TVertex *)nextVertex;
144  ViewEdge *mate = (tvertex)->mate(getCurrentEdge());
145  while (!it.isEnd()) {
146  ViewEdge *ve = *it;
147  if (ve == mate) {
148  result = ve;
149  return 0;
150  }
151  ++it;
152  }
153  result = nullptr;
154  return 0;
155  }
156  if (nextVertex->getNature() & Nature::NON_T_VERTEX) {
157  // soc NonTVertex *nontvertex = (NonTVertex*)nextVertex;
158  ViewEdge *newEdge(nullptr);
159  // we'll try to chain the edges by keeping the same nature...
160  // the preseance order is : SILHOUETTE, BORDER, CREASE, MATERIAL_BOUNDARY, EDGE_MARK,
161  // SUGGESTIVE, VALLEY, RIDGE
162  Nature::EdgeNature natures[8] = {
171  };
172  int numNatures = ARRAY_SIZE(natures);
173  for (int i = 0; i < numNatures; ++i) {
174  if (getCurrentEdge()->getNature() & natures[i]) {
175  int n = 0;
176  while (!it.isEnd()) {
177  ViewEdge *ve = *it;
178  if (ve->getNature() & natures[i]) {
179  ++n;
180  newEdge = ve;
181  }
182  ++it;
183  }
184  if (n == 1) {
185  result = newEdge;
186  }
187  else {
188  result = nullptr;
189  }
190  return 0;
191  }
192  }
193  }
194  result = nullptr;
195  return 0;
196 }
197 
199 {
201  return -1;
202  }
203  AdjacencyIterator it(ait);
204  // Iterates over next edges to see if one of them respects the predicate:
205  while (!it.isEnd()) {
206  ViewEdge *ve = *it;
207  if (_unary_predicate->operator()(*ve) < 0) {
208  return -1;
209  }
210  if (_unary_predicate->result) {
211  if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) {
212  return -1;
213  }
214  if (_binary_predicate->result) {
215  result = ve;
216  return 0;
217  }
218  }
219  ++it;
220  }
221  result = nullptr;
222  return 0;
223 }
224 
225 } /* namespace Freestyle */
#define ARRAY_SIZE(arr)
Chaining iterators.
int Director_BPy_ChainingIterator_init(ChainingIterator *c_it)
Definition: Director.cpp:194
int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator &a_it)
Definition: Director.cpp:208
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)
virtual unsigned getTimeStamp() const
Definition: Interface1D.h:185
static TimeStamp * instance()
Definition: TimeStamp.h:32
unsigned getTimeStamp() const
Definition: TimeStamp.h:37
virtual Nature::EdgeNature getNature() const
Definition: ViewMap.h:924
ViewVertex * B()
Definition: ViewMap.h:1083
ViewVertex * A()
Definition: ViewMap.h:1077
unsigned getChainingTimeStamp()
Definition: ViewMap.h:1124
virtual Nature::VertexNature getNature() const
Definition: ViewMap.h:331
static const EdgeNature BORDER
Definition: Nature.h:52
static const EdgeNature MATERIAL_BOUNDARY
Definition: Nature.h:62
static const EdgeNature EDGE_MARK
Definition: Nature.h:64
unsigned short EdgeNature
Definition: Nature.h:46
static const EdgeNature VALLEY
Definition: Nature.h:58
static const EdgeNature CREASE
Definition: Nature.h:54
static const VertexNature T_VERTEX
Definition: Nature.h:42
static const EdgeNature RIDGE
Definition: Nature.h:56
static const VertexNature NON_T_VERTEX
Definition: Nature.h:40
static const EdgeNature SILHOUETTE
Definition: Nature.h:50
static const EdgeNature SUGGESTIVE_CONTOUR
Definition: Nature.h:60
inherits from class Rep
Definition: AppCanvas.cpp:32