Permalink
Browse files

rework in VMap BIH generation

  • Loading branch information...
zgn1988 committed Dec 14, 2016
1 parent 6ad2f7a commit 73ea02dab63ff786325631b793b9d6bdfddb0ad4
Showing with 14 additions and 14 deletions.
  1. +14 −14 src/collision/BoundingIntervalHierarchy.cpp
@@ -41,8 +41,7 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
return;
}
// calculate extents
int axis = -1, prevAxis;
int middle;
int axis = -1, prevAxis, rightOrig;
float clipL = G3D::fnan(), clipR = G3D::fnan(), prevClip = G3D::fnan();
float split = G3D::fnan(), prevSplit;
bool wasLeft = true;
@@ -68,10 +67,10 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
// partition L/R subsets
clipL = -G3D::inf();
clipR = G3D::inf();
rightOrig = right; // save this for later
float nodeL = G3D::inf();
float nodeR = -G3D::inf();
middle = right;
for (int i = left; i <= middle;)
for (int i = left; i <= right;)
{
int obj = dat.indices[i];
float minb = dat.primBound[obj].low()[axis];
@@ -88,9 +87,9 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
{
// move to the right most
int t = dat.indices[i];
dat.indices[i] = dat.indices[middle];
dat.indices[middle] = t;
middle--;
dat.indices[i] = dat.indices[right];
dat.indices[right] = t;
right--;
if (clipR > minb)
clipR = minb;
}
@@ -119,12 +118,12 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
// update nodebox and recurse
nodeBox.lo[axis] = nodeL;
nodeBox.hi[axis] = nodeR;
subdivide(left, right, tempTree, dat, gridBox, nodeBox, nextIndex, depth + 1, stats);
subdivide(left, rightOrig, tempTree, dat, gridBox, nodeBox, nextIndex, depth + 1, stats);
return;
}
}
// ensure we are making progress in the subdivision
if (middle == right)
if (right == rightOrig)
{
// all left
if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) {
@@ -143,7 +142,7 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
gridBox.hi[axis] = split;
prevClip = G3D::fnan();
}
else if (left > middle)
else if (left > right)
{
// all right
if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) {
@@ -152,6 +151,7 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
createNode(tempTree, nodeIndex, left, right);
return;
}
right = rightOrig;
if (clipR >= split) {
// keep looping on right half
gridBox.lo[axis] = split;
@@ -201,8 +201,8 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
// compute index of child nodes
int nextIndex = tempTree.size();
// allocate left node
int nl = middle - left + 1;
int nr = right - (middle + 1) + 1;
int nl = right - left + 1;
int nr = rightOrig - (right + 1) + 1;
if (nl > 0) {
tempTree.push_back(0);
tempTree.push_back(0);
@@ -228,11 +228,11 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
nodeBoxR.lo[axis] = clipR;
// recurse
if (nl > 0)
subdivide(left, middle, tempTree, dat, gridBoxL, nodeBoxL, nextIndex, depth + 1, stats);
subdivide(left, right, tempTree, dat, gridBoxL, nodeBoxL, nextIndex, depth + 1, stats);
else
stats.updateLeaf(depth + 1, 0);
if (nr > 0)
subdivide(middle + 1, right, tempTree, dat, gridBoxR, nodeBoxR, nextIndex + 3, depth + 1, stats);
subdivide(right + 1, rightOrig, tempTree, dat, gridBoxR, nodeBoxR, nextIndex + 3, depth + 1, stats);
else
stats.updateLeaf(depth + 1, 0);
}

0 comments on commit 73ea02d

Please sign in to comment.