Blender  V2.93
Functions1D.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 "Functions1D.h"
23 
24 using namespace std;
25 
26 namespace Freestyle::Functions1D {
27 
29 {
30  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
31  return 0;
32 }
33 
35 {
36  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
37  return 0;
38 }
39 
41 {
42  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
43  return 0;
44 }
45 
47 {
48  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
49  return 0;
50 }
51 
53 {
54  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
55  return 0;
56 }
57 
59 {
60  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
61  return 0;
62 }
63 
65 {
66  FEdge *fe = dynamic_cast<FEdge *>(&inter);
67  if (fe) {
68  Vec3r res = fe->orientation2d();
69  result = Vec2f(res[0], res[1]);
70  }
71  else {
72  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
73  }
74  return 0;
75 }
76 
78 {
79  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
80  return 0;
81 }
82 
84 {
85  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
86  return 0;
87 }
88 
90 {
91  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
92  if (ve) {
93  result = ve->qi();
94  return 0;
95  }
96  FEdge *fe = dynamic_cast<FEdge *>(&inter);
97  if (fe) {
98  result = fe->qi();
99  return 0;
100  }
101  result = integrate(_func, inter.verticesBegin(), inter.verticesEnd(), _integration);
102  return 0;
103 }
104 
106 {
107  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
108  if (ve) {
109  result = ve->getNature();
110  }
111  else {
112  // we return a nature that contains every natures of the viewedges spanned by the chain.
114  Interface0DIterator it = inter.verticesBegin();
115  while (!it.isEnd()) {
116  nat |= _func(it);
117  ++it;
118  }
119  result = nat;
120  }
121  return 0;
122 }
123 
125 {
126  TimeStamp *timestamp = TimeStamp::instance();
127  inter.setTimeStamp(timestamp->getTimeStamp());
128  return 0;
129 }
130 
132 {
133  TimeStamp *timestamp = TimeStamp::instance();
134  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
135  if (ve) {
136  ve->setChainingTimeStamp(timestamp->getTimeStamp());
137  }
138  return 0;
139 }
140 
142 {
143  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
144  if (ve) {
146  }
147  return 0;
148 }
149 
151 {
152  vector<ViewShape *> shapesVector;
153  set<ViewShape *> shapesSet;
154  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
155  if (ve) {
156  shapesVector.push_back(ve->viewShape());
157  }
158  else {
159  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
160  for (; it != itend; ++it) {
161  shapesSet.insert(Functions0D::getShapeF0D(it));
162  }
163  shapesVector.insert<set<ViewShape *>::iterator>(
164  shapesVector.begin(), shapesSet.begin(), shapesSet.end());
165  }
166  result = shapesVector;
167  return 0;
168 }
169 
171 {
172  vector<ViewShape *> shapesVector;
173  set<ViewShape *> shapesSet;
174  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
175  if (ve) {
176  result = ve->occluders();
177  }
178  else {
179  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
180  for (; it != itend; ++it) {
181  Functions0D::getOccludersF0D(it, shapesSet);
182  }
183  shapesVector.insert(shapesVector.begin(), shapesSet.begin(), shapesSet.end());
184  result = shapesVector;
185  }
186  return 0;
187 }
188 
190 {
191  vector<ViewShape *> shapesVector;
192  set<ViewShape *> shapesSet;
193  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
194  if (ve) {
195  ViewShape *aShape = ve->aShape();
196  if (aShape) {
197  shapesVector.push_back(aShape);
198  }
199  }
200  else {
201  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
202  for (; it != itend; ++it) {
203  shapesSet.insert(Functions0D::getOccludeeF0D(it));
204  }
205  shapesVector.insert<set<ViewShape *>::iterator>(
206  shapesVector.begin(), shapesSet.begin(), shapesSet.end());
207  }
208  result = shapesVector;
209  return 0;
210 }
211 
212 // Internal
214 
215 void getOccludeeF1D(Interface1D &inter, set<ViewShape *> &oShapes)
216 {
217  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
218  if (ve) {
219  ViewShape *aShape = ve->aShape();
220  if (aShape == nullptr) {
221  oShapes.insert((ViewShape *)nullptr);
222  return;
223  }
224  oShapes.insert(aShape);
225  }
226  else {
227  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
228  for (; it != itend; ++it) {
229  oShapes.insert(Functions0D::getOccludeeF0D(it));
230  }
231  }
232 }
233 
234 void getOccludersF1D(Interface1D &inter, set<ViewShape *> &oShapes)
235 {
236  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
237  if (ve) {
238  vector<ViewShape *> &occluders = ve->occluders();
239  oShapes.insert<vector<ViewShape *>::iterator>(occluders.begin(), occluders.end());
240  }
241  else {
242  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
243  for (; it != itend; ++it) {
244  set<ViewShape *> shapes;
245  Functions0D::getOccludersF0D(it, shapes);
246  for (set<ViewShape *>::iterator s = shapes.begin(), send = shapes.end(); s != send; ++s) {
247  oShapes.insert(*s);
248  }
249  }
250  }
251 }
252 
253 void getShapeF1D(Interface1D &inter, set<ViewShape *> &oShapes)
254 {
255  ViewEdge *ve = dynamic_cast<ViewEdge *>(&inter);
256  if (ve) {
257  oShapes.insert(ve->viewShape());
258  }
259  else {
260  Interface0DIterator it = inter.verticesBegin(), itend = inter.verticesEnd();
261  for (; it != itend; ++it) {
262  oShapes.insert(Functions0D::getShapeF0D(it));
263  }
264  }
265 }
266 
267 } // namespace Freestyle::Functions1D
Functions taking 1D input.
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:90
const int qi() const
Definition: Silhouette.h:886
Vec3r orientation2d() const
Definition: Silhouette.h:926
virtual bool isEnd() const
Definition: Interface0D.h:296
virtual Interface0DIterator verticesEnd()
Definition: Interface1D.cpp:35
virtual Interface0DIterator verticesBegin()
Definition: Interface1D.cpp:29
void setTimeStamp(unsigned iTimeStamp)
Definition: Interface1D.h:191
unsigned getTimeStamp() const
Definition: TimeStamp.h:37
int qi() const
Definition: ViewMap.h:1292
ViewShape * viewShape()
Definition: ViewMap.h:1101
virtual Nature::EdgeNature getNature() const
Definition: ViewMap.h:924
vector< ViewShape * > & occluders()
Definition: ViewMap.h:1139
void setChainingTimeStamp(unsigned ts)
Definition: ViewMap.h:1213
ViewShape * aShape()
Definition: ViewMap.h:1109
unsigned getChainingTimeStamp()
Definition: ViewMap.h:1124
ViewShape * getShapeF0D(Interface0DIterator &it)
ViewShape * getOccludeeF0D(Interface0DIterator &it)
void getOccludersF0D(Interface0DIterator &it, set< ViewShape * > &oOccluders)
void getOccludeeF1D(Interface1D &inter, set< ViewShape * > &oShapes)
void getShapeF1D(Interface1D &inter, set< ViewShape * > &oShapes)
void getOccludersF1D(Interface1D &inter, set< ViewShape * > &oShapes)
VecMat::Vec2< float > Vec2f
Definition: Geom.h:34
static const EdgeNature NO_FEATURE
Definition: Nature.h:48
unsigned short EdgeNature
Definition: Nature.h:46
T integrate(UnaryFunction0D< T > &fun, Interface0DIterator it, Interface0DIterator it_end, IntegrationType integration_type=MEAN)
Definition: Interface1D.h:72