This algorithm is really as simple as it seems. Two efficiency issues are also considered within the recursion. After building the geometrically-refined octree grid, there are two more steps necessary to produce a grid suitable for computation. As mentioned in Section , there are only two key algorithms for operating on an octree once it has been created, visit , and neighbor . Both are recursive and remarkably simple.
Recursion is an extremely useful programming construct, but it can be expensive.
Rewriting visit to run linearly using a stack is trivial but included for the curious in Figure . Note that the second visit code is nearly identical to the first. The other key octree algorithm is the neighbor computation. While at first glance, this seems to be a complicated search, in reality it is very simple. Define the neighbors of root to be NULL .