Files
Jungfraujoch/viewer/windows/JFJochCalibrationWindow.cpp
T
leonarski_fandClaude Opus 5 57f9e42382 Viewer: the region of interest belongs to the diffraction view alone
Drawing an ROI only means something where there are detector counts to
accumulate. Gate the gesture on a virtual AllowROI(), true only for
JFJochDiffractionImage: shift-drag, the resize handles, the hover cursor and the
"Clear ROI" context entry now do nothing in the azimuthal, grid-scan and
calibration views, which cannot report anything about a box anyway.

The statistics move out of the base class into the diffraction view and read the
int32 image directly, so no float copy of the detector image is built for them
either. With the labels already converted, image_fp is now untouched by the
diffraction view, and the lazy EnsurePixelValues machinery it needed is gone.
image_fp stays as the base's representation for the views whose data really is
float: the azimuthal profile, the grid-scan 1/sigma^2 map, and the calibration
viewer's eight source types.

Removed with it: the ROI readouts in the calibration and 2D azimuthal windows,
which were the only two consumers of roiCalculated -- the diffraction view
emitted it and nothing listened. Nothing surfaces ROI statistics now; the
pixel-mask case wants rectangles counting excluded pixels and deserves its own
design. JFJochViewerROIResult is still used by the side-panel ROI list, so the
widget stays.

Verified in the GUI: shift-drag in the diffraction view still draws the box,
turns it into a named ROI and runs the statistics; fit-view panel remains
pixel-identical to the pre-series baseline.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 21:32:47 +02:00

113 lines
4.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochCalibrationWindow.h"
#include <QCloseEvent>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
JFJochCalibrationWindow::JFJochCalibrationWindow(QWidget *parent) : JFJochHelperWindow(parent) {
QWidget *centralWidget = new QWidget(this);
setWindowTitle("Calibration image viewer");
setCentralWidget(centralWidget);
auto grid_layout = new QGridLayout();
viewer = new JFJochSimpleImage(this);
calibration_option = new QComboBox(this);
color_map_select = new QComboBox(this);
color_map_select->addItem("Viridis", static_cast<int>(ColorScaleEnum::Viridis));
color_map_select->addItem("Heat", static_cast<int>(ColorScaleEnum::Heat));
color_map_select->addItem("Indigo", static_cast<int>(ColorScaleEnum::Indigo));
color_map_select->addItem("B/W", static_cast<int>(ColorScaleEnum::BW));
color_map_select->setCurrentIndex(static_cast<int>(ColorScaleEnum::Indigo));
background_slider = new SliderPlusBox(1, 32768, 1.0, 0, this, SliderPlusBox::ScaleType::Linear);
foreground_slider = new SliderPlusBox(1, 32768, 1.0, 0, this, SliderPlusBox::ScaleType::Linear);
auto background_row = new QHBoxLayout();
auto foreground_row = new QHBoxLayout();
background_row->addWidget(new QLabel("Background:"));
background_row->addWidget(background_slider);
foreground_row->addWidget(new QLabel("Foreground:"));
foreground_row->addWidget(foreground_slider);
grid_layout->addWidget(calibration_option, 0, 0);
grid_layout->addWidget(color_map_select, 0, 1);
grid_layout->addLayout(background_row, 1, 0, 1, 2);
grid_layout->addLayout(foreground_row, 2, 0, 1, 2);
grid_layout->addWidget(viewer, 3, 0, 1, 2);
connect(viewer, &JFJochSimpleImage::backgroundChanged,
[this] (float val) {
QSignalBlocker blocker(background_slider);
background_slider->setValue(val);
});
connect(viewer, &JFJochSimpleImage::foregroundChanged,
[this] (float val) {
QSignalBlocker blocker(foreground_slider);
foreground_slider->setValue(val);
});
connect(background_slider, &SliderPlusBox::valueChanged, viewer, &JFJochSimpleImage::changeBackground);
connect(foreground_slider, &SliderPlusBox::valueChanged, viewer, &JFJochSimpleImage::changeForeground);
connect(color_map_select, &QComboBox::currentIndexChanged, this, [this](int index) {
viewer->setColorMap(index);
});
connect(calibration_option, &QComboBox::currentIndexChanged, this, &JFJochCalibrationWindow::CalibrationSelected);
centralWidget->setLayout(grid_layout);
statusBar = new QStatusBar(this);
setStatusBar(statusBar);
connect(viewer, &JFJochSimpleImage::writeStatusBar,
statusBar, &QStatusBar::showMessage);
}
void JFJochCalibrationWindow::datasetLoaded(std::shared_ptr<const JFJochReaderDataset> in_dataset) {
dataset = std::move(in_dataset);
QSignalBlocker b(calibration_option);
calibration_option->clear();
if (dataset) {
calibration_option->addItem("Pixel mask");
for (auto &calibration : dataset->calibration_data)
calibration_option->addItem(calibration.c_str());
}
LoadMask();
}
void JFJochCalibrationWindow::calibrationLoaded(std::shared_ptr<const SimpleImage> image) {
viewer->setImage(image);
}
void JFJochCalibrationWindow::LoadMask() {
if (dataset) {
auto mask = std::make_shared<SimpleImage>();
auto tmp = dataset->pixel_mask->GetMask();
mask->buffer.resize(tmp.size() * sizeof(uint32_t));
memcpy(mask->buffer.data(), tmp.data(), tmp.size() * sizeof(uint32_t));
mask->image = CompressedImage(mask->buffer.data(), mask->buffer.size(),
dataset->experiment.GetXPixelsNum(), dataset->experiment.GetYPixelsNum(), CompressedImageMode::Uint32);
viewer->setImage(mask);
}
}
void JFJochCalibrationWindow::CalibrationSelected(int val) {
if (val == 0)
LoadMask();
else
emit loadCalibration(calibration_option->itemText(val));
}
void JFJochCalibrationWindow::setFeatureColor(QColor input) {
viewer->setFeatureColor(input);
}