tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
examples/scene_info/main.c
#include <stdio.h>
#include <example_utils.h>
static void print_camera(const tpbrt_scene_t* const scene) {
const tpbrt_camera_t* const camera = &scene->camera;
printf("camera: %s", EXAMPLE_NAME(example_camera_names, camera->type));
switch (camera->type) {
printf(" fov=%g lensradius=%g focaldistance=%g", camera->as.perspective.fov, camera->as.perspective.lens_radius,
break;
printf(" screenwindow=[%g %g %g %g]", camera->as.orthographic.screen_window[0],
break;
printf(" lensfile=\"" EXAMPLE_STR_FMT "\" aperturediameter=%g", EXAMPLE_STR_ARG(camera->as.realistic.lens_file),
break;
default: break;
}
printf(" shutter=[%g, %g]\n", camera->shutter_open, camera->shutter_close);
const tpbrt_mat4_t* start = TPBRT_NULL;
const tpbrt_mat4_t* end = TPBRT_NULL;
if (start != TPBRT_NULL && end != TPBRT_NULL) {
// NOLINTBEGIN(readability-magic-numbers)
printf(" position start=(%g %g %g) end=(%g %g %g)%s\n", start->m[3], start->m[7], start->m[11], end->m[3],
end->m[7], end->m[11], start == end ? "" : " (animated)");
// NOLINTEND(readability-magic-numbers)
}
}
static void print_film(const tpbrt_film_t* const film) {
printf("film: %s %ux%u -> \"" EXAMPLE_STR_FMT "\" iso=%g diagonal=%gmm\n",
EXAMPLE_NAME(example_film_names, film->type), film->x_resolution, film->y_resolution, EXAMPLE_STR_ARG(film->file_name),
film->iso, film->diagonal);
printf(" cropwindow=[%g %g %g %g]\n", film->crop_window[0], film->crop_window[1], film->crop_window[2],
film->crop_window[3]);
}
static void print_sampler(const tpbrt_sampler_t* const sampler) {
printf("sampler: %s", EXAMPLE_NAME(example_sampler_names, sampler->type));
switch (sampler->type) {
case TPBRT_SAMPLER_TYPE_HALTON: printf(" pixelsamples=%u", sampler->as.halton.pixel_samples); break;
case TPBRT_SAMPLER_TYPE_INDEPENDENT: printf(" pixelsamples=%u", sampler->as.independent.pixel_samples); break;
case TPBRT_SAMPLER_TYPE_PADDED_SOBOL: printf(" pixelsamples=%u", sampler->as.padded_sobol.pixel_samples); break;
case TPBRT_SAMPLER_TYPE_SOBOL: printf(" pixelsamples=%u", sampler->as.sobol.pixel_samples); break;
case TPBRT_SAMPLER_TYPE_Z_SOBOL: printf(" pixelsamples=%u", sampler->as.z_sobol.pixel_samples); break;
printf(" %ux%u jitter=%s", sampler->as.stratified.x_samples, sampler->as.stratified.y_samples,
sampler->as.stratified.jitter ? "true" : "false");
break;
default: break;
}
printf(" seed=%d\n", (int)sampler->seed);
}
static void print_integrator(const tpbrt_integrator_t* const integrator) {
printf("integrator: %s", EXAMPLE_NAME(example_integrator_names, integrator->type));
switch (integrator->type) {
case TPBRT_INTEGRATOR_TYPE_VOL_PATH: printf(" maxdepth=%u", integrator->as.vol_path.max_depth); break;
case TPBRT_INTEGRATOR_TYPE_PATH: printf(" maxdepth=%u", integrator->as.path.max_depth); break;
case TPBRT_INTEGRATOR_TYPE_BDPT: printf(" maxdepth=%u", integrator->as.bdpt.max_depth); break;
printf(" maxdepth=%u radius=%g", integrator->as.sppm.max_depth, integrator->as.sppm.radius);
break;
default: break;
}
printf("\n");
}
int main(const int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "usage: %s scene.pbrt\n", argv[0]);
return 1;
}
const tpbrt_error_t err = tpbrt_scene_load_from_file(argv[1], &scene);
if (err != TPBRT_ERROR_NONE) {
example_print_error(argv[1], err);
return 1;
}
print_camera(&scene);
print_film(&scene.film);
print_sampler(&scene.sampler);
print_integrator(&scene.integrator);
printf("filter: %s radius=(%g, %g)\n", EXAMPLE_NAME(example_filter_names, scene.filter.type), scene.filter.x_radius,
scene.filter.y_radius);
printf("accelerator: %s\n", EXAMPLE_NAME(example_accelerator_names, scene.accelerator.type));
printf("time: [%g, %g]\n", scene.start_time, scene.end_time);
size_t shapes_by_type[TPBRT_SHAPE_TYPE_MAX_NUM] = { 0 };
for (size_t i = 0; i < scene.shapes.count; ++i) { ++shapes_by_type[scene.shapes.shapes[i].type]; }
size_t object_shapes = 0u;
for (size_t o = 0; o < scene.objects.count; ++o) {
const tpbrt_shapes_list_t children = scene.objects.objects[o].children;
for (size_t i = 0; i < children.count; ++i) { ++shapes_by_type[children.shapes[i].type]; }
object_shapes += children.count;
}
printf("\nshapes: %zu (+%zu inside %zu object(s), %zu instance(s))\n", scene.shapes.count, object_shapes,
scene.objects.count, scene.instances.count);
for (unsigned t = 0; t < TPBRT_SHAPE_TYPE_MAX_NUM; ++t) {
if (shapes_by_type[t] != 0u) { printf(" %-14s %zu\n", EXAMPLE_NAME(example_shape_names, t), shapes_by_type[t]); }
}
printf("materials: %zu\n", scene.materials.count);
for (size_t i = 0; i < scene.materials.count; ++i) {
const tpbrt_material_t* const m = &scene.materials.materials[i];
printf(" %-14s \"" EXAMPLE_STR_FMT "\"\n", EXAMPLE_NAME(example_material_names, m->type), EXAMPLE_STR_ARG(m->name));
}
printf("textures: %zu\n", scene.textures.count);
for (size_t i = 0; i < scene.textures.count; ++i) {
const tpbrt_texture_t* const t = &scene.textures.textures[i];
printf(" %-14s \"" EXAMPLE_STR_FMT "\" (%s)\n", EXAMPLE_NAME(example_texture_class_names, t->tex_class),
EXAMPLE_STR_ARG(t->name), t->type == TPBRT_TEXTURE_TYPE_FLOAT ? "float" : "spectrum");
}
printf("media: %zu\n", scene.medias.count);
for (size_t i = 0; i < scene.medias.count; ++i) {
const tpbrt_media_t* const m = &scene.medias.medias[i];
printf(" %-14s \"" EXAMPLE_STR_FMT "\"\n", EXAMPLE_NAME(example_media_names, m->type), EXAMPLE_STR_ARG(m->name));
}
printf("lights: %zu light source(s), %zu area light(s)\n", scene.lights.lights_sources.count,
return 0;
}
@ TPBRT_CAMERA_TYPE_PERSPECTIVE
Perspective camera.
Definition camera.h:28
@ TPBRT_CAMERA_TYPE_REALISTIC
Realistic camera.
Definition camera.h:30
@ TPBRT_CAMERA_TYPE_ORTHOGRAPHIC
Orthographic camera.
Definition camera.h:26
tpbrt_error_t
Error type (used as result type where success = TPBRT_ERROR_NONE = 0).
Definition error.h:20
@ TPBRT_ERROR_NONE
No error -> Success.
Definition error.h:22
@ TPBRT_INTEGRATOR_TYPE_VOL_PATH
Volumetric path tracing.
Definition integrator.h:40
@ TPBRT_INTEGRATOR_TYPE_PATH
Path tracing.
Definition integrator.h:30
@ TPBRT_INTEGRATOR_TYPE_BDPT
Bidirectional path tracing.
Definition integrator.h:24
@ TPBRT_INTEGRATOR_TYPE_SPPM
Stochastic progressive photon mapping.
Definition integrator.h:38
@ TPBRT_SAMPLER_TYPE_INDEPENDENT
Independent sampler.
Definition sampler.h:24
@ TPBRT_SAMPLER_TYPE_HALTON
Halton sampler.
Definition sampler.h:22
@ TPBRT_SAMPLER_TYPE_SOBOL
Sobol sampler.
Definition sampler.h:28
@ TPBRT_SAMPLER_TYPE_STRATIFIED
Stratified sampler.
Definition sampler.h:30
@ TPBRT_SAMPLER_TYPE_Z_SOBOL
Z-Sobol sampler.
Definition sampler.h:32
@ TPBRT_SAMPLER_TYPE_PADDED_SOBOL
Padded sobol sampler.
Definition sampler.h:26
void tpbrt_scene_free(tpbrt_scene_t *scene)
Free all scene resources.
tpbrt_error_t tpbrt_scene_load_from_file(const tpbrt_char_t *filepath, tpbrt_scene_t *out_scene)
Loads scene from given file.
@ TPBRT_SHAPE_TYPE_MAX_NUM
Count of available shape types.
Definition shape.h:44
@ TPBRT_TEXTURE_TYPE_FLOAT
Float texture.
Definition texture.h:58
#define TPBRT_NULL
NULL value.
Definition fwd.h:19
tpbrt_error_t tpbrt_get_transform(const tpbrt_transforms_list_t *transforms, tpbrt_transform_handle_t handle, const tpbrt_mat4_t **transform)
Returns pointer to transform to which handle is provided.
tpbrt_accelerator_type_t type
Accelerator type.
Definition accelerator.h:88
tpbrt_size_t count
Number of area lights in list.
Definition light.h:231
tpbrt_float_t screen_window[4]
The bounds of the film plane in screen space.
Definition camera.h:45
tpbrt_float_t focal_distance
The focal distance of the lens. If "lensradius" is zero, this has no effect. Otherwise,...
Definition camera.h:64
tpbrt_float_t fov
Specifies the field of view for the perspective camera. This is the spread angle of the viewing frust...
Definition camera.h:66
tpbrt_float_t lens_radius
The radius of the lens.
Definition camera.h:62
tpbrt_string_t lens_file
Specifies the name of a lens description file that gives the collection of lens elements in the lens ...
Definition camera.h:146
tpbrt_float_t aperture_diameter
Diameter of the lens system's aperture, specified in mm. The smaller the aperture,...
Definition camera.h:148
PBRT Camera representation.
Definition camera.h:159
tpbrt_float_t shutter_close
The time at which the virtual camera shutter closes.
Definition camera.h:163
tpbrt_camera_perspective_params_t perspective
Perspective camera parameters.
Definition camera.h:176
union tpbrt_camera_t::@2 as
Initialized value depends on current type value.
tpbrt_transform_animated_t transform
Transform handle.
Definition camera.h:165
tpbrt_camera_type_t type
Camera type.
Definition camera.h:184
tpbrt_float_t shutter_open
The time at which the virtual camera shutter opens.
Definition camera.h:161
tpbrt_camera_realistic_params_t realistic
Realistic camera parameters.
Definition camera.h:180
tpbrt_camera_orthographic_params_t orthographic
Orthographic camera parameters.
Definition camera.h:174
PBRT film representation.
Definition film.h:105
tpbrt_float_t iso
Film sensitivity to light; final pixel values are scaled by the "iso" value divided by 100.
Definition film.h:119
tpbrt_string_t file_name
The output filename.
Definition film.h:111
tpbrt_uint_t y_resolution
The number of pixels in the y direction.
Definition film.h:115
tpbrt_uint_t x_resolution
The number of pixels in the x direction.
Definition film.h:113
tpbrt_float_t crop_window[4]
The sub-region of the image to render. The four values specified should be fractions in the range [0,...
Definition film.h:107
tpbrt_float_t diagonal
Diagonal length of the film, in mm. (This value is only used when the RealisticCamera is used....
Definition film.h:117
tpbrt_film_type_t type
Film type.
Definition film.h:134
tpbrt_float_t y_radius
The width of the filter in the y direction.
Definition filter.h:72
tpbrt_filter_type_t type
filter type.
Definition filter.h:85
tpbrt_float_t x_radius
The width of the filter in the x direction.
Definition filter.h:70
tpbrt_uint_t max_depth
Maximum length of a light-carrying path sampled by the integrator.
Definition integrator.h:77
tpbrt_uint_t max_depth
Maximum length of a light-carrying path sampled by the integrator.
Definition integrator.h:122
tpbrt_uint_t max_depth
Maximum length of a light-carrying path sampled by the integrator.
Definition integrator.h:166
tpbrt_float_t radius
Initial photon search radius. (This value will be reduced as photons are accumulated at each pixel....
Definition integrator.h:170
PBRT integrator representation.
Definition integrator.h:192
tpbrt_integrator_path_params_t path
Path integrator parameters.
Definition integrator.h:204
tpbrt_integrator_sppm_params_t sppm
SPPM integrator parameters.
Definition integrator.h:212
tpbrt_integrator_type_t type
Value type.
Definition integrator.h:218
tpbrt_integrator_vol_path_params_t vol_path
VOL path integrator parameters.
Definition integrator.h:214
tpbrt_integrator_bdpt_params_t bdpt
BDPT integrator parameters.
Definition integrator.h:198
union tpbrt_integrator_t::@6 as
Value dependent on type value.
tpbrt_uint_t max_depth
Maximum length of a light-carrying path sampled by the integrator.
Definition integrator.h:181
tpbrt_area_lights_list_t area_lights
List of area lights.
Definition light.h:242
tpbrt_lights_sources_list_t lights_sources
List of light sources.
Definition light.h:240
tpbrt_size_t count
Number of light sources in list.
Definition light.h:220
4 by 4 row-major matrix.
Definition math.h:181
tpbrt_float_t m[16u]
Array of 16 elements.
Definition math.h:210
PBRT material representation.
Definition material.h:376
tpbrt_material_type_t type
Material value type.
Definition material.h:409
tpbrt_string_t name
Material name (if it is not named material name is empty).
Definition material.h:380
tpbrt_size_t count
Number of materials in list.
Definition material.h:420
tpbrt_material_t * materials
Materials list data.
Definition material.h:418
PBRT media representation.
Definition media.h:208
tpbrt_string_t name
Media name.
Definition media.h:214
tpbrt_media_type_t type
Media value type.
Definition media.h:231
tpbrt_size_t count
Number of media items in list.
Definition media.h:251
tpbrt_media_t * medias
Medias list items.
Definition media.h:249
tpbrt_shapes_list_t children
Objects shapes.
Definition object.h:28
tpbrt_size_t count
Number of objects instances in list.
Definition object_instance.h:38
tpbrt_object_t * objects
Objects in list.
Definition object.h:39
tpbrt_size_t count
Number of objects in list.
Definition object.h:41
tpbrt_uint_t pixel_samples
The number of samples to take in each pixel.
Definition sampler.h:60
tpbrt_uint_t pixel_samples
The number of samples to take in each pixel.
Definition sampler.h:71
tpbrt_uint_t pixel_samples
The number of samples to take in each pixel.
Definition sampler.h:80
tpbrt_uint_t pixel_samples
The number of samples to take in each pixel.
Definition sampler.h:91
tpbrt_bool_t jitter
Whether or not the generated samples should be jittered inside each stratum; this is generally only w...
Definition sampler.h:106
tpbrt_uint_t x_samples
The number of samples per pixel to take in the x direction.
Definition sampler.h:102
tpbrt_uint_t y_samples
The number of samples per pixel to take in the y direction. In general, "xsamples" and "ysamples" sho...
Definition sampler.h:104
PBRT sampler representation.
Definition sampler.h:124
tpbrt_sampler_padded_sobol_params_t padded_sobol
Padded sobol sampler parameters.
Definition sampler.h:135
tpbrt_sampler_stratified_params_t stratified
Stratified sampler parameters.
Definition sampler.h:139
union tpbrt_sampler_t::@22 as
Value dependent on type value.
tpbrt_sampler_type_t type
Sampler value type.
Definition sampler.h:145
tpbrt_sampler_sobol_params_t sobol
Sobol sampler parameters.
Definition sampler.h:137
tpbrt_sampler_independent_params_t independent
Independent sampler parameters.
Definition sampler.h:133
tpbrt_sampler_z_sobol_params_t z_sobol
Z-Sobol sampler parameters.
Definition sampler.h:141
tpbrt_int_t seed
A seed to use for the pseudorandom number generator. The default seed value is zero,...
Definition sampler.h:126
tpbrt_sampler_halton_params_t halton
Halton sampler parameters.
Definition sampler.h:131
tpbrt_uint_t pixel_samples
The number of samples to take in each pixel.
Definition sampler.h:115
PBRT scene representation.
Definition scene.h:38
tpbrt_camera_t camera
Scene camera.
Definition scene.h:43
tpbrt_filter_t filter
Scene filter.
Definition scene.h:55
tpbrt_film_t film
Scene film.
Definition scene.h:45
tpbrt_shapes_list_t shapes
List with all scene shapes.
Definition scene.h:68
tpbrt_transforms_list_t transforms
List with all unique transforms.
Definition scene.h:74
tpbrt_sampler_t sampler
Scene sampler.
Definition scene.h:51
tpbrt_float_t start_time
Scene animation start time.
Definition scene.h:53
tpbrt_lights_list_t lights
List with all scene lights.
Definition scene.h:66
tpbrt_materials_list_t materials
List with all scene materials.
Definition scene.h:62
tpbrt_float_t end_time
Scene animation end time.
Definition scene.h:57
tpbrt_textures_list_t textures
List with all scene textures.
Definition scene.h:60
tpbrt_accelerator_t accelerator
Scene accelerator.
Definition scene.h:49
tpbrt_medias_list_t medias
List with all scene medias.
Definition scene.h:64
tpbrt_objects_list_t objects
List with all scene objects.
Definition scene.h:70
tpbrt_objects_instances_list_t instances
List with all scene objects instances.
Definition scene.h:72
tpbrt_integrator_t integrator
Scene integrator.
Definition scene.h:47
tpbrt_shape_type_t type
Shape value type.
Definition shape.h:232
List of shapes.
Definition shape.h:261
tpbrt_size_t count
Number of shapes in list.
Definition shape.h:265
tpbrt_shape_t * shapes
Shapes list data.
Definition shape.h:263
PBRT texture representation.
Definition texture.h:376
tpbrt_string_t name
Texture name.
Definition texture.h:386
tpbrt_texture_type_t type
Texture type.
Definition texture.h:380
tpbrt_texture_class_t tex_class
Texture class.
Definition texture.h:382
tpbrt_texture_t * textures
Textures list data.
Definition texture.h:437
tpbrt_size_t count
Number of textures in list.
Definition texture.h:439
tpbrt_transform_handle_t start_transform
Handle to starting transform.
Definition transform.h:34
tpbrt_transform_handle_t end_transform
Handle to ending transform.
Definition transform.h:36