79#define MALLOC_6(x,t) (t *)malloc((x)*sizeof(t))
80#define REALLOC_6(x,y,t) (t *)((x == NULL) ? malloc((y)*sizeof(t)) : realloc((x),(y)*sizeof(t)))
81#define FREE_6(x) if ((char *)(x) != NULL) free((char *)(x))
83#define FIFFV_COORD_UNKNOWN 0
89#define VEC_DOT_6(x,y) ((x)[X_6]*(y)[X_6] + (x)[Y_6]*(y)[Y_6] + (x)[Z_6]*(y)[Z_6])
90#define VEC_LEN_6(x) sqrt(VEC_DOT_6(x,x))
92#define VEC_COPY_6(to,from) {\
93 (to)[X_6] = (from)[X_6];\
94 (to)[Y_6] = (from)[Y_6];\
95 (to)[Z_6] = (from)[Z_6];\
98static void skip_comments(FILE *in)
106 for (c = fgetc(in); c != EOF && c !=
'\n'; c = fgetc(in))
116static int whitespace(
int c)
119 if (c ==
'\t' || c ==
'\n' || c ==
' ')
125static int whitespace_quote(
int c,
int inquote)
131 return (c ==
'\t' || c ==
'\n' || c ==
' ');
134static char *next_word(FILE *in)
145 for (k = 0, p = 0, c = fgetc(in); c != EOF && !whitespace_quote(c,inquote) ; c = fgetc(in), k++) {
146 if (k == 0 && c ==
'"')
151 if (c == EOF && k == 0) {
158 for (k = 0, c = fgetc(in); whitespace(c) ; c = fgetc(in), k++)
165 printf(
"<%s>\n",next);
170static int get_ival(FILE *in,
int *ival)
173 char *next = next_word(in);
175 qWarning(
"missing integer");
178 else if (sscanf(next,
"%d",ival) != 1) {
179 qWarning(
"bad integer : %s",next);
187static int get_fval(FILE *in,
float *fval)
190 char *next = next_word(in);
191 setlocale(LC_NUMERIC,
"C");
193 qWarning(
"bad integer");
196 else if (sscanf(next,
"%g",fval) != 1) {
197 qWarning(
"bad floating point number : %s",next);
205static void normalize(
float *rr)
213 for (k = 0; k < 3; k++)
220 int type,
int coil_class,
int acc,
int np,
float size,
float base,
const QString& desc)
226 qWarning (
"No coil definition set to augment.");
230 qWarning(
"Number of integration points should be positive (type = %d acc = %d)",type,acc);
236 qWarning(
"Illegal accuracy (type = %d acc = %d)",type,acc);
243 qWarning(
"Illegal coil class (type = %d acc = %d class = %d)",type,acc,coil_class);
284 for (
int k = 0; k <
ncoil; k++)
300 qWarning() << ch.
ch_name <<
"is not a MEG channel. Cannot create a coil definition.";
306 for (k = 0, def = NULL; k < this->
ncoil; k++) {
308 this->coils[k]->accuracy == acc) {
309 def = this->
coils[k];
313 printf(
"Desired coil definition not found (type = %d acc = %d)",ch.
chpos.
coil_type,acc);
322 if (!def->
desc.isEmpty())
347 for (p = 0; p < res->
np; p++) {
348 res->
w[p] = def->
w[p];
349 for (c = 0; c < 3; c++) {
372 for (k = 0; k < nch; k++) {
398 for (k = 0; k < nch; k++) {
421 FILE *in = fopen(
name.toUtf8().constData(),
"r");
423 int type,coil_class,acc,np;
430 qWarning() <<
"FwdCoilSet::read_coil_defs - File is NULL" <<
name;
439 if (get_ival(in,&coil_class) !=
OK)
441 if (get_ival(in,&type) !=
OK)
443 if (get_ival(in,&acc) !=
OK)
445 if (get_ival(in,&np) !=
OK)
447 if (get_fval(in,&size) !=
OK)
449 if (get_fval(in,&base) !=
OK)
451 desc = next_word(in);
455 def = fwd_add_coil_to_set(res,type,coil_class,acc,np,size,base,desc);
458 FREE_6(desc); desc = NULL;
460 for (p = 0; p < def->
np; p++) {
464 if (get_fval(in,def->
w+p) !=
OK)
480 qWarning(
"Unreasonable integration point: %f %f %f mm (coil type = %d acc = %d)", 1000*def->
rmag[p][
X_6],1000*def->
rmag[p][
Y_6],1000*def->
rmag[p][
Z_6], def->
type,def->
accuracy);
488 normalize(def->
cosmag[p]);
494 printf(
"%d coil definitions read\n",res->
ncoil);
513 qWarning(
"Coordinate frame of the transformation does not match the coil set in fwd_dup_coil_set");
526 for (
int k = 0; k < this->
ncoil; k++) {
537 for (
int p = 0; p < coil->
np; p++) {
553 for (
int k = 0; k < this->
ncoil; k++)
554 if (this->
coils[k]->type == type)
565 for (
int k = 0; k < this->
ncoil; k++)
566 if (this->
coils[k]->type == type)
579 for (
int k = 0; k < this->
ncoil; k++)
580 if (this->
coils[k]->type == type)
#define FIFFV_COORD_DEVICE
#define FIFFV_COORD_UNKNOWN
FiffChInfo class declaration.
#define VEC_COPY_6(to, from)
#define REALLOC_6(x, y, t)
FwdCoil class declaration.
#define FWD_COIL_ACCURACY_ACCURATE
#define FWD_COIL_ACCURACY_NORMAL
#define FWD_COIL_ACCURACY_POINT
#define FWD_COILC_AXIAL_GRAD2
#define FWD_COILC_AXIAL_GRAD
#define FWD_COILC_PLANAR_GRAD
FwdCoilSet class declaration.
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Forward modelling (BEM, MEG/EEG lead fields).
Coordinate transformation description.
Single MEG or EEG sensor coil with integration points, weights, and coordinate frame.
static FwdCoil * create_eeg_el(const FIFFLIB::FiffChInfo &ch, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
Collection of FwdCoil objects representing a full MEG or EEG sensor array.
bool is_axial_coil_type(int type) const
FwdCoil * create_meg_coil(const FIFFLIB::FiffChInfo &ch, int acc, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
static FwdCoilSet * create_eeg_els(const QList< FIFFLIB::FiffChInfo > &chs, int nch, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
void fwd_free_coil_set_user_data()
FwdCoilSet * dup_coil_set(const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans()) const
bool is_magnetometer_coil_type(int type) const
static FwdCoilSet * read_coil_defs(const QString &name)
fwdUserFreeFunc user_data_free
FwdCoilSet * create_meg_coils(const QList< FIFFLIB::FiffChInfo > &chs, int nch, int acc, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
bool is_planar_coil_type(int type) const
bool is_eeg_electrode_type(int type) const
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const