add load background and subtract before plotting.
This commit is contained in:
parent
77af9c7ef3
commit
fe605a1d75
@ -28,6 +28,8 @@ Display::Display(QWidget *parent) :
|
||||
connect(buttonGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onButtonClicked(QAbstractButton*)));
|
||||
|
||||
connect(ui->pushButton_savebkg, &QPushButton::clicked, this, &Display::onSaveBackgroundClicked);
|
||||
connect(ui->pushButton_loadbkg, &QPushButton::clicked, this, &Display::onLoadBackgroundClicked);
|
||||
connect(ui->checkBox_subbkg, &QCheckBox::stateChanged, this, &Display::onCheckBoxStateChanged);
|
||||
}
|
||||
|
||||
Display::~Display()
|
||||
@ -77,6 +79,23 @@ void Display::plot(const QVector<unsigned short> &data)
|
||||
max = dataY[i];
|
||||
}
|
||||
|
||||
|
||||
if (subtractBackground && ui->checkBox_subbkg->isChecked()) {
|
||||
// Check if background subtraction is enabled and the checkbox is checked
|
||||
QString planeName = ui->lineTitle->text();
|
||||
planeName.remove(QChar(' '));
|
||||
|
||||
// Check if background data exists for this plane
|
||||
if (backgroundDataMap.contains(planeName)) {
|
||||
const QVector<unsigned short> &backgroundData = backgroundDataMap[planeName];
|
||||
|
||||
// Subtract background data from the current data
|
||||
for (int i = 0; i < nrPoints; ++i) {
|
||||
dataY[i] -= backgroundData[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ui->radioButtonAutoscale->isChecked())
|
||||
ui->plot->yAxis->setRange(min-0.05*(max-min),max+0.05*(max-min));
|
||||
else if (ui->radioButtonFixedScale ->isChecked())
|
||||
@ -160,3 +179,48 @@ void Display::onSaveBackgroundClicked()
|
||||
qDebug() << "Error: Failed to open" << filename << "for writing";
|
||||
}
|
||||
}
|
||||
|
||||
void Display::onLoadBackgroundClicked()
|
||||
{
|
||||
// Get the plane's name (you might need to adjust how you retrieve it)
|
||||
QString planeName = ui->lineTitle->text();
|
||||
|
||||
// Remove invalid characters from the plane name (e.g., spaces)
|
||||
planeName.remove(QChar(' '));
|
||||
|
||||
// Generate the filename with the plane name appended
|
||||
QString filename = QString("background_%1.txt").arg(planeName);
|
||||
|
||||
// Open the file for reading
|
||||
QFile file(filename);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream stream(&file);
|
||||
|
||||
// Read the data from the file and store it in the map
|
||||
QVector<unsigned short> backgroundData;
|
||||
while (!stream.atEnd()) {
|
||||
QString line = stream.readLine();
|
||||
unsigned short value = line.toUShort();
|
||||
backgroundData.append(value);
|
||||
}
|
||||
|
||||
// Close the file
|
||||
file.close();
|
||||
|
||||
// Store the background data in the map
|
||||
backgroundDataMap[planeName] = backgroundData;
|
||||
|
||||
// Notify the user that the data has been loaded
|
||||
qDebug() << "Background data loaded for" << planeName;
|
||||
} else {
|
||||
// Failed to open the file
|
||||
qDebug() << "Error: Failed to open" << filename << "for reading";
|
||||
}
|
||||
}
|
||||
|
||||
void Display::onCheckBoxStateChanged(int state)
|
||||
{
|
||||
// The state argument will be Qt::Unchecked (0) or Qt::Checked (2)
|
||||
subtractBackground = (state == Qt::Checked);
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,8 @@ public slots:
|
||||
void showEvent(QShowEvent *event);
|
||||
void onButtonClicked(QAbstractButton *button);
|
||||
void onSaveBackgroundClicked();
|
||||
void onLoadBackgroundClicked();
|
||||
void onCheckBoxStateChanged(int state);
|
||||
|
||||
protected:
|
||||
int nrPoints = 0;
|
||||
@ -41,6 +43,9 @@ private:
|
||||
QRadioButton *radioButtonFixedScale; // Pointer to the Fixed Scale radio button
|
||||
QRadioButton *radioButtonAutoscale; // Pointer to the Autoscale radio button
|
||||
QButtonGroup *buttonGroup;
|
||||
QMap<QString, QVector<unsigned short>> backgroundDataMap; // Map to store background data for each plane
|
||||
bool subtractBackground = false; // Flag to track if background subtraction is enabled
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -144,6 +144,32 @@
|
||||
<string>save bkg</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_loadbkg">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>420</x>
|
||||
<y>360</y>
|
||||
<width>80</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>load bkg</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="checkBox_subbkg">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<y>360</y>
|
||||
<width>77</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>sub bkg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
Binary file not shown.
@ -12,6 +12,7 @@
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QCheckBox>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QFrame>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
@ -41,6 +42,8 @@ public:
|
||||
QSpinBox *spinBox_fixedmin;
|
||||
QSpinBox *spinBox_fixedmax;
|
||||
QPushButton *pushButton_savebkg;
|
||||
QPushButton *pushButton_loadbkg;
|
||||
QCheckBox *checkBox_subbkg;
|
||||
QButtonGroup *buttonGroup;
|
||||
|
||||
void setupUi(QDialog *display)
|
||||
@ -133,6 +136,12 @@ public:
|
||||
pushButton_savebkg = new QPushButton(display);
|
||||
pushButton_savebkg->setObjectName("pushButton_savebkg");
|
||||
pushButton_savebkg->setGeometry(QRect(510, 360, 80, 24));
|
||||
pushButton_loadbkg = new QPushButton(display);
|
||||
pushButton_loadbkg->setObjectName("pushButton_loadbkg");
|
||||
pushButton_loadbkg->setGeometry(QRect(420, 360, 80, 24));
|
||||
checkBox_subbkg = new QCheckBox(display);
|
||||
checkBox_subbkg->setObjectName("checkBox_subbkg");
|
||||
checkBox_subbkg->setGeometry(QRect(330, 360, 77, 22));
|
||||
|
||||
retranslateUi(display);
|
||||
|
||||
@ -146,6 +155,8 @@ public:
|
||||
radioButtonMaxScale->setText(QCoreApplication::translate("display", "Max Y-Scale", nullptr));
|
||||
radioButtonFixedScale->setText(QCoreApplication::translate("display", "Fixed Y-Scale", nullptr));
|
||||
pushButton_savebkg->setText(QCoreApplication::translate("display", "save bkg", nullptr));
|
||||
pushButton_loadbkg->setText(QCoreApplication::translate("display", "load bkg", nullptr));
|
||||
checkBox_subbkg->setText(QCoreApplication::translate("display", "sub bkg", nullptr));
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user