Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:13:46

0001 #ifndef BVH_V2_SPLIT_HEURISTIC_H
0002 #define BVH_V2_SPLIT_HEURISTIC_H
0003 
0004 #include "bvh/v2/bbox.h"
0005 #include "bvh/v2/utils.h"
0006 
0007 #include <cstddef>
0008 
0009 namespace bvh::v2 {
0010 
0011 template <typename T>
0012 class SplitHeuristic {
0013 public:
0014     /// Creates an SAH evaluator object, used by top-down builders to determine where to split.
0015     /// The two parameters are the log of the size of primitive clusters in base 2, and the ratio of
0016     /// the cost of intersecting a node (a ray-box intersection) over the cost of intersecting a
0017     /// primitive.
0018     BVH_ALWAYS_INLINE SplitHeuristic(
0019         size_t log_cluster_size = 0,
0020         T cost_ratio = static_cast<T>(1.))
0021         : log_cluster_size_(log_cluster_size)
0022         , prim_offset_(make_bitmask<size_t>(log_cluster_size))
0023         , cost_ratio_(cost_ratio)
0024     {}
0025 
0026     BVH_ALWAYS_INLINE size_t get_prim_count(size_t size) const {
0027         return (size + prim_offset_) >> log_cluster_size_;
0028     }
0029 
0030     template <size_t N>
0031     BVH_ALWAYS_INLINE T get_leaf_cost(size_t begin, size_t end, const BBox<T, N>& bbox) const {
0032         return bbox.get_half_area() * static_cast<T>(get_prim_count(end - begin));
0033     }
0034 
0035     template <size_t N>
0036     BVH_ALWAYS_INLINE T get_non_split_cost(size_t begin, size_t end, const BBox<T, N>& bbox) const {
0037         return bbox.get_half_area() * (static_cast<T>(get_prim_count(end - begin)) - cost_ratio_);
0038     }
0039 
0040 private:
0041     size_t log_cluster_size_;
0042     size_t prim_offset_;
0043     T cost_ratio_;
0044 };
0045 
0046 } // namespace bvh::v2
0047 
0048 #endif