7#include <cgv/math/fray.h>
8#include <cgv/math/fvec.h>
9#include <cgv/media/axis_aligned_box.h>
19 float t = std::numeric_limits<float>::max();
27class ray_intersectable {
29 ray_intersectable() {}
30 virtual ~ray_intersectable() {}
129 void build(
const std::vector<const ray_intersectable*>& primitives,
size_t max_depth = 8);
138 std::vector<const ray_intersectable*> _primitives;
142 std::unique_ptr<bvh_node> _root = std::make_unique<bvh_node>();
149 void split(
bvh_node* node,
int depth = 0);
155#include <cgv/config/lib_end.h>
A Bounding Volume Hierarchy(BVH) using axis-aligned bounding boxes to partition primitives into a bin...
void build(const std::vector< const ray_intersectable * > &primitives, size_t max_depth=8)
Build the hierarchy over the given primitives.
bvh_result closest_intersection(const cgv::ray3 &ray) const
Calculate the closest intersection with positive distance, if any, of the given ray with the stored p...
An interface to define objects that are intersectable with a ray.
virtual bool intersect(const cgv::ray3 &ray, ray_intersection_info &info) const =0
Test if the object is intersected by the given ray.
virtual cgv::box3 get_bounds() const =0
Return the axis-aligned bounding box of the primitive.
namespace for data management components
this header is dependency free
cgv::math::fray< float, 3 > ray3
3d ray using 32 bit single precision floating point type
cgv::media::axis_aligned_box< float, 3 > box3
declare type of 3d single precision floating point axis-aligned boxes
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
A single node of a bounding volume hierarchy.
std::vector< size_t > primitive_indices
The list of primitive indices contained in this node. After building the tree, only leaf nodes will h...
cgv::box3 bounds
The node's axis aligned bounding box.
std::unique_ptr< bvh_node > child_b
The second child node of this node.
std::unique_ptr< bvh_node > child_a
The first child node of this node.
The result of a BVH intersection test.
size_t primitive_index
The index of the hit primitive as given during BVH construction.
ray_intersection_info intersection
Intersection information of the hit.
bool is_hit
True if a primitive was hit.
const ray_intersectable * primitive
A pointer to the hit primitive.
Holds information about a single intersection of a ray and primitive.
cgv::vec3 normal
The intersection surface normal.
cgv::vec2 uv
The intersection surface texture coordinates.
float t
The ray parameter.