24 #define SPHERICAL_GRID_LOGGING 0
36 #include "../geometry/BBox.h"
37 #include "../geometry/GridHelpers.h"
38 #include "../geometry/Polygon.h"
40 #include "../system/PointerSequence.h"
42 #include "../winged_edge/WEdge.h"
46 #ifdef WITH_CXX_GUARDEDALLOC
65 #ifdef WITH_CXX_GUARDEDALLOC
66 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid:OccluderData")
76 explicit Cell() =
default;
86 vector<OccluderData *>
faces;
119 bool testOccluder(
bool wantOccludee);
120 void markCurrentOccludeeCandidate(
real depth);
127 vector<OccluderData *>::iterator _current, _occludeeCandidate;
129 #ifdef WITH_CXX_GUARDEDALLOC
130 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid:Iterator")
172 void getCellCoordinates(
const Vec3r &point,
unsigned &
x,
unsigned &
y);
177 unsigned _cellsX, _cellsY;
179 float _cellOrigin[2];
185 #ifdef WITH_CXX_GUARDEDALLOC
186 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid")
192 _current = _cell->faces.begin();
193 while (_current != _cell->faces.end() && !testOccluder(
false)) {
200 if (_foundOccludee) {
201 #if SPHERICAL_GRID_LOGGING
203 std::cout <<
"\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth
207 _current = _occludeeCandidate;
211 #if SPHERICAL_GRID_LOGGING
213 std::cout <<
"\tStarting occludee search from current position" << std::endl;
217 while (_current != _cell->faces.end() && !testOccluder(
true)) {
222 inline bool SphericalGrid::Iterator::testOccluder(
bool wantOccludee)
225 if (_current == _cell->faces.end()) {
230 #if SPHERICAL_GRID_LOGGING
232 std::cout <<
"\tTesting occluder " << (*_current)->poly.getVertices()[0];
233 for (
unsigned int i = 1; i < (*_current)->poly.getVertices().
size(); ++i) {
234 std::cout <<
", " << (*_current)->poly.getVertices()[i];
236 std::cout <<
" from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl;
241 if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) {
242 #if SPHERICAL_GRID_LOGGING
244 std::cout <<
"\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl;
247 _current = _cell->faces.end();
255 if ((*_current)->deepest < _target[2]) {
256 #if SPHERICAL_GRID_LOGGING
258 std::cout <<
"\t\tSkipping: shallower than target while looking for occludee" << std::endl;
265 if ((*_current)->shallowest > _target[2]) {
266 #if SPHERICAL_GRID_LOGGING
268 std::cout <<
"\t\tStopping: deeper than target while looking for occluder" << std::endl;
279 (*_current)->poly.getBBox(bbMin, bbMax);
280 if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] ||
281 _target[1] > bbMax[1]) {
282 #if SPHERICAL_GRID_LOGGING
284 std::cout <<
"\t\tSkipping: bounding box violation" << std::endl;
302 #if SPHERICAL_GRID_LOGGING
304 std::cout <<
"\t\tReporting depth of occluder/ee: " << depth;
307 if (depth > _target[2]) {
308 #if SPHERICAL_GRID_LOGGING
310 std::cout <<
" is deeper than target" << std::endl;
314 if (!_foundOccludee || _occludeeDepth > depth) {
315 markCurrentOccludeeCandidate(depth);
319 #if SPHERICAL_GRID_LOGGING
321 std::cout << std::endl;
329 if (_current != _cell->faces.end()) {
332 }
while (_current != _cell->faces.end() && !testOccluder(
false));
338 if (_current != _cell->faces.end()) {
341 }
while (_current != _cell->faces.end() && !testOccluder(
true));
347 return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2];
352 return _current != _cell->faces.end();
355 inline void SphericalGrid::Iterator::markCurrentOccludeeCandidate(
real depth)
357 #if SPHERICAL_GRID_LOGGING
359 std::cout <<
"\t\tFound occludeeCandidate at depth " << depth << std::endl;
362 _occludeeCandidate = _current;
363 _occludeeDepth = depth;
364 _foundOccludee =
true;
369 return (*_current)->face;
374 return &((*_current)->cameraSpacePolygon);
378 : poly(p), cameraSpacePolygon(source.getCameraSpacePolygon()), face(source.getWFace())
388 for (
unsigned int i = 0; i < 2; ++i) {
396 inline void SphericalGrid::Cell::checkAndInsert(
OccluderSource &source,
401 if (occluder ==
NULL) {
406 faces.push_back(occluder);
418 unsigned startX, startY, endX, endY;
419 getCellCoordinates(bbMin, startX, startY);
420 getCellCoordinates(bbMax, endX, endY);
422 for (
unsigned int i = startX; i <= endX; ++i) {
423 for (
unsigned int j = startY; j <= endY; ++j) {
424 if (_cells[i * _cellsY + j] !=
NULL) {
425 _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder);
430 return occluder !=
NULL;
NSNotificationCenter * center
_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 y
_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.
Read Guarded memory(de)allocation.
Class to define a cell grid surrounding the projected image of a scene.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
const vector< Point > & getVertices() const
void getBBox(Point &min, Point &max) const
Polygon3r & getGridSpacePolygon()
void reportDepth(Vec3r origin, Vec3r u, real t)
Iterator(SphericalGrid &grid, Vec3r ¢er, real epsilon=1.0e-06)
Polygon3r * getCameraSpacePolygon()
void assignCells(OccluderSource &source, GridDensityProvider &density, ViewMap *viewMap)
const Vec3r & viewpoint() const
bool orthographicProjection() const
Cell * findCell(const Vec3r &point)
void distributePolygons(OccluderSource &source)
bool insertOccluder(OccluderSource &source, OccluderData *&occluder)
VecMat::Vec3< real > Vec3r
real distancePointToPolygon(const Vec3r &point, const Polygon3r &poly)
bool insideProscenium(const real proscenium[4], const Polygon3r &polygon)
Polygon3r cameraSpacePolygon
OccluderData(OccluderSource &source, Polygon3r &p)