star-line

Structure for accelerating line importance sampling
git clone git://git.meso-star.fr/star-line.git
Log | Files | Refs | README | LICENSE

commit 5988c0e10871220ec62d94324d42c66b564caeaa
parent 6fa5435894fc593813354a27ad591e0fb092edb9
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 29 Apr 2026 12:30:35 +0200

Fix an issue when constructing a tree from subtree

When the tree is constructed in a single step, the polylines of the
child nodes are either all already constructed or must all be
constructed. This is no longer necessarily true when the tree is
constructed by first building subtrees. The children corresponding to
the roots of the subtrees then have their polylines, but the children
that are not roots of subtrees do not.

Hence this commit, which modifies the function that constructs the
polyline for a tree's nodes so that it takes into account that some
children of a node may have their polyline and others may not.

Diffstat:
Msrc/sln_tree_build.c | 25+++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/sln_tree_build.c b/src/sln_tree_build.c @@ -767,10 +767,16 @@ build_polylines const size_t ichild0 = inode + NODE(inode)->offset + 0; const struct sln_node* node = darray_node_cdata_get(&tree->nodes)+inode; const unsigned nchildren = node_child_count(node, tree->args.arity); + int child_polylines_are_missing = 1; size_t i = 0; + FOR_EACH(i, 0, nchildren) { + child_polylines_are_missing = NODE(ichild0 + i)->nvertices == 0; + if(child_polylines_are_missing) break; + } + /* Child nodes have their polyline created */ - if(NODE(ichild0)->nvertices) { + if(!child_polylines_are_missing) { #ifndef NDEBUG /* Check that all children have their polylines created */ FOR_EACH(i, 1, nchildren) { @@ -794,15 +800,18 @@ build_polylines ASSERT(istack + (nchildren - 1/*ichild0*/ + 1/*inode*/) <= STACK_SIZE); stack[istack++] = inode; /* Push the current node */ - /* Push the children except the 1st one */ - FOR_EACH_REVERSE(i, nchildren-1, 0) { - const size_t ichild = ichild0 + i; - ASSERT(NODE(ichild)->nvertices == 0); - stack[istack++] = ichild; + /* Push the child nodes, except for those whose polyline has already + * been constructed, as is the case when the child node was the root + * of a separately constructed subtree */ + FOR_EACH_REVERSE(i, nchildren, 0) { + const size_t ichild = ichild0 + i-1; + if(NODE(ichild)->nvertices == 0) stack[istack++] = ichild; } - /* Recursively build the polyline of the 1st child */ - inode = ichild0; + /* Ensure that at least one child was pushed */ + ASSERT(stack[istack-1] != inode); + + inode = stack[--istack]; /* Recursively build the polyline of the 1st child */ } }