commit 99cccfab59e7b7aee2062342c50dc64cfe0e5c9f
parent a6bc2cb94b0059aab8ca95fbb1efd14f664226e1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 27 Nov 2017 16:24:02 +0100
Handle the updates of the SSP 0.5 API
Diffstat:
3 files changed, 34 insertions(+), 27 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -35,10 +35,10 @@ set(S4VS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src/)
# Check dependencies
################################################################################
find_package(RCMake 0.3 REQUIRED)
-find_package(RSys 0.4 REQUIRED)
+find_package(RSys 0.6 REQUIRED)
find_package(Star3D 0.4.1 REQUIRED)
find_package(Star3DAW 0.1.3 REQUIRED)
-find_package(StarSP 0.4 REQUIRED)
+find_package(StarSP 0.5 REQUIRED)
find_package(StarMC 0.3 REQUIRED)
include_directories(
diff --git a/src/s4vs.c b/src/s4vs.c
@@ -38,18 +38,22 @@
#include "s4vs_realization.h"
static res_T
-compute_4v_s(struct s3d_scene* scene, const size_t max_steps, const double ks)
+compute_4v_s
+ (struct s3d_scene* scene,
+ const size_t max_realisations,
+ const double ks)
{
+ char dump[64];
struct s4vs_context ctx;
struct s3d_scene_view* view = NULL;
struct smc_device* smc = NULL;
struct smc_integrator integrator;
struct smc_estimator* estimator = NULL;
struct smc_estimator_status estimator_status;
- struct time t1,t2,dt;
+ struct time t0, t1;
float S, V, reference;
res_T res = RES_OK;
- ASSERT(scene && max_steps > 0 && ks >= 0);
+ ASSERT(scene && max_realisations > 0 && ks >= 0);
S3D(scene_view_create(scene, S3D_SAMPLE|S3D_TRACE, &view));
@@ -79,15 +83,15 @@ compute_4v_s(struct s3d_scene* scene, const size_t max_steps, const double ks)
SMC(device_create(NULL, NULL, SMC_NTHREADS_DEFAULT, NULL, &smc));
integrator.integrand = &s4vs_realization; /* Realization function */
integrator.type = &smc_double; /* Type of the Monte Carlo weight */
- integrator.max_steps = max_steps; /* Realization count */
- integrator.max_failures = max_steps / 1000; /* cancel if 0.1% of the realization fail */
+ integrator.max_steps = max_realisations; /* Realization count */
+ integrator.max_failures = max_realisations / 1000;
/* Solve */
- time_current(&t1);
+ time_current(&t0);
SMC(solve(smc, &integrator, &ctx, &estimator));
- time_current(&t2);
- time_sub(&dt,&t2,&t1);
- printf("Computation time : %li msec.\n \n", time_val(&dt, TIME_MSEC));
+ time_sub(&t0, time_current(&t1), &t0);
+ time_dump(&t0, TIME_ALL, NULL, dump, sizeof(dump));
+ printf("Computation time: %s\n", dump);
/* Print the simulation results */
SMC(estimator_get_status(estimator, &estimator_status));
@@ -99,12 +103,12 @@ compute_4v_s(struct s3d_scene* scene, const size_t max_steps, const double ks)
(unsigned long)estimator_status.NF);
goto error;
}
- printf("4V/S = %g ~ %g +/- %g\n# failures: %lu/%lu\n",
+ printf("4V/S = %g ~ %g +/- %g\n#failures = %lu/%lu\n",
reference,
SMC_DOUBLE(estimator_status.E),
SMC_DOUBLE(estimator_status.SE),
(unsigned long)estimator_status.NF,
- (unsigned long)max_steps);
+ (unsigned long)max_realisations);
exit:
/* Clean-up data */
@@ -160,12 +164,13 @@ error:
int
main(int argc, char* argv[])
{
+ char dump[64];
struct s3d_scene* scene = NULL;
- unsigned long nsteps = 10000;
+ struct time t0, t1;
+ unsigned long nrealisations = 10000;
double ks = 0.0;
res_T res = RES_OK;
int err = 0;
- struct time t1,t2,dt;
/* Check command arguments */
if(argc < 2 || argc > 4) {
@@ -174,21 +179,21 @@ main(int argc, char* argv[])
}
/* Import file's content in the scene */
- time_current(&t1);
+ time_current(&t0);
res = import_obj(argv[1], &scene);
if(res != RES_OK) {
fprintf(stderr, "Couldn't import `%s'\n", argv[1]);
goto error;
}
- time_current(&t2);
- time_sub(&dt,&t2,&t1);
- printf("obj file loaded in %li msec.\n \n", time_val(&dt, TIME_MSEC));
+ time_sub(&t0, time_current(&t1), &t0);
+ time_dump(&t0, TIME_ALL, NULL, dump, sizeof(dump));
+ printf("Obj loaded in %s.\n", dump);
/* Set number of realizations */
if(argc >= 3) {
- res = cstr_to_ulong(argv[2], &nsteps);
- if(nsteps <= 0 || res != RES_OK) {
- fprintf(stderr, "Invalid number of steps `%s'\n", argv[2]);
+ res = cstr_to_ulong(argv[2], &nrealisations);
+ if(nrealisations <= 0 || res != RES_OK) {
+ fprintf(stderr, "Invalid number of realisations `%s'\n", argv[2]);
goto error;
}
}
@@ -202,7 +207,7 @@ main(int argc, char* argv[])
}
}
- res = compute_4v_s(scene, nsteps, ks);
+ res = compute_4v_s(scene, nrealisations, ks);
if(res != RES_OK) {
fprintf(stderr, "Error in 4V/S integration\n");
goto error;
diff --git a/src/s4vs_realization.c b/src/s4vs_realization.c
@@ -61,7 +61,7 @@ s4vs_realization(void* out_length, struct ssp_rng* rng, void* context)
struct s4vs_context* ctx = (struct s4vs_context*)context;
struct s3d_attrib attrib;
struct s3d_primitive prim;
- double sample[4];
+ double sample[3];
double normal[3];
float u[3], x[3], st[2];
const float range[2] = {0.f, FLT_MAX};
@@ -84,7 +84,7 @@ s4vs_realization(void* out_length, struct ssp_rng* rng, void* context)
f3_set(x, attrib.value);
/* Cosine weighted sampling of the hemisphere around the sampled normal */
- ssp_ran_hemisphere_cos(rng, normal, sample);
+ ssp_ran_hemisphere_cos(rng, normal, sample, NULL);
f3_set_d3(u, sample);
/* Find the 1st hit from the sampled location along the sampled direction */
@@ -95,13 +95,15 @@ s4vs_realization(void* out_length, struct ssp_rng* rng, void* context)
keep_running = 1;
while(keep_running) { /* Here we go for the diffuse random walk */
- sigma = ssp_ran_exp(rng, ctx->ks); /* Sample a length according to ks */
+
+ /* Sample a length according to ks */
+ sigma = ssp_ran_exp(rng, ctx->ks);
if(sigma < hit.distance) {
int i;
FOR_EACH(i, 0, 3) x[i] = x[i] + (float)sigma*u[i];
d3_normalize(sample, d3_set_f3(sample, u));
- f3_set_d3(u, ssp_ran_sphere_hg(rng, sample, ctx->g, sample));
+ f3_set_d3(u, ssp_ran_sphere_hg(rng, sample, ctx->g, sample, NULL));
/* sample a new direction */
S3D(scene_view_trace_ray(ctx->view, x, u, range, NULL, &hit));