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 double FWD_BEM_IP_APPROACH_LIMIT = 0.1;
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{
94 class MNETriangle;
95 class MNESurface;
96 class MNESourceSpace;
97 class MNECTFCompDataSet;
98 class MNENamedMatrix;
99}
100
101namespace FIFFLIB {
102 class FiffNamedMatrix;
103}
104//=============================================================================================================
105// DEFINE NAMESPACE FWDLIB
106//=============================================================================================================
107
108namespace FWDLIB
109{
110
111//=============================================================================================================
112// FWDLIB FORWARD DECLARATIONS
113//=============================================================================================================
114
116class FwdThreadArg;
117
118//=============================================================================================================
133{
134public:
135 typedef std::unique_ptr<FwdBemModel> UPtr;
136
137 //=========================================================================================================
144 explicit FwdBemModel();
145
146 //=========================================================================================================
153 virtual ~FwdBemModel();
154
155 //=========================================================================================================
163
170 static QString fwd_bem_make_bem_sol_name(const QString& name);
171
172 //============================= fwd_bem_model.c =============================
173
180 static const QString& fwd_bem_explain_surface(int kind);
181
188 static const QString& fwd_bem_explain_method(int method);
189
193 static int get_int( FIFFLIB::FiffStream::SPtr& stream, const FIFFLIB::FiffDirNode::SPtr& node,int what,int *res);
194
202
203 //=========================================================================================================
211 static FwdBemModel::UPtr fwd_bem_load_surfaces(const QString& name,
212 const std::vector<int>& kinds);
213
214 //=========================================================================================================
223 static FwdBemModel::UPtr fwd_bem_load_homog_surface(const QString& name);
224
225 //=========================================================================================================
232 static FwdBemModel::UPtr fwd_bem_load_three_layer_surfaces(const QString& name);
233
234 //=========================================================================================================
245 int fwd_bem_load_solution(const QString& name, int bem_method);
246
247 //=========================================================================================================
255
256 //============================= dipole_fit_guesses.c =============================
257
258 //=========================================================================================================
273 static std::unique_ptr<MNELIB::MNESurface> make_guesses(MNELIB::MNESurface* guess_surf,
274 float guessrad,
275 const Eigen::Vector3f& guess_r0,
276 float grid,
277 float exclude,
278 float mindist);
279
280 //============================= fwd_bem_linear_collocation.c =============================
281
282 /*
283 * The following approach is based on:
284 *
285 * de Munck JC: "A linear discretization of the volume conductor boundary integral equation
286 * using analytically integrated elements",
287 * IEEE Trans Biomed Eng. 1992 39(9) : 986 - 990
288 */
289
290 //=========================================================================================================
298 static double calc_beta(const Eigen::Vector3d& rk, const Eigen::Vector3d& rk1);
299
300 //=========================================================================================================
308 static void lin_pot_coeff(const Eigen::Vector3f& from,
310 Eigen::Vector3d& omega);
311
312 //=========================================================================================================
320 Eigen::MatrixXf& mat);
321
322 //=========================================================================================================
329 static Eigen::MatrixXf fwd_bem_lin_pot_coeff(const std::vector<MNELIB::MNESurface*>& surfs);
330
331 //=========================================================================================================
338
339 //============================= fwd_bem_solution.c =============================
340
341 //=========================================================================================================
354 static Eigen::MatrixXf fwd_bem_multi_solution(Eigen::MatrixXf& solids,
355 const Eigen::MatrixXf *gamma,
356 int nsurf,
357 const Eigen::VectorXi& ntri);
358
359 //=========================================================================================================
367 static Eigen::MatrixXf fwd_bem_homog_solution(Eigen::MatrixXf& solids, int ntri);
368
369 //=========================================================================================================
382 static void fwd_bem_ip_modify_solution(Eigen::MatrixXf &solution,
383 Eigen::MatrixXf& ip_solution,
384 float ip_mult,
385 int nsurf,
386 const Eigen::VectorXi &ntri);
387
388 //============================= fwd_bem_constant_collocation.c =============================
389
390 //=========================================================================================================
400 static int fwd_bem_check_solids(const Eigen::MatrixXf& angles, int ntri1, int ntri2, float desired);
401
402 //=========================================================================================================
409 static Eigen::MatrixXf fwd_bem_solid_angles(const std::vector<MNELIB::MNESurface*>& surfs);
410
411 //=========================================================================================================
418
419 //============================= fwd_bem_model.c =============================
420
421 //=========================================================================================================
429
430 //=========================================================================================================
442 int fwd_bem_load_recompute_solution(const QString& name,
443 int bem_method,
444 int force_recompute);
445
446 //============================= fwd_bem_pot.c =============================
447
448 //=========================================================================================================
461 static float fwd_bem_inf_field(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp, const Eigen::Vector3f& dir);
462
463 //=========================================================================================================
474 static float fwd_bem_inf_pot(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp);
475
476 //=========================================================================================================
487
488 //=========================================================================================================
500 void fwd_bem_pot_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
501 FwdCoilSet* els, int all_surfs,
502 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
503
504 //=========================================================================================================
514 void fwd_bem_lin_pot_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
515 FwdCoilSet* els, int all_surfs,
516 Eigen::Ref<Eigen::VectorXf> pot);
517
518 //=========================================================================================================
530 void fwd_bem_lin_pot_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
531 FwdCoilSet* els, int all_surfs,
532 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
533
534 //=========================================================================================================
544 void fwd_bem_pot_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
545 FwdCoilSet* els, int all_surfs,
546 Eigen::Ref<Eigen::VectorXf> pot);
547
548 //=========================================================================================================
561 static int fwd_bem_pot_els(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
562 FwdCoilSet& els, Eigen::Ref<Eigen::VectorXf> pot,
563 void *client);
564
565 //=========================================================================================================
581 static int fwd_bem_pot_grad_els(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
582 FwdCoilSet& els, Eigen::Ref<Eigen::VectorXf> pot,
583 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad,
584 void *client);
585
586 //============================= fwd_bem_field.c =============================
587
588 /*
589 * Integration formulas from:
590 * L. Urankar, "Common compact analytical formulas for computation of
591 * geometry integrals on a basic Cartesian sub-domain in boundary and
592 * volume integral methods", Engineering Analysis with Boundary Elements,
593 * 7(3), 1990, 124-129.
594 */
595
596 //=========================================================================================================
606 static void calc_f(const Eigen::Vector3d& xx, const Eigen::Vector3d& yy,
607 Eigen::Vector3d& f0, Eigen::Vector3d& fx, Eigen::Vector3d& fy);
608
609 //=========================================================================================================
620 static void calc_magic(double u, double z,
621 double A, double B,
622 Eigen::Vector3d& beta, double& D);
623
624 //=========================================================================================================
638 static void field_integrals(const Eigen::Vector3f& from,
640 double& I1p,
641 Eigen::Vector2d& T, Eigen::Vector2d& S1, Eigen::Vector2d& S2,
642 Eigen::Vector3d& f0, Eigen::Vector3d& fx, Eigen::Vector3d& fy);
643
644 //=========================================================================================================
653 static double one_field_coeff(const Eigen::Vector3f& dest, const Eigen::Vector3f& normal,
655
656 //=========================================================================================================
663 Eigen::MatrixXf fwd_bem_field_coeff(FwdCoilSet* coils);
664
665 /*
666 * Linear field formulas from:
667 * Ferguson et al., "A Complete Linear Discretization for Calculating
668 * the Magnetic Field Using the Boundary-Element Method",
669 * IEEE Trans. Biomed. Eng., submitted.
670 */
671
672 //=========================================================================================================
680 static double calc_gamma(const Eigen::Vector3d& rk, const Eigen::Vector3d& rk1);
681
682 //=========================================================================================================
691 static void fwd_bem_one_lin_field_coeff_ferg(const Eigen::Vector3f& dest, const Eigen::Vector3f& dir,
693 Eigen::Vector3d& res);
694
695 //=========================================================================================================
704 static void fwd_bem_one_lin_field_coeff_uran(const Eigen::Vector3f& dest, const Eigen::Vector3f& dir,
706 Eigen::Vector3d& res);
707
708 //=========================================================================================================
717 static void fwd_bem_one_lin_field_coeff_simple(const Eigen::Vector3f& dest, const Eigen::Vector3f& normal,
718 MNELIB::MNETriangle& source,
719 Eigen::Vector3d& res);
720
721 //=========================================================================================================
725 typedef void (*linFieldIntFunc)(const Eigen::Vector3f& dest, const Eigen::Vector3f& dir,
726 MNELIB::MNETriangle& tri, Eigen::Vector3d& res);
727
728 //=========================================================================================================
736 Eigen::MatrixXf fwd_bem_lin_field_coeff(FwdCoilSet* coils, int method);
737
738 //=========================================================================================================
749
750 static constexpr double MAG_FACTOR = 1e-7;
751
752 //=========================================================================================================
761 void fwd_bem_lin_field_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
762 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> B);
763
764 //=========================================================================================================
773 void fwd_bem_field_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
774 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> B);
775
776 //=========================================================================================================
787 void fwd_bem_field_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
788 FwdCoilSet& coils,
789 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
790
791 //=========================================================================================================
804 static float fwd_bem_inf_field_der(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp,
805 const Eigen::Vector3f& dir, const Eigen::Vector3f& comp);
806
807 //=========================================================================================================
817 static float fwd_bem_inf_pot_der(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Vector3f& rp,
818 const Eigen::Vector3f& comp);
819
820 //=========================================================================================================
831 void fwd_bem_lin_field_grad_calc(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
832 FwdCoilSet& coils,
833 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad);
834
835 //=========================================================================================================
849 static int fwd_bem_field(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
850 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> B,
851 void *client);
852
853 //=========================================================================================================
869 static int fwd_bem_field_grad(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
870 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
871 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad,
872 void *client);
873
874 //============================= compute_forward.c =============================
875
876 //=========================================================================================================
886
887 //=========================================================================================================
903 int compute_forward_meg(std::vector<std::unique_ptr<MNELIB::MNESourceSpace>>& spaces,
904 FwdCoilSet* coils,
905 FwdCoilSet* comp_coils,
906 MNELIB::MNECTFCompDataSet* comp_data,
907 bool fixed_ori,
908 const Eigen::Vector3f& r0,
909 bool use_threads,
911 FIFFLIB::FiffNamedMatrix& resp_grad,
912 bool bDoGRad);
913
914 //=========================================================================================================
928 int compute_forward_eeg(std::vector<std::unique_ptr<MNELIB::MNESourceSpace>>& spaces,
929 FwdCoilSet* els,
930 bool fixed_ori,
931 FwdEegSphereModel* eeg_model,
932 bool use_threads,
934 FIFFLIB::FiffNamedMatrix& resp_grad,
935 bool bDoGrad);
936
937 //============================= fwd_spherefield.c =============================
938
939 //=========================================================================================================
952 static int fwd_sphere_field(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
953 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
954 void *client);
955
956 //=========================================================================================================
969 static int fwd_sphere_field_vec(const Eigen::Vector3f& rd,
970 FwdCoilSet& coils, Eigen::Ref<Eigen::MatrixXf> Bval,
971 void *client);
972
973 //=========================================================================================================
989 static int fwd_sphere_field_grad(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q,
990 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
991 Eigen::Ref<Eigen::VectorXf> xgrad, Eigen::Ref<Eigen::VectorXf> ygrad, Eigen::Ref<Eigen::VectorXf> zgrad,
992 void *client);
993
994 //============================= fwd_mag_dipole_field.c =============================
995
996 //=========================================================================================================
1007 static int fwd_mag_dipole_field(const Eigen::Vector3f& rm, const Eigen::Vector3f& M,
1008 FwdCoilSet& coils, Eigen::Ref<Eigen::VectorXf> Bval,
1009 void *client);
1010
1011 //=========================================================================================================
1023 static int fwd_mag_dipole_field_vec(const Eigen::Vector3f& rm,
1024 FwdCoilSet& coils, Eigen::Ref<Eigen::MatrixXf> Bval,
1025 void *client);
1026
1027public:
1028 QString surf_name;
1029
1030 std::vector<std::shared_ptr<MNELIB::MNESurface>> surfs;
1031
1032 Eigen::VectorXi ntri;
1033 Eigen::VectorXi np;
1034 int nsurf;
1035
1036 Eigen::VectorXf sigma;
1037 Eigen::MatrixXf gamma;
1038 Eigen::VectorXf source_mult;
1039 Eigen::VectorXf field_mult;
1040
1042 QString sol_name;
1043
1044 Eigen::MatrixXf solution;
1045 Eigen::VectorXf v0;
1046 int nsol;
1047
1049
1052};
1053
1054//=============================================================================================================
1055// INLINE DEFINITIONS
1056//=============================================================================================================
1057} // NAMESPACE FWDLIB
1058
1059#endif // FWD_BEM_MODEL_H
Symbol-visibility macro and build-info entry points for the FWDLIB (MEG/EEG forward-modelling) librar...
#define FWDSHARED_EXPORT
Definition fwd_global.h:44
Container of FwdCoil instances representing either a sensor-type template database or a concrete per-...
Matrix paired with row and column name lists, the on-disk form of FIFFB_PROJ_ITEM / FIFFB_MNE_NAMED_M...
Recursive node of the parsed FIFF block tree (FIFFB_* hierarchy with directory entries and children).
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-...
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:83
constexpr int FWD_BEM_CONSTANT_COLL
constexpr double FWD_BEM_IP_APPROACH_LIMIT
constexpr int FWD_BEM_LIN_FIELD_URANKAR
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.
int fwd_bem_load_solution(const QString &name, int bem_method)
Load a pre-computed BEM solution from a FIFF file.
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.
int fwd_bem_compute_solution(int bem_method)
Compute the BEM solution matrix using the specified method.
static constexpr double MAG_FACTOR
int fwd_bem_specify_coils(FwdCoilSet *coils)
Precompute the coil-specific BEM solution for MEG.
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.
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.
int fwd_bem_load_recompute_solution(const QString &name, int bem_method, int force_recompute)
Load a BEM solution from file, recomputing if necessary.
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.
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.
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:66
Per-triangle geometric data for a cortical or BEM surface.