commit ce9caaa0e19532455d8cb83db8951bfd5d348873
parent d0864ba7039e87982c546a9eccae68a76ffe9991
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 31 Aug 2022 09:15:50 +0200
Add and test suvm_get_mesh_desc function
Diffstat:
3 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/src/suvm.h b/src/suvm.h
@@ -97,6 +97,18 @@ struct suvm_polyhedron {
float upper[3/*#coords*/];
};
+/* Internal copy of the unstructured mesh */
+struct suvm_mesh_desc {
+ const float* positions;
+ const uint32_t* indices;
+ size_t nvertices;
+ size_t nprimitives;
+ unsigned dvertex; /* Dimension of a vertex */
+ unsigned dprimitive; /* Dimension of a primitive */
+};
+#define SUVM_MESH_DESC_NULL__ {NULL, NULL, 0, 0, 0, 0}
+static const struct suvm_mesh_desc SUVM_MESH_DESC_NULL = SUVM_MESH_DESC_NULL__;
+
struct suvm_tetrahedral_mesh_args {
size_t ntetrahedra; /* #tetrahedra */
size_t nvertices; /* #vertices */
@@ -229,6 +241,11 @@ suvm_volume_compute_hash
const int cpnt_mask, /* Combination of suvm_volume_cpnt_flag */
hash256_T hash);
+SUVM_API res_T
+suvm_volume_get_mesh_desc
+ (const struct suvm_volume* volume,
+ struct suvm_mesh_desc* desc);
+
/*******************************************************************************
* Primitive API
******************************************************************************/
diff --git a/src/suvm_volume.c b/src/suvm_volume.c
@@ -762,3 +762,28 @@ exit:
error:
goto exit;
}
+
+res_T
+suvm_volume_get_mesh_desc
+ (const struct suvm_volume* vol,
+ struct suvm_mesh_desc* desc)
+{
+ res_T res = RES_OK;
+
+ if(!vol || !desc) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ desc->positions = darray_float_cdata_get(&vol->positions);
+ desc->indices = darray_u32_cdata_get(&vol->indices);
+ desc->dvertex = 3;
+ desc->dprimitive = 4;
+ desc->nvertices = darray_float_size_get(&vol->positions) / desc->dvertex;
+ desc->nprimitives = darray_u32_size_get(&vol->indices) / desc->dprimitive;
+
+exit:
+ return res;
+error:
+ goto exit;
+}
diff --git a/src/test_suvm_volume.c b/src/test_suvm_volume.c
@@ -169,12 +169,38 @@ check_volume_polyhedra(const struct suvm_volume* vol, struct mesh* msh)
}
static void
+check_volume_mesh(const struct suvm_volume* vol, struct mesh* msh)
+{
+ struct suvm_mesh_desc desc = SUVM_MESH_DESC_NULL;
+ size_t i;
+
+ CHK(suvm_volume_get_mesh_desc(vol, &desc) == RES_OK);
+ CHK(desc.nvertices == msh->nvertices);
+ CHK(desc.nprimitives == msh->ntetrahedra);
+ CHK(desc.dvertex == 3);
+ CHK(desc.dprimitive == 4);
+
+ FOR_EACH(i, 0, desc.nvertices) {
+ CHK(desc.positions[i*3+0] == (float)msh->vertices[i*3+0]);
+ CHK(desc.positions[i*3+1] == (float)msh->vertices[i*3+1]);
+ CHK(desc.positions[i*3+2] == (float)msh->vertices[i*3+2]);
+ }
+ FOR_EACH(i, 0, desc.nprimitives) {
+ CHK(desc.indices[i*4+0] == (uint32_t)msh->tetrahedra[i*4+0]);
+ CHK(desc.indices[i*4+1] == (uint32_t)msh->tetrahedra[i*4+1]);
+ CHK(desc.indices[i*4+2] == (uint32_t)msh->tetrahedra[i*4+2]);
+ CHK(desc.indices[i*4+3] == (uint32_t)msh->tetrahedra[i*4+3]);
+ }
+}
+
+static void
test_tetrahedral_mesh_creation(struct suvm_device* dev)
{
struct mesh msh = MESH_NULL;
struct suvm_tetrahedral_mesh_args args = SUVM_TETRAHEDRAL_MESH_ARGS_NULL;
struct suvm_volume* vol = NULL;
struct suvm_primitive prim = SUVM_PRIMITIVE_NULL;
+ struct suvm_mesh_desc desc = SUVM_MESH_DESC_NULL;
struct suvm_polyhedron poly;
size_t nprims;
@@ -272,6 +298,12 @@ test_tetrahedral_mesh_creation(struct suvm_device* dev)
check_volume_polyhedra(vol, &msh);
+ CHK(suvm_volume_get_mesh_desc(NULL, &desc) == RES_BAD_ARG);
+ CHK(suvm_volume_get_mesh_desc(vol, NULL) == RES_BAD_ARG);
+ CHK(suvm_volume_get_mesh_desc(vol, &desc) == RES_OK);
+
+ check_volume_mesh(vol, &msh);
+
CHK(suvm_volume_ref_put(vol) == RES_OK);
}
@@ -671,6 +703,7 @@ test_volume_at_cube(struct suvm_device* dev)
msh.vertex_data_alignment = args.vertex_data.alignment;
CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK);
+ check_volume_mesh(vol, &msh);
pos[0] = 0.25;
pos[1] = 0.4;
@@ -821,6 +854,7 @@ test_volume_at_ball(struct suvm_device* dev)
aabb_sz = d3_len(d3_sub(vec, aabb_upp, aabb_low));
CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK);
+ check_volume_mesh(vol, &msh);
check_volume_polyhedra(vol, &msh);