12#define BOX_GRID_LOGGING 0
51 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:BoxGrid:OccluderData")
60 explicit Cell() =
default;
70 vector<OccluderData *>
faces;
102 bool testOccluder(
bool wantOccludee);
103 void markCurrentOccludeeCandidate(
real depth);
110 vector<OccluderData *>::iterator _current, _occludeeCandidate;
112 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:BoxGrid:Iterator")
124 BoxGrid(
const BoxGrid &other);
125 BoxGrid &operator=(
const BoxGrid &other);
158 uint _cellsX, _cellsY;
160 float _cellOrigin[2];
161 cellContainer _cells;
162 occluderContainer _faces;
166 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:BoxGrid")
171 _current = _cell->faces.begin();
172 while (_current != _cell->faces.end() && !testOccluder(
false)) {
179 if (_foundOccludee) {
182 std::cout <<
"\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth
186 _current = _occludeeCandidate;
192 std::cout <<
"\tStarting occludee search from current position" << std::endl;
196 while (_current != _cell->faces.end() && !testOccluder(
true)) {
201inline bool BoxGrid::Iterator::testOccluder(
bool wantOccludee)
204 if (_current == _cell->faces.end()) {
211 std::cout <<
"\tTesting occluder " << (*_current)->poly.getVertices()[0];
212 for (
uint i = 1;
i < (*_current)->poly.getVertices().
size(); ++
i) {
213 std::cout <<
", " << (*_current)->poly.getVertices()[
i];
215 std::cout <<
" from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl;
220 if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) {
223 std::cout <<
"\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl;
226 _current = _cell->faces.end();
234 if ((*_current)->deepest < _target[2]) {
237 std::cout <<
"\t\tSkipping: shallower than target while looking for occludee" << std::endl;
244 if ((*_current)->shallowest > _target[2]) {
247 std::cout <<
"\t\tStopping: deeper than target while looking for occluder" << std::endl;
258 (*_current)->poly.getBBox(bbMin, bbMax);
259 if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] ||
260 _target[1] > bbMax[1])
264 std::cout <<
"\t\tSkipping: bounding box violation" << std::endl;
279 real depth = -(origin + (u * t))[2];
282 std::cout <<
"\t\tReporting depth of occluder/ee: " << depth;
285 if (depth > _target[2]) {
288 std::cout <<
" is deeper than target" << std::endl;
292 if (!_foundOccludee || _occludeeDepth > depth) {
293 markCurrentOccludeeCandidate(depth);
299 std::cout << std::endl;
307 if (_current != _cell->faces.end()) {
310 }
while (_current != _cell->faces.end() && !testOccluder(
false));
316 if (_current != _cell->faces.end()) {
319 }
while (_current != _cell->faces.end() && !testOccluder(
true));
325 return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2];
330 return _current != _cell->faces.end();
333inline void BoxGrid::Iterator::markCurrentOccludeeCandidate(
real depth)
337 std::cout <<
"\t\tFound occludeeCandidate at depth " << depth << std::endl;
340 _occludeeCandidate = _current;
341 _occludeeDepth = depth;
342 _foundOccludee =
true;
347 return (*_current)->face;
352 return &((*_current)->cameraSpacePolygon);
370 if (occluder ==
nullptr) {
375 faces.push_back(occluder);
387 uint startX, startY, endX, endY;
388 getCellCoordinates(bbMin, startX, startY);
389 getCellCoordinates(bbMax, endX, endY);
391 for (
uint i = startX;
i <= endX; ++
i) {
392 for (
uint j = startY; j <= endY; ++j) {
393 if (_cells[
i * _cellsY + j] !=
nullptr) {
394 _cells[
i * _cellsY + j]->checkAndInsert(source, poly, occluder);
399 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
void getBBox(Point &min, Point &max) const
Polygon3r & getGridSpacePolygon()
VecMat::Vec3< real > Vec3r
bool insideProscenium(const real proscenium[4], const Polygon3r &polygon)
Polygon3r cameraSpacePolygon
OccluderData(OccluderSource &source, Polygon3r &p)