solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 5d4e3ff8b80f30edcc5ecf24914550b2c890da95
parent a78c2029928ad56ff7972aee26fe25f6f41ee981
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 14 Mar 2017 13:55:32 +0100

Fix the ssol_mc_receiver_get_mc_shape function

Return an error if the receiver does not instantiated the submitted
shape.

Diffstat:
Msrc/ssol.h | 1+
Msrc/ssol_estimator_c.h | 2+-
Msrc/ssol_mc_receiver.c | 3+++
Msrc/ssol_object.c | 12++++++++++++
Msrc/ssol_object_c.h | 6++++++
Msrc/test_ssol_solver1.c | 7++++++-
6 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/ssol.h b/src/ssol.h @@ -314,6 +314,7 @@ struct ssol_mc_receiver { /* Internal data */ size_t N__; void* mc__; + const struct ssol_instance* instance__; }; struct ssol_mc_shape { diff --git a/src/ssol_estimator_c.h b/src/ssol_estimator_c.h @@ -194,7 +194,7 @@ mc_receiver_1side_get_mc_shape struct mc_shape_1side* mc_shape1 = NULL; struct mc_shape_1side mc_shape1_null; res_T res = RES_OK; - ASSERT(mc_rcv && shape && out_mc_prim1); + ASSERT(mc_rcv && shape && out_mc_shape1); mc_shape_1side_init(shape->dev->allocator, &mc_shape1_null); diff --git a/src/ssol_mc_receiver.c b/src/ssol_mc_receiver.c @@ -15,6 +15,7 @@ #include "ssol.h" #include "ssol_estimator_c.h" +#include "ssol_object_c.h" /******************************************************************************* * Exported functions @@ -56,6 +57,7 @@ ssol_estimator_get_mc_receiver #undef SETUP_MC_RESULT rcv->mc__ = mc_rcv1; rcv->N__ = estimator->realisation_count; + rcv->instance__ = instance; return RES_OK; } @@ -68,6 +70,7 @@ ssol_mc_receiver_get_mc_shape struct mc_receiver_1side* mc_rcv1; if(!rcv || !shape || !mc) return RES_BAD_ARG; + if(!object_has_shape(rcv->instance__->object, shape)) return RES_BAD_ARG; mc_rcv1 = rcv->mc__; mc->N__ = rcv->N__; mc->mc__ = htable_shape2mc_find(&mc_rcv1->shape2mc, &shape); diff --git a/src/ssol_object.c b/src/ssol_object.c @@ -229,3 +229,15 @@ ssol_object_get_area(const struct ssol_object* object, double* area) return RES_OK; } +/******************************************************************************* + * Local function + ******************************************************************************/ +int +object_has_shape(struct ssol_object* obj, const struct ssol_shape* shape) +{ + unsigned id; + ASSERT(obj && shape); + S3D(shape_get_id(shape->shape_rt, &id)); + return htable_shaded_shape_find(&obj->shaded_shapes_rt, &id) != NULL; +} + diff --git a/src/ssol_object_c.h b/src/ssol_object_c.h @@ -53,4 +53,10 @@ struct ssol_object { ref_T ref; }; +extern LOCAL_SYM int +object_has_shape + (struct ssol_object* obj, + const struct ssol_shape* shape); + #endif /* SSOL_OBJECT_C_H */ + diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c @@ -52,6 +52,7 @@ main(int argc, char** argv) struct ssol_device* dev; struct ssp_rng* rng; struct ssol_scene* scene; + struct ssol_shape* dummy; struct ssol_shape* square; struct ssol_vertex_data attribs[1] = { SSOL_VERTEX_DATA_NULL__ }; struct ssol_material *m_mtl, *m_mtl2; @@ -129,6 +130,7 @@ main(int argc, char** argv) CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); /* Create scene content */ + CHECK(ssol_shape_create_mesh(dev, &dummy), RES_OK); CHECK(ssol_shape_create_mesh(dev, &square), RES_OK); attribs[0].usage = SSOL_POSITION; attribs[0].get = get_position; @@ -435,6 +437,7 @@ main(int argc, char** argv) CHECK(ssol_mc_receiver_get_mc_shape(NULL, NULL, &mc_shape), RES_BAD_ARG); CHECK(ssol_mc_receiver_get_mc_shape(&mc_rcv, NULL, &mc_shape), RES_BAD_ARG); CHECK(ssol_mc_receiver_get_mc_shape(NULL, square, &mc_shape), RES_BAD_ARG); + CHECK(ssol_mc_receiver_get_mc_shape(&mc_rcv, dummy, &mc_shape), RES_BAD_ARG); CHECK(ssol_mc_receiver_get_mc_shape(&mc_rcv, square, &mc_shape), RES_OK); CHECK(ssol_shape_get_triangles_count(square, &ntris), RES_OK); @@ -453,6 +456,7 @@ main(int argc, char** argv) CHECK(ssol_mc_shape_get_mc_primitive(&mc_shape, (unsigned)i, &mc_prim), RES_OK); dbl += mc_prim.integrated_irradiance.E; } + CHECK(eq_eps(dbl, a_m, 1.e-6), 1); CHECK(ssol_estimator_ref_put(estimator), RES_OK); @@ -506,18 +510,19 @@ main(int argc, char** argv) CHECK(ssol_instance_ref_put(target), RES_OK); CHECK(ssol_object_ref_put(m_object), RES_OK); CHECK(ssol_object_ref_put(t_object), RES_OK); + CHECK(ssol_shape_ref_put(dummy), RES_OK); CHECK(ssol_shape_ref_put(square), RES_OK); CHECK(ssol_material_ref_put(m_mtl), RES_OK); CHECK(ssol_material_ref_put(v_mtl), RES_OK); CHECK(ssol_device_ref_put(dev), RES_OK); CHECK(ssol_scene_ref_put(scene), RES_OK); - CHECK(ssp_rng_ref_put(rng), RES_OK); CHECK(ssol_spectrum_ref_put(abs), RES_OK); CHECK(ssol_atmosphere_ref_put(atm), RES_OK); CHECK(ssol_estimator_ref_put(estimator), RES_OK); CHECK(ssol_spectrum_ref_put(spectrum), RES_OK); CHECK(ssol_sun_ref_put(sun), RES_OK); CHECK(ssol_sun_ref_put(sun_mono), RES_OK); + CHECK(ssp_rng_ref_put(rng), RES_OK); check_memory_allocator(&allocator); mem_shutdown_proxy_allocator(&allocator);