From 4a8d036cafaf729f00bf11d2a517be37ce51075a Mon Sep 17 00:00:00 2001 From: Julien Staub Date: Thu, 27 Nov 2025 19:08:08 +0100 Subject: [PATCH 1/2] fix cras in View/Show statistics --- wftstats.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wftstats.cpp b/wftstats.cpp index c09305be..8a46b9cc 100644 --- a/wftstats.cpp +++ b/wftstats.cpp @@ -261,12 +261,12 @@ void wftStats::computeWftRunningAvg( QVector wavefronts, int ndx){ QHash sizes; for (int i = 0; i < last; ++i){ QString size = QString("%1 %2").arg(wavefronts[i]->workData.rows).arg(wavefronts[i]->workData.cols); - if (*sizes.find(size)) - { + if (sizes.contains(size)) { ++sizes[size]; } - else + else { sizes[size] = 1; + } } int max = 0; QString maxkey; From 098dd331550ceba7ad4ac721c0e4db651f0188a9 Mon Sep 17 00:00:00 2001 From: Julien Staub Date: Thu, 27 Nov 2025 19:36:05 +0100 Subject: [PATCH 2/2] use range for loor and avoid int/string/int back and forth --- wftstats.cpp | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/wftstats.cpp b/wftstats.cpp index 8a46b9cc..3b4c876e 100644 --- a/wftstats.cpp +++ b/wftstats.cpp @@ -257,31 +257,22 @@ void wftStats::computeWftRunningAvg( QVector wavefronts, int ndx){ outliersInner.clear(); outliersOuter.clear(); // normalize the size to the most common size - int last = wavefronts.length(); - QHash sizes; - for (int i = 0; i < last; ++i){ - QString size = QString("%1 %2").arg(wavefronts[i]->workData.rows).arg(wavefronts[i]->workData.cols); - if (sizes.contains(size)) { - ++sizes[size]; - } - else { - sizes[size] = 1; + std::map, int> sizes; + int maxCount = 0; + int rrows = 0; + int rcols = 0; + + for (wavefront* wf : wavefronts) { + auto key = std::make_pair(wf->workData.rows, wf->workData.cols); + int newCount = ++sizes[key]; // operator[] inserts default 0 then increments + // keep track of the size that occurs most often + if (newCount > maxCount) { + maxCount = newCount; + rrows = wf->workData.rows; + rcols = wf->workData.cols; } } - int max = 0; - QString maxkey; - foreach(QString v, sizes.keys()){ - int a = sizes[v]; - if (a > max) { - max = a; - maxkey = v; - } - } - int rrows, rcols; - - QTextStream s(&maxkey); - s >> rrows >> rcols; cv::Mat mask = wavefronts[0]->workMask.clone(); cv::resize(mask,mask,cv::Size(rcols,rrows)); QVector twaves = wavefronts; @@ -291,6 +282,7 @@ void wftStats::computeWftRunningAvg( QVector wavefronts, int ndx){ wftPoints.clear(); trueNdx.clear(); inrange.clear(); + int last = wavefronts.length(); for (int j = 0; j < last; ++j){ int i = (ndx + j) % wavefronts.size(); //i = samndx[j];