Skip to content

Commit

Permalink
[ENH] Finalized changes to allow variable cluster size
Browse files Browse the repository at this point in the history
  • Loading branch information
johaenns authored and LorenzE committed Apr 30, 2024
1 parent d3ed4d0 commit 16a9381
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/applications/mne_scan/plugins/rtfwd/rtfwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ RtFwd::RtFwd()
, m_bBusy(false)
, m_bDoRecomputation(false)
, m_bDoClustering(true)
, m_bNClusterChanged(true)
, m_bDoFwdComputation(false)
{
// set init values
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -398,6 +398,7 @@ void RtFwd::onClusterNumberChanged(int iNClusterNumber)
{
m_mutex.lock();
m_pFwdSettings->ncluster = iNClusterNumber;
m_bNClusterChanged = true;
m_mutex.unlock();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/applications/mne_scan/plugins/rtfwd/rtfwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 6 additions & 2 deletions src/libraries/disp/viewers/fwdsettingsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ 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));
m_pUi->m_lineEdit_sSourceOri->setText("fixed");
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";
Expand Down Expand Up @@ -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<int>::of(&QSpinBox::valueChanged),
this, &FwdSettingsView::clusterNumberChanged);

// load settings
Expand Down Expand Up @@ -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;}");
Expand Down

0 comments on commit 16a9381

Please sign in to comment.