I want to efficiently find all triangles (e.g. facets of a polyhedral mesh) that are contained in or intersected by a volume (e.g. AABB or sphere query). I want to do this, if possible and reasonable, with CGALs built-in features.
My current solution is simple brute force: for all facets in mesh, check if distance of facet to ball center is smaller than the ball radius. I used a fuzzy sphere query of the KD-tree on the vertices before, but it was not accurate enough for my application. I need full sphere-triangle intersections.
The CGAL AABB tree (https://doc.cgal.org/latest/AABB_tree/index.html) seems like the best datastructure but I need the 3D linear Kernel which has no intersection test for triangles and any kind of volume (https://doc.cgal.org/latest/Kernel_23/group__intersection__linear__grp.html). The CGAL KD tree doesn't work because it can only contain points.
My ideas are:
- Add a custom do_intersect() for Triangle_3 and Sphere_3 that the AABB tree can use. Is that even possible? This will probably require a custom squared_distance() as well.
- Convert the volume query into two area queries by projecting the triangles on e.g. the XY and YZ planes. Can the AABB tree even handle 2D search? There is no intersection for circle and 2D triangle but I could use the intersection of Iso_rectangle_2 and Triangle_2 as good first guess.
- Somehow traverse the internals of the AABB tree and stop before I find a node that doesn't contain my query anymore.
- Modify the closest_point_and_primitive() method, give an optional max_distance parameter and return all primitives within that distance. This would require me to mess with the CGAL code.
- Write my own datastructure. This will take some time to get it right.
Did I miss anything? Which solution would be the least effort?