56 using namespace Eigen;
57 using namespace FIFFLIB;
58 using namespace MNELIB;
59 using namespace FWDLIB;
60 using namespace INVERSELIB;
83 #define VEC_COPY_16(to,from) {\
84 (to)[X_16] = (from)[X_16];\
85 (to)[Y_16] = (from)[Y_16];\
86 (to)[Z_16] = (from)[Z_16];\
89 #define MALLOC_16(x,t) (t *)malloc((x)*sizeof(t))
91 #define REALLOC_16(x,y,t) (t *)((x == NULL) ? malloc((y)*sizeof(t)) : realloc((x),(y)*sizeof(t)))
93 #define ALLOC_CMATRIX_16(x,y) mne_cmatrix_16((x),(y))
95 static void matrix_error_16(
int kind,
int nr,
int nc)
99 printf(
"Failed to allocate memory pointers for a %d x %d matrix\n",nr,nc);
101 printf(
"Failed to allocate memory for a %d x %d matrix\n",nr,nc);
103 printf(
"Allocation error for a %d x %d matrix\n",nr,nc);
104 if (
sizeof(
void *) == 4) {
105 printf(
"This is probably because you seem to be using a computer with 32-bit architecture.\n");
106 printf(
"Please consider moving to a 64-bit platform.");
108 printf(
"Cannot continue. Sorry.\n");
112 float **mne_cmatrix_16(
int nr,
int nc)
119 m = MALLOC_16(nr,
float *);
120 if (!m) matrix_error_16(1,nr,nc);
121 whole = MALLOC_16(nr*nc,
float);
122 if (!whole) matrix_error_16(2,nr,nc);
129 #define FREE_16(x) if ((char *)(x) != NULL) free((char *)(x))
130 #define FREE_CMATRIX_16(m) mne_free_cmatrix_16((m))
132 void mne_free_cmatrix_16 (
float **m)
140 void fromFloatEigenMatrix_16(
const Eigen::MatrixXf& from_mat,
float **& to_mat,
const int m,
const int n)
142 for (
int i = 0; i < m; ++i)
143 for (
int j = 0; j < n; ++j)
144 to_mat[i][j] = from_mat(i,j);
147 void fromFloatEigenMatrix_16(
const Eigen::MatrixXf& from_mat,
float **& to_mat)
149 fromFloatEigenMatrix_16(from_mat, to_mat, from_mat.rows(), from_mat.cols());
153 void fromIntEigenMatrix_16(
const Eigen::MatrixXi& from_mat,
int **&to_mat,
const int m,
const int n)
155 for (
int i = 0; i < m; ++i)
156 for (
int j = 0; j < n; ++j)
157 to_mat[i][j] = from_mat(i,j);
160 void fromIntEigenMatrix_16(
const Eigen::MatrixXi& from_mat,
int **&to_mat)
162 fromIntEigenMatrix_16(from_mat, to_mat, from_mat.rows(), from_mat.cols());
169 GuessData::GuessData()
190 float guessrad = 0.080;
194 if (!guessname.isEmpty()) {
198 if (MneSurfaceOrVolume::mne_read_source_spaces(guessname,&sp,&nsp) == FAIL)
201 printf(
"Incorrect number of source spaces in guess file");
202 for (
k = 0;
k < nsp;
k++)
207 printf(
"Read guesses from %s\n",guessname.toUtf8().constData());
208 guesses = sp[0]; FREE_16(sp);
212 int free_inner_skull = FALSE;
215 VEC_COPY_16(r0,f->
r0);
216 FiffCoordTransOld::fiff_coord_trans_inv(r0,f->
mri_head_t,TRUE);
218 printf(
"Using inner skull surface from the BEM (%s)...\n",f->
bemname.toUtf8().constData());
219 if ((inner_skull = f->
bem_model->fwd_bem_find_surface(FIFFV_BEM_SURF_ID_BRAIN)) == NULL)
222 else if (!guess_surfname.isEmpty()) {
223 printf(
"Reading inner skull surface from %s...\n",guess_surfname.toUtf8().data());
224 if ((inner_skull = MneSurfaceOrVolume::read_bem_surface(guess_surfname,FIFFV_BEM_SURF_ID_BRAIN,TRUE,NULL)) == NULL)
226 free_inner_skull = TRUE;
228 if ((guesses = (
MneSourceSpaceOld*)FwdBemModel::make_guesses(inner_skull,guessrad,r0,grid,exclude,mindist)) == NULL)
230 if (free_inner_skull)
233 if (MneSurfaceOrVolume::mne_transform_source_spaces_to(f->
coord_frame,f->
mri_head_t,&guesses,1) != OK)
235 printf(
"Guess locations are now in %s coordinates.\n",FiffCoordTransOld::mne_coord_frame_name(f->
coord_frame));
236 this->
nguess = guesses->nuse;
237 this->
rr = ALLOC_CMATRIX_16(guesses->nuse,3);
238 for (
k = 0, p = 0;
k < guesses->np;
k++)
239 if (guesses->inuse[
k]) {
240 VEC_COPY_16(this->
rr[p],guesses->rr[
k]);
243 delete guesses; guesses = NULL;
245 printf(
"Go through all guess source locations...");
258 for (
k = 0;
k < this->
nguess; k++) {
259 if ((this->
guess_fwd[k] = DipoleFitData::dipole_forward_one(f,this->
rr[k],NULL)) == NULL)
263 printf(
"%f %f %f\n",sing[0],sing[1],sing[2]);
268 printf(
"[done %d sources]\n",p);
289 float guessrad = 0.080f;
292 if (!guessname.isEmpty()) {
296 if (MneSurfaceOrVolume::mne_read_source_spaces(guessname,&sp,&nsp) == FIFF_FAIL)
299 qCritical(
"Incorrect number of source spaces in guess file");
300 for (
k = 0;
k < nsp;
k++)
305 printf(
"Read guesses from %s\n",guessname.toUtf8().constData());
306 guesses = sp[0]; FREE_16(sp);
310 int free_inner_skull = FALSE;
313 VEC_COPY_16(r0,f->
r0);
314 FiffCoordTransOld::fiff_coord_trans_inv(r0,f->
mri_head_t,TRUE);
316 printf(
"Using inner skull surface from the BEM (%s)...\n",f->
bemname.toUtf8().constData());
317 if ((inner_skull = f->
bem_model->fwd_bem_find_surface(FIFFV_BEM_SURF_ID_BRAIN)) == NULL)
320 else if (!guess_surfname.isEmpty()) {
321 printf(
"Reading inner skull surface from %s...\n",guess_surfname.toUtf8().data());
322 if ((inner_skull = MneSurfaceOrVolume::read_bem_surface(guess_surfname,FIFFV_BEM_SURF_ID_BRAIN,TRUE,NULL)) == NULL)
324 free_inner_skull = TRUE;
326 if ((guesses = (
MneSourceSpaceOld*)FwdBemModel::make_guesses(inner_skull,guessrad,r0,grid,exclude,mindist)) == NULL)
328 if (free_inner_skull)
334 if (guesses->nuse == 0) {
335 qCritical(
"No active guess locations remaining.");
338 if (guess_save_name) {
339 printf(
"###################DEBUG writing source spaces not yet implemented.");
347 if (MneSurfaceOrVolume::mne_transform_source_spaces_to(f->
coord_frame,f->
mri_head_t,&guesses,1) != OK)
349 printf(
"Guess locations are now in %s coordinates.\n",FiffCoordTransOld::mne_coord_frame_name(f->
coord_frame));
351 this->
nguess = guesses->nuse;
352 this->
rr = ALLOC_CMATRIX_16(guesses->nuse,3);
353 for (
k = 0, p = 0;
k < guesses->np;
k++)
354 if (guesses->inuse[
k]) {
355 VEC_COPY_16(this->
rr[p],guesses->rr[
k]);
400 qCritical(
"Data missing in compute_guess_fields");
404 qCritical(
"Noise covariance missing in compute_guess_fields");
407 printf(
"Go through all guess source locations...");
421 printf(
"%f %f %f\n",sing[0],sing[1],sing[2]);
425 printf(
"[done %d sources]\n",this->nguess);