star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit 626f7604c074eee33127620c024fa146c3ac8d43
parent 4cfb3b80788932e28a777d4ab8e55640c442946b
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Thu,  6 Mar 2025 16:46:58 +0100

Expand the API for geometry

Implement getters for geometries in volumes and surfaces. Implements a
getter for the geometry descriptor.

Diffstat:
Msrc/sphin.h | 27+++++++++++++++++++++++++--
Msrc/sphin_config.c | 4++--
Msrc/sphin_geometry.c | 25+++++++++++++++++++++++++
Msrc/sphin_surface.c | 37+++++++++++++++++++++++++++++++++++--
Msrc/sphin_volume.c | 38++++++++++++++++++++++++++++++++++++--
5 files changed, 123 insertions(+), 8 deletions(-)

diff --git a/src/sphin.h b/src/sphin.h @@ -150,9 +150,9 @@ static const struct sphin_source_direction_distribution * The responsibility for interpreting or structuring this data lies with the * user or the functions that load the mesh. */ struct sphin_mesh { - const double *coords; /* A sequence of triplets (x, y, z): + const double* coords; /* A sequence of triplets (x, y, z): * [x0, y0, z0, x1, y1, z1, ...] */ - const size_t *indices; /* A sequence of indices that represents each triangle + const size_t* indices; /* A sequence of indices that represents each triangle * in the coords array */ size_t triangle_count; size_t vertex_count; @@ -284,6 +284,18 @@ SPHIN_API res_T sphin_volume_get_sensor (struct sphin_volume* volume, struct sphin_sensor** sensor); + +SPHIN_API res_T +sphin_volume_get_geometry_count + (struct sphin_volume* volume, + size_t* ngeometries); + +SPHIN_API res_T +sphin_volume_get_geometry + (struct sphin_volume* volume, + size_t igeometry, + struct sphin_geometry** geometry); + /******************************************************************************* * API of the surface ******************************************************************************/ @@ -305,6 +317,17 @@ sphin_surface_get_source (const struct sphin_surface* surface, struct sphin_source** source); /* May be NULL <=> no source */ +SPHIN_API res_T +sphin_surface_get_geometry_count + (struct sphin_surface* surface, + size_t* ngeometries); + +SPHIN_API res_T +sphin_surface_get_geometry + (struct sphin_surface* surface, + size_t igeometry, + struct sphin_geometry** geometry); + /******************************************************************************* * API of the source ******************************************************************************/ diff --git a/src/sphin_config.c b/src/sphin_config.c @@ -375,7 +375,7 @@ sphin_config_get_volume return RES_BAD_ARG; } - res = sphin_config_get_volume_count(config, &nvolumes); + nvolumes = darray_sphin_volume_ptr_size_get(&config->volumes); if (RES_OK != res || ivolume > nvolumes) { return RES_BAD_ARG; } @@ -410,7 +410,7 @@ sphin_config_get_surface return RES_BAD_ARG; } - res = sphin_config_get_surface_count(config, &nsurfaces); + nsurfaces = darray_sphin_surface_ptr_size_get(&config->surfaces); if (RES_OK != res || isurface > nsurfaces) { return RES_BAD_ARG; } diff --git a/src/sphin_geometry.c b/src/sphin_geometry.c @@ -189,3 +189,28 @@ sphin_geometry_ref_put(struct sphin_geometry* geometry) ref_put(&geometry->ref, release_geometry); return RES_OK; } + +res_T +sphin_geometry_get_desc + (const struct sphin_geometry* geometry, + struct sphin_geometry_descriptor* desc) +{ + char* filename = NULL; + struct sphin_mesh mesh = SPHIN_MESH_NULL; + + if (NULL == geometry || NULL == desc) { + return RES_BAD_ARG; + } + + mesh.coords = darray_double_data_get((struct darray_double*)&geometry->coords); + mesh.indices = darray_size_t_data_get((struct darray_size_t*)&geometry->indices); + mesh.vertex_count = darray_double_size_get(&geometry->coords) / 3; + mesh.triangle_count = darray_size_t_size_get(&geometry->indices) / 3; + + filename = (char*)str_get((struct str*)&geometry->stl_filename); + desc->filename = filename; + desc->side = geometry->side; + desc->mesh = mesh; + + return RES_OK; +} diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -214,11 +214,9 @@ parse_surface res = parse_brdf(surface->sphin, txtrdr, token, &surface->brdf); } else if (0 == strcmp(keyword, "source")) { - token = trim_string(token); res = parse_source(surface->sphin, txtrdr, name, &surface->source); } else if (0 == strcmp(keyword, "sensor")) { - token = trim_string(token); res = parse_sensor(surface->sphin, txtrdr, name, &surface->sensor); } else { @@ -289,3 +287,38 @@ sphin_surface_get_source *source = surface->source; /* NULL if surface has no source */ return RES_OK; } + +res_T +sphin_surface_get_geometry_count + (struct sphin_surface* surface, + size_t* ngeometries) +{ + if (NULL == surface) { + return RES_BAD_ARG; + } + + *ngeometries = darray_sphin_geometry_ptr_size_get(&surface->geometries); + + return RES_OK; +} + +res_T +sphin_surface_get_geometry + (struct sphin_surface* surface, + size_t igeometry, + struct sphin_geometry** geometry) +{ + size_t ngeometries; + if (NULL == surface) { + return RES_BAD_ARG; + } + + ngeometries = darray_sphin_geometry_ptr_size_get(&surface->geometries); + if (igeometry > ngeometries) { + return RES_BAD_ARG; + } + + *geometry = darray_sphin_geometry_ptr_data_get(&surface->geometries)[igeometry]; + + return RES_OK; +} diff --git a/src/sphin_volume.c b/src/sphin_volume.c @@ -250,8 +250,7 @@ parse_volume res = parse_ka(volume, txtrdr, token); } else if (0 == strcmp(keyword, "sensor")) { - token = trim_string(token); - res = parse_sensor(volume->sphin, txtrdr, token, &volume->sensor); + res = parse_sensor(volume->sphin, txtrdr, name, &volume->sensor); } else { break; @@ -320,3 +319,38 @@ sphin_volume_get_sensor *sensor = volume->sensor; return RES_OK; } + +res_T +sphin_volume_get_geometry_count + (struct sphin_volume* volume, + size_t* ngeometries) +{ + if (NULL == volume) { + return RES_BAD_ARG; + } + + *ngeometries = darray_sphin_geometry_ptr_size_get(&volume->geometries); + + return RES_OK; +} + +res_T +sphin_volume_get_geometry + (struct sphin_volume* volume, + size_t igeometry, + struct sphin_geometry** geometry) +{ + size_t ngeometries; + if (NULL == volume) { + return RES_BAD_ARG; + } + + ngeometries = darray_sphin_geometry_ptr_size_get(&volume->geometries); + if (igeometry > ngeometries) { + return RES_BAD_ARG; + } + + *geometry = darray_sphin_geometry_ptr_data_get(&volume->geometries)[igeometry]; + + return RES_OK; +}