Blender V4.3
OccluderSource.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include <algorithm>
11
12#include "OccluderSource.h"
13
14#include "BLI_sys_types.h"
15
16#include "BKE_global.hh"
17
18namespace Freestyle {
19
20OccluderSource::OccluderSource(const GridHelpers::Transform &t, WingedEdge &we)
21 : wingedEdge(we), valid(false), transform(t)
22{
23 begin();
24}
25
27
29{
30 vector<Vec3r> vertices(GridHelpers::enumerateVertices((*currentFace)->getEdgeList()));
31 // This doesn't work, because our functor's polymorphism won't survive the copy:
32 // std::transform(vertices.begin(), vertices.end(), vertices.begin(), transform);
33 // so we have to do:
34 for (vector<Vec3r>::iterator i = vertices.begin(); i != vertices.end(); ++i) {
35 (*i) = transform(*i);
36 }
37 cachedPolygon = Polygon3r(vertices, transform((*currentFace)->GetNormal()));
38}
39
41{
42 vector<WShape *> &wshapes = wingedEdge.getWShapes();
43 currentShape = wshapes.begin();
44 shapesEnd = wshapes.end();
45 valid = false;
46 if (currentShape != shapesEnd) {
47 vector<WFace *> &wFaces = (*currentShape)->GetFaceList();
48 currentFace = wFaces.begin();
49 facesEnd = wFaces.end();
50
51 if (currentFace != facesEnd) {
53 valid = true;
54 }
55 }
56}
57
59{
60 if (valid) {
62 while (currentFace == facesEnd) {
64 if (currentShape == shapesEnd) {
65 valid = false;
66 return false;
67 }
68
69 vector<WFace *> &wFaces = (*currentShape)->GetFaceList();
70 currentFace = wFaces.begin();
71 facesEnd = wFaces.end();
72 }
74 return true;
75 }
76 return false;
77}
78
80{
81 // Or:
82 // return currentShapes != shapesEnd && currentFace != facesEnd;
83 return valid;
84}
85
87{
88 return valid ? *currentFace : nullptr;
89}
90
92{
93 return Polygon3r(GridHelpers::enumerateVertices((*currentFace)->getEdgeList()),
94 (*currentFace)->GetNormal());
95}
96
101
103{
104 begin();
105 const Vec3r &initialPoint = cachedPolygon.getVertices()[0];
106 proscenium[0] = proscenium[1] = initialPoint[0];
107 proscenium[2] = proscenium[3] = initialPoint[1];
108 while (isValid()) {
110 next();
111 }
112 if (G.debug & G_DEBUG_FREESTYLE) {
113 cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
114 << ", " << proscenium[3] << ")" << endl;
115 }
116}
117
119{
120 real area = 0.0;
121 uint numFaces = 0;
122 for (begin(); isValid(); next()) {
123 Vec3r min, max;
125 area += (max[0] - min[0]) * (max[1] - min[1]);
126 ++numFaces;
127 }
128 area /= numFaces;
129 return area;
130}
131
132} /* namespace Freestyle */
@ G_DEBUG_FREESTYLE
unsigned int uint
Class to define a cell grid surrounding the projected image of a scene.
void getBBox(Point &min, Point &max) const
Definition Polygon.h:73
const vector< Point > & getVertices() const
Definition Polygon.h:68
vector< WFace * >::const_iterator facesEnd
virtual void getOccluderProscenium(real proscenium[4])
vector< WShape * >::const_iterator currentShape
vector< WShape * >::const_iterator shapesEnd
vector< WFace * >::const_iterator currentFace
const GridHelpers::Transform & transform
vector< WShape * > & getWShapes()
Definition WEdge.h:1327
#define G(x, y, z)
void expandProscenium(real proscenium[4], const Polygon3r &polygon)
vector< Vec3r > enumerateVertices(const vector< WOEdge * > &fedges)
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
#define min(a, b)
Definition sort.c:32
float max