tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
camera.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_CAMERA_HPP_
3#define _TINYPBRT_CAMERA_HPP_
4
6
8
9#include <string_view>
10
14
15namespace tpbrt {
37
44 [[nodiscard]] constexpr std::string_view to_string(const camera_type type) noexcept {
45 using enum camera_type;
46 switch (type) {
47 case ORTHOGRAPHIC: return "orthographic";
48 case PERSPECTIVE: return "perspective";
49 case REALISTIC: return "realistic";
50 case SPHERICAL: return "spherical";
51 case MAX_NUM: return "maxnum";
52 default: return "UNKNOWN";
53 }
54 }
55
60 struct camera_orthographic_params : detail::wrapper<camera_orthographic_params, tpbrt_camera_orthographic_params_t> {
63
65 using wrapper::wrapper;
66
68 [[nodiscard]] constexpr float_t frame_aspect_ratio() const noexcept { return _native->frame_aspect_ratio; }
69
71 [[nodiscard]] constexpr screen_window_array_type screen_window() const noexcept { return _native->screen_window; }
72
74 [[nodiscard]] constexpr float_t lens_radius() const noexcept { return _native->lens_radius; }
75
77 [[nodiscard]] constexpr float_t focal_distance() const noexcept { return _native->focal_distance; }
78
80 [[nodiscard]] constexpr auto reflect() const noexcept {
81 return std::make_tuple(frame_aspect_ratio(), screen_window(), lens_radius(), focal_distance());
82 }
83 };
84
89 struct camera_perspective_params : detail::wrapper<camera_perspective_params, tpbrt_camera_perspective_params_t> {
92
94 using wrapper::wrapper;
95
97 [[nodiscard]] constexpr float_t frame_aspect_ratio() const noexcept { return _native->frame_aspect_ratio; }
98
100 [[nodiscard]] constexpr screen_window_array_type screen_window() const noexcept { return _native->screen_window; }
101
103 [[nodiscard]] constexpr float_t lens_radius() const noexcept { return _native->lens_radius; }
104
106 [[nodiscard]] constexpr float_t focal_distance() const noexcept { return _native->focal_distance; }
107
109 [[nodiscard]] constexpr float_t fov() const noexcept { return _native->fov; }
110
112 [[nodiscard]] constexpr auto reflect() const noexcept {
113 return std::make_tuple(frame_aspect_ratio(), screen_window(), lens_radius(), focal_distance(), fov());
114 }
115 };
116
129
136 [[nodiscard]] constexpr std::string_view to_string(const camera_spherical_mapping mapping) noexcept {
137 using enum camera_spherical_mapping;
138 switch (mapping) {
139 case EQUAL_AREA: return "equalarea";
140 case EQUI_RECTANGULAR: return "equirectangular";
141 case MAX_NUM: return "maxnum";
142 default: return "UNKNOWN";
143 }
144 }
145
150 struct camera_spherical_params : detail::wrapper<camera_spherical_params, tpbrt_camera_spherical_params_t> {
152 using wrapper::wrapper;
153
155 [[nodiscard]] constexpr camera_spherical_mapping mapping() const noexcept {
156 return static_cast<camera_spherical_mapping>(_native->mapping);
157 }
158
160 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(mapping()); }
161 };
162
175
182 [[nodiscard]] constexpr std::string_view to_string(const camera_realistic_aperture_type type) noexcept {
184 switch (type) {
185 case FILE_NAME: return "filename";
186 case BUILTIN: return "builtin";
187 case MAX_NUM: return "maxnum";
188 default: return "UNKNOWN";
189 }
190 }
191
210
217 [[nodiscard]] constexpr std::string_view to_string(const camera_realistic_aperture_builtin builtin) noexcept {
219 switch (builtin) {
220 case CIRCULAR: return "circular";
221 case GAUSSIAN: return "gaussian";
222 case SQUARE: return "square";
223 case PENTAGON: return "pentagon";
224 case STAR: return "star";
225 case MAX_NUM: return "maxnum";
226 default: return "UNKNOWN";
227 }
228 }
229
235 : detail::wrapper<camera_realistic_aperture, tpbrt_camera_realistic_aperture_t>,
236 detail::with_variant<camera_realistic_aperture, camera_realistic_aperture_builtin, string> {
238 using wrapper::wrapper;
239
241 [[nodiscard]] constexpr camera_realistic_aperture_type type() const noexcept {
242 return static_cast<camera_realistic_aperture_type>(_native->type);
243 }
244
246 [[nodiscard]] constexpr bool_t is_file_name() const noexcept {
248 }
249
251 [[nodiscard]] constexpr bool_t is_builtin() const noexcept { return type() == camera_realistic_aperture_type::BUILTIN; }
252
254 [[nodiscard]] constexpr std::optional<string> as_file_name() const noexcept {
255 if (!is_file_name()) { return std::nullopt; }
256 return _native->as.file_name;
257 }
258
260 [[nodiscard]] constexpr std::optional<camera_realistic_aperture_builtin> as_builtin() const noexcept {
261 if (!is_builtin()) { return std::nullopt; }
262 return static_cast<camera_realistic_aperture_builtin>(_native->as.builtin);
263 }
264
266 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
268 switch (type()) {
269 case FILE_NAME: return _native->as.file_name;
270 case BUILTIN: return static_cast<camera_realistic_aperture_builtin>(_native->as.builtin);
271 case MAX_NUM: [[fallthrough]];
272 default: break;
273 }
274 return std::nullopt;
275 }
276
278 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(to_variant(), type()); }
279 };
280
285 struct camera_realistic_params : detail::wrapper<camera_realistic_params, tpbrt_camera_realistic_params_t> {
287 using wrapper::wrapper;
288
290 [[nodiscard]] constexpr string lens_file() const noexcept { return _native->lens_file; }
291
293 [[nodiscard]] constexpr float_t aperture_diameter() const noexcept { return _native->aperture_diameter; }
294
296 [[nodiscard]] constexpr float_t focus_distance() const noexcept { return _native->focus_distance; }
297
299 [[nodiscard]] constexpr camera_realistic_aperture aperture() const noexcept { return _native->aperture; }
300
302 [[nodiscard]] constexpr auto reflect() const noexcept {
303 return std::make_tuple(lens_file(), aperture_diameter(), focus_distance(), aperture());
304 }
305 };
306
311 struct camera : detail::wrapper<camera, tpbrt_camera_t>,
312 detail::with_variant<camera, camera_orthographic_params, camera_perspective_params, camera_spherical_params,
313 camera_realistic_params> {
315 using wrapper::wrapper;
316
318 [[nodiscard]] constexpr float_t shutter_open() const noexcept { return _native->shutter_open; }
319
321 [[nodiscard]] constexpr float_t shutter_close() const noexcept { return _native->shutter_close; }
322
324 [[nodiscard]] constexpr transform_animated transform() const noexcept { return _native->transform; }
325
327 [[nodiscard]] constexpr media_handle interior_media_handle() const noexcept { return _native->interior_media_handle; }
328
330 [[nodiscard]] constexpr media_handle exterior_media_handle() const noexcept { return _native->exterior_media_handle; }
331
333 [[nodiscard]] constexpr camera_type type() const noexcept { return static_cast<camera_type>(_native->type); }
334
336 [[nodiscard]] constexpr bool_t is_orthographic() const noexcept { return type() == camera_type::ORTHOGRAPHIC; }
337
339 [[nodiscard]] constexpr bool_t is_perspective() const noexcept { return type() == camera_type::PERSPECTIVE; }
340
342 [[nodiscard]] constexpr bool_t is_spherical() const noexcept { return type() == camera_type::SPHERICAL; }
343
345 [[nodiscard]] constexpr bool_t is_realistic() const noexcept { return type() == camera_type::REALISTIC; }
346
348 [[nodiscard]] constexpr std::optional<camera_orthographic_params> as_orthographic() const noexcept {
349 if (!is_orthographic()) { return std::nullopt; }
350 return _native->as.orthographic;
351 }
352
354 [[nodiscard]] constexpr std::optional<camera_perspective_params> as_perspective() const noexcept {
355 if (!is_perspective()) { return std::nullopt; }
356 return _native->as.perspective;
357 }
358
360 [[nodiscard]] constexpr std::optional<camera_spherical_params> as_spherical() const noexcept {
361 if (!is_spherical()) { return std::nullopt; }
362 return _native->as.spherical;
363 }
364
366 [[nodiscard]] constexpr std::optional<camera_realistic_params> as_realistic() const noexcept {
367 if (!is_realistic()) { return std::nullopt; }
368 return _native->as.realistic;
369 }
370
372 [[nodiscard]] constexpr variant_type to_variant() const noexcept {
373 using enum camera_type;
374 switch (type()) {
375 case ORTHOGRAPHIC: return _native->as.orthographic;
376 case PERSPECTIVE: return _native->as.perspective;
377 case SPHERICAL: return _native->as.spherical;
378 case REALISTIC: return _native->as.realistic;
379 case MAX_NUM: [[fallthrough]];
380 default: break;
381 }
382 return std::nullopt;
383 }
384
386 [[nodiscard]] constexpr auto reflect() const noexcept {
388 to_variant(), type());
389 }
390 };
391} // namespace tpbrt
392#endif // _TINYPBRT_CAMERA_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.
camera_type
Used to declare camera type.
Definition camera.hpp:25
camera_realistic_aperture_builtin
Realistic camera aperture builtin type.
Definition camera.hpp:196
camera_spherical_mapping
Spherical camera mapping.
Definition camera.hpp:121
camera_realistic_aperture_type
Realistic camera aperture value type.
Definition camera.hpp:167
@ ORTHOGRAPHIC
Orthographic camera.
@ REALISTIC
Realistic camera.
@ SPHERICAL
Spherical camera.
@ PERSPECTIVE
Perspective camera.
@ GAUSSIAN
Gaussian aperture shape.
@ CIRCULAR
Circular aperture shape.
@ PENTAGON
Pentagon aperture shape.
@ EQUAL_AREA
An area-preserving mapping based on an octahedral encoding of the unit sphere is used.
@ EQUI_RECTANGULAR
An equirectangular mapping.
@ FILE_NAME
Aperture will be read from given file specifying an image to be used to specify the shape.
@ BUILTIN
Aperture value is a builtin aperture.
@ TPBRT_CAMERA_SPHERICAL_MAPPING_EQUI_RECTANGULAR
An equirectangular mapping.
Definition camera.h:77
@ TPBRT_CAMERA_SPHERICAL_MAPPING_EQUAL_AREA
An area-preserving mapping based on an octahedral encoding of the unit sphere is used.
Definition camera.h:75
@ TPBRT_CAMERA_SPHERICAL_MAPPING_MAX_NUM
Count of available spherical camera mappings.
Definition camera.h:79
@ TPBRT_CAMERA_REALISTIC_APERTURE_TYPE_BUILTIN
Aperture value is a builtin aperture.
Definition camera.h:99
@ TPBRT_CAMERA_REALISTIC_APERTURE_TYPE_MAX_NUM
Count of available realistic camera apertures.
Definition camera.h:101
@ TPBRT_CAMERA_REALISTIC_APERTURE_TYPE_FILE_NAME
Aperture will be read from given file specifying an image to be used to specify the shape.
Definition camera.h:97
@ TPBRT_CAMERA_REALISTIC_APERTURE_BUILTIN_GAUSSIAN
Gaussian aperture shape.
Definition camera.h:112
@ TPBRT_CAMERA_REALISTIC_APERTURE_BUILTIN_CIRCULAR
Circular aperture shape.
Definition camera.h:110
@ TPBRT_CAMERA_REALISTIC_APERTURE_BUILTIN_MAX_NUM
Count of available realistic camera builtin apertures.
Definition camera.h:120
@ TPBRT_CAMERA_REALISTIC_APERTURE_BUILTIN_SQUARE
Square aperture shape.
Definition camera.h:114
@ TPBRT_CAMERA_REALISTIC_APERTURE_BUILTIN_PENTAGON
Pentagon aperture shape.
Definition camera.h:116
@ TPBRT_CAMERA_REALISTIC_APERTURE_BUILTIN_STAR
Star aperture shape.
Definition camera.h:118
@ TPBRT_CAMERA_TYPE_PERSPECTIVE
Perspective camera.
Definition camera.h:28
@ TPBRT_CAMERA_TYPE_MAX_NUM
Count of available camera types.
Definition camera.h:34
@ TPBRT_CAMERA_TYPE_SPHERICAL
Spherical camera.
Definition camera.h:32
@ TPBRT_CAMERA_TYPE_REALISTIC
Realistic camera.
Definition camera.h:30
@ TPBRT_CAMERA_TYPE_ORTHOGRAPHIC
Orthographic camera.
Definition camera.h:26
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
Generic C++ array view with type conversion (a non owning view on memory owned by the C library).
Definition common.hpp:448
C++ wrapper for tpbrt_camera_orthographic_params_t.
Definition camera.hpp:60
constexpr float_t focal_distance() const noexcept
Returns focal_distance value.
Definition camera.hpp:77
constexpr screen_window_array_type screen_window() const noexcept
Returns screen_window value.
Definition camera.hpp:71
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition camera.hpp:80
constexpr float_t frame_aspect_ratio() const noexcept
Returns frame_aspect_ratio value.
Definition camera.hpp:68
constexpr float_t lens_radius() const noexcept
Returns lens_radius value.
Definition camera.hpp:74
C++ wrapper for tpbrt_camera_perspective_params_t.
Definition camera.hpp:89
constexpr float_t focal_distance() const noexcept
Returns focal_distance value.
Definition camera.hpp:106
constexpr screen_window_array_type screen_window() const noexcept
Returns screen_window value.
Definition camera.hpp:100
constexpr float_t lens_radius() const noexcept
Returns lens_radius value.
Definition camera.hpp:103
constexpr float_t fov() const noexcept
Returns fov value.
Definition camera.hpp:109
constexpr float_t frame_aspect_ratio() const noexcept
Returns frame_aspect_ratio value.
Definition camera.hpp:97
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition camera.hpp:112
C++ wrapper for tpbrt_camera_realistic_aperture_t.
Definition camera.hpp:236
constexpr bool_t is_builtin() const noexcept
Returns true if type is builtin.
Definition camera.hpp:251
constexpr std::optional< string > as_file_name() const noexcept
Returns camera realistic aperture as file name.
Definition camera.hpp:254
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition camera.hpp:278
constexpr camera_realistic_aperture_type type() const noexcept
Returns type value.
Definition camera.hpp:241
constexpr bool_t is_file_name() const noexcept
Returns true if type is file name.
Definition camera.hpp:246
constexpr std::optional< camera_realistic_aperture_builtin > as_builtin() const noexcept
Returns camera realistic aperture as builtin.
Definition camera.hpp:260
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition camera.hpp:266
C++ wrapper for tpbrt_camera_realistic_params_t.
Definition camera.hpp:285
constexpr string lens_file() const noexcept
Returns lens_file value.
Definition camera.hpp:290
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition camera.hpp:302
constexpr float_t aperture_diameter() const noexcept
Returns aperture_diameter value.
Definition camera.hpp:293
constexpr float_t focus_distance() const noexcept
Returns focus_distance value.
Definition camera.hpp:296
constexpr camera_realistic_aperture aperture() const noexcept
Returns aperture value.
Definition camera.hpp:299
C++ wrapper for tpbrt_camera_spherical_params_t.
Definition camera.hpp:150
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition camera.hpp:160
constexpr camera_spherical_mapping mapping() const noexcept
Returns mapping value.
Definition camera.hpp:155
C++ wrapper for tpbrt_camera_t.
Definition camera.hpp:313
constexpr transform_animated transform() const noexcept
Returns transform value.
Definition camera.hpp:324
constexpr media_handle interior_media_handle() const noexcept
Returns interior_media_handle value.
Definition camera.hpp:327
constexpr float_t shutter_close() const noexcept
Returns shutter_close value.
Definition camera.hpp:321
constexpr bool_t is_orthographic() const noexcept
Returns true if type is orthographic.
Definition camera.hpp:336
constexpr bool_t is_realistic() const noexcept
Returns true if type is realistic.
Definition camera.hpp:345
constexpr camera_type type() const noexcept
Returns type value.
Definition camera.hpp:333
constexpr std::optional< camera_spherical_params > as_spherical() const noexcept
Returns camera parameters as spherical.
Definition camera.hpp:360
constexpr std::optional< camera_orthographic_params > as_orthographic() const noexcept
Returns camera parameters as orthographic.
Definition camera.hpp:348
constexpr std::optional< camera_perspective_params > as_perspective() const noexcept
Returns camera parameters as perspective.
Definition camera.hpp:354
constexpr std::optional< camera_realistic_params > as_realistic() const noexcept
Returns camera parameters as realistic.
Definition camera.hpp:366
constexpr bool_t is_spherical() const noexcept
Returns true if type is spherical.
Definition camera.hpp:342
constexpr float_t shutter_open() const noexcept
Returns shutter_open value.
Definition camera.hpp:318
constexpr media_handle exterior_media_handle() const noexcept
Returns exterior_media_handle value.
Definition camera.hpp:330
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition camera.hpp:386
constexpr variant_type to_variant() const noexcept
Conversion to variant.
Definition camera.hpp:372
constexpr bool_t is_perspective() const noexcept
Returns true if type is perspective.
Definition camera.hpp:339
C++ wrapper for tpbrt_media_handle_t.
Definition media.hpp:458
C++ wrapper for tpbrt_transform_animated_t.
Definition transform.hpp:39