From 16a9381834d2c81269a553e0a1af7af752393006 Mon Sep 17 00:00:00 2001 From: johaenns Date: Mon, 29 Apr 2024 10:15:48 +0200 Subject: [PATCH] [ENH] Finalized changes to allow variable cluster size --- .../mne_scan/plugins/rtfwd/rtfwd.cpp | 19 ++++++++++++------- .../mne_scan/plugins/rtfwd/rtfwd.h | 2 ++ .../disp/viewers/fwdsettingsview.cpp | 8 ++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/applications/mne_scan/plugins/rtfwd/rtfwd.cpp b/src/applications/mne_scan/plugins/rtfwd/rtfwd.cpp index 1cf260088b..28bf0c87b4 100644 --- a/src/applications/mne_scan/plugins/rtfwd/rtfwd.cpp +++ b/src/applications/mne_scan/plugins/rtfwd/rtfwd.cpp @@ -91,6 +91,7 @@ RtFwd::RtFwd() , m_bBusy(false) , m_bDoRecomputation(false) , m_bDoClustering(true) +, m_bNClusterChanged(true) , m_bDoFwdComputation(false) { // set init values @@ -348,7 +349,6 @@ void RtFwd::onDoForwardComputation() { m_mutex.lock(); m_bDoFwdComputation = true; - // get value for number in cluster and set m_pFwdSettings->ncluster here m_mutex.unlock(); } @@ -398,6 +398,7 @@ void RtFwd::onClusterNumberChanged(int iNClusterNumber) { m_mutex.lock(); m_pFwdSettings->ncluster = iNClusterNumber; + m_bNClusterChanged = true; m_mutex.unlock(); } @@ -438,6 +439,7 @@ void RtFwd::run() bool bDoRecomputation = false; // indicate if we want to recompute bool bDoClustering = false; // indicate if we want to cluster bool bFwdReady = false; // only cluster if fwd is ready + bool bNClusterChanged = false; // Perform new clustering when cluster size changed bool bHpiConnectected = false; // only update/recompute if hpi is connected bool bDoFwdComputation = false; // compute forward if requested bool bIsInit = false; // only recompute if initial fwd solulion is calculated @@ -470,10 +472,9 @@ void RtFwd::run() m_mutex.lock(); if(!m_bDoClustering) { m_pRTFSOutput->measurementData()->setValue(pFwdSolution); - bFwdReady = false; // make sure to not cluster emit statusInformationChanged(5); //finished } - bFwdReady = true; // enable cluster + bFwdReady = true; // provide fwd for clustering if wanted m_bDoFwdComputation = false; // don't call this again if not requested bIsInit = true; // init computation finished -> recomputation possible m_mutex.unlock(); @@ -513,7 +514,7 @@ void RtFwd::run() if(!bDoClustering) { m_pRTFSOutput->measurementData()->setValue(pFwdSolution); - bFwdReady = false; + //bFwdReady = false; // doesn't seem to be necessary? bDoClustering = false anyway emit statusInformationChanged(5); //finished } } @@ -522,18 +523,22 @@ void RtFwd::run() // do clustering if requested and fwd is ready m_mutex.lock(); bDoClustering = m_bDoClustering; + bNClusterChanged = m_bNClusterChanged; m_mutex.unlock(); - if(bDoClustering && bFwdReady) { + if(bDoClustering && bFwdReady && bNClusterChanged) { emit statusInformationChanged(3); // clustering pClusteredFwd = MNEForwardSolution::SPtr(new MNEForwardSolution(pFwdSolution->cluster_forward_solution(*m_pAnnotationSet.data(), m_pFwdSettings->ncluster))); emit clusteringAvailable(pClusteredFwd->nsource); m_pRTFSOutput->measurementData()->setValue(pClusteredFwd); - bFwdReady = false; + //bFwdReady = false; // fwd remains ready, allows for reclustering. + m_mutex.lock(); + m_bNClusterChanged = false; + m_mutex.unlock(); - emit statusInformationChanged(5); //finished + emit statusInformationChanged(6); //finished } } } diff --git a/src/applications/mne_scan/plugins/rtfwd/rtfwd.h b/src/applications/mne_scan/plugins/rtfwd/rtfwd.h index 26a253651b..f4872eb434 100644 --- a/src/applications/mne_scan/plugins/rtfwd/rtfwd.h +++ b/src/applications/mne_scan/plugins/rtfwd/rtfwd.h @@ -216,6 +216,8 @@ class RTFWDSHARED_EXPORT RtFwd : public SCSHAREDLIB::AbstractAlgorithm bool m_bBusy; /**< Indicates if we have to update headposition.**/ bool m_bDoRecomputation; /**< If recomputation is activated.**/ bool m_bDoClustering; /**< If clustering is activated.**/ + bool m_bNClusterChanged; /**< Perform new clustering when cluster size changed**/ + bool m_bDoFwdComputation; /**< Do a forward computation. **/ QString m_sAtlasDir; /**< File to Atlas. */ diff --git a/src/libraries/disp/viewers/fwdsettingsview.cpp b/src/libraries/disp/viewers/fwdsettingsview.cpp index 826634b857..978673cade 100644 --- a/src/libraries/disp/viewers/fwdsettingsview.cpp +++ b/src/libraries/disp/viewers/fwdsettingsview.cpp @@ -82,7 +82,7 @@ FwdSettingsView::FwdSettingsView(const QString& sSettingsPath, // init m_pUi->m_checkBox_bDoRecomputation->setChecked(false); - m_pUi->m_checkBox_bDoClustering->setChecked(false); + m_pUi->m_checkBox_bDoClustering->setChecked(true); m_pUi->m_lineEdit_iNChan->setText(QString::number(0)); m_pUi->m_lineEdit_iNSourceSpace->setText(QString::number(0)); m_pUi->m_lineEdit_iNDipole->setText(QString::number(0)); @@ -90,6 +90,7 @@ FwdSettingsView::FwdSettingsView(const QString& sSettingsPath, m_pUi->m_lineEdit_sCoordFrame->setText("Head Space"); m_pUi->m_lineEdit_iNDipoleClustered->setText("Not Clustered"); m_pUi->m_spinBox_iNDipoleClustered->setValue(200); + m_pUi->m_spinBox_iNDipoleClustered->setKeyboardTracking(false); // load init annotation set QString t_sAtlasDir = QCoreApplication::applicationDirPath() + "/../resources/data/MNE-sample-data/subjects/sample/label"; @@ -117,7 +118,7 @@ FwdSettingsView::FwdSettingsView(const QString& sSettingsPath, this, &FwdSettingsView::onClusteringStatusChanged); connect(m_pUi->m_qPushButton_ComputeForward, &QPushButton::clicked, this, &FwdSettingsView::doForwardComputation); - connect(m_pUi->m_spinBox_iNDipoleClustered, &QSpinBox::valueChanged, + connect(m_pUi->m_spinBox_iNDipoleClustered, QOverload::of(&QSpinBox::valueChanged), this, &FwdSettingsView::clusterNumberChanged); // load settings @@ -207,6 +208,9 @@ void FwdSettingsView::setRecomputationStatus(int iStatus) } else if (iStatus == 4) { m_pUi->m_label_recomputationFeedback->setText("Not Computed"); m_pUi->m_label_recomputationFeedback->setStyleSheet("QLabel { background-color : red;}"); + } else if (iStatus == 5) { + m_pUi->m_label_recomputationFeedback->setText("Not Clustered"); + m_pUi->m_label_recomputationFeedback->setStyleSheet("QLabel { background-color : yellow;}"); } else { m_pUi->m_label_recomputationFeedback->setText("Finished"); m_pUi->m_label_recomputationFeedback->setStyleSheet("QLabel { background-color : green;}");