v2.0.0
Loading...
Searching...
No Matches
mne_inverse_operator.h
Go to the documentation of this file.
1//=============================================================================================================
37
38#ifndef MNE_INVERSE_OPERATOR_H
39#define MNE_INVERSE_OPERATOR_H
40
41//=============================================================================================================
42// INCLUDES
43//=============================================================================================================
44
45#include "mne_global.h"
46#include "mne_source_spaces.h"
48
49#include <fiff/fiff_types.h>
51#include <fiff/fiff_proj.h>
52#include <fiff/fiff_cov.h>
53#include <fiff/fiff_info.h>
54
55//=============================================================================================================
56// EIGEN INCLUDES
57//=============================================================================================================
58
59#include <Eigen/Core>
60
61//=============================================================================================================
62// QT INCLUDES
63//=============================================================================================================
64
65#include <QList>
66
67//=============================================================================================================
68// FORWARD DECLARATIONS
69//=============================================================================================================
70
71namespace FSLIB
72{
73 class FsLabel;
74}
75
76//=============================================================================================================
77// DEFINE NAMESPACE MNELIB
78//=============================================================================================================
79
80namespace MNELIB
81{
82
83//=========================================================================================================
88{
89 Eigen::VectorXi roiIdx;
90 Eigen::MatrixXd ctrs;
91 Eigen::VectorXd sumd;
92 Eigen::MatrixXd D;
93 qint32 iLabelIdxOut;
94};
95
96//=========================================================================================================
101{
102 Eigen::MatrixXd matRoiMT;
103 Eigen::MatrixXd matRoiMTOrig;
104 qint32 nClusters;
105 Eigen::VectorXi idcs;
106 qint32 iLabelIdxIn;
107 QString sDistMeasure;
108
114 {
115 const QString distMeasure = sDistMeasure.isEmpty()
116 ? QStringLiteral("cityblock")
117 : sDistMeasure;
118
119 RegionMTOut out;
120 UTILSLIB::KMeans kMeans(distMeasure, QStringLiteral("sample"), 5);
122 out.roiIdx, out.ctrs, out.sumd, out.D);
124 return out;
125 }
126};
127
128//=============================================================================================================
138{
139public:
140 typedef QSharedPointer<MNEInverseOperator> SPtr;
141 typedef QSharedPointer<const MNEInverseOperator> ConstSPtr;
142
143 //=========================================================================================================
148
149 //=========================================================================================================
155 explicit MNEInverseOperator(QIODevice& p_IODevice);
156
157 //=========================================================================================================
170 const MNEForwardSolution& forward,
171 const FIFFLIB::FiffCov& noiseCov,
172 float loose = 0.2f,
173 float depth = 0.8f,
174 bool fixed = false,
175 bool limit_depth_chs = true);
176
177 //=========================================================================================================
184
185 //=========================================================================================================
190
191 //=========================================================================================================
208 bool assemble_kernel(const FSLIB::FsLabel &label,
209 const QString &method,
210 bool pick_normal,
211 Eigen::MatrixXd &K,
212 Eigen::SparseMatrix<double> &noise_norm,
213 QList<Eigen::VectorXi> &vertno);
214
215 //=========================================================================================================
223 bool check_ch_names(const FIFFLIB::FiffInfo &info) const;
224
225 //=========================================================================================================
239 Eigen::MatrixXd cluster_kernel(const FSLIB::FsAnnotationSet &annotationSet,
240 qint32 clusterSize,
241 Eigen::MatrixXd &D,
242 const QString &method = QStringLiteral("cityblock")) const;
243
244 //=========================================================================================================
249 inline Eigen::MatrixXd& getKernel();
250
251 //=========================================================================================================
256 inline Eigen::MatrixXd getKernel() const;
257
258 //=========================================================================================================
263 inline bool isFixedOrient() const;
264
265 //=========================================================================================================
283 MNEForwardSolution forward,
284 const FIFFLIB::FiffCov& noiseCov,
285 float loose = 0.2f,
286 float depth = 0.8f,
287 bool fixed = false,
288 bool limit_depth_chs = true);
289
290 //=========================================================================================================
306 float lambda2,
307 bool dSPM,
308 bool sLORETA = false) const;
309
310 //=========================================================================================================
319 static bool read_inverse_operator(QIODevice &p_IODevice, MNEInverseOperator& inv);
320
321 //=========================================================================================================
327 void write(QIODevice &p_IODevice);
328
329 //=========================================================================================================
335 void writeToStream(FIFFLIB::FiffStream* p_pStream);
336
337 //=========================================================================================================
346 friend std::ostream& operator<<(std::ostream& out, const MNEInverseOperator &inv);
347
348public:
355 Eigen::MatrixXf source_nn;
356 Eigen::VectorXd sing;
368 QList<FIFFLIB::FiffProj> projs;
369 Eigen::MatrixXd proj;
370 Eigen::MatrixXd whitener;
371 Eigen::VectorXd reginv;
372 Eigen::SparseMatrix<double> noisenorm;
373
374private:
375 Eigen::MatrixXd m_K;
376};
377
378//=============================================================================================================
379// INLINE DEFINITIONS
380//=============================================================================================================
381
382inline Eigen::MatrixXd& MNEInverseOperator::getKernel()
383{
384 return m_K;
385}
386
387//=============================================================================================================
388
389inline Eigen::MatrixXd MNEInverseOperator::getKernel() const
390{
391 return m_K;
392}
393
394//=============================================================================================================
395
397{
398 return this->source_ori == FIFFV_MNE_FIXED_ORI;
399}
400
401//=============================================================================================================
402
403inline std::ostream& operator<<(std::ostream& out, const MNEInverseOperator &inv)
404{
405 out << "#### MNE Inverse Operator ####\n"
406 << " methods: " << inv.methods << '\n'
407 << " source_ori: " << inv.source_ori << '\n'
408 << " nsource: " << inv.nsource << '\n'
409 << " nchan: " << inv.nchan << '\n'
410 << " coord_frame: " << inv.coord_frame << '\n'
411 << " eigen_leads: " << *inv.eigen_leads << '\n'
412 << " eigen_fields:" << *inv.eigen_fields << '\n';
413 return out;
414}
415} // NAMESPACE
416
417#ifndef metatype_mneinverseoperatorsptr
418#define metatype_mneinverseoperatorsptr
419Q_DECLARE_METATYPE(QSharedPointer<MNELIB::MNEInverseOperator>);
420#endif
421
422#ifndef metatype_mneinverseoperators
423#define metatype_mneinverseoperators
425#endif
426
427#endif // MNE_INVERSE_OPERATOR_H
FiffInfo class declaration.
#define FIFFV_MNE_FIXED_ORI
FiffNamedMatrix class declaration.
FiffProj class declaration.
FiffCov class declaration.
Old fiff_type declarations - replace them.
MNESourceSpaces class declaration.
Q_DECLARE_METATYPE(QSharedPointer< MNELIB::MNEInverseOperator >)
mne library export/import macros.
#define MNESHARED_EXPORT
Definition mne_global.h:52
MNEForwardSolution class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
std::ostream & operator<<(std::ostream &out, const MNELIB::MNEForwardSolution &p_MNEForwardSolution)
FreeSurfer surface and annotation I/O.
qint32 fiff_int_t
Definition fiff_types.h:89
Coordinate transformation description.
covariance data
Definition fiff_cov.h:85
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:91
FIFF measurement file information.
Definition fiff_info.h:86
light measurement info
QSharedDataPointer< FiffNamedMatrix > SDPtr
FIFF File I/O routines.
Freesurfer/MNE label.
Definition fs_label.h:81
K-Means Clustering.
Definition kmeans.h:109
bool calculate(const Eigen::MatrixXd &X, qint32 kClusters, Eigen::VectorXi &idx, Eigen::MatrixXd &C, Eigen::VectorXd &sumD, Eigen::MatrixXd &D)
Definition kmeans.cpp:140
Output of a multi-threaded KMeans clustering step for a single cortical region.
Input parameters for multi-threaded KMeans clustering on a single cortical region.
Eigen::MatrixXd matRoiMTOrig
Eigen::MatrixXd matRoiMT
RegionMTOut cluster() const
Run KMeans clustering on this region.
MNE-style inverse operator.
MNEInverseOperator()
Constructs an empty inverse operator with invalid sentinel values.
FIFFLIB::FiffCov::SDPtr fmri_prior
QSharedPointer< const MNEInverseOperator > ConstSPtr
QSharedPointer< MNEInverseOperator > SPtr
Eigen::MatrixXd cluster_kernel(const FSLIB::FsAnnotationSet &annotationSet, qint32 clusterSize, Eigen::MatrixXd &D, const QString &method=QStringLiteral("cityblock")) const
Cluster the inverse kernel by cortical parcellation.
QList< FIFFLIB::FiffProj > projs
Eigen::SparseMatrix< double > noisenorm
FIFFLIB::FiffCov::SDPtr orient_prior
static MNEInverseOperator make_inverse_operator(const FIFFLIB::FiffInfo &info, MNEForwardSolution forward, const FIFFLIB::FiffCov &noiseCov, float loose=0.2f, float depth=0.8f, bool fixed=false, bool limit_depth_chs=true)
Assemble an inverse operator from a forward solution and noise covariance.
friend std::ostream & operator<<(std::ostream &out, const MNEInverseOperator &inv)
Stream-output operator for diagnostic printing.
FIFFLIB::FiffNamedMatrix::SDPtr eigen_leads
bool check_ch_names(const FIFFLIB::FiffInfo &info) const
Verify that inverse-operator channels are present in the measurement info.
FIFFLIB::FiffCoordTrans mri_head_t
MNEInverseOperator prepare_inverse_operator(qint32 nave, float lambda2, bool dSPM, bool sLORETA=false) const
Prepare the inverse operator for source estimation.
FIFFLIB::FiffCov::SDPtr depth_prior
void write(QIODevice &p_IODevice)
Write the inverse operator to a FIFF file.
Eigen::MatrixXd & getKernel()
Access the most recently assembled kernel (mutable).
bool assemble_kernel(const FSLIB::FsLabel &label, const QString &method, bool pick_normal, Eigen::MatrixXd &K, Eigen::SparseMatrix< double > &noise_norm, QList< Eigen::VectorXi > &vertno)
Assemble the inverse kernel matrix.
void writeToStream(FIFFLIB::FiffStream *p_pStream)
Write the inverse operator into an already-open FIFF stream.
~MNEInverseOperator()
Destructor.
FIFFLIB::FiffCov::SDPtr noise_cov
FIFFLIB::FiffCov::SDPtr source_cov
static bool read_inverse_operator(QIODevice &p_IODevice, MNEInverseOperator &inv)
Read an inverse operator from a FIFF file.
bool isFixedOrient() const
Check whether the inverse operator uses fixed source orientations.
FIFFLIB::FiffNamedMatrix::SDPtr eigen_fields
Source Space descritpion.