Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ray.h
Go to the documentation of this file.
1#ifndef BVH_V2_RAY_H
2#define BVH_V2_RAY_H
3
4#include "bvh/v2/vec.h"
5
6namespace bvh::v2 {
7
8struct Octant {
9 uint32_t value = 0;
10 static constexpr size_t max_dim = sizeof(value) * CHAR_BIT;
11
12 uint32_t operator [] (size_t i) const { return (value >> i) & uint32_t{1}; }
13};
14
15template <typename T, size_t N>
16struct Ray {
19
20 Ray() = default;
22 const Vec<T, N>& org,
23 const Vec<T, N>& dir,
24 T tmin = 0,
25 T tmax = std::numeric_limits<T>::max())
26 : org(org), dir(dir), tmin(tmin), tmax(tmax)
27 {}
28
29 template <bool SafeInverse = false>
31 return Vec<T, N>::generate([&] (size_t i) {
32 return SafeInverse ? safe_inverse(dir[i]) : static_cast<T>(1) / dir[i];
33 });
34 }
35
37 static_assert(N <= Octant::max_dim);
38 Octant octant;
39 static_for<0, N>([&] (size_t i) {
40 octant.value |= std::signbit(dir[i]) * (uint32_t{1} << i);
41 });
42 return octant;
43 }
44
45 // Pads the inverse direction according to T. Ize's "Robust BVH ray traversal"
47 return Vec<T, N>::generate([&] (size_t i) { return add_ulp_magnitude(inv_dir[i], 2); });
48 }
49};
50
51} // namespace bvh::v2
52
53#endif
#define N
Definition bbox.h:9
BVH_ALWAYS_INLINE T safe_inverse(T x)
Computes the inverse of the given value, always returning a finite value.
Definition utils.h:59
BVH_ALWAYS_INLINE T add_ulp_magnitude(T t, unsigned ulp)
Adds the given number of ULPs (Units in the Last Place) to the given floating-point number.
Definition utils.h:47
#define BVH_ALWAYS_INLINE
Definition platform.h:19
static constexpr size_t max_dim
Definition ray.h:10
uint32_t operator[](size_t i) const
Definition ray.h:12
uint32_t value
Definition ray.h:9
Ray()=default
BVH_ALWAYS_INLINE Ray(const Vec< T, N > &org, const Vec< T, N > &dir, T tmin=0, T tmax=std::numeric_limits< T >::max())
Definition ray.h:21
static BVH_ALWAYS_INLINE Vec< T, N > pad_inv_dir(const Vec< T, N > &inv_dir)
Definition ray.h:46
Vec< T, N > dir
Definition ray.h:17
BVH_ALWAYS_INLINE Vec< T, N > get_inv_dir() const
Definition ray.h:30
Vec< T, N > org
Definition ray.h:17
BVH_ALWAYS_INLINE Octant get_octant() const
Definition ray.h:36
static BVH_ALWAYS_INLINE Vec< T, N > generate(F &&f)
Definition vec.h:40