void UniformGrid::refine(KdTree * tree) { int level1; float hh; Vector3F sample, subs; int u; unsigned k; BoundingBox box; m_cellsToRefine->begin(); while (!m_cellsToRefine->end()) { sdb::CellValue * parentCell = m_cellsToRefine->value(); if(parentCell->visited > 0) { k = m_cellsToRefine->key(); level1 = parentCell->level + 1; hh = cellSizeAtLevel(level1) * .5f; sample = cellCenter(k); removeCell(k); for(u = 0; u < 8; u++) { subs = sample + Vector3F(hh * Cell8ChildOffset[u][0], hh * Cell8ChildOffset[u][1], hh * Cell8ChildOffset[u][2]); box.setMin(subs.x - hh, subs.y - hh, subs.z - hh); box.setMax(subs.x + hh, subs.y + hh, subs.z + hh); if(tree->intersectBox(box)) addCell(subs, level1); } } m_cellsToRefine->next(); } }
void BccLattice::prepareTetrahedron() { const float hh = cellSizeAtLevel(11); NodeCenterOffset.set(hh, hh, hh); const unsigned noctahedron = m_greenEdges->size(); m_tetrahedrons = new Tetrahedron[noctahedron * 4]; m_numTetrahedrons = 0; }
void BccLattice::drawVisitedNodes(GeoDrawer * drawer) { drawer->setWired(0); glColor3f(0.1f, 0.2f, 0.5f); sdb::CellHash * latticeNode = cells(); float h = cellSizeAtLevel(11); Vector3F l; latticeNode->begin(); while(!latticeNode->end()) { if(latticeNode->value()->visited) { l = nodeCenter(latticeNode->key()); drawer->cube(l, h); } latticeNode->next(); } }
void UniformGrid::create(KdTree * tree, int maxLevel) { m_maxLevel = maxLevel; std::cout<<"\n UniformGrid create max level "<<maxLevel; // start at 8 cells per axis int level = 3; const int dim = 1<<level; int i, j, k; const float h = cellSizeAtLevel(level); const float hh = h * .5f; const Vector3F ori = origin() + Vector3F(hh, hh, hh); Vector3F sample; BoundingBox box; for(k=0; k < dim; k++) { for(j=0; j < dim; j++) { for(i=0; i < dim; i++) { sample = ori + Vector3F(h* (float)i, h* (float)j, h* (float)k); box.setMin(sample.x - hh, sample.y - hh, sample.z - hh); box.setMax(sample.x + hh, sample.y + hh, sample.z + hh); if(tree->intersectBox(&box)) addCell(sample, level); } } } bool needRefine = tagCellsToRefine(tree); while(needRefine && level < maxLevel) { std::cout<<"\n level"<<level<<" n cell "<<numCells(); refine(tree); level++; if(level < maxLevel) needRefine = tagCellsToRefine(tree); } m_cellsToRefine->clear(); std::cout<<"\n level"<<level<<" n cell "<<numCells(); }