3 ms·
I'm also working on a linear octree (like quadtree but 3d) right now. An array sorted by Morton code is a quadtree/octree and an equally spaced kd-tree. Radix
by exDM69 4y ago
I'm also working on a linear octree (like quadtree but 3d) right now.
An array sorted by Morton code is a quadtree/octree and an equally spaced kd-tree.
Radix sorting can be used for sorting in linear time (and GPUs).
When looking at the Morton code, if the most significant bit is 0 then it is on the left side of the x=0 plane, and right side if the bit is 1. You can find the split position where the bit flips with binary search.
Then recurse to both halves using the next most significant bit which corresponds to the y=0 plane. Each level of recursion splits the space in two.
You could also get the splits "for free" from the histograms produced during radix sorting to reduce the number of binary searches.
This idea can be extended to AABBs instead of points by XORing the end point Morton codes and counting the leading zeros.
A lot of literature was written on this topic in the past 10-20 years for the purpose of building acceleration structures for Ray tracing on the GPU.