How to get results efficiently out of an Octree/Quadtree?

Posted by Reveazure on Stack Overflow See other posts from Stack Overflow or by Reveazure
Published on 2010-06-16T17:34:03Z Indexed on 2010/06/16 17:52 UTC
Read the original article Hit count: 146

I am working on a piece of 3D software that has sometimes has to perform intersections between massive numbers of curves (sometimes ~100,000). The most natural way to do this is to do an N^2 bounding box check, and then those curves whose bounding boxes overlap get intersected.

I heard good things about octrees, so I decided to try implementing one to see if I would get improved performance.

Here's my design: Each octree node is implemented as a class with a list of subnodes and an ordered list of object indices.

When an object is being added, it's added to the lowest node that entirely contains the object, or some of that node's children if the object doesn't fill all of the children.

Now, what I want to do is retrieve all objects that share a tree node with a given object. To do this, I traverse all tree nodes, and if they contain the given index, I add all of their other indices to an ordered list.

This is efficient because the indices within each node are already ordered, so finding out if each index is already in the list is fast. However, the list ends up having to be resized, and this takes up most of the time in the algorithm. So what I need is some kind of tree-like data structure that will allow me to efficiently add ordered data, and also be efficient in memory.

Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Performance