commit 916b8a4c8938502c4c5fcde09bc39f365799baf3
parent 72af64630300e75b52271b1e691a8d19556c6ca0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 7 Jan 2021 12:04:03 +0100
Upd the comportment of the suvm_volume_intersect_aabb function
Up to now, a volumetric primitives was considered as "intersecting" the
box when its AABB was intersected. This test was actually conservative.
In this commit, we now perform the real intersection test between the
tetrahedra and the box and thus we return only the tetrahedra that
effectively are intersected by the box.
Diffstat:
3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/src/suvm.h b/src/suvm.h
@@ -192,9 +192,8 @@ suvm_volume_at
struct suvm_primitive* prim, /* Geometric primitive where `pos' lies */
double barycentric_coords[4]); /* `pos' into the primitive */
-/* Iterate over the volumetric primitives whose axis aligned bounding box
- * intersects the submitted Axis Aligned Bounding Box and invoke the `clbk'
- * function onto them. */
+/* Iterate over the volumetric primitives intersecting the submitted Axis
+ * Aligned Bounding Box and invoke the `clbk' function onto them. */
SUVM_API res_T
suvm_volume_intersect_aabb
(struct suvm_volume* volume,
diff --git a/src/suvm_volume_intersect_aabb.c b/src/suvm_volume_intersect_aabb.c
@@ -96,8 +96,16 @@ suvm_volume_intersect_aabb
size_t istack;
if(node->type == NODE_LEAF) {
+ struct suvm_polyhedron tetra;
+ enum suvm_intersection_type intersect;
+
leaf = CONTAINER_OF(node, struct node_leaf, node);
- if(aabb_intersect_aabb(lowf, uppf, leaf->low, leaf->upp)) {
+
+ /* Check the intersection between the tetrahedron and the AABB */
+ tetrahedron_setup(vol, leaf->low, leaf->upp, leaf->prim_id, &tetra);
+ intersect = suvm_polyhedron_intersect_aabb(&tetra, lowf, uppf);
+
+ if(intersect != SUVM_INTERSECT_NONE) {
struct suvm_primitive prim = SUVM_PRIMITIVE_NULL;
/* Setup the intersected primitive */
volume_primitive_setup(vol, leaf->prim_id, &prim);
diff --git a/src/test_suvm_volume.c b/src/test_suvm_volume.c
@@ -415,6 +415,8 @@ check_prims_intersect_aabb
double vtx[4][3];
double prim_low[3];
double prim_upp[3];
+ float lowf[3];
+ float uppf[3];
CHK(primitives);
prims = darray_prim_data_get(primitives);
@@ -451,26 +453,19 @@ check_prims_intersect_aabb
* that the input primitives are effectively the same of the ones detected by
* this brute force procedure */
iprim_challenge = 0;
+ f3_set_d3(lowf, low);
+ f3_set_d3(uppf, upp);
FOR_EACH(iprim, 0, msh->ntetrahedra) {
- /* Fetch tetrahedron vertices */
- get_indices(iprim, ids, msh);
- get_position(ids[0], vtx[0], msh);
- get_position(ids[1], vtx[1], msh);
- get_position(ids[2], vtx[2], msh);
- get_position(ids[3], vtx[3], msh);
+ struct suvm_primitive prim;
+ struct suvm_polyhedron tetra;
+ enum suvm_intersection_type intersect;
- /* Compute the primitive AABB */
- prim_low[0] = MMIN(MMIN(vtx[0][0], vtx[1][0]), MMIN(vtx[2][0], vtx[3][0]));
- prim_low[1] = MMIN(MMIN(vtx[0][1], vtx[1][1]), MMIN(vtx[2][1], vtx[3][1]));
- prim_low[2] = MMIN(MMIN(vtx[0][2], vtx[1][2]), MMIN(vtx[2][2], vtx[3][2]));
- prim_upp[0] = MMAX(MMAX(vtx[0][0], vtx[1][0]), MMAX(vtx[2][0], vtx[3][0]));
- prim_upp[1] = MMAX(MMAX(vtx[0][1], vtx[1][1]), MMAX(vtx[2][1], vtx[3][1]));
- prim_upp[2] = MMAX(MMAX(vtx[0][2], vtx[1][2]), MMAX(vtx[2][2], vtx[3][2]));
+ CHK(suvm_volume_get_primitive(vol, iprim, &prim) == RES_OK);
+ CHK(suvm_primitive_setup_polyhedron(&prim, &tetra) == RES_OK);
- /* Check that the primitives intersect the AABB */
- if(prim_low[0] < upp[0] && prim_upp[0] > low[0]
- && prim_low[1] < upp[1] && prim_upp[1] > low[1]
- && prim_low[2] < upp[2] && prim_upp[2] > low[2]) {
+ /* Check that the primitive intersects the AABB */
+ intersect = suvm_polyhedron_intersect_aabb(&tetra, lowf, uppf);
+ if(intersect != SUVM_INTERSECT_NONE) {
CHK(iprim == prims[iprim_challenge].iprim);
++iprim_challenge;
}