Some checks failed
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 8m11s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 7m28s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 8m46s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 7m48s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 8m0s
Build Packages / build:rpm (rocky8) (push) Successful in 8m21s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 8m20s
Build Packages / Generate python client (push) Successful in 18s
Build Packages / Create release (push) Has been skipped
Build Packages / Build documentation (push) Successful in 36s
Build Packages / build:rpm (rocky9) (push) Successful in 9m19s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 6m43s
Build Packages / Unit tests (push) Failing after 1h25m28s
This is an UNSTABLE release. * jfjoch_viewer: Fix bug when resolution estimation/B-Factor/Profile radius were not set (NaN) * jfjoch_viewer: Show spots is off by default, resolution ring mode is enabled by default * jfjoch_viewer: Fit to window of image is now default when size of the grid changes Reviewed-on: #13 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch> Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
153 lines
4.3 KiB
C++
153 lines
4.3 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;
|
|
this->settings = std::nullopt;
|
|
if (scene())
|
|
scene()->clear();
|
|
CalcROI();
|
|
}
|
|
|
|
void JFJochGridScanImage::loadData(const std::vector<float> &data, const GridScanSettings &settings) {
|
|
if (data.empty()) {
|
|
clear();
|
|
return;
|
|
}
|
|
this->settings = settings;
|
|
|
|
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);
|
|
|
|
float minv = std::numeric_limits<float>::infinity();
|
|
float maxv = -std::numeric_limits<float>::infinity();
|
|
for (float v : image_fp) {
|
|
if (std::isfinite(v)) {
|
|
if (v < minv) minv = v;
|
|
if (v > maxv) maxv = v;
|
|
}
|
|
}
|
|
if (!std::isfinite(minv) || !std::isfinite(maxv)) {
|
|
minv = 0.0f;
|
|
maxv = 1.0f;
|
|
}
|
|
if (!(maxv > minv)) {
|
|
maxv = minv + 1.0f;
|
|
}
|
|
background = minv;
|
|
foreground = maxv;
|
|
|
|
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);
|
|
}
|
|
|
|
void JFJochGridScanImage::setImage(int64_t val) {
|
|
if (settings) {
|
|
current_image_W = settings->GetElementPosX_step(val);
|
|
current_image_H = settings->GetElementPosY_step(val);
|
|
} else {
|
|
current_image_W = -1;
|
|
current_image_H = -1;
|
|
}
|
|
Redraw();
|
|
}
|
|
|
|
void JFJochGridScanImage::addCustomOverlay() {
|
|
if (current_image_W < 0 || current_image_H < 0 || current_image_W >= W || current_image_H >= H)
|
|
return;
|
|
|
|
QPen pen(feature_color, 3);
|
|
pen.setCosmetic(true);
|
|
|
|
auto rect = scene()->addRect(current_image_W, current_image_H, 1, 1, pen);
|
|
}
|
|
|