Build Packages / build:viewer-tgz:cpu (push) Successful in 12m14s
Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 8m24s
Build Packages / build:rpm (rocky8_nocuda) (push) Failing after 5m36s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 12m55s
Build Packages / build:viewer-tgz:cuda (push) Successful in 14m11s
Build Packages / build:rpm (rocky9_nocuda) (push) Failing after 5m6s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Failing after 4m11s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Failing after 3m58s
Build Packages / build:rpm (rocky8) (push) Failing after 3m22s
Build Packages / build:rpm (rocky9_sls9) (push) Failing after 4m12s
Build Packages / build:rpm (rocky9) (push) Failing after 3m20s
Build Packages / build:rpm (rocky8_sls9) (push) Failing after 4m23s
Build Packages / build:rpm (ubuntu2204) (push) Failing after 3m36s
Build Packages / build:windows:nocuda (push) Successful in 17m9s
Build Packages / build:rpm (ubuntu2404) (push) Failing after 4m8s
Build Packages / Generate python client (push) Successful in 35s
Build Packages / Build documentation (push) Successful in 52s
Build Packages / Create release (push) Skipped
Build Packages / build:windows:cuda (push) Successful in 19m32s
Build Packages / XDS test (durin plugin) (push) Successful in 7m22s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 7m28s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m15s
Build Packages / build:rugnux:windows (push) Successful in 12m10s
Build Packages / DIALS test (push) Successful in 17m32s
Build Packages / Unit tests (push) Successful in 1h16m29s
Two independent reviews of the merged grid-scan work. The findings that changed behaviour: The ice score's spot channel was fed a list the spot budget had already stripped. FilterSpotsByCount orders ice-band spots LAST when indexing is not to use them, so on a frame with more spots than the budget the ice spots are the first discarded - and the channel that exists for "ice arrives as discrete spots and leaves the radial profile flat" then read zero on exactly the frames it was written for. Probed at 3000 spots with 1200 on the hexagonal radii and a budget of 1000: 1.000 before the cap, 0.000 after. IceScore now takes d-spacings and is handed the list from before the cap. The viewer scaled the crystal box by the SIGNED grid step, where every other consumer takes the magnitude. On a negative step that mirrors the box - +30 deg drawn as -30 - and hands QRectF a negative width. rugnux --mode raster never put its settings on the experiment, so the indexing switch was read at its default while a deprecated per-run flag did the actual work; and RugnuxCommandLine emitted no --mode for Grid, so a raster job copied to a cluster ran the default mx - indexing, integrating and merging every cell of the raster. res_A is NaN where nothing in a blob measured a resolution, and nlohmann writes NaN as null, which the schema and the generated clients both reject. It is now left unset. The broker's configuration example named a key that does not exist (calibration, not calibration_settings); nlohmann ignores unknown keys, so a user copying it got a silently ignored block. The changelog had lost the rc.166 heading and 21 rc.167 entries to a bad edit of mine, and three entries had been filed under rc.166. Also: a warning where mode Grid meets a dataset with no grid scan, which was silent and indistinguishable from finding nothing; the viewer combo still named the retired ice_ring_score; and the claim that growth "cannot invent a crystal" was too strong - it cannot start a patch, but the cell count is read over the grown patch, so it does decide which patches pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFEJG6WBQv8th4UJFNe53N
287 lines
9.8 KiB
C++
287 lines
9.8 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochGridScanImage.h"
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
JFJochGridScanImage::JFJochGridScanImage(QWidget *parent) : JFJochImage(parent) {}
|
|
|
|
void JFJochGridScanImage::clear() {
|
|
W = 0;
|
|
H = 0;
|
|
this->settings = std::nullopt;
|
|
composite = false;
|
|
obj_map.clear();
|
|
protein_map.clear();
|
|
ice_map.clear();
|
|
crystals.clear();
|
|
if (scene())
|
|
scene()->clear();
|
|
resetScenePointers();
|
|
}
|
|
|
|
void JFJochGridScanImage::SetupGrid(const GridScanSettings &in_settings) {
|
|
this->settings = in_settings;
|
|
|
|
W = in_settings.GetGridSizeX_step();
|
|
H = in_settings.GetGridSizeY_step();
|
|
// Draw a cell in the proportion of the area it covers, so a scan with a coarse x step and a
|
|
// fine y step looks like the sample region it was taken over, not like a square grid.
|
|
pixel_aspect_ = std::fabs(in_settings.GetGridStepY_um() / in_settings.GetGridStepX_um());
|
|
|
|
std::vector<int64_t> indices(static_cast<size_t>(W) * H);
|
|
std::iota(indices.begin(), indices.end(), 0);
|
|
image_index = in_settings.Rearrange(indices, -1);
|
|
}
|
|
|
|
void JFJochGridScanImage::loadData(const std::vector<float> &data, const GridScanSettings &settings, bool in_one_over_d2) {
|
|
if (data.empty()) {
|
|
clear();
|
|
return;
|
|
}
|
|
composite = false;
|
|
SetupGrid(settings);
|
|
image_fp = settings.Rearrange(data, NAN);
|
|
|
|
one_over_d2 = in_one_over_d2;
|
|
if (one_over_d2) {
|
|
for (int i = 0; i < image_fp.size(); i++)
|
|
if (!std::isnan(image_fp[i]))
|
|
image_fp[i] = 1.0f / (image_fp[i] * image_fp[i]);
|
|
}
|
|
|
|
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;
|
|
|
|
RenderImage();
|
|
Redraw();
|
|
}
|
|
|
|
void JFJochGridScanImage::loadComposite(const std::vector<float> &bkg, const std::vector<float> &protein,
|
|
const std::vector<float> &ice,
|
|
const std::vector<GridScanCrystal> &in_crystals,
|
|
const GridScanSettings &settings) {
|
|
if (bkg.empty() && protein.empty() && ice.empty()) {
|
|
clear();
|
|
return;
|
|
}
|
|
composite = true;
|
|
one_over_d2 = false;
|
|
SetupGrid(settings);
|
|
|
|
obj_map = settings.Rearrange(grid_scan::NormaliseBackground(bkg), NAN);
|
|
// A score that has not been measured is not a score of zero, but for the colouring the two are
|
|
// the same thing: nothing painted over the grey.
|
|
protein_map = settings.Rearrange(protein, 0.0f);
|
|
ice_map = settings.Rearrange(ice, 0.0f);
|
|
crystals = in_crystals;
|
|
|
|
image_fp = obj_map;
|
|
background = 0.0f;
|
|
foreground = 1.0f;
|
|
|
|
RenderImage();
|
|
Redraw();
|
|
}
|
|
|
|
void JFJochGridScanImage::ColorRow(size_t y, const PixelColorMap &map, QRgb *out) const {
|
|
if (!composite) {
|
|
JFJochImage::ColorRow(y, map, out);
|
|
return;
|
|
}
|
|
|
|
for (size_t x = 0; x < W; ++x) {
|
|
const size_t idx = y * W + x;
|
|
if (std::isnan(obj_map[idx])) {
|
|
out[x] = qRgb(map.gap.r, map.gap.g, map.gap.b);
|
|
continue;
|
|
}
|
|
const rgb c = grid_scan::CompositeColor(obj_map[idx], protein_map[idx], ice_map[idx]);
|
|
out[x] = qRgb(c.r, c.g, c.b);
|
|
}
|
|
}
|
|
|
|
QString JFJochGridScanImage::PixelLabel(int x, int y) const {
|
|
if (!composite)
|
|
return JFJochImage::PixelLabel(x, y);
|
|
|
|
const size_t idx = static_cast<size_t>(y) * W + x;
|
|
if (std::isnan(obj_map[idx]))
|
|
return QStringLiteral("-");
|
|
return QString("%1/%2").arg(QString::number(protein_map[idx], 'f', 2),
|
|
QString::number(ice_map[idx], 'f', 2));
|
|
}
|
|
|
|
void JFJochGridScanImage::mouseHover(const QPointF &pt, Qt::KeyboardModifiers modifiers) {
|
|
// Map mouse position to image pixel if inside bounds
|
|
if (W == 0 || H == 0 || image_index.empty())
|
|
return;
|
|
|
|
// 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 (modifiers & Qt::ShiftModifier)
|
|
emit imageSelected(image_id);
|
|
|
|
if (composite) {
|
|
emit writeStatusBar(QString("Image %1 x %2 y %3 protein %4 ice %5")
|
|
.arg(image_id)
|
|
.arg(x)
|
|
.arg(y)
|
|
.arg(QString::number(protein_map[idx], 'f', 2))
|
|
.arg(QString::number(ice_map[idx], 'f', 2)),
|
|
6000);
|
|
} else if (one_over_d2) {
|
|
if (std::isnan(image_fp[idx]))
|
|
emit writeStatusBar(QString("Image %1 x %2 y %3 no resolution estimation")
|
|
.arg(image_id)
|
|
.arg(x)
|
|
.arg(y),
|
|
6000);
|
|
else
|
|
emit writeStatusBar(QString("Image %1 x %2 y %3 d = %4 Å")
|
|
.arg(image_id)
|
|
.arg(x)
|
|
.arg(y)
|
|
.arg(QString::number(1 / std::sqrt(image_fp[idx]), 'f', 2)),
|
|
6000);
|
|
} else {
|
|
emit writeStatusBar(QString("Image %1 x %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::drawCrystalFrames() {
|
|
// White over black rather than a colour from the palette: the frame has to stay legible over
|
|
// the pale plate, the grey loop, cyan, orange and everything in between, and no single hue
|
|
// does that.
|
|
QPen halo(Qt::black, 5);
|
|
halo.setCosmetic(true);
|
|
QPen line(Qt::white, 2);
|
|
line.setCosmetic(true);
|
|
|
|
// Magnitudes: the step sign says which way the stage moved, and the display grid has already
|
|
// applied it. Using the signed value here mirrors the box on a negative step, drawing +30 deg
|
|
// as -30 and handing QRectF a negative width.
|
|
const float step_x = std::fabs(settings->GetGridStepX_um());
|
|
const float step_y = std::fabs(settings->GetGridStepY_um());
|
|
|
|
for (const auto &c : crystals) {
|
|
if (grid_scan::IsRoundBlob(c.major_um, c.minor_um)) {
|
|
// No orientation to show, so no oriented box - a circle of the mean extent.
|
|
const float r_um = 0.25f * (c.major_um + c.minor_um);
|
|
const QRectF box(c.nx + 0.5 - r_um / step_x, c.ny + 0.5 - r_um / step_y,
|
|
2 * r_um / step_x, 2 * r_um / step_y);
|
|
addOverlayItem(scene()->addEllipse(box, halo));
|
|
addOverlayItem(scene()->addEllipse(box, line));
|
|
} else {
|
|
QPolygonF poly;
|
|
for (const auto &corner : grid_scan::CrystalFrameCorners(c.nx, c.ny, c.major_um, c.minor_um,
|
|
c.angle_deg, step_x, step_y))
|
|
poly << QPointF(corner.x, corner.y);
|
|
addOverlayItem(scene()->addPolygon(poly, halo));
|
|
addOverlayItem(scene()->addPolygon(poly, line));
|
|
}
|
|
}
|
|
}
|
|
|
|
void JFJochGridScanImage::addCustomOverlay() {
|
|
if (composite && settings)
|
|
drawCrystalFrames();
|
|
|
|
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);
|
|
addOverlayItem(rect);
|
|
}
|