jfjoch_viewer: Update status bar from JFJochAzintImageView
This commit is contained in:
@@ -116,6 +116,10 @@ JFJochViewerSidePanel::JFJochViewerSidePanel(QWidget *parent) : QWidget(parent)
|
||||
|
||||
connect(this, &JFJochViewerSidePanel::imageLoaded,
|
||||
chart, &JFJochViewerSidePanelChart::loadImage);
|
||||
connect(chart, &JFJochViewerSidePanelChart::writeStatusBar,
|
||||
[&] (QString string, int timeout_ms) {
|
||||
emit writeStatusBar(string, timeout_ms);
|
||||
});
|
||||
|
||||
layout->addWidget(new TitleLabel("ROI", this));
|
||||
|
||||
@@ -317,3 +321,7 @@ void JFJochViewerSidePanel::SetROIBox(QRect box) {
|
||||
void JFJochViewerSidePanel::SetROICircle(double x, double y, double radius) {
|
||||
roi->SetROICircle(x, y, radius);
|
||||
}
|
||||
|
||||
void JFJochViewerSidePanel::setColorMap(int color_map) {
|
||||
chart->setColorMap(color_map);
|
||||
}
|
||||
|
||||
@@ -47,12 +47,14 @@ signals:
|
||||
void ROICircleConfigured(double center_x, double center_y, double radius);
|
||||
void AddROIToUserMask();
|
||||
void SubtractROIFromUserMask();
|
||||
void writeStatusBar(QString string, int timeout_ms = 0);
|
||||
public:
|
||||
JFJochViewerSidePanel(QWidget *parent);
|
||||
public slots:
|
||||
void loadImage(std::shared_ptr<const JFJochReaderImage> image);
|
||||
void SetROIBox(QRect box);
|
||||
void SetROICircle(double x, double y, double radius);
|
||||
void setColorMap(int color_map);
|
||||
private slots:
|
||||
void editingFinished();
|
||||
void enableResRings(bool input);
|
||||
|
||||
@@ -33,6 +33,11 @@ JFJochViewerSidePanelChart::JFJochViewerSidePanelChart(QWidget *parent) : QWidge
|
||||
layout->addWidget(stack);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
connect(azint_image, &JFJochAzIntImageView::writeStatusBar,
|
||||
[&](QString string, int timeout_ms) {
|
||||
emit writeStatusBar(string, timeout_ms);
|
||||
});
|
||||
}
|
||||
|
||||
void JFJochViewerSidePanelChart::comboBoxSelected(int val) {
|
||||
@@ -103,3 +108,7 @@ void JFJochViewerSidePanelChart::loadImage(std::shared_ptr<const JFJochReaderIma
|
||||
image = in_image;
|
||||
redrawPlot();
|
||||
}
|
||||
|
||||
void JFJochViewerSidePanelChart::setColorMap(int color_map) {
|
||||
azint_image->setColorMap(color_map);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ class JFJochViewerSidePanelChart : public QWidget {
|
||||
QComboBox *combo_box;
|
||||
void redrawPlot();
|
||||
|
||||
signals:
|
||||
void writeStatusBar(QString string, int timeout_ms = 0);
|
||||
|
||||
private slots:
|
||||
void comboBoxSelected(int val);
|
||||
|
||||
@@ -33,6 +36,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void loadImage(std::shared_ptr<const JFJochReaderImage> image);
|
||||
void setColorMap(int color_map);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -150,6 +150,9 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString
|
||||
connect(toolBarDisplay, &JFJochViewerToolbarDisplay::colorMapChanged, viewer,
|
||||
&JFJochDiffractionImage::setColorMap);
|
||||
|
||||
connect(toolBarDisplay, &JFJochViewerToolbarDisplay::colorMapChanged, side_panel,
|
||||
&JFJochViewerSidePanel::setColorMap);
|
||||
|
||||
connect(viewer, &JFJochDiffractionImage::foregroundChanged,
|
||||
toolBarDisplay, &JFJochViewerToolbarDisplay::updateForeground);
|
||||
|
||||
@@ -264,6 +267,8 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString
|
||||
viewer, &JFJochDiffractionImage::setResolutionRing);
|
||||
connect(viewer, &JFJochDiffractionImage::writeStatusBar,
|
||||
statusbar, &JFJochViewerStatusBar::display);
|
||||
connect(side_panel, &JFJochViewerSidePanel::writeStatusBar,
|
||||
statusbar, &JFJochViewerStatusBar::display);
|
||||
|
||||
connect(metadataWindow, &JFJochViewerMetadataWindow::datasetUpdated,
|
||||
reading_worker, &JFJochImageReadingWorker::UpdateDataset);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -10,20 +10,22 @@
|
||||
#include <QLabel>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "JFJochImage.h"
|
||||
#include "../../common/ColorScale.h"
|
||||
|
||||
class JFJochAzIntImageView : public QWidget {
|
||||
class JFJochAzIntImageView : public JFJochImage {
|
||||
Q_OBJECT
|
||||
|
||||
QLabel* label;
|
||||
QImage img;
|
||||
ColorScale color_scale;
|
||||
bool auto_range = true;
|
||||
float range_min = 0.0f;
|
||||
float range_max = 1.0f;
|
||||
|
||||
void updateLabelPixmap();
|
||||
void resizeEvent(QResizeEvent* e) override;
|
||||
std::vector<float> data;
|
||||
std::vector<float> phi;
|
||||
std::vector<float> q;
|
||||
|
||||
void mouseHover(QMouseEvent* event) override;
|
||||
public:
|
||||
explicit JFJochAzIntImageView(QWidget *parent = nullptr);
|
||||
void Clear();
|
||||
@@ -33,7 +35,6 @@ public:
|
||||
const std::vector<float> &q,
|
||||
int azimuthal_bins);
|
||||
|
||||
void SetColorScale(ColorScaleEnum map);
|
||||
void SetRangeAuto();
|
||||
void SetRange(float min_val, float max_val);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user