Blender  V2.93
OccluderSource.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 <algorithm>
23 
24 #include "OccluderSource.h"
25 
26 #include "BKE_global.h"
27 
28 namespace Freestyle {
29 
30 OccluderSource::OccluderSource(const GridHelpers::Transform &t, WingedEdge &we)
31  : wingedEdge(we), valid(false), transform(t)
32 {
33  begin();
34 }
35 
37 
39 {
40  vector<Vec3r> vertices(GridHelpers::enumerateVertices((*currentFace)->getEdgeList()));
41  // This doesn't work, because our functor's polymorphism won't survive the copy:
42  // std::transform(vertices.begin(), vertices.end(), vertices.begin(), transform);
43  // so we have to do:
44  for (vector<Vec3r>::iterator i = vertices.begin(); i != vertices.end(); ++i) {
45  (*i) = transform(*i);
46  }
47  cachedPolygon = Polygon3r(vertices, transform((*currentFace)->GetNormal()));
48 }
49 
51 {
52  vector<WShape *> &wshapes = wingedEdge.getWShapes();
53  currentShape = wshapes.begin();
54  shapesEnd = wshapes.end();
55  valid = false;
56  if (currentShape != shapesEnd) {
57  vector<WFace *> &wFaces = (*currentShape)->GetFaceList();
58  currentFace = wFaces.begin();
59  facesEnd = wFaces.end();
60 
61  if (currentFace != facesEnd) {
63  valid = true;
64  }
65  }
66 }
67 
69 {
70  if (valid) {
71  ++currentFace;
72  while (currentFace == facesEnd) {
73  ++currentShape;
74  if (currentShape == shapesEnd) {
75  valid = false;
76  return false;
77  }
78 
79  vector<WFace *> &wFaces = (*currentShape)->GetFaceList();
80  currentFace = wFaces.begin();
81  facesEnd = wFaces.end();
82  }
84  return true;
85  }
86  return false;
87 }
88 
90 {
91  // Or:
92  // return currentShapes != shapesEnd && currentFace != facesEnd;
93  return valid;
94 }
95 
97 {
98  return valid ? *currentFace : nullptr;
99 }
100 
102 {
103  return Polygon3r(GridHelpers::enumerateVertices((*currentFace)->getEdgeList()),
104  (*currentFace)->GetNormal());
105 }
106 
108 {
109  return cachedPolygon;
110 }
111 
113 {
114  begin();
115  const Vec3r &initialPoint = cachedPolygon.getVertices()[0];
116  proscenium[0] = proscenium[1] = initialPoint[0];
117  proscenium[2] = proscenium[3] = initialPoint[1];
118  while (isValid()) {
120  next();
121  }
122  if (G.debug & G_DEBUG_FREESTYLE) {
123  cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
124  << ", " << proscenium[3] << ")" << endl;
125  }
126 }
127 
129 {
130  real area = 0.0;
131  unsigned numFaces = 0;
132  for (begin(); isValid(); next()) {
133  Vec3r min, max;
135  area += (max[0] - min[0]) * (max[1] - min[1]);
136  ++numFaces;
137  }
138  area /= numFaces;
139  return area;
140 }
141 
142 } /* namespace Freestyle */
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:140
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Class to define a cell grid surrounding the projected image of a scene.
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
const vector< Point > & getVertices() const
Definition: Polygon.h:81
void getBBox(Point &min, Point &max) const
Definition: Polygon.h:86
vector< WFace * >::const_iterator currentFace
vector< WFace * >::const_iterator facesEnd
virtual real averageOccluderArea()
virtual void getOccluderProscenium(real proscenium[4])
vector< WShape * >::const_iterator shapesEnd
vector< WShape * >::const_iterator currentShape
const GridHelpers::Transform & transform
vector< WShape * > & getWShapes()
Definition: WEdge.h:1369
void expandProscenium(real proscenium[4], const Polygon3r &polygon)
Definition: GridHelpers.h:166
vector< Vec3r > enumerateVertices(const vector< WOEdge * > &fedges)
Definition: GridHelpers.h:152
inherits from class Rep
Definition: AppCanvas.cpp:32
double real
Definition: Precision.h:26
static void area(int d1, int d2, int e1, int e2, float weights[2])
#define min(a, b)
Definition: sort.c:51
float max
#define G(x, y, z)