From cbd0aed8e53e2c6ec3d4d5f9cf3d3cad1cbe9398 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 30 Jun 2025 12:03:39 +0200 Subject: [PATCH] gui shows roi now --- slsDetectorGui/include/qDrawPlot.h | 6 +- .../slsDetectorPlotting/include/SlsQt1DPlot.h | 8 +- .../slsDetectorPlotting/include/SlsQt2DPlot.h | 8 +- .../slsDetectorPlotting/src/SlsQt1DPlot.cpp | 28 ++++--- .../slsDetectorPlotting/src/SlsQt2DPlot.cpp | 28 +++---- slsDetectorGui/src/qDetectorMain.cpp | 1 + slsDetectorGui/src/qDrawPlot.cpp | 84 ++++++++++--------- .../include/sls/detectorData.h | 9 -- slsDetectorSoftware/src/DetectorImpl.cpp | 3 +- slsReceiverSoftware/src/ClientInterface.cpp | 2 +- 10 files changed, 92 insertions(+), 85 deletions(-) diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 92f660b50..c4b3b2a9d 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -40,6 +40,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { void SetDataCallBack(bool enable); void SetBinary(bool enable, int from = 0, int to = 0); void StartAcquisition(); + void UpdateROI(); public slots: void SetPersistency(int val); @@ -166,8 +167,8 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { int64_t currentFrame{0}; mutable std::mutex mPlots; int64_t currentAcqIndex{0}; - slsDetectorDefs::ROI rxRoi{}; - bool isRxRoiDisplayed{false}; + bool hasRoi{false}; + bool roiDisplayInitialized{false}; bool isGapPixels{false}; unsigned int nPixelsX{0}; @@ -176,6 +177,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { uint32_t gainMask{0}; int gainOffset{0}; bool gotthard25; + std::vector roi{1}; }; } // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h index 9dfdee151..878a43b81 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h @@ -5,6 +5,8 @@ #include "SlsQt1DZoomer.h" #include "sls/ansi.h" +#include "sls/sls_detector_defs.h" + #include #include #include @@ -141,8 +143,9 @@ class SlsQt1DPlot : public QwtPlot { void SetLogX(bool yes = 1); void SetLogY(bool yes = 1); - void EnableRoiBox(std::array roi); - void DisableRoiBox(); + void EnableRoiBoxes(std::vector roi, int ymin, + int ymax); + void DisableRoiBoxes(); private: bool gainPlot{false}; @@ -169,6 +172,7 @@ class SlsQt1DPlot : public QwtPlot { friend void SlsQtH1D::Attach(SlsQt1DPlot *p); friend void SlsQtH1D::Detach(SlsQt1DPlot *p); + std::vector> roiBoxes{}; QwtPlotShapeItem *roiBox{nullptr}; signals: diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h index 4c55db6af..f7142b6eb 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h @@ -3,6 +3,8 @@ #pragma once #include "SlsQt2DHist.h" #include "SlsQt2DZoomer.h" +#include "sls/sls_detector_defs.h" + #include #include #include @@ -71,8 +73,8 @@ class SlsQt2DPlot : public QwtPlot { void SetLogz(bool enable, bool isMin, bool isMax, double min, double max); void SetZRange(bool isMin, bool isMax, double min, double max); void LogZ(bool on = 1); - void EnableRoiBox(std::array roi); - void DisableRoiBox(); + void EnableRoiBoxes(std::vector roi); + void DisableRoiBoxes(); public slots: void showSpectrogram(bool on); @@ -101,7 +103,7 @@ class SlsQt2DPlot : public QwtPlot { QList contourLevelsLog; bool disableZoom{false}; int isLog; - QwtPlotShapeItem *roiBox{nullptr}; + std::vector> roiBoxes{}; }; } // namespace sls diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp index 55716cc33..8ae58d4b2 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp @@ -462,24 +462,26 @@ void SlsQt1DPlot::SetLog(int axisId, bool yes) { Update(); } -void SlsQt1DPlot::EnableRoiBox(std::array roi) { - if (roiBox == nullptr) { - roiBox = new QwtPlotShapeItem(); - roiBox->attach(this); - roiBox->setPen(QColor(Qt::yellow), 2.0, Qt::SolidLine); +void SlsQt1DPlot::EnableRoiBoxes(std::vector roi, + int ymin, int ymax) { + roiBoxes.clear(); + for (auto &r : roi) { + auto box = std::make_unique(); + box->setPen(QColor(Qt::yellow), 2.0, Qt::SolidLine); + // TopLeft - BottomRight (max points are +1 on graph) + QRectF myRect(QPointF(r.xmin, ymin), QPointF(r.xmax - 1, ymax - 1)); + box->setRect(myRect); + box->attach(this); + roiBoxes.push_back(std::move(box)); } - - // TopLeft - BottomRight (max points are +1 on graph) - QRect myRect(QPoint(roi[0], roi[2]), QPoint(roi[1] - 1, roi[3] - 1)); - roiBox->setRect(QRectF(myRect)); replot(); } -void SlsQt1DPlot::DisableRoiBox() { - if (roiBox != nullptr) { - roiBox->detach(); - replot(); +void SlsQt1DPlot::DisableRoiBoxes() { + for (auto &r : roiBoxes) { + r->detach(); } + replot(); } void SlsQt1DPlot::SetZoomX(const QRectF &rect) { diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp index 3418abf08..ecd7b6eb3 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cpp @@ -350,25 +350,25 @@ void SlsQt2DPlot::showSpectrogram(bool on) { Update(); } -void SlsQt2DPlot::EnableRoiBox(std::array roi) { - if (roiBox == nullptr) { - roiBox = new QwtPlotShapeItem(); +void SlsQt2DPlot::EnableRoiBoxes(std::vector roi) { + roiBoxes.clear(); + for (auto &r : roi) { + auto box = std::make_unique(); + box->setPen(QColor(Qt::yellow), 2.0, Qt::SolidLine); + // TopLeft - BottomRight (max points are +1 on graph) + QRectF myRect(QPointF(r.xmin, r.ymin), QPointF(r.xmax - 1, r.ymax - 1)); + box->setRect(myRect); + box->attach(this); + roiBoxes.push_back(std::move(box)); } - roiBox->setPen(QColor(Qt::yellow), 2.0, Qt::SolidLine); - - // TopLeft - BottomRight (max points are +1 on graph) - QRect myRect(QPoint(roi[0], roi[2]), QPoint(roi[1] - 1, roi[3] - 1)); - roiBox->setRect(QRectF(myRect)); - - roiBox->attach(this); replot(); } -void SlsQt2DPlot::DisableRoiBox() { - if (roiBox != nullptr) { - roiBox->detach(); - replot(); +void SlsQt2DPlot::DisableRoiBoxes() { + for (auto &r : roiBoxes) { + r->detach(); } + replot(); } } // namespace sls diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index c5ddc8618..438707c36 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -539,6 +539,7 @@ void qDetectorMain::EnableTabs(bool enable) { tabDeveloper->Refresh(); tabPlot->Refresh(); + plot->UpdateROI(); plot->StartAcquisition(); } else { // to enable scan box tabPlot->Refresh(); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 829a3c81a..0eb8e2e11 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -608,7 +608,6 @@ void qDrawPlot::StartAcquisition() { currentFrame = 0; boxPlot->setTitle("Old Plot"); det->clearAcquiringFlag(); // (from previous exit) or if running - isRxRoiDisplayed = false; // ensure data streaming in receiver (if plot enabled) if (isPlot) { @@ -632,6 +631,33 @@ void qDrawPlot::StartAcquisition() { LOG(logDEBUG) << "End of Starting Acquisition in qDrawPlot"; } +void qDrawPlot::UpdateROI() { + try { + std::lock_guard lock(mPlots); + roi = det->getRxROI(); + roiDisplayInitialized = false; + // roi enabled + if (roi.size() > 1 || !roi[0].completeRoi()) { + hasRoi = true; + // update gap pixels (gap pixels only for 2d) + if (isGapPixels) { + for (auto &r : roi) { + r.xmin += ((r.xmin / 1024) * 6 + (r.xmin / 256) * 2); + r.xmax += ((r.xmax / 1024) * 6 + (r.xmax / 256) * 2); + r.ymin += ((r.ymin / 512) * 34 + (r.ymin / 256) * 2); + r.ymax += ((r.ymax / 512) * 34 + (r.ymax / 256) * 2); + } + LOG(logINFO) + << "Roi recalculated with gap pixels: " << ToString(roi); + } + } else { + hasRoi = false; + } + LOG(logDEBUG) << "Roi: " << ToString(roi); + } + CATCH_DISPLAY("Could not get reciver ROI.", "qDrawPlot::UpdateRoi") +} + void qDrawPlot::AcquireThread() { LOG(logDEBUG) << "Acquire Thread"; std::string mess; @@ -709,7 +735,6 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, << " \t dynamic range: " << data->dynamicRange << std::endl << " \t file index: " << data->fileIndex << std::endl << " \t complete image: " << data->completeImage << std::endl - << " \t rx Roi: " << ToString(data->rxRoi) << std::endl << " ]"; progress = data->progressIndex; @@ -717,22 +742,6 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, currentFrame = frameIndex; LOG(logDEBUG) << "[ Progress:" << progress << "%, Frame:" << currentFrame << " ]"; - if (!isRxRoiDisplayed) { - rxRoi.xmin = data->rxRoi[0]; - rxRoi.xmax = data->rxRoi[1]; - rxRoi.ymin = data->rxRoi[2]; - rxRoi.ymax = data->rxRoi[3]; - // only for 2d anyway - if (isGapPixels) { - rxRoi.xmin += ((rxRoi.xmin / 1024) * 6 + (rxRoi.xmin / 256) * 2); - rxRoi.xmax += ((rxRoi.xmax / 1024) * 6 + (rxRoi.xmax / 256) * 2); - rxRoi.ymin += ((rxRoi.ymin / 512) * 34 + (rxRoi.ymin / 256) * 2); - rxRoi.ymax += ((rxRoi.ymax / 512) * 34 + (rxRoi.ymax / 256) * 2); - LOG(logINFO) << "Rx_roi recalculated with gap pixels: " - << ToString(rxRoi); - } - LOG(logDEBUG) << "Rx_roi: " << ToString(rxRoi); - } // 1d check if npixelX has changed (m3 for different counters enabled) if (is1d && static_cast(nPixelsX) != data->nx) { @@ -971,30 +980,27 @@ void qDrawPlot::Update1dPlot() { xyRangeChanged = false; } plot1d->DisableZoom(disableZoom); - if (!isRxRoiDisplayed) { - isRxRoiDisplayed = true; - if (rxRoi.completeRoi()) { - plot1d->DisableRoiBox(); + if (!roiDisplayInitialized) { + roiDisplayInitialized = true; + if (!hasRoi) { + plot1d->DisableRoiBoxes(); if (isGainDataExtracted) { - gainplot1d->DisableRoiBox(); + gainplot1d->DisableRoiBoxes(); } lblRxRoiEnabled->hide(); } else { - plot1d->EnableRoiBox(std::array{ - rxRoi.xmin, rxRoi.xmax, (int)plot1d->GetYMinimum(), - (int)plot1d->GetYMaximum()}); + plot1d->EnableRoiBoxes(roi, (int)plot1d->GetYMinimum(), + (int)plot1d->GetYMaximum()); if (isGainDataExtracted) { - gainplot1d->EnableRoiBox( - std::array{rxRoi.xmin, rxRoi.xmax, 0, 3}); + gainplot1d->EnableRoiBoxes(roi, 0, 3); } lblRxRoiEnabled->show(); } } // ymin and ymax could change (so replot roi every time) - if (!rxRoi.completeRoi()) { - plot1d->EnableRoiBox(std::array{rxRoi.xmin, rxRoi.xmax, - (int)plot1d->GetYMinimum(), - (int)plot1d->GetYMaximum()}); + if (hasRoi) { + plot1d->EnableRoiBoxes(roi, (int)plot1d->GetYMinimum(), + (int)plot1d->GetYMaximum()); } } @@ -1025,18 +1031,18 @@ void qDrawPlot::Update2dPlot() { } plot2d->DisableZoom(disableZoom); plot2d->SetZRange(isZRange[0], isZRange[1], zRange[0], zRange[1]); - if (!isRxRoiDisplayed) { - isRxRoiDisplayed = true; - if (rxRoi.completeRoi()) { - plot2d->DisableRoiBox(); + if (!roiDisplayInitialized) { + roiDisplayInitialized = true; + if (!hasRoi) { + plot2d->DisableRoiBoxes(); if (isGainDataExtracted) { - gainplot2d->DisableRoiBox(); + gainplot2d->DisableRoiBoxes(); } lblRxRoiEnabled->hide(); } else { - plot2d->EnableRoiBox(rxRoi.getIntArray()); + plot2d->EnableRoiBoxes(roi); if (isGainDataExtracted) { - gainplot2d->EnableRoiBox(rxRoi.getIntArray()); + gainplot2d->EnableRoiBoxes(roi); } lblRxRoiEnabled->show(); } diff --git a/slsDetectorSoftware/include/sls/detectorData.h b/slsDetectorSoftware/include/sls/detectorData.h index 33f983a66..c55906482 100644 --- a/slsDetectorSoftware/include/sls/detectorData.h +++ b/slsDetectorSoftware/include/sls/detectorData.h @@ -19,14 +19,6 @@ class detectorData { databytes(databytes), dynamicRange(dynamicRange), completeImage(completeImage){}; - detectorData(double progressIndex, std::string fileName, int nx, int ny, - char *data, int databytes, int dynamicRange, - uint64_t fileIndex, bool completeImage, - std::array rxRoi) - : progressIndex(progressIndex), fileName(fileName), - fileIndex(fileIndex), nx(nx), ny(ny), data(data), - databytes(databytes), dynamicRange(dynamicRange), - completeImage(completeImage), rxRoi(rxRoi){}; /** * data has to be deleted by caller */ @@ -62,7 +54,6 @@ class detectorData { int databytes; int dynamicRange; bool completeImage; - std::array rxRoi{{-1, -1, -1, -1}}; }; } // namespace sls diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 35e0b4dd8..5727edb78 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -535,7 +535,6 @@ void DetectorImpl::readFrameFromReceiver() { bool quadEnable = false; // to flip image bool eiger = false; - std::array rxRoi{}; // TODO: get roi from json header std::vector runningList(zmqSocket.size()); std::vector connectList(zmqSocket.size()); @@ -732,7 +731,7 @@ void DetectorImpl::readFrameFromReceiver() { thisData = new detectorData(currentProgress, currentFileName, nDetActualPixelsX, nDetActualPixelsY, callbackImage, imagesize, dynamicRange, - currentFileIndex, completeImage, rxRoi); + currentFileIndex, completeImage); try { dataReady( thisData, currentFrameIndex, diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index c05ee6245..902870a8f 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -1843,7 +1843,7 @@ int ClientInterface::get_roi_metadata(Interface &socket) { if (detType == CHIPTESTBOARD || detType == XILINX_CHIPTESTBOARD) functionNotImplemented(); auto retvals = impl()->getMultiROIMetadata(); - LOG(logINFORED) << "Receiver ROI metadata retval:" << ToString(retvals); + LOG(logDEBUG1) << "Receiver ROI metadata retval:" << ToString(retvals); auto size = static_cast(retvals.size()); socket.Send(size); if (size > 0)