From ab72e3ab6fcef7c6b0d77fe47381a134580b8de8 Mon Sep 17 00:00:00 2001 From: RDoerfel Date: Fri, 12 Mar 2021 15:03:24 +0100 Subject: [PATCH 1/3] Fix:use abs value to determine max channel --- libraries/inverse/hpiFit/hpifit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/inverse/hpiFit/hpifit.cpp b/libraries/inverse/hpiFit/hpifit.cpp index 5fcc9f2c0d4..6592f9e7f9e 100644 --- a/libraries/inverse/hpiFit/hpifit.cpp +++ b/libraries/inverse/hpiFit/hpifit.cpp @@ -256,7 +256,7 @@ void HPIFit::fitHPI(const MatrixXd& t_mat, for (int j = 0; j < iNumCoils; j++) { int iChIdx = 0; VectorXd::Index indMax; - matAmp.col(j).maxCoeff(&indMax); + matAmp.col(j).cwiseAbs().maxCoeff(&indMax); if(indMax < m_vecInnerind.size()) { iChIdx = m_vecInnerind.at(indMax); } From c5ddb63e08f3b1bbd1021a4525c3f2f17439f7f3 Mon Sep 17 00:00:00 2001 From: RDoerfel Date: Fri, 12 Mar 2021 17:59:36 +0100 Subject: [PATCH 2/3] WIP:update projectors all the time and apply comp/proj seperately --- applications/mne_scan/plugins/hpi/hpi.cpp | 18 ++++++++++++------ applications/mne_scan/plugins/hpi/hpi.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/applications/mne_scan/plugins/hpi/hpi.cpp b/applications/mne_scan/plugins/hpi/hpi.cpp index 1a4758b88fb..4e09705e8f4 100644 --- a/applications/mne_scan/plugins/hpi/hpi.cpp +++ b/applications/mne_scan/plugins/hpi/hpi.cpp @@ -287,12 +287,14 @@ void Hpi::updateProjections() || m_matCompProjectors.rows() == 0 || m_matCompProjectors.cols() == 0) { m_iNumberBadChannels = m_pFiffInfo->bads.size(); - } else { + } /*else { m_mutex.unlock(); return; - } + }*/ m_mutex.unlock(); + qDebug() << "updating projectors"; + Eigen::MatrixXd matProjectors = Eigen::MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size()); Eigen::MatrixXd matComp = Eigen::MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size()); @@ -324,6 +326,7 @@ void Hpi::updateProjections() } m_mutex.lock(); + m_matProjectors = matProjectors; m_matCompProjectors = matProjectors * matComp; m_mutex.unlock(); } @@ -493,6 +496,7 @@ void Hpi::run() m_mutex.unlock(); MatrixXd matDataMerged(m_pFiffInfo->chs.size(), int(m_pFiffInfo->sfreq/iNumberOfFitsPerSecond)); + MatrixXd matDataProj(m_pFiffInfo->chs.size(), int(m_pFiffInfo->sfreq/iNumberOfFitsPerSecond)); while(!isInterruptionRequested()) { m_mutex.lock(); @@ -522,8 +526,9 @@ void Hpi::run() m_mutex.lock(); if(m_bDoFreqOrder) { // find correct frequencie order if requested - HPI.findOrder(matDataMerged, - m_matCompProjectors, + matDataProj = m_matCompProjectors * matDataMerged; + HPI.findOrder(matDataProj, + m_matProjectors, fitResult.devHeadTrans, m_vCoilFreqs, fitResult.errorDistances, @@ -536,8 +541,9 @@ void Hpi::run() // Perform actual fitting m_mutex.lock(); - HPI.fitHPI(matDataMerged, - m_matCompProjectors, + matDataProj = m_matCompProjectors * matDataMerged; + HPI.fitHPI(matDataProj, + m_matProjectors, fitResult.devHeadTrans, m_vCoilFreqs, fitResult.errorDistances, diff --git a/applications/mne_scan/plugins/hpi/hpi.h b/applications/mne_scan/plugins/hpi/hpi.h index d36a9d13849..d1b064b1509 100644 --- a/applications/mne_scan/plugins/hpi/hpi.h +++ b/applications/mne_scan/plugins/hpi/hpi.h @@ -268,6 +268,7 @@ class HPISHARED_EXPORT Hpi : public SCSHAREDLIB::AbstractAlgorithm Eigen::MatrixXd m_matData; /**< The last data block.*/ Eigen::MatrixXd m_matCompProjectors; /**< Holds the matrix with the SSP and compensator projectors.*/ + Eigen::MatrixXd m_matProjectors; /**< Holds the matrix with the SSP.*/ QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ QSharedPointer m_pCircularBuffer; /**< Holds incoming raw data. */ From 3c216ce023ea81277c0cd02216d6bb136322e278 Mon Sep 17 00:00:00 2001 From: RDoerfel Date: Sat, 13 Mar 2021 17:54:38 +0100 Subject: [PATCH 3/3] Enh:only call updateProjectors() if necessary --- applications/mne_scan/plugins/hpi/hpi.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/applications/mne_scan/plugins/hpi/hpi.cpp b/applications/mne_scan/plugins/hpi/hpi.cpp index 4e09705e8f4..5afedafef44 100644 --- a/applications/mne_scan/plugins/hpi/hpi.cpp +++ b/applications/mne_scan/plugins/hpi/hpi.cpp @@ -191,7 +191,13 @@ void Hpi::update(SCMEASLIB::Measurement::SPtr pMeasurement) // Check if data is present if(pRTMSA->getMultiSampleArray().size() > 0) { //If bad channels changed, recalcluate projectors - updateProjections(); + if(m_iNumberBadChannels != m_pFiffInfo->bads.size() + || m_matCompProjectors.rows() == 0 + || m_matCompProjectors.cols() == 0) { + updateProjections(); + m_iNumberBadChannels = m_pFiffInfo->bads.size(); + } + m_mutex.lock(); bool bDoSingleHpi = m_bDoSingleHpi; @@ -282,19 +288,6 @@ void Hpi::initPluginControlWidgets() void Hpi::updateProjections() { if(m_pFiffInfo) { - m_mutex.lock(); - if(m_iNumberBadChannels != m_pFiffInfo->bads.size() - || m_matCompProjectors.rows() == 0 - || m_matCompProjectors.cols() == 0) { - m_iNumberBadChannels = m_pFiffInfo->bads.size(); - } /*else { - m_mutex.unlock(); - return; - }*/ - m_mutex.unlock(); - - qDebug() << "updating projectors"; - Eigen::MatrixXd matProjectors = Eigen::MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size()); Eigen::MatrixXd matComp = Eigen::MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size()); @@ -363,7 +356,7 @@ void Hpi::onAllowedRotationChanged(double dAllowedRotation) void Hpi::onDigitizersChanged(const QList& lDigitzers, const QString& sFilePath) -{ +{ m_mutex.lock(); if(m_pFiffInfo) { m_pFiffInfo->dig = lDigitzers;