12#define SPHERICAL_GRID_LOGGING 0
34#ifdef WITH_CXX_GUARDEDALLOC
53#ifdef WITH_CXX_GUARDEDALLOC
54 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid:OccluderData")
64 explicit Cell() =
default;
74 vector<OccluderData *>
faces;
108 bool testOccluder(
bool wantOccludee);
109 void markCurrentOccludeeCandidate(
real depth);
116 vector<OccluderData *>::iterator _current, _occludeeCandidate;
118#ifdef WITH_CXX_GUARDEDALLOC
119 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid:Iterator")
133 SphericalGrid(
const SphericalGrid &other);
134 SphericalGrid &operator=(
const SphericalGrid &other);
166 uint _cellsX, _cellsY;
168 float _cellOrigin[2];
169 cellContainer _cells;
170 occluderContainer _faces;
174#ifdef WITH_CXX_GUARDEDALLOC
175 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid")
181 _current = _cell->faces.begin();
182 while (_current != _cell->faces.end() && !testOccluder(
false)) {
189 if (_foundOccludee) {
190#if SPHERICAL_GRID_LOGGING
192 std::cout <<
"\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth
196 _current = _occludeeCandidate;
200#if SPHERICAL_GRID_LOGGING
202 std::cout <<
"\tStarting occludee search from current position" << std::endl;
206 while (_current != _cell->faces.end() && !testOccluder(
true)) {
211inline bool SphericalGrid::Iterator::testOccluder(
bool wantOccludee)
214 if (_current == _cell->faces.end()) {
219#if SPHERICAL_GRID_LOGGING
221 std::cout <<
"\tTesting occluder " << (*_current)->poly.getVertices()[0];
222 for (
uint i = 1; i < (*_current)->poly.getVertices().
size(); ++i) {
223 std::cout <<
", " << (*_current)->poly.getVertices()[i];
225 std::cout <<
" from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl;
230 if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) {
231#if SPHERICAL_GRID_LOGGING
233 std::cout <<
"\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl;
236 _current = _cell->faces.end();
244 if ((*_current)->deepest < _target[2]) {
245#if SPHERICAL_GRID_LOGGING
247 std::cout <<
"\t\tSkipping: shallower than target while looking for occludee" << std::endl;
254 if ((*_current)->shallowest > _target[2]) {
255#if SPHERICAL_GRID_LOGGING
257 std::cout <<
"\t\tStopping: deeper than target while looking for occluder" << std::endl;
268 (*_current)->poly.getBBox(bbMin, bbMax);
269 if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] ||
270 _target[1] > bbMax[1])
272#if SPHERICAL_GRID_LOGGING
274 std::cout <<
"\t\tSkipping: bounding box violation" << std::endl;
291 real depth = (origin + u * t).
norm();
292#if SPHERICAL_GRID_LOGGING
294 std::cout <<
"\t\tReporting depth of occluder/ee: " << depth;
297 if (depth > _target[2]) {
298#if SPHERICAL_GRID_LOGGING
300 std::cout <<
" is deeper than target" << std::endl;
304 if (!_foundOccludee || _occludeeDepth > depth) {
305 markCurrentOccludeeCandidate(depth);
309#if SPHERICAL_GRID_LOGGING
311 std::cout << std::endl;
319 if (_current != _cell->faces.end()) {
322 }
while (_current != _cell->faces.end() && !testOccluder(
false));
328 if (_current != _cell->faces.end()) {
331 }
while (_current != _cell->faces.end() && !testOccluder(
true));
337 return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2];
342 return _current != _cell->faces.end();
345inline void SphericalGrid::Iterator::markCurrentOccludeeCandidate(
real depth)
347#if SPHERICAL_GRID_LOGGING
349 std::cout <<
"\t\tFound occludeeCandidate at depth " << depth << std::endl;
352 _occludeeCandidate = _current;
353 _occludeeDepth = depth;
354 _foundOccludee =
true;
359 return (*_current)->face;
364 return &((*_current)->cameraSpacePolygon);
378 for (
uint i = 0; i < 2; ++i) {
386inline void SphericalGrid::Cell::checkAndInsert(
OccluderSource &source,
391 if (occluder ==
nullptr) {
396 faces.push_back(occluder);
408 uint startX, startY, endX, endY;
409 getCellCoordinates(bbMin, startX, startY);
410 getCellCoordinates(bbMax, endX, endY);
412 for (
uint i = startX; i <= endX; ++i) {
413 for (
uint j = startY; j <= endY; ++j) {
414 if (_cells[i * _cellsY + j] !=
nullptr) {
415 _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder);
420 return occluder !=
nullptr;
A class to hold a bounding box.
Class to define a cell grid surrounding the projected image of a scene.
Class to define a cell grid surrounding the projected image of a scene.
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
Class to define a cell grid surrounding the projected image of a scene.
Simple RAII wrappers for std:: sequential containers.
Class to define a polygon.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
Classes to define a Winged Edge data structure.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
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)
local_group_size(16, 16) .push_constant(Type b
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)