MNE-CPP  beta 1.0
main.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include <iostream>
43 #include <vector>
44 #include <math.h>
45 
46 
47 //*************************************************************************************************************
48 //=============================================================================================================
49 // MNE INCLUDES
50 //=============================================================================================================
51 
52 #include <fiff/fiff_evoked_set.h>
54 
55 #include <fiff/fiff_evoked.h>
56 #include <mne/mne_sourceestimate.h>
58 
59 
60 //*************************************************************************************************************
61 //=============================================================================================================
62 // QT INCLUDES
63 //=============================================================================================================
64 
65 #include <QtCore/QCoreApplication>
66 
67 
68 //*************************************************************************************************************
69 //=============================================================================================================
70 // USED NAMESPACES
71 //=============================================================================================================
72 
73 using namespace FIFFLIB;
74 using namespace MNELIB;
75 using namespace INVERSELIB;
76 
77 
78 //*************************************************************************************************************
79 //=============================================================================================================
80 // MAIN
81 //=============================================================================================================
82 
83 //=============================================================================================================
92 int main(int argc, char *argv[])
93 {
94  QCoreApplication a(argc, argv);
95 
96 // fname_data - Name of the data file
97 // setno - Data set number
98 // fname_inv - Inverse operator file name
99 // nave - Number of averages (scales the noise covariance)
100 // If negative, the number of averages in the data will be
101 // used
102 // lambda2 - The regularization factor
103 // dSPM - do dSPM?
104 // sLORETA - do sLORETA?
105 
106 // QFile t_fileEvoked("./MNE-sample-data/MEG/sample/sample_audvis-ave.fif");
107 // QFile t_fileInv("./MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-meg-eeg-inv.fif");
108 
109  QFile t_fileEvoked("E:/Data/sl_data/MEG/mind006/mind006_051209_auditory01_raw-ave.fif");
110  QFile t_fileInv("E:/Data/sl_data/MEG/mind006/mind006_051209_auditory01_raw-oct-6p-meg-inv.fif");
111 
112  float snr = 1.0f;
113  QString method("dSPM"); //"MNE" | "dSPM" | "sLORETA"
114  QString t_sFileNameStc("");
115 
116  // Parse command line parameters
117  for(qint32 i = 0; i < argc; ++i)
118  {
119  if(strcmp(argv[i], "-snr") == 0 || strcmp(argv[i], "--snr") == 0)
120  {
121  if(i + 1 < argc)
122  snr = atof(argv[i+1]);
123  }
124  else if(strcmp(argv[i], "-method") == 0 || strcmp(argv[i], "--method") == 0)
125  {
126  if(i + 1 < argc)
127  method = QString::fromUtf8(argv[i+1]);
128  }
129  else if(strcmp(argv[i], "-stc") == 0 || strcmp(argv[i], "--stc") == 0)
130  {
131  if(i + 1 < argc)
132  t_sFileNameStc = QString::fromUtf8(argv[i+1]);
133  }
134  }
135 
136  double lambda2 = 1.0 / pow(snr, 2);
137  qDebug() << "Start calculation with: SNR" << snr << "; Lambda" << lambda2 << "; Method" << method << "; stc:" << t_sFileNameStc;
138 
139  //
140  // Read the data first
141  //
142  fiff_int_t setno = 0;
143  QPair<QVariant, QVariant> baseline(QVariant(), 0);
144  FiffEvoked evoked(t_fileEvoked, setno, baseline);
145  if(evoked.isEmpty())
146  return 1;
147 
148  //
149  // Then the inverse operator
150  //
151  MNEInverseOperator inverse_operator(t_fileInv);
152 
153  //
154  // Compute inverse solution
155  //
156  MinimumNorm minimumNorm(inverse_operator, lambda2, method);
157  MNESourceEstimate sourceEstimate = minimumNorm.calculateInverse(evoked);
158 
159  //
160  //Results
161  //
162  std::cout << "\npart ( block( 0, 0, 10, 10) ) of the inverse solution:\n" << sourceEstimate.data.block(0,0,10,10) << std::endl;
163  printf("tmin = %f s\n", sourceEstimate.tmin);
164  printf("tstep = %f s\n", sourceEstimate.tstep);
165 
166 
167  if(!t_sFileNameStc.isEmpty())
168  {
169  QFile t_fileStc(t_sFileNameStc);
170  sourceEstimate.write(t_fileStc);
171 
172  //test if everything was written correctly
173  MNESourceEstimate readSourceEstimate(t_fileStc);
174 
175  std::cout << "\npart ( block( 0, 0, 10, 10) ) of the inverse solution:\n" << readSourceEstimate.data.block(0,0,10,10) << std::endl;
176  printf("tmin = %f s\n", readSourceEstimate.tmin);
177  printf("tstep = %f s\n", readSourceEstimate.tstep);
178  }
179 
180  return 0;//a.exec();
181 }
evoked data
Definition: fiff_evoked.h:91
Minimum norm class declaration.
bool write(QIODevice &p_IODevice)
MNEInverseOperator class declaration.
Definition: fiff.h:98
FiffEvokedSet class declaration.
MNESourceEstimate class declaration.
Minimum norm estimation.
Definition: minimumnorm.h:82