star-line

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

commit 9f49170cb0f0823ffb52de36afe6291e6dc2f8e0
parent 51c5fbcab8cc14f428751617bf78b7e5f8801762
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  7 Apr 2026 15:04:00 +0200

Upd the function that computes the #children per node

It now also returns the number of lines per child. This means the
function can be used within the function that distributes the lines,
which requires not only the number of children but also the way the
lines are distributed among them. Until now, the calculation of the
number of children was duplicated because the number of lines per child
was an internal variable of the function. This duplication was a source
of bugs because updating the distribution policy would have required
updating both calculations, which were supposed to be identical. Now,
they are identical by design, since the same function is used.

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

diff --git a/src/sln_tree_build.c b/src/sln_tree_build.c @@ -97,11 +97,14 @@ eval_ka } static INLINE size_t -node_child_count(const struct sln_tree* tree, const size_t inode) +node_child_count + (const struct sln_tree* tree, + const size_t inode, + size_t* out_nlines_per_child) /* Max #lines per child. May be NULL */ { const struct sln_node* node = NULL; size_t nlines = 0; /* #lines in the node */ - size_t nlines_child = 0; /* #lines in a child */ + size_t nlines_per_child = 0; /* Max #lines in a child */ size_t nchildren = 0; /* Pre-conditions */ @@ -120,12 +123,13 @@ node_child_count(const struct sln_tree* tree, const size_t inode) * distribution, this option is preferred over ensuring a number of children * equal to the tree's arity. In other words, the tree's balance is * prioritized. */ - nlines_child = (nlines + tree->args.arity-1/*ceil*/)/tree->args.arity; + nlines_per_child = (nlines + tree->args.arity-1/*ceil*/)/tree->args.arity; /* From the previous line repartition, compute the number of children */ - nchildren = (nlines + nlines_child-1/*ceil*/)/nlines_child; + nchildren = (nlines + nlines_per_child-1/*ceil*/)/nlines_per_child; ASSERT(nchildren >= 2); + if(out_nlines_per_child) *out_nlines_per_child = nlines_per_child; return nchildren; } @@ -248,7 +252,7 @@ merge_children_polylines #define NODE(Id) (darray_node_data_get(&tree->nodes) + (Id)) - nchildren = node_child_count(tree, inode); + nchildren = node_child_count(tree, inode, NULL); /* Compute the number of vertices to be merged, * i.e., the sum of vertices of the children */ @@ -500,7 +504,7 @@ build_polylines2(struct sln_tree* tree) } else { const size_t ichild0 = inode + NODE(inode)->offset + 0; - const size_t nchildren = node_child_count(tree, inode); + const size_t nchildren = node_child_count(tree, inode, NULL); size_t i = 0; /* Child nodes have their polyline created */ @@ -729,12 +733,13 @@ partition_lines2(struct sln_tree* tree) /* Split the node */ } else { size_t node_range[2] = {0,0}; + size_t nlines_per_child = 0; + size_t nchildren = 0; size_t i = 0; /* Compute how the lines of a node are distributed among its children, * as well as the number of children that node has */ - const size_t nlines_child = (nlines + arity-1/*ceil*/)/arity; - const size_t nchildren = (nlines + nlines_child-1/*ceil*/)/nlines_child; + nchildren = node_child_count(tree, inode, &nlines_per_child); /* Calculate the index of the first child */ size_t ichildren = darray_node_size_get(&tree->nodes); @@ -754,8 +759,8 @@ partition_lines2(struct sln_tree* tree) /* Set the range of lines line for the newly created child. Note that * the boundaries of the range are inclusive, which is why 1 is * subtracted to the upper bound */ - NODE(ichildren+i)->range[0] = node_range[0] + nlines_child*(i+0); - NODE(ichildren+i)->range[1] = node_range[0] + nlines_child*(i+1)-1; + NODE(ichildren+i)->range[0] = node_range[0] + nlines_per_child*(i+0); + NODE(ichildren+i)->range[1] = node_range[0] + nlines_per_child*(i+1)-1; /* Check that the child's lines are a subset of the parent's lines. Note * that the upper bound of the child's line interval is not checked, as