12#define BOX_GRID_LOGGING 0
34#ifdef WITH_CXX_GUARDEDALLOC
53#ifdef WITH_CXX_GUARDEDALLOC
54 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:BoxGrid:OccluderData")
64 explicit Cell() =
default;
74 vector<OccluderData *> faces;
106 bool testOccluder(
bool wantOccludee);
107 void markCurrentOccludeeCandidate(
real depth);
114 vector<OccluderData *>::iterator _current, _occludeeCandidate;
116#ifdef WITH_CXX_GUARDEDALLOC
117 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:BoxGrid:Iterator")
159 void getCellCoordinates(
const Vec3r &point,
uint &x,
uint &y);
164 uint _cellsX, _cellsY;
166 float _cellOrigin[2];
172#ifdef WITH_CXX_GUARDEDALLOC
173 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:BoxGrid")
179 _current = _cell->faces.begin();
180 while (_current != _cell->faces.end() && !testOccluder(
false)) {
187 if (_foundOccludee) {
190 std::cout <<
"\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth
194 _current = _occludeeCandidate;
200 std::cout <<
"\tStarting occludee search from current position" << std::endl;
204 while (_current != _cell->faces.end() && !testOccluder(
true)) {
209inline bool BoxGrid::Iterator::testOccluder(
bool wantOccludee)
212 if (_current == _cell->faces.end()) {
219 std::cout <<
"\tTesting occluder " << (*_current)->poly.getVertices()[0];
220 for (
uint i = 1; i < (*_current)->poly.getVertices().
size(); ++i) {
221 std::cout <<
", " << (*_current)->poly.getVertices()[i];
223 std::cout <<
" from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl;
228 if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) {
231 std::cout <<
"\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl;
234 _current = _cell->faces.end();
242 if ((*_current)->deepest < _target[2]) {
245 std::cout <<
"\t\tSkipping: shallower than target while looking for occludee" << std::endl;
252 if ((*_current)->shallowest > _target[2]) {
255 std::cout <<
"\t\tStopping: deeper than target while looking for occluder" << std::endl;
266 (*_current)->poly.getBBox(bbMin, bbMax);
267 if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] ||
268 _target[1] > bbMax[1])
272 std::cout <<
"\t\tSkipping: bounding box violation" << std::endl;
287 real depth = -(origin + (u * t))[2];
290 std::cout <<
"\t\tReporting depth of occluder/ee: " << depth;
293 if (depth > _target[2]) {
296 std::cout <<
" is deeper than target" << std::endl;
300 if (!_foundOccludee || _occludeeDepth > depth) {
301 markCurrentOccludeeCandidate(depth);
307 std::cout << std::endl;
315 if (_current != _cell->faces.end()) {
318 }
while (_current != _cell->faces.end() && !testOccluder(
false));
324 if (_current != _cell->faces.end()) {
327 }
while (_current != _cell->faces.end() && !testOccluder(
true));
333 return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2];
338 return _current != _cell->faces.end();
341inline void BoxGrid::Iterator::markCurrentOccludeeCandidate(
real depth)
345 std::cout <<
"\t\tFound occludeeCandidate at depth " << depth << std::endl;
348 _occludeeCandidate = _current;
349 _occludeeDepth = depth;
350 _foundOccludee =
true;
355 return (*_current)->face;
360 return &((*_current)->cameraSpacePolygon);
364 : poly(p), cameraSpacePolygon(source.getCameraSpacePolygon()), face(source.getWFace())
368 poly.getBBox(
min, max);
378 if (occluder ==
nullptr) {
383 faces.push_back(occluder);
393 poly.getBBox(bbMin, bbMax);
395 uint startX, startY, endX, endY;
396 getCellCoordinates(bbMin, startX, startY);
397 getCellCoordinates(bbMax, endX, endY);
399 for (
uint i = startX; i <= endX; ++i) {
400 for (
uint j = startY; j <= endY; ++j) {
401 if (_cells[i * _cellsY + j] !=
nullptr) {
402 _cells[i * _cellsY + j]->checkAndInsert(source, poly, occluder);
407 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.
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)
Polygon3r * getCameraSpacePolygon()
Iterator(BoxGrid &grid, Vec3r ¢er, real epsilon=1.0e-06)
void reportDepth(Vec3r origin, Vec3r u, real t)
void assignCells(OccluderSource &source, GridDensityProvider &density, ViewMap *viewMap)
const Vec3r & viewpoint() const
Cell * findCell(const Vec3r &point)
void distributePolygons(OccluderSource &source)
bool insertOccluder(OccluderSource &source, OccluderData *&occluder)
bool orthographicProjection() const
Polygon3r & getGridSpacePolygon()
local_group_size(16, 16) .push_constant(Type b
VecMat::Vec3< real > Vec3r
bool insideProscenium(const real proscenium[4], const Polygon3r &polygon)
Polygon3r cameraSpacePolygon
OccluderData(OccluderSource &source, Polygon3r &p)