star-camera

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

commit bbc8a9158df1ce3e8165f0e9e45b5163f09d71f1
parent 492e84e43b5158e4c46dd8f33e2a4f86fda833ba
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 29 Jul 2021 16:29:45 +0200

Test the orthographic pinhole camera

Diffstat:
Mcmake/CMakeLists.txt | 7++++---
Msrc/scam_orthographic.c | 4++--
Msrc/test_scam_cbox.c | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/test_scam_orthographic_pinhole.c | 2+-
4 files changed, 94 insertions(+), 35 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -79,7 +79,7 @@ if(NOT NO_TEST) function(new_test _name) build_test(${_name}) - add_test(${_name}_${_palette} ${_name}) + add_test(${_name} ${_name}) endfunction() new_test(test_scam_orthographic_pinhole) @@ -90,8 +90,9 @@ if(NOT NO_TEST) 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) + add_test(test_scam_cbox_orthographic_pinhole test_scam_cbox orthographic pinhole) + add_test(test_scam_cbox_perspective_pinhole test_scam_cbox perspective pinhole) + add_test(test_scam_cbox_perspective_thin_lens test_scam_cbox perspective thin-lens) endif() endif() diff --git a/src/scam_orthographic.c b/src/scam_orthographic.c @@ -130,7 +130,7 @@ pinhole_generate_ray /* Setup the ray direction to the image plane normal, i.e. the z axis of the * camera */ - d3_set(ray->dir, cam->param.ortho.camera2world+9); + d3_set(ray->dir, cam->param.ortho.camera2world+6); } static INLINE void @@ -174,7 +174,7 @@ thin_lens_generate_ray /* Transform the ray from camera space to world space */ d33_muld3(ray->dir, cam->param.ortho.camera2world, ray->dir); d33_muld3(ray->org, cam->param.ortho.camera2world, ray->org); - d3_add(ray->org, cam->param.persp.position, ray->org); + d3_add(ray->org, cam->param.ortho.position, ray->org); } /******************************************************************************* diff --git a/src/test_scam_cbox.c b/src/test_scam_cbox.c @@ -31,11 +31,16 @@ #define IMG_HEIGHT 480 #define IMG_SPP 16 -enum camera_model { +enum lens_model { PINHOLE, THIN_LENS }; +enum camera_model { + ORTHOGRAPHIC, + PERSPECTIVE +}; + static struct s3d_scene_view* create_s3d_scene_view(void) { @@ -66,6 +71,69 @@ create_s3d_scene_view(void) } static void +create_perspective(const enum lens_model lens_model, struct scam** cam) +{ + struct scam_perspective_args args = SCAM_PERSPECTIVE_ARGS_DEFAULT; + CHK(cam); + + 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; + + switch(lens_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); +} + +static void +create_orthographic(const enum lens_model lens_model, struct scam** cam) +{ + struct scam_orthographic_args args = SCAM_ORTHOGRAPHIC_ARGS_DEFAULT; + CHK(cam); + + 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.height = 500; + args.aspect_ratio = (double)IMG_WIDTH/(double)IMG_HEIGHT; + + switch(lens_model) { + case PINHOLE: + args.lens_radius = 0; + break; + case THIN_LENS: + CHK(0 == 1); /* Not implemented yet */ + break; + default: FATAL("Unreachable code.\n"); break; + } + CHK(scam_create_orthographic(NULL, NULL, 1, &args, cam) == RES_OK); +} + + +static void draw (const struct scam* cam, struct s3d_scene_view* view, @@ -136,54 +204,44 @@ draw int main(int argc, char** argv) { - struct scam_perspective_args args = SCAM_PERSPECTIVE_ARGS_DEFAULT; struct s3d_scene_view* view = NULL; struct scam* cam = NULL; struct image img; enum camera_model cam_model; + enum lens_model lens_model; int err = 0; - if(argc <= 1) { - fprintf(stderr, "Usage: %s <pinhole|thin-lens>\n", argv[0]); + if(argc <= 2) { + fprintf(stderr, "Usage: %s <orthographic|perspective> <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; + if(!strcmp(argv[1], "orthographic")) { + cam_model = ORTHOGRAPHIC; + } else if(!strcmp(argv[1], "perspective")) { + cam_model = PERSPECTIVE; } else { fprintf(stderr, "Invalid camera model `%s'.\n", argv[1]); goto error; } - view = create_s3d_scene_view(); + if(!strcmp(argv[2], "pinhole")){ + lens_model = PINHOLE; + } else if(!strcmp(argv[2], "thin-lens")) { + lens_model = THIN_LENS; + } else { + fprintf(stderr, "Invalid lens model `%s'.\n", argv[2]); + goto error; + } - 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; + view = create_s3d_scene_view(); switch(cam_model) { - case PINHOLE: - args.lens_radius = 0; - break; - case THIN_LENS: - args.lens_radius = 5; - args.focal_distance = 300; - break; + case ORTHOGRAPHIC: create_orthographic(lens_model, &cam); break; + case PERSPECTIVE: create_perspective(lens_model, &cam); break; default: FATAL("Unreachable code.\n"); break; } - CHK(scam_create_perspective(NULL, NULL, 1, &args, &cam) == RES_OK); - image_init(NULL, &img); CHK(image_setup (&img, IMG_WIDTH, IMG_HEIGHT, IMG_WIDTH*3, IMAGE_RGB8, NULL) == RES_OK); diff --git a/src/test_scam_orthographic_pinhole.c b/src/test_scam_orthographic_pinhole.c @@ -113,7 +113,7 @@ main(int argc, char** argv) CHK(scam_generate_ray(cam, &sample, &ray) == RES_OK); /* Check the ray direction */ - CHK(d3_eq_eps(ray.dir, axis_z, 1.e-6) == RES_OK); + CHK(d3_eq_eps(ray.dir, axis_z, 1.e-6)); /* Transform the ray origin in camera space */ d3_sub(pos, ray.org, args.position);