tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
filter.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_FILTER_HPP_
3#define _TINYPBRT_FILTER_HPP_
4
6
8
10
11namespace tpbrt {
35
42 [[nodiscard]] constexpr std::string_view to_string(const filter_type type) noexcept {
43 using enum filter_type;
44 switch (type) {
45 case BOX: return "box";
46 case GAUSSIAN: return "gaussian";
47 case MITCHELL: return "mitchell";
48 case SINC: return "sinc";
49 case TRIANGLE: return "triangle";
50 case MAX_NUM: return "maxnum";
51 default: return "UNKNOWN";
52 }
53 }
54
59 struct filter_gaussian_params : detail::wrapper<filter_gaussian_params, tpbrt_filter_gaussian_params_t> {
61 using wrapper::wrapper;
62
64 [[nodiscard]] constexpr float_t sigma() const noexcept { return _native->sigma; }
65
67 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(sigma()); }
68 };
69
74 struct filter_mitchell_params : detail::wrapper<filter_mitchell_params, tpbrt_filter_mitchell_params_t> {
76 using wrapper::wrapper;
77
79 [[nodiscard]] constexpr float_t b() const noexcept { return _native->b; }
80
82 [[nodiscard]] constexpr float_t c() const noexcept { return _native->c; }
83
85 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(b(), c()); }
86 };
87
92 struct filter_sinc_params : detail::wrapper<filter_sinc_params, tpbrt_filter_sinc_params_t> {
94 using wrapper::wrapper;
95
97 [[nodiscard]] constexpr float_t tau() const noexcept { return _native->tau; }
98
100 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(tau()); }
101 };
102
107 struct filter : detail::wrapper<filter, tpbrt_filter_t>,
108 detail::with_variant<filter, filter_gaussian_params, filter_mitchell_params, filter_sinc_params> {
110 using wrapper::wrapper;
111
113 [[nodiscard]] constexpr float_t x_radius() const noexcept { return _native->x_radius; }
114
116 [[nodiscard]] constexpr float_t y_radius() const noexcept { return _native->y_radius; }
117
119 [[nodiscard]] constexpr filter_type type() const noexcept { return static_cast<filter_type>(_native->type); }
120
122 [[nodiscard]] constexpr bool_t is_gaussian() const noexcept { return type() == filter_type::GAUSSIAN; }
123
125 [[nodiscard]] constexpr bool_t is_mitchell() const noexcept { return type() == filter_type::MITCHELL; }
126
128 [[nodiscard]] constexpr bool_t is_sinc() const noexcept { return type() == filter_type::SINC; }
129
131 [[nodiscard]] constexpr std::optional<filter_gaussian_params> as_gaussian() const noexcept {
132 if (!is_gaussian()) { return std::nullopt; }
133 return _native->as.gaussian;
134 }
135
137 [[nodiscard]] constexpr std::optional<filter_mitchell_params> as_mitchell() const noexcept {
138 if (!is_mitchell()) { return std::nullopt; }
139 return _native->as.mitchell;
140 }
141
143 [[nodiscard]] constexpr std::optional<filter_sinc_params> as_sinc() const noexcept {
144 if (!is_sinc()) { return std::nullopt; }
145 return _native->as.sinc;
146 }
147
149 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
150 using enum filter_type;
151 switch (type()) {
152 case GAUSSIAN: return _native->as.gaussian;
153 case MITCHELL: return _native->as.mitchell;
154 case SINC: return _native->as.sinc;
155 case MAX_NUM: [[fallthrough]];
156 default: break;
157 }
158 return std::nullopt;
159 }
160
162 [[nodiscard]] constexpr auto reflect() const noexcept {
163 return std::make_tuple(x_radius(), y_radius(), to_variant(), type());
164 }
165 };
166} // namespace tpbrt
167#endif // _TINYPBRT_FILTER_HPP_
constexpr std::string_view to_string(const accelerator_type type) noexcept
Converts accelerator_type enum value to string.
Definition accelerator.hpp:39
@ MAX_NUM
Count of available accelerator types.
@ GAUSSIAN
Gaussian aperture shape.
tpbrt_uchar_t uchar_t
Unsigned char type.
Definition fwd.hpp:34
filter_type
Filter type.
Definition filter.hpp:21
@ GAUSSIAN
Gaussian filter.
@ SINC
Sinc filter.
@ MITCHELL
Mitchell filter.
@ TRIANGLE
Triangle filter.
@ BOX
Box filter.
@ TPBRT_FILTER_TYPE_MAX_NUM
Count of available filter types.
Definition filter.h:32
@ TPBRT_FILTER_TYPE_TRIANGLE
Triangle filter.
Definition filter.h:30
@ TPBRT_FILTER_TYPE_BOX
Box filter.
Definition filter.h:22
@ TPBRT_FILTER_TYPE_GAUSSIAN
Gaussian filter.
Definition filter.h:24
@ TPBRT_FILTER_TYPE_MITCHELL
Mitchell filter.
Definition filter.h:26
@ TPBRT_FILTER_TYPE_SINC
Sinc filter.
Definition filter.h:28
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_filter_gaussian_params_t.
Definition filter.hpp:59
constexpr float_t sigma() const noexcept
Returns sigma value.
Definition filter.hpp:64
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition filter.hpp:67
C++ wrapper for tpbrt_filter_mitchell_params_t.
Definition filter.hpp:74
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition filter.hpp:85
constexpr float_t c() const noexcept
Returns c value.
Definition filter.hpp:82
constexpr float_t b() const noexcept
Returns b value.
Definition filter.hpp:79
C++ wrapper for tpbrt_filter_sinc_params_t.
Definition filter.hpp:92
constexpr float_t tau() const noexcept
Returns tau value.
Definition filter.hpp:97
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition filter.hpp:100
C++ wrapper for tpbrt_filter_t.
Definition filter.hpp:108
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition filter.hpp:162
constexpr float_t x_radius() const noexcept
Returns x_radius value.
Definition filter.hpp:113
constexpr bool_t is_mitchell() const noexcept
Returns true if type is mitchell.
Definition filter.hpp:125
constexpr std::optional< filter_gaussian_params > as_gaussian() const noexcept
Returns gaussian parameters (std::nullopt if the type is different).
Definition filter.hpp:131
constexpr filter_type type() const noexcept
Returns type value.
Definition filter.hpp:119
constexpr bool_t is_sinc() const noexcept
Returns true if type is sinc.
Definition filter.hpp:128
constexpr std::optional< filter_sinc_params > as_sinc() const noexcept
Returns sinc parameters (std::nullopt if the type is different).
Definition filter.hpp:143
constexpr float_t y_radius() const noexcept
Returns y_radius value.
Definition filter.hpp:116
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition filter.hpp:149
constexpr std::optional< filter_mitchell_params > as_mitchell() const noexcept
Returns mitchell parameters (std::nullopt if the type is different).
Definition filter.hpp:137
constexpr bool_t is_gaussian() const noexcept
Returns true if type is gaussian.
Definition filter.hpp:122