Files
Jungfraujoch/viewer/image_viewer/JFJochSimpleImage.cpp
T
leonarski_f efe882f4b6
Build Packages / Unit tests (push) Failing after 1s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 25m52s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 29m5s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 29m54s
Build Packages / build:rpm (rocky8) (push) Successful in 31m55s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 32m12s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 32m48s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 35m27s
Build Packages / Generate python client (push) Successful in 25s
Build Packages / build:rpm (rocky9) (push) Successful in 31m59s
Build Packages / Create release (push) Skipped
Build Packages / Build documentation (push) Successful in 1m36s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 24m8s
Build Packages / XDS test (neggia plugin) (push) Successful in 17m46s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 21m36s
Build Packages / XDS test (durin plugin) (push) Successful in 19m40s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 19m38s
Build Packages / DIALS test (push) Successful in 26m30s
jfjoch_viewer: Better display (to be tested) of pixel refine
2026-06-09 16:28:17 +02:00

142 lines
4.5 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochSimpleImage.h"
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QMouseEvent>
#include <QtMath>
#include <cstring>
#include <algorithm>
#include "../../common/JFJochException.h"
JFJochSimpleImage::JFJochSimpleImage(QWidget *parent)
: JFJochImage(parent) {
auto *scn = new QGraphicsScene(this);
setScene(scn);
// Keep overlays in pixel units independent of zoom (for labels font sizing)
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
// The predicted/float image is unreadable with 3-decimal per-pixel labels.
label_decimals_ = 1;
}
void JFJochSimpleImage::setImage(std::shared_ptr<const SimpleImage> img) {
if (img) {
image_ = std::move(img);
loadImageInternal();
GeneratePixmap();
Redraw();
CalcROI();
} else {
image_.reset();
W = 0; H = 0;
if (scene())
scene()->clear();
resetScenePointers();
CalcROI();
}
}
void JFJochSimpleImage::setShoeboxes(QVector<QRect> boxes) {
shoeboxes_ = std::move(boxes);
// Redraw overlays on the current image (no-op if no image yet).
updateOverlay();
}
void JFJochSimpleImage::addCustomOverlay() {
if (shoeboxes_.isEmpty() || !scene())
return;
// Cosmetic 1-px outline so the box edges stay thin at any zoom; only draw the
// ones currently in view (there can be hundreds of reflections).
const QRectF visibleRect = mapToScene(viewport()->geometry()).boundingRect();
QPen pen(QColor(0, 220, 255), 0); // cyan, distinct from the prediction colours
pen.setCosmetic(true);
for (const QRect &b : shoeboxes_) {
const QRectF r(b.x(), b.y(), b.width(), b.height());
if (!visibleRect.intersects(r))
continue;
auto *item = scene()->addRect(r, pen);
addOverlayItem(item);
}
}
void JFJochSimpleImage::mouseHover(QMouseEvent *event) {
if (image_) {
const QPointF scenePos = mapToScene(event->pos());
// Hover feedback / status bar display
if ((scenePos.x() >= 0)
&& (scenePos.x() < image_->image.GetWidth())
&& (scenePos.y() >= 0)
&& (scenePos.y() < image_->image.GetHeight())) {
const auto ix = int(scenePos.x());
const auto iy = int(scenePos.y());
const auto idx = iy * int(image_->image.GetWidth()) + ix;
if (idx >= 0 && idx < int(image_fp.size()))
emit writeStatusBar(QString("x=%1 y=%2 I=%3")
.arg(scenePos.x(), 0, 'f', 1)
.arg(scenePos.y(), 0, 'f', 1)
.arg(image_fp[size_t(idx)]), 3000);
} else {
emit writeStatusBar("", 1000);
}
}
}
template<class T>
void JFJochSimpleImage::loadImageInternal(const uint8_t *input) {
const size_t W = image_->image.GetWidth();
const size_t H = image_->image.GetHeight();
auto ptr = reinterpret_cast<const T *>(input);
for (int i = 0; i < W * H; i++)
image_fp[i] = static_cast<float>(ptr[i]);
}
void JFJochSimpleImage::loadImageInternal() {
W = image_->image.GetWidth();
H = image_->image.GetHeight();
if (W == 0 || H == 0) return;
image_fp.resize(W * H);
std::vector<uint8_t> image_buffer;
// Access uncompressed data
const uint8_t *src = image_->image.GetUncompressedPtr(image_buffer);
const auto mode = image_->image.GetMode();
switch (mode) {
case CompressedImageMode::Uint8:
loadImageInternal<uint8_t>(src);
break;
case CompressedImageMode::Int8:
loadImageInternal<int8_t>(src);
break;
case CompressedImageMode::Uint16:
loadImageInternal<uint16_t>(src);
break;
case CompressedImageMode::Int16:
loadImageInternal<int16_t>(src);
break;
case CompressedImageMode::Uint32:
loadImageInternal<uint32_t>(src);
break;
case CompressedImageMode::Int32:
loadImageInternal<int32_t>(src);
break;
case CompressedImageMode::Float32:
loadImageInternal<float>(src);
break;
case CompressedImageMode::Float64:
loadImageInternal<double>(src);
break;
default:
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Image format not supported");
}
}