star-uvm

Spatial structuring of unstructured volumetric meshes
git clone git://git.meso-star.fr/star-uvm.git
Log | Files | Refs | README | LICENSE

commit 660741337dce874990e602570dda88832537bbcb
parent 05fd610446aef20b2b554a377d95ae3b37c7b047
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 24 Sep 2020 15:36:29 +0200

Upd the profile of suvm_tetrahedral_mesh_create

Diffstat:
Msrc/suvm.h | 25++++++++++++++++++-------
Msrc/suvm_volume.c | 61++++++++++++++++++++++++++++++-------------------------------
2 files changed, 48 insertions(+), 38 deletions(-)

diff --git a/src/suvm.h b/src/suvm.h @@ -53,6 +53,23 @@ struct suvm_primitive { size_t nvertices; /* #vertices of the primitive */ }; +struct suvm_tetrahedral_mesh_args { + size_t ntetrahedras; /* #tetrahedrals */ + size_t nvertices; /* #vertices */ + + /* Each tetrahedra has to list the bottom triangle in conterclockwise order, + * and then the top vertex. */ + void (*get_indices)(const size_t itetra, size_t ids[4], void* ctx); + void (*get_position)(const size_t ivert, double pos[3], void* ctx); + + /* Per tetrahedra/vertex data. SUVM_DATA_NULL <=> no data */ + struct suvm_data tetrahedra_data; + struct suvm_data vertex_data; + + void* context; /* Client data set as the last param of the callbacks */ +}; +static const struct suvm_tetrahedral_mesh_args SUVM_TETRAHEDRAL_MESH_ARGS_NULL; + /* Forward declaration of external data types */ struct logger; struct mem_allocator; @@ -87,13 +104,7 @@ suvm_device_ref_put SUVM_API res_T suvm_tetrahedral_mesh_create (struct suvm_device* dev, - const size_t ntetras, /* #tetrahedrals */ - void (*get_indices)(const size_t itetra, size_t ids[4], void* ctx), - const struct suvm_data* tetra_data, /* NULL <=> no tetra data */ - const size_t nverts, /* #vertices */ - void (*get_position)(const size_t ivert, const double pos[3], void* ctx), - const struct suvm_data* vert_data, /* NULL <=> no vertex data */ - void* context, /* Client data set as the last param of the callbacks */ + const struct suvm_tetrahedral_mesh_args* args, struct suvm_volume** volume); SUVM_API res_T diff --git a/src/suvm_volume.c b/src/suvm_volume.c @@ -81,6 +81,16 @@ struct suvm_volume { /******************************************************************************* * Helper functions ******************************************************************************/ +static INLINE int +check_tetrahedral_mesh_args(const struct suvm_tetrahedral_mesh_args* args) +{ + return args + && args->ntetrahedras + && args->nvertices + && args->get_indices + && args->get_position; +} + static INLINE void buffer_release(struct buffer* buf) { @@ -144,48 +154,43 @@ volume_get_primitives_count(const struct suvm_volume* vol) static res_T setup_tetrahedral_mesh - (struct suvm_volume* vol, - const size_t ntetras, - void (*get_indices)(const size_t itetra, size_t ids[4], void* ctx), - const struct suvm_data* tetra_data, - const size_t nverts, - void (*get_position)(const size_t ivert, const double pos[3], void* ctx), - const struct suvm_data* vert_data, - void* context) + (struct suvm_volume* vol, const struct suvm_tetrahedral_mesh_args* args) { size_t itetra; size_t ivert; res_T res = RES_OK; - ASSERT(vol && ntetras && get_indices && nverts && get_position); + ASSERT(vol && args); /* Store the tetrahedral indices */ - res = darray_size_t_resize(&vol->indices, ntetras*4/*#vertices per tetra*/); + res = darray_size_t_resize + (&vol->indices, args->ntetrahedras*4/*#vertices per tetra*/); if(res != RES_OK) { log_err(vol->dev, "Could not allocate list of tetrahedra indices -- %s.\n", res_to_cstr(res)); goto error; } - FOR_EACH(itetra, 0, ntetras) { + FOR_EACH(itetra, 0, args->ntetrahedras) { size_t* tetra = darray_size_t_data_get(&vol->indices)+itetra*4; - get_indices(itetra, tetra, context); + args->get_indices(itetra, tetra, args->context); } /* Store the vertex positions */ - res = darray_double_resize(&vol->positions, nverts*3/*#coords per vertex*/); + res = darray_double_resize + (&vol->positions, args->nvertices*3/*#coords per vertex*/); if(res != RES_OK) { log_err(vol->dev, "Could not allocate the list tetrahedra vertices -- %s.\n", res_to_cstr(res)); goto error; } - FOR_EACH(ivert, 0, nverts) { + FOR_EACH(ivert, 0, args->nvertices) { double* vert = darray_double_data_get(&vol->positions)+ivert*3; - get_position(ivert, vert, context); + args->get_position(ivert, vert, args->context); } /* Store the per tetrahedral data */ - if(tetra_data && tetra_data->get) { - res = buffer_init_from_data - (vol->dev->allocator, &vol->prim_data, tetra_data, ntetras); + if(args->tetrahedra_data.get) { + res = buffer_init_from_data(vol->dev->allocator, &vol->prim_data, + &args->tetrahedra_data, args->ntetrahedras); if(res != RES_OK) { log_err(vol->dev, "Could not setup the per volumetric primitive data -- %s.\n", @@ -195,9 +200,9 @@ setup_tetrahedral_mesh } /* Store the per vertex data */ - if(vert_data && vert_data->get) { - res = buffer_init_from_data - (vol->dev->allocator, &vol->vert_data, vert_data, nverts); + if(args->vertex_data.get) { + res = buffer_init_from_data(vol->dev->allocator, &vol->vert_data, + &args->vertex_data, args->nvertices); if(res != RES_OK) { log_err(vol->dev, "Could not setup the per vertex data -- %s.\n", res_to_cstr(res)); @@ -420,19 +425,13 @@ volume_release(ref_T* ref) res_T suvm_tetrahedral_mesh_create (struct suvm_device* dev, - const size_t ntetras, - void (*get_indices)(const size_t itetha, size_t ids[4], void* ctx), - const struct suvm_data* tetra_data, - const size_t nverts, - void (*get_position)(const size_t ivert, const double pos[3], void* ctx), - const struct suvm_data* vert_data, - void* context, + const struct suvm_tetrahedral_mesh_args* args, struct suvm_volume** out_vol) { struct suvm_volume* vol = NULL; res_T res = RES_OK; - if(!dev || !ntetras || !get_indices || !nverts || !get_position || !out_vol) { + if(!dev || !check_tetrahedral_mesh_args(args) || !out_vol) { res = RES_BAD_ARG; goto error; } @@ -449,10 +448,10 @@ suvm_tetrahedral_mesh_create darray_double_init(dev->allocator, &vol->positions); /* Locally copy the volumetric mesh data */ - res = setup_tetrahedral_mesh(vol, ntetras, get_indices, tetra_data, nverts, - get_position, vert_data, context); + res = setup_tetrahedral_mesh(vol, args); if(res != RES_OK) goto error; + /* Build the BVH of the volumetric mesh */ res = build_bvh(vol); if(res != RES_OK) goto error;