Files
Jungfraujoch/viewer/windows/JFJochViewerProcessingWidget.cpp
2025-06-10 18:14:04 +02:00

144 lines
5.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochViewerProcessingWidget.h"
#include <QHBoxLayout>
#include <QGroupBox>
#include <QFormLayout>
#include <QCloseEvent>
JFJochViewerProcessingWidget::JFJochViewerProcessingWidget(QWidget *parent)
: QWidget(parent) {
m_settings.enable = false;
auto centralWidget = new QWidget(this);
auto mainLayout = new QVBoxLayout(centralWidget);
auto generalGroup = new QGroupBox("Spot finding", this);
auto generalLayout = new QFormLayout(generalGroup);
m_enableCheckBox = new QCheckBox("Enable", this);
generalLayout->addRow("", m_enableCheckBox);
connect(m_enableCheckBox, &QCheckBox::toggled, [this](bool checked) {
m_settings.enable = checked;
emit settingsChanged(m_settings);
});
m_signalToNoise = new SliderPlusBox(1.0, 10.0, 0.1, 1, this);
generalLayout->addRow("Signal to Noise threshold:", m_signalToNoise);
connect(m_signalToNoise, &SliderPlusBox::valueChanged, [this] (double val) {
m_settings.signal_to_noise_threshold = val;
emit settingsChanged(m_settings);
});
m_photonCount = new SliderPlusBox(0.0, 100.0, 1.0, 0, this);
generalLayout->addRow("Photon count threshold:", m_photonCount);
connect(m_photonCount, &SliderPlusBox::valueChanged, [this] (double val) {
m_settings.photon_count_threshold = val;
emit settingsChanged(m_settings);
});
m_minPixPerSpot = new SliderPlusBox(1.0, 20.0, 1.0, 0, this);
generalLayout->addRow("Minimum pixels per spot:", m_minPixPerSpot);
connect(m_minPixPerSpot, &SliderPlusBox::valueChanged, [this] (double val) {
m_settings.min_pix_per_spot = std::lround(val);
emit settingsChanged(m_settings);
});
m_maxPixPerSpot = new SliderPlusBox(10.0, 200.0, 1.0, 0, this);
generalLayout->addRow("Maximum pixels per spot:", m_maxPixPerSpot);
connect(m_maxPixPerSpot, &SliderPlusBox::valueChanged, [this] (double val) {
m_settings.max_pix_per_spot = std::lround(val);
emit settingsChanged(m_settings);
});
m_highResolution = new SliderPlusBox(0.8, 10.0, 0.1, 1, this);
generalLayout->addRow("High resolution", m_highResolution);
connect(m_highResolution, &SliderPlusBox::valueChanged, [this] (double val) {
m_settings.high_resolution_limit = val;
emit settingsChanged(m_settings);
});
m_lowResolution = new SliderPlusBox(10.0, 100.0, 0.1, 1, this);
generalLayout->addRow("Low resolution", m_lowResolution);
connect(m_lowResolution, &SliderPlusBox::valueChanged, [this] (double val) {
m_settings.low_resolution_limit = val;
emit settingsChanged(m_settings);
});
auto processingGroup = new QGroupBox("Other steps", this);
auto processingLayout = new QFormLayout(processingGroup);
m_indexingCheckBox = new QCheckBox("Enable Indexing", this);
processingLayout->addRow("", m_indexingCheckBox);
connect(m_indexingCheckBox, &QCheckBox::toggled, [this](bool checked) {
m_settings.indexing = checked;
emit settingsChanged(m_settings);
});
m_resolutionEstimateCheckBox = new QCheckBox("Enable Resolution Estimate", this);
processingLayout->addRow("", m_resolutionEstimateCheckBox);
connect(m_resolutionEstimateCheckBox, &QCheckBox::toggled, [this](bool checked) {
m_settings.resolution_estimate = checked;
emit settingsChanged(m_settings);
});
m_quickIntegrationCheckBox = new QCheckBox("Enable Quick Integration", this);
processingLayout->addRow("", m_quickIntegrationCheckBox);
connect(m_quickIntegrationCheckBox, &QCheckBox::toggled, [this](bool checked) {
m_settings.quick_integration = checked;
emit settingsChanged(m_settings);
});
auto buttonsLayout = new QHBoxLayout();
m_resetButton = new QPushButton("Reset to Defaults", this);
buttonsLayout->addWidget(m_resetButton);
buttonsLayout->addStretch();
connect(m_resetButton, &QPushButton::clicked, this, &JFJochViewerProcessingWidget::resetToDefaults);
mainLayout->addWidget(generalGroup);
mainLayout->addWidget(processingGroup);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
updateUiFromSettings();
}
void JFJochViewerProcessingWidget::updateUiFromSettings() {
m_enableCheckBox->setChecked(m_settings.enable);
m_signalToNoise->setValue(m_settings.signal_to_noise_threshold);
m_photonCount->setValue(std::lround(m_settings.photon_count_threshold));
m_minPixPerSpot->setValue(std::lround(m_settings.min_pix_per_spot));
m_maxPixPerSpot->setValue(std::lround(m_settings.max_pix_per_spot));
m_highResolution->setValue(m_settings.high_resolution_limit);
m_lowResolution->setValue(m_settings.low_resolution_limit);
m_indexingCheckBox->setChecked(m_settings.indexing);
m_resolutionEstimateCheckBox->setChecked(m_settings.resolution_estimate);
m_quickIntegrationCheckBox->setChecked(m_settings.quick_integration);
}
void JFJochViewerProcessingWidget::resetToDefaults() {
// Reset to default values
m_settings = SpotFindingSettings();
m_settings.enable = false;
updateUiFromSettings();
emit settingsChanged(m_settings);
}