commit e11f21b907a6d11677627f5a4671dd923366f181
parent 9a2da88754a9b5042ec8ef8d501912ec209b4542
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 5 Feb 2018 09:47:02 +0100
Add to the merge functor a pointer toward client side data
Diffstat:
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/htvox.h b/src/htvox.h
@@ -84,8 +84,8 @@ htvox_scene_create
const double upper[3], /* Upper bound of the scene */
const size_t nvoxels[3], /* # voxels along the 3 axis */
void (*get)(const size_t xyz[3], double* value, void* ctx),
- int (*merge)(const double min_val, const double max_val),
- void* context, /* Client data send as the last param of the `get' callback */
+ int (*merge)(const double min_val, const double max_val, void* ctx),
+ void* context, /* Client data send as the last param of the callbacks */
struct htvox_scene** scn);
HTVOX_API res_T
diff --git a/src/htvox_scene.c b/src/htvox_scene.c
@@ -43,7 +43,8 @@ struct stack {
struct octree_builder {
struct stack stacks[OCTREE_DEPTH_MAX];
struct octree_buffer* buffer;
- int (*merge)(const double min_val, const double max_val);
+ int (*merge)(const double min_val, const double max_val, void* ctx);
+ void* context; /* Client side data sent to the merge callback */
int octree_depth;
uint64_t mcode; /* Morton code of the last registered voxels */
};
@@ -68,7 +69,8 @@ static INLINE void
stack_setup_node
(struct stack* stack,
struct octree_node* node,
- int (*merge_func)(const double min_val, const double max_val))
+ int (*merge_func)(const double min_val, const double max_val, void* ctx),
+ void* context)
{
double data_min = DBL_MAX;
double data_max =-DBL_MAX;
@@ -97,7 +99,7 @@ stack_setup_node
if(data_min == VOXEL_EMPTY_DATA || data_max == VOXEL_EMPTY_DATA) {
merge = data_min == data_max;
} else {
- merge = merge_func(data_min, data_max);
+ merge = merge_func(data_min, data_max, context);
}
if(merge) {
node->is_leaf = 1;
@@ -195,7 +197,8 @@ static res_T
octree_builder_init
(struct octree_builder* bldr,
const size_t definition,
- int (*merge)(const double min_val, const double max_val),
+ int (*merge)(const double min_val, const double max_val, void* ctx),
+ void* context,
struct octree_buffer* buffer)
{
int ilvl;
@@ -217,6 +220,7 @@ octree_builder_init
octree_buffer_clear(buffer);
bldr->merge = merge;
+ bldr->context = context;
bldr->buffer = buffer;
exit:
@@ -255,7 +259,8 @@ octree_builder_add_voxel(struct octree_builder* bldr, const struct voxel* vox)
/* The next voxel is not in the ilvl^th stack. Setup the parent node of the
* nodes registered into the stack */
stack_node = &bldr->stacks[ilvl+1].nodes[bldr->stacks[ilvl+1].len];
- stack_setup_node(&bldr->stacks[ilvl], stack_node, bldr->merge);
+ stack_setup_node
+ (&bldr->stacks[ilvl], stack_node, bldr->merge, bldr->context);
bldr->stacks[ilvl+1].len += 1;
ASSERT(bldr->stacks[ilvl+1].len <= 8);
@@ -323,7 +328,7 @@ htvox_scene_create
const double upper[3], /* Upper bound of the scene */
const size_t nvoxels[3], /* # voxels along the 3 axis */
void (*get)(const size_t xyz[3], double* value, void* ctx),
- int (*merge)(const double min_val, const double max_val),
+ int (*merge)(const double min_val, const double max_val, void* ctx),
void* context, /* Client data send as the last param of the `get' callback */
struct htvox_scene** out_scn)
{
@@ -391,7 +396,8 @@ htvox_scene_create
scn->definition = round_up_pow2(scn->definition);
/* Intialize the octree builder */
- res = octree_builder_init(&bldr, scn->definition, merge, &scn->buffer);
+ res = octree_builder_init
+ (&bldr, scn->definition, merge, context, &scn->buffer);
if(res != RES_OK) goto error;
mcode_max = scn->definition * scn->definition * scn->definition;