v2.0.0
Loading...
Searching...
No Matches
mne_inverse_operator.h
Go to the documentation of this file.
1//=============================================================================================================
27
28#ifndef MNE_INVERSE_OPERATOR_H
29#define MNE_INVERSE_OPERATOR_H
30
31//=============================================================================================================
32// INCLUDES
33//=============================================================================================================
34
35#include "mne_global.h"
36#include "mne_source_spaces.h"
38
39#include <fiff/fiff_types.h>
41#include <fiff/fiff_proj.h>
42#include <fiff/fiff_cov.h>
43#include <fiff/fiff_info.h>
44
45//=============================================================================================================
46// EIGEN INCLUDES
47//=============================================================================================================
48
49#include <Eigen/Core>
50
51//=============================================================================================================
52// QT INCLUDES
53//=============================================================================================================
54
55#include <QList>
56
57//=============================================================================================================
58// FORWARD DECLARATIONS
59//=============================================================================================================
60
61namespace FSLIB
62{
63 class FsLabel;
64}
65
66//=============================================================================================================
67// DEFINE NAMESPACE MNELIB
68//=============================================================================================================
69
70namespace MNELIB
71{
72
73//=========================================================================================================
78{
79 Eigen::VectorXi roiIdx;
80 Eigen::MatrixXd ctrs;
81 Eigen::VectorXd sumd;
82 Eigen::MatrixXd D;
83 qint32 iLabelIdxOut;
84};
85
86//=========================================================================================================
91{
92 Eigen::MatrixXd matRoiMT;
93 Eigen::MatrixXd matRoiMTOrig;
94 qint32 nClusters;
95 Eigen::VectorXi idcs;
96 qint32 iLabelIdxIn;
97 QString sDistMeasure;
98
104 {
105 const QString distMeasure = sDistMeasure.isEmpty()
106 ? QStringLiteral("cityblock")
107 : sDistMeasure;
108
109 RegionMTOut out;
110 UTILSLIB::KMeans kMeans(distMeasure, QStringLiteral("sample"), 5);
112 out.roiIdx, out.ctrs, out.sumd, out.D);
114 return out;
115 }
116};
117
118//=============================================================================================================
128{
129public:
130 typedef QSharedPointer<MNEInverseOperator> SPtr;
131 typedef QSharedPointer<const MNEInverseOperator> ConstSPtr;
132
133 //=========================================================================================================
138
139 //=========================================================================================================
145 explicit MNEInverseOperator(QIODevice& p_IODevice);
146
147 //=========================================================================================================
160 const MNEForwardSolution& forward,
161 const FIFFLIB::FiffCov& noiseCov,
162 float loose = 0.2f,
163 float depth = 0.8f,
164 bool fixed = false,
165 bool limit_depth_chs = true);
166
167 //=========================================================================================================
174
175 //=========================================================================================================
180
181 //=========================================================================================================
198 bool assemble_kernel(const FSLIB::FsLabel &label,
199 const QString &method,
200 bool pick_normal,
201 Eigen::MatrixXd &K,
202 Eigen::SparseMatrix<double> &noise_norm,
203 QList<Eigen::VectorXi> &vertno);
204
205 //=========================================================================================================
213 bool check_ch_names(const FIFFLIB::FiffInfo &info) const;
214
215 //=========================================================================================================
229 Eigen::MatrixXd cluster_kernel(const FSLIB::FsAnnotationSet &annotationSet,
230 qint32 clusterSize,
231 Eigen::MatrixXd &D,
232 const QString &method = QStringLiteral("cityblock")) const;
233
234 //=========================================================================================================
239 inline Eigen::MatrixXd& getKernel();
240
241 //=========================================================================================================
246 inline Eigen::MatrixXd getKernel() const;
247
248 //=========================================================================================================
253 inline bool isFixedOrient() const;
254
255 //=========================================================================================================
273 MNEForwardSolution forward,
274 const FIFFLIB::FiffCov& noiseCov,
275 float loose = 0.2f,
276 float depth = 0.8f,
277 bool fixed = false,
278 bool limit_depth_chs = true);
279
280 //=========================================================================================================
296 float lambda2,
297 bool dSPM,
298 bool sLORETA = false) const;
299
300 //=========================================================================================================
309 static bool read_inverse_operator(QIODevice &p_IODevice, MNEInverseOperator& inv);
310
311 //=========================================================================================================
317 void write(QIODevice &p_IODevice);
318
319 //=========================================================================================================
325 void writeToStream(FIFFLIB::FiffStream* p_pStream);
326
327 //=========================================================================================================
336 friend std::ostream& operator<<(std::ostream& out, const MNEInverseOperator &inv);
337
338public:
340 FIFFLIB::fiff_int_t methods;
341 FIFFLIB::fiff_int_t source_ori;
342 FIFFLIB::fiff_int_t nsource;
343 FIFFLIB::fiff_int_t nchan;
344 FIFFLIB::fiff_int_t coord_frame;
345 Eigen::MatrixXf source_nn;
346 Eigen::VectorXd sing;
357 FIFFLIB::fiff_int_t nave;
358 QList<FIFFLIB::FiffProj> projs;
359 Eigen::MatrixXd proj;
360 Eigen::MatrixXd whitener;
361 Eigen::VectorXd reginv;
362 Eigen::SparseMatrix<double> noisenorm;
363
364private:
365 Eigen::MatrixXd m_K;
366};
367
368//=============================================================================================================
369// INLINE DEFINITIONS
370//=============================================================================================================
371
372inline Eigen::MatrixXd& MNEInverseOperator::getKernel()
373{
374 return m_K;
375}
376
377//=============================================================================================================
378
379inline Eigen::MatrixXd MNEInverseOperator::getKernel() const
380{
381 return m_K;
382}
383
384//=============================================================================================================
385
387{
388 return this->source_ori == FIFFV_MNE_FIXED_ORI;
389}
390
391//=============================================================================================================
392
393inline std::ostream& operator<<(std::ostream& out, const MNEInverseOperator &inv)
394{
395 out << "#### MNE Inverse Operator ####\n"
396 << " methods: " << inv.methods << '\n'
397 << " source_ori: " << inv.source_ori << '\n'
398 << " nsource: " << inv.nsource << '\n'
399 << " nchan: " << inv.nchan << '\n'
400 << " coord_frame: " << inv.coord_frame << '\n'
401 << " eigen_leads: " << *inv.eigen_leads << '\n'
402 << " eigen_fields:" << *inv.eigen_fields << '\n';
403 return out;
404}
405} // NAMESPACE
406
407#ifndef metatype_mneinverseoperatorsptr
408#define metatype_mneinverseoperatorsptr
409Q_DECLARE_METATYPE(QSharedPointer<MNELIB::MNEInverseOperator>);
410#endif
411
412#ifndef metatype_mneinverseoperators
413#define metatype_mneinverseoperators
415#endif
416
417#endif // MNE_INVERSE_OPERATOR_H
Q_DECLARE_METATYPE(QSharedPointer< MNELIB::MNEInverseOperator >)
Forward solution (gain matrix mapping source dipoles to sensor measurements).
MNELIB shared-library export/import macros and library build metadata.
#define MNESHARED_EXPORT
Definition mne_global.h:40
Container pairing the left and right cortical source spaces of a subject.
#define FIFFV_MNE_FIXED_ORI
Matrix paired with row and column name lists, the on-disk form of FIFFB_PROJ_ITEM / FIFFB_MNE_NAMED_M...
SSP projection item: a named projection vector set with active/desired flags, parsed from FIFFB_PROJ_...
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Noise / data covariance matrix as stored under FIFFB_MNE_COV, with channel names, kind,...
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
Core MNE data structures (source spaces, source estimates, hemispheres).
std::ostream & operator<<(std::ostream &out, const MNELIB::MNEForwardSolution &p_MNEForwardSolution)
FreeSurfer surface, annotation and parcellation I/O for mne-cpp.
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
FIFF noise / data covariance: matrix, channel names, kind, applied projectors, bads,...
Definition fiff_cov.h:79
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:85
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:88
Stripped FIFF measurement info: channel list, sampling rate, device→head transform and bad-channel li...
QSharedDataPointer< FiffNamedMatrix > SDPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
Container holding the lh and/or rh FsAnnotation for one parcellation atlas.
A FreeSurfer/MNE surface label: per-vertex indices, Tk-RAS positions and scalar values for one hemisp...
Definition fs_label.h:79
Lloyd-style K-means clustering with configurable metric, seeding and replicates.
Definition kmeans.h:110
bool calculate(const Eigen::MatrixXd &X, qint32 kClusters, Eigen::VectorXi &idx, Eigen::MatrixXd &C, Eigen::VectorXd &sumD, Eigen::MatrixXd &D)
Definition kmeans.cpp:131
In-memory representation of an -fwd.fif forward solution.
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
List of MNESourceSpace objects forming a subject source space.