2f8d486b51
Add JFJochViewerROIList to the side panel: a list of the dataset's ROIs with selection, add (box/circle/azimuthal), rename and delete, plus a statistics readout (sum/mean/std/max/valid/masked/centre-of-mass) for the selected ROI, taken from the analysis output for the current image. Edits emit a full ROIDefinition, routed to the worker's SetROIDefinition. Per-ROI statistics now live in this panel rather than the canvas labels; the diffraction image's labels show only the ROI name, and the ad-hoc ROIIntegrationCPU computation there is removed in favour of the analysis pipeline. The result widget now reports std dev instead of variance. The single-ROI scratch panel remains for now and will be retired once the interactive canvas editing replaces it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
74 lines
2.8 KiB
C++
74 lines
2.8 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochViewerROIResult.h"
|
|
#include <cmath>
|
|
#include <QGridLayout>
|
|
|
|
JFJochViewerROIResult::JFJochViewerROIResult(QWidget *parent) : QWidget(parent) {
|
|
QGridLayout *layout = new QGridLayout;
|
|
|
|
roi_sum = new QLabel("", this);
|
|
roi_mean = new QLabel("", this);
|
|
roi_var = new QLabel("", this);
|
|
roi_max = new QLabel("", this);
|
|
roi_npixel = new QLabel("", this);
|
|
roi_masked = new QLabel("", this);
|
|
roi_x = new QLabel("", this);
|
|
roi_y = new QLabel("", this);
|
|
|
|
label_1 = new QLabel("", this);
|
|
label_2 = new QLabel("", this);
|
|
|
|
label_1->setAlignment(Qt::AlignCenter);
|
|
label_2->setAlignment(Qt::AlignCenter);
|
|
|
|
layout->addWidget(roi_mean, 0, 0);
|
|
layout->addWidget(roi_var, 0, 1);
|
|
layout->addWidget(roi_sum, 0, 2);
|
|
layout->addWidget(roi_max, 0, 3);
|
|
layout->addWidget(label_1, 1,0,1,2);
|
|
layout->addWidget(roi_npixel, 1, 2);
|
|
layout->addWidget(roi_masked, 1, 3);
|
|
layout->addWidget(label_2, 2,0,1,2);
|
|
layout->addWidget(roi_x, 2, 2);
|
|
layout->addWidget(roi_y, 2, 3);
|
|
setLayout(layout);
|
|
}
|
|
|
|
void JFJochViewerROIResult::SetROIResult(ROIMessage roi) {
|
|
if ( roi.pixels > 0) {
|
|
auto roi_npixel_val = static_cast<double>(roi.pixels);
|
|
double roi_mean_val = static_cast<double>(roi.sum) / roi_npixel_val;
|
|
double variance = static_cast<double>(roi.sum_square) / roi_npixel_val - roi_mean_val * roi_mean_val;
|
|
double std_dev = std::sqrt(std::max(0.0, variance));
|
|
|
|
roi_sum->setText(QString("Sum <b>%1</b>").arg(roi.sum));
|
|
roi_mean->setText(QString("Mean <b>%1</b>").arg(QString::number(roi_mean_val, 'f', 3)));
|
|
roi_var->setText(QString("Std <b>%1</b>").arg(QString::number(std_dev, 'f', 3)));
|
|
roi_max->setText(QString("Max <b>%1</b>").arg(roi.max_count));
|
|
roi_npixel->setText(QString("Valid <b>%1</b>").arg(roi.pixels));
|
|
roi_masked->setText(QString("Masked <b>%1</b>").arg(roi.pixels_masked));
|
|
if (roi.sum == 0) {
|
|
roi_x->setText(QString("x: <b>N/A</b>"));
|
|
roi_y->setText(QString("y: <b>N/A</b>"));
|
|
} else {
|
|
roi_x->setText(QString("x: <b>%1</b>").arg(static_cast<float>(roi.x_weighted) / roi.sum));
|
|
roi_y->setText(QString("y: <b>%1</b>").arg(static_cast<float>(roi.y_weighted) / roi.sum));
|
|
}
|
|
label_1->setText(QString("Pixel count"));
|
|
label_2->setText(QString("Center of mass"));
|
|
} else {
|
|
roi_sum->setText("");
|
|
roi_mean->setText("");
|
|
roi_var->setText("");
|
|
roi_max->setText("");
|
|
roi_npixel->setText("");
|
|
roi_masked->setText("");
|
|
roi_x->setText("");
|
|
roi_y->setText("");
|
|
label_1->setText("");
|
|
label_2->setText("");
|
|
}
|
|
}
|