MNE-CPP  beta 1.0
main.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include <fs/label.h>
43 #include <fs/surface.h>
44 #include <fs/annotationset.h>
45 
46 #include <fiff/fiff_evoked.h>
47 #include <mne/mne_sourceestimate.h>
49 
50 #include <disp3D/inverseview.h>
51 
52 #include <iostream>
53 
54 
55 //*************************************************************************************************************
56 //=============================================================================================================
57 // QT INCLUDES
58 //=============================================================================================================
59 
60 #include <QGuiApplication>
61 #include <QSet>
62 
63 
64 //*************************************************************************************************************
65 //=============================================================================================================
66 // USED NAMESPACES
67 //=============================================================================================================
68 
69 using namespace MNELIB;
70 using namespace FSLIB;
71 using namespace FIFFLIB;
72 using namespace INVERSELIB;
73 using namespace DISP3DLIB;
74 
75 
76 //*************************************************************************************************************
77 //=============================================================================================================
78 // MAIN
79 //=============================================================================================================
80 
81 //=============================================================================================================
90 int main(int argc, char *argv[])
91 {
92  QGuiApplication a(argc, argv);
93 
94  //########################################################################################
95  // Source Estimate
96 
97  QFile t_fileFwd("./MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif");
98  QFile t_fileCov("./MNE-sample-data/MEG/sample/sample_audvis-cov.fif");
99  QFile t_fileEvoked("./MNE-sample-data/MEG/sample/sample_audvis-ave.fif");
100  AnnotationSet t_annotationSet("sample", 2, "aparc.a2009s", "./MNE-sample-data/subjects");
101  SurfaceSet t_surfSet("sample", 2, "white", "./MNE-sample-data/subjects");
102 
103 
104  QString t_sFileClusteredInverse("");//QFile t_fileClusteredInverse("./clusteredInverse-inv.fif");
105 
106  double snr = 1.0;
107  double lambda2 = 1.0 / pow(snr, 2);
108  QString method("dSPM"); //"MNE" | "dSPM" | "sLORETA"
109 
110  // Load data
111  fiff_int_t setno = 1;
112  QPair<QVariant, QVariant> baseline(QVariant(), 0);
113  FiffEvoked evoked(t_fileEvoked, setno, baseline);
114  if(evoked.isEmpty())
115  return 1;
116 
117  std::cout << "Evoked description: " << evoked.comment.toLatin1().constData() << std::endl;
118 
119  MNEForwardSolution t_Fwd(t_fileFwd);
120  if(t_Fwd.isEmpty())
121  return 1;
122 
123  FiffCov noise_cov(t_fileCov);
124 
125  // regularize noise covariance
126  noise_cov = noise_cov.regularize(evoked.info, 0.05, 0.05, 0.1, true);
127 
128  //
129  // Cluster forward solution;
130  //
131  MNEForwardSolution t_clusteredFwd = t_Fwd.cluster_forward_solution(t_annotationSet, 40);
132 
133  //
134  // make an inverse operators
135  //
136  FiffInfo info = evoked.info;
137 
138  MNEInverseOperator inverse_operator(info, t_clusteredFwd, noise_cov, 0.2f, 0.8f);
139 
140  if(!t_sFileClusteredInverse.isEmpty())
141  {
142  QFile t_fileClusteredInverse(t_sFileClusteredInverse);
143  inverse_operator.write(t_fileClusteredInverse);
144  }
145 
146  //
147  // Compute inverse solution
148  //
149  MinimumNorm minimumNorm(inverse_operator, lambda2, method);
150  MNESourceEstimate sourceEstimate = minimumNorm.calculateInverse(evoked);
151 
152  if(sourceEstimate.isEmpty())
153  return 1;
154 
155 // // View activation time-series
156 // std::cout << "\nsourceEstimate:\n" << sourceEstimate.data.block(0,0,10,10) << std::endl;
157 // std::cout << "time\n" << sourceEstimate.times.block(0,0,1,10) << std::endl;
158 // std::cout << "timeMin\n" << sourceEstimate.times[0] << std::endl;
159 // std::cout << "timeMax\n" << sourceEstimate.times[sourceEstimate.times.size()-1] << std::endl;
160 // std::cout << "time step\n" << sourceEstimate.tstep << std::endl;
161 
162  //Source Estimate end
163  //########################################################################################
164 
165  QList<Label> t_qListLabels;
166  QList<RowVector4i> t_qListRGBAs;
167 
168  //ToDo overload toLabels using instead of t_surfSet rr of MNESourceSpace
169  t_annotationSet.toLabels(t_surfSet, t_qListLabels, t_qListRGBAs);
170 
171  InverseView view(minimumNorm.getSourceSpace(), t_qListLabels, t_qListRGBAs, 24, true, false);
172 
173  if (view.stereoType() != QGLView::RedCyanAnaglyph)
174  view.camera()->setEyeSeparation(0.3f);
175  QStringList args = QCoreApplication::arguments();
176  int w_pos = args.indexOf("-width");
177  int h_pos = args.indexOf("-height");
178  if (w_pos >= 0 && h_pos >= 0)
179  {
180  bool ok = true;
181  int w = args.at(w_pos + 1).toInt(&ok);
182  if (!ok)
183  {
184  qWarning() << "Could not parse width argument:" << args;
185  return 1;
186  }
187  int h = args.at(h_pos + 1).toInt(&ok);
188  if (!ok)
189  {
190  qWarning() << "Could not parse height argument:" << args;
191  return 1;
192  }
193  view.resize(w, h);
194  }
195  else
196  {
197  view.resize(800, 600);
198  }
199  view.setTitle(QString("Online Brain Monitoring - %1").arg(evoked.comment));
200  view.show();
201 
202 
203 // //only one time point - P100
204 // qint32 sample = 0;
205 // for(qint32 i = 0; i < sourceEstimate.times.size(); ++i)
206 // {
207 // if(sourceEstimate.times(i) >= 0.05f)
208 // {
209 // sample = i;
210 // break;
211 // }
212 // }
213 // sample += (qint32)ceil(0.106/sourceEstimate.tstep); //100ms
214 // sourceEstimate = sourceEstimate.reduce(sample, 1);
215 
216  //Push Estimate
217  view.pushSourceEstimate(sourceEstimate);
218 
219  return a.exec();
220 }
FIFF measurement file information.
Definition: fiff_info.h:96
MNEForwardSolution cluster_forward_solution(const AnnotationSet &p_AnnotationSet, qint32 p_iClusterSize, MatrixXd &p_D=defaultD, const FiffCov &p_pNoise_cov=defaultCov, const FiffInfo &p_pInfo=defaultInfo, QString p_sMethod="cityblock") const
3D stereoscopic labels
Definition: inverseview.h:118
evoked data
Definition: fiff_evoked.h:91
Minimum norm class declaration.
Annotation set.
Definition: annotationset.h:96
covariance data
Definition: fiff_cov.h:94
Definition: fiff.h:98
Surface class declaration.
MNESourceEstimate class declaration.
Minimum norm estimation.
Definition: minimumnorm.h:82
AnnotationSet class declaration.
InverseView class declaration.
Label class declaration.
A hemisphere set of surfaces.
Definition: surfaceset.h:83