commit faced5269910261592e0dacb15c87321434e8990
parent 1ec55162a3e031295acda8a4f2281d335563eead
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 29 Sep 2020 15:46:22 +0200
Update the profile of suvm_volume_at
Return the 4 barycentric coordinates rather than 3
Diffstat:
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/suvm.h b/src/suvm.h
@@ -55,6 +55,8 @@ struct suvm_primitive {
#define SUVM_PRIMITIVE_NULL__ {NULL, {NULL}, SIZE_MAX, SIZE_MAX}
static const struct suvm_primitive SUVM_PRIMITIVE_NULL = SUVM_PRIMITIVE_NULL__;
+#define SUVM_PRIMITIVE_NONE(Prim) ((Prim)->iprim == SIZE_MAX)
+
struct suvm_tetrahedral_mesh_args {
size_t ntetrahedra; /* #tetrahedra */
size_t nvertices; /* #vertices */
@@ -134,7 +136,7 @@ suvm_volume_at
(struct suvm_volume* volume,
const double pos[3],
struct suvm_primitive* prim, /* Geometric primitive where `pos' lies */
- double uvw[3]); /* Parametric coordinate of `pos' into the primitive */
+ double barycentric_coords[4]); /* `pos' into the primitive */
END_DECLS
diff --git a/src/suvm_volume_at.c b/src/suvm_volume_at.c
@@ -107,7 +107,7 @@ suvm_volume_at
(struct suvm_volume* vol,
const double pos_in[3],
struct suvm_primitive* prim,
- double uvw[4])
+ double barycentric_coords[4])
{
struct darray_node stack;
struct node* node = NULL;
@@ -115,19 +115,19 @@ suvm_volume_at
struct node_inner* inner = NULL;
float pos[3];
size_t iprim = SIZE_MAX; /* Index of the hit primitive */
+ int stack_is_init = 0;
res_T res = RES_OK;
- darray_node_init(vol->dev->allocator, &stack);
-
- if(!vol || !pos_in || !prim || !uvw) {
+ if(!vol || !pos_in || !prim || !barycentric_coords) {
res = RES_BAD_ARG;
goto error;
}
-
*prim = SUVM_PRIMITIVE_NULL;
pos[0] = (float)pos_in[0];
pos[1] = (float)pos_in[1];
pos[2] = (float)pos_in[2];
+ darray_node_init(vol->dev->allocator, &stack);
+ stack_is_init = 1;
node = vol->bvh_root;
ASSERT(node);
@@ -148,9 +148,10 @@ suvm_volume_at
leaf = CONTAINER_OF(node, struct node_leaf, node);
if(intersect_leaf(vol, leaf, pos, bcoords)) {
iprim = leaf->prim_id;
- uvw[0] = (double)bcoords[0];
- uvw[1] = (double)bcoords[1];
- uvw[2] = (double)bcoords[2];
+ barycentric_coords[0] = (double)bcoords[0];
+ barycentric_coords[1] = (double)bcoords[1];
+ barycentric_coords[2] = (double)bcoords[2];
+ barycentric_coords[3] = (double)bcoords[3];
break;
}
@@ -202,7 +203,7 @@ suvm_volume_at
}
exit:
- darray_node_release(&stack);
+ if(stack_is_init) darray_node_release(&stack);
return res;
error:
goto exit;