56 using namespace Eigen;
57 using namespace FIFFLIB;
58 using namespace FWDLIB;
60 #define MALLOC_5(x,t) (t *)malloc((x)*sizeof(t))
62 #define FREE_5(x) if ((char *)(x) != NULL) free((char *)(x))
63 #define FREE_CMATRIX_5(m) mne_free_cmatrix_5((m))
65 #define ALLOC_CMATRIX_5(x,y) mne_cmatrix_5((x),(y))
71 #define VEC_DOT_5(x,y) ((x)[X_5]*(y)[X_5] + (x)[Y_5]*(y)[Y_5] + (x)[Z_5]*(y)[Z_5])
72 #define VEC_LEN_5(x) sqrt(VEC_DOT_5(x,x))
74 #define VEC_COPY_5(to,from) {\
75 (to)[X_5] = (from)[X_5];\
76 (to)[Y_5] = (from)[Y_5];\
77 (to)[Z_5] = (from)[Z_5];\
80 static void matrix_error_5(
int kind,
int nr,
int nc)
84 printf(
"Failed to allocate memory pointers for a %d x %d matrix\n",nr,nc);
86 printf(
"Failed to allocate memory for a %d x %d matrix\n",nr,nc);
88 printf(
"Allocation error for a %d x %d matrix\n",nr,nc);
89 if (
sizeof(
void *) == 4) {
90 printf(
"This is probably because you seem to be using a computer with 32-bit architecture.\n");
91 printf(
"Please consider moving to a 64-bit platform.");
93 printf(
"Cannot continue. Sorry.\n");
97 float **mne_cmatrix_5(
int nr,
int nc)
104 m = MALLOC_5(nr,
float *);
105 if (!m) matrix_error_5(1,nr,nc);
106 whole = MALLOC_5(nr*nc,
float);
107 if (!whole) matrix_error_5(2,nr,nc);
114 void mne_free_cmatrix_5 (
float **m)
122 static void normalize_5(
float *rr)
127 float ll = VEC_LEN_5(rr);
130 for (
k = 0;
k < 3;
k++)
140 FwdCoil::FwdCoil(
int p_np)
142 coil_class = FWD_COILC_UNKNOWN;
143 accuracy = FWD_COIL_ACCURACY_POINT;
147 rmag = ALLOC_CMATRIX_5(np,3);
148 cosmag = ALLOC_CMATRIX_5(np,3);
149 w = MALLOC_5(np,
float);
153 for (
int k = 0;
k < 3;
k++) {
168 if (!p_FwdCoil.
chname.isEmpty())
169 this->chname = p_FwdCoil.
chname;
170 if (!p_FwdCoil.
desc.isEmpty())
171 this->desc = p_FwdCoil.
desc;
173 this->accuracy = p_FwdCoil.
accuracy;
174 this->base = p_FwdCoil.
base;
175 this->size = p_FwdCoil.
size;
176 this->np = p_FwdCoil.
np;
177 this->type = p_FwdCoil.
type;
179 rmag = ALLOC_CMATRIX_5(this->np,3);
180 cosmag = ALLOC_CMATRIX_5(this->np,3);
181 w = MALLOC_5(this->np,
float);
183 VEC_COPY_5(this->r0,p_FwdCoil.
r0);
184 VEC_COPY_5(this->ex,p_FwdCoil.
ex);
185 VEC_COPY_5(this->ey,p_FwdCoil.
ey);
186 VEC_COPY_5(this->ez,p_FwdCoil.
ez);
188 for (
int p = 0; p < p_FwdCoil.
np; p++) {
189 this->w[p] = p_FwdCoil.
w[p];
190 VEC_COPY_5(this->rmag[p],p_FwdCoil.
rmag[p]);
191 VEC_COPY_5(this->cosmag[p],p_FwdCoil.
cosmag[p]);
200 FREE_CMATRIX_5(rmag);
201 FREE_CMATRIX_5(cosmag);
212 if (ch.
kind != FIFFV_EEG_CH) {
213 qWarning() << ch.
ch_name <<
"is not an EEG channel. Cannot create an electrode definition.";
216 if (t && t->
from != FIFFV_COORD_HEAD) {
217 printf(
"Inappropriate coordinate transformation in fwd_create_eeg_el");
227 res->
desc =
"EEG electrode";
229 res->
accuracy = FWD_COIL_ACCURACY_NORMAL;
237 FiffCoordTransOld::fiff_coord_trans(res->
r0,t,FIFFV_MOVE);
238 FiffCoordTransOld::fiff_coord_trans(res->
ex,t,FIFFV_MOVE);
246 for (c = 0; c < 3; c++)
248 normalize_5(res->
cosmag[0]);
254 for (c = 0; c < 3; c++)
256 normalize_5(res->
cosmag[1]);
268 bool FwdCoil::is_axial_coil()
const
270 return (this->coil_class == FWD_COILC_MAG ||
271 this->coil_class == FWD_COILC_AXIAL_GRAD ||
272 this->coil_class == FWD_COILC_AXIAL_GRAD2);
277 bool FwdCoil::is_magnetometer_coil()
const
279 return this->coil_class == FWD_COILC_MAG;
284 bool FwdCoil::is_planar_coil()
const
286 return this->coil_class == FWD_COILC_PLANAR_GRAD;
291 bool FwdCoil::is_eeg_electrode()
const
293 return this->coil_class == FWD_COILC_EEG;