Blender V4.3
Silhouette.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include "Silhouette.h"
11#include "ViewMap.h"
12
13namespace Freestyle {
14
15/**********************************/
16/* */
17/* */
18/* SVertex */
19/* */
20/* */
21/**********************************/
22
24{
26 if (_pViewVertex) {
27 nature |= _pViewVertex->getNature();
28 }
29 return nature;
30}
31
33{
34 return this;
35}
36
38{
39 return _pViewVertex;
40}
41
43{
44 return dynamic_cast<NonTVertex *>(_pViewVertex);
45}
46
48{
49 return dynamic_cast<TVertex *>(_pViewVertex);
50}
51
53{
54 return shape()->importance();
55}
56
57#if 0
58Material SVertex::material() const
59{
60 return _Shape->material();
61}
62#endif
63
65{
66 return _Shape->getId();
67}
68
69const SShape *SVertex::shape() const
70{
71 return _Shape;
72}
73
74int SVertex::qi() const
75{
78 }
79 return (_FEdges[0])->qi();
80}
81
82occluder_container::const_iterator SVertex::occluders_begin() const
83{
86 }
87 return (_FEdges[0])->occluders_begin();
88}
89
90occluder_container::const_iterator SVertex::occluders_end() const
91{
94 }
95 return (_FEdges[0])->occluders_end();
96}
97
99{
100 if (getNature() & Nature::T_VERTEX) {
102 }
103 return (_FEdges[0])->occluders_empty();
104}
105
107{
108 if (getNature() & Nature::T_VERTEX) {
110 }
111 return (_FEdges[0])->occluders_size();
112}
113
115{
116 if (getNature() & Nature::T_VERTEX) {
118 }
119 return (_FEdges[0])->occludee();
120}
121
123{
124 if (getNature() & Nature::T_VERTEX) {
126 }
127 return (_FEdges[0])->occluded_shape();
128}
129
131{
132 if (getNature() & Nature::T_VERTEX) {
134 }
135 return (_FEdges[0])->occludee_empty();
136}
137
139{
140 if (getNature() & Nature::T_VERTEX) {
142 }
143 return (_FEdges[0])->z_discontinuity();
144}
145
147{
148 if (getNature() & Nature::T_VERTEX) {
149 return nullptr;
150 }
151 return _FEdges[0];
152}
153
155{
156 FEdge *result = nullptr;
157 SVertex *iVertexB = dynamic_cast<SVertex *>(&inter);
158 if (!iVertexB) {
159 return result;
160 }
161 vector<FEdge *>::const_iterator fe = _FEdges.begin(), feend = _FEdges.end();
162 for (; fe != feend; ++fe) {
163 if ((((*fe)->vertexA() == this) && ((*fe)->vertexB() == iVertexB)) ||
164 (((*fe)->vertexB() == this) && ((*fe)->vertexA() == iVertexB)))
165 {
166 result = (*fe);
167 }
168 }
169 if ((result == nullptr) && (getNature() & Nature::T_VERTEX)) {
170 SVertex *brother;
171 ViewVertex *vvertex = viewvertex();
172 TVertex *tvertex = dynamic_cast<TVertex *>(vvertex);
173 if (tvertex) {
174 brother = tvertex->frontSVertex();
175 if (this == brother) {
176 brother = tvertex->backSVertex();
177 }
178 const vector<FEdge *> &fedges = brother->fedges();
179 for (fe = fedges.begin(), feend = fedges.end(); fe != feend; ++fe) {
180 if ((((*fe)->vertexA() == brother) && ((*fe)->vertexB() == iVertexB)) ||
181 (((*fe)->vertexB() == brother) && ((*fe)->vertexA() == iVertexB)))
182 {
183 result = (*fe);
184 }
185 }
186 }
187 }
188 if ((result == nullptr) && (iVertexB->getNature() & Nature::T_VERTEX)) {
189 SVertex *brother;
190 ViewVertex *vvertex = iVertexB->viewvertex();
191 TVertex *tvertex = dynamic_cast<TVertex *>(vvertex);
192 if (tvertex) {
193 brother = tvertex->frontSVertex();
194 if (iVertexB == brother) {
195 brother = tvertex->backSVertex();
196 }
197 for (fe = _FEdges.begin(), feend = _FEdges.end(); fe != feend; ++fe) {
198 if ((((*fe)->vertexA() == this) && ((*fe)->vertexB() == brother)) ||
199 (((*fe)->vertexB() == this) && ((*fe)->vertexA() == brother)))
200 {
201 result = (*fe);
202 }
203 }
204 }
205 }
206
207 return result;
208}
209
210/**********************************/
211/* */
212/* */
213/* FEdge */
214/* */
215/* */
216/**********************************/
217
219{
220 return _ViewEdge->getNature();
221}
222
223#if 0
224float FEdge::viewedge_length() const
225{
226 return _ViewEdge->viewedge_length();
227}
228#endif
229
231{
232 ViewShape *aShape = _ViewEdge->aShape();
233 if (aShape == nullptr) {
234 return nullptr;
235 }
236 return aShape->sshape();
237}
238
240{
241 return _VertexA->shape()->importance();
242}
243
245{
246 return _ViewEdge->qi();
247}
248
249occluder_container::const_iterator FEdge::occluders_begin() const
250{
251 return _ViewEdge->occluders_begin();
252}
253
254occluder_container::const_iterator FEdge::occluders_end() const
255{
256 return _ViewEdge->occluders_end();
257}
258
260{
261 return _ViewEdge->occluders_empty();
262}
263
265{
266 return _ViewEdge->occluders_size();
267}
268
270{
271 return _ViewEdge->occludee_empty();
272}
273
275{
276 return _VertexA->shape()->getId();
277}
278
279const SShape *FEdge::shape() const
280{
281 return _VertexA->shape();
282}
283
285{
287 return 0;
288 }
289
291
292 Vec3r bbox_size_vec(box.getMax() - box.getMin());
293 real bboxsize = bbox_size_vec.norm();
294 if (occludee_empty()) {
295 // return FLT_MAX;
296 return 1.0;
297 // return bboxsize;
298 }
299
300#if 0
301 real result;
302 z_discontinuity_functor<SVertex> _functor;
303 Evaluate<SVertex, z_discontinuity_functor<SVertex>>(&_functor, iCombination, result);
304#endif
305 Vec3r middle(_VertexB->point3d() - _VertexA->point3d());
306 middle /= 2;
307 Vec3r disc_vec(middle - _occludeeIntersection);
308 real res = disc_vec.norm() / bboxsize;
309
310 return res;
311 // return fabs((middle.z() - _occludeeIntersection.z()));
312}
313
314#if 0
315float FEdge::local_average_depth(int iCombination) const
316{
317 float result;
318 local_average_depth_functor<SVertex> functor;
319 Evaluate(&functor, iCombination, result);
320
321 return result;
322}
323
324float FEdge::local_depth_variance(int iCombination) const
325{
326 float result;
327
328 local_depth_variance_functor<SVertex> functor;
329
330 Evaluate(&functor, iCombination, result);
331
332 return result;
333}
334
335real FEdge::local_average_density(float sigma, int iCombination) const
336{
337 float result;
338
339 density_functor<SVertex> functor(sigma);
340
341 Evaluate(&functor, iCombination, result);
342
343 return result;
344}
345
346Vec3r FEdge::normal(int &oException /* = Exception::NO_EXCEPTION */)
347{
348 Vec3r Na = _VertexA->normal(oException);
349 if (oException != Exception::NO_EXCEPTION) {
350 return Na;
351 }
352 Vec3r Nb = _VertexB->normal(oException);
353 if (oException != Exception::NO_EXCEPTION) {
354 return Nb;
355 }
356 return (Na + Nb) / 2.0;
357}
358
359Vec3r FEdge::curvature2d_as_vector(int iCombination) const
360{
362 curvature2d_as_vector_functor<SVertex> _functor;
363 Evaluate<Vec3r, curvature2d_as_vector_functor<SVertex>>(&_functor, iCombination, result);
364 return result;
365}
366
367real FEdge::curvature2d_as_angle(int iCombination) const
368{
369 real result;
370 curvature2d_as_angle_functor<SVertex> _functor;
371 Evaluate<real, curvature2d_as_angle_functor<SVertex>>(&_functor, iCombination, result);
372 return result;
373}
374#endif
375
376/**********************************/
377/* */
378/* */
379/* FEdgeSharp */
380/* */
381/* */
382/**********************************/
383
384#if 0
385Material FEdge::material() const
386{
387 return _VertexA->shape()->material();
388}
389#endif
390
395
400
401/**********************************/
402/* */
403/* */
404/* FEdgeSmooth */
405/* */
406/* */
407/**********************************/
408
413
414} /* namespace Freestyle */
Classes to define a silhouette structure.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
static int raiseException(exception_type exception=UNDEFINED)
Definition Exception.h:32
const FrsMaterial & aFrsMaterial() const
const FrsMaterial & bFrsMaterial() const
const FrsMaterial & frs_material() const
bool occluders_empty() const
int occluders_size() const
occluder_container::const_iterator occluders_end() const
SShape * shape()
Definition Silhouette.h:636
SVertex * _VertexB
Definition Silhouette.h:502
ViewEdge * _ViewEdge
Definition Silhouette.h:509
occluder_container::const_iterator occluders_begin() const
SVertex * _VertexA
Definition Silhouette.h:501
Id shape_id() const
const SShape * occluded_shape() const
int viewedge_nature() const
Vec3r _occludeeIntersection
Definition Silhouette.h:514
int invisibility() const
float shape_importance() const
Nature::EdgeNature getNature() const
Definition Silhouette.h:615
real z_discontinuity() const
bool occludee_empty() const
float importance() const
const FrsMaterial & frs_material(uint i) const
ViewVertex * viewvertex()
Definition Silhouette.h:278
const SShape * occluded_shape() const
virtual FEdge * getFEdge(Interface0D &)
Vec3r normal() const
Definition Silhouette.h:407
virtual ViewVertex * castToViewVertex()
real z_discontinuity() const
occluder_container::const_iterator occluders_begin() const
bool occluders_empty() const
Id shape_id() const
const Vec3r & point3d() const
Definition Silhouette.h:402
virtual NonTVertex * castToNonTVertex()
virtual SVertex * castToSVertex()
occluder_container::const_iterator occluders_end() const
virtual TVertex * castToTVertex()
virtual Nature::VertexNature getNature() const
int occluders_size() const
const Polygon3r & occludee() const
const vector< FEdge * > & fedges()
Definition Silhouette.h:250
bool occludee_empty() const
float shape_importance() const
SVertex * backSVertex()
Definition ViewMap.h:525
SVertex * frontSVertex()
Definition ViewMap.h:519
value_type norm() const
Definition VecMat.h:94
int qi() const
Definition ViewMap.h:1280
ViewShape * aShape()
Definition ViewMap.h:1095
virtual Nature::EdgeNature getNature() const
Definition ViewMap.h:910
occluder_container::const_iterator occluders_begin() const
Definition ViewMap.h:1285
const bool occludee_empty() const
Definition ViewMap.h:1312
bool occluders_empty() const
Definition ViewMap.h:1300
int occluders_size() const
Definition ViewMap.h:1295
occluder_container::const_iterator occluders_end() const
Definition ViewMap.h:1290
BBox< Vec3r > getScene3dBBox() const
Definition ViewMap.h:151
static ViewMap * getInstance()
Definition ViewMap.h:92
SShape * sshape()
Definition ViewMap.h:1539
virtual Nature::VertexNature getNature() const
Definition ViewMap.h:316
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
static const EdgeNature BORDER
Definition Nature.h:42
static const VertexNature S_VERTEX
Definition Nature.h:26
ushort VertexNature
Definition Nature.h:22
static const VertexNature T_VERTEX
Definition Nature.h:32
static const EdgeNature SILHOUETTE
Definition Nature.h:40
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14