12#define SPHERICAL_GRID_LOGGING 0
51 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid:OccluderData")
60 explicit Cell() =
default;
70 vector<OccluderData *>
faces;
104 bool testOccluder(
bool wantOccludee);
105 void markCurrentOccludeeCandidate(
real depth);
112 vector<OccluderData *>::iterator _current, _occludeeCandidate;
114 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid:Iterator")
127 SphericalGrid(
const SphericalGrid &other);
128 SphericalGrid &operator=(
const SphericalGrid &other);
160 uint _cellsX, _cellsY;
162 float _cellOrigin[2];
163 cellContainer _cells;
164 occluderContainer _faces;
168 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:SphericalGrid")
173 _current = _cell->faces.begin();
174 while (_current != _cell->faces.end() && !testOccluder(
false)) {
181 if (_foundOccludee) {
182#if SPHERICAL_GRID_LOGGING
184 std::cout <<
"\tStarting occludee search from occludeeCandidate at depth " << _occludeeDepth
188 _current = _occludeeCandidate;
192#if SPHERICAL_GRID_LOGGING
194 std::cout <<
"\tStarting occludee search from current position" << std::endl;
198 while (_current != _cell->faces.end() && !testOccluder(
true)) {
203inline bool SphericalGrid::Iterator::testOccluder(
bool wantOccludee)
206 if (_current == _cell->faces.end()) {
211#if SPHERICAL_GRID_LOGGING
213 std::cout <<
"\tTesting occluder " << (*_current)->poly.getVertices()[0];
214 for (
uint i = 1;
i < (*_current)->poly.getVertices().
size(); ++
i) {
215 std::cout <<
", " << (*_current)->poly.getVertices()[
i];
217 std::cout <<
" from shape " << (*_current)->face->GetVertex(0)->shape()->GetId() << std::endl;
222 if (_foundOccludee && (*_current)->shallowest > _occludeeDepth) {
223#if SPHERICAL_GRID_LOGGING
225 std::cout <<
"\t\tAborting: shallowest > occludeeCandidate->deepest" << std::endl;
228 _current = _cell->faces.end();
236 if ((*_current)->deepest < _target[2]) {
237#if SPHERICAL_GRID_LOGGING
239 std::cout <<
"\t\tSkipping: shallower than target while looking for occludee" << std::endl;
246 if ((*_current)->shallowest > _target[2]) {
247#if SPHERICAL_GRID_LOGGING
249 std::cout <<
"\t\tStopping: deeper than target while looking for occluder" << std::endl;
260 (*_current)->poly.getBBox(bbMin, bbMax);
261 if (_target[0] < bbMin[0] || _target[0] > bbMax[0] || _target[1] < bbMin[1] ||
262 _target[1] > bbMax[1])
264#if SPHERICAL_GRID_LOGGING
266 std::cout <<
"\t\tSkipping: bounding box violation" << std::endl;
283 real depth = (origin + u * t).
norm();
284#if SPHERICAL_GRID_LOGGING
286 std::cout <<
"\t\tReporting depth of occluder/ee: " << depth;
289 if (depth > _target[2]) {
290#if SPHERICAL_GRID_LOGGING
292 std::cout <<
" is deeper than target" << std::endl;
296 if (!_foundOccludee || _occludeeDepth > depth) {
297 markCurrentOccludeeCandidate(depth);
301#if SPHERICAL_GRID_LOGGING
303 std::cout << std::endl;
311 if (_current != _cell->faces.end()) {
314 }
while (_current != _cell->faces.end() && !testOccluder(
false));
320 if (_current != _cell->faces.end()) {
323 }
while (_current != _cell->faces.end() && !testOccluder(
true));
329 return _current != _cell->faces.end() && (*_current)->shallowest <= _target[2];
334 return _current != _cell->faces.end();
337inline void SphericalGrid::Iterator::markCurrentOccludeeCandidate(
real depth)
339#if SPHERICAL_GRID_LOGGING
341 std::cout <<
"\t\tFound occludeeCandidate at depth " << depth << std::endl;
344 _occludeeCandidate = _current;
345 _occludeeDepth = depth;
346 _foundOccludee =
true;
351 return (*_current)->face;
356 return &((*_current)->cameraSpacePolygon);
378inline void SphericalGrid::Cell::checkAndInsert(
OccluderSource &source,
383 if (occluder ==
nullptr) {
388 faces.push_back(occluder);
400 uint startX, startY, endX, endY;
401 getCellCoordinates(bbMin, startX, startY);
402 getCellCoordinates(bbMax, endX, endY);
404 for (
uint i = startX;
i <= endX; ++
i) {
405 for (
uint j = startY; j <= endY; ++j) {
406 if (_cells[
i * _cellsY + j] !=
nullptr) {
407 _cells[
i * _cellsY + j]->checkAndInsert(source, poly, occluder);
412 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)
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)
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)