MNE-CPP  beta 1.0
mne_inverse_operator.h
Go to the documentation of this file.
1 //=============================================================================================================
36 #ifndef MNE_INVERSE_OPERATOR_H
37 #define MNE_INVERSE_OPERATOR_H
38 
39 //*************************************************************************************************************
40 //=============================================================================================================
41 // INCLUDES
42 //=============================================================================================================
43 
44 #include "mne_global.h"
45 #include "mne_sourcespace.h"
46 #include "mne_forwardsolution.h"
47 
48 
49 //*************************************************************************************************************
50 //=============================================================================================================
51 // FIFF INCLUDES
52 //=============================================================================================================
53 
54 #include <fiff/fiff_types.h>
55 #include <fiff/fiff_named_matrix.h>
56 #include <fiff/fiff_proj.h>
57 #include <fiff/fiff_cov.h>
58 #include <fiff/fiff_info.h>
59 
60 #include <utils/mnemath.h>
61 
62 
63 //*************************************************************************************************************
64 //=============================================================================================================
65 // Eigen INCLUDES
66 //=============================================================================================================
67 
68 #include <Eigen/Core>
69 
70 
71 //*************************************************************************************************************
72 //=============================================================================================================
73 // Qt INCLUDES
74 //=============================================================================================================
75 
76 #include <QList>
77 
78 
79 //*************************************************************************************************************
80 //=============================================================================================================
81 // FORWARD DECLARATIONS
82 //=============================================================================================================
83 
84 namespace FSLIB
85 {
86 class Label;
87 }
88 
89 
90 //*************************************************************************************************************
91 //=============================================================================================================
92 // DEFINE NAMESPACE MNELIB
93 //=============================================================================================================
94 
95 namespace MNELIB
96 {
97 
98 //*************************************************************************************************************
99 //=============================================================================================================
100 // USED NAMESPACES
101 //=============================================================================================================
102 
103 using namespace FSLIB;
104 using namespace FIFFLIB;
105 using namespace Eigen;
106 
107 
108 //=========================================================================================================
113 {
114  VectorXi roiIdx;
115  MatrixXd ctrs;
116  VectorXd sumd;
117  MatrixXd D;
119  qint32 iLabelIdxOut;
120 };
121 
122 
123 //=========================================================================================================
127 struct RegionMT
128 {
129  MatrixXd matRoiMT;
130  MatrixXd matRoiMTOrig;
132  qint32 nClusters;
133  VectorXi idcs;
134  qint32 iLabelIdxIn;
136  QString sDistMeasure;
138  RegionMTOut cluster() const
139  {
140  QString t_sDistMeasure;
141  if(sDistMeasure.isEmpty())
142  t_sDistMeasure = QString("cityblock");
143  else
144  t_sDistMeasure = sDistMeasure;
145 
146  // Kmeans Reduction
147  RegionMTOut p_RegionMTOut;
148 
149  KMeans t_kMeans(t_sDistMeasure, QString("sample"), 5);
150 
151  t_kMeans.calculate(this->matRoiMT, this->nClusters, p_RegionMTOut.roiIdx, p_RegionMTOut.ctrs, p_RegionMTOut.sumd, p_RegionMTOut.D);
152 
153  p_RegionMTOut.iLabelIdxOut = this->iLabelIdxIn;
154 
155  return p_RegionMTOut;
156  }
157 };
158 
159 
160 //=============================================================================================================
166 class MNESHARED_EXPORT MNEInverseOperator
167 {
168 public:
169  typedef QSharedPointer<MNEInverseOperator> SPtr;
170  typedef QSharedPointer<const MNEInverseOperator> ConstSPtr;
172  //=========================================================================================================
177 
178  //=========================================================================================================
184  MNEInverseOperator(QIODevice& p_IODevice);
185 
186  //=========================================================================================================
198  MNEInverseOperator(const FiffInfo &info, MNEForwardSolution forward, const FiffCov& p_noise_cov, float loose = 0.2f, float depth = 0.8f, bool fixed = false, bool limit_depth_chs = true);
199 
200  //=========================================================================================================
206  MNEInverseOperator(const MNEInverseOperator &p_MNEInverseOperator);
207 
208  //=========================================================================================================
213 
214  //=========================================================================================================
231  bool assemble_kernel(const Label &label, QString method, bool pick_normal, MatrixXd &K, SparseMatrix<double> &noise_norm, QList<VectorXi> &vertno);
232 
233  //=========================================================================================================
241  bool check_ch_names(const FiffInfo &info) const;
242 
243  //=========================================================================================================
254  MatrixXd cluster_kernel(const AnnotationSet &p_AnnotationSet, qint32 p_iClusterSize, MatrixXd& p_D, QString p_sMethod = "cityblock") const;
255 
256  //=========================================================================================================
262  inline MatrixXd& getKernel();
263 
264  //=========================================================================================================
270  inline MatrixXd getKernel() const;
271 
272  //=========================================================================================================
278  inline bool isFixedOrient() const;
279 
280  //=========================================================================================================
294  static MNEInverseOperator make_inverse_operator(const FiffInfo &info, MNEForwardSolution forward, const FiffCov& p_noise_cov, float loose = 0.2f, float depth = 0.8f, bool fixed = false, bool limit_depth_chs = true);
295 
296  //=========================================================================================================
311  MNEInverseOperator prepare_inverse_operator(qint32 nave ,float lambda2, bool dSPM, bool sLORETA = false) const;
312 
313  //=========================================================================================================
326  static bool read_inverse_operator(QIODevice &p_IODevice, MNEInverseOperator& inv);
327 
328  //=========================================================================================================
336  void write(QIODevice &p_IODevice);
337 
338  //=========================================================================================================
344  void writeToStream(FiffStream* p_pStream);
345 
346  //=========================================================================================================
355  friend std::ostream& operator<<(std::ostream& out, const MNELIB::MNEInverseOperator &p_MNEInverseOperator);
356 
357 public:
359  fiff_int_t methods;
360  fiff_int_t source_ori;
361  fiff_int_t nsource;
362  fiff_int_t nchan;
363  fiff_int_t coord_frame;
364  MatrixXf source_nn;
365  VectorXd sing;
376  fiff_int_t nave;
377  QList<FiffProj> projs;
378  MatrixXd proj;
379  MatrixXd whitener;
380  VectorXd reginv;
381  SparseMatrix<double> noisenorm;
383 private:
384  MatrixXd m_K;
385 };
386 
387 //*************************************************************************************************************
388 //=============================================================================================================
389 // INLINE DEFINITIONS
390 //=============================================================================================================
391 
393 {
394  return m_K;
395 }
396 
397 
398 //*************************************************************************************************************
399 
400 inline MatrixXd MNEInverseOperator::getKernel() const
401 {
402  return m_K;
403 }
404 
405 
406 //*************************************************************************************************************
407 
409 {
410  return this->source_ori == FIFFV_MNE_FIXED_ORI;
411 }
412 
413 
414 //*************************************************************************************************************
415 
416 inline std::ostream& operator<<(std::ostream& out, const MNELIB::MNEInverseOperator &p_MNEInverseOperator)
417 {
418  out << "#### MNE Inverse Operator ####\n";
419 
420  out << "\n methods: " << p_MNEInverseOperator.methods << std::endl;
421  out << "\n source_ori: " << p_MNEInverseOperator.source_ori << std::endl;
422  out << "\n nsource: " << p_MNEInverseOperator.nsource << std::endl;
423  out << "\n nchan: " << p_MNEInverseOperator.nchan << std::endl;
424  out << "\n coord_frame:\n\t" << p_MNEInverseOperator.coord_frame << std::endl;
425 
426  out << "\n eigen_leads: " << p_MNEInverseOperator.eigen_leads << std::endl;
427  out << "\n eigen_fields:\n\t" << p_MNEInverseOperator.eigen_fields << std::endl;
428 
429  return out;
430 }
431 
432 } // NAMESPACE
433 
434 #endif // MNE_INVERSE_OPERATOR_H
QSharedDataPointer< FiffCov > SDPtr
Definition: fiff_cov.h:99
FIFF measurement file information.
Definition: fiff_info.h:96
bool calculate(MatrixXd X, qint32 kClusters, VectorXi &idx, MatrixXd &C, VectorXd &sumD, MatrixXd &D)
Definition: kmeans.cpp:93
FiffNamedMatrix::SDPtr eigen_fields
Source Space descritpion.
FiffProj class declaration.
Old fiff_type declarations - replace them.
QSharedDataPointer< FiffNamedMatrix > SDPtr
FiffNamedMatrix class declaration.
SparseMatrix< double > noisenorm
FiffNamedMatrix::SDPtr eigen_leads
FiffInfo class declaration.
MNEForwardSolution class declaration, which provides the forward solution including the source space ...
Annotation set.
Definition: annotationset.h:96
covariance data
Definition: fiff_cov.h:94
Definition: fiff.h:98
Coordinate transformation description.
MNESourceSpace class declaration.
K-Means Clustering.
Definition: kmeans.h:86
MNEMath class declaration.
light measurement info
Freesurfer/MNE label.
Definition: label.h:97
FIFF File I/O routines.
Definition: fiff_stream.h:129
QSharedPointer< const MNEInverseOperator > ConstSPtr
QSharedPointer< MNEInverseOperator > SPtr
FiffCov class declaration.