jfjoch_viewer: Update status bar from JFJochAzintImageView
This commit is contained in:
@@ -7,26 +7,22 @@
|
||||
#include "../../common/JFJochException.h"
|
||||
|
||||
JFJochAzIntImageView::JFJochAzIntImageView(QWidget *parent)
|
||||
: QWidget(parent), label(new QLabel(this)) {
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(label);
|
||||
setLayout(layout);
|
||||
color_scale.Select(ColorScaleEnum::Viridis);
|
||||
: JFJochImage(parent) {
|
||||
}
|
||||
|
||||
void JFJochAzIntImageView::Clear() {
|
||||
img = QImage();
|
||||
label->clear();
|
||||
W = 0;
|
||||
H = 0;
|
||||
image_fp.clear();
|
||||
if (scene())
|
||||
scene()->clear();
|
||||
}
|
||||
|
||||
// data: size = azimuthal_bins * q_bins
|
||||
// Layout: q varies fastest (i % q_bins == q index)
|
||||
void JFJochAzIntImageView::SetData(const std::vector<float> &data,
|
||||
const std::vector<float> &phi,
|
||||
const std::vector<float> &q,
|
||||
const std::vector<float> &in_phi,
|
||||
const std::vector<float> &in_q,
|
||||
int azimuthal_bins) {
|
||||
if (azimuthal_bins <= 0) {
|
||||
Clear();
|
||||
@@ -35,7 +31,7 @@ void JFJochAzIntImageView::SetData(const std::vector<float> &data,
|
||||
|
||||
int q_bins = data.size() / azimuthal_bins;
|
||||
|
||||
if (q_bins <= 0 || phi.size() != data.size() || q.size() != data.size()) {
|
||||
if (q_bins <= 0 || in_phi.size() != data.size() || in_q.size() != data.size()) {
|
||||
Clear();
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Mismatch in input size");
|
||||
@@ -62,56 +58,38 @@ void JFJochAzIntImageView::SetData(const std::vector<float> &data,
|
||||
}
|
||||
}
|
||||
|
||||
// Build an RGB image (q along X, azimuth along Y) using ColorScale
|
||||
img = QImage(q_bins, azimuthal_bins, QImage::Format_RGB32);
|
||||
for (int az = 0; az < azimuthal_bins; ++az) {
|
||||
QRgb* scan = reinterpret_cast<QRgb*>(img.scanLine(az));
|
||||
for (int q = 0; q < q_bins; ++q) {
|
||||
float v = data[az * q_bins + q];
|
||||
if (!std::isfinite(v)) {
|
||||
auto c = color_scale.Apply(ColorScaleSpecial::BadPixel);
|
||||
scan[q] = qRgb(c.r, c.g, c.b);
|
||||
} else {
|
||||
auto c = color_scale.Apply(v, local_min, local_max);
|
||||
scan[q] = qRgb(c.r, c.g, c.b);
|
||||
}
|
||||
}
|
||||
phi = in_phi;
|
||||
q = in_q;
|
||||
|
||||
// Update base class members
|
||||
W = q_bins;
|
||||
H = azimuthal_bins;
|
||||
image_fp = data;
|
||||
|
||||
// Update foreground/background for color mapping
|
||||
background = local_min;
|
||||
foreground = local_max;
|
||||
|
||||
// Generate pixmap and redraw using base class functionality
|
||||
GeneratePixmap();
|
||||
Redraw();
|
||||
}
|
||||
|
||||
void JFJochAzIntImageView::mouseHover(QMouseEvent* event) {
|
||||
if (!scene() || W == 0 || H == 0) return;
|
||||
|
||||
QPointF scenePos = mapToScene(event->pos());
|
||||
int x = static_cast<int>(scenePos.x());
|
||||
int y = static_cast<int>(scenePos.y());
|
||||
|
||||
if (x >= 0 && x < static_cast<int>(W) && y >= 0 && y < static_cast<int>(H)) {
|
||||
size_t idx = y * W + x;
|
||||
|
||||
QString statusText = QString("Q: %1 Å^-1 phi: %2° value: %3")
|
||||
.arg(QString::number(q[idx], 'f', 3))
|
||||
.arg(QString::number(phi[idx], 'f', 3))
|
||||
.arg(QString::number(image_fp[idx], 'f', 3));
|
||||
|
||||
emit writeStatusBar(statusText, 0);
|
||||
}
|
||||
|
||||
updateLabelPixmap();
|
||||
|
||||
}
|
||||
|
||||
void JFJochAzIntImageView::SetColorScale(ColorScaleEnum map) {
|
||||
color_scale.Select(map);
|
||||
updateLabelPixmap();
|
||||
}
|
||||
|
||||
void JFJochAzIntImageView::SetRangeAuto() {
|
||||
auto_range = true;
|
||||
updateLabelPixmap();
|
||||
}
|
||||
|
||||
void JFJochAzIntImageView::SetRange(float min_val, float max_val) {
|
||||
range_min = min_val;
|
||||
range_max = max_val;
|
||||
auto_range = false;
|
||||
updateLabelPixmap();
|
||||
}
|
||||
|
||||
|
||||
void JFJochAzIntImageView::resizeEvent(QResizeEvent *e) {
|
||||
QWidget::resizeEvent(e);
|
||||
updateLabelPixmap();
|
||||
}
|
||||
|
||||
|
||||
void JFJochAzIntImageView::updateLabelPixmap() {
|
||||
if (img.isNull()) {
|
||||
label->clear();
|
||||
return;
|
||||
}
|
||||
// Keep aspect ratio; smooth transform for readability
|
||||
auto scaled = QPixmap::fromImage(img).scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
label->setPixmap(scaled);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user