tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
accelerator.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_ACCELERATOR_HPP_
3#define _TINYPBRT_ACCELERATOR_HPP_
4
6
8
9#include <string_view>
10#include <tuple>
11
13
14namespace tpbrt {
32
39 [[nodiscard]] constexpr std::string_view to_string(const accelerator_type type) noexcept {
40 using enum accelerator_type;
41 switch (type) {
42 case BVH: return "bvh";
43 case KD_TREE: return "kdtree";
44 case MAX_NUM: return "maxnum";
45 default: return "UNKNOWN";
46 }
47 }
48
65
72 [[nodiscard]] constexpr std::string_view to_string(const accelerator_bvh_split_method method) noexcept {
74 switch (method) {
75 case SAH: return "sah";
76 case MIDDLE: return "middle";
77 case EQUAL: return "equal";
78 case HLBVH: return "hlbvh";
79 case MAX_NUM: return "maxnum";
80 default: return "UNKNOWN";
81 }
82 }
83
88 struct accelerator_bvh_params : detail::wrapper<accelerator_bvh_params, tpbrt_accelerator_bvh_params_t> {
90 using wrapper::wrapper;
91
93 [[nodiscard]] constexpr uint_t max_node_prims() const noexcept { return _native->max_node_prims; }
94
96 [[nodiscard]] constexpr accelerator_bvh_split_method split_method() const noexcept {
97 return static_cast<accelerator_bvh_split_method>(_native->split_method);
98 }
99
101 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(max_node_prims(), split_method()); }
102 };
103
108 struct accelerator_kd_tree_params : detail::wrapper<accelerator_kd_tree_params, tpbrt_accelerator_kd_tree_params_t> {
110 using wrapper::wrapper;
111
113 [[nodiscard]] constexpr uint_t intersect_cost() const noexcept { return _native->intersect_cost; }
114
116 [[nodiscard]] constexpr uint_t traversal_cost() const noexcept { return _native->traversal_cost; }
117
119 [[nodiscard]] constexpr float_t empty_bonus() const noexcept { return _native->empty_bonus; }
120
122 [[nodiscard]] constexpr uint_t max_prims() const noexcept { return _native->max_prims; }
123
125 [[nodiscard]] constexpr int_t max_depth() const noexcept { return _native->max_depth; }
126
128 [[nodiscard]] constexpr auto reflect() const noexcept {
129 return std::make_tuple(intersect_cost(), traversal_cost(), empty_bonus(), max_prims(), max_depth());
130 }
131 };
132
137 struct accelerator : detail::wrapper<accelerator, tpbrt_accelerator_t>,
138 detail::with_variant<accelerator, accelerator_bvh_params, accelerator_kd_tree_params> {
140 using wrapper::wrapper;
141
143 [[nodiscard]] constexpr accelerator_type type() const noexcept { return static_cast<accelerator_type>(_native->type); }
144
146 [[nodiscard]] constexpr bool_t is_bvh() const noexcept { return type() == accelerator_type::BVH; }
147
149 [[nodiscard]] constexpr bool_t is_kd_tree() const noexcept { return type() == accelerator_type::KD_TREE; }
150
152 [[nodiscard]] constexpr std::optional<accelerator_bvh_params> as_bvh() const noexcept {
153 if (!is_bvh()) { return std::nullopt; }
154 return _native->as.bvh;
155 }
156
158 [[nodiscard]] constexpr std::optional<accelerator_kd_tree_params> as_kd_tree() const noexcept {
159 if (!is_kd_tree()) { return std::nullopt; }
160 return _native->as.kd_tree;
161 }
162
164 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
165 using enum accelerator_type;
166 switch (type()) {
167 case BVH: return _native->as.bvh;
168 case KD_TREE: return _native->as.kd_tree;
169 case MAX_NUM: [[fallthrough]];
170 default: break;
171 }
172 return std::nullopt;
173 }
174
176 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(to_variant(), type()); }
177 };
178} // namespace tpbrt
179#endif // _TINYPBRT_ACCELERATOR_HPP_
constexpr std::string_view to_string(const accelerator_type type) noexcept
Converts accelerator_type enum value to string.
Definition accelerator.hpp:39
accelerator_type
Used to declare accelerator type.
Definition accelerator.hpp:24
accelerator_bvh_split_method
Used to declare BVH split method.
Definition accelerator.hpp:53
@ MAX_NUM
Count of available accelerator types.
@ KD_TREE
KD Tree acceleration.
@ BVH
BVH acceleration.
@ HLBVH
HLBVH split method. Selects the HLBVH algorithm, which parallelizes well.
@ SAH
SAH split method. Denotes the surface area heuristic.
@ MIDDLE
Middle split method. Splits each node at its midpoint along the split axis.
@ EQUAL
Equal split method. Splits the current group of primitives into two equal-sized sets.
@ TPBRT_ACCELERATOR_BVH_SPLIT_METHOD_SAH
SAH split method. Denotes the surface area heuristic.
Definition accelerator.h:35
@ TPBRT_ACCELERATOR_BVH_SPLIT_METHOD_MIDDLE
Middle split method. Splits each node at its midpoint along the split axis.
Definition accelerator.h:37
@ TPBRT_ACCELERATOR_BVH_SPLIT_METHOD_MAX_NUM
Count of available BVH split methods.
Definition accelerator.h:43
@ TPBRT_ACCELERATOR_BVH_SPLIT_METHOD_HLBVH
HLBVH split method. Selects the HLBVH algorithm, which parallelizes well.
Definition accelerator.h:41
@ TPBRT_ACCELERATOR_BVH_SPLIT_METHOD_EQUAL
Equal split method. Splits the current group of primitives into two equal-sized sets.
Definition accelerator.h:39
@ TPBRT_ACCELERATOR_TYPE_KD_TREE
KD Tree acceleration.
Definition accelerator.h:24
@ TPBRT_ACCELERATOR_TYPE_BVH
BVH acceleration.
Definition accelerator.h:22
@ TPBRT_ACCELERATOR_TYPE_MAX_NUM
Count of available accelerator types.
Definition accelerator.h:26
tpbrt_uchar_t uchar_t
Unsigned char type.
Definition fwd.hpp:34
tpbrt_int_t int_t
Int type.
Definition fwd.hpp:87
tpbrt_uint_t uint_t
Unsigned int type.
Definition fwd.hpp:92
bool bool_t
Bool type.
Definition fwd.hpp:82
tpbrt_float_t float_t
Float type.
Definition fwd.hpp:97
Definition accelerator.hpp:14
C++ wrapper for tpbrt_accelerator_bvh_params_t.
Definition accelerator.hpp:88
constexpr accelerator_bvh_split_method split_method() const noexcept
Returns split_method value.
Definition accelerator.hpp:96
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition accelerator.hpp:101
constexpr uint_t max_node_prims() const noexcept
Returns max_node_prims value.
Definition accelerator.hpp:93
C++ wrapper for tpbrt_accelerator_kd_tree_params_t.
Definition accelerator.hpp:108
constexpr uint_t traversal_cost() const noexcept
Returns traversal_cost value.
Definition accelerator.hpp:116
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition accelerator.hpp:128
constexpr float_t empty_bonus() const noexcept
Returns empty_bonus value.
Definition accelerator.hpp:119
constexpr uint_t max_prims() const noexcept
Returns max_prims value.
Definition accelerator.hpp:122
constexpr uint_t intersect_cost() const noexcept
Returns intersect_cost value.
Definition accelerator.hpp:113
constexpr int_t max_depth() const noexcept
Returns max_depth value.
Definition accelerator.hpp:125
C++ wrapper for tpbrt_accelerator_t.
Definition accelerator.hpp:138
constexpr std::optional< accelerator_bvh_params > as_bvh() const noexcept
Returns accelerator parameters as bvh.
Definition accelerator.hpp:152
constexpr bool_t is_bvh() const noexcept
Returns true if type is bvh.
Definition accelerator.hpp:146
constexpr accelerator_type type() const noexcept
Returns type value.
Definition accelerator.hpp:143
constexpr std::optional< accelerator_kd_tree_params > as_kd_tree() const noexcept
Returns accelerator parameters as kd tree.
Definition accelerator.hpp:158
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition accelerator.hpp:176
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition accelerator.hpp:164
constexpr bool_t is_kd_tree() const noexcept
Returns true if type is kd tree.
Definition accelerator.hpp:149