v2.0.0
Loading...
Searching...
No Matches
fwd_bem_model.h
Go to the documentation of this file.
1//=============================================================================================================
38
39#ifndef FWD_BEM_MODEL_H
40#define FWD_BEM_MODEL_H
41
42//=============================================================================================================
43// INCLUDES
44//=============================================================================================================
45
46#include "fwd_global.h"
47#include "fwd_coil_set.h"
48
50#include <fiff/fiff_dir_node.h>
51#include <fiff/fiff_tag.h>
53
54#include <memory>
55#include <vector>
56
57//=============================================================================================================
58// EIGEN INCLUDES
59//=============================================================================================================
60
61#include <Eigen/Core>
62
63//=============================================================================================================
64// QT INCLUDES
65//=============================================================================================================
66
67#include <QString>
68
69//=============================================================================================================
70// BEM METHOD CONSTANTS
71//=============================================================================================================
72
73namespace FWDLIB
74{
75
76constexpr int FWD_BEM_UNKNOWN = -1;
77constexpr int FWD_BEM_CONSTANT_COLL = 1;
78constexpr int FWD_BEM_LINEAR_COLL = 2;
79
80constexpr float FWD_BEM_IP_APPROACH_LIMIT = 0.1f;
81
82constexpr int FWD_BEM_LIN_FIELD_SIMPLE = 1;
84constexpr int FWD_BEM_LIN_FIELD_URANKAR = 3;
85
86} // namespace FWDLIB
87
88//=============================================================================================================
89// FORWARD DECLARATIONS
90//=============================================================================================================
91
92namespace MNELIB
93{
94class MNETriangle;
95class MNESurface;
96class MNESourceSpace;
97class MNECTFCompDataSet;
98class MNENamedMatrix;
99}
100
101namespace FIFFLIB
102{
103class FiffNamedMatrix;
104}
105//=============================================================================================================
106// DEFINE NAMESPACE FWDLIB
107//=============================================================================================================
108
109namespace FWDLIB
110{
111
112//=============================================================================================================
113// FWDLIB FORWARD DECLARATIONS
114//=============================================================================================================
115
117class FwdThreadArg;
118
119//=============================================================================================================
136{
137public:
138 typedef std::unique_ptr<FwdBemModel> UPtr;
139
140 //=========================================================================================================
147 explicit FwdBemModel();
148
149 //=========================================================================================================
156 virtual ~FwdBemModel();
157
158 //=========================================================================================================
166
173 static QString fwd_bem_make_bem_sol_name(const QString& name);
174
175 //============================= fwd_bem_model.c =============================
176
183 static const QString& fwd_bem_explain_surface(int kind);
184
191 static const QString& fwd_bem_explain_method(int method);
192
202 static int get_int(FIFFLIB::FiffStream::SPtr& stream, const FIFFLIB::FiffDirNode::SPtr& node, int what, int* res);
203
211
212 //=========================================================================================================
220 static FwdBemModel::UPtr fwd_bem_load_surfaces(const QString& name,
221 const std::vector<int>& kinds);
222
223 //=========================================================================================================
232 static FwdBemModel::UPtr fwd_bem_load_homog_surface(const QString& name);
233
234 //=========================================================================================================
241 static FwdBemModel::UPtr fwd_bem_load_three_layer_surfaces(const QString& name);
242
243 //=========================================================================================================
254 int fwd_bem_load_solution(const QString& name, int bemMethod);
255
256 //=========================================================================================================
264
265 //============================= dipole_fit_guesses.c =============================
266
267 //=========================================================================================================
282 static std::unique_ptr<MNELIB::MNESurface> make_guesses(MNELIB::MNESurface* guess_surf,
283 float guessrad,
284 const Eigen::Vector3f& guess_r0,
285 float grid,
286 float exclude,
287 float mindist);
288
289 //============================= fwd_bem_linear_collocation.c =============================
290
291 /*
292 * The following approach is based on:
293 *
294 * de Munck JC: "A linear discretization of the volume conductor boundary integral equation
295 * using analytically integrated elements",
296 * IEEE Trans Biomed Eng. 1992 39(9) : 986 - 990
297 */
298
299 //=========================================================================================================
307 static double calc_beta(const Eigen::Vector3d& rk, const Eigen::Vector3d& rk1);
308
309 //=========================================================================================================
317 static void lin_pot_coeff(const Eigen::Vector3f& from,
319 Eigen::Vector3d& omega);
320
321 //=========================================================================================================
329 Eigen::MatrixXf& mat);
330
331 //=========================================================================================================
338 static Eigen::MatrixXf fwd_bem_lin_pot_coeff(const std::vector<MNELIB::MNESurface*>& surfs);
339
340 //=========================================================================================================
347
348 //============================= fwd_bem_solution.c =============================
349
350 //=========================================================================================================
363 static Eigen::MatrixXf fwd_bem_multi_solution(Eigen::MatrixXf& solids,
364 const Eigen::MatrixXf* gamma,
365 int nsurf,
366 const Eigen::VectorXi& ntri);
367
368 //=========================================================================================================
376 static Eigen::MatrixXf fwd_bem_homog_solution(Eigen::MatrixXf& solids, int ntri);
377
378 //=========================================================================================================
391 static void fwd_bem_ip_modify_solution(Eigen::MatrixXf& solution,
392 Eigen::MatrixXf& ip_solution,
393 float ip_mult,
394 int nsurf,
395 const Eigen::VectorXi& ntri);
396
397 //============================= fwd_bem_constant_collocation.c =============================
398
399 //=========================================================================================================
409 static int fwd_bem_check_solids(const Eigen::MatrixXf& angles, int ntri1, int ntri2, float desired);
410
411 //=========================================================================================================
418 static Eigen::MatrixXf fwd_bem_solid_angles(const std::vector<MNELIB::MNESurface*>& surfs);
419
420 //=========================================================================================================
427
428 //============================= fwd_bem_model.c =============================
429
430 //=========================================================================================================
437 int fwd_bem_compute_solution(int bemMethod);
438
439 //=========================================================================================================
451 int fwd_bem_load_recompute_solution(const QString& name,
452 int bemMethod,
453 int force_recompute);
454
455 //=========================================================================================================
465 int fwd_bem_save_model(const QString& name) const;
466
467 //============================= fwd_bem_pot.c =============================
468
469 //=========================================================================================================
482 static float fwd_bem_inf_field(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp, const Eigen::Vector3f& dir);
483
484 //=========================================================================================================
495 static float fwd_bem_inf_pot(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp);
496
497 //=========================================================================================================
508
509 //=========================================================================================================
521 void fwd_bem_pot_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
522 FwdCoilSet* els, int all_surfs,
523 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
524
525 //=========================================================================================================
535 void fwd_bem_lin_pot_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
536 FwdCoilSet* els, int all_surfs,
537 Eigen::Ref<Eigen::VectorXf> pot);
538
539 //=========================================================================================================
551 void fwd_bem_lin_pot_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
552 FwdCoilSet* els, int all_surfs,
553 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
554
555 //=========================================================================================================
565 void fwd_bem_pot_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
566 FwdCoilSet* els, int all_surfs,
567 Eigen::Ref<Eigen::VectorXf> pot);
568
569 //=========================================================================================================
582 static int fwd_bem_pot_els(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
583 FwdCoilSet& els, Eigen::Ref<Eigen::VectorXf> pot,
584 void* client);
585
586 //=========================================================================================================
602 static int fwd_bem_pot_grad_els(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
603 FwdCoilSet& els, Eigen::Ref<Eigen::VectorXf> pot,
604 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad,
605 void* client);
606
607 //============================= fwd_bem_field.c =============================
608
609 /*
610 * Integration formulas from:
611 * L. Urankar, "Common compact analytical formulas for computation of
612 * geometry integrals on a basic Cartesian sub-domain in boundary and
613 * volume integral methods", Engineering Analysis with Boundary Elements,
614 * 7(3), 1990, 124-129.
615 */
616
617 //=========================================================================================================
627 static void calc_f(const Eigen::Vector3d& xx, const Eigen::Vector3d& yy,
628 Eigen::Vector3d& f0, Eigen::Vector3d& fx, Eigen::Vector3d& fy);
629
630 //=========================================================================================================
641 static void calc_magic(double u, double z,
642 double A, double B,
643 Eigen::Vector3d& beta, double& D);
644
645 //=========================================================================================================
659 static void field_integrals(const Eigen::Vector3f& from,
661 double& I1p,
662 Eigen::Vector2d& T, Eigen::Vector2d& S1, Eigen::Vector2d& S2,
663 Eigen::Vector3d& f0, Eigen::Vector3d& fx, Eigen::Vector3d& fy);
664
665 //=========================================================================================================
674 static double one_field_coeff(const Eigen::Vector3f& dest, const Eigen::Vector3f& normal,
676
677 //=========================================================================================================
684 Eigen::MatrixXf fwd_bem_field_coeff(FwdCoilSet* coils);
685
686 /*
687 * Linear field formulas from:
688 * Ferguson et al., "A Complete Linear Discretization for Calculating
689 * the Magnetic Field Using the Boundary-Element Method",
690 * IEEE Trans. Biomed. Eng., submitted.
691 */
692
693 //=========================================================================================================
701 static double calc_gamma(const Eigen::Vector3d& rk, const Eigen::Vector3d& rk1);
702
703 //=========================================================================================================
712 static void fwd_bem_one_lin_field_coeff_ferg(const Eigen::Vector3f& dest, const Eigen::Vector3f& dir,
714 Eigen::Vector3d& res);
715
716 //=========================================================================================================
725 static void fwd_bem_one_lin_field_coeff_uran(const Eigen::Vector3f& dest, const Eigen::Vector3f& dir,
727 Eigen::Vector3d& res);
728
729 //=========================================================================================================
738 static void fwd_bem_one_lin_field_coeff_simple(const Eigen::Vector3f& dest, const Eigen::Vector3f& normal,
739 MNELIB::MNETriangle& source,
740 Eigen::Vector3d& res);
741
742 //=========================================================================================================
746 typedef void (*linFieldIntFunc)(const Eigen::Vector3f& dest, const Eigen::Vector3f& dir,
747 MNELIB::MNETriangle& tri, Eigen::Vector3d& res);
748
749 //=========================================================================================================
757 Eigen::MatrixXf fwd_bem_lin_field_coeff(FwdCoilSet* coils, int method);
758
759 //=========================================================================================================
770
771 static constexpr double MAG_FACTOR = 1e-7;
772
773 //=========================================================================================================
782 void fwd_bem_lin_field_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
783 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> B);
784
785 //=========================================================================================================
794 void fwd_bem_field_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
795 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> B);
796
797 //=========================================================================================================
808 void fwd_bem_field_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
809 FwdCoilSet& coils,
810 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
811
812 //=========================================================================================================
825 static float fwd_bem_inf_field_der(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp,
826 const Eigen::Vector3f& dir, const Eigen::Vector3f& comp);
827
828 //=========================================================================================================
838 static float fwd_bem_inf_pot_der(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp,
839 const Eigen::Vector3f& comp);
840
841 //=========================================================================================================
852 void fwd_bem_lin_field_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
853 FwdCoilSet& coils,
854 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
855
856 //=========================================================================================================
870 static int fwd_bem_field(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
871 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> B,
872 void* client);
873
874 //=========================================================================================================
890 static int fwd_bem_field_grad(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
891 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
892 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad,
893 void* client);
894
895 //============================= compute_forward.c =============================
896
897 //=========================================================================================================
907
908 //=========================================================================================================
924 int compute_forward_meg(std::vector<std::unique_ptr<MNELIB::MNESourceSpace>>& spaces,
925 FwdCoilSet* coils,
926 FwdCoilSet* comp_coils,
927 MNELIB::MNECTFCompDataSet* comp_data,
928 bool fixed_ori,
929 const Eigen::Vector3f& r0,
930 bool use_threads,
932 FIFFLIB::FiffNamedMatrix& resp_grad,
933 bool bDoGRad);
934
935 //=========================================================================================================
949 int compute_forward_eeg(std::vector<std::unique_ptr<MNELIB::MNESourceSpace>>& spaces,
950 FwdCoilSet* els,
951 bool fixed_ori,
952 FwdEegSphereModel* eeg_model,
953 bool use_threads,
955 FIFFLIB::FiffNamedMatrix& resp_grad,
956 bool bDoGrad);
957
958 //============================= fwd_spherefield.c =============================
959
960 //=========================================================================================================
973 static int fwd_sphere_field(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
974 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
975 void* client);
976
977 //=========================================================================================================
990 static int fwd_sphere_field_vec(const Eigen::Vector3f& rd,
991 FwdCoilSet& coils, Eigen::Ref<Eigen::MatrixXf> Bval,
992 void* client);
993
994 //=========================================================================================================
1010 static int fwd_sphere_field_grad(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
1011 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
1012 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad,
1013 void* client);
1014
1015 //============================= fwd_mag_dipole_field.c =============================
1016
1017 //=========================================================================================================
1028 static int fwd_mag_dipole_field(const Eigen::Vector3f& rm, const Eigen::Vector3f& M,
1029 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
1030 void* client);
1031
1032 //=========================================================================================================
1044 static int fwd_mag_dipole_field_vec(const Eigen::Vector3f& rm,
1045 FwdCoilSet& coils, Eigen::Ref<Eigen::MatrixXf> Bval,
1046 void* client);
1047
1048public:
1049 QString surf_name;
1050
1051 std::vector<std::shared_ptr<MNELIB::MNESurface>> surfs;
1052
1053 Eigen::VectorXi ntri;
1054 Eigen::VectorXi np;
1055 int nsurf;
1056
1057 Eigen::VectorXf sigma;
1058 Eigen::MatrixXf gamma;
1059 Eigen::VectorXf source_mult;
1060 Eigen::VectorXf field_mult;
1061
1063 QString sol_name;
1064
1065 Eigen::MatrixXf solution;
1066 Eigen::VectorXf v0;
1067 int nsol;
1068
1070
1073};
1074
1075//=============================================================================================================
1076// INLINE DEFINITIONS
1077//=============================================================================================================
1078} // NAMESPACE FWDLIB
1079
1080#endif // FWD_BEM_MODEL_H
FIFF tag: the 16-byte tag header (kind, type, size, next) plus its decoded payload.
4x4 affine FIFF coordinate transform (FIFF_COORD_TRANS) annotated with source/destination coordinate-...
Recursive node of the parsed FIFF block tree (FIFFB_* hierarchy with directory entries and children).
Matrix paired with row and column name lists, the on-disk form of FIFFB_PROJ_ITEM / FIFFB_MNE_NAMED_M...
Container of FwdCoil instances representing either a sensor-type template database or a concrete per-...
Symbol-visibility macro and build-info entry points for the FWDLIB (MEG/EEG forward-modelling) librar...
#define FWDSHARED_EXPORT
Definition fwd_global.h:44
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O, in-memory data structures and high-level readers/writers.
Forward modelling — BEM solver, spherical models, sensor/coil definitions and the lead-field assembly...
Definition compute_fwd.h:85
constexpr int FWD_BEM_CONSTANT_COLL
constexpr int FWD_BEM_LIN_FIELD_URANKAR
constexpr float FWD_BEM_IP_APPROACH_LIMIT
constexpr int FWD_BEM_LINEAR_COLL
constexpr int FWD_BEM_LIN_FIELD_FERGUSON
constexpr int FWD_BEM_UNKNOWN
constexpr int FWD_BEM_LIN_FIELD_SIMPLE
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
QSharedPointer< FiffDirNode > SPtr
FIFF named matrix: dense / sparse Eigen matrix plus row-name and column-name string lists.
QSharedPointer< FiffStream > SPtr
static FwdBemModel::UPtr fwd_bem_load_three_layer_surfaces(const QString &name)
Load a three-layer BEM model (scalp, outer skull, inner skull) from a FIFF file.
static void field_integrals(const Eigen::Vector3f &from, MNELIB::MNETriangle &to, double &I1p, Eigen::Vector2d &T, Eigen::Vector2d &S1, Eigen::Vector2d &S2, Eigen::Vector3d &f0, Eigen::Vector3d &fx, Eigen::Vector3d &fy)
Compute the geometry integrals for the magnetic field from a triangle.
void fwd_bem_field_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > B)
Compute BEM magnetic fields at coils using constant collocation.
static double calc_gamma(const Eigen::Vector3d &rk, const Eigen::Vector3d &rk1)
Compute the gamma angle for the linear field integration (Ferguson).
Eigen::VectorXi np
void fwd_bem_pot_grad_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet *els, int all_surfs, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad)
Compute the gradient of BEM potentials with respect to dipole position (constant collocation).
Eigen::VectorXf source_mult
static double calc_beta(const Eigen::Vector3d &rk, const Eigen::Vector3d &rk1)
Compute the beta angle used in the linear collocation integration.
static int get_int(FIFFLIB::FiffStream::SPtr &stream, const FIFFLIB::FiffDirNode::SPtr &node, int what, int *res)
Read an integer tag from a FIFF node.
Eigen::MatrixXf gamma
static void fwd_bem_one_lin_field_coeff_uran(const Eigen::Vector3f &dest, const Eigen::Vector3f &dir, MNELIB::MNETriangle &tri, Eigen::Vector3d &res)
Compute linear field coefficients using the Urankar method.
static Eigen::MatrixXf fwd_bem_multi_solution(Eigen::MatrixXf &solids, const Eigen::MatrixXf *gamma, int nsurf, const Eigen::VectorXi &ntri)
Compute the multi-surface BEM solution from solid-angle coefficients.
static FwdBemModel::UPtr fwd_bem_load_surfaces(const QString &name, const std::vector< int > &kinds)
Load BEM surfaces of specified kinds from a FIFF file.
static void correct_auto_elements(MNELIB::MNESurface &surf, Eigen::MatrixXf &mat)
Correct the auto (self-coupling) elements of the linear collocation matrix.
static int fwd_sphere_field_grad(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > Bval, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad, void *client)
Callback: compute the spherical-model magnetic field and its position gradient at coils.
static int fwd_bem_check_solids(const Eigen::MatrixXf &angles, int ntri1, int ntri2, float desired)
Verify that solid-angle sums match the expected value.
static int fwd_mag_dipole_field_vec(const Eigen::Vector3f &rm, FwdCoilSet &coils, Eigen::Ref< Eigen::MatrixXf > Bval, void *client)
Callback: compute the vector magnetic field of a magnetic dipole at coils.
static constexpr double MAG_FACTOR
int fwd_bem_specify_coils(FwdCoilSet *coils)
Precompute the coil-specific BEM solution for MEG.
int fwd_bem_load_solution(const QString &name, int bemMethod)
Load a pre-computed BEM solution from a FIFF file.
static Eigen::MatrixXf fwd_bem_solid_angles(const std::vector< MNELIB::MNESurface * > &surfs)
Compute the solid-angle matrix for all BEM surfaces.
int fwd_bem_specify_els(FwdCoilSet *els)
Precompute the electrode-specific BEM solution.
static void fwd_bem_one_lin_field_coeff_simple(const Eigen::Vector3f &dest, const Eigen::Vector3f &normal, MNELIB::MNETriangle &source, Eigen::Vector3d &res)
Compute linear field coefficients using the simple (direct) method.
std::vector< std::shared_ptr< MNELIB::MNESurface > > surfs
Eigen::VectorXf field_mult
std::unique_ptr< FwdBemModel > UPtr
static void fwd_bem_one_lin_field_coeff_ferg(const Eigen::Vector3f &dest, const Eigen::Vector3f &dir, MNELIB::MNETriangle &tri, Eigen::Vector3d &res)
Compute linear field coefficients using the Ferguson method.
static QString fwd_bem_make_bem_sol_name(const QString &name)
Build a standard BEM solution file name from a model name.
static Eigen::MatrixXf fwd_bem_homog_solution(Eigen::MatrixXf &solids, int ntri)
Compute the homogeneous (single-layer) BEM solution.
void fwd_bem_lin_field_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > B)
Compute BEM magnetic fields at coils using linear collocation.
static int fwd_mag_dipole_field(const Eigen::Vector3f &rm, const Eigen::Vector3f &M, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > Bval, void *client)
Callback: compute the magnetic field of a magnetic dipole at coils.
MNELIB::MNESurface * fwd_bem_find_surface(int kind)
Find a surface of the given kind in this BEM model.
void fwd_bem_free_solution()
Release the potential solution matrix and associated workspace.
Eigen::MatrixXf fwd_bem_field_coeff(FwdCoilSet *coils)
Assemble the constant-collocation magnetic field coefficient matrix.
static int fwd_sphere_field(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > Bval, void *client)
Callback: compute the spherical-model magnetic field at coils.
static void lin_pot_coeff(const Eigen::Vector3f &from, MNELIB::MNETriangle &to, Eigen::Vector3d &omega)
Compute the linear potential coefficients for one source-destination pair.
int fwd_bem_load_recompute_solution(const QString &name, int bemMethod, int force_recompute)
Load a BEM solution from file, recomputing if necessary.
Eigen::VectorXi ntri
void fwd_bem_field_grad_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad)
Compute the gradient of BEM magnetic fields with respect to dipole position (constant collocation).
static const QString & fwd_bem_explain_method(int method)
Return a human-readable label for a BEM method.
void fwd_bem_pot_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet *els, int all_surfs, Eigen::Ref< Eigen::VectorXf > pot)
Compute BEM potentials at electrodes using constant collocation.
void fwd_bem_lin_field_grad_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad)
Compute the gradient of BEM magnetic fields with respect to dipole position (linear collocation).
static void calc_f(const Eigen::Vector3d &xx, const Eigen::Vector3d &yy, Eigen::Vector3d &f0, Eigen::Vector3d &fx, Eigen::Vector3d &fy)
Compute the f0, fx, fy integration helper values from corner coordinates.
int fwd_bem_linear_collocation_solution()
Compute the linear-collocation BEM solution for this model.
static int fwd_bem_field(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > B, void *client)
Callback: compute BEM magnetic fields at coils for a dipole.
static int fwd_bem_field_grad(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > Bval, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad, void *client)
Callback: compute BEM magnetic fields and position gradients at coils.
int compute_forward_eeg(std::vector< std::unique_ptr< MNELIB::MNESourceSpace > > &spaces, FwdCoilSet *els, bool fixed_ori, FwdEegSphereModel *eeg_model, bool use_threads, FIFFLIB::FiffNamedMatrix &resp, FIFFLIB::FiffNamedMatrix &resp_grad, bool bDoGrad)
Compute the EEG forward solution for one or more source spaces.
static float fwd_bem_inf_pot(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, const Eigen::Vector3f &rp)
Compute the infinite-medium electric potential at a single point.
int fwd_bem_compute_solution(int bemMethod)
Compute the BEM solution matrix using the specified method.
static int fwd_bem_pot_els(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &els, Eigen::Ref< Eigen::VectorXf > pot, void *client)
Callback: compute BEM potentials at electrodes for a dipole.
static Eigen::MatrixXf fwd_bem_lin_pot_coeff(const std::vector< MNELIB::MNESurface * > &surfs)
Assemble the full linear-collocation potential coefficient matrix.
int fwd_bem_set_head_mri_t(const FIFFLIB::FiffCoordTrans &t)
Set the Head-to-MRI coordinate transform for this BEM model.
void(* linFieldIntFunc)(const Eigen::Vector3f &dest, const Eigen::Vector3f &dir, MNELIB::MNETriangle &tri, Eigen::Vector3d &res)
Function pointer type for linear field coefficient integration methods.
static float fwd_bem_inf_field_der(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, const Eigen::Vector3f &rp, const Eigen::Vector3f &dir, const Eigen::Vector3f &comp)
Compute the derivative of the infinite-medium magnetic field with respect to dipole position.
static FwdBemModel::UPtr fwd_bem_load_homog_surface(const QString &name)
Load a single-layer (homogeneous) BEM model from a FIFF file.
static float fwd_bem_inf_field(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, const Eigen::Vector3f &rp, const Eigen::Vector3f &dir)
Compute the infinite-medium magnetic field at a single point.
static float fwd_bem_inf_pot_der(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, const Eigen::Vector3f &rp, const Eigen::Vector3f &comp)
Compute the derivative of the infinite-medium electric potential with respect to dipole position.
static int fwd_sphere_field_vec(const Eigen::Vector3f &rd, FwdCoilSet &coils, Eigen::Ref< Eigen::MatrixXf > Bval, void *client)
Callback: compute the spherical-model vector magnetic field at coils.
void fwd_bem_lin_pot_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet *els, int all_surfs, Eigen::Ref< Eigen::VectorXf > pot)
Compute BEM potentials at electrodes using linear collocation.
FwdBemModel()
Constructs an empty BEM model.
static double one_field_coeff(const Eigen::Vector3f &dest, const Eigen::Vector3f &normal, MNELIB::MNETriangle &tri)
Compute the constant-collocation magnetic field coefficient for one triangle.
static const QString & fwd_bem_explain_surface(int kind)
Return a human-readable label for a BEM surface kind.
static void meg_eeg_fwd_one_source_space(FwdThreadArg *arg)
Thread worker: compute the forward solution for one source space.
int compute_forward_meg(std::vector< std::unique_ptr< MNELIB::MNESourceSpace > > &spaces, FwdCoilSet *coils, FwdCoilSet *comp_coils, MNELIB::MNECTFCompDataSet *comp_data, bool fixed_ori, const Eigen::Vector3f &r0, bool use_threads, FIFFLIB::FiffNamedMatrix &resp, FIFFLIB::FiffNamedMatrix &resp_grad, bool bDoGRad)
Compute the MEG forward solution for one or more source spaces.
static void fwd_bem_ip_modify_solution(Eigen::MatrixXf &solution, Eigen::MatrixXf &ip_solution, float ip_mult, int nsurf, const Eigen::VectorXi &ntri)
Modify the BEM solution with the isolated-problem (IP) approach.
int fwd_bem_save_model(const QString &name) const
Save the surfaces, conductivities and potential solution (MNE-C fwd_bem_save_model).
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.
int fwd_bem_constant_collocation_solution()
Compute the constant-collocation BEM solution for this model.
Eigen::MatrixXf solution
void fwd_bem_lin_pot_grad_calc(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet *els, int all_surfs, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad)
Compute the gradient of BEM potentials with respect to dipole position (linear collocation).
static int fwd_bem_pot_grad_els(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &els, Eigen::Ref< Eigen::VectorXf > pot, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad, void *client)
Callback: compute BEM potentials and position gradients at electrodes.
Eigen::MatrixXf fwd_bem_lin_field_coeff(FwdCoilSet *coils, int method)
Assemble the linear-collocation magnetic field coefficient matrix.
Eigen::VectorXf sigma
static void calc_magic(double u, double z, double A, double B, Eigen::Vector3d &beta, double &D)
Compute the "magic" beta and D factors for the Urankar field integration.
Eigen::VectorXf v0
FIFFLIB::FiffCoordTrans head_mri_t
Container of FwdCoil instances acting both as the in-memory image of the coil_def....
Multi-shell concentric-sphere head model holding the Berg-Scherg equivalent-source parameters that ac...
Per-thread work packet carrying the dipole-index range, coil set, field/grad callback and write-back ...
Collection of CTF third-order gradient compensation operators.
Lightweight triangulated surface (vertices, triangles, normals).
Definition mne_surface.h:68
Per-triangle geometric data for a cortical or BEM surface.