star-uvm

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

commit b9380a86aa98f8a8b9ef70f2906f79f675e3e751
parent 8fd1fe4ea96cbe4e9990615567e211def3792ad3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 16 Dec 2020 14:29:29 +0100

Test the voxelisation of a tetrahedron

Diffstat:
Msrc/test_suvm_primitive_intersection.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/src/test_suvm_primitive_intersection.c b/src/test_suvm_primitive_intersection.c @@ -54,7 +54,52 @@ get_position(const size_t ivert, double pos[3], void* ctx) } static void -test_tetra_aabb_intersection(struct suvm_device* dev) +write_voxels + (FILE* stream, + const enum suvm_intersection_type* vxls, + const size_t def[3], + const float vxl_sz[3]) +{ + size_t ix, iy, iz; + size_t ivxl; + size_t i; + CHK(stream && vxls && def && def[0] && def[1] && def[2]); + + fprintf(stream, "# vtk DataFile Version 2.0\n"); + fprintf(stream, "nothing\n"); + fprintf(stream, "ASCII\n"); + + fprintf(stream, "DATASET RECTILINEAR_GRID\n"); + fprintf(stream, "DIMENSIONS %lu %lu %lu\n", def[0]+1, def[1]+1, def[2]+1); + fprintf(stream, "X_COORDINATES %lu float\n", def[0]+1); + FOR_EACH(i, 0, def[0]+1) fprintf(stream, "%g ", (float)i*vxl_sz[0]); + fprintf(stream, "\n"); + fprintf(stream, "Y_COORDINATES %lu float\n", def[1]+1); + FOR_EACH(i, 0, def[1]+1) fprintf(stream, "%g ", (float)i*vxl_sz[1]); + fprintf(stream, "\n"); + fprintf(stream, "Z_COORDINATES %lu float\n", def[2]+1); + FOR_EACH(i, 0, def[2]+1) fprintf(stream, "%g ", (float)i*vxl_sz[2]); + fprintf(stream, "\n"); + + fprintf(stream, "CELL_DATA %lu\n", def[0]*def[1]*def[2]); + fprintf(stream, "SCALARS intersect_type int 1\n"); + fprintf(stream, "LOOKUP_TABLE default\n"); + + ivxl = 0; + FOR_EACH(iz, 0, def[2]) { + FOR_EACH(iy, 0, def[1]) { + FOR_EACH(ix, 0, def[0]) { + fprintf(stream, "%i\n", vxls[ivxl]); + ++ivxl; + } + } + } +} + +static void +test_tetra_aabb_intersection + (struct suvm_device* dev, + struct mem_allocator* allocator) { const double vertices[] = { 0.0, 0.0, 0.0, @@ -70,7 +115,12 @@ test_tetra_aabb_intersection(struct suvm_device* dev) struct suvm_volume* vol= NULL; float low[3]; float upp[3]; + const size_t def[3] = {16, 16, 16}; size_t nprims; + size_t ix, iy, iz; + enum suvm_intersection_type* vxls = NULL; + float vxl_sz[3]; + size_t ivxl; args.ntetrahedra = 1; args.nvertices = 4; @@ -107,6 +157,30 @@ test_tetra_aabb_intersection(struct suvm_device* dev) f3(upp, 1.f, 1.f, 0.66665f /*~ 1-1/3 */); CHK(suvm_polyhedron_intersect_aabb(&poly, low, upp) == SUVM_INTERSECT_NONE); + CHK(allocator != NULL); + vxls = MEM_CALLOC(allocator, def[0]*def[1]*def[2], sizeof(*vxls)); + CHK(vxls != NULL); + + vxl_sz[0] = 1.f/(float)def[0]; + vxl_sz[1] = 1.f/(float)def[1]; + vxl_sz[2] = 1.f/(float)def[2]; + ivxl = 0; + FOR_EACH(iz, 0, def[2]) { + low[2] = (float)iz * vxl_sz[2]; + upp[2] = low[2] + vxl_sz[2]; + FOR_EACH(iy, 0, def[1]) { + low[1] = (float)iy * vxl_sz[1]; + upp[1] = low[1] + vxl_sz[1]; + FOR_EACH(ix, 0, def[0]) { + low[0] = (float)ix * vxl_sz[0]; + upp[0] = low[0] + vxl_sz[0]; + vxls[ivxl] = suvm_polyhedron_intersect_aabb(&poly, low, upp); + ++ivxl; + } + } + } + write_voxels(stderr, vxls, def, vxl_sz); + MEM_RM(allocator, vxls); CHK(suvm_volume_ref_put(vol) == RES_OK); } @@ -121,7 +195,7 @@ main(int argc, char** argv) CHK(suvm_device_create(NULL, &mem_default_allocator, 1, &dev) == RES_OK); - test_tetra_aabb_intersection(dev); + test_tetra_aabb_intersection(dev, &mem_default_allocator); CHK(suvm_device_ref_put(dev) == RES_OK); check_memory_allocator(&mem_default_allocator);