star-vx

Structuring voxels for ray-tracing
git clone git://git.meso-star.fr/star-vx.git
Log | Files | Refs | README | LICENSE

commit 39261db9d22d4717126ce51d4636dace11abace2
parent 7edac48da854da3190c5cd1e969b9cdb643bdb28
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 14 Sep 2018 09:56:58 +0200

Merge the svx_<oc|bin>tree_trace_ray functions

Replace the <oc|bin>tree trace functions by the svx_tree_trace_ray
function that is generic to the tree type.

Diffstat:
Msrc/svx.h | 16++--------------
Msrc/svx_bintree_trace_ray.c | 2+-
Msrc/svx_octree_trace_ray.c | 8++++----
Msrc/svx_tree.c | 27+++++++++++++++++++++++++++
Msrc/svx_tree.h | 22++++++++++++++++++++++
Msrc/test_svx_bintree_trace_ray.c | 4++--
Msrc/test_svx_octree_trace_ray.c | 4++--
7 files changed, 60 insertions(+), 23 deletions(-)

diff --git a/src/svx.h b/src/svx.h @@ -254,22 +254,10 @@ svx_tree_for_each_leaf void* context); /* Client data sent as the last argument of the functor */ SVX_API res_T -svx_octree_trace_ray +svx_tree_trace_ray (struct svx_tree* tree, const double ray_origin[3], - const double ray_direction[3], - const double ray_range[2], - const svx_hit_challenge_T challenge, /* NULL <=> Traversed up to the leaves */ - const svx_hit_filter_T filter, /* NULL <=> Stop RT at the 1st hit voxel */ - void* context, /* Data sent to the filter functor */ - struct svx_hit* hit); - -/* TODO merge with the svx_octree_trace_ray API */ -SVX_API res_T -svx_bintree_trace_ray - (struct svx_tree* tree, - const double ray_origin[3], - const double ray_direction[3], + const double ray_direction[3], /* Must be normalized */ const double ray_range[2], const svx_hit_challenge_T challenge, /* NULL <=> Traversed up to the leaves */ const svx_hit_filter_T filter, /* NULL <=> Stop RT at the 1st hit voxel */ diff --git a/src/svx_bintree_trace_ray.c b/src/svx_bintree_trace_ray.c @@ -64,7 +64,7 @@ setup_hit * Exported function ******************************************************************************/ res_T -svx_bintree_trace_ray +bintree_trace_ray (struct svx_tree* btree, const double ray_org[3], const double ray_dir[3], diff --git a/src/svx_octree_trace_ray.c b/src/svx_octree_trace_ray.c @@ -375,16 +375,16 @@ trace_ray } /******************************************************************************* - * Exported function + * Local function ******************************************************************************/ res_T -svx_octree_trace_ray +octree_trace_ray (struct svx_tree* oct, const double org[3], const double dir[3], const double range[2], - svx_hit_challenge_T challenge, - svx_hit_filter_T filter, + const svx_hit_challenge_T challenge, + const svx_hit_filter_T filter, void* context, struct svx_hit* hit) { diff --git a/src/svx_tree.c b/src/svx_tree.c @@ -95,6 +95,33 @@ svx_tree_for_each_leaf(struct svx_tree* tree, svx_leaf_function_T func, void* ct } res_T +svx_tree_trace_ray + (struct svx_tree* tree, + const double org[3], + const double dir[3], + const double range[2], + const svx_hit_challenge_T challenge, /* NULL <=> Traversed up to the leaves */ + const svx_hit_filter_T filter, /* NULL <=> Stop RT at the 1st hit voxel */ + void* context, /* Data sent to the filter functor */ + struct svx_hit* hit) +{ + res_T res = RES_OK; + if(!tree) return RES_BAD_ARG; + switch(tree->type) { + case SVX_BINTREE: + res = bintree_trace_ray + (tree, org, dir, range, challenge, filter, context, hit); + break; + case SVX_OCTREE: + res = octree_trace_ray + (tree, org, dir, range, challenge, filter, context, hit); + break; + default: FATAL("Unreachable code.\n"); break; + } + return res; +} + +res_T svx_tree_at (struct svx_tree* tree, const double pos[3], diff --git a/src/svx_tree.h b/src/svx_tree.h @@ -52,5 +52,27 @@ tree_create const size_t vxsz, struct svx_tree** out_tree); +extern LOCAL_SYM res_T +octree_trace_ray + (struct svx_tree* oct, + const double ray_origin[3], + const double ray_direction[3], + const double ray_range[2], + const svx_hit_challenge_T challenge, + const svx_hit_filter_T filter, + void* context, + struct svx_hit* hit); + +extern LOCAL_SYM res_T +bintree_trace_ray + (struct svx_tree* btree, + const double ray_origin[3], + const double ray_direction[3], + const double ray_range[2], + const svx_hit_challenge_T challenge, + const svx_hit_filter_T filter, + void* context, + struct svx_hit* hit); + #endif /* SVX_TREE_H */ diff --git a/src/test_svx_bintree_trace_ray.c b/src/test_svx_bintree_trace_ray.c @@ -186,7 +186,7 @@ draw_image(FILE* stream, struct svx_tree* btree) pix[0] = (double)ix / (double)width; camera_ray(&cam, pix, &r); - CHK(svx_bintree_trace_ray + CHK(svx_tree_trace_ray (btree, r.org, r.dir, r.range, NULL, hit_filter, &r, &hit) == RES_OK); pixels[ipix+0] = 0; pixels[ipix+1] = 0; @@ -246,7 +246,7 @@ main(int argc, char** argv) d3(r.dir, -1, 0, 0); d2(r.range, 0, DBL_MAX); - #define RT svx_bintree_trace_ray + #define RT svx_tree_trace_ray CHK(RT(NULL, r.org, r.dir, r.range, NULL, NULL, NULL, &hit) == RES_BAD_ARG); CHK(RT(btree, NULL, r.dir, r.range, NULL, NULL, NULL, &hit) == RES_BAD_ARG); CHK(RT(btree, r.org, NULL, r.range, NULL, NULL, NULL, &hit) == RES_BAD_ARG); diff --git a/src/test_svx_octree_trace_ray.c b/src/test_svx_octree_trace_ray.c @@ -220,7 +220,7 @@ draw_image(FILE* stream, struct svx_tree* oct, const struct scene* scn) pix[0] = (double)ix / (double)width; camera_ray(&cam, pix, &r); - CHK(svx_octree_trace_ray + CHK(svx_tree_trace_ray (oct, r.org, r.dir, r.range, NULL, hit_filter, &r, &hit) == RES_OK); if(SVX_HIT_NONE(&hit)) { pixels[ipix+0] = 0; @@ -296,7 +296,7 @@ main(int argc, char** argv) /*dump_data(stdout, oct, CHAR__, 1, write_scalars);*/ - #define RT svx_octree_trace_ray + #define RT svx_tree_trace_ray d3(r.org, -5,-5, 0); d3(r.dir, 0, 1, 0); d2(r.range, 0, INF);