commit 134ae95a64866f8b5668b022635b4e5e60906c78
parent 2e58e37060b0623813c7e6242ecddf1393e4ff8b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 29 Oct 2015 14:13:42 +0100
Refactor the definition of the S3D spherical mesh
Add the schiff_mesh_get_<indices|position> functions and rely on them
to setup the S3D mesh of the sphere.
Diffstat:
2 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/src/schiff_mesh.h b/src/schiff_mesh.h
@@ -58,5 +58,35 @@ schiff_mesh_dump
(struct schiff_mesh* mesh,
const char* filename);
+static INLINE void
+schiff_mesh_get_indices
+ (struct schiff_mesh* mesh,
+ const unsigned itri,
+ unsigned ids[3])
+{
+ const size_t i = itri * 3;
+ ASSERT(mesh);
+ ASSERT(darray_uint_size_get(&mesh->indices) % 3 == 0);
+ ASSERT(itri < darray_uint_size_get(&mesh->indices) / 3);
+ ids[0] = darray_uint_data_get(&mesh->indices)[i + 0];
+ ids[1] = darray_uint_data_get(&mesh->indices)[i + 1];
+ ids[2] = darray_uint_data_get(&mesh->indices)[i + 2];
+}
+
+static INLINE void
+schiff_mesh_get_position
+ (struct schiff_mesh* mesh,
+ const unsigned ivert,
+ float vertex[3])
+{
+ const size_t i = ivert * 3;
+ ASSERT(mesh && vertex);
+ ASSERT(darray_float_size_get(&mesh->vertices) % 3 == 0);
+ ASSERT(ivert < darray_float_size_get(&mesh->vertices) / 3);
+ vertex[0] = darray_float_data_get(&mesh->vertices)[i + 0];
+ vertex[1] = darray_float_data_get(&mesh->vertices)[i + 1];
+ vertex[2] = darray_float_data_get(&mesh->vertices)[i + 2];
+}
+
#endif /* SBOX_SCHIFF_MESH_H */
diff --git a/src/schiff_sphere.c b/src/schiff_sphere.c
@@ -47,9 +47,9 @@ struct sphere {
/* Geometry distribution of a sphere */
struct schiff_sphere_geometry_distribution_context {
- struct schiff_mesh* mesh; /* Triangular mesh of an unit sphere */
+ struct schiff_mesh* mesh; /* Triangular mesh of the template mesh */
struct schiff_optical_properties* properties; /* Per wavelength properties */
- double log_mean_radius; /* Log of the mean sphere radius */
+ double log_mean_radius; /* Log of the mean radius */
double log_sigma; /* Log of the sigma argument of the lognormal distribution*/
};
@@ -60,22 +60,14 @@ static void
get_indices(const unsigned itri, unsigned ids[3], void* ctx)
{
struct sphere* sphere = ctx;
- const size_t i = itri * 3;
- ASSERT(darray_uint_size_get(&sphere->mesh->indices) % 3 == 0);
- ASSERT(itri < darray_uint_size_get(&sphere->mesh->indices) / 3);
- ids[0] = darray_uint_data_get(&sphere->mesh->indices)[i + 0];
- ids[1] = darray_uint_data_get(&sphere->mesh->indices)[i + 1];
- ids[2] = darray_uint_data_get(&sphere->mesh->indices)[i + 2];
+ schiff_mesh_get_indices(sphere->mesh, itri, ids);
}
static void
get_position(const unsigned ivert, float vertex[3], void* ctx)
{
struct sphere* sphere = ctx;
- const size_t i = ivert * 3;
- ASSERT(darray_float_size_get(&sphere->mesh->vertices) % 3 == 0);
- ASSERT(ivert < darray_float_size_get(&sphere->mesh->vertices) / 3);
- f3_set(vertex, darray_float_data_get(&sphere->mesh->vertices) + i);
+ schiff_mesh_get_position(sphere->mesh, ivert, vertex);
f3_mulf(vertex, vertex, sphere->radius);
}
@@ -149,7 +141,6 @@ schiff_sphere_sample_geometry
get_indices, (unsigned)nverts, &attrib, 1, &sphere);
}
-
/*******************************************************************************
* Local functions
******************************************************************************/
@@ -180,13 +171,11 @@ schiff_run_sphere
}
}
- /* Generate the spherical mesh */
+ /* Generate the mesh template of the distribution */
res = schiff_mesh_init_sphere
(&mem_default_allocator, &mesh, args->distrib.sphere.nslices);
if(res != RES_OK) {
- fprintf(stderr,
- "Couldn't create the sphere mesh discretised in %u steps along 2PI\n",
- args->distrib.sphere.nslices);
+ fprintf(stderr, "Couldn't create the mesh template of the distribution.\n");
goto error;
}