46 #include <fiff/fiff_evoked.h>
67 #include <QGuiApplication>
77 using namespace FSLIB;
98 int main(
int argc,
char *argv[])
100 QGuiApplication a(argc, argv);
114 QFile t_fileRaw(
"E:/Data/sl_data/MEG/mind006/mind006_051209_median01_raw.fif");
115 QString t_sEventName =
"E:/Data/sl_data/MEG/mind006/mind006_051209_median01_raw-eve.fif";
116 QFile t_fileFwd(
"E:/Data/sl_data/MEG/mind006/mind006_051209_median01_raw-oct-6-fwd.fif");
117 AnnotationSet t_annotationSet(
"E:/Data/sl_data/subjects/mind006/label/lh.aparc.a2009s.annot",
"E:/Data/sl_data/subjects/mind006/label/rh.aparc.a2009s.annot");
118 SurfaceSet t_surfSet(
"E:/Data/sl_data/subjects/mind006/surf/lh.white",
"E:/Data/sl_data/subjects/mind006/surf/rh.white");
120 QString t_sFileNameStc(
"");
123 bool doMovie =
false;
125 qint32 numDipolePairs = 7;
132 bool keep_comp =
false;
133 fiff_int_t dest_comp = 0;
134 bool pick_all =
true;
140 for(qint32 i = 0; i < argc; ++i)
142 if(strcmp(argv[i],
"-stc") == 0 || strcmp(argv[i],
"--stc") == 0)
145 t_sFileNameStc = QString::fromUtf8(argv[i+1]);
167 picks.resize(raw.info.nchan);
169 for(k = 0; k < raw.info.nchan; ++k)
176 include <<
"STI 014";
177 bool want_meg =
true;
178 bool want_eeg =
false;
179 bool want_stim =
false;
181 picks = raw.info.pick_types(want_meg, want_eeg, want_stim, include, raw.info.bads);
184 QStringList ch_names;
185 for(k = 0; k < picks.cols(); ++k)
186 ch_names << raw.info.ch_names[picks(0,k)];
191 if (raw.info.projs.size() == 0)
192 printf(
"No projector specified for these data\n");
198 for (k = 0; k < raw.info.projs.size(); ++k)
199 raw.info.projs[k].active =
true;
201 printf(
"%d projection items activated\n",raw.info.projs.size());
206 fiff_int_t nproj = raw.info.make_projector(raw.proj);
210 printf(
"The projection vectors do not apply to these channels\n");
214 printf(
"Created an SSP operator (subspace dimension = %d)\n",nproj);
221 qint32 current_comp = raw.info.get_current_comp();
222 if (current_comp > 0)
223 printf(
"Current compensation grade : %d\n",current_comp);
226 dest_comp = current_comp;
228 if (current_comp != dest_comp)
230 qDebug() <<
"This part needs to be debugged";
233 raw.info.set_current_comp(dest_comp);
234 printf(
"Appropriate compensator added to change to grade %d.\n",dest_comp);
238 printf(
"Could not make the compensator\n");
247 if (t_sEventName.size() == 0)
249 p = t_fileRaw.fileName().indexOf(
".fif");
252 t_sEventName = t_fileRaw.fileName().replace(p, 4,
"-eve.fif");
256 printf(
"Raw file name does not end properly\n");
261 t_EventFile.setFileName(t_sEventName);
263 printf(
"Events read from %s\n",t_sEventName.toUtf8().constData());
270 p = t_fileRaw.fileName().indexOf(
".fif");
273 t_EventFile.setFileName(t_sEventName);
276 printf(
"Error while read events.\n");
279 printf(
"Binary event file %s read\n",t_sEventName.toUtf8().constData());
286 printf(
"Text file %s is not supported jet.\n",t_sEventName.toUtf8().constData());
329 MatrixXi selected = MatrixXi::Zero(1, events.rows());
330 for (p = 0; p < events.rows(); ++p)
332 if (events(p,1) == 0 && events(p,2) == event)
334 selected(0,count) = p;
338 selected.conservativeResize(1, count);
340 printf(
"%d matching events found\n",count);
343 printf(
"No desired events found.\n");
348 fiff_int_t event_samp, from, to;
357 for (p = 0; p < count; ++p)
362 event_samp = events(selected(p),0);
363 from = event_samp + tmin*raw.info.sfreq;
364 to = event_samp + floor(tmax*raw.info.sfreq + 0.5);
368 if(raw.read_raw_segment(epoch->
epoch, timesDummy, from, to, picks))
372 times.resize(1, to-from+1);
373 for (qint32 i = 0; i < times.cols(); ++i)
374 times(0, i) = ((float)(from-event_samp+i)) / raw.info.sfreq;
377 epoch->
event = event;
378 epoch->
tmin = ((float)(from)-(float)(raw.first_samp))/raw.info.sfreq;
379 epoch->
tmax = ((
float)(to)-(
float)(raw.first_samp))/raw.info.sfreq;
385 printf(
"Can't read the event data segments");
392 printf(
"Read %d epochs, %d samples each.\n",data.size(),(qint32)data[0]->epoch.cols());
395 std::cout << data[0]->epoch.block(0,0,10,10) << std::endl;
396 qDebug() << data[0]->epoch.rows() <<
" x " << data[0]->epoch.cols();
398 std::cout << times.block(0,0,1,10) << std::endl;
399 qDebug() << times.rows() <<
" x " << times.cols();
434 std::cout <<
"Select following epochs to average:\n" << vecSel << std::endl;
436 FiffEvoked evoked = data.
average(raw.info, tmin*raw.info.sfreq, floor(tmax*raw.info.sfreq + 0.5), vecSel);
454 RapMusic t_rapMusic(t_clusteredFwd,
false, numDipolePairs);
457 t_rapMusic.setStcAttr(200,0.5);
487 QList<Label> t_qListLabels;
488 QList<RowVector4i> t_qListRGBAs;
491 t_annotationSet.toLabels(t_surfSet, t_qListLabels, t_qListRGBAs);
493 InverseView view(t_rapMusic.getSourceSpace(), t_qListLabels, t_qListRGBAs, 24,
true,
false,
false);
495 if (view.stereoType() != QGLView::RedCyanAnaglyph)
496 view.camera()->setEyeSeparation(0.3f);
497 QStringList args = QCoreApplication::arguments();
498 int w_pos = args.indexOf(
"-width");
499 int h_pos = args.indexOf(
"-height");
500 if (w_pos >= 0 && h_pos >= 0)
503 int w = args.at(w_pos + 1).toInt(&ok);
506 qWarning() <<
"Could not parse width argument:" << args;
509 int h = args.at(h_pos + 1).toInt(&ok);
512 qWarning() <<
"Could not parse height argument:" << args;
519 view.resize(800, 600);
524 view.pushSourceEstimate(sourceEstimate);
526 if(!t_sFileNameStc.isEmpty())
528 QFile t_fileClusteredStc(t_sFileNameStc);
529 sourceEstimate.
write(t_fileClusteredStc);
static bool make_compensator(const FiffInfo &info, fiff_int_t from, fiff_int_t to, FiffCtfComp &ctf_comp, bool exclude_comp_chs=false)
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
MNEEpochDataList class declaration.
static bool read_events(QIODevice &p_IODevice, MatrixXi &eventlist)
FIFF raw measurement data.
bool write(QIODevice &p_IODevice)
RapMusic algorithm class declaration.
FiffEvoked pick_channels(const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList) const
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
The RapMusic class provides the RAP MUSIC Algorithm CPU implementation. ToDo: Paper references...
AnnotationSet class declaration.
InverseView class declaration.
MNEMath class declaration.
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
A hemisphere set of surfaces.