MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / BuildTree

Method BuildTree

GTE/Mathematics/BVTree.h:181–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179
180 private:
181 void BuildTree(size_t depth, size_t nodeIndex, size_t i0, size_t i1)
182 {
183 auto& node = mNodes[nodeIndex];
184 node.minIndex = i0;
185 node.maxIndex = i1;
186
187 if (i0 < i1)
188 {
189 // The node is interior. Compute a bounding volume for the
190 // primitives' vertices.
191 ComputeInteriorBoundingVolume(i0, i1, node.boundingVolume);
192 if (depth == mHeight)
193 {
194 // The user-specified height has been reached. Do not
195 // continue the recursion past this node.
196 return;
197 }
198
199 // The BoundingVolume type provides a function to access a
200 // splitting axis, typically one in a direction of largest
201 // distribution of primitive vertices. Use the splitting axis
202 // to partition the centroids of the primitives into two
203 // subsets, one for the left child and one for the right
204 // child. The subsets have numbers of elements that differ by
205 // at most 1, so the tree is balanced.
206 size_t j0{}, j1{};
207 SplitPoints(i0, i1, node.boundingVolume, j0, j1);
208
209 // Recurse on the two children.
210 node.leftChild = 2 * nodeIndex + 1;
211 node.rightChild = node.leftChild + 1;
212 BuildTree(depth + 1, node.leftChild, i0, j0);
213 BuildTree(depth + 1, node.rightChild, j1, i1);
214 }
215 else // i0 = i1
216 {
217 // The node is a leaf. Compute a bounding volume for a single
218 // primitive's vertices.
219 ComputeLeafBoundingVolume(i0, node.boundingVolume);
220 }
221 }
222
223 struct ProjectionInfo
224 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected