42 #include "ui_hpisettingsview.h"
52 #include <QFileDialog>
53 #include <QMessageBox>
55 #include <QJsonObject>
66 using namespace DISPLIB;
67 using namespace FIFFLIB;
77 , m_pUi(new Ui::HpiSettingsViewWidget)
82 connect(
m_pUi->m_pushButton_loadDigitizers, &QPushButton::released,
84 connect(
m_pUi->m_pushButton_doFreqOrder, &QPushButton::clicked,
86 connect(
m_pUi->m_pushButton_doSingleFit, &QPushButton::clicked,
88 connect(
m_pUi->m_tableWidget_Frequencies, &QTableWidget::cellChanged,
90 connect(
m_pUi->m_pushButton_addCoil, &QPushButton::clicked,
92 connect(
m_pUi->m_pushButton_removeCoil, &QPushButton::clicked,
94 connect(
m_pUi->m_checkBox_useSSP, &QCheckBox::clicked,
96 connect(
m_pUi->m_checkBox_useComp, &QCheckBox::clicked,
98 connect(
m_pUi->m_checkBox_continousHPI, &QCheckBox::clicked,
100 connect(
m_pUi->m_spinBox_samplesToFit, QOverload<int>::of(&QSpinBox::valueChanged),
102 connect(
m_pUi->m_doubleSpinBox_maxHPIContinousDist,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
104 connect(
m_pUi->m_doubleSpinBox_moveThreshold,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
106 connect(
m_pUi->m_doubleSpinBox_rotThreshold,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
108 connect(
m_pUi->comboBox_coilPreset,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
119 HpiSettingsView::~HpiSettingsView()
129 const double dMeanErrorDist)
134 for(
int i = 0; i < vError.size(); ++i) {
135 if(i < m_pUi->m_tableWidget_results->rowCount()) {
136 sGof = QString::number(vError[i]*1000,
'f',2)+QString(
" mm");
137 m_pUi->m_tableWidget_results->item(i, 1)->setText(sGof);
141 m_pUi->m_label_averagedFitError->setText(QString::number(dMeanErrorDist*1000,
'f',2)+QString(
" mm"));
144 if(dMeanErrorDist*1000 >
m_pUi->m_doubleSpinBox_maxHPIContinousDist->value()) {
145 m_pUi->m_label_fitFeedback->setText(
"Last fit: Bad");
146 m_pUi->m_label_fitFeedback->setStyleSheet(
"QLabel { background-color : red;}");
148 m_pUi->m_label_fitFeedback->setText(
"Last fit: Good");
149 m_pUi->m_label_fitFeedback->setStyleSheet(
"QLabel { background-color : green;}");
156 const double dMeanGof)
159 QString sGof(
"00.00");
161 for(
int i = 0; i < vGoF.size(); ++i) {
162 if(i < m_pUi->m_tableWidget_results->rowCount()) {
163 sGof = QString::number(vGoF[i]*100,
'f',2)+QString(
" %");
164 m_pUi->m_tableWidget_results->item(i, 2)->setText(sGof);
168 m_pUi->m_average_gof_set->setText(QString::number(dMeanGof*100,
'f',2)+QString(
" %"));
177 m_pUi->m_qLineEdit_moveResult->setText(QString::number(dMovement*1000,
'f',2) + QString(
" mm"));
178 m_pUi->m_qLineEdit_rotResult->setText(QString::number(dRotation,
'f',2) + QString(
" °"));
180 if(dMovement*1000 >
m_pUi->m_doubleSpinBox_moveThreshold->value() || dRotation >
m_pUi->m_doubleSpinBox_rotThreshold->value()) {
181 m_pUi->m_label_movementFeedback->setText(
"Big");
182 m_pUi->m_label_movementFeedback->setStyleSheet(
"QLabel { background-color : red;}");
184 m_pUi->m_label_movementFeedback->setText(
"Small");
185 m_pUi->m_label_movementFeedback->setStyleSheet(
"QLabel { background-color : green;}");
193 return m_pUi->m_checkBox_useSSP->isChecked();
200 return m_pUi->m_checkBox_useComp->isChecked();
207 return m_pUi->m_doubleSpinBox_maxHPIContinousDist->value();
214 return m_pUi->m_doubleSpinBox_moveThreshold->value();
221 return m_pUi->m_doubleSpinBox_rotThreshold->value();
228 return m_pUi->m_checkBox_continousHPI->isChecked();
235 return m_pUi->m_spinBox_samplesToFit->value();
246 QSettings settings(
"MNECPP");
248 settings.setValue(
m_sSettingsPath + QString(
"/HpiSettingsView/coilFreqs"),
251 settings.setValue(
m_sSettingsPath + QString(
"/HpiSettingsView/useSSP"),
252 QVariant::fromValue(
m_pUi->m_checkBox_useSSP->isChecked()));
254 settings.setValue(
m_sSettingsPath + QString(
"/HpiSettingsView/useCOMP"),
255 QVariant::fromValue(
m_pUi->m_checkBox_useComp->isChecked()));
257 settings.setValue(
m_sSettingsPath + QString(
"/HpiSettingsView/continousHPI"),\
258 QVariant::fromValue(
m_pUi->m_checkBox_continousHPI->isChecked()));
260 settings.setValue(
m_sSettingsPath + QString(
"/HpiSettingsView/maxError"),
261 QVariant::fromValue(
m_pUi->m_doubleSpinBox_maxHPIContinousDist->value()));
263 settings.setValue(
m_sSettingsPath + QString(
"/HpiSettingsView/fittingWindowSize"),
264 QVariant::fromValue(
m_pUi->m_spinBox_samplesToFit->value()));
275 QSettings settings(
"MNECPP");
276 QVariant defaultData;
282 m_pUi->m_checkBox_useSSP->setChecked(settings.value(
m_sSettingsPath + QString(
"/HpiSettingsView/useSSP"),
false).toBool());
283 m_pUi->m_checkBox_useComp->setChecked(settings.value(
m_sSettingsPath + QString(
"/HpiSettingsView/useCOMP"),
false).toBool());
284 m_pUi->m_checkBox_continousHPI->setChecked(settings.value(
m_sSettingsPath + QString(
"/HpiSettingsView/continousHPI"),
false).toBool());
285 m_pUi->m_doubleSpinBox_maxHPIContinousDist->setValue(settings.value(
m_sSettingsPath + QString(
"/HpiSettingsView/maxError"), 10.0).toDouble());
286 m_pUi->m_spinBox_samplesToFit->setValue(settings.value(
m_sSettingsPath + QString(
"/HpiSettingsView/fittingWindowSize"), 300).toInt());
294 case GuiMode::Clinical:
306 case ProcessingMode::Offline:
318 QString fileName_HPI = QFileDialog::getOpenFileName(
this,
319 tr(
"Open digitizer file"),
321 tr(
"Fiff file (*.fif)"));
323 if(!fileName_HPI.isEmpty()) {
324 m_pUi->m_lineEdit_filePath->setText(fileName_HPI);
328 if (!fileName_HPI.isEmpty()) {
329 fileName_HPI = fileName_HPI.trimmed();
330 QFileInfo checkFile(fileName_HPI);
332 if (checkFile.exists() && checkFile.isFile()) {
334 m_pUi->m_checkBox_continousHPI->setChecked(
false);
338 msgBox.setText(
"File could not be loaded!");
354 if(QTableWidgetItem *pItem =
m_pUi->m_tableWidget_Frequencies->item(row, col)) {
355 if(pItem->text() ==
"none") {
369 if(
m_pUi->m_tableWidget_Frequencies->rowCount() + 1 >
m_pUi->m_label_numberLoadedCoils->text().toInt()) {
371 msgBox.setText(
"Cannot add more HPI coils. Not enough digitzed HPI coils loaded.");
377 m_pUi->m_tableWidget_Frequencies->insertRow(
m_pUi->m_tableWidget_Frequencies->rowCount());
378 QTableWidgetItem* pTableItemA =
new QTableWidgetItem(QString::number(
m_pUi->m_tableWidget_Frequencies->rowCount()));
379 pTableItemA->setFlags(Qt::ItemIsEnabled);
380 m_pUi->m_tableWidget_Frequencies->setItem(
m_pUi->m_tableWidget_Frequencies->rowCount()-1,
386 m_pUi->m_tableWidget_Frequencies->setItem(
m_pUi->m_tableWidget_Frequencies->rowCount()-1,
388 new QTableWidgetItem(QString::number(
m_vCoilFreqs.at(
m_pUi->m_tableWidget_Frequencies->rowCount()-1))));
390 m_pUi->m_tableWidget_Frequencies->setItem(
m_pUi->m_tableWidget_Frequencies->rowCount()-1,
392 new QTableWidgetItem(
"none"));
397 m_pUi->m_tableWidget_results->insertRow(
m_pUi->m_tableWidget_results->rowCount());
398 QTableWidgetItem* pTableItemB =
new QTableWidgetItem(QString::number(
m_pUi->m_tableWidget_Frequencies->rowCount()));
399 pTableItemB->setFlags(Qt::ItemIsEnabled);
400 m_pUi->m_tableWidget_results->setItem(
m_pUi->m_tableWidget_results->rowCount()-1,
405 QTableWidgetItem* pTableItemC =
new QTableWidgetItem(
"0mm");
406 pTableItemC->setFlags(Qt::ItemIsEnabled);
407 m_pUi->m_tableWidget_results->setItem(
m_pUi->m_tableWidget_results->rowCount()-1,
412 QTableWidgetItem* pTableItemD =
new QTableWidgetItem(
"00.00");
413 pTableItemD->setFlags(Qt::ItemIsEnabled);
414 m_pUi->m_tableWidget_results->setItem(
m_pUi->m_tableWidget_results->rowCount()-1,
425 int row =
m_pUi->m_tableWidget_Frequencies->currentRow();
429 m_pUi->m_tableWidget_Frequencies->removeRow(row);
431 for (
int i = 0; i <
m_pUi->m_tableWidget_Frequencies->rowCount(); ++i) {
432 m_pUi->m_tableWidget_Frequencies->item(i, 0)->setText(QString::number(i+1));
435 m_pUi->m_tableWidget_results->removeRow(row);
437 for (
int i = 0; i <
m_pUi->m_tableWidget_results->rowCount(); ++i) {
438 m_pUi->m_tableWidget_results->item(i, 0)->setText(QString::number(i+1));
451 QFile t_fileDig(fileName);
473 qint16 numFiducials = 0;
475 qint16 numAdditional = 0;
477 for(
int i = 0; i < digSet.
size(); ++i) {
478 switch(digSet[i].kind) {
479 case FIFFV_POINT_HPI:
485 case FIFFV_POINT_CARDINAL:
488 case FIFFV_POINT_EEG:
491 case FIFFV_POINT_EXTRA:
498 m_pUi->m_label_numberLoadedCoils->setNum(numHPI);
499 m_pUi->m_label_numberLoadedFiducials->setNum(numFiducials);
500 m_pUi->m_label_numberLoadedEEG->setNum(numEEG);
501 m_pUi->m_label_numberLoadedAdditional->setNum(numAdditional);
527 m_pUi->m_tableWidget_Frequencies->insertRow(
m_pUi->m_tableWidget_Frequencies->rowCount());
528 QTableWidgetItem* pTableItemA =
new QTableWidgetItem(QString::number(
m_pUi->m_tableWidget_Frequencies->rowCount()));
529 pTableItemA->setFlags(Qt::ItemIsEnabled);
530 m_pUi->m_tableWidget_Frequencies->setItem(
m_pUi->m_tableWidget_Frequencies->rowCount()-1,
535 m_pUi->m_tableWidget_Frequencies->setItem(
m_pUi->m_tableWidget_Frequencies->rowCount()-1,
537 new QTableWidgetItem(QString::number(iCoilFreq)));
545 m_pUi->m_tableWidget_results->insertRow(
m_pUi->m_tableWidget_results->rowCount());
546 QTableWidgetItem* pTableItemB =
new QTableWidgetItem(QString::number(
m_pUi->m_tableWidget_Frequencies->rowCount()));
547 pTableItemB->setFlags(Qt::ItemIsEnabled);
548 m_pUi->m_tableWidget_results->setItem(
m_pUi->m_tableWidget_results->rowCount()-1,
553 QTableWidgetItem* pTableItemC =
new QTableWidgetItem(
"0mm");
554 pTableItemC->setFlags(Qt::ItemIsEnabled);
555 m_pUi->m_tableWidget_results->setItem(
m_pUi->m_tableWidget_results->rowCount()-1,
560 QTableWidgetItem* pTableItemD =
new QTableWidgetItem(
"00.00%");
561 pTableItemD->setFlags(Qt::ItemIsEnabled);
562 m_pUi->m_tableWidget_results->setItem(
m_pUi->m_tableWidget_results->rowCount()-1,
571 m_pUi->m_tableWidget_Frequencies->clear();
572 m_pUi->m_tableWidget_Frequencies->setRowCount(0);
573 m_pUi->m_tableWidget_Frequencies->setHorizontalHeaderItem(0,
new QTableWidgetItem(
"#Coil"));
574 m_pUi->m_tableWidget_Frequencies->setHorizontalHeaderItem(1,
new QTableWidgetItem(
"Frequency (Hz)"));
576 m_pUi->m_tableWidget_results->clear();
577 m_pUi->m_tableWidget_results->setRowCount(0);
578 m_pUi->m_tableWidget_results->setHorizontalHeaderItem(0,
new QTableWidgetItem(
"#Coil"));
579 m_pUi->m_tableWidget_results->setHorizontalHeaderItem(1,
new QTableWidgetItem(
"Error"));
580 m_pUi->m_tableWidget_results->setHorizontalHeaderItem(2,
new QTableWidgetItem(
"GoF"));
595 QFile inFile(sFilePath);
596 if (inFile.open(QIODevice::ReadOnly)){
597 QByteArray inArray = inFile.readAll();
607 QJsonArray presetData =
m_CoilPresets.object()[QString::number(iNumCoils)].toArray();
616 m_pUi->comboBox_coilPreset->clear();
617 m_pUi->comboBox_coilPreset->addItem(
"Load preset");
619 for(
const auto& entry : presetData){
620 QString name = entry.toObject()[
"name"].toString();
623 for (
const auto& coil : entry.toObject()[
"coils"].toArray()){
624 data.append(coil.toInt());
627 m_pUi->comboBox_coilPreset->addItem(name, QVariant::fromValue(data));
635 if (iCoilPresetIndex < (
m_pUi->comboBox_coilPreset->count())){
636 auto coilFreqData =
m_pUi->comboBox_coilPreset->itemData(iCoilPresetIndex);
637 if (!coilFreqData.isNull() && coilFreqData.canConvert<QVector<int>>()){