solstice-solver

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

commit bf2b8481c5923d693b4569d6e02f5dd68478e5c7
parent 3f500ee497b80ed0005fe68e27c9b171c0b80842
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 12 Oct 2016 18:08:00 +0200

Fix issues in the ssol_solver function

Diffstat:
Msrc/ssol_scene.c | 3++-
Msrc/ssol_solver.c | 11++++++-----
Msrc/test_ssol_solver1.c | 4++--
Msrc/test_ssol_utils.c | 2+-
4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/ssol_scene.c b/src/ssol_scene.c @@ -385,7 +385,8 @@ hit_filter_function /* Discard self intersection */ switch(sshape->shape->type) { case SHAPE_MESH: - if(S3D_PRIMITIVE_EQ(&hit->prim, &rdata->prim_from)) { + if(hit->distance <= 1.e-6 /* FIXME hack */ + || S3D_PRIMITIVE_EQ(&hit->prim, &rdata->prim_from)) { /* Discard self intersection for mesh, i.e. when the intersected * primitive is the primitive from which the ray starts */ return 1; diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -918,6 +918,7 @@ ssol_solve sshape = darray_shaded_shape_cdata_get(&inst->object->shaded_shapes)+id; /* Fetch the current position and its associated normal */ + d3_set_f3(pos, posf); switch(sshape->shape->type) { case SHAPE_MESH: S3D(primitive_get_attrib(&prim, S3D_GEOMETRY_NORMAL, uv, &attr)); @@ -925,7 +926,6 @@ ssol_solve d3_set_f3(N, attr.value); break; case SHAPE_PUNCHED: - d3_set_f3(pos, posf); punched_shape_project_point(sshape->shape, inst->transform, pos, pos, N); break; default: FATAL("Unreachable code"); break; @@ -992,7 +992,7 @@ ssol_solve f2_set(out.uv, uv); out.weight = weight; n = fwrite(&out, sizeof(out), 1, output); - if(n != sizeof(out)) { + if(n < 1) { res = RES_IO_ERR; goto error; } @@ -1007,6 +1007,7 @@ ssol_solve surface_fragment_setup(&frag, pos, dir, N, &prim, uv); /* Shade the surface fragment */ + SSF(bsdf_clear(bsdf)); res = material_shade(mtl, &frag, wl, bsdf); if(res != RES_OK) goto error; @@ -1031,8 +1032,8 @@ ssol_solve ++depth; /* Retrieve the hit instance and shaded shape */ - inst = *htable_instance_find(&scn->instances_rt, &prim.inst_id); - id = *htable_shaded_shape_find(&inst->object->shaded_shapes_rt, &prim.geom_id); + inst = *htable_instance_find(&scn->instances_rt, &hit.prim.inst_id); + id = *htable_shaded_shape_find(&inst->object->shaded_shapes_rt, &hit.prim.geom_id); sshape = darray_shaded_shape_cdata_get(&inst->object->shaded_shapes)+id; /* Fetch the current position and its associated normal */ @@ -1063,8 +1064,8 @@ ssol_solve estimator->missing.weight += weight; estimator->missing.sqr_weight += weight*weight; } - } + estimator->realisation_count += nrealisations; exit: if(view_rt) S3D(scene_view_ref_put(view_rt)); diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c @@ -177,7 +177,7 @@ main(int argc, char** argv) CHECK(ssol_instance_set_receiver(heliostat, 0), RES_OK); CHECK(ssol_instance_set_receiver(secondary, 0), RES_OK); CHECK(ssol_instance_set_receiver(target, 0), RES_OK); - CHECK(ssol_solve(scene, rng, 10, stdout, estimator), RES_BAD_ARG); /* no receiver in scene */ + CHECK(ssol_solve(scene, rng, 10, stdout, estimator), RES_OK); /* no receiver in scene */ CHECK(ssol_instance_set_receiver(heliostat, SSOL_FRONT), RES_OK); CHECK(ssol_instance_set_receiver(secondary, SSOL_FRONT), RES_OK); CHECK(ssol_instance_set_receiver(target, SSOL_FRONT), RES_OK); @@ -197,7 +197,7 @@ main(int argc, char** argv) #define N__ 10000 CHECK(ssol_estimator_clear(estimator), RES_OK); CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); - CHECK(ssol_instance_get_id(target, &r_id), RES_OK); + CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(pp_sum(tmp, (int32_t)r_id, count, &m, &std), RES_OK); diff --git a/src/test_ssol_utils.c b/src/test_ssol_utils.c @@ -36,7 +36,7 @@ pp_sum double sum = 0; double sum2 = 0; double E, V, SE; - + if(!f || !mean || !std || !count) return RES_BAD_ARG;