42 #include <disp3DNew/brainview.h>
48 #include <fiff/fiff_evoked.h>
66 #include <QGuiApplication>
76 using namespace FSLIB;
96 int main(
int argc,
char *argv[])
98 QGuiApplication a(argc, argv);
101 QFile t_fileFwd(
"./MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif");
102 QFile t_fileCov(
"./MNE-sample-data/MEG/sample/sample_audvis-cov.fif");
103 QFile t_fileRaw(
"./MNE-sample-data/MEG/sample/sample_audvis_raw.fif");
104 QString t_sEventName =
"./MNE-sample-data/MEG/sample/sample_audvis_raw-eve.fif";
111 bool keep_comp =
false;
112 fiff_int_t dest_comp = 0;
113 bool pick_all =
true;
128 picks.resize(raw.info.nchan);
130 for(k = 0; k < raw.info.nchan; ++k)
137 include <<
"STI 014";
138 bool want_meg =
true;
139 bool want_eeg =
false;
140 bool want_stim =
false;
143 picks = raw.info.pick_types(want_meg, want_eeg, want_stim, include, raw.info.bads);
146 QStringList ch_names;
147 for(k = 0; k < picks.cols(); ++k)
148 ch_names << raw.info.ch_names[picks(0,k)];
153 if (raw.info.projs.size() == 0)
154 printf(
"No projector specified for these data\n");
160 for (k = 0; k < raw.info.projs.size(); ++k)
161 raw.info.projs[k].active =
true;
163 printf(
"%d projection items activated\n",raw.info.projs.size());
168 fiff_int_t nproj = raw.info.make_projector(raw.proj);
172 printf(
"The projection vectors do not apply to these channels\n");
176 printf(
"Created an SSP operator (subspace dimension = %d)\n",nproj);
184 qint32 current_comp = raw.info.get_current_comp();
185 if (current_comp > 0)
186 printf(
"Current compensation grade : %d\n",current_comp);
189 dest_comp = current_comp;
191 if (current_comp != dest_comp)
193 qDebug() <<
"This part needs to be debugged";
197 raw.info.set_current_comp(dest_comp);
198 printf(
"Appropriate compensator added to change to grade %d.\n",dest_comp);
202 printf(
"Could not make the compensator\n");
212 if (t_sEventName.size() == 0)
214 p = t_fileRaw.fileName().indexOf(
".fif");
217 t_sEventName = t_fileRaw.fileName().replace(p, 4,
"-eve.fif");
221 printf(
"Raw file name does not end properly\n");
226 t_EventFile.setFileName(t_sEventName);
228 printf(
"Events read from %s\n",t_sEventName.toUtf8().constData());
235 p = t_fileRaw.fileName().indexOf(
".fif");
238 t_EventFile.setFileName(t_sEventName);
241 printf(
"Error while read events.\n");
244 printf(
"Binary event file %s read\n",t_sEventName.toUtf8().constData());
251 printf(
"Text file %s is not supported jet.\n",t_sEventName.toUtf8().constData());
259 MatrixXi selected = MatrixXi::Zero(1, events.rows());
260 for (p = 0; p < events.rows(); ++p)
262 if (events(p,1) == 0 && events(p,2) == event)
264 selected(0,count) = p;
268 selected.conservativeResize(1, count);
270 printf(
"%d matching events found\n",count);
273 printf(
"No desired events found.\n");
278 fiff_int_t event_samp, from, to;
287 for (p = 0; p < count; ++p)
292 event_samp = events(selected(p),0);
293 from = event_samp + tmin*raw.info.sfreq;
294 to = event_samp + floor(tmax*raw.info.sfreq + 0.5);
298 if(raw.read_raw_segment(epoch->
epoch, timesDummy, from, to, picks))
302 times.resize(1, to-from+1);
303 for (qint32 i = 0; i < times.cols(); ++i)
304 times(0, i) = ((float)(from-event_samp+i)) / raw.info.sfreq;
307 epoch->
event = event;
308 epoch->
tmin = ((float)(from)-(float)(raw.first_samp))/raw.info.sfreq;
309 epoch->
tmax = ((
float)(to)-(
float)(raw.first_samp))/raw.info.sfreq;
315 printf(
"Can't read the event data segments");
322 printf(
"Read %d epochs, %d samples each.\n",data.size(),(qint32)data[0]->epoch.cols());
325 std::cout << data[0]->epoch.block(0,0,10,10) << std::endl;
326 qDebug() << data[0]->epoch.rows() <<
" x " << data[0]->epoch.cols();
328 std::cout << times.block(0,0,1,10) << std::endl;
329 qDebug() << times.rows() <<
" x " << times.cols();
336 qint32 numAverages = 99;
337 VectorXi vecSel(numAverages);
340 for(qint32 i = 0; i < vecSel.size(); ++i)
342 qint32 val = rand() % data.size();
346 std::cout <<
"Select following epochs to average:\n" << vecSel << std::endl;
348 FiffEvoked evoked = data.
average(raw.info, tmin*raw.info.sfreq, floor(tmax*raw.info.sfreq + 0.5), vecSel);
352 QString method(
"dSPM");
354 QString t_sFileNameClusteredInv(
"");
355 QString t_sFileNameStc(
"test_mind006_051209_auditory01.stc");
358 for(qint32 i = 0; i < argc; ++i)
360 if(strcmp(argv[i],
"-snr") == 0 || strcmp(argv[i],
"--snr") == 0)
363 snr = atof(argv[i+1]);
365 else if(strcmp(argv[i],
"-method") == 0 || strcmp(argv[i],
"--method") == 0)
368 method = QString::fromUtf8(argv[i+1]);
370 else if(strcmp(argv[i],
"-inv") == 0 || strcmp(argv[i],
"--inv") == 0)
373 t_sFileNameClusteredInv = QString::fromUtf8(argv[i+1]);
375 else if(strcmp(argv[i],
"-stc") == 0 || strcmp(argv[i],
"--stc") == 0)
378 t_sFileNameStc = QString::fromUtf8(argv[i+1]);
382 double lambda2 = 1.0 / pow(snr, 2);
383 qDebug() <<
"Start calculation with: SNR" << snr <<
"; Lambda" << lambda2 <<
"; Method" << method <<
"; stc:" << t_sFileNameStc;
392 noise_cov = noise_cov.regularize(evoked.
info, 0.05, 0.05, 0.1,
true);
404 MinimumNorm minimumNorm(inverse_operator, lambda2, method);
411 std::cout<<
"Creating BrainView"<<std::endl;
413 BrainView testWindow(
"sample", 2,
"inflated",
"./MNE-sample-data/subjects");
415 testWindow.initStcDataModel(
"sample", 2,
"inflated",
"./MNE-sample-data/subjects",
"aparc.a2009s", t_Fwd);
417 testWindow.addSourceEstimate(sourceEstimate);
static bool make_compensator(const FiffInfo &info, fiff_int_t from, fiff_int_t to, FiffCtfComp &ctf_comp, bool exclude_comp_chs=false)
FIFF measurement file information.
MNEEpochDataList class declaration.
FreeSurfer surface visualisation.
static bool read_events(QIODevice &p_IODevice, MatrixXi &eventlist)
FIFF raw measurement data.
Minimum norm class declaration.
Surface class declaration.
MNESourceEstimate class declaration.
FiffEvoked average(FiffInfo &p_info, fiff_int_t first, fiff_int_t last, VectorXi sel=defaultVectorXi, bool proj=false)
QSharedPointer< MNEEpochData > SPtr
AnnotationSet class declaration.
MNEMath class declaration.
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...