star-camera

Camera models
git clone git://git.meso-star.fr/star-camera.git
Log | Files | Refs | README | LICENSE

commit 57605ea5785e9e384689d9519b280a5af8a7a0e2
parent a48466167528bd2e8d2f4c5bebf0f4b54c19d326
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 27 Jul 2021 14:37:44 +0200

Test the CBox rendering with the thin lens model

Diffstat:
Mcmake/CMakeLists.txt | 5++++-
Msrc/test_scam_cbox.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/test_scam_cbox.h | 8++++----
3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -85,8 +85,11 @@ if(NOT NO_TEST) new_test(test_scam_thin_lens) if(Star3D_FOUND) - new_test(test_scam_cbox) + build_test(test_scam_cbox) target_link_libraries(test_scam_cbox Star3D) + + add_test(test_scam_cbox_pinhole test_scam_cbox pinhole) + add_test(test_scam_cbox_thin_lens test_scam_cbox thin-lens) endif() endif() diff --git a/src/test_scam_cbox.c b/src/test_scam_cbox.c @@ -25,10 +25,17 @@ #include <rsys/image.h> #include <rsys/mem_allocator.h> +#include <string.h> + #define IMG_WIDTH 640 #define IMG_HEIGHT 480 #define IMG_SPP 16 +enum camera_model { + PINHOLE, + THIN_LENS +}; + static struct s3d_scene_view* create_s3d_scene_view(void) { @@ -91,6 +98,8 @@ draw /* Generate the camera ray */ sample.film[0] = ((double)x + rand_canonical()) * pixsz[0]; sample.film[1] = ((double)y + rand_canonical()) * pixsz[1]; + sample.lens[0] = rand_canonical(); + sample.lens[1] = rand_canonical(); CHK(scam_generate_ray(cam, &sample, &ray) == RES_OK); /* Trace the ray */ @@ -131,15 +140,48 @@ main(int argc, char** argv) struct s3d_scene_view* view = NULL; struct scam* cam = NULL; struct image img; - (void)argc, (void)argv; + enum camera_model cam_model; + int err = 0; + + if(argc <= 1) { + fprintf(stderr, "Usage: %s <pinhole|thin-lens>\n", argv[0]); + goto error; + } + + if(!strcmp(argv[1], "pinhole")){ + cam_model = PINHOLE; + } else if(!strcmp(argv[1], "thin-lens")) { + cam_model = THIN_LENS; + } else { + fprintf(stderr, "Invalid camera model `%s'.\n", argv[1]); + goto error; + } view = create_s3d_scene_view(); - d3(args.position, 276.0, -700.0, 273.0); - d3(args.target, 276.0, 0.0, 273.0); - d3(args.up, 0, 0, 1); + args.position[0] = 89.66; + args.position[1] = 21.89; + args.position[2] = 202.22; + args.target[0] = 150.03; + args.target[1] = 135; + args.target[2] = 196.87; + args.up[0] = 0; + args.up[1] = 0; + args.up[2] = 1; + args.field_of_view = 1.22173047639603070383; /* ~70 degrees */ args.aspect_ratio = (double)IMG_WIDTH/(double)IMG_HEIGHT; - args.field_of_view = PI*0.25; + + switch(cam_model) { + case PINHOLE: + args.lens_radius = 0; + break; + case THIN_LENS: + args.lens_radius = 5; + args.focal_distance = 300; + break; + default: FATAL("Unreachable code.\n"); break; + } + CHK(scam_create_perspective(NULL, NULL, 1, &args, &cam) == RES_OK); image_init(NULL, &img); @@ -154,6 +196,10 @@ main(int argc, char** argv) CHK(scam_ref_put(cam) == RES_OK); image_release(&img); +exit: CHK(mem_allocated_size() == 0); - return 0; + return err; +error: + err = 1; + goto exit; } diff --git a/src/test_scam_cbox.h b/src/test_scam_cbox.h @@ -109,7 +109,7 @@ const double cbox_cols[] = { const unsigned cbox_nvtxs = sizeof(cbox_vtxs) / sizeof(float[3]); const unsigned cbox_ntris = sizeof(cbox_tris) / sizeof(unsigned[3]); STATIC_ASSERT - ( sizeof(cbox_tris)/sizeof(unsigned[3]) + ( sizeof(cbox_tris)/sizeof(unsigned[3]) == sizeof(cbox_cols)/sizeof(double[3]), Unexpected_data_layout); /******************************************************************************* @@ -132,9 +132,9 @@ cbox_get_tri(const unsigned itri, unsigned tri[3], void* data) const unsigned id = itri * 3; (void)data; CHK(itri < cbox_ntris); - tri[0] = cbox_tris[id+0]; - tri[1] = cbox_tris[id+1]; - tri[2] = cbox_tris[id+2]; + tri[0] = cbox_tris[id+0]; + tri[1] = cbox_tris[id+1]; + tri[2] = cbox_tris[id+2]; } static INLINE void