star-vx

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

commit f72b19c13ab06c1ec14926fc3647eab85fb63ab9
parent 91b1381d6b978f013543e5329adf6faec4c2424e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  6 Feb 2018 14:59:40 +0100

Test and fix the htvox_scene_at function

Diffstat:
Msrc/htvox_scene.c | 7++++---
Msrc/test_htvox_scene.c | 35++++++++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/src/htvox_scene.c b/src/htvox_scene.c @@ -673,6 +673,7 @@ htvox_scene_at low[2] = 0; scale_exp2 = 0.5; + inode = scn->root; do { struct octree_xnode* node = octree_buffer_get_node(&scn->buffer, inode); @@ -697,9 +698,9 @@ htvox_scene_at /* Define the child of the current node into which pos `lies' and compute * its lower left corner */ - if(pos[0] > mid[0]) { ichild |= 4; low[0] += mid[0]; } - if(pos[1] > mid[1]) { ichild |= 2; low[1] += mid[1]; } - if(pos[2] > mid[2]) { ichild |= 1; low[2] += mid[2]; } + if(pos[0] > mid[0]) { ichild |= 4; low[0] = mid[0]; } + if(pos[1] > mid[1]) { ichild |= 2; low[1] = mid[1]; } + if(pos[2] > mid[2]) { ichild |= 1; low[2] = mid[2]; } /* Fetch the child node */ inode = octree_buffer_get_child_index(&scn->buffer, inode, ichild); diff --git a/src/test_htvox_scene.c b/src/test_htvox_scene.c @@ -209,10 +209,13 @@ main(int argc, char** argv) struct mem_allocator allocator; double low[3]; double upp[3]; + double pos[3]; + double delta[3]; size_t nvxls[3]; size_t nvoxels; struct check_context ctx; void* ptr = (void*)0xDECAFBAD; + size_t x, y, z; (void)argc, (void)argv; CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); @@ -221,7 +224,7 @@ main(int argc, char** argv) d3_splat(low, 0.0); d3_splat(upp, 1.0); - nvxls[0] = nvxls[1] = nvxls[2] = 10; + nvxls[0] = nvxls[1] = nvxls[2] = 5; ctx.lower = low; ctx.upper = upp; @@ -262,6 +265,34 @@ main(int argc, char** argv) CHK(htvox_scene_get_voxels_count(scn, &nvoxels) == RES_OK); CHK(nvoxels == nvxls[0]*nvxls[1]*nvxls[2]); + delta[0] = (upp[0] - low[0])/(double)nvxls[0]; + delta[1] = (upp[1] - low[1])/(double)nvxls[1]; + delta[2] = (upp[2] - low[2])/(double)nvxls[2]; + + FOR_EACH(x, 0, nvxls[0]) { + pos[0] = low[0] + ((double)x + 0.5) * delta[0]; + FOR_EACH(y, 0, nvxls[1]) { + pos[1] = low[1] + ((double)y + 0.5) * delta[1]; + FOR_EACH(z, 0, nvxls[2]) { + struct htvox_voxel vox; + uint32_t ui3[3]; + uint64_t mcode; + + pos[2] = low[2] + ((double)z + 0.5) * delta[2]; + + ui3[0] = (uint32_t)x; + ui3[1] = (uint32_t)y; + ui3[2] = (uint32_t)z; + + CHK(htvox_scene_at(scn, pos, &vox) == RES_OK); + CHK(!HTVOX_VOXEL_NONE(&vox)); + + mcode = morton_xyz_encode_u21(ui3); + CHK(vox.data == mcode); + } + } + } + d3_splat(low, DBL_MAX); d3_splat(upp,-DBL_MAX); CHK(htvox_scene_get_aabb(NULL, low, upp) == RES_BAD_ARG); @@ -272,6 +303,8 @@ main(int argc, char** argv) CHK(upp[0] == 1 && upp[1] == 1 && upp[2] == 1); CHK(htvox_scene_ref_put(scn) == RES_OK); + + nvxls[0] = nvxls[1] = nvxls[2] = 8; CHK(NEW_SCN(dev, low, upp, nvxls, get, merge_level0, ptr, &scn) == RES_OK); CHK(htvox_scene_get_voxels_count(scn, &nvoxels) == RES_OK); CHK(nvoxels == nvxls[0]*nvxls[1]*nvxls[2] / 8);