star-line

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

commit 650297586f4e5cc9330ee424fcfb85039ca50efd
parent 1c3d7a18170221d6445d5322385d8655c36f1f36
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  6 Mar 2026 17:56:04 +0100

Print progress message during structure construction

Two progress messages are printed: one for line partitioning, the other
for meshing the structure node spectrum.

The messages displayed notify the percentage of progress, printed every
10%. No dynamic updating of the progress message is used in order to
avoid the use of escape sequences. Even though the escape character '\r'
that would then be used is certainly supported by all terminals that
will ever be used with the library, its use would in any case make
logging messages more difficult when they are redirected to a text file.
Hence this simple and stupid solution, supported everywhere and by all
outputs, including files.

Diffstat:
Msrc/sln_tree_build.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/sln_tree_build.c b/src/sln_tree_build.c @@ -176,17 +176,27 @@ build_polylines(struct sln_tree* tree) size_t stack[STACK_SIZE*2]; size_t istack = 0; size_t inode = 0; + size_t nnodes_total = 0; + size_t nnodes_processed = 0; + int progress = 0; res_T res = RES_OK; ASSERT(tree); + #define LOG_MSG "Meshing: %3d%%\n" #define NODE(Id) (darray_node_data_get(&tree->nodes) + (Id)) #define IS_LEAF(Id) (NODE(Id)->offset == 0) + nnodes_total = darray_node_size_get(&tree->nodes); + + /* Print that nothing has been done yet */ + INFO(tree->sln, LOG_MSG, progress); + /* Push back SIZE_MAX which, once pop up, will mark the end of recursion */ stack[istack++] = SIZE_MAX; inode = 0; /* Root node */ while(inode != SIZE_MAX) { + const size_t istack_saved = istack; if(IS_LEAF(inode)) { res = build_leaf_polyline(tree, NODE(inode)); @@ -220,9 +230,27 @@ build_polylines(struct sln_tree* tree) inode = ichild0; } } + + /* Handle progression bar */ + if(istack < istack_saved) { + int pcent = 0; + + nnodes_processed += istack_saved - istack; + ASSERT(nnodes_processed <= nnodes_total); + + /* Print progress update */ + pcent = (int)((double)nnodes_processed*100.0/(double)nnodes_total+0.5); + if(pcent/10 > progress/10) { + progress = pcent; + INFO(tree->sln, LOG_MSG, progress); + } + } } + ASSERT(nnodes_processed == nnodes_total); #undef NODE + #undef IS_LEAF + #undef LOG_MSG exit: return res; @@ -235,13 +263,20 @@ partition_lines(struct sln_tree* tree) { size_t stack[STACK_SIZE]; size_t istack = 0; - size_t inode; - size_t nlines; + size_t inode = 0; + size_t nlines = 0; + size_t nlines_total = 0; + size_t nlines_processed = 0; + int progress = 0; res_T res = RES_OK; ASSERT(tree); SHTR(line_list_get_size(tree->args.lines, &nlines)); + nlines_total = nlines; + nlines_processed = 0; + + #define LOG_MSG "Partitioning: %3d%%\n" #define NODE(Id) (darray_node_data_get(&tree->nodes) + (Id)) #define CREATE_NODE { \ res = darray_node_push_back(&tree->nodes, &SLN_NODE_NULL); \ @@ -257,6 +292,10 @@ partition_lines(struct sln_tree* tree) /* Push back SIZE_MAX which, once pop up, will mark the end of recursion */ stack[istack++] = SIZE_MAX; + /* Print that although nothing has been done yet, + * the calculation is nevertheless in progress */ + INFO(tree->sln, LOG_MSG, progress); + inode = 0; /* Root node */ while(inode != SIZE_MAX) { /* #lines into the node */ @@ -264,9 +303,21 @@ partition_lines(struct sln_tree* tree) /* Make a leaf */ if(nlines <= MAX_NLINES_PER_LEAF) { + int pcent = 0; + NODE(inode)->offset = 0; inode = stack[--istack]; /* Pop the next node */ + ASSERT(nlines_processed + nlines <= nlines_total); + nlines_processed += nlines; + + /* Print progress update */ + pcent = (int)((double)nlines_processed*100.0/(double)nlines_total+0.5); + if(pcent/10 > progress/10) { + progress = pcent; + INFO(tree->sln, LOG_MSG, progress); + } + /* Split the node */ } else { /* Median split */ @@ -299,6 +350,8 @@ partition_lines(struct sln_tree* tree) stack[istack++] = ichildren + 1; /* Push the right child */ } } + ASSERT(nlines_processed == nlines_total); + #undef NODE #undef CREATE_NODE