84#define VEC_COPY_16(to,from) {\
85 (to)[X_16] = (from)[X_16];\
86 (to)[Y_16] = (from)[Y_16];\
87 (to)[Z_16] = (from)[Z_16];\
90#define MALLOC_16(x,t) (t *)malloc((x)*sizeof(t))
92#define REALLOC_16(x,y,t) (t *)((x == nullptr) ? malloc((y)*sizeof(t)) : realloc((x),(y)*sizeof(t)))
94#define ALLOC_CMATRIX_16(x,y) mne_cmatrix_16((x),(y))
96static void matrix_error_16(
int kind,
int nr,
int nc)
100 printf(
"Failed to allocate memory pointers for a %d x %d matrix\n",nr,nc);
102 printf(
"Failed to allocate memory for a %d x %d matrix\n",nr,nc);
104 printf(
"Allocation error for a %d x %d matrix\n",nr,nc);
105 if (
sizeof(
void *) == 4) {
106 printf(
"This is probably because you seem to be using a computer with 32-bit architecture.\n");
107 printf(
"Please consider moving to a 64-bit platform.");
109 printf(
"Cannot continue. Sorry.\n");
121 if (!m) matrix_error_16(1,nr,nc);
123 if (!whole) matrix_error_16(2,nr,nc);
130#define FREE_16(x) if ((char *)(x) != nullptr) free((char *)(x))
131#define FREE_CMATRIX_16(m) mne_free_cmatrix_16((m))
143 for (
int i = 0; i < m; ++i)
144 for (
int j = 0; j < n; ++j)
145 to_mat[i][j] = from_mat(i,j);
156 for (
int i = 0; i < m; ++i)
157 for (
int j = 0; j < n; ++j)
158 to_mat[i][j] = from_mat(i,j);
187 float guessrad = 0.080;
188 std::unique_ptr<MNESourceSpace> guesses;
191 if (!guessname.isEmpty()) {
195 std::vector<std::unique_ptr<MNESourceSpace>> sp;
198 if (
static_cast<int>(sp.size()) != 1) {
199 printf(
"Incorrect number of source spaces in guess file");
202 printf(
"Read guesses from %s\n",guessname.toUtf8().constData());
203 guesses = std::move(sp[0]);
207 int free_inner_skull =
FALSE;
208 Eigen::Vector3f r0 = f->
r0;
213 printf(
"Using inner skull surface from the BEM (%s)...\n",f->
bemname.toUtf8().constData());
217 else if (!guess_surfname.isEmpty()) {
218 printf(
"Reading inner skull surface from %s...\n",guess_surfname.toUtf8().data());
221 free_inner_skull =
TRUE;
226 if (free_inner_skull)
230 std::vector<std::unique_ptr<MNESourceSpace>> guesses_vec;
231 guesses_vec.push_back(std::move(guesses));
234 guesses = std::move(guesses_vec[0]);
238 this->
nguess = guesses->nuse;
239 this->
rr.resize(guesses->nuse, 3);
240 for (k = 0, p = 0; k < guesses->np; k++)
241 if (guesses->inuse[k]) {
242 this->
rr.row(p) = guesses->rr.row(k);
247 printf(
"Go through all guess source locations...");
258 for (k = 0; k < this->
nguess; k++) {
264 printf(
"%f %f %f\n",sing[0],sing[1],sing[2]);
269 printf(
"[done %d sources]\n",p);
285 float guessrad = 0.080f;
286 std::unique_ptr<MNESourceSpace> guesses;
288 if (!guessname.isEmpty()) {
292 std::vector<std::unique_ptr<MNESourceSpace>> sp;
295 if (
static_cast<int>(sp.size()) != 1) {
296 qCritical(
"Incorrect number of source spaces in guess file");
299 printf(
"Read guesses from %s\n",guessname.toUtf8().constData());
300 guesses = std::move(sp[0]);
304 int free_inner_skull =
FALSE;
305 Eigen::Vector3f r0 = f->
r0;
310 printf(
"Using inner skull surface from the BEM (%s)...\n",f->
bemname.toUtf8().constData());
314 else if (!guess_surfname.isEmpty()) {
315 printf(
"Reading inner skull surface from %s...\n",guess_surfname.toUtf8().data());
318 free_inner_skull =
TRUE;
323 if (free_inner_skull)
329 if (guesses->nuse == 0) {
330 qCritical(
"No active guess locations remaining.");
333 if (guess_save_name) {
334 printf(
"###################DEBUG writing source spaces not yet implemented.");
343 std::vector<std::unique_ptr<MNESourceSpace>> guesses_vec;
344 guesses_vec.push_back(std::move(guesses));
347 guesses = std::move(guesses_vec[0]);
351 this->
nguess = guesses->nuse;
352 this->
rr.resize(guesses->nuse, 3);
353 for (k = 0, p = 0; k < guesses->np; k++)
354 if (guesses->inuse[k]) {
355 this->
rr.row(p) = guesses->rr.row(k);
385 qCritical(
"Data missing in compute_guess_fields");
389 qCritical(
"Noise covariance missing in compute_guess_fields");
392 printf(
"Go through all guess source locations...");
398 for (
int k = 0; k < this->
nguess; k++) {
407 printf(
"%f %f %f\n",sing[0],sing[1],sing[2]);
411 printf(
"[done %d sources]\n",this->nguess);
void fromFloatEigenMatrix_16(const Eigen::MatrixXf &from_mat, float **&to_mat, const int m, const int n)
void fromIntEigenMatrix_16(const Eigen::MatrixXi &from_mat, int **&to_mat, const int m, const int n)
float ** mne_cmatrix_16(int nr, int nc)
void mne_free_cmatrix_16(float **m)
Dipole Fit Data class declaration.
InvDipoleForward class declaration.
InvGuessData class declaration.
FiffTag class declaration, which provides fiff tag I/O and processing methods.
FiffStream class declaration.
#define FIFFV_BEM_SURF_ID_BRAIN
MNESurface class declaration.
MNESourceSpace class declaration.
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
dipoleFitFuncsRec * dipoleFitFuncs
Pointer alias for dipoleFitFuncsRec, used throughout the dipole fitting module.
Forward modelling (BEM, MEG/EEG lead fields).
static std::unique_ptr< MNELIB::MNESurface > make_guesses(MNELIB::MNESurface *guess_surf, float guessrad, const Eigen::Vector3f &guess_r0, float grid, float exclude, float mindist)
Generate a set of dipole guess locations inside a boundary surface.
Dipole fit workspace holding sensor geometry, forward model, noise covariance, and projection data.
std::unique_ptr< FIFFLIB::FiffCoordTrans > mri_head_t
static InvDipoleForward * dipole_forward_one(InvDipoleFitData *d, const Eigen::Vector3f &rd, InvDipoleForward *old)
Compute the forward solution for a single dipole position.
std::unique_ptr< MNELIB::MNECovMatrix > noise
std::unique_ptr< dipoleFitFuncsRec > sphere_funcs
std::unique_ptr< FWDLIB::FwdBemModel > bem_model
std::unique_ptr< dipoleFitFuncsRec > mag_dipole_funcs
dipoleFitFuncsRec * funcs
std::vector< InvDipoleForward::UPtr > guess_fwd
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > rr
bool compute_guess_fields(InvDipoleFitData *f)
This defines a source space.
static int read_source_spaces(const QString &name, std::vector< std::unique_ptr< MNESourceSpace > > &spaces)
static int transform_source_spaces_to(int coord_frame, const FIFFLIB::FiffCoordTrans &t, std::vector< std::unique_ptr< MNESourceSpace > > &spaces)
static MNESurface * read_bem_surface(const QString &name, int which, int add_geometry, float *sigmap)
Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
static QString frame_name(int frame)