57using namespace FIFFLIB;
58using 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];\
80static 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");
97float **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);
114void mne_free_cmatrix_5 (
float **m)
122static void normalize_5(
float *rr)
127 float ll = VEC_LEN_5(rr);
130 for (
k = 0;
k < 3;
k++)
147 rmag = 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())
170 if (!p_FwdCoil.
desc.isEmpty())
176 this->
np = p_FwdCoil.
np;
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]);
200 FREE_CMATRIX_5(
rmag);
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]);
286 return this->
coil_class == FWD_COILC_PLANAR_GRAD;
FiffChInfo class declaration.
FwdCoil class declaration.
Coordinate transformation descriptor.
bool is_eeg_electrode() const
bool is_planar_coil() const
bool is_axial_coil() const
bool is_magnetometer_coil() const
static FwdCoil * create_eeg_el(const FIFFLIB::FiffChInfo &ch, const FIFFLIB::FiffCoordTransOld *t)