jfjoch_viewer: navigation keys, one-shot auto-contrast, file manager panel, cleanup
* Dataset-info plot hover shows a horizontal crosshair alongside the existing vertical one, so a run of hovers reads as a level or a drift at a glance. * `A` applies auto-contrast once instead of switching on persistent Auto mode (a new `oneShotAutoForeground()`, distinct from the toolbar's Auto toggle); pressing it a second time on the same image switches Auto on for good, and pressing it while Auto is already on leaves it on. The value itself comes from one `AutoForegroundValue()` shared with the continuous Auto path. * `Home`/`End`/`Page Up`/`Page Down` navigate the dataset (first/last image, one image forward/back); claimed in the diffraction view's keyPressEvent before QGraphicsView's default handling, which otherwise eats them to scroll the viewport. * Alt+wheel dataset navigation is removed - some window managers already took it before the app ever saw it, per the caveat that used to sit next to its entry in the shortcuts list. * The image strip dock and its dedicated thumbnail-rendering machinery in the reading worker (SetThumbnail*, RenderThumbnail_i) are removed; it cost a lot and nothing else used any of it. * Toolbar text: "Colour" -> "Color". * Color map, Auto and HDR mode now persist across sessions, the same way the window layout already does. * The Inspector's "Dataset:" path wraps at '/' (a zero-width space after each one) instead of being cut off when it doesn't fit one line. * LoadFile no longer reopens an already-open file - it forwards straight to LoadImage instead - which was the likely cause of a D-Bus client's per-image navigation lagging behind the same navigation done via the grid-scan hover. * New file-manager dock (left, tabbed with Settings via tabifyDockWidget): a directory tree filtered to *_master.h5/*_process.h5, rooted at JUNGFRAUJOCH_DATA_ROOT if set, else the last-browsed root, else the home directory. Most beamline users care about opening images, not reprocessing settings, so it's the tab raised by default. Its filter box narrows files only - a directory always passes - because filtering the directories too hid the matching files under any directory whose own name did not match, and hid the root's ancestors, which left the tree with no valid root index until the root was set again by hand. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PogHY7bWXV4bpctDPdyuDN Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
40dd6f25fd
commit
d24cdfcff4
20 files changed
+375
-462
No files matched your search
@@ -21,8 +21,6 @@
|
||||
#include <QVector>
|
||||
#include <QMutexLocker>
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QFontMetrics>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../preview/JFJochTIFF.h"
|
||||
@@ -110,7 +108,6 @@ JFJochImageReadingWorker::JFJochImageReadingWorker(const SpotFindingSettings &se
|
||||
http_reader.Experiment(experiment);
|
||||
hdf5_reader.Experiment(experiment);
|
||||
cbf_reader.Experiment(experiment);
|
||||
thumb_color_scale_.Select(ColorScaleEnum::Indigo);
|
||||
|
||||
autoload_timer = new QTimer(this);
|
||||
autoload_timer->setInterval(autoload_interval);
|
||||
@@ -205,6 +202,15 @@ void JFJochImageReadingWorker::FileOpenRetryTimerExpired() {
|
||||
|
||||
void JFJochImageReadingWorker::LoadFile_i(const QString &filename, qint64 image_number, qint64 summation, bool retry) {
|
||||
try {
|
||||
// The file (in file mode) is already open: nothing to (re)read, just move to the requested
|
||||
// image. Without this, a caller that re-issues LoadFile per image instead of LoadImage (e.g.
|
||||
// a D-Bus client stepping through a dataset) pays a full close+reopen+reparse of the HDF5
|
||||
// dataset for every single image, instead of the cheap single-image read LoadImage does.
|
||||
if (!http_mode && !filename.isEmpty() && filename == current_file) {
|
||||
LoadImage_i(image_number, summation);
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<const JFJochReaderDataset> dataset;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
@@ -1162,128 +1168,3 @@ void JFJochImageReadingWorker::SetActiveSnapshot(QString name) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JFJochImageReadingWorker::SetThumbnailColorMap(int color_map) {
|
||||
QMutexLocker locker(&m);
|
||||
thumb_color_scale_.Select(static_cast<ColorScaleEnum>(color_map));
|
||||
}
|
||||
|
||||
void JFJochImageReadingWorker::SetThumbnailFeatureColor(QColor c) {
|
||||
QMutexLocker locker(&m);
|
||||
thumb_feature_color_ = c;
|
||||
}
|
||||
|
||||
void JFJochImageReadingWorker::SetThumbnailSpotColor(QColor c) {
|
||||
QMutexLocker locker(&m);
|
||||
thumb_spot_color_ = c;
|
||||
}
|
||||
|
||||
void JFJochImageReadingWorker::RenderThumbnails(QVector<qint64> image_numbers, bool show_spots) {
|
||||
// File mode only; live HTTP cannot address arbitrary images cheaply.
|
||||
if (http_mode)
|
||||
return;
|
||||
for (qint64 n : image_numbers) {
|
||||
QImage thumb = RenderThumbnail_i(n, show_spots);
|
||||
if (!thumb.isNull())
|
||||
emit thumbnailReady(n, thumb);
|
||||
}
|
||||
}
|
||||
|
||||
QImage JFJochImageReadingWorker::RenderThumbnail_i(int64_t image_number, bool show_spots) {
|
||||
// Everything runs inside one try: an uncaught exception here would be on the worker thread and
|
||||
// would std::terminate the whole app. On any failure we just skip this thumbnail.
|
||||
try {
|
||||
std::shared_ptr<JFJochReaderImage> img;
|
||||
{
|
||||
QMutexLocker locker(&m);
|
||||
if (http_mode || image_number < 0 || image_number >= total_images)
|
||||
return {};
|
||||
img = file_reader->LoadImage(image_number, 1);
|
||||
}
|
||||
if (!img)
|
||||
return {};
|
||||
|
||||
const int W = static_cast<int>(img->Dataset().experiment.GetXPixelsNum());
|
||||
const int H = static_cast<int>(img->Dataset().experiment.GetYPixelsNum());
|
||||
const auto &px = img->Image();
|
||||
if (W <= 0 || H <= 0 || static_cast<int64_t>(px.size()) < static_cast<int64_t>(W) * H)
|
||||
return {};
|
||||
|
||||
const auto &lut = thumb_color_scale_.LUTData();
|
||||
const int lutSize = static_cast<int>(lut.size());
|
||||
if (lutSize <= 0)
|
||||
return {};
|
||||
|
||||
// Downsample by block-maximum (keeps sharp Bragg spots), then map through the LUT.
|
||||
constexpr int maxDim = 120;
|
||||
const double s = static_cast<double>(maxDim) / std::max(W, H);
|
||||
const int tw = std::max(1, static_cast<int>(W * s));
|
||||
const int th = std::max(1, static_cast<int>(H * s));
|
||||
const int bx = std::max(1, W / tw);
|
||||
const int by = std::max(1, H / th);
|
||||
|
||||
const float fg = std::max(1.0f, static_cast<float>(img->GetAutoContrastValue()));
|
||||
const float invRange = (lutSize - 1) / fg;
|
||||
const rgb gap = thumb_color_scale_.Apply(ColorScaleSpecial::Gap);
|
||||
|
||||
QImage out(tw, th, QImage::Format_RGB32);
|
||||
for (int ty = 0; ty < th; ++ty) {
|
||||
QRgb *line = reinterpret_cast<QRgb *>(out.scanLine(ty));
|
||||
const int y1 = std::min(H, ty * by + by);
|
||||
for (int tx = 0; tx < tw; ++tx) {
|
||||
const int x1 = std::min(W, tx * bx + bx);
|
||||
int32_t best = 0;
|
||||
bool any = false;
|
||||
for (int yy = ty * by; yy < y1; ++yy)
|
||||
for (int xx = tx * bx; xx < x1; ++xx) {
|
||||
const int32_t v = px[yy * W + xx];
|
||||
if (v == GAP_PXL_VALUE || v == ERROR_PXL_VALUE || v == BEAM_STOP_PXL_VALUE) continue;
|
||||
if (v == SATURATED_PXL_VALUE) { best = static_cast<int32_t>(fg); any = true; continue; }
|
||||
if (!any || v > best) { best = v; any = true; }
|
||||
}
|
||||
rgb c;
|
||||
if (!any) {
|
||||
c = gap;
|
||||
} else {
|
||||
int idx = static_cast<int>(std::max(0, best) * invRange + 0.5f);
|
||||
idx = std::clamp(idx, 0, lutSize - 1);
|
||||
c = lut[idx];
|
||||
}
|
||||
line[tx] = qRgb(c.r, c.g, c.b);
|
||||
}
|
||||
}
|
||||
|
||||
if (show_spots) {
|
||||
QPainter p(&out);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
for (const auto &sp : img->ImageData().spots) {
|
||||
p.setPen(QPen(sp.indexed ? thumb_feature_color_ : thumb_spot_color_, 1.0));
|
||||
p.drawEllipse(QPointF(sp.x * s, sp.y * s), 1.6, 1.6);
|
||||
}
|
||||
}
|
||||
|
||||
// Image-number badge in the top-left, so the strip needs no text label (and loses no height).
|
||||
{
|
||||
QPainter p(&out);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
QFont f = p.font();
|
||||
f.setBold(true);
|
||||
f.setPixelSize(11);
|
||||
p.setFont(f);
|
||||
const QString label = QString::number(image_number + 1);
|
||||
const QRect tb = QFontMetrics(f).boundingRect(label);
|
||||
const QRect badge(2, 2, tb.width() + 8, tb.height() + 2);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(QColor(0xFA, 0x72, 0x68)); // coral
|
||||
p.drawRoundedRect(badge, 3, 3);
|
||||
p.setPen(Qt::white);
|
||||
p.drawText(badge, Qt::AlignCenter, label);
|
||||
}
|
||||
return out;
|
||||
} catch (const std::exception &e) {
|
||||
logger.Debug("Thumbnail render failed for image {}: {}", image_number, e.what());
|
||||
return {};
|
||||
} catch (...) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user