commit 344467206bf5ecb09fbaa1ceebff244a99de3ab5
parent 1f84b7e24e79d5e5e884e1ed00fcd6ab6c0ecf45
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 12 Sep 2016 01:09:29 +0200
Fix test solver #1
- mirrors' area was not taken into account
- 0-weighted realisations were not taken into account
Diffstat:
4 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/src/ssol_solver.c b/src/ssol_solver.c
@@ -353,6 +353,7 @@ init_realisation
/* create 2 s3d_scene_view for raytracing and sampling */
res = set_views(&rs->data);
if (res != RES_OK) goto error;
+ S3D(scene_view_compute_area(rs->data.view_samp, &rs->data.sampled_area));
/* create sun distributions */
res = set_sun_distributions(&rs->data);
if (res != RES_OK) goto error;
@@ -522,7 +523,7 @@ receive_sunlight(struct realisation* rs)
seg->self_instance = NULL;
seg->hit_front = seg->self_front;
seg->self_front = 99;
- seg->weight = sun->dni * rs->start.cos_sun;
+ seg->weight = rs->data.sampled_area * sun->dni * start->cos_sun;
ASSERT(seg->weight > 0);
/* fill fragment from starting point */
@@ -615,9 +616,9 @@ ssol_solve
}
/* propagation ended */
- fprintf(output, "Realization %u success mask: 0x%0x\n",
+ fprintf(output, "Realisation %u success mask: 0x%0x\n",
(unsigned)r, rs.success_mask);
- fprintf(output, "Realization %u end: %s\n\n",
+ fprintf(output, "Realisation %u end: %s\n\n",
(unsigned)r, END_TEXT[rs.end]);
}
diff --git a/src/ssol_solver_c.h b/src/ssol_solver_c.h
@@ -104,6 +104,8 @@ struct solver_data {
/* Tmp data used for propagation */
struct brdf_composite* brdfs;
struct surface_fragment fragment;
+
+ float sampled_area;
};
struct realisation {
diff --git a/src/test_ssol_postprocess.h b/src/test_ssol_postprocess.h
@@ -24,21 +24,24 @@ pp_sum(FILE* f, const char* target, double* mean, double* std)
{
double sum = 0, sum2 = 0, var;
size_t cpt = 0;
- char expect_tok2[256];
+ char expect_tok[256];
ASSERT(f && target && mean && std);
- snprintf(expect_tok2, 256, "'%s':", target);
+ snprintf(expect_tok, 256, "'%s':", target);
rewind(f);
while (!feof(f)) {
char buf[256];
if (fgets(buf, 256, f)) {
- char tok1[256], tok2[256];
+ char tok[256];
double w;
- if(3 != sscanf(buf, "%s %s %*f %*f %*f %lf", tok1, tok2, &w)) continue;
- if (strcmp(tok1, "Receiver")) continue;
- if (strcmp(tok2, expect_tok2)) continue;
- sum += w;
- sum2 += w * w;
- cpt++;
+ if(2 == sscanf(buf, "Receiver %s %*f %*f %*f %lf", tok, &w)) {
+ if (strcmp(tok, expect_tok)) continue;
+ sum += w;
+ sum2 += w * w;
+ }
+ else if (1 == sscanf(buf, "Realisation %*d %s:", tok)) {
+ if (strcmp(tok, "end:")) continue;
+ cpt++;
+ }
}
}
if (cpt) {
diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c
@@ -131,13 +131,15 @@ main(int argc, char** argv)
CHECK(ssol_scene_attach_instance(scene, target), RES_OK);
CHECK(ssol_solve(scene, rng, 20, stdout), RES_OK);
-
tmp = tmpfile();
CHECK(!tmp, 0);
- CHECK(ssol_solve(scene, rng, 1000, tmp), RES_OK);
+#define N 10000
+ CHECK(ssol_solve(scene, rng, N, tmp), RES_OK);
CHECK(pp_sum(tmp, "cible", &m, &std), RES_OK);
- CHECK(eq_eps(m, 1000 / sqrt(2), 1e-3), 1);
- CHECK(eq_eps(std, 0, 1e-6), 1);
+#define DNI_cos (1000 * cos(PI / 4))
+ CHECK(eq_eps(m, 4 * DNI_cos, 4 * DNI_cos * 2e-2), 1);
+#define SQR(x) ((x)*(x))
+ CHECK(eq_eps(std, sqrt((SQR(8 * DNI_cos) / 2 - SQR(4 * DNI_cos)) / N), 0.01), 1);
/* free data */