68 #define MALLOC_60(x,t) (t *)malloc((x)*sizeof(t))
70 #define ALLOC_CMATRIX_60(x,y) mne_cmatrix_60((x),(y))
72 #define FREE_60(x) if ((char *)(x) != NULL) free((char *)(x))
74 #define FREE_CMATRIX_60(m) mne_free_cmatrix_60((m))
76 void mne_free_cmatrix_60 (
float **m)
84 static void matrix_error_60 (
int kind,
int nr,
int nc)
87 printf(
"Failed to allocate memory pointers for a %d x %d matrix\n",nr,nc);
89 printf(
"Failed to allocate memory for a %d x %d matrix\n",nr,nc);
91 printf(
"Allocation error for a %d x %d matrix\n",nr,nc);
92 if (
sizeof(
void *) == 4) {
93 printf(
"This is probably because you seem to be using a computer with 32-bit architecture.\n");
94 printf(
"Please consider moving to a 64-bit platform.");
96 printf(
"Cannot continue. Sorry.\n");
100 float **mne_cmatrix_60 (
int nr,
int nc)
106 m = MALLOC_60(nr,
float *);
107 if (!m) matrix_error_60(1,nr,nc);
108 whole = MALLOC_60(nr*nc,
float);
109 if (!whole) matrix_error_60(2,nr,nc);
120 using namespace Eigen;
121 using namespace FIFFLIB;
122 using namespace MNELIB;
123 using namespace FWDLIB;
129 FwdCompData::FwdCompData()
148 delete this->comp_coils;
152 FREE_CMATRIX_60(this->vec_work);
154 if (this->client_free && this->client)
155 this->client_free(this->client);
160 int FwdCompData::fwd_comp_field(
float *rd,
float *Q,
FwdCoilSet *coils,
float *res,
void *client)
168 printf(
"Field computation function is missing in fwd_comp_field_vec");
174 if (comp->field(rd,Q,coils,res,comp->client) == FAIL)
179 if (!comp->comp_coils || comp->comp_coils->ncoil <= 0 || !comp->set || !comp->set->current)
185 comp->work = MALLOC_60(comp->comp_coils->ncoil,
float);
189 if (comp->field(rd,Q,comp->comp_coils,comp->work,comp->client) == FAIL)
194 return MneCTFCompDataSet::mne_apply_ctf_comp(comp->set,TRUE,res,coils->ncoil,comp->work,comp->comp_coils->ncoil);
199 void FwdCompData::fwd_free_comp_data(
void *d)
206 if (comp->client_free && comp->client)
207 comp->client_free(comp->client);
223 QList<FiffChInfo> chs;
224 QList<FiffChInfo> compchs;
230 if (!coils || coils->ncoil <= 0) {
231 printf(
"Coil data missing in fwd_make_ctf_comp_coils");
238 for (
k = 0;
k < coils->ncoil;
k++) {
240 coil = coils->coils[
k];
242 chs[
k].chpos.coil_type = coil->
type;
243 chs[
k].kind = (coil->
coil_class == FWD_COILC_EEG) ? FIFFV_EEG_CH : FIFFV_MEG_CH;
245 nchan = coils->ncoil;
246 if (comp_coils && comp_coils->ncoil > 0) {
247 for (
k = 0;
k < comp_coils->ncoil;
k++) {
249 coil = comp_coils->coils[
k];
250 compchs[
k].ch_name = coil->
chname;
251 compchs[
k].chpos.coil_type = coil->
type;
252 compchs[
k].kind = (coil->
coil_class == FWD_COILC_EEG) ? FIFFV_EEG_CH : FIFFV_MEG_CH;
254 ncomp = comp_coils->ncoil;
256 res = MneCTFCompDataSet::mne_make_ctf_comp(set,chs,nchan,compchs,ncomp);
267 fwdVecFieldFunc vec_field,
268 fwdFieldGradFunc field_grad,
270 fwdUserFreeFunc client_free)
286 qWarning(
"No coils to duplicate");
287 comp->comp_coils = NULL;
290 comp->vec_field = vec_field;
291 comp->field_grad = field_grad;
292 comp->client = client;
293 comp->client_free = client_free;
295 if (fwd_make_ctf_comp_coils(comp->set,
297 comp->comp_coils) != OK) {
298 fwd_free_comp_data(comp);
308 int FwdCompData::fwd_comp_field_vec(
float *rd,
FwdCoilSet *coils,
float **res,
void *client)
316 if (!comp->vec_field) {
317 printf(
"Field computation function is missing in fwd_comp_field_vec");
323 if (comp->vec_field(rd,coils,res,comp->client) == FAIL)
328 if (!comp->comp_coils || comp->comp_coils->ncoil <= 0 || !comp->set || !comp->set->current)
334 comp->vec_work = ALLOC_CMATRIX_60(3,comp->comp_coils->ncoil);
338 if (comp->vec_field(rd,comp->comp_coils,comp->vec_work,comp->client) == FAIL)
343 for (
k = 0;
k < 3;
k++) {
344 if (MneCTFCompDataSet::mne_apply_ctf_comp(comp->set,TRUE,res[
k],coils->ncoil,comp->vec_work[
k],comp->comp_coils->ncoil) == FAIL)
352 int FwdCompData::fwd_comp_field_grad(
float *rd,
float *Q,
FwdCoilSet* coils,
float *res,
float *xgrad,
float *ygrad,
float *zgrad,
void *client)
359 if (!comp->field_grad) {
360 qCritical(
"Field and gradient computation function is missing in fwd_comp_field_grad");
366 if (comp->field_grad(rd,Q,coils,res,xgrad,ygrad,zgrad,comp->client) == FAIL)
371 if (!comp->comp_coils || comp->comp_coils->ncoil <= 0 || !comp->set || !comp->set->current)
377 comp->work = MALLOC_60(comp->comp_coils->ncoil,
float);
379 comp->vec_work = ALLOC_CMATRIX_60(3,comp->comp_coils->ncoil);
383 if (comp->field_grad(rd,Q,comp->comp_coils,comp->work,comp->vec_work[0],comp->vec_work[1],comp->vec_work[2],comp->client) == FAIL)
388 if (MneCTFCompDataSet::mne_apply_ctf_comp(comp->set,TRUE,res,coils->ncoil,comp->work,comp->comp_coils->ncoil) != OK)
390 if (MneCTFCompDataSet::mne_apply_ctf_comp(comp->set,TRUE,xgrad,coils->ncoil,comp->vec_work[0],comp->comp_coils->ncoil) != OK)
392 if (MneCTFCompDataSet::mne_apply_ctf_comp(comp->set,TRUE,ygrad,coils->ncoil,comp->vec_work[1],comp->comp_coils->ncoil) != OK)
394 if (MneCTFCompDataSet::mne_apply_ctf_comp(comp->set,TRUE,zgrad,coils->ncoil,comp->vec_work[2],comp->comp_coils->ncoil) != OK)