v2.0.0
Loading...
Searching...
No Matches
source_morph.cpp
Go to the documentation of this file.
1//=============================================================================================================
20
21//=============================================================================================================
22// INCLUDES
23//=============================================================================================================
24
25#include "source_morph.h"
26
27//=============================================================================================================
28// QT INCLUDES
29//=============================================================================================================
30
31#include <QDebug>
32
33//=============================================================================================================
34// USED NAMESPACES
35//=============================================================================================================
36
37using namespace INVLIB;
38using namespace Eigen;
39
40//=============================================================================================================
41// DEFINE MEMBER METHODS
42//=============================================================================================================
43
44void SourceMorph::compute(const VectorXi& verticesFrom,
45 const VectorXi& verticesTo,
46 const SparseMatrix<double>& morphMap)
47{
48 if (verticesFrom.size() == 0 || verticesTo.size() == 0) {
49 qWarning() << "[SourceMorph::compute] Empty vertex vectors.";
50 return;
51 }
52
53 if (morphMap.rows() != verticesTo.size() || morphMap.cols() != verticesFrom.size()) {
54 qWarning() << "[SourceMorph::compute] Morph map dimensions mismatch:"
55 << morphMap.rows() << "x" << morphMap.cols()
56 << "but expected" << verticesTo.size() << "x" << verticesFrom.size();
57 return;
58 }
59
60 m_verticesFrom = verticesFrom;
61 m_verticesTo = verticesTo;
62 m_morphMatrix = morphMap;
63 m_bComputed = true;
64}
65
66//=============================================================================================================
67
69{
70 if (!m_bComputed) {
71 qWarning() << "[SourceMorph::apply] Morph not computed. Call compute() first.";
72 return InvSourceEstimate();
73 }
74
75 if (stcFrom.isEmpty()) {
76 qWarning() << "[SourceMorph::apply] Source estimate is empty.";
77 return InvSourceEstimate();
78 }
79
80 if (stcFrom.data.rows() != m_morphMatrix.cols()) {
81 qWarning() << "[SourceMorph::apply] Source estimate rows" << stcFrom.data.rows()
82 << "!= morph matrix cols" << m_morphMatrix.cols();
83 return InvSourceEstimate();
84 }
85
86 // Apply morph: data_to = morphMatrix * data_from
87 MatrixXd morphedData = m_morphMatrix * stcFrom.data;
88
89 InvSourceEstimate stcTo(morphedData, m_verticesTo, stcFrom.tmin, stcFrom.tstep);
90 stcTo.method = stcFrom.method;
91 stcTo.sourceSpaceType = stcFrom.sourceSpaceType;
92 stcTo.orientationType = stcFrom.orientationType;
93
94 return stcTo;
95}
Sparse morph operator that re-samples an INVLIB::InvSourceEstimate from one subject's source space on...
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
Source-space inverse-solution container with dense grid plus optional focal-dipole,...
InvSourceSpaceType sourceSpaceType
InvOrientationType orientationType
InvSourceEstimate apply(const InvSourceEstimate &stcFrom) const
Apply the morphing to a source estimate.
void compute(const Eigen::VectorXi &verticesFrom, const Eigen::VectorXi &verticesTo, const Eigen::SparseMatrix< double > &morphMap)
Compute the morphing transformation.