commit b7e6b813f3a88bd8c1c13b4eaf8b4af5fc632e07
parent ead635bfaf41c2545a118aa202800d19872d9393
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sun, 22 Sep 2019 13:50:25 +0200
Upd the profile of the geometry distrib functions
The sample function can now return a pointer toward the client side data
of the sampled shape. These data are then sent to the
sample_volume_scaling function.
Diffstat:
5 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/sschiff.h b/src/sschiff.h
@@ -72,10 +72,12 @@ struct sschiff_geometry_distribution {
double characteristic_length;
res_T (*sample) /* Sample a geometry i.e. a shape */
(struct ssp_rng* rng,
- struct s3d_shape* shape, /* Sampled shape */
+ void** shape, /* Returned client side data of the sampled shape */
+ struct s3d_shape* s3d_shape, /* Star-3D shape where geometry are stored */
void* context);
res_T (*sample_volume_scaling) /* Can be NULL <=> No volume scaling */
(struct ssp_rng* rng,
+ void* shape, /* Client side shape into which a volume scaling is sampled */
double* scale_factor, /* Scale factor to apply to the shape volume */
void* context);
void* context;
diff --git a/src/sschiff_estimator.c b/src/sschiff_estimator.c
@@ -81,6 +81,7 @@ struct integrator_context {
struct s3d_shape* shape;
struct s3d_scene* scene;
struct s3d_scene_view* view;
+ void* shape_data; /* Client side data of the shape */
struct ssp_rng* rng; /* Random Number Generator */
size_t nwavelengths; /* #wavelengths */
@@ -560,7 +561,7 @@ radiative_properties
/* Sample a volume scaling factor if necessary */
if(distrib->sample_volume_scaling) {
res = distrib->sample_volume_scaling
- (ctx->rng, &volume_scaling, distrib->context);
+ (ctx->rng, ctx->shape_data, &volume_scaling, distrib->context);
if(res != RES_OK) {
log_error(dev, "Error in sampling a volume scaling.\n");
goto error;
@@ -1123,7 +1124,8 @@ integrator_context_release(struct integrator_context* ctx)
if(ctx->rng) SSP(rng_ref_put(ctx->rng));
if(ctx->estimator) SSCHIFF(estimator_ref_put(ctx->estimator));
if(ctx->shape) S3D(shape_ref_put(ctx->shape));
- if(ctx->scene) S3D(scene_ref_put(ctx->scene));
+ if(ctx->scene) S3D(scene_ref_put(ctx->scene));
+ if(ctx->view) S3D(scene_view_ref_put(ctx->view));
#define RELEASE(Data) if(Data) sa_release(Data)
if(ctx->accums) {
@@ -1252,7 +1254,7 @@ begin_realisation
/* Sample a particle */
res = distrib->sample
- (ctx->rng, ctx->shape, distrib->context);
+ (ctx->rng, &ctx->shape_data, ctx->shape, distrib->context);
if(res != RES_OK) {
log_error(dev, "Error in sampling a particle.\n");
goto error;
diff --git a/src/test_sschiff_estimator_cylinder.c b/src/test_sschiff_estimator_cylinder.c
@@ -58,18 +58,21 @@ get_material_property
static res_T
sample_cylinder
(struct ssp_rng* rng,
+ void** shape_data,
struct s3d_shape* shape,
void* sampler_context)
{
struct sampler_context* sampler_ctx = sampler_context;
- ASSERT(sampler_context);
+ ASSERT(sampler_context && shape_data);
(void)rng;
+ *shape_data = (void*)((intptr_t)0xDECAFBAD);
return s3d_mesh_copy(sampler_ctx->shape, shape);
}
static res_T
sample_volume_scaling
(struct ssp_rng* rng,
+ void* shape,
double* volume_scaling,
void* sampler_context)
{
@@ -77,6 +80,8 @@ sample_volume_scaling
double sample;
double sphere_volume;
ASSERT(sampler_context);
+
+ CHK(shape == (void*)((intptr_t)0xDECAFBAD));
sample = ssp_ran_lognormal(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma));
sphere_volume = 4.0*PI*sample*sample*sample / 3.0;
diff --git a/src/test_sschiff_estimator_rhodo.c b/src/test_sschiff_estimator_rhodo.c
@@ -2553,18 +2553,21 @@ get_material_property
static res_T
sample_cylinder
(struct ssp_rng* rng,
+ void** shape_data,
struct s3d_shape* shape,
void* sampler_context)
{
struct sampler_context* sampler_ctx = sampler_context;
- CHK(sampler_context);
+ CHK(sampler_context && shape_data);
(void)rng;
+ *shape_data = NULL;
return s3d_mesh_copy(sampler_ctx->shape, shape);
}
static res_T
sample_volume_scaling
(struct ssp_rng* rng,
+ void* shape,
double* volume_scaling,
void* sampler_context)
{
@@ -2572,6 +2575,7 @@ sample_volume_scaling
double sphere_volume;
double sample;
CHK(volume_scaling != NULL);
+ CHK(shape == NULL);
sample = ssp_ran_lognormal(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma));
sphere_volume = 4.0*PI*sample*sample*sample / 3.0;
diff --git a/src/test_sschiff_estimator_sphere.c b/src/test_sschiff_estimator_sphere.c
@@ -63,18 +63,20 @@ get_material_property
static res_T
sample_sphere
(struct ssp_rng* rng,
+ void** shape_data,
struct s3d_shape* shape,
void* sampler_context)
{
struct sampler_context* sampler_ctx = sampler_context;
struct sphere sphere;
-
- CHK(rng != NULL);
+ CHK(rng && shape_data);
sphere.geometry = &sampler_ctx->geometry;
sphere.radius = (float)ssp_ran_lognormal
(rng, log(sampler_ctx->mean_radius), log(sampler_ctx->sigma));
+ *shape_data = NULL;
+
return sphere_setup_s3d_shape(&sphere, shape);
}