tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_COLOR_HPP_
3#define _TINYPBRT_COLOR_HPP_
4
6
8
9#include <optional>
10#include <tuple>
11
14
15namespace tpbrt {
37
44 [[nodiscard]] constexpr std::string_view to_string(const color_space space) noexcept {
45 using enum color_space;
46 switch (space) {
47 case ACES_2065_1: return "aces2065-1";
48 case REC_2020: return "rec2020";
49 case DCI_P3: return "dci-p3";
50 case SRGB: return "srgb";
51 case MAX_NUM: return "maxnum";
52 default: return "UNKNOWN";
53 }
54 }
55
76
83 [[nodiscard]] constexpr std::string_view to_string(const spectrum_type type) noexcept {
84 using enum spectrum_type;
85 switch (type) {
86 case WAVELENGTHS: return "wavelengths";
87 case RGB: return "rgb";
88 case BLACKBODY: return "blackbody";
89 case FILE: return "file";
90 case BUILTIN: return "builtin";
91 case CONSTANT: return "constant";
92 case MAX_NUM: return "maxnum";
93 default: return "UNKNOWN";
94 }
95 }
96
101 struct wavelength : detail::wrapper<wavelength, tpbrt_wavelength_t> {
103 using wrapper::wrapper;
104
106 [[nodiscard]] constexpr float_t lambda() const noexcept { return _native->wavelength; }
107
109 [[nodiscard]] constexpr float_t value() const noexcept { return _native->value; }
110
112 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(lambda(), value()); }
113 };
114
196 };
197
204 [[nodiscard]] constexpr std::string_view to_string(const spectrum_builtin builtin) noexcept {
205 using enum spectrum_builtin;
206 switch (builtin) {
207 case GLASS_BK7: return "glass-BK7";
208 case GLASS_BAF10: return "glass-BAF10";
209 case GLASS_FK51A: return "glass-FK51A";
210 case GLASS_LASF9: return "glass-LASF9";
211 case GLASS_F5: return "glass-F5";
212 case GLASS_F10: return "glass-F10";
213 case GLASS_F11: return "glass-F11";
214 case METAL_AG_ETA: return "metal-Ag-eta";
215 case METAL_AG_K: return "metal-Ag-k";
216 case METAL_AL_ETA: return "metal-Al-eta";
217 case METAL_AL_K: return "metal-Al-k";
218 case METAL_AU_ETA: return "metal-Au-eta";
219 case METAL_AU_K: return "metal-Au-k";
220 case METAL_CU_ETA: return "metal-Cu-eta";
221 case METAL_CU_K: return "metal-Cu-k";
222 case METAL_CU_ZN_ETA: return "metal-CuZn-eta";
223 case METAL_CU_ZN_K: return "metal-CuZn-k";
224 case METAL_MG_O_ETA: return "metal-MgO-eta";
225 case METAL_MG_O_K: return "metal-MgO-k";
226 case METAL_TI_O2_ETA: return "metal-TiO2-eta";
227 case METAL_TI_O2_K: return "metal-TiO2-k";
228 case STD_ILLUM_A: return "stdillum-A";
229 case STD_ILLUM_D50: return "stdillum-D50";
230 case STD_ILLUM_D65: return "stdillum-D65";
231 case STD_ILLUM_F1: return "stdillum-F1";
232 case STD_ILLUM_F2: return "stdillum-F2";
233 case STD_ILLUM_F3: return "stdillum-F3";
234 case STD_ILLUM_F4: return "stdillum-F4";
235 case STD_ILLUM_F5: return "stdillum-F5";
236 case STD_ILLUM_F6: return "stdillum-F6";
237 case STD_ILLUM_F7: return "stdillum-F7";
238 case STD_ILLUM_F8: return "stdillum-F8";
239 case STD_ILLUM_F9: return "stdillum-F9";
240 case STD_ILLUM_F10: return "stdillum-F10";
241 case STD_ILLUM_F11: return "stdillum-F11";
242 case STD_ILLUM_F12: return "stdillum-F12";
243 case ILLUM_ACES_D60: return "illum-acesD60";
244 case MAX_NUM: return "maxnum";
245 default: return "UNKNOWN";
246 }
247 }
248
254 struct blackbody : detail::wrapper<blackbody, tpbrt_blackbody_t> {
256 using wrapper::wrapper;
257
259 [[nodiscard]] constexpr float_t temperature() const noexcept { return *_native; }
260
262 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(temperature()); }
263 };
264
269 struct spectrum : detail::wrapper<spectrum, tpbrt_spectrum_t>,
270 detail::with_variant<spectrum, wavelength_array, rgb, blackbody, string, spectrum_builtin, float_t> {
272 using wrapper::wrapper;
273
275 [[nodiscard]] constexpr spectrum_type type() const noexcept { return static_cast<spectrum_type>(_native->type); }
276
278 [[nodiscard]] constexpr bool_t is_wavelengths() const noexcept { return type() == spectrum_type::WAVELENGTHS; }
279
281 [[nodiscard]] constexpr bool_t is_rgb() const noexcept { return type() == spectrum_type::RGB; }
282
284 [[nodiscard]] constexpr bool_t is_blackbody() const noexcept { return type() == spectrum_type::BLACKBODY; }
285
287 [[nodiscard]] constexpr bool_t is_file() const noexcept { return type() == spectrum_type::FILE; }
288
290 [[nodiscard]] constexpr bool_t is_builtin() const noexcept { return type() == spectrum_type::BUILTIN; }
291
293 [[nodiscard]] constexpr bool_t is_constant() const noexcept { return type() == spectrum_type::CONSTANT; }
294
296 [[nodiscard]] constexpr std::optional<wavelength_array> as_wavelengths() const noexcept {
297 if (!is_wavelengths()) { return std::nullopt; }
298 return _native->as.wavelengths;
299 }
300
302 [[nodiscard]] constexpr std::optional<rgb> as_rgb() const noexcept {
303 if (!is_rgb()) { return std::nullopt; }
304 return _native->as.rgb;
305 }
306
308 [[nodiscard]] constexpr std::optional<blackbody> as_blackbody() const noexcept {
309 if (!is_blackbody()) { return std::nullopt; }
310 return _native->as.blackbody;
311 }
312
314 [[nodiscard]] constexpr std::optional<string> as_file() const noexcept {
315 if (!is_file()) { return std::nullopt; }
316 return _native->as.file_name;
317 }
318
320 [[nodiscard]] constexpr std::optional<spectrum_builtin> as_builtin() const noexcept {
321 if (!is_builtin()) { return std::nullopt; }
322 return static_cast<spectrum_builtin>(_native->as.builtin);
323 }
324
326 [[nodiscard]] constexpr std::optional<float_t> as_constant() const noexcept {
327 if (!is_constant()) { return std::nullopt; }
328 return _native->as.constant;
329 }
330
332 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
333 using enum spectrum_type;
334 switch (type()) {
335 case WAVELENGTHS: return _native->as.wavelengths;
336 case RGB: return _native->as.rgb;
337 case BLACKBODY:
338 return blackbody(
339 _native->as.blackbody
340 ); // float in C: without the explicit type the variant would pick float_t
341 case FILE: return _native->as.file_name;
342 case BUILTIN: return static_cast<spectrum_builtin>(_native->as.builtin);
343 case CONSTANT: return _native->as.constant;
344 case MAX_NUM: [[fallthrough]];
345 default: break;
346 }
347 return std::nullopt;
348 }
349
351 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(to_variant(), type()); }
352 };
353} // namespace tpbrt
354#endif // _TINYPBRT_COLOR_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.
@ BUILTIN
Aperture value is a builtin aperture.
spectrum_type
Spectrum value type.
Definition color.hpp:60
spectrum_builtin
Spectrum builtins.
Definition color.hpp:119
color_space
Color space types.
Definition color.hpp:25
@ WAVELENGTHS
Spectrum defined as list of pairs (wavelength, value).
@ RGB
Spectrum defined as RGB value.
@ CONSTANT
Spectrum defined as single constant float value.
@ FILE
Spectrum defined as file which contains wavelengths.
@ BLACKBODY
Spectrum defined as Blackbody temperature in Kelvins.
@ BUILTIN
Spectrum defined as builtin value.
@ METAL_AG_K
Extinction coefficient for silver.
@ STD_ILLUM_D65
CIE standard illuminant D65.
@ STD_ILLUM_F2
CIE standard illuminant F2.
@ STD_ILLUM_D50
CIE standard illuminant D50.
@ GLASS_F11
Index of refraction for F11 glass.
@ GLASS_LASF9
Index of refraction for LASF9 glass.
@ METAL_CU_ETA
Index of refraction for copper.
@ STD_ILLUM_F11
CIE standard illuminant F11.
@ STD_ILLUM_F7
CIE standard illuminant F7.
@ METAL_CU_ZN_K
Extinction coefficient for copper zinc alloy.
@ STD_ILLUM_F1
CIE standard illuminant F1.
@ STD_ILLUM_F5
CIE standard illuminant F5.
@ GLASS_BAF10
Index of refraction for BAF10 glass.
@ METAL_TI_O2_ETA
Index of refraction for titanium dioxide.
@ METAL_AL_K
Extinction coefficient for aluminum.
@ STD_ILLUM_F8
CIE standard illuminant F8.
@ STD_ILLUM_F6
CIE standard illuminant F6.
@ METAL_AG_ETA
Index of refraction for silver.
@ STD_ILLUM_F10
CIE standard illuminant F10.
@ METAL_MG_O_K
Extinction coefficient for magnesium oxide.
@ METAL_TI_O2_K
Extinction coefficient for titanium dioxide.
@ METAL_AL_ETA
Index of refraction for aluminum.
@ METAL_MG_O_ETA
Index of refraction for magnesium oxide.
@ STD_ILLUM_F3
CIE standard illuminant F3.
@ STD_ILLUM_A
CIE standard illuminant A.
@ GLASS_FK51A
Index of refraction for FK51A glass.
@ METAL_CU_ZN_ETA
Index of refraction for copper zinc alloy.
@ ILLUM_ACES_D60
D60 illuminant from ACES.
@ METAL_CU_K
Extinction coefficient for copper.
@ STD_ILLUM_F9
CIE standard illuminant F9.
@ GLASS_F10
Index of refraction for F10 glass.
@ METAL_AU_K
Extinction coefficient for gold.
@ STD_ILLUM_F4
CIE standard illuminant F4.
@ GLASS_F5
Index of refraction for F5 glass.
@ METAL_AU_ETA
Index of refraction for gold.
@ GLASS_BK7
Index of refraction for BK7 glass.
@ STD_ILLUM_F12
CIE standard illuminant F12.
@ SRGB
The venerable sRGB color space; it has the smallest gamut of pbrt-v4's color spaces,...
@ ACES_2065_1
The standard color space defined in the Academy Color Encoding System.
@ DCI_P3
The DCI-P3 color space, widely used in current displays.
@ REC_2020
The ITU-R Recommendation BT.2020 color space.
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F5
CIE standard illuminant F5.
Definition color.h:141
@ TPBRT_SPECTRUM_BUILTIN_METAL_CU_ZN_K
Extinction coefficient for copper zinc alloy.
Definition color.h:117
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_A
CIE standard illuminant A.
Definition color.h:127
@ TPBRT_SPECTRUM_BUILTIN_METAL_CU_ZN_ETA
Index of refraction for copper zinc alloy.
Definition color.h:115
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F7
CIE standard illuminant F7.
Definition color.h:145
@ TPBRT_SPECTRUM_BUILTIN_MAX_NUM
Count of available spectrum builtins.
Definition color.h:159
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F11
CIE standard illuminant F11.
Definition color.h:153
@ TPBRT_SPECTRUM_BUILTIN_METAL_AU_K
Extinction coefficient for gold.
Definition color.h:109
@ TPBRT_SPECTRUM_BUILTIN_GLASS_F11
Index of refraction for F11 glass.
Definition color.h:97
@ TPBRT_SPECTRUM_BUILTIN_METAL_TI_O2_ETA
Index of refraction for titanium dioxide.
Definition color.h:123
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F2
CIE standard illuminant F2.
Definition color.h:135
@ TPBRT_SPECTRUM_BUILTIN_METAL_CU_K
Extinction coefficient for copper.
Definition color.h:113
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F12
CIE standard illuminant F12.
Definition color.h:155
@ TPBRT_SPECTRUM_BUILTIN_METAL_MG_O_K
Extinction coefficient for magnesium oxide.
Definition color.h:121
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F9
CIE standard illuminant F9.
Definition color.h:149
@ TPBRT_SPECTRUM_BUILTIN_GLASS_F10
Index of refraction for F10 glass.
Definition color.h:95
@ TPBRT_SPECTRUM_BUILTIN_METAL_TI_O2_K
Extinction coefficient for titanium dioxide.
Definition color.h:125
@ TPBRT_SPECTRUM_BUILTIN_METAL_AL_ETA
Index of refraction for aluminum.
Definition color.h:103
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F10
CIE standard illuminant F10.
Definition color.h:151
@ TPBRT_SPECTRUM_BUILTIN_GLASS_LASF9
Index of refraction for LASF9 glass.
Definition color.h:91
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F3
CIE standard illuminant F3.
Definition color.h:137
@ TPBRT_SPECTRUM_BUILTIN_METAL_AU_ETA
Index of refraction for gold.
Definition color.h:107
@ TPBRT_SPECTRUM_BUILTIN_GLASS_BK7
Index of refraction for BK7 glass.
Definition color.h:85
@ TPBRT_SPECTRUM_BUILTIN_METAL_AL_K
Extinction coefficient for aluminum.
Definition color.h:105
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F4
CIE standard illuminant F4.
Definition color.h:139
@ TPBRT_SPECTRUM_BUILTIN_METAL_CU_ETA
Index of refraction for copper.
Definition color.h:111
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_D65
CIE standard illuminant D65.
Definition color.h:131
@ TPBRT_SPECTRUM_BUILTIN_METAL_AG_ETA
Index of refraction for silver.
Definition color.h:99
@ TPBRT_SPECTRUM_BUILTIN_ILLUM_ACES_D60
D60 illuminant from ACES.
Definition color.h:157
@ TPBRT_SPECTRUM_BUILTIN_METAL_MG_O_ETA
Index of refraction for magnesium oxide.
Definition color.h:119
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F8
CIE standard illuminant F8.
Definition color.h:147
@ TPBRT_SPECTRUM_BUILTIN_GLASS_FK51A
Index of refraction for FK51A glass.
Definition color.h:89
@ TPBRT_SPECTRUM_BUILTIN_METAL_AG_K
Extinction coefficient for silver.
Definition color.h:101
@ TPBRT_SPECTRUM_BUILTIN_GLASS_BAF10
Index of refraction for BAF10 glass.
Definition color.h:87
@ TPBRT_SPECTRUM_BUILTIN_GLASS_F5
Index of refraction for F5 glass.
Definition color.h:93
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F6
CIE standard illuminant F6.
Definition color.h:143
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_F1
CIE standard illuminant F1.
Definition color.h:133
@ TPBRT_SPECTRUM_BUILTIN_STD_ILLUM_D50
CIE standard illuminant D50.
Definition color.h:129
@ TPBRT_COLOR_SPACE_ACES_2065_1
The standard color space defined in the Academy Color Encoding System.
Definition color.h:25
@ TPBRT_COLOR_SPACE_REC_2020
The ITU-R Recommendation BT.2020 color space.
Definition color.h:27
@ TPBRT_COLOR_SPACE_DCI_P3
The DCI-P3 color space, widely used in current displays.
Definition color.h:29
@ TPBRT_COLOR_SPACE_MAX_NUM
Count of available color spaces.
Definition color.h:33
@ TPBRT_COLOR_SPACE_SRGB
The venerable sRGB color space; it has the smallest gamut of pbrt-v4's color spaces,...
Definition color.h:31
@ TPBRT_SPECTRUM_TYPE_BUILTIN
Spectrum defined as builtin value.
Definition color.h:50
@ TPBRT_SPECTRUM_TYPE_BLACKBODY
Spectrum defined as Blackbody temperature in Kelvins.
Definition color.h:46
@ TPBRT_SPECTRUM_TYPE_CONSTANT
Spectrum defined as single constant float value.
Definition color.h:52
@ TPBRT_SPECTRUM_TYPE_MAX_NUM
Count of available spectrum value types.
Definition color.h:54
@ TPBRT_SPECTRUM_TYPE_WAVELENGTHS
Spectrum defined as list of pairs (wavelength, value).
Definition color.h:42
@ TPBRT_SPECTRUM_TYPE_RGB
Spectrum defined as RGB value.
Definition color.h:44
@ TPBRT_SPECTRUM_TYPE_FILE
Spectrum defined as file which contains wavelengths.
Definition color.h:48
tpbrt_uchar_t uchar_t
Unsigned char type.
Definition fwd.hpp:34
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_blackbody_t (a separate type, so a blackbody spectrum is not confused with a co...
Definition color.hpp:254
constexpr float_t temperature() const noexcept
Returns blackbody temperature in Kelvin.
Definition color.hpp:259
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition color.hpp:262
C++ wrapper for tpbrt_spectrum_t.
Definition color.hpp:270
constexpr spectrum_type type() const noexcept
Returns type value.
Definition color.hpp:275
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition color.hpp:351
constexpr std::optional< float_t > as_constant() const noexcept
Returns spectrum value as constant.
Definition color.hpp:326
constexpr bool_t is_builtin() const noexcept
Returns true if type is builtin.
Definition color.hpp:290
constexpr bool_t is_rgb() const noexcept
Returns true if type is rgb.
Definition color.hpp:281
constexpr std::optional< string > as_file() const noexcept
Returns spectrum value as file.
Definition color.hpp:314
constexpr std::optional< blackbody > as_blackbody() const noexcept
Returns spectrum value as blackbody.
Definition color.hpp:308
constexpr bool_t is_wavelengths() const noexcept
Returns true if type is wavelengths.
Definition color.hpp:278
constexpr std::optional< rgb > as_rgb() const noexcept
Returns spectrum value as rgb.
Definition color.hpp:302
constexpr bool_t is_file() const noexcept
Returns true if type is file.
Definition color.hpp:287
constexpr std::optional< wavelength_array > as_wavelengths() const noexcept
Returns spectrum value as wavelengths.
Definition color.hpp:296
constexpr std::optional< spectrum_builtin > as_builtin() const noexcept
Returns spectrum value as builtin.
Definition color.hpp:320
constexpr bool_t is_constant() const noexcept
Returns true if type is constant.
Definition color.hpp:293
constexpr bool_t is_blackbody() const noexcept
Returns true if type is blackbody.
Definition color.hpp:284
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition color.hpp:332
C++ wrapper for tpbrt_wavelength_t.
Definition color.hpp:101
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition color.hpp:112
constexpr float_t value() const noexcept
Returns value value.
Definition color.hpp:109
constexpr float_t lambda() const noexcept
Returns wavelength value.
Definition color.hpp:106