commit bfbd9deef50ac53ef07b45fee80d4d6bdd08d03c
parent bbc8a9158df1ce3e8165f0e9e45b5163f09d71f1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 30 Jul 2021 15:18:55 +0200
Rm the thin-lens model from the orthogonal camera
What could be its meaning?
Diffstat:
6 files changed, 30 insertions(+), 123 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -82,7 +82,7 @@ if(NOT NO_TEST)
add_test(${_name} ${_name})
endfunction()
- new_test(test_scam_orthographic_pinhole)
+ new_test(test_scam_orthographic)
new_test(test_scam_perspective_pinhole)
new_test(test_scam_perspective_thin_lens)
@@ -90,7 +90,7 @@ if(NOT NO_TEST)
build_test(test_scam_cbox)
target_link_libraries(test_scam_cbox Star3D)
- add_test(test_scam_cbox_orthographic_pinhole test_scam_cbox orthographic pinhole)
+ add_test(test_scam_cbox_orthographic 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()
diff --git a/src/scam.h b/src/scam.h
@@ -64,10 +64,6 @@ struct scam_orthographic_args {
double up[3]; /* Vector defining the upward orientation */
double height; /* Height of the image plane */
double aspect_ratio; /* Image plane aspect ratio (width / height) */
- double lens_radius; /* Radius of 0 <=> pinhole */
-
- /* Distance to focus on. Used when lens_radius != 0 */
- double focal_distance;
};
#define SCAM_ORTHOGRAPHIC_ARGS_DEFAULT__ { \
{0,0,0}, /* Position */ \
@@ -75,8 +71,6 @@ struct scam_orthographic_args {
{0,0,1}, /* Up */ \
1.0, /* Height of the image plane */ \
1.0, /* Aspect ratio */ \
- 0.0, /* Lens radius */ \
- 1.0 /* Focal distance. Unused for radius == 0 */ \
}
static const struct scam_orthographic_args SCAM_ORTHOGRAPHIC_ARGS_DEFAULT =
SCAM_ORTHOGRAPHIC_ARGS_DEFAULT__;
diff --git a/src/scam_c.h b/src/scam_c.h
@@ -51,8 +51,6 @@ struct orthographic {
double height; /* Height of the image plane */
double aspect_ratio; /* width / height */
- double lens_radius; /* 0 <=> pinhole camera */
- double focal_distance; /* Unused when lens_radius == 0 */
};
#define ORTHOGRAPHIC_DEFAULT__ { \
{1,0,0, 0,1,0, 0,0,1}, /* Screen to world transformation */ \
@@ -60,8 +58,6 @@ struct orthographic {
{0,0,0}, /* Lens position */ \
1.0, /* Height */ \
1.0, /* Aspect ratio */ \
- 0.0, /* Lens radius */ \
- -1.0 /* Focal distance */ \
}
static const struct orthographic ORTHOGRAPHIC_DEFAULT = ORTHOGRAPHIC_DEFAULT__;
diff --git a/src/scam_orthographic.c b/src/scam_orthographic.c
@@ -29,12 +29,10 @@ static res_T
setup_orthographic(struct scam* cam, const struct scam_orthographic_args* args)
{
double x[3], y[3], z[3];
- int pinhole = 0;
res_T res = RES_OK;
ASSERT(cam && args && cam->type == SCAM_ORTHOGRAPHIC);
cam->param.ortho = ORTHOGRAPHIC_DEFAULT;
- pinhole = args->lens_radius == 0;
if(args->aspect_ratio <= 0) {
log_err(cam,
@@ -52,22 +50,6 @@ setup_orthographic(struct scam* cam, const struct scam_orthographic_args* args)
goto error;
}
- if(args->lens_radius < 0) {
- log_err(cam,
- "orthographic camera: invalid negative lens radius: %g\n",
- args->lens_radius);
- res = RES_BAD_ARG;
- goto error;
- }
-
- if(!pinhole && args->focal_distance < 0) {
- log_err(cam,
- "orthographic camera: invalid negative focal distance: %g\n",
- args->focal_distance);
- res = RES_BAD_ARG;
- goto error;
- }
-
if(d3_normalize(z, d3_sub(z, args->target, args->position)) <= 0
|| d3_normalize(x, d3_cross(x, z, args->up)) <= 0
|| d3_normalize(y, d3_cross(y, z, x)) <= 0) {
@@ -83,8 +65,6 @@ setup_orthographic(struct scam* cam, const struct scam_orthographic_args* args)
cam->param.ortho.height = args->height;
cam->param.ortho.aspect_ratio = args->aspect_ratio;
- cam->param.ortho.lens_radius= args->lens_radius;
- cam->param.ortho.focal_distance = args->focal_distance;
d3_set(cam->param.ortho.position, args->position);
@@ -102,81 +82,6 @@ error:
goto exit;
}
-static INLINE void
-pinhole_generate_ray
- (const struct scam* cam,
- const struct scam_sample* sample,
- struct scam_ray* ray)
-{
- double x[3], y[3];
- double pos[3];
-
- ASSERT(cam && sample && ray);
- ASSERT(cam->param.ortho.lens_radius == 0);
- ASSERT(cam->type == SCAM_ORTHOGRAPHIC);
- ASSERT(0 <= sample->film[0] && sample->film[0] < 1);
- ASSERT(0 <= sample->film[1] && sample->film[1] < 1);
-
- /* Transform the sampled position in screen space */
- pos[0] = sample->film[0]*2-1;
- pos[1] = sample->film[1]*2-1;
- pos[2] = 0;
-
- /* Transform the sampled position in world space */
- d3_muld(x, cam->param.ortho.screen2world+0, pos[0]);
- d3_muld(y, cam->param.ortho.screen2world+3, pos[1]);
- d3_add(ray->org, x, y);
- d3_add(ray->org, ray->org, cam->param.ortho.position);
-
- /* 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+6);
-}
-
-static INLINE void
-thin_lens_generate_ray
- (const struct scam* cam,
- const struct scam_sample* sample,
- struct scam_ray* ray)
-{
- double focus_pt[3];
- double theta;
- double len;
- double r;
- (void)len;
-
- ASSERT(cam && sample && ray);
- ASSERT(cam->param.ortho.lens_radius > 0);
- ASSERT(cam->type == SCAM_PERSPECTIVE);
- ASSERT(0 <= sample->film[0] && sample->film[0] < 1);
- ASSERT(0 <= sample->film[1] && sample->film[1] < 1);
- ASSERT(0 <= sample->lens[0] && sample->lens[0] < 1);
- ASSERT(0 <= sample->lens[1] && sample->lens[1] < 1);
-
- /* find the focus point by intersecting the image plane normal with the focus
- * plane in camera space */
- focus_pt[0] = 0;
- focus_pt[1] = 0;
- focus_pt[2] = cam->param.ortho.focal_distance;
-
- /* Uniformly sample a position onto the lens in camera space */
- theta = 2 * PI * sample->lens[0];
- r = cam->param.ortho.lens_radius * sqrt(sample->lens[1]);
- ray->org[0] = r * cos(theta);
- ray->org[1] = r * sin(theta);
- ray->org[2] = 0;
-
- /* Compute the ray direction in camera space */
- d3_sub(ray->dir, focus_pt, ray->org);
- len = d3_normalize(ray->dir, ray->dir);
- ASSERT(len >= 1.e-6);
-
- /* 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.ortho.position, ray->org);
-}
-
/*******************************************************************************
* Exported function
******************************************************************************/
@@ -221,10 +126,26 @@ orthographic_generate_ray
const struct scam_sample* sample,
struct scam_ray* ray)
{
- ASSERT(cam && cam->type == SCAM_ORTHOGRAPHIC);
- if(cam->param.ortho.lens_radius == 0) {
- pinhole_generate_ray(cam, sample, ray);
- } else {
- thin_lens_generate_ray(cam, sample, ray);
- }
+ double x[3], y[3];
+ double pos[3];
+
+ ASSERT(cam && sample && ray);
+ ASSERT(cam->type == SCAM_ORTHOGRAPHIC);
+ ASSERT(0 <= sample->film[0] && sample->film[0] < 1);
+ ASSERT(0 <= sample->film[1] && sample->film[1] < 1);
+
+ /* Transform the sampled position in screen space */
+ pos[0] = sample->film[0]*2-1;
+ pos[1] = sample->film[1]*2-1;
+ pos[2] = 0;
+
+ /* Transform the sampled position in world space */
+ d3_muld(x, cam->param.ortho.screen2world+0, pos[0]);
+ d3_muld(y, cam->param.ortho.screen2world+3, pos[1]);
+ d3_add(ray->org, x, y);
+ d3_add(ray->org, ray->org, cam->param.ortho.position);
+
+ /* 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+6);
}
diff --git a/src/test_scam_cbox.c b/src/test_scam_cbox.c
@@ -120,15 +120,9 @@ create_orthographic(const enum lens_model lens_model, struct scam** cam)
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;
- }
+ /* No thin-lens model for orthographic projection */
+ CHK(lens_model == PINHOLE);
+
CHK(scam_create_orthographic(NULL, NULL, 1, &args, cam) == RES_OK);
}
@@ -212,7 +206,9 @@ main(int argc, char** argv)
int err = 0;
if(argc <= 2) {
- fprintf(stderr, "Usage: %s <orthographic|perspective> <pinhole|thin-lens>\n", argv[0]);
+ fprintf(stderr,
+ "Usage: %s <orthographic|perspective> <pinhole|thin-lens>\n",
+ argv[0]);
goto error;
}
diff --git a/src/test_scam_orthographic_pinhole.c b/src/test_scam_orthographic.c