commit a48466167528bd2e8d2f4c5bebf0f4b54c19d326
parent 30ba1221268c7ecf0d4d7d92909dd1fbe2c59c44
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 27 Jul 2021 09:14:13 +0200
Test the ray generation for the thin lens model
Diffstat:
3 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/src/scam_perspective.c b/src/scam_perspective.c
@@ -221,7 +221,7 @@ scam_create_perspective
res = setup_perspective(cam, args);
if(res != RES_OK) goto error;
- exit:
+exit:
if(out_cam) *out_cam = cam;
return res;
error:
diff --git a/src/test_scam_pinhole.c b/src/test_scam_pinhole.c
@@ -154,6 +154,7 @@ main(int argc, char** argv)
CHK(d3_eq(ray.org, args.position));
/* Check that the generated ray is in the view frustum */
+ CHK(d3_is_normalized(ray.dir));
cos_ray_axis_x = d3_dot(ray.dir, axis_x);
cos_ray_axis_y = d3_dot(ray.dir, axis_y);
cos_ray_axis_z = d3_dot(ray.dir, axis_z);
diff --git a/src/test_scam_thin_lens.c b/src/test_scam_thin_lens.c
@@ -18,7 +18,9 @@
#include "scam.h"
#include "test_scam_utils.h"
+#include <rsys/double2.h>
#include <rsys/double3.h>
+#include <rsys/double33.h>
#include <rsys/math.h>
#include <rsys/mem_allocator.h>
@@ -31,6 +33,7 @@ main(int argc, char** argv)
struct scam_ray ray = SCAM_RAY_NULL;
const size_t nsamps = 1000;
size_t i;
+ double transform[9];
double axis_x[3];
double axis_y[3];
double axis_z[3];
@@ -95,6 +98,12 @@ main(int argc, char** argv)
sin_hori_hfov = sin(hori_hfov);
sin_vert_hfov = sin(args.field_of_view*0.5);
+ /* Compute the world to camera space transformation */
+ d3_set(transform + 0, axis_x);
+ d3_set(transform + 3, axis_y);
+ d3_set(transform + 6, axis_z);
+ d33_transpose(transform, transform);
+
sample.lens[0] = nextafterf(0, -1);
CHK(scam_generate_ray(cam, &sample, &ray) == RES_BAD_ARG);
sample.lens[0] = 1;
@@ -112,22 +121,43 @@ main(int argc, char** argv)
double cos_ray_axis_x;
double cos_ray_axis_y;
double cos_ray_axis_z;
+ double dir[3];
+ double pos[3];
+ double dst;
+
sample.film[0] = rand_canonical();
sample.film[1] = rand_canonical();
sample.lens[0] = rand_canonical();
sample.lens[1] = rand_canonical();
CHK(scam_generate_ray(cam, &sample, &ray) == RES_OK);
- /* Check that the ray origin lies on the lens */
- /*CHK(d3_eq(ray.org, args.position));*/
-
- /* Check that the generated ray is in the view frustum */
- /*cos_ray_axis_x = d3_dot(ray.dir, axis_x);
- cos_ray_axis_y = d3_dot(ray.dir, axis_y);
- cos_ray_axis_z = d3_dot(ray.dir, axis_z);
+ /* Transform the position in camera space */
+ d3_sub(pos, ray.org, args.position);
+ d33_muld3(pos, transform, pos);
+
+ /* Check that the sampled position lies onto the thin lens */
+ dst = d2_len(pos);
+ CHK(eq_eps(pos[2], 0, 1.e-6));
+ CHK(dst < args.lens_radius
+ || eq_eps(dst, args.lens_radius, args.lens_radius*1.e-6));
+
+ /* Compute the ray starting from the lens center and intersecting the focal
+ * plane at the same position of the generated ray */
+ pos[0] = ray.org[0] + ray.dir[0]*args.focal_distance;
+ pos[1] = ray.org[1] + ray.dir[1]*args.focal_distance;
+ pos[2] = ray.org[2] + ray.dir[2]*args.focal_distance;
+ CHK(d3_is_normalized(ray.dir));
+ d3_add(pos, ray.org, ray.dir);
+ d3_sub(dir, pos, args.position);
+ d3_normalize(dir, dir);
+
+ /* Check that the computed direction is in the view frustum */
+ cos_ray_axis_x = d3_dot(dir, axis_x);
+ cos_ray_axis_y = d3_dot(dir, axis_y);
+ cos_ray_axis_z = d3_dot(dir, axis_z);
CHK(cos_ray_axis_z >= 0);
CHK(cos_ray_axis_y <= sin_vert_hfov);
- CHK(cos_ray_axis_x <= sin_hori_hfov);*/
+ CHK(cos_ray_axis_x <= sin_hori_hfov);
}
CHK(scam_ref_put(cam) == RES_OK);