74 , file_id(
FiffId(p_FiffInfo.file_id))
75 , sfreq(p_FiffInfo.sfreq)
76 , highpass(p_FiffInfo.highpass)
77 , lowpass(p_FiffInfo.lowpass)
78 , dev_ctf_t(p_FiffInfo.dev_ctf_t)
79 , dig_trans(p_FiffInfo.dig_trans)
80 , acq_pars(p_FiffInfo.acq_pars)
81 , acq_stim(p_FiffInfo.acq_stim)
87 for(i = 0; i < p_FiffInfo.
dig.size(); ++i)
90 for(i = 0; i < p_FiffInfo.
projs.size(); ++i)
93 for(i = 0; i < p_FiffInfo.
comps.size(); ++i)
131 qint32 first_comp = -1;
134 for (k = 0; k < this->
nchan; ++k)
136 if (this->
chs[k].kind == FIFFV_MEG_CH)
138 comp = this->
chs[k].coil_type >> 16;
141 else if (comp != first_comp)
142 printf(
"Compensation is not set equally on all MEG channels");
153 qDebug() <<
"make_compensator not debugged jet";
155 MatrixXd C1, C2, comp_tmp;
157 qDebug() <<
"Todo add all need ctf variables.";
160 ctf_comp.
data->clear();
174 printf(
"Cannot create compensator C1\n");
175 printf(
"Desired compensation matrix (kind = %d) not found\n",from);
186 printf(
"Cannot create compensator C2\n");
187 printf(
"Desired compensation matrix (kind = %d) not found\n",to);
196 comp_tmp = MatrixXd::Identity(this->
nchan,this->
nchan) + C1 - C2 - C2*C1;
199 if (exclude_comp_chs)
201 VectorXi pick = MatrixXi::Zero(1,this->
nchan);
203 for (k = 0; k < this->
nchan; ++k)
205 if (this->
chs[k].kind != FIFFV_REF_MEG_CH)
213 printf(
"Nothing remains after excluding the compensation channels\n");
217 ctf_comp.
data->data.resize(npick,this->nchan);
218 for (k = 0; k < npick; ++k)
219 ctf_comp.
data->data.row(k) = comp_tmp.block(pick(k), 0, 1, this->nchan);
229 qDebug() <<
"make_compensator not debugged jet";
231 MatrixXd presel, postsel;
232 qint32 k, col, c, ch, row, row_ch=0, channelAvailable;
233 for (k = 0; k < this->comps.size(); ++k)
235 if (this->comps[k].kind == kind)
236 { this_data = this->comps[k].data;
240 presel = MatrixXd::Zero(this_data->ncol,this->nchan);
241 for(col = 0; col < this_data->ncol; ++col)
243 channelAvailable = 0;
244 for (c = 0; c < this->ch_names.size(); ++c)
246 if (QString::compare(this_data->col_names.at(col),this->ch_names.at(c)) == 0)
252 if (channelAvailable == 0)
254 printf(
"Channel %s is not available in data\n",this_data->col_names.at(col).toUtf8().constData());
257 else if (channelAvailable > 1)
259 printf(
"Ambiguous channel %s",this_data->col_names.at(col).toUtf8().constData());
262 presel(col,ch) = 1.0;
267 postsel = MatrixXd::Zero(this->nchan,this_data->nrow);
268 for (c = 0; c < this->nchan; ++c)
270 channelAvailable = 0;
271 for (row = 0; row < this_data->row_names.size(); ++row)
273 if (QString::compare(this_data->col_names.at(c),this->ch_names.at(row)) == 0)
279 if (channelAvailable > 1)
281 printf(
"Ambiguous channel %s", this->ch_names.at(c).toUtf8().constData());
284 else if (channelAvailable == 1)
286 postsel(c,row_ch) = 1.0;
289 this_comp = postsel*this_data->data*presel;
293 this_comp = defaultMatrixXd;
311 for(qint32 i = 0; i < sel.size(); ++i)
314 res.
chs.append(this->
chs[idx]);
317 res.
nchan = sel.size();
327 QList<FiffChInfo> new_chs;
329 fiff_int_t coil_type;
331 for(k = 0; k < chs.size(); ++k)
332 new_chs.append(chs[k]);
334 qint32 lower_half = 65535;
335 for (k = 0; k < chs.size(); ++k)
337 if (chs[k].kind == FIFFV_MEG_CH)
339 coil_type = chs[k].coil_type & lower_half;
340 new_chs[k].coil_type = (coil_type | (value << 16));
354 fiff_int_t data_type = 4;
356 QList<FiffChInfo>
chs;
358 for(k = 0; k < this->
nchan; ++k)
361 fiff_int_t nchan = chs.size();
382 bool have_hpi_result =
false;
383 bool have_isotrak =
false;
391 p_pStream->
write_string(FIFF_DACQ_PARS, this->acq_pars);
394 p_pStream->
write_string(FIFF_DACQ_STIM, this->acq_stim);
401 if (!have_hpi_result)
412 if (this->
dig.size() > 0 && !have_isotrak)
415 for (qint32 k = 0; k < this->
dig.size(); ++k)
431 if (this->
bads.size() > 0)
435 p_pStream->
end_block(FIFFB_MNE_BAD_CHANNELS);
444 p_pStream->
write_int(FIFF_DATA_PACK,&data_type);
450 MatrixXd cals(1,nchan);
452 for(k = 0; k <
nchan; ++k)
459 cals(0,k) = chs[k].cal;
void write_string(fiff_int_t kind, const QString &data)
QList< FiffCtfComp > comps
FIFF measurement file information.
Digitization point description.
QSharedDataPointer< FiffNamedMatrix > SDPtr
Universially unique identifier.
FiffInfo pick_info(const RowVectorXi &sel=defaultVectorXi) const
qint32 get_current_comp()
FiffCoordTrans ctf_head_t
void set_current_comp(fiff_int_t value)
void write_dig_point(const FiffDigPoint &dig)
void writeToStream(FiffStream *p_pStream)
void write_float(fiff_int_t kind, const float *data, fiff_int_t nel=1)
FiffInfo class declaration.
void write_int(fiff_int_t kind, const fiff_int_t *data, fiff_int_t nel=1)
void start_block(fiff_int_t kind)
FiffNamedMatrix::SDPtr data
FiffStream class declaration.
void write_ctf_comp(const QList< FiffCtfComp > &comps)
bool make_compensator(fiff_int_t from, fiff_int_t to, FiffCtfComp &ctf_comp, bool exclude_comp_chs=false) const
void write_ch_info(FiffChInfo *ch)
FiffCoordTrans dev_head_t
void write_proj(const QList< FiffProj > &projs)
void write_coord_trans(const FiffCoordTrans &trans)
QList< FiffDigPoint > dig
void write_id(fiff_int_t kind, const FiffId &id=defaultFiffId)
CTF software compensation data.
void write_name_list(fiff_int_t kind, const QStringList &data)
void end_block(fiff_int_t kind)