commit 8f1c0b37afd1174191fc01ed02d0830cf281f1d4
parent 558ed6fc0554eb24d1d1c6add4d00532a473f2f6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Mar 2018 15:17:31 +0100
Small upd of the svx_octree_for_each_leaf function
Diffstat:
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/src/svx_octree.c b/src/svx_octree.c
@@ -636,7 +636,7 @@ svx_octree_for_each_leaf
struct octree_index inode;
size_t depth;
double low[3];
- double upp[3];
+ double hsz[3]; /* Half size */
} stack[OCTREE_DEPTH_MAX*8];
int istack;
struct svx_voxel leaf = SVX_VOXEL_NULL;
@@ -649,40 +649,37 @@ svx_octree_for_each_leaf
stack[0].low[0] = oct->oclow[0];
stack[0].low[1] = oct->oclow[1];
stack[0].low[2] = oct->oclow[2];
- stack[0].upp[0] = oct->ocupp[0];
- stack[0].upp[1] = oct->ocupp[1];
- stack[0].upp[2] = oct->ocupp[2];
+ stack[0].hsz[0] = (oct->ocupp[0] - oct->oclow[0])*0.5;
+ stack[0].hsz[1] = (oct->ocupp[1] - oct->oclow[1])*0.5;
+ stack[0].hsz[2] = (oct->ocupp[2] - oct->oclow[2])*0.5;
istack = 1;
do {
const struct stack_entry entry = stack[--istack];
const size_t child_depth = entry.depth + 1;
+ double child_hsz[3];
+ double mid[3]; /* Middle point of the current node */
struct octree_xnode* node;
int ichild;
node = octree_buffer_get_node(&oct->buffer, entry.inode);
+ mid[0] = entry.low[0] + entry.hsz[0];
+ mid[1] = entry.low[1] + entry.hsz[1];
+ mid[2] = entry.low[2] + entry.hsz[2];
+ child_hsz[0] = entry.hsz[0] * 0.5;
+ child_hsz[1] = entry.hsz[1] * 0.5;
+ child_hsz[2] = entry.hsz[2] * 0.5;
+
FOR_EACH(ichild, 0, 8) {
const uint8_t ichild_flag = (uint8_t)BIT(ichild);
- double half_sz[3]; /* Half size of the current node */
- double mid[3]; /* Middle point of the current node */
- double upp[3];
double low[3];
if((node->is_valid & ichild_flag) == 0) continue; /* Empty node */
- half_sz[0] = (entry.upp[0] - entry.low[0])*0.5;
- half_sz[1] = (entry.upp[1] - entry.low[1])*0.5;
- half_sz[2] = (entry.upp[2] - entry.low[2])*0.5;
- mid[0] = entry.low[0] + half_sz[0];
- mid[1] = entry.low[1] + half_sz[1];
- mid[2] = entry.low[2] + half_sz[2];
low[0] = ichild&4 ? mid[0] : entry.low[0];
low[1] = ichild&2 ? mid[1] : entry.low[1];
low[2] = ichild&1 ? mid[2] : entry.low[2];
- upp[0] = low[0] + half_sz[0];
- upp[1] = low[1] + half_sz[1];
- upp[2] = low[2] + half_sz[2];
if(node->is_leaf & ichild_flag) {
struct octree_index iattr;
@@ -690,15 +687,8 @@ svx_octree_for_each_leaf
iattr = octree_buffer_get_child_attr_index
(&oct->buffer, entry.inode, ichild);
- ASSERT(upp[0] <= oct->upper[0]);
- ASSERT(upp[1] <= oct->upper[1]);
- ASSERT(upp[2] <= oct->upper[2]);
- ASSERT(low[0] >= oct->lower[0]);
- ASSERT(low[1] >= oct->lower[1]);
- ASSERT(low[2] >= oct->lower[2]);
-
d3_set(leaf.lower, low);
- d3_set(leaf.upper, upp);
+ 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.depth = child_depth;
@@ -710,12 +700,8 @@ svx_octree_for_each_leaf
top->inode = octree_buffer_get_child_node_index
(&oct->buffer, entry.inode, ichild);
- top->low[0] = low[0];
- top->low[1] = low[1];
- top->low[2] = low[2];
- top->upp[0] = upp[0];
- top->upp[1] = upp[1];
- top->upp[2] = upp[2];
+ d3_set(top->low, low);
+ d3_set(top->hsz, child_hsz);
top->depth = child_depth;
++istack;
}