46 stats.updateLeaf(depth, right -
left + 1);
51 int axis = -1, prevAxis, rightOrig;
61 if (d.x < 0 || d.y < 0 || d.z < 0)
62 throw std::logic_error(
"negative node extents");
63 for (
int i = 0; i < 3; i++)
65 if (nodeBox.
hi[i] < gridBox.
lo[i] || nodeBox.
lo[i] > gridBox.
hi[i])
68 throw std::logic_error(
"invalid node overlap");
72 axis = d.primaryAxis();
73 split = 0.5f * (gridBox.
lo[axis] + gridBox.
hi[axis]);
80 for (
int i =
left; i <= right;)
82 int obj = dat.indices[i];
83 float minb = dat.primBound[obj].low()[axis];
84 float maxb = dat.primBound[obj].high()[axis];
85 float center = (minb + maxb) * 0.5f;
96 int t = dat.indices[i];
97 dat.indices[i] = dat.indices[right];
98 dat.indices[right] = t;
107 if (nodeL > nodeBox.
lo[axis] && nodeR < nodeBox.
hi[axis])
109 float nodeBoxW = nodeBox.
hi[axis] - nodeBox.
lo[axis];
110 float nodeNewW = nodeR - nodeL;
112 if (1.3f * nodeNewW < nodeBoxW)
115 int nextIndex = tempTree.size();
117 tempTree.push_back(0);
118 tempTree.push_back(0);
119 tempTree.push_back(0);
122 tempTree[nodeIndex + 0] = (axis << 30) | (1 << 29) | nextIndex;
126 nodeBox.
lo[axis] = nodeL;
127 nodeBox.
hi[axis] = nodeR;
128 subdivide(
left, rightOrig, tempTree, dat, gridBox, nodeBox, nextIndex, depth + 1, stats);
133 if (right == rightOrig)
136 if (prevAxis == axis &&
G3D::fuzzyEq(prevSplit, split)) {
138 stats.updateLeaf(depth, right -
left + 1);
142 if (clipL <= split) {
144 gridBox.
hi[axis] = split;
149 gridBox.
hi[axis] = split;
152 else if (
left > right)
155 if (prevAxis == axis &&
G3D::fuzzyEq(prevSplit, split)) {
157 stats.updateLeaf(depth, right -
left + 1);
162 if (clipR >= split) {
164 gridBox.
lo[axis] = split;
169 gridBox.
lo[axis] = split;
175 if (prevAxis != -1 && !
isnan(prevClip))
179 int nextIndex = tempTree.size();
181 tempTree.push_back(0);
182 tempTree.push_back(0);
183 tempTree.push_back(0);
188 tempTree[nodeIndex + 0] = (prevAxis << 30) | nextIndex;
195 tempTree[nodeIndex + 0] = (prevAxis << 30) | (nextIndex - 3);
201 stats.updateLeaf(depth, 0);
203 nodeIndex = nextIndex;
209 int nextIndex = tempTree.size();
211 int nl = right -
left + 1;
212 int nr = rightOrig - (right + 1) + 1;
214 tempTree.push_back(0);
215 tempTree.push_back(0);
216 tempTree.push_back(0);
221 tempTree.push_back(0);
222 tempTree.push_back(0);
223 tempTree.push_back(0);
227 tempTree[nodeIndex + 0] = (axis << 30) | nextIndex;
231 AABound gridBoxL(gridBox), gridBoxR(gridBox);
232 AABound nodeBoxL(nodeBox), nodeBoxR(nodeBox);
233 gridBoxL.hi[axis] = gridBoxR.lo[axis] = split;
234 nodeBoxL.hi[axis] = clipL;
235 nodeBoxR.lo[axis] = clipR;
238 subdivide(left, right, tempTree, dat, gridBoxL, nodeBoxL, nextIndex, depth + 1, stats);
240 stats.updateLeaf(depth + 1, 0);
242 subdivide(right + 1, rightOrig, tempTree, dat, gridBoxR, nodeBoxR, nextIndex + 3, depth + 1, stats);
244 stats.updateLeaf(depth + 1, 0);
float finf()
Definition: g3dmath.cpp:71
G3D::Vector3 lo
Definition: BoundingIntervalHierarchy.h:60
float fnan()
Definition: g3dmath.cpp:82
Definition: BoundingIntervalHierarchy.h:58
#define isnan
Definition: BoundingIntervalHierarchy.cpp:24
static uint32 floatToRawIntBits(float f)
Definition: BoundingIntervalHierarchy.h:36
T max(const T &x, const T &y)
Definition: g3dmath.h:320
T min(const T &x, const T &y)
Definition: g3dmath.h:305
G3D::Vector3 hi
Definition: BoundingIntervalHierarchy.h:60
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
void createNode(std::vector< uint32 > &tempTree, int nodeIndex, uint32 left, uint32 right) const
Definition: BoundingIntervalHierarchy.h:390
void subdivide(int left, int right, std::vector< uint32 > &tempTree, buildData &dat, AABound &gridBox, AABound &nodeBox, int nodeIndex, int depth, BuildStats &stats)
Definition: BoundingIntervalHierarchy.cpp:41
#define MAX_STACK_SIZE
Definition: BoundingIntervalHierarchy.h:34
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857