From e6e506809f77d6bce82b44074d00fc4740a8bda1 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 19 Sep 2026 17:48:45 +0200 Subject: [PATCH] Bragg integration: size each image's reflection list to what is kept Finalize reserved npredicted reflections and kept only the ones whose fit succeeded. On a dense long-axis pattern more than half the predicted reflections lose their background ring, so each retained per-image vector carried more dead capacity than data for the rest of the pass. Count the kept ones first and reserve exactly that. No result changes. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_013nW6FNRP1bBJJ8pfHiByAT --- .../bragg_integration/BraggIntegrationEngine.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/image_analysis/bragg_integration/BraggIntegrationEngine.cpp b/image_analysis/bragg_integration/BraggIntegrationEngine.cpp index f44132c1e..ced5d0caf 100644 --- a/image_analysis/bragg_integration/BraggIntegrationEngine.cpp +++ b/image_analysis/bragg_integration/BraggIntegrationEngine.cpp @@ -215,8 +215,14 @@ std::vector BraggIntegrationEngine::Finalize(const std::vector &results, int64_t image_number) const { + // Sized to what is kept, not to what was predicted: this vector is the one every image holds to the + // end of the pass, and a background ring lost to the neighbours drops a reflection here - on a + // dense pattern more than half of them, which a reserve of npredicted would carry as dead capacity. + size_t n_ok = 0; + for (size_t i = 0; i < npredicted; ++i) + n_ok += results[i].ok ? 1 : 0; std::vector out; - out.reserve(npredicted); + out.reserve(n_ok); for (size_t i = 0; i < npredicted; ++i) { const auto &fr = results[i]; if (!fr.ok)