48 using namespace COMMUNICATIONLIB;
49 using namespace FIFFLIB;
50 using namespace Eigen;
67 QTcpSocket::disconnectFromHost();
81 QString t_sCommand(
"");
84 this->waitForReadyRead(100);
89 m_clientID = *t_pTag->toInt();
99 bool t_bReadMeasBlockStart =
false;
100 bool t_bReadMeasBlockEnd =
false;
101 QString col_names, row_names;
108 while(!t_bReadMeasBlockStart)
111 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MEAS_INFO)
113 printf(
"FIFF_BLOCK_START FIFFB_MEAS_INFO\n");
114 t_bReadMeasBlockStart =
true;
122 bool dev_head_t_read =
false;
123 bool ctf_head_t_read =
false;
125 while(!t_bReadMeasBlockEnd)
131 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_DACQ_PARS)
133 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_DACQ_PARS)
136 if(t_pTag->kind == FIFF_DACQ_PARS)
137 p_pFiffInfo->acq_pars = t_pTag->toString();
138 else if(t_pTag->kind == FIFF_DACQ_STIM)
139 p_pFiffInfo->acq_stim = t_pTag->toString();
147 if (!dev_head_t_read)
149 p_pFiffInfo->dev_head_t = t_pTag->toCoordTrans();
150 dev_head_t_read =
true;
152 else if (!ctf_head_t_read)
154 p_pFiffInfo->ctf_head_t = t_pTag->toCoordTrans();
155 ctf_head_t_read =
true;
161 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_ISOTRAK)
163 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_ISOTRAK)
168 p_pFiffInfo->dig.append(t_pTag->toDigPoint());
174 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_PROJ)
176 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_PROJ)
179 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_PROJ_ITEM)
182 qint32 countProj = p_pFiffInfo->projs.size();
183 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_PROJ_ITEM)
186 switch (t_pTag->kind)
190 p_pFiffInfo->projs.append(proj);
191 p_pFiffInfo->projs[countProj].desc = t_pTag->toString();
193 case FIFF_PROJ_ITEM_KIND:
194 p_pFiffInfo->projs[countProj].kind = *(t_pTag->toInt());
197 p_pFiffInfo->projs[countProj].data->ncol = *(t_pTag->toInt());
199 case FIFF_PROJ_ITEM_NVEC:
200 p_pFiffInfo->projs[countProj].data->nrow = *(t_pTag->toInt());
203 p_pFiffInfo->projs[countProj].active = *(t_pTag->toInt());
205 case FIFF_PROJ_ITEM_CH_NAME_LIST:
206 p_pFiffInfo->projs[countProj].data->col_names = FiffStream::split_name_list(t_pTag->toString());
208 case FIFF_PROJ_ITEM_VECTORS:
210 p_pFiffInfo->projs[countProj].data->data = t_pTag->toFloatMatrix().transpose().cast<
double>();
218 for(qint32 i = 0; i < p_pFiffInfo->projs.size(); ++i)
220 if(p_pFiffInfo->projs[i].data->data.rows() != p_pFiffInfo->projs[i].data->nrow)
221 p_pFiffInfo->projs[i].data->data.transposeInPlace();
227 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MNE_CTF_COMP)
229 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_MNE_CTF_COMP)
232 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MNE_CTF_COMP_DATA)
235 qint32 countComp = p_pFiffInfo->comps.size();
236 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_MNE_CTF_COMP_DATA)
239 switch (t_pTag->kind)
243 p_pFiffInfo->comps.append(comp);
244 p_pFiffInfo->comps[countComp].ctfkind = *(t_pTag->toInt());
246 if (p_pFiffInfo->comps[countComp].ctfkind == 1194410578)
247 p_pFiffInfo->comps[countComp].kind = 1;
248 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194476114)
249 p_pFiffInfo->comps[countComp].kind = 2;
250 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194541650)
251 p_pFiffInfo->comps[countComp].kind = 3;
252 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194479433)
253 p_pFiffInfo->comps[countComp].kind = 4;
254 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194544969)
255 p_pFiffInfo->comps[countComp].kind = 5;
257 p_pFiffInfo->comps[countComp].kind = p_pFiffInfo->comps[countComp].ctfkind;
260 p_pFiffInfo->comps[countComp].save_calibrated = *(t_pTag->toInt());
263 p_pFiffInfo->comps[countComp].data->nrow = *(t_pTag->toInt());
266 p_pFiffInfo->comps[countComp].data->ncol = *(t_pTag->toInt());
268 case FIFF_MNE_ROW_NAMES:
269 row_names = t_pTag->toString();
270 if (!row_names.isEmpty())
271 p_pFiffInfo->comps[countComp].data->row_names = FiffStream::split_name_list(row_names);
273 case FIFF_MNE_COL_NAMES:
274 col_names = t_pTag->toString();
275 if (!col_names.isEmpty())
276 p_pFiffInfo->comps[countComp].data->col_names = FiffStream::split_name_list(col_names);
280 p_pFiffInfo->comps[countComp].data->data = t_pTag->toFloatMatrix().transpose().cast<
double>();
290 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MNE_BAD_CHANNELS)
292 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_MNE_BAD_CHANNELS)
295 if(t_pTag->kind == FIFF_MNE_CH_NAME_LIST)
296 p_pFiffInfo->bads = FiffStream::split_name_list(t_pTag->data());
305 p_pFiffInfo->sfreq = *(t_pTag->toFloat());
308 p_pFiffInfo->linefreq = *(t_pTag->toFloat());
311 p_pFiffInfo->highpass = *(t_pTag->toFloat());
314 p_pFiffInfo->lowpass = *(t_pTag->toFloat());
317 p_pFiffInfo->nchan = *(t_pTag->toInt());
320 p_pFiffInfo->meas_date[0] = t_pTag->toInt()[0];
321 p_pFiffInfo->meas_date[1] = t_pTag->toInt()[1];
324 p_pFiffInfo->proj_id = *t_pTag->toInt();
327 p_pFiffInfo->proj_name = t_pTag->toString();
330 p_pFiffInfo->xplotter_layout = t_pTag->toString();
333 p_pFiffInfo->experimenter = t_pTag->toString();
336 p_pFiffInfo->description = t_pTag->toString();
339 p_pFiffInfo->gantry_angle = *t_pTag->toInt();
342 p_pFiffInfo->utc_offset = t_pTag->toString();
347 p_pFiffInfo->chs.append(t_pTag->toChInfo());
350 if(t_pTag->kind == FIFF_BLOCK_END && *t_pTag->toInt() == FIFFB_MEAS_INFO)
352 printf(
"FIFF_BLOCK_END FIFFB_MEAS_INFO\n");
353 t_bReadMeasBlockEnd =
true;
361 for (qint32 c = 0; c < p_pFiffInfo->nchan; ++c)
362 p_pFiffInfo->ch_names << p_pFiffInfo->chs[c].ch_name;
374 bool t_bReadMeasBlockStart =
false;
375 bool t_bReadMeasBlockEnd =
false;
376 QString col_names, row_names;
383 while(!t_bReadMeasBlockStart)
386 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MEAS_INFO)
388 printf(
"FIFF_BLOCK_START FIFFB_MEAS_INFO\n");
389 t_bReadMeasBlockStart =
true;
397 bool dev_head_t_read =
false;
398 bool ctf_head_t_read =
false;
400 while(!t_bReadMeasBlockEnd)
406 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_DACQ_PARS)
408 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_DACQ_PARS)
411 if(t_pTag->kind == FIFF_DACQ_PARS)
412 p_pFiffInfo->acq_pars = t_pTag->toString();
413 else if(t_pTag->kind == FIFF_DACQ_STIM)
414 p_pFiffInfo->acq_stim = t_pTag->toString();
422 if (!dev_head_t_read)
424 p_pFiffInfo->dev_head_t = t_pTag->toCoordTrans();
425 dev_head_t_read =
true;
427 else if (!ctf_head_t_read)
429 p_pFiffInfo->ctf_head_t = t_pTag->toCoordTrans();
430 ctf_head_t_read =
true;
436 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_ISOTRAK)
438 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_ISOTRAK)
443 p_pFiffInfo->dig.append(t_pTag->toDigPoint());
444 p_pDigData->points.append(t_pTag->toDigPoint());
447 p_pDigData->coord_frame = *t_pTag->toInt();
454 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_PROJ)
456 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_PROJ)
459 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_PROJ_ITEM)
462 qint32 countProj = p_pFiffInfo->projs.size();
463 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_PROJ_ITEM)
466 switch (t_pTag->kind)
470 p_pFiffInfo->projs.append(proj);
471 p_pFiffInfo->projs[countProj].desc = t_pTag->toString();
473 case FIFF_PROJ_ITEM_KIND:
474 p_pFiffInfo->projs[countProj].kind = *(t_pTag->toInt());
477 p_pFiffInfo->projs[countProj].data->ncol = *(t_pTag->toInt());
479 case FIFF_PROJ_ITEM_NVEC:
480 p_pFiffInfo->projs[countProj].data->nrow = *(t_pTag->toInt());
483 p_pFiffInfo->projs[countProj].active = *(t_pTag->toInt());
485 case FIFF_PROJ_ITEM_CH_NAME_LIST:
486 p_pFiffInfo->projs[countProj].data->col_names = FiffStream::split_name_list(t_pTag->toString());
488 case FIFF_PROJ_ITEM_VECTORS:
490 p_pFiffInfo->projs[countProj].data->data = t_pTag->toFloatMatrix().transpose().cast<
double>();
498 for(qint32 i = 0; i < p_pFiffInfo->projs.size(); ++i)
500 if(p_pFiffInfo->projs[i].data->data.rows() != p_pFiffInfo->projs[i].data->nrow)
501 p_pFiffInfo->projs[i].data->data.transposeInPlace();
507 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MNE_CTF_COMP)
509 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_MNE_CTF_COMP)
512 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MNE_CTF_COMP_DATA)
515 qint32 countComp = p_pFiffInfo->comps.size();
516 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_MNE_CTF_COMP_DATA)
519 switch (t_pTag->kind)
523 p_pFiffInfo->comps.append(comp);
524 p_pFiffInfo->comps[countComp].ctfkind = *(t_pTag->toInt());
526 if (p_pFiffInfo->comps[countComp].ctfkind == 1194410578)
527 p_pFiffInfo->comps[countComp].kind = 1;
528 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194476114)
529 p_pFiffInfo->comps[countComp].kind = 2;
530 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194541650)
531 p_pFiffInfo->comps[countComp].kind = 3;
532 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194479433)
533 p_pFiffInfo->comps[countComp].kind = 4;
534 else if (p_pFiffInfo->comps[countComp].ctfkind == 1194544969)
535 p_pFiffInfo->comps[countComp].kind = 5;
537 p_pFiffInfo->comps[countComp].kind = p_pFiffInfo->comps[countComp].ctfkind;
540 p_pFiffInfo->comps[countComp].save_calibrated = *(t_pTag->toInt());
543 p_pFiffInfo->comps[countComp].data->nrow = *(t_pTag->toInt());
546 p_pFiffInfo->comps[countComp].data->ncol = *(t_pTag->toInt());
548 case FIFF_MNE_ROW_NAMES:
549 row_names = t_pTag->toString();
550 if (!row_names.isEmpty())
551 p_pFiffInfo->comps[countComp].data->row_names = FiffStream::split_name_list(row_names);
553 case FIFF_MNE_COL_NAMES:
554 col_names = t_pTag->toString();
555 if (!col_names.isEmpty())
556 p_pFiffInfo->comps[countComp].data->col_names = FiffStream::split_name_list(col_names);
560 p_pFiffInfo->comps[countComp].data->data = t_pTag->toFloatMatrix().transpose().cast<
double>();
570 if(t_pTag->kind == FIFF_BLOCK_START && *(t_pTag->toInt()) == FIFFB_MNE_BAD_CHANNELS)
572 while(t_pTag->kind != FIFF_BLOCK_END || *(t_pTag->toInt()) != FIFFB_MNE_BAD_CHANNELS)
575 if(t_pTag->kind == FIFF_MNE_CH_NAME_LIST)
576 p_pFiffInfo->bads = FiffStream::split_name_list(t_pTag->data());
585 p_pFiffInfo->sfreq = *(t_pTag->toFloat());
588 p_pFiffInfo->linefreq = *(t_pTag->toFloat());
591 p_pFiffInfo->highpass = *(t_pTag->toFloat());
594 p_pFiffInfo->lowpass = *(t_pTag->toFloat());
597 p_pFiffInfo->nchan = *(t_pTag->toInt());
600 p_pFiffInfo->meas_date[0] = t_pTag->toInt()[0];
601 p_pFiffInfo->meas_date[1] = t_pTag->toInt()[1];
604 p_pFiffInfo->proj_id = *t_pTag->toInt();
607 p_pFiffInfo->proj_name = t_pTag->toString();
610 p_pFiffInfo->xplotter_layout = t_pTag->toString();
613 p_pFiffInfo->experimenter = t_pTag->toString();
616 p_pFiffInfo->description = t_pTag->toString();
619 p_pFiffInfo->gantry_angle = *t_pTag->toInt();
622 p_pFiffInfo->utc_offset = t_pTag->toString();
627 p_pFiffInfo->chs.append(t_pTag->toChInfo());
630 if(t_pTag->kind == FIFF_BLOCK_END && *t_pTag->toInt() == FIFFB_MEAS_INFO)
632 printf(
"FIFF_BLOCK_END FIFFB_MEAS_INFO\n");
633 t_bReadMeasBlockEnd =
true;
641 for (qint32 c = 0; c < p_pFiffInfo->nchan; ++c)
642 p_pFiffInfo->ch_names << p_pFiffInfo->chs[c].ch_name;
644 p_pDigData->npoint = p_pDigData->points.size();
646 for (
int k = 0;
k < p_pDigData->npoint;
k++) {
647 p_pDigData->active.append(1);
648 p_pDigData->discard.append(0);
651 return MetaData(p_pFiffInfo, p_pDigData);
672 qint32 nSamples = (t_pTag->size()/4)/p_nChannels;
673 data = MatrixXf(Map< MatrixXf >(t_pTag->toFloat(), p_nChannels, nSamples));