53 using namespace FIFFLIB;
54 using namespace UTILSLIB;
55 using namespace Eigen;
78 , file_id(p_FiffInfo.file_id)
79 , sfreq(p_FiffInfo.sfreq)
80 , linefreq(p_FiffInfo.linefreq)
81 , highpass(p_FiffInfo.highpass)
82 , lowpass(p_FiffInfo.lowpass)
83 , proj_id(p_FiffInfo.proj_id)
84 , proj_name(p_FiffInfo.proj_name)
85 , xplotter_layout(p_FiffInfo.xplotter_layout)
86 , experimenter(p_FiffInfo.experimenter)
87 , description(p_FiffInfo.description)
88 , utc_offset(p_FiffInfo.utc_offset)
89 , gantry_angle(p_FiffInfo.gantry_angle)
90 , dev_ctf_t(p_FiffInfo.dev_ctf_t)
92 , dig_trans(p_FiffInfo.dig_trans)
93 , projs(p_FiffInfo.projs)
94 , comps(p_FiffInfo.comps)
95 , acq_pars(p_FiffInfo.acq_pars)
96 , acq_stim(p_FiffInfo.acq_stim)
140 qint32 first_comp = -1;
145 if (this->
chs[k].kind == FIFFV_MEG_CH)
147 comp = this->
chs[
k].chpos.coil_type >> 16;
150 else if (comp != first_comp)
151 printf(
"Compensation is not set equally on all MEG channels");
161 MatrixXd C1, C2, comp_tmp;
165 ctf_comp.data->clear();
169 ctf_comp.data->data = MatrixXd::Identity(this->
nchan, this->
nchan);
179 printf(
"Cannot create compensator C1\n");
180 printf(
"Desired compensation matrix (kind = %d) not found\n",from);
191 printf(
"Cannot create compensator C2\n");
192 printf(
"Desired compensation matrix (kind = %d) not found\n",to);
201 comp_tmp = MatrixXd::Identity(this->
nchan,this->
nchan) + C1 - C2 - C2*C1;
204 if (exclude_comp_chs)
206 VectorXi pick = MatrixXi::Zero(1,this->
nchan);
218 printf(
"Nothing remains after excluding the compensation channels\n");
222 ctf_comp.data->data.resize(npick,this->nchan);
223 for (
k = 0;
k < npick; ++
k)
224 ctf_comp.data->data.row(
k) = comp_tmp.block(pick(
k), 0, 1, this->nchan);
226 ctf_comp.data->data = comp_tmp;
237 MatrixXd presel, postsel;
238 qint32
k, col, c, ch=0, row, row_ch=0, channelAvailable;
240 for (
k = 0;
k < this->comps.size(); ++
k)
242 if (this->comps[
k].kind == kind)
244 this_data = this->comps[
k].data;
249 presel = MatrixXd::Zero(this_data->ncol,this->nchan);
251 for(col = 0; col < this_data->ncol; ++col)
253 channelAvailable = 0;
254 for (c = 0; c < this->ch_names.size(); ++c)
256 if (QString::compare(this_data->col_names.at(col),this->ch_names.at(c)) == 0)
262 if (channelAvailable == 0)
264 printf(
"Channel %s is not available in data\n",this_data->col_names.at(col).toUtf8().constData());
267 else if (channelAvailable > 1)
269 printf(
"Ambiguous channel %s",this_data->col_names.at(col).toUtf8().constData());
272 presel(col,ch) = 1.0;
277 postsel = MatrixXd::Zero(this->nchan,this_data->nrow);
279 for (c = 0; c < this->nchan; ++c)
281 channelAvailable = 0;
282 for (row = 0; row < this_data->row_names.size(); ++row)
284 if (QString::compare(this->ch_names.at(c),this_data->row_names.at(row)) == 0)
290 if (channelAvailable > 1)
292 printf(
"Ambiguous channel %s", this->ch_names.at(c).toUtf8().constData());
295 else if (channelAvailable == 1)
297 postsel(c,row_ch) = 1.0;
300 this_comp = postsel*this_data->data*presel;
304 this_comp = defaultMatrixXd;
321 for(qint32 i = 0; i < sel.size(); ++i)
324 res.
chs.append(this->
chs[idx]);
327 res.
nchan =
static_cast<int>(sel.size());
336 QList<FiffChInfo> newList;
338 fiff_int_t coil_type;
340 for(
k = 0;
k < listFiffChInfo.size(); ++
k)
341 newList.append(listFiffChInfo[
k]);
343 qint32 lower_half = 65535;
344 for (
k = 0;
k < listFiffChInfo.size(); ++
k)
346 if (listFiffChInfo[
k].kind == FIFFV_MEG_CH)
348 coil_type = listFiffChInfo[
k].chpos.coil_type & lower_half;
349 newList[
k].chpos.coil_type = (coil_type | (value << 16));
362 fiff_int_t data_type = 4;
364 QList<FiffChInfo>
chs;
390 bool have_hpi_result =
false;
391 bool have_isotrak =
false;
395 if (!this->
acq_pars.isEmpty() || !this->acq_stim.isEmpty())
409 if (!have_hpi_result)
420 if (this->
dig.size() > 0 && !have_isotrak)
423 for (qint32
k = 0;
k < this->
dig.size(); ++
k)
439 if (this->
bads.size() > 0)
443 p_pStream->
end_block(FIFFB_MNE_BAD_CHANNELS);
465 MatrixXd cals(1,
nchan);
474 cals(0,
k) =
static_cast<double>(
chs[
k].cal);
486 std::cout <<
"Sample frequency: " <<
sfreq <<
"\n";
488 std::cout <<
"Number of digitizer points: " <<
dig.size() <<
"\n";
489 for (
auto& point :
dig){
490 if (point.kind == FIFFV_POINT_HPI){
491 std::cout <<
"HPI Point " << point.ident <<
" - " << point.r[0] <<
", " << point.r[1] <<
", " << point.r[2] <<
"\n";