star-gs

Literate program for a geometric sensitivity calculation
git clone git://git.meso-star.fr/star-gs.git
Log | Files | Refs | README | LICENSE

commit bf58170701b10064fbdff9b8900fa7b478656c91
parent 665323415ddd2fb32796cb7c0e1604e2586e7cb0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 15 Sep 2021 12:00:39 +0200

Add the sgs_geometry_get_aabb function

Diffstat:
Msrc/sgs_compute_sensitivity_translation.c | 8++++++++
Msrc/sgs_geometry.c | 32++++++++++++++++++++++++++++++++
Msrc/sgs_geometry.h | 6++++++
Msrc/sgs_geometry_box.c | 2++
Msrc/sgs_geometry_c.h | 6++++++
Msrc/sgs_geometry_slope.c | 2++
Msrc/sgs_geometry_step.c | 2++
7 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/src/sgs_compute_sensitivity_translation.c b/src/sgs_compute_sensitivity_translation.c @@ -246,6 +246,14 @@ compute_sensitivity_translation(struct sgs* sgs) goto error; } + if(sgs_geometry_get_sampling_mask(sgs->geom) != SGS_SURFACE_Z_POS) { + sgs_log_err(sgs, + "Invalid sensitivity emissive surface. Only positive Z face of the box " + "geometry can be a sensitivity source.\n"); + res = RES_BAD_ARG; + goto error; + } + /* Create the Star-MonteCarlo device */ res = smc_device_create (&sgs->logger, sgs->allocator, sgs->nthreads, &ssp_rng_mt19937_64, &smc); diff --git a/src/sgs_geometry.c b/src/sgs_geometry.c @@ -189,6 +189,17 @@ sgs_geometry_get_type(const struct sgs_geometry* geom) return geom->type; } +void +sgs_geometry_get_aabb + (const struct sgs_geometry* geom, + double low[3], + double upp[3]) +{ + ASSERT(geom && low && upp); + d3_set(low, geom->low); + d3_set(upp, geom->upp); +} + int sgs_geometry_get_sampling_mask(const struct sgs_geometry* geom) { @@ -404,6 +415,27 @@ error: goto exit; } +void +geometry_compute_aabb(struct sgs_geometry* geom) +{ + const double* coords = NULL; + size_t i; + ASSERT(geom); + d3_splat(geom->low, DBL_MAX); + d3_splat(geom->upp,-DBL_MAX); + + coords = darray_double_cdata_get(&geom->verts); + FOR_EACH(i, 0, darray_double_size_get(&geom->verts)) { + const double* vert = coords + i*3; + geom->low[0] = MMIN(geom->low[0], vert[0]); + geom->low[1] = MMIN(geom->low[1], vert[1]); + geom->low[2] = MMIN(geom->low[2], vert[2]); + geom->upp[0] = MMAX(geom->upp[0], vert[0]); + geom->upp[1] = MMAX(geom->upp[1], vert[1]); + geom->upp[2] = MMAX(geom->upp[2], vert[2]); + } +} + res_T geometry_setup_view_rt(struct sgs_geometry* geom) { diff --git a/src/sgs_geometry.h b/src/sgs_geometry.h @@ -190,6 +190,12 @@ extern LOCAL_SYM enum sgs_geometry_type sgs_geometry_get_type (const struct sgs_geometry* geom); +extern LOCAL_SYM void +sgs_geometry_get_aabb + (const struct sgs_geometry* geom, + double low[3], + double upp[3]); + extern LOCAL_SYM int sgs_geometry_get_sampling_mask (const struct sgs_geometry* geom); diff --git a/src/sgs_geometry_box.c b/src/sgs_geometry_box.c @@ -138,6 +138,8 @@ sgs_geometry_box_create res = geometry_setup_view_sp(geom, args->sampling_mask); if(res != RES_OK) goto error; + geometry_compute_aabb(geom); + exit: *out_geom = geom; return res; diff --git a/src/sgs_geometry_c.h b/src/sgs_geometry_c.h @@ -38,6 +38,8 @@ struct sgs_geometry { struct s3d_scene_view* view_rt; struct s3d_scene_view* view_sp; + double low[3], upp[3]; /* Axis aligned bounding box */ + enum sgs_geometry_type type; int sampling_mask; /* Combination of enum sgs_surface_type */ @@ -52,6 +54,10 @@ geometry_create const int sampling_mask, struct sgs_geometry** out_geom); +extern LOCAL_SYM void +geometry_compute_aabb + (struct sgs_geometry* geom); + extern LOCAL_SYM res_T geometry_setup_view_rt (struct sgs_geometry* geom); diff --git a/src/sgs_geometry_slope.c b/src/sgs_geometry_slope.c @@ -142,6 +142,8 @@ sgs_geometry_slope_create res = geometry_setup_view_sp(geom, args->sampling_mask); if(res != RES_OK) goto error; + geometry_compute_aabb(geom); + exit: *out_geom = geom; return res; diff --git a/src/sgs_geometry_step.c b/src/sgs_geometry_step.c @@ -191,6 +191,8 @@ sgs_geometry_step_create res = geometry_setup_view_sp(geom, args->sampling_mask); if(res != RES_OK) goto error; + geometry_compute_aabb(geom); + exit: *out_geom = geom; return res;