31void BoxGrid::Cell::setDimensions(real x, real y, real sizeX, real sizeY)
35 boundary[1] = x + sizeX +
epsilon;
37 boundary[3] = y + sizeY +
epsilon;
40bool BoxGrid::Cell::compareOccludersByShallowestPoint(
const BoxGrid::OccluderData *a,
41 const BoxGrid::OccluderData *
b)
43 return a->shallowest <
b->shallowest;
46void BoxGrid::Cell::indexPolygons()
49 sort(faces.begin(), faces.end(), compareOccludersByShallowestPoint);
56 : _target(grid.transform(center)), _foundOccludee(
false)
59 _cell = grid.findCell(_target);
62 cout <<
"Searching for occluders of edge centered at " << _target <<
" in cell ["
63 << 1_cell->boundary[0] <<
", " << _cell->boundary[1] <<
", " << _cell->boundary[2] <<
", "
64 << _cell->boundary[3] <<
"] (" << _cell->faces.size() <<
" occluders)" << endl;
69 _current = _cell->faces.begin();
84 cout <<
"Generate Cell structure" << endl;
90 cout <<
"Distribute occluders" << endl;
96 cout <<
"Reorganize cells" << endl;
101 cout <<
"Ready to use BoxGrid" << endl;
111 _cellSize = density.cellSize();
112 _cellsX = density.cellsX();
113 _cellsY = density.cellsY();
114 _cellOrigin[0] = density.cellOrigin(0);
115 _cellOrigin[1] = density.cellOrigin(1);
117 cout <<
"Using " << _cellsX <<
"x" << _cellsY <<
" cells of size " << _cellSize <<
" square."
119 cout <<
"Cell origin: " << _cellOrigin[0] <<
", " << _cellOrigin[1] << endl;
123 _cells.resize(_cellsX * _cellsY);
124 for (cellContainer::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) {
130 for (ViewMap::fedges_container::iterator f = fedges.begin(), fend = fedges.end(); f != fend; ++f)
132 if ((*f)->isInImage()) {
135 getCellCoordinates(point, i, j);
136 if (_cells[i * _cellsY + j] ==
nullptr) {
140 x = _cellOrigin[0] + _cellSize * i;
143 y = _cellOrigin[1] + _cellSize * j;
147 Cell *
b = _cells[i * _cellsY + j] =
new Cell();
148 b->setDimensions(x, y, width, height);
157 ulong nKeptFaces = 0;
164 _faces.push_back(occluder);
179 cout <<
"Distributed " << nFaces <<
" occluders. Retained " << nKeptFaces <<
"." << endl;
186 for (vector<Cell *>::iterator i = _cells.begin(), end = _cells.end(); i != end; ++i) {
188 (*i)->indexPolygons();
193void BoxGrid::getCellCoordinates(
const Vec3r &point,
uint &x,
uint &y)
195 x =
min(_cellsX - 1,
uint(
floor(
max(
double(0.0f), point[0] - _cellOrigin[0]) / _cellSize)));
196 y =
min(_cellsY - 1,
uint(
floor(
max(
double(0.0f), point[1] - _cellOrigin[1]) / _cellSize)));
202 getCellCoordinates(point, x, y);
203 return _cells[x * _cellsY +
y];
221Vec3r BoxGrid::Transform::operator()(
const Vec3r &point)
const
223 return Vec3r(point[0], point[1], -point[2]);
Class to define a cell grid surrounding the projected image of a scene.
static DBVT_INLINE btDbvtNode * sort(btDbvtNode *n, btDbvtNode *&r)
Iterator(BoxGrid &grid, Vec3r ¢er, real epsilon=1.0e-06)
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
vector< FEdge * > fedges_container
fedges_container & FEdges()
local_group_size(16, 16) .push_constant(Type b
ccl_device_inline float2 floor(const float2 a)
VecMat::Vec3< real > Vec3r
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.