Noticed in your log you ran into a tradeoff between tree build depth
and curve quality. This is actually a useful thing to consider in
more detail - once you have the initial bounding box set, I think
there may be a refinement approach you can take that involves a lot
less overhead than deeper tree builds.
If you need more refinement than is offered by the initial surface
tree intersection (guaranteed with a shallow, fast tree build):
1. Take the set of leaf intersected bounding boxes from the two
surfaces. For each surface, insert its bounding boxes that are part
of the intersection set into their own container. Those are your
2. For each box, if the dimensions look "too large" for the preferred
line segment distance for the current situation, iterate over the
boxes in the containers and for each box generate the four child
bounding boxes the way the SurfaceTree depth building would. Stash
those in two more containers and use those new bbox sets to
re-generate an intersection set consisting of smaller, refined boxes.
Once the finer intersection box set is generated, you can discard the
previous courser sets and use the new intersection set - unless I'm
missing something (possible) you shouldn't need to preserve the full
tree hierarchy in this situation.
3. Repeat step 1 and 2 until you have small enough boxes for the
local situation. This avoids having to build the entire tree to great
depth, which is where we get into performance trouble (particularly
memory consumption) and lets you get as much dimensional refinement as
you need in tricky local situations. This way, you're only storing
what you need, and only generating the deep boxes you need.
That approach (or some variation of it) may give you more flexibility