commit 76293eee22c16ebe70d800333937176f7a8a649d
parent 1bd5a776351aa1e583232659702f062ee3dcdb0c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 9 Mar 2018 12:19:53 +0100
Fix compilation of the svx_octree_trace_ray function
Diffstat:
4 files changed, 43 insertions(+), 45 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -43,7 +43,8 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(SVX_FILES_SRC
svx_device.c
svx_octree.c
- svx_octree_buffer.c)
+ svx_octree_buffer.c
+ svx_octree_trace_ray.c)
set(SSOL_FILES_INC
svx_device.h
svx_octree.h
diff --git a/src/svx_octree.c b/src/svx_octree.c
@@ -85,16 +85,6 @@ check_octree(struct octree_buffer* buf, const struct octree_index root)
}
#endif
-static FINLINE size_t
-absolute_attr_index
- (const struct octree_buffer* buf,
- const struct octree_index index)
-{
- ASSERT(buf);
- return index.ipage * buf->pagesize/buf->voxsize + index.inode;
-
-}
-
static INLINE int
check_svx_voxel_desc(const struct svx_voxel_desc* desc)
{
@@ -622,8 +612,8 @@ svx_octree_get_desc
d3_set(desc->lower, oct->lower);
d3_set(desc->upper, oct->upper);
desc->nleaves = oct->nleaves;
- desc->nvoxels = absolute_attr_index(&oct->buffer, oct->buffer.attr_head)
- + 1; /* Root node */
+ desc->nvoxels = octree_buffer_absolute_attr_index
+ (&oct->buffer, oct->buffer.attr_head) + 1; /* Root node */
desc->depth = oct->depth;
return RES_OK;
}
@@ -695,7 +685,7 @@ svx_octree_for_each_leaf
d3_set(leaf.lower, low);
d3_add(leaf.upper, low, entry.hsz);
leaf.data = octree_buffer_get_attr(&oct->buffer, iattr);
- leaf.id = absolute_attr_index(&oct->buffer, iattr);
+ leaf.id = octree_buffer_absolute_attr_index(&oct->buffer, iattr);
leaf.depth = child_depth;
leaf.is_leaf = 1;
@@ -769,7 +759,7 @@ svx_octree_at
d3_set(vox.upper, oct->upper);
if(filter) {
vox.data = oct->root_attr;
- vox.id = absolute_attr_index(&oct->buffer, oct->buffer.attr_head);
+ vox.id = octree_buffer_absolute_attr_index(&oct->buffer, oct->buffer.attr_head);
if(!filter(&vox, position, context)) { *voxel = vox; goto exit; }
}
@@ -810,7 +800,7 @@ svx_octree_at
vox.upper[1] = vox.lower[1] + ocsz[1] * scale_exp2;
vox.upper[2] = vox.lower[2] + ocsz[2] * scale_exp2;
vox.data = octree_buffer_get_attr(&oct->buffer, iattr);
- vox.id = absolute_attr_index(&oct->buffer, iattr);
+ vox.id = octree_buffer_absolute_attr_index(&oct->buffer, iattr);
vox.is_leaf = (node->is_leaf & ichild_flag) != 0;
if(vox.is_leaf || !filter(&vox, position, context)) {
diff --git a/src/svx_octree_buffer.h b/src/svx_octree_buffer.h
@@ -236,4 +236,13 @@ octree_buffer_get_child_attr_index
return child_id;
}
+static FINLINE size_t
+octree_buffer_absolute_attr_index
+ (const struct octree_buffer* buf,
+ const struct octree_index index)
+{
+ ASSERT(buf);
+ return index.ipage * buf->pagesize/buf->voxsize + index.inode;
+}
+
#endif /* SVX_OCTREE_BUFFER_H */
diff --git a/src/svx_octree_trace_ray.c b/src/svx_octree_trace_ray.c
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "svx.h"
-#include "svx_scene.h"
+#include "svx_octree.h"
struct ray {
/* Ray parameters in the normalized octree space [1, 2]^3 whose ray direction
@@ -56,10 +56,10 @@ uitof(const uint32_t ui)
static FINLINE void
setup_hit
- (const struct svx_octree* oct,
+ (struct svx_octree* oct,
const struct octree_index iattr, /* Index toward the voxel attributes */
const double distance, /* Hit distance */
- const double corner[3], /* Corner of the current voxel in [1, 2]^3 space */
+ const float corner[3], /* Corner of the current voxel in [1, 2]^3 space */
const double scale_exp2, /* Size of the voxel in [1, 2]^3] space */
const size_t depth, /* Depth of the voxel in the octree hierarchy */
const int is_leaf, /* Define if the voxel is a leaf or not */
@@ -67,13 +67,13 @@ setup_hit
struct svx_hit* hit)
{
double low[3], upp[3];
- ASSERT(oct && corner && voxsz && hit);
+ ASSERT(oct && corner && hit);
ASSERT(distance > 0);
hit->distance = distance;
- hit->voxel.data = octree_buffer_get_attr(&oct->buffer, &iattr);
+ hit->voxel.data = octree_buffer_get_attr(&oct->buffer, iattr);
hit->voxel.depth = depth,
- hit->voxel.id = absolute_attr_index(&oct->buffer, iattr);
+ hit->voxel.id = octree_buffer_absolute_attr_index(&oct->buffer, iattr);
hit->voxel.is_leaf = is_leaf;
/* Transform the voxel aabb in the [0, 1]^3 normalized space and flip it wrt
@@ -101,9 +101,9 @@ setup_hit
static res_T
setup_ray
(const struct svx_octree* oct,
- const double org[3]
+ const double org[3],
const double dir[3],
- const double range[2]
+ const double range[2],
struct ray* ray)
{
double rcp_ocsz[3]; /* Reciprocal size of the World space octree AABB */
@@ -141,15 +141,15 @@ setup_ray
/* Let a ray defines as org + t*dir and X the coordinate of an axis aligned
* plane. The ray intersects X at t = (X - org)/dir = (X - org) * ts; with ts
* = 1/dir. Note that one assume that dir is always negative. */
- ray->ts[0] = 1.0 / -abs(dir_adjusted[0]);
- ray->ts[1] = 1.0 / -abs(dir_adjusted[1]);
- ray->ts[2] = 1.0 / -abs(dir_adjusted[2]);
+ ray->ts[0] = 1.0 / -fabs(dir_adjusted[0]);
+ ray->ts[1] = 1.0 / -fabs(dir_adjusted[1]);
+ ray->ts[2] = 1.0 / -fabs(dir_adjusted[2]);
/* Mirror rays with position directions */
ray->octant_mask = 0;
- if(ray_dir[0] > 0) { ray->octant_mask ^= 4; ray->org[0] = 3.0 - ray->org[0]; }
- if(ray_dir[1] > 0) { ray->octant_mask ^= 2; ray->org[0] = 3.0 - ray->org[1]; }
- if(ray_dir[2] > 0) { ray->octant_mask ^= 1; ray->org[0] = 3.0 - ray->org[2]; }
+ if(dir[0] > 0) { ray->octant_mask ^= 4; ray->org[0] = 3.0 - ray->org[0]; }
+ if(dir[1] > 0) { ray->octant_mask ^= 2; ray->org[0] = 3.0 - ray->org[1]; }
+ if(dir[2] > 0) { ray->octant_mask ^= 1; ray->org[0] = 3.0 - ray->org[2]; }
/* Save the world space ray origin */
ray->orgws[0] = org[0];
@@ -166,10 +166,11 @@ setup_ray
static res_T
trace_ray
- (const struct svx_octree* oct,
- const svx_challenge_voxel_T challenge,
- const svx_hit_filter_function_T filter,
+ (struct svx_octree* oct,
const struct ray* ray,
+ const svx_hit_challenge_T challenge,
+ const svx_hit_filter_T filter,
+ void* context,
struct svx_hit* hit)
{
#define SCALE_MAX 23 /* #mantisse bits */
@@ -178,19 +179,15 @@ trace_ray
double t_max;
} stack[SCALE_MAX + 1/*Dummy entry use to avoid invalid read*/];
struct octree_index inode;
- double t_min, tmax;
- float low[3], upp[3]; /* AABB of the current node in normalized space */
- float mid[3]; /* Middle point of the current node in normalized space */
+ double t_min, t_max;
float corner[3];
float scale_exp2;
+ uint32_t scale_max;
uint32_t scale; /* stack index */
uint32_t ichild;
ASSERT(oct && ray && hit);
- hit = SVX_HIT_NONE; /* Initialise the hit to "no intersection" */
-
- f3_splat(low, 1);
- f3_splat(upp, 2);
+ *hit = SVX_HIT_NULL; /* Initialise the hit to "no intersection" */
/* Compute the min/max ray intersection with the octree AABB in normalized
* space. Note that in this space, the octree AABB is in [1, 2]^3 */
@@ -239,7 +236,7 @@ trace_ray
/* Traverse the current child */
if((node->is_valid & ichild_flag)
&& t_min <= (t_max_child = MMIN(t_max, t_max_corner))) {
- const int is_leaf = is_leaf = (node->is_leaf & ichild_flag) != 0;
+ const int is_leaf = (node->is_leaf & ichild_flag) != 0;
int go_deeper = 1;
/* If the current voxel is a leaf or if a challenge function is set,
@@ -248,7 +245,7 @@ trace_ray
const double dst = t_min < ray->range[0] ? t_max_child : t_min;
const size_t depth = SCALE_MAX - scale;
const struct octree_index iattr = octree_buffer_get_child_attr_index
- (&oct->buffer, &inode, ichild_adjusted);
+ (&oct->buffer, inode, (int)ichild_adjusted);
setup_hit(oct, iattr, dst, corner, scale_exp2, depth, is_leaf,
ray->octant_mask, hit);
@@ -376,8 +373,8 @@ svx_octree_trace_ray
const double org[3],
const double dir[3],
const double range[2],
- svx_challenge_voxel_T challenge,
- svx_hit_filter_function_T filter,
+ svx_hit_challenge_T challenge,
+ svx_hit_filter_T filter,
void* context,
struct svx_hit* hit)
{
@@ -397,7 +394,7 @@ svx_octree_trace_ray
goto exit;
}
- res = trace_ray(oct, challenge, filter, ray, hit);
+ res = trace_ray(oct, &ray, challenge, filter, context, hit);
if(res != RES_OK) goto error;
exit:
@@ -405,3 +402,4 @@ exit:
error:
goto exit;
}
+