21 size_t IndexBits =
sizeof(
T) * CHAR_BIT,
22 size_t PrimCountBits = 4>
27 static constexpr size_t dimension = Dim;
28 static constexpr size_t prim_count_bits = PrimCountBits;
29 static constexpr size_t index_bits = IndexBits;
44 return other.
bounds == bounds;
47 return other.
bounds != bounds;
59 static_for<0, Dim>([&] (
size_t i) {
60 bounds[i * 2 + 0] = bbox.
min[i];
61 bounds[i * 2 + 1] = bbox.
max[i];
66 return Vec<T, Dim>::generate([&] (
size_t i) {
return bounds[2 *
static_cast<uint32_t
>(i) + octant[i]]; });
70 return Vec<T, Dim>::generate([&] (
size_t i) {
return bounds[2 *
static_cast<uint32_t
>(i) + 1 - octant[i]]; });
78 const Octant& octant)
const
80 auto tmin = (get_min_bounds(octant) - ray.
org) * inv_dir;
81 auto tmax = (get_max_bounds(octant) - ray.
org) * inv_dir_pad;
82 return make_intersection_result(ray, tmin, tmax);
89 const Octant& octant)
const
91 auto tmin =
fast_mul_add(get_min_bounds(octant), inv_dir, inv_org);
92 auto tmax =
fast_mul_add(get_max_bounds(octant), inv_dir, inv_org);
93 return make_intersection_result(ray, tmin, tmax);
97 for (
auto&& bound : bounds)
104 for (
auto& bound : node.
bounds)
105 bound = stream.
read<T>();
118 static_for<0, Dim>([&] (
size_t i) {
122 return std::pair<T, T> { t0,
t1 };
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Stream of data that can be used to serialize data structures.
bool write(const T &data)
BVH_ALWAYS_INLINE T robust_max(T a, T b)
BVH_ALWAYS_INLINE T fast_mul_add(T a, T b, T c)
Fast multiply-add operation.
BVH_ALWAYS_INLINE T robust_min(T a, T b)
Packed index data structure.
UnsignedIntType< Bits > Type
Binary BVH node, containing its bounds and an index into its children or the primitives it contains.
BVH_ALWAYS_INLINE BBox< T, Dim > get_bbox() const
static BVH_ALWAYS_INLINE Node deserialize(InputStream &stream)
BVH_ALWAYS_INLINE std::pair< T, T > intersect_robust(const Ray< T, Dim > &ray, const Vec< T, Dim > &inv_dir, const Vec< T, Dim > &inv_dir_pad, const Octant &octant) const
Robust ray-node intersection routine. See "Robust BVH Ray Traversal", by T. Ize.
BVH_ALWAYS_INLINE Vec< T, Dim > get_max_bounds(const Octant &octant) const
BVH_ALWAYS_INLINE void set_bbox(const BBox< T, Dim > &bbox)
BVH_ALWAYS_INLINE Vec< T, Dim > get_min_bounds(const Octant &octant) const
static BVH_ALWAYS_INLINE std::pair< T, T > make_intersection_result(const Ray< T, Dim > &ray, const Vec< T, Dim > &tmin, const Vec< T, Dim > &tmax)
Index index
Index to the children of an inner node, or to the primitives for a leaf node.
std::array< T, Dim *2 > bounds
Bounds of the node, laid out in memory as [min_x, max_x, min_y, max_y, ...].
BVH_ALWAYS_INLINE void serialize(OutputStream &stream) const
BVH_ALWAYS_INLINE std::pair< T, T > intersect_fast(const Ray< T, Dim > &ray, const Vec< T, Dim > &inv_dir, const Vec< T, Dim > &inv_org, const Octant &octant) const
BVH_ALWAYS_INLINE bool is_leaf() const
static BVH_ALWAYS_INLINE Vec< T, N > generate(F &&f)