From a98d2d1d71573b7541d94e89ea106aa0fa184357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6hli?= Date: Sun, 22 May 2022 20:51:52 +0200 Subject: [PATCH] Initial Upload --- urc.rc | 1 + visualizationenlarge.cpp | 321 +++++++++++++++++++++++++++++++++++++++ visualizationenlarge.h | 62 ++++++++ visualizationenlarge.ui | 63 ++++++++ 4 files changed, 447 insertions(+) create mode 100644 urc.rc create mode 100644 visualizationenlarge.cpp create mode 100644 visualizationenlarge.h create mode 100644 visualizationenlarge.ui diff --git a/urc.rc b/urc.rc new file mode 100644 index 0000000..1588dac --- /dev/null +++ b/urc.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "uranos.ico" \ No newline at end of file diff --git a/visualizationenlarge.cpp b/visualizationenlarge.cpp new file mode 100644 index 0000000..13e15aa --- /dev/null +++ b/visualizationenlarge.cpp @@ -0,0 +1,321 @@ +#include "visualizationenlarge.h" +#include "ui_visualizationenlarge.h" + + +// variables for drawing the enlarged visulization view +float squareDim = 10; + +int horizontalSliderValue = 50; +int horizontalSliderColorZeroValue = 0; +int manualColorZero = 0; +int manualColor = 0; +int colorScheme = 0; +int screenshotcounter = 1; + +bool plotTopViewLog = false; +bool silderColorMoved = false; +bool useManualColor = false; + +string workFolder; + +VisualizationEnlarge::VisualizationEnlarge(QWidget *parent) : + QDialog(parent), + ui(new Ui::VisualizationEnlarge) +{ + ui->setupUi(this); + setupRunGraph(ui->customPlot); +} + +VisualizationEnlarge::~VisualizationEnlarge() +{ + delete ui; +} + +void VisualizationEnlarge::setSquareDimSize(float squareDimSize) +{ + squareDim = squareDimSize; +} + +void VisualizationEnlarge::sethorizontalSliderValue(int value) +{ + horizontalSliderValue = value; +} + +void VisualizationEnlarge::sethorizontalSliderColorZeroValue(int value) +{ + horizontalSliderColorZeroValue = value; +} + + +void VisualizationEnlarge::setmanualColorZero(int value) +{ + manualColorZero = value; +} + +void VisualizationEnlarge::setmanualColor(int value) +{ + manualColor = value; +} + +void VisualizationEnlarge::setsilderColorMoved(bool value) +{ + silderColorMoved = value; +} + +void VisualizationEnlarge::setplotTopViewLog(bool value) +{ + plotTopViewLog = value; +} + +void VisualizationEnlarge::setuseManualColor(bool value) +{ + useManualColor = value; +} + +void VisualizationEnlarge::setColorScheme(int value) +{ + colorScheme = value; +} + +void VisualizationEnlarge::setWorkFolder(string text) +{ + workFolder = text; +} + + +void VisualizationEnlarge::plotGraph(TH2F* data, int size, float squareDimSize) +{ + setSquareDimSize(squareDimSize); + + float entryWeight, maximumWeight; + float pixelsum; + + QColor lightBlue = QColor (215, 237, 255); + + ui->customPlot->clearPlottables(); + ui->customPlot->plotLayout()->remove(ui->customPlot->plotLayout()->element(0,1)); + + int elementCount = ui->customPlot->plotLayout()->elementCount(); + + for(int i = 0; i < elementCount; i++) + { + if(qobject_cast(ui->customPlot->plotLayout()->elementAt(i))) ui->customPlot->plotLayout()->removeAt(i); + } + ui->customPlot->plotLayout()->simplify(); + + QCPColorMap *colorMap = new QCPColorMap( ui->customPlot->xAxis, ui->customPlot->yAxis); + + if (size == 500) colorMap->data()->setSize(500, 500); + if (size == 1000) colorMap->data()->setSize(1000, 1000); + if (size == 2000) colorMap->data()->setSize(1000, 1000); + if (size == 4000) colorMap->data()->setSize(1000, 1000); + colorMap->data()->setRange(QCPRange(-::squareDim/2./1000., ::squareDim/2./1000.), QCPRange(-::squareDim/2./1000., ::squareDim/2./1000.)); + + if (plotTopViewLog) colorMap->setDataScaleType(QCPAxis::stLogarithmic); + + QCPColorScale *colorScale = new QCPColorScale(ui->customPlot); + + colorScale->setType(QCPAxis::atRight); + colorMap->setColorScale(colorScale); + colorScale->axis()->setLabel("Neutron Hit Density"); + + colorScale->axis()->setSubTickPen(QPen(lightBlue)); + colorScale->axis()->setTickPen(QPen(lightBlue)); + colorScale->axis()->setTickLabelColor(lightBlue); + colorScale->axis()->setLabelColor(lightBlue); + + QCPLayoutGrid *subLayout = new QCPLayoutGrid; + ui->customPlot->plotLayout()->addElement(0, 1, subLayout); + + subLayout->setMargins(QMargins(10, 10, 10, 5)); + subLayout->addElement(0, 0, colorScale); + + ui->customPlot->plotLayout()->element(0,0)->setMaximumSize(997,997); + + float minZ = 0; + + if (plotTopViewLog) minZ = 1; + + if (true) + { + if (size == 500) + { + for (int x=0; x<500; x+=1) + { + for (int y=0; y<500; y+=1) + { + colorMap->data()->setCell((int)x, (int)y, data->GetBinContent(x,y)); + } + } + entryWeight = (data->GetEntries())/(500.*500.)*4.; maximumWeight = 1.* data->GetBinContent(data->GetMaximumBin()); + } + if (size == 1000) + { + for (int x=0; x<1000; x+=1) + { + for (int y=0; y<1000; y+=1) + { + colorMap->data()->setCell((int)x, (int)y, data->GetBinContent(x,y)); + } + } + entryWeight = (data->GetEntries())/(1000.*1000.)*4.; maximumWeight = 1.* data->GetBinContent(data->GetMaximumBin()); + } + if (size == 2000) + { + for (int x=0; x<1000; x+=1) + { + for (int y=0; y<1000; y+=1) + { + pixelsum = 0; + for (int xadd=0; xadd<2; xadd+=1) + { + for (int yadd=0; yadd<2; yadd+=1) + { + pixelsum+=data->GetBinContent(2*x+xadd,2*y+yadd); + } + } + pixelsum = pixelsum/4.; + + colorMap->data()->setCell((int)x, (int)y, pixelsum); + } + } + entryWeight = (data->GetEntries())/(1000.*1000.)*4.; maximumWeight = 1.* data->GetBinContent(data->GetMaximumBin()); + } + + if (size == 4000) + { + for (int x=0; x<1000; x+=1) + { + for (int y=0; y<1000; y+=1) + { + pixelsum = 0; + for (int xadd=0; xadd<4; xadd+=1) + { + for (int yadd=0; yadd<4; yadd+=1) + { + pixelsum+=data->GetBinContent(4*x+xadd,4*y+yadd); + } + } + pixelsum = pixelsum/16.; + + colorMap->data()->setCell((int)x, (int)y, pixelsum); + } + } + entryWeight = (data->GetEntries())/(1000.*1000.)*4.; maximumWeight = 1.* data->GetBinContent(data->GetMaximumBin()); + } + } + + float colorscaleMax = (horizontalSliderValue*1.)/99.*maximumWeight; + if (colorscaleMax < 1) colorscaleMax = 1; + + if (colorScheme==0) {colorMap->setGradient(QCPColorGradient::gpJet); colorScale->setGradient(QCPColorGradient::gpCold); } + if (colorScheme==1) {colorMap->setGradient(QCPColorGradient::gpNight); colorScale->setGradient(QCPColorGradient::gpNight); } + if (colorScheme==2) {colorMap->setGradient(QCPColorGradient::gpCold); colorScale->setGradient(QCPColorGradient::gpCold);} + if (colorScheme==3) {colorMap->setGradient(QCPColorGradient::gpThermal); colorScale->setGradient(QCPColorGradient::gpThermal);} + if (colorScheme==4) {colorMap->setGradient(QCPColorGradient::gpHot); colorScale->setGradient(QCPColorGradient::gpHot);} + if (colorScheme==5) {colorMap->setGradient(QCPColorGradient::gpPolar); colorScale->setGradient(QCPColorGradient::gpPolar);} + if (colorScheme==6) {colorMap->setGradient(QCPColorGradient::gpGrayscale); colorScale->setGradient(QCPColorGradient::gpGrayscale);} + + colorMap->setInterpolate(true); + + if (manualColorZero < minZ) { manualColorZero = minZ;} + + if (!silderColorMoved) + { + if (entryWeight*1.1 < 5) {colorMap->setDataRange(QCPRange(minZ,5)); colorScale->setDataRange(QCPRange(minZ,5));} + else {colorMap->setDataRange(QCPRange(minZ,entryWeight*1.1)); colorScale->setDataRange(QCPRange(minZ,entryWeight*1.1));} + } + else + { + if (horizontalSliderColorZeroValue == 0) { colorMap->setDataRange(QCPRange( minZ , colorscaleMax )); colorScale->setDataRange(QCPRange(minZ,colorscaleMax));} + else { colorMap->setDataRange(QCPRange( (horizontalSliderColorZeroValue*1.)/99.*colorscaleMax , colorscaleMax )); colorScale->setDataRange(QCPRange((horizontalSliderColorZeroValue*1.)/99.*colorscaleMax,colorscaleMax));} + } + + if (useManualColor) + { + colorMap->setDataRange(QCPRange( manualColorZero,manualColor )); + colorScale->setDataRange(QCPRange(manualColorZero,manualColor)); + } + + ui->customPlot->rescaleAxes(); + ui->customPlot->replot(); +} + +void VisualizationEnlarge::setupRunGraph(QCustomPlot *customPlot) +{ + //QColor lightBlue = QColor ( 234 , 246 , 255); + QColor lightBlue = QColor ( 215 , 237 , 255); + QColor someBlue = QColor ( 0 , 88 , 156); + customPlot->setBackground(someBlue); + customPlot->axisRect()->setBackground(Qt::white); + customPlot->xAxis->setTickLabelColor(lightBlue); + customPlot->yAxis->setTickLabelColor(lightBlue); + customPlot->xAxis->setLabelColor(lightBlue); + customPlot->yAxis->setLabelColor(lightBlue); + customPlot->xAxis->setBasePen(QPen(lightBlue)); + customPlot->xAxis->setSubTickPen(QPen(lightBlue)); + customPlot->yAxis->setTickPen(QPen(lightBlue)); + customPlot->yAxis->setBasePen(QPen(lightBlue)); + customPlot->yAxis->setSubTickPen(QPen(lightBlue)); + customPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); + + QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis,customPlot->yAxis); + customPlot->axisRect()->setupFullAxesBox(true); + customPlot->xAxis->setLabel("x [m]"); + customPlot->yAxis->setLabel("y [m]"); + + colorMap->data()->setSize(500, 500); + colorMap->data()->setRange(QCPRange(-::squareDim/2./1000., ::squareDim/2./1000.), QCPRange(-::squareDim/2./1000., ::squareDim/2./1000.)); + + colorMap->setGradient(QCPColorGradient::gpJet); + colorMap->rescaleDataRange(true); + QCPRange dataR = colorMap->dataRange(); dataR*=2; + colorMap->setDataRange(dataR); + + QCPColorScale *colorScale = new QCPColorScale(ui->customPlot); + ui->customPlot->plotLayout()->addElement(0, 1, colorScale); + colorScale->setType(QCPAxis::atRight); + colorMap->setColorScale(colorScale); + colorScale->axis()->setLabel("Neutron Flux"); + + ui->customPlot->plotLayout()->element(0,0)->setMaximumSize(997,997); + + colorScale->axis()->setSubTickPen(QPen(lightBlue)); + colorScale->axis()->setTickPen(QPen(lightBlue)); + colorScale->axis()->setTickLabelColor(lightBlue); + colorScale->axis()->setLabelColor(lightBlue); + + colorScale->setDataRange(dataR); + + customPlot->rescaleAxes(); + + customPlot->replot(); +} + +//void VisualizationEnlarge::setFocus(MainWindow* wF) +//{ +// +//} + + +void VisualizationEnlarge::on_pushButtonPNG_toggled(bool checked) +{ + //originalPixmap.save(QString::fromStdString(workFolder)+fileName, format.toAscii()); +} + +void VisualizationEnlarge::on_pushButtonPNG_clicked() +{ + QScreen *screen = QGuiApplication::primaryScreen(); + + QPixmap originalPixmap; + + originalPixmap = screen->grabWindow(ui->customPlot->winId()); + + QString fileName = QString::fromStdString(workFolder)+"/neutronHitDensityExport_"+QString::number(screenshotcounter)+".png"; + + if (!originalPixmap.save(fileName)) + { + QMessageBox::warning(this, tr("Save Error"), tr("The image could not be saved to \"%1\".").arg(QDir::toNativeSeparators(fileName))); + } + screenshotcounter++; +} diff --git a/visualizationenlarge.h b/visualizationenlarge.h new file mode 100644 index 0000000..4a00781 --- /dev/null +++ b/visualizationenlarge.h @@ -0,0 +1,62 @@ +#ifndef VISUALIZATIONENLARGE_H +#define VISUALIZATIONENLARGE_H + +#include + +#include "qcustomplot.h" + +//#include "mainwindow.h" +#include "Toolkit.h" + +namespace Ui { +class VisualizationEnlarge; +} + +class VisualizationEnlarge : public QDialog +{ + Q_OBJECT + QMessageBox* msgBox; + +public: + explicit VisualizationEnlarge(QWidget *parent = 0); + ~VisualizationEnlarge(); + + + + void setSquareDimSize(float squareDimSize); + + void sethorizontalSliderValue(int value); + + void sethorizontalSliderColorZeroValue(int value); + + void setmanualColorZero(int value); + + void setmanualColor(int value); + + void setsilderColorMoved(bool value); + + void setplotTopViewLog(bool value); + + void setuseManualColor(bool value); + + void setColorScheme(int value); + + void setWorkFolder(string text); + + void plotGraph(TH2F* data, int size, float squareDimSize); + + void setupRunGraph(QCustomPlot *customPlot); + + //void setFocus(MainWindow* wF); + +private slots: + void on_pushButtonPNG_toggled(bool checked); + + void on_pushButtonPNG_clicked(); + +private: + Ui::VisualizationEnlarge *ui; + +}; + +#endif // VISUALIZATIONENLARGE_H diff --git a/visualizationenlarge.ui b/visualizationenlarge.ui new file mode 100644 index 0000000..8905d46 --- /dev/null +++ b/visualizationenlarge.ui @@ -0,0 +1,63 @@ + + + VisualizationEnlarge + + + + 0 + 0 + 1212 + 1052 + + + + + 1250 + 1052 + + + + Enlarged Visualization + + + + + 0 + 0 + 1211 + 1052 + + + + + 1250 + 1052 + + + + + + 1140 + 10 + 61 + 41 + + + + URANOS +Export + + + + + + + QCustomPlot + QWidget +
qcustomplot.h
+ 1 +
+
+ + +