#include <cstdio>
#include <type_traits>
namespace {
void print_spectrum(
const char*
const label,
const tpbrt::spectrum spectrum) {
std::printf("%s ", label);
spectrum.visit([](const auto& value) {
using T = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<T, tpbrt::rgb>) { std::printf("rgb(%g, %g, %g)", value.r(), value.g(), value.b()); }
else if constexpr (std::is_same_v<T, tpbrt::blackbody>) { std::printf("blackbody %g K", value.temperature()); }
else if constexpr (std::is_same_v<T, tpbrt::spectrum_builtin>) {
}
else if constexpr (std::is_same_v<T, tpbrt::float_t>) { std::printf("constant %g", value); }
else if constexpr (std::is_same_v<T, tpbrt::wavelength_array>) { std::printf("%zu samples", value.size()); }
else { std::printf("file %.*s", static_cast<int>(value.size()), value.data()); }
});
std::printf("\n");
}
}
int main(const int argc, const char* const* const argv) {
if (argc < 2) {
std::fprintf(stderr, "usage: %s <scene.pbrt>\n", argv[0]);
return 1;
}
if (!scene) {
std::fprintf(stderr,
"cannot load %s: %s\n", argv[1],
tpbrt::to_string(scene.get_error()).c_str());
return 1;
}
if (const auto perspective = scene->camera().as_perspective()) { std::printf(" (fov %g)", perspective->fov()); }
std::printf(
"\nfilm: %s %ux%u -> %.*s\n",
tpbrt::to_string(scene->film().type()).data(), scene->film().x_resolution(),
scene->film().y_resolution(), static_cast<int>(scene->film().file_name().size()), scene->film().file_name().data());
std::printf(
"integrator: %s\n",
tpbrt::to_string(scene->integrator().type()).data());
std::printf(
"filter: %s (radius %g x %g)\n",
tpbrt::to_string(scene->filter().type()).data(), scene->filter().x_radius(),
scene->filter().y_radius());
std::printf(
"light: %s, scale %g\n",
tpbrt::to_string(light.type()).data(), light.scale());
if (const auto infinite = light.as_infinite()) { print_spectrum(" L", infinite->l()); }
if (
const auto point = light.as_point()) { print_spectrum(
" I",
point->i()); }
}
if (light.power().has_value()) { std::printf(", power %g W", light.power().value()); }
std::printf("\n");
if (const auto diffuse = light.as_diffuse()) { print_spectrum(" L", diffuse->l()); }
}
std::printf("texture: \"%.*s\" %s %s, mapping %s\n", static_cast<int>(texture.name().size()),
}
return 0;
}
constexpr std::string_view to_string(const accelerator_type type) noexcept
Converts accelerator_type enum value to string.
Definition accelerator.hpp:39
point3 point
C++ wrapper for tpbrt_point_t.
Definition fwd.hpp:172
result< scene > load_scene_from_file(const std::string &filepath)
Loads scene from given file.
Definition scene.hpp:198
C++ wrapper for tpbrt_area_light_t.
Definition light.hpp:357
C++ wrapper for tpbrt_light_source_t.
Definition light.hpp:206
C++ wrapper for tpbrt_spectrum_t.
Definition color.hpp:270
C++ wrapper for tpbrt_texture_t.
Definition texture.hpp:696