commit 30e8153cd7029eb992340a84f6b0bfa2c977a2b9
parent 727196b479f34c0f139fd5eb712b36410bdbd094
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Mar 2018 16:38:29 +0100
Code refactoring
Diffstat:
2 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/src/svx.h b/src/svx.h
@@ -40,6 +40,7 @@
/* Maximum memory size of a voxel */
#define SVX_MAX_SIZEOF_VOXEL (sizeof(double)*16)
+/* Volume element */
struct svx_voxel {
double lower[3], upper[3]; /* AABB of the voxel */
const void* data; /* Data of the voxel */
@@ -112,6 +113,34 @@ static const struct svx_hit SVX_HIT_NULL = SVX_HIT_NULL__;
#define SVX_HIT_NONE(Hit) ((Hit)->distance >= DBL_MAX)
+/* Function to invoke on a leaf */
+typedef void
+(*svx_leaf_function_T)
+ (const struct svx_voxel* leaf,
+ const size_t ileaf, /* Identifier of the leaf in [0, #leafs[ */
+ void* context);
+
+/* Hit filter function data type. One can define such function to discard
+ * intersections along a ray with respect to user defined criteria, e.g.:
+ * masked/transparent voxel, etc. Return 0 or the intersection is not
+ * discarded and a value not equal to zero otherwise. */
+typedef int
+(*svx_hit_filter_function_T)
+ (const struct svx_hit* hit,
+ const double ray_org[3],
+ const double ray_dir[3],
+ void* context); /* User data submitted on trace ray invocation */
+
+/* Hit filter function data type. One can define such function to discard
+ * voxels during the traversal of the octree with respect to user defined
+ * criteria, eg, depth or size of the voxel, etc. Return 0 if the voxel is not
+ * discarded and a value not equal to zero otherwise. */
+typedef int
+(*svx_at_filter_function_T)
+ (const struct svx_voxel* voxel,
+ const double position[3],
+ void* context);
+
/* Forward declaration of external data types */
struct logger;
struct mem_allocator;
@@ -168,10 +197,7 @@ svx_octree_get_desc
SVX_API res_T
svx_octree_for_each_leaf
(struct svx_octree* octree,
- void (*functor)
- (const struct svx_voxel* leaf,
- const size_t ileaf, /* Identifier of the leaf in [0, #leafs[ */
- void* ctx), /* Client data */
+ svx_leaf_function_T functor,
void* context); /* Client data sent as the last argument of the callback */
SVX_API res_T
@@ -180,19 +206,17 @@ svx_octree_trace_ray
const double ray_origin[3],
const double ray_direction[3],
const double ray_range[2],
+ svx_hit_filter_function_T filter,
+ void* context, /* Data sent to the filter functor */
struct svx_hit* hit);
SVX_API res_T
svx_octree_at
(struct svx_octree* octree,
const double position[3],
- int (*filter) /* Filter function. May be NULL <=> traverse up to leaves */
- (const struct svx_voxel* voxel,
- const double position[3], /* Submitted position */
- void* ctx), /* Client data */
+ svx_at_filter_function_T filter,
void* context, /* Client data sent as the last argument of the filter func */
struct svx_voxel* voxel);
#endif /* SVX_H */
-
diff --git a/src/svx_octree.c b/src/svx_octree.c
@@ -715,11 +715,8 @@ res_T
svx_octree_at
(struct svx_octree* oct,
const double position[3],
- int (*filter) /* Filter function. May be NULL */
- (const struct svx_voxel* voxel,
- const double position[3],
- void* ctx),
- void* context, /* Client data sent as the last argument of the filter func */
+ svx_at_filter_function_T filter,
+ void* context,
struct svx_voxel* voxel)
{
struct octree_index inode;