mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
Gainzoom (#556)
* gain plot: dont allow zoom, only zoom on main plot * fixed gain plot zooming * fixing panning for gainplots
This commit is contained in:
@ -64,6 +64,8 @@ class qDrawPlot : public QWidget, private Ui::PlotObject {
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private slots:
|
||||
void Zoom1DGainPlot(const QRectF &rect);
|
||||
void Zoom2DGainPlot(const QRectF &rect);
|
||||
void SetSaveFileName(QString val);
|
||||
void UpdatePlot();
|
||||
|
||||
|
@ -169,9 +169,16 @@ class SlsQt1DPlot : public QwtPlot {
|
||||
|
||||
QwtPlotShapeItem *roiBox{nullptr};
|
||||
|
||||
signals:
|
||||
void PlotZoomedSignal(const QRectF &);
|
||||
|
||||
public slots:
|
||||
void SetZoomX(const QRectF &rect);
|
||||
void UnZoom();
|
||||
void Update();
|
||||
|
||||
private slots:
|
||||
void GetPannedCoord(int, int);
|
||||
};
|
||||
|
||||
} // namespace sls
|
||||
|
@ -76,6 +76,13 @@ class SlsQt2DPlot : public QwtPlot {
|
||||
|
||||
public slots:
|
||||
void showSpectrogram(bool on);
|
||||
void SetZoom(const QRectF &rect);
|
||||
|
||||
private slots:
|
||||
void GetPannedCoord(int, int);
|
||||
|
||||
signals:
|
||||
void PlotZoomedSignal(const QRectF &);
|
||||
|
||||
private:
|
||||
void SetupZoom();
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
/* TODO! short description */
|
||||
#include "SlsQt1DPlot.h"
|
||||
#include "sls/logger.h"
|
||||
#include <iostream>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_math.h>
|
||||
@ -464,6 +465,16 @@ void SlsQt1DPlot::DisableRoiBox() {
|
||||
}
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::SetZoomX(const QRectF &rect) {
|
||||
double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
|
||||
rect.getCoords(&xmin, &ymin, &xmax, &ymax);
|
||||
LOG(logDEBUG1) << "Zoomed in at " << xmin << "\t" << xmax << "\t" << ymin
|
||||
<< "\t" << ymax;
|
||||
SetXMinMax(xmin, xmax);
|
||||
// SetYMinMax(ymin, ymax);
|
||||
replot();
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::UnZoom() {
|
||||
setAxisScale(QwtPlot::xBottom, zoomer->x(), zoomer->x() + zoomer->w());
|
||||
setAxisScale(QwtPlot::yLeft, zoomer->y(), zoomer->y() + zoomer->h());
|
||||
@ -480,6 +491,22 @@ void SlsQt1DPlot::SetZoom(double xmin, double ymin, double x_width,
|
||||
Update();
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::GetPannedCoord(int, int) {
|
||||
double xmin = invTransform(QwtPlot::xBottom, 0);
|
||||
double xmax = invTransform(QwtPlot::xBottom, canvas()->rect().width());
|
||||
double ymax = invTransform(QwtPlot::yLeft, 0);
|
||||
double ymin = invTransform(QwtPlot::yLeft, canvas()->rect().height());
|
||||
LOG(logDEBUG1) << "Rect1 " << xmin << "\t" << xmax << "\t" << ymin << "\t"
|
||||
<< ymax;
|
||||
QPointF topLeft = QPointF(xmin, ymin);
|
||||
QPointF bottomRight = QPointF(xmax, ymax);
|
||||
const QRectF rectf = QRectF(topLeft, bottomRight);
|
||||
rectf.getCoords(&xmin, &ymin, &xmax, &ymax);
|
||||
LOG(logDEBUG1) << "RectF " << xmin << "\t" << xmax << "\t" << ymin << "\t"
|
||||
<< ymax;
|
||||
emit PlotZoomedSignal(rectf);
|
||||
}
|
||||
|
||||
void SlsQt1DPlot::RemoveHLine() {
|
||||
if (hline)
|
||||
hline->detach();
|
||||
@ -540,6 +567,11 @@ void SlsQt1DPlot::SetupZoom() {
|
||||
const QColor c(Qt::darkBlue);
|
||||
zoomer->setRubberBandPen(c);
|
||||
zoomer->setTrackerPen(c);
|
||||
|
||||
connect(zoomer, SIGNAL(zoomed(const QRectF &)), this,
|
||||
SIGNAL(PlotZoomedSignal(const QRectF &)));
|
||||
connect(panner, SIGNAL(panned(int, int)), this,
|
||||
SLOT(GetPannedCoord(int, int)));
|
||||
}
|
||||
|
||||
// Set a plain canvas frame and align the scales to it
|
||||
|
@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
#include "SlsQt2DPlot.h"
|
||||
// #include "sls/ansi.h"
|
||||
#include "sls/logger.h"
|
||||
|
||||
#include <qlist.h>
|
||||
#include <qprinter.h>
|
||||
@ -141,6 +141,12 @@ void SlsQt2DPlot::SetupZoom() {
|
||||
const QColor c(Qt::darkBlue);
|
||||
zoomer->setRubberBandPen(c);
|
||||
zoomer->setTrackerPen(c);
|
||||
|
||||
connect(zoomer, SIGNAL(zoomed(const QRectF &)), this,
|
||||
SIGNAL(PlotZoomedSignal(const QRectF &)));
|
||||
|
||||
connect(panner, SIGNAL(panned(int, int)), this,
|
||||
SLOT(GetPannedCoord(int, int)));
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::UnZoom(bool replot) {
|
||||
@ -153,6 +159,32 @@ void SlsQt2DPlot::UnZoom(bool replot) {
|
||||
// zoomer->zoom(0);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::GetPannedCoord(int, int) {
|
||||
double xmin = invTransform(QwtPlot::xBottom, 0);
|
||||
double xmax = invTransform(QwtPlot::xBottom, canvas()->rect().width());
|
||||
double ymax = invTransform(QwtPlot::yLeft, 0);
|
||||
double ymin = invTransform(QwtPlot::yLeft, canvas()->rect().height());
|
||||
LOG(logDEBUG1) << "Rect1 " << xmin << "\t" << xmax << "\t" << ymin << "\t"
|
||||
<< ymax;
|
||||
QPointF topLeft = QPointF(xmin, ymin);
|
||||
QPointF bottomRight = QPointF(xmax, ymax);
|
||||
const QRectF rectf = QRectF(topLeft, bottomRight);
|
||||
rectf.getCoords(&xmin, &ymin, &xmax, &ymax);
|
||||
LOG(logDEBUG1) << "RectF " << xmin << "\t" << xmax << "\t" << ymin << "\t"
|
||||
<< ymax;
|
||||
emit PlotZoomedSignal(rectf);
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetZoom(const QRectF &rect) {
|
||||
double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
|
||||
rect.getCoords(&xmin, &ymin, &xmax, &ymax);
|
||||
LOG(logDEBUG1) << "Plot zooming in to " << xmin << " " << xmax << " "
|
||||
<< ymin << " " << ymax;
|
||||
SetXMinMax(xmin, xmax);
|
||||
SetYMinMax(ymin, ymax);
|
||||
replot();
|
||||
}
|
||||
|
||||
void SlsQt2DPlot::SetZoom(double xmin, double ymin, double x_width,
|
||||
double y_width) {
|
||||
zoomer->setZoomBase(QRectF(xmin, ymin, x_width, y_width));
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include <QtConcurrentRun>
|
||||
#include <qwt_scale_engine.h>
|
||||
|
||||
namespace sls {
|
||||
|
||||
@ -170,14 +171,15 @@ void qDrawPlot::SetupPlots() {
|
||||
QList<double> majorTicks({0, 1, 2, 3});
|
||||
QwtScaleDiv div(0, 3, QList<double>(), QList<double>(), majorTicks);
|
||||
gainplot1d->setAxisScaleDiv(QwtPlot::yLeft, div);
|
||||
// gainplot1d->axisScaleDraw(QwtPlot::xBottom)->enableComponent(QwtScaleDraw::Ticks,
|
||||
// false);
|
||||
// gainplot1d->axisScaleDraw(QwtPlot::yLeft)->enableComponent(QwtScaleDraw::Labels,
|
||||
// false);
|
||||
|
||||
gainhist1d->setItemAttribute(QwtPlotItem::Legend, false);
|
||||
gainhist1d->Attach(gainplot1d);
|
||||
gainplot1d->DisableZoom(true);
|
||||
gainplot1d->hide();
|
||||
|
||||
connect(plot1d, SIGNAL(PlotZoomedSignal(const QRectF &)), this,
|
||||
SLOT(Zoom1DGainPlot(const QRectF &)));
|
||||
|
||||
// setup 2d data
|
||||
|
||||
delete[] data2d;
|
||||
@ -226,8 +228,12 @@ void qDrawPlot::SetupPlots() {
|
||||
gainplot2d->enableAxis(QwtPlot::xBottom, false);
|
||||
// set ticks to just 3
|
||||
gainplot2d->setAxisScaleDiv(QwtPlot::yRight, div);
|
||||
gainplot2d->DisableZoom(true);
|
||||
gainplot2d->hide();
|
||||
|
||||
connect(plot2d, SIGNAL(PlotZoomedSignal(const QRectF &)), this,
|
||||
SLOT(Zoom2DGainPlot(const QRectF &)));
|
||||
|
||||
// layout of plots
|
||||
int ratio = qDefs::DATA_GAIN_PLOT_RATIO - 1;
|
||||
plotLayout->addWidget(plot1d, 0, 0, ratio, ratio);
|
||||
@ -237,6 +243,16 @@ void qDrawPlot::SetupPlots() {
|
||||
Qt::AlignRight | Qt::AlignTop);
|
||||
}
|
||||
|
||||
void qDrawPlot::Zoom1DGainPlot(const QRectF &rect) {
|
||||
std::lock_guard<std::mutex> lock(mPlots);
|
||||
gainplot1d->SetZoomX(rect);
|
||||
}
|
||||
|
||||
void qDrawPlot::Zoom2DGainPlot(const QRectF &rect) {
|
||||
std::lock_guard<std::mutex> lock(mPlots);
|
||||
gainplot2d->SetZoom(rect);
|
||||
}
|
||||
|
||||
void qDrawPlot::resizeEvent(QResizeEvent *event) {
|
||||
if (gainplot2d->isVisible()) {
|
||||
gainplot2d->setFixedWidth(plot2d->width() /
|
||||
@ -254,9 +270,9 @@ void qDrawPlot::resizeEvent(QResizeEvent *event) {
|
||||
|
||||
bool qDrawPlot::GetIsRunning() { return isRunning; }
|
||||
|
||||
void qDrawPlot::SetRunning(bool enable) {
|
||||
void qDrawPlot::SetRunning(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(mPlots);
|
||||
isRunning = enable;
|
||||
isRunning = enable;
|
||||
}
|
||||
|
||||
double qDrawPlot::GetProgress() { return progress; }
|
||||
@ -525,6 +541,7 @@ void qDrawPlot::ClonePlot() {
|
||||
h->SetLineColor(iHist);
|
||||
h->setStyleLinesorDots(isLines);
|
||||
h->setSymbolMarkers(isMarkers);
|
||||
h->setItemAttribute(QwtPlotItem::Legend, false);
|
||||
cloneplotHists1D.append(h);
|
||||
h->Attach(cloneplot1D);
|
||||
}
|
||||
@ -545,7 +562,11 @@ void qDrawPlot::ClonePlot() {
|
||||
QList<double> majorTicks({0, 1, 2, 3});
|
||||
QwtScaleDiv div(0, 3, QList<double>(), QList<double>(), majorTicks);
|
||||
clonegainplot1D->setAxisScaleDiv(QwtPlot::yLeft, div);
|
||||
clonegainplot1D->DisableZoom(true);
|
||||
h->Attach(clonegainplot1D);
|
||||
|
||||
connect(cloneplot1D, SIGNAL(PlotZoomedSignal(const QRectF &)),
|
||||
clonegainplot1D, SLOT(SetZoomX(const QRectF &)));
|
||||
}
|
||||
} else {
|
||||
LOG(logDEBUG) << "Cloning 2D Image";
|
||||
@ -586,6 +607,10 @@ void qDrawPlot::ClonePlot() {
|
||||
clonegainplot2D->enableAxis(2, false);
|
||||
clonegainplot2D->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY,
|
||||
-0.5, nPixelsY - 0.5, gainData);
|
||||
clonegainplot2D->DisableZoom(true);
|
||||
|
||||
connect(cloneplot2D, SIGNAL(PlotZoomedSignal(const QRectF &)),
|
||||
clonegainplot2D, SLOT(SetZoom(const QRectF &)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1104,47 +1129,57 @@ void qDrawPlot::Update2dPlot() {
|
||||
void qDrawPlot::Update1dXYRange() {
|
||||
if (!isXYRange[qDefs::XMIN] && !isXYRange[qDefs::XMAX]) {
|
||||
plot1d->EnableXAutoScaling();
|
||||
gainplot1d->EnableXAutoScaling();
|
||||
} else {
|
||||
double xmin = (isXYRange[qDefs::XMIN] ? xyRange[qDefs::XMIN]
|
||||
: plot1d->GetXMinimum());
|
||||
double xmax = (isXYRange[qDefs::XMAX] ? xyRange[qDefs::XMAX]
|
||||
: plot1d->GetXMaximum());
|
||||
plot1d->SetXMinMax(xmin, xmax);
|
||||
gainplot1d->SetXMinMax(xmin, xmax);
|
||||
}
|
||||
|
||||
if (!isXYRange[qDefs::YMIN] && !isXYRange[qDefs::YMAX]) {
|
||||
plot1d->EnableYAutoScaling();
|
||||
gainplot1d->EnableYAutoScaling();
|
||||
} else {
|
||||
double ymin = (isXYRange[qDefs::YMIN] ? xyRange[qDefs::YMIN]
|
||||
: plot1d->GetYMinimum());
|
||||
double ymax = (isXYRange[qDefs::YMAX] ? xyRange[qDefs::YMAX]
|
||||
: plot1d->GetYMaximum());
|
||||
plot1d->SetYMinMax(ymin, ymax);
|
||||
gainplot1d->SetYMinMax(ymin, ymax);
|
||||
}
|
||||
plot1d->Update();
|
||||
gainplot1d->Update();
|
||||
}
|
||||
|
||||
void qDrawPlot::Update2dXYRange() {
|
||||
if (!isXYRange[qDefs::XMIN] && !isXYRange[qDefs::XMAX]) {
|
||||
plot2d->EnableXAutoScaling();
|
||||
gainplot2d->EnableXAutoScaling();
|
||||
} else {
|
||||
double xmin = (isXYRange[qDefs::XMIN] ? xyRange[qDefs::XMIN]
|
||||
: plot2d->GetXMinimum());
|
||||
double xmax = (isXYRange[qDefs::XMAX] ? xyRange[qDefs::XMAX]
|
||||
: plot2d->GetXMaximum());
|
||||
plot2d->SetXMinMax(xmin, xmax);
|
||||
gainplot2d->SetXMinMax(xmin, xmax);
|
||||
}
|
||||
|
||||
if (!isXYRange[qDefs::YMIN] && !isXYRange[qDefs::YMAX]) {
|
||||
plot2d->EnableYAutoScaling();
|
||||
gainplot2d->EnableYAutoScaling();
|
||||
} else {
|
||||
double ymin = (isXYRange[qDefs::YMIN] ? xyRange[qDefs::YMIN]
|
||||
: plot2d->GetYMinimum());
|
||||
double ymax = (isXYRange[qDefs::YMAX] ? xyRange[qDefs::YMAX]
|
||||
: plot2d->GetYMaximum());
|
||||
plot2d->SetYMinMax(ymin, ymax);
|
||||
gainplot2d->SetYMinMax(ymin, ymax);
|
||||
}
|
||||
plot2d->Update();
|
||||
gainplot2d->Update();
|
||||
}
|
||||
|
||||
void qDrawPlot::toDoublePixelData(double *dest, char *source, int size,
|
||||
|
Reference in New Issue
Block a user