commit 7f8e5e1d44a19afb0a0e0d00b3f5932fa5062071
parent 2b89d0131e302a1f82e3698cbd1ab6e337398d37
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Oct 2015 16:05:04 +0200
Update the estimator test
Randomly sample a super shape rather than always returning the Cornell
Box.
Diffstat:
2 files changed, 100 insertions(+), 69 deletions(-)
diff --git a/src/salgae_estimator.c b/src/salgae_estimator.c
@@ -39,7 +39,7 @@
#include <star/s3d.h>
#include <star/ssp.h>
-#define NDIRS 10
+#define NDIRS 5
struct salgae_estimator {
size_t nsteps;
@@ -185,7 +185,8 @@ static res_T
radiative_path_length
(struct salgae_device* dev,
struct ssp_rng* rng,
- struct salgae_integrator_desc* desc)
+ struct salgae_integrator_desc* desc,
+ const int istep)
{
struct s3d_shape* shape = NULL;
struct s3d_scene* scene = NULL;
@@ -265,7 +266,7 @@ radiative_path_length
f3_min(lower, lower, pt[i]);
f3_max(upper, upper, pt[i]);
}
- sprintf(thumb_name, "thumb_%d.ppm", idir);
+ sprintf(thumb_name, "%d_%d.ppm", istep, idir);
trace_rays(scene, basis, centroid, lower, upper, thumb_name);
}
S3D(scene_end_session(scene));
@@ -341,6 +342,7 @@ salgae_integrate
struct salgae_estimator** out_estimator)
{
struct salgae_estimator* estimator = NULL;
+ int i;
res_T res = RES_OK;
if(!dev || !rng || !desc || !check_desc(desc) || wavelength < 0.0
@@ -354,8 +356,10 @@ salgae_integrate
estimator->nsteps = steps_count;
estimator->wavelength = wavelength;
- res = radiative_path_length(dev, rng, desc);
- if(res != RES_OK) goto error;
+ FOR_EACH(i, 0, (int)steps_count) {
+ res = radiative_path_length(dev, rng, desc, i);
+ if(res != RES_OK) goto error;
+ }
exit:
if(out_estimator) *out_estimator = estimator;
diff --git a/src/test_salgae_estimator.c b/src/test_salgae_estimator.c
@@ -34,73 +34,76 @@
#include <star/s3d.h>
#include <star/ssp.h>
-static const float verts[] = {
- /* Box */
- 552.f, 0.f, 0.f,
- 0.f, 0.f, 0.f,
- 0.f, 559.f, 0.f,
- 552.f, 559.f, 0.f,
- 552.f, 0.f, 548.f,
- 0.f, 0.f, 548.f,
- 0.f, 559.f, 548.f,
- 552.f, 559.f, 548.f,
- /* Short block */
- 130.f, 65.f, 0.f,
- 82.f, 225.f, 0.f,
- 240.f, 272.f, 0.f,
- 290.f, 114.f, 0.f,
- 130.f, 65.f, 165.f,
- 82.f, 225.f, 165.f,
- 240.f, 272.f, 165.f,
- 290.f, 114.f, 165.f,
- /* Tall block */
- 423.0f, 247.0f, 0.f,
- 265.0f, 296.0f, 0.f,
- 314.0f, 456.0f, 0.f,
- 472.0f, 406.0f, 0.f,
- 423.0f, 247.0f, 330.f,
- 265.0f, 296.0f, 330.f,
- 314.0f, 456.0f, 330.f,
- 472.0f, 406.0f, 330.f
-};
-static const unsigned nverts = (unsigned)(sizeof(verts) / (sizeof(float)*3));
-static const unsigned ids[] = {
- /* Box */
- 0, 1, 2, 2, 3, 0,
- 4, 5, 6, 6, 7, 4,
- 1, 2, 6, 6, 5, 1,
- 0, 3, 7, 7, 4, 0,
- 2, 3, 7, 7, 6, 2,
- /* Short block */
- 12, 13, 14, 14, 15, 12,
- 9, 10, 14, 14, 13, 9,
- 8, 11, 15, 15, 12, 8,
- 10, 11, 15, 15, 14, 10,
- 8, 9, 13, 13, 12, 8,
- /* Tall block */
- 20, 21, 22, 22, 23, 20,
- 17, 18, 22, 22, 21, 17,
- 16, 19, 23, 23, 20, 16,
- 18, 19, 23, 23, 22, 18,
- 16, 17, 21, 21, 20, 16
+#define STEP 0.05f
+
+enum { A, B, M, N0, N1, N2 };
+
+struct super_shape {
+ float super_formulas[2][6];
+ size_t ntheta, nphi;
};
-static const unsigned nids = (unsigned)(sizeof(ids)/sizeof(uint32_t));
static void
-get_ids(const unsigned itri, unsigned indices[3], void* data)
+super_shape_get_indices(const unsigned itri, unsigned ids[3], void* ctx)
{
- const unsigned id = itri * 3;
- (void)data;
- indices[0] = ids[id + 0];
- indices[1] = ids[id + 1];
- indices[2] = ids[id + 2];
+ struct super_shape* sshape = ctx;
+ const size_t iquad = itri / 2;
+ const size_t iquad_tri = itri % 2;
+ const size_t i = iquad / (sshape->nphi - 1);
+ const size_t j = iquad % (sshape->nphi - 1);
+ size_t A, B;
+
+ B = i * sshape->nphi + j + 1;
+ A = ((i + 1) % sshape->ntheta) * sshape->nphi + j;
+ if(iquad_tri == 0) {
+ ids[0] = (unsigned)B - 1;
+ ids[1] = (unsigned)A;
+ ids[2] = (unsigned)B;
+ } else { ASSERT(iquad_tri == 1);
+ ids[0] = (unsigned)B;
+ ids[1] = (unsigned)A;
+ ids[2] = (unsigned)A + 1;
+ }
}
static void
-get_pos(const unsigned ivert, float vertex[3], void* data)
+super_shape_get_vertex_position(const unsigned ivert, float vertex[3], void* ctx)
{
- (void)data;
- f3_set(vertex, verts + (ivert*3));
+ struct super_shape* sshape = ctx;
+ const size_t itheta = ivert / sshape->nphi;
+ const size_t iphi = ivert % sshape->nphi;
+ double angle[2];
+ double sin_angle[2];
+ double cos_angle[2];
+ double uv[2];
+ int iform;
+ ASSERT(itheta < sshape->ntheta);
+
+ if(iphi == sshape->nphi - 1) { /* Polar vertices: Force polar coordinates */
+ angle[0] = PI;
+ angle[1] = PI/2;
+ } else {
+ angle[0] = -PI + (double)itheta * STEP;
+ angle[1] = -PI/2 + (double)iphi * STEP;
+ }
+
+ FOR_EACH(iform, 0, 2) {
+ double m, k, g;
+ float* form = sshape->super_formulas[iform];
+ m = cos(form[M] * angle[iform] / 4.0);
+ m = fabs(m) / form[A];
+ k = sin(form[M] * angle[iform] / 4.0);
+ k = fabs(k) / form[B];
+ g = pow(m, form[N1]) + pow(k, form[N2]);
+ uv[iform] = pow(g, (-1.0/form[N0]));
+
+ cos_angle[iform] = cos(angle[iform]);
+ sin_angle[iform] = sin(angle[iform]);
+ }
+
+ vertex[0] = (float)(uv[0] * cos_angle[0] * uv[1] * cos_angle[1]);
+ vertex[1] = (float)(uv[0] * sin_angle[0] * uv[1] * cos_angle[1]);
+ vertex[2] = (float)(uv[1] * sin_angle[1]);
}
static res_T
@@ -111,18 +114,42 @@ sample_geometry
void* sampler_context)
{
struct s3d_vertex_data attrib;
+ struct super_shape sshape;
+ const size_t ntheta = (int)((2*PI)/STEP) + 1;
+ const size_t nphi = (int)((PI)/STEP) + 1;
+ const size_t nverts = ntheta * nphi;
+ const size_t nprims = ntheta * (nphi - 1)/*#quads*/ * 2/*#triangles*/;
+
(void)sampler_context;
+
NCHECK(rng, NULL);
NCHECK(mtl, NULL);
NCHECK(shape, NULL);
attrib.usage = S3D_POSITION;
attrib.type = S3D_FLOAT3;
- attrib.get = get_pos;
+ attrib.get = super_shape_get_vertex_position;
+
+ sshape.super_formulas[0][A] = 1;
+ sshape.super_formulas[0][B] = 1;
+ sshape.super_formulas[0][M] = (float)ssp_rng_uniform_double(rng, 0.1, 6);
+ sshape.super_formulas[0][N0] = 1;
+ sshape.super_formulas[0][N1] = 1;
+ sshape.super_formulas[0][N2] = (float)ssp_rng_uniform_double(rng, 0.1, 6);
+
+ sshape.super_formulas[1][A] = 1;
+ sshape.super_formulas[1][B] = 1;
+ sshape.super_formulas[1][M] = (float)ssp_rng_uniform_double(rng, 0.1, 6);
+ sshape.super_formulas[1][N0] = 1;
+ sshape.super_formulas[1][N1] = 1;
+ sshape.super_formulas[1][N2] = (float)ssp_rng_uniform_double(rng, 0.1, 6);
+
+ sshape.ntheta = ntheta;
+ sshape.nphi = nphi;
*mtl = SALGAE_NULL_MATERIAL;
- return s3d_mesh_setup_indexed_vertices
- (shape, nids/3, get_ids, nverts, &attrib, 1, NULL);
+ return s3d_mesh_setup_indexed_vertices(shape, (unsigned)nprims,
+ super_shape_get_indices, (unsigned)nverts, &attrib, 1, &sshape);
}
int
@@ -138,7 +165,7 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
- CHECK(salgae_device_create(NULL, &allocator, 1, NULL, &dev), RES_OK);
+ CHECK(salgae_device_create(NULL, &allocator, 0, NULL, &dev), RES_OK);
desc.sample_geometry = sample_geometry;
desc.scattering_angles_count = 1;
@@ -157,7 +184,7 @@ main(int argc, char** argv)
CHECK(salgae_integrate(NULL, NULL, &desc, 0, 1, &estimator), RES_BAD_ARG);
CHECK(salgae_integrate(dev, NULL, &desc, 0, 1, &estimator), RES_BAD_ARG);
CHECK(salgae_integrate(NULL, rng, &desc, 0, 1, &estimator), RES_BAD_ARG);
- CHECK(salgae_integrate(dev, rng, &desc, 0, 1, &estimator), RES_OK);
+ CHECK(salgae_integrate(dev, rng, &desc, 0, 10, &estimator), RES_OK);
CHECK(salgae_estimator_ref_get(NULL), RES_BAD_ARG);
CHECK(salgae_estimator_ref_get(estimator), RES_OK);