Files
Jungfraujoch/viewer/image_viewer/JFJochGridScanImage.cpp
Filip Leonarski 95acf3aba3
All checks were successful
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 9m17s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 10m9s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 7m29s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 8m52s
Build Packages / Generate python client (push) Successful in 25s
Build Packages / Build documentation (push) Successful in 49s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 8m47s
Build Packages / build:rpm (rocky8) (push) Successful in 8m49s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 7m4s
Build Packages / build:rpm (rocky9) (push) Successful in 8m52s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 8m11s
Build Packages / Unit tests (push) Successful in 1h14m42s
v1.0.0-rc.104 (#9)
This is an UNSTABLE release.

jfjoch_writer: Fix and improve the way grid scan geometry is saved (non-NXmx extension makes it way easier)
jfjoch_viewer: Display grid scan results in 2D (work in progress)
jfjoch_viewer: Improve auto-scaling on start of images (work in progress)
jfjoch_viewer: Add B-factor and resolution estimate to the dataset info plots

Reviewed-on: #9
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
2025-11-19 17:28:10 +01:00

115 lines
3.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochGridScanImage.h"
JFJochGridScanImage::JFJochGridScanImage(QWidget *parent) : JFJochImage(parent) {}
void JFJochGridScanImage::clear() {
W = 0;
H = 0;
if (scene())
scene()->clear();
CalcROI();
}
void JFJochGridScanImage::loadData(const std::vector<float> &data, const GridScanSettings &settings) {
if (data.empty()) {
clear();
return;
}
W = settings.GetGridSizeX_step();
H = settings.GetGridSizeY_step();
image_fp = settings.Rearrange(data, NAN);
std::vector<int64_t> indices(image_fp.size());
std::iota(indices.begin(), indices.end(), 0);
image_index = settings.Rearrange(indices, -1);
background = *std::ranges::min_element(image_fp);
foreground = *std::ranges::max_element(image_fp);
GeneratePixmap();
Redraw();
CalcROI();
}
void JFJochGridScanImage::mouseHover(QMouseEvent *event) {
// Map mouse position to image pixel if inside bounds
if (W == 0 || H == 0 || image_index.empty())
return;
const QPointF pt = mapToScene(event->pos());
// Convert view coordinates to image pixel by truncation
int x = static_cast<int>(pt.x());
int y = static_cast<int>(pt.y());
if (x < 0 || x >= W || y < 0 || y >= H)
return;
int idx = y * W + x;
if (idx < 0 || idx >= static_cast<int>(image_index.size()))
return;
int64_t image_id = image_index[idx];
if (image_id >= 0) {
if (event->modifiers() & Qt::ShiftModifier)
emit imageSelected(image_id);
emit writeStatusBar(QString("Image %1 y %2 y %3 value %4")
.arg(image_id)
.arg(x)
.arg(y)
.arg(QString::number(image_fp[idx], 'f', 3)),
6000);
}
}
void JFJochGridScanImage::loadImage(QMouseEvent *event) {
// Map mouse position to image pixel if inside bounds
if (W == 0 || H == 0 || image_index.empty())
return;
const QPointF pt = mapToScene(event->pos());
// Convert view coordinates to image pixel by truncation
int x = static_cast<int>(pt.x());
int y = static_cast<int>(pt.y());
if (x < 0 || x >= W || y < 0 || y >= H)
return;
int idx = y * W + x;
if (idx < 0 || idx >= static_cast<int>(image_index.size()))
return;
int64_t image_id = image_index[idx];
if (image_id >= 0)
emit imageSelected(image_id);
}
void JFJochGridScanImage::mouseDoubleClickEvent(QMouseEvent *event) {
// Map mouse position to image pixel if inside bounds
if (W == 0 || H == 0 || image_index.empty())
return;
const QPointF pt = mapToScene(event->pos());
// Convert view coordinates to image pixel by truncation
int x = static_cast<int>(pt.x());
int y = static_cast<int>(pt.y());
if (x < 0 || x >= W || y < 0 || y >= H)
return;
int idx = y * W + x;
if (idx < 0 || idx >= static_cast<int>(image_index.size()))
return;
int64_t image_id = image_index[idx];
if (image_id >= 0)
emit imageSelected(image_id);
JFJochImage::mouseDoubleClickEvent(event);
}