From d6b24c50a331a583da063663f4e7decc915c894b Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 25 Sep 2024 13:24:51 -0700 Subject: [PATCH] simplify: Slightly improve tracing for pruning Since we rarely have no-op pruning now, it should be fine to always print pruning stats; this also makes it easier for us to print single line traces for the cleanup passes. --- src/simplifier.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/simplifier.cpp b/src/simplifier.cpp index cf502e6e..e37d674b 100644 --- a/src/simplifier.cpp +++ b/src/simplifier.cpp @@ -1463,16 +1463,20 @@ static size_t pruneComponents(unsigned int* indices, size_t index_count, const u } } +#if TRACE + size_t pruned_components = 0; + for (size_t i = 0; i < component_count; ++i) + pruned_components += (component_errors[i] >= nexterror && component_errors[i] <= error_cutoff); + + printf("pruned %d triangles in %d components (goal %e)\n", int((index_count - write) / 3), int(pruned_components), sqrtf(error_cutoff)); +#endif + + // update next error with the smallest error of the remaining components for future pruning nexterror = FLT_MAX; for (size_t i = 0; i < component_count; ++i) if (component_errors[i] > error_cutoff) nexterror = nexterror > component_errors[i] ? component_errors[i] : nexterror; -#if TRACE - if (write < index_count) - printf("pruned %d / %d triangles (error <= %e)\n", int((index_count - write) / 3), int(index_count / 3), sqrtf(error_cutoff)); -#endif - return write; } @@ -1982,11 +1986,12 @@ size_t meshopt_simplifyEdge(unsigned int* destination, const unsigned int* indic while ((options & meshopt_SimplifyPrune) && result_count > target_index_count && component_nexterror <= error_limit) { #if TRACE - printf("pass %d: pruning remaining components\n", int(pass_count++)); + printf("pass %d: cleanup; ", int(pass_count++)); #endif float component_cutoff = component_nexterror * 1.5f < error_limit ? component_nexterror * 1.5f : error_limit; + // track maximum error in eligible components as we are increasing resulting error float component_maxerror = 0; for (size_t i = 0; i < component_count; ++i) if (component_errors[i] > component_maxerror && component_errors[i] <= component_cutoff)