Search code examples
c++data-structuresraytracing

mesh partitioning and fast lookup


I am writing a raytracer and I am trying to partition some mesh data (points and faces) so i can calculate intersections.

Currently I for every intersection calculation i have to look up every face and see if the ray intersect with it. I am trying to find a faster way to do that, namely only lookup relevant faces.

What is a good data structure for storing the graph data (kd tree? equally partitioned space?) How can i look up relevant spaces/faces given a ray?

PS: Im using C++


Solution

  • A spatial partitioning data structure (a BSP tree, a k-D tree or an octree), or even more generally a bounding volume hierarchy (AABB tree) should do the job. See this answer to a related question for the construction of a BSP tree from a mesh and its traversal. The C++ library CGAL provides an AABB tree data structure with the required construction and query.