31void SphericalGrid::Cell::setDimensions(real x, real y, real sizeX, real sizeY)
35 boundary[1] = x + sizeX +
epsilon;
37 boundary[3] = y + sizeY +
epsilon;
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);
59 _cell = grid.findCell(_target);
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;
108 _cellSize = density.cellSize();
109 _cellsX = density.cellsX();
110 _cellsY = density.cellsY();
111 _cellOrigin[0] = density.cellOrigin(0);
112 _cellOrigin[1] = density.cellOrigin(1);
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()) {
130 Vec3r point = SphericalGrid::Transform::sphericalProjection((*f)->center3d());
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];
217Vec3r SphericalGrid::Transform::operator()(
const Vec3r &point)
const
222Vec3r SphericalGrid::Transform::sphericalProjection(
const Vec3r &
M)
226 newPoint[0] = ::atan(
M[0] /
M[2]);
227 newPoint[1] = ::atan(
M[1] /
M[2]);
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)
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()
local_group_size(16, 16) .push_constant(Type b
ccl_device_inline float2 floor(const float2 a)
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.