40bool SphericalGrid::Cell::compareOccludersByShallowestPoint(
const SphericalGrid::OccluderData *
a,
41 const SphericalGrid::OccluderData *
b)
43 return a->shallowest <
b->shallowest;
46void SphericalGrid::Cell::indexPolygons()
49 sort(
faces.begin(),
faces.end(), compareOccludersByShallowestPoint);
56 : _target(SphericalGrid::
Transform::sphericalProjection(center)), _foundOccludee(
false)
60#if SPHERICAL_GRID_LOGGING
62 cout <<
"Searching for occluders of edge centered at " << _target <<
" in cell ["
63 << _cell->boundary[0] <<
", " << _cell->boundary[1] <<
", " << _cell->boundary[2] <<
", "
64 << _cell->boundary[3] <<
"] (" << _cell->faces.size() <<
" occluders)" << endl;
69 _current = _cell->faces.begin();
83 cout <<
"Generate Cell structure" << endl;
88 cout <<
"Distribute occluders" << endl;
93 cout <<
"Reorganize cells" << endl;
98 cout <<
"Ready to use SphericalGrid" << endl;
109 _cellsX = density.
cellsX();
110 _cellsY = density.
cellsY();
114 cout <<
"Using " << _cellsX <<
"x" << _cellsY <<
" cells of size " << _cellSize <<
" square."
116 cout <<
"Cell origin: " << _cellOrigin[0] <<
", " << _cellOrigin[1] << endl;
120 _cells.resize(_cellsX * _cellsY);
121 for (cellContainer::iterator
i = _cells.begin(), end = _cells.end();
i != end; ++
i) {
127 for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; ++f)
129 if ((*f)->isInImage()) {
132 getCellCoordinates(point,
i, j);
133 if (_cells[
i * _cellsY + j] ==
nullptr) {
137 x = _cellOrigin[0] + _cellSize *
i;
140 y = _cellOrigin[1] + _cellSize * j;
144 Cell *
b = _cells[
i * _cellsY + j] =
new Cell();
145 b->setDimensions(
x,
y, width, height);
154 ulong nKeptFaces = 0;
161 _faces.push_back(occluder);
175 cout <<
"Distributed " << nFaces <<
" occluders. Retained " << nKeptFaces <<
"." << endl;
182 for (vector<Cell *>::iterator
i = _cells.begin(), end = _cells.end();
i != end; ++
i) {
184 (*i)->indexPolygons();
189void SphericalGrid::getCellCoordinates(
const Vec3r &point,
uint &
x,
uint &
y)
191 x =
min(_cellsX - 1,
uint(
floor(
max(
double(0.0f), point[0] - _cellOrigin[0]) / _cellSize)));
192 y =
min(_cellsY - 1,
uint(
floor(
max(
double(0.0f), point[1] - _cellOrigin[1]) / _cellSize)));
198 getCellCoordinates(point,
x,
y);
199 return _cells[
x * _cellsY +
y];
228 newPoint[2] =
::sqrt(
M[0] *
M[0] +
M[1] *
M[1] +
M[2] *
M[2]);
Class to define a cell grid surrounding the projected image of a scene.
static DBVT_INLINE btDbvtNode * sort(btDbvtNode *n, btDbvtNode *&r)
float cellOrigin(int index)
Iterator(SphericalGrid &grid, Vec3r ¢er, real epsilon=1.0e-06)
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)
vector< FEdge * > fedges_container
fedges_container & FEdges()
VecMat::Vec3< real > Vec3r
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.