BEM (Boundary Element Method) model definition. More...
#include <fwd_bem_model.h>
Public Types | |
| typedef std::unique_ptr< FwdBemModel > | UPtr |
| typedef 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. | |
Public Member Functions | |
| FwdBemModel () | |
| Constructs an empty BEM model. | |
| virtual | ~FwdBemModel () |
| Destroys the BEM model. | |
| void | fwd_bem_free_solution () |
| Release the potential solution matrix and associated workspace. | |
| MNELIB::MNESurface * | fwd_bem_find_surface (int kind) |
| Find a surface of the given kind in this BEM model. | |
| int | fwd_bem_load_solution (const QString &name, int bem_method) |
| Load a pre-computed BEM solution from a FIFF file. | |
| int | fwd_bem_set_head_mri_t (const FIFFLIB::FiffCoordTrans &t) |
| Set the Head-to-MRI coordinate transform for this BEM model. | |
| int | fwd_bem_linear_collocation_solution () |
| Compute the linear-collocation BEM solution for this model. | |
| int | fwd_bem_constant_collocation_solution () |
| Compute the constant-collocation BEM solution for this model. | |
| int | fwd_bem_compute_solution (int bem_method) |
| Compute the BEM solution matrix using the specified method. | |
| int | fwd_bem_load_recompute_solution (const QString &name, int bem_method, int force_recompute) |
| Load a BEM solution from file, recomputing if necessary. | |
| int | fwd_bem_specify_els (FwdCoilSet *els) |
| Precompute the electrode-specific BEM solution. | |
| 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). | |
| 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. | |
| 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). | |
| 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. | |
| Eigen::MatrixXf | fwd_bem_field_coeff (FwdCoilSet *coils) |
| Assemble the constant-collocation magnetic field coefficient matrix. | |
| Eigen::MatrixXf | fwd_bem_lin_field_coeff (FwdCoilSet *coils, int method) |
| Assemble the linear-collocation magnetic field coefficient matrix. | |
| int | fwd_bem_specify_coils (FwdCoilSet *coils) |
| Precompute the coil-specific BEM solution for MEG. | |
| 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. | |
| 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. | |
| 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). | |
| 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). | |
| 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. | |
| 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 Public Member Functions | |
| static QString | fwd_bem_make_bem_sol_name (const QString &name) |
| Build a standard BEM solution file name from a model name. | |
| static const QString & | fwd_bem_explain_surface (int kind) |
| Return a human-readable label for a BEM surface kind. | |
| static const QString & | fwd_bem_explain_method (int method) |
| Return a human-readable label for a BEM method. | |
| 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. | |
| 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 FwdBemModel::UPtr | fwd_bem_load_homog_surface (const QString &name) |
| Load a single-layer (homogeneous) BEM model from a FIFF file. | |
| 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 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. | |
| static double | calc_beta (const Eigen::Vector3d &rk, const Eigen::Vector3d &rk1) |
| Compute the beta angle used in the linear collocation integration. | |
| 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. | |
| static void | correct_auto_elements (MNELIB::MNESurface &surf, Eigen::MatrixXf &mat) |
| Correct the auto (self-coupling) elements of the linear collocation matrix. | |
| static Eigen::MatrixXf | fwd_bem_lin_pot_coeff (const std::vector< MNELIB::MNESurface * > &surfs) |
| Assemble the full linear-collocation potential coefficient matrix. | |
| 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 Eigen::MatrixXf | fwd_bem_homog_solution (Eigen::MatrixXf &solids, int ntri) |
| Compute the homogeneous (single-layer) BEM solution. | |
| 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 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 Eigen::MatrixXf | fwd_bem_solid_angles (const std::vector< MNELIB::MNESurface * > &surfs) |
| Compute the solid-angle matrix for all BEM surfaces. | |
| 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 (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 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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 double | calc_gamma (const Eigen::Vector3d &rk, const Eigen::Vector3d &rk1) |
| Compute the gamma angle for the linear field integration (Ferguson). | |
| 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 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 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. | |
| 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 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_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. | |
| static void | meg_eeg_fwd_one_source_space (FwdThreadArg *arg) |
| Thread worker: compute the forward solution for one source space. | |
| 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 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. | |
| 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_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. | |
| 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. | |
Public Attributes | |
| QString | surf_name |
| std::vector< std::shared_ptr< MNELIB::MNESurface > > | surfs |
| Eigen::VectorXi | ntri |
| Eigen::VectorXi | np |
| int | nsurf |
| Eigen::VectorXf | sigma |
| Eigen::MatrixXf | gamma |
| Eigen::VectorXf | source_mult |
| Eigen::VectorXf | field_mult |
| int | bem_method |
| QString | sol_name |
| Eigen::MatrixXf | solution |
| Eigen::VectorXf | v0 |
| int | nsol |
| FIFFLIB::FiffCoordTrans | head_mri_t |
| float | ip_approach_limit |
| bool | use_ip_approach |
Static Public Attributes | |
| static constexpr double | MAG_FACTOR = 1e-7 |
BEM (Boundary Element Method) model definition.
Holds the BEM model surfaces, conductivity parameters, and potential solution matrix used in MEG/EEG forward computations. Surfaces are stored from outermost to innermost and owned by this object.
Refactored from the MNE-C fwdBemModel / fwdBemModelRec struct (fwd_types.h). Raw C-style arrays replaced with Eigen types; surface ownership managed through std::unique_ptr.
Definition at line 128 of file fwd_bem_model.h.
| typedef void(* FWDLIB::FwdBemModel::linFieldIntFunc) (const Eigen::Vector3f &dest, const Eigen::Vector3f &dir, MNELIB::MNETriangle &tri, Eigen::Vector3d &res) |
Function pointer type for linear field coefficient integration methods.
Definition at line 721 of file fwd_bem_model.h.
| typedef std::unique_ptr<FwdBemModel> FWDLIB::FwdBemModel::UPtr |
Unique pointer type for FwdBemModel.
Definition at line 131 of file fwd_bem_model.h.
|
explicit |
Constructs an empty BEM model.
All Eigen containers are left at size zero; scalar members are set to safe defaults (nsurf = 0, nsol = 0, bem_method = FWD_BEM_UNKNOWN).
Definition at line 184 of file fwd_bem_model.cpp.
|
virtual |
Destroys the BEM model.
FsSurface ownership is released automatically via std::unique_ptr. The solution matrix is freed by fwd_bem_free_solution().
Definition at line 196 of file fwd_bem_model.cpp.
|
static |
Compute the beta angle used in the linear collocation integration.
| [in] | rk | Position vector of vertex k. |
| [in] | rk1 | Position vector of vertex k+1. |
Definition at line 538 of file fwd_bem_model.cpp.
|
static |
Compute the f0, fx, fy integration helper values from corner coordinates.
| [in] | xx | Corner x-coordinates. |
| [in] | yy | Corner y-coordinates. |
| [out] | f0 | Integral f0. |
| [out] | fx | Integral fx. |
| [out] | fy | Integral fy. |
Definition at line 1539 of file fwd_bem_model.cpp.
|
static |
Compute the gamma angle for the linear field integration (Ferguson).
| [in] | rk | Position vector of vertex k. |
| [in] | rk1 | Position vector of vertex k+1. |
Definition at line 1783 of file fwd_bem_model.cpp.
|
static |
Compute the "magic" beta and D factors for the Urankar field integration.
| [in] | u | Coordinate u. |
| [in] | z | Coordinate z. |
| [in] | A | Parameter A. |
| [in] | B | Parameter B. |
| [out] | beta | Output beta factor. |
| [out] | D | Output D factor. |
Definition at line 1563 of file fwd_bem_model.cpp.
| int FwdBemModel::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.
| [in] | spaces | Source spaces. |
| [in] | els | Electrode locations. |
| [in] | fixed_ori | If true, use fixed-orientation dipoles. |
| [in] | eeg_model | Sphere model definition. |
| [in] | use_threads | If true, parallelize across source spaces. |
| [out] | resp | Forward solution matrix. |
| [out] | resp_grad | Gradient forward solution matrix. |
| [in] | bDoGrad | If true, also compute the gradient solution. |
Definition at line 2815 of file fwd_bem_model.cpp.
| int FwdBemModel::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.
| [in] | spaces | Source spaces. |
| [in] | coils | MEG coil set. |
| [in] | comp_coils | Compensator coil set (may be nullptr). |
| [in] | comp_data | CTF compensation data (may be nullptr). |
| [in] | fixed_ori | If true, use fixed-orientation dipoles. |
| [in] | r0 | Sphere model origin. |
| [in] | use_threads | If true, parallelize across source spaces. |
| [out] | resp | Forward solution matrix. |
| [out] | resp_grad | Gradient forward solution matrix. |
| [in] | bDoGRad | If true, also compute the gradient solution. |
Definition at line 2577 of file fwd_bem_model.cpp.
|
static |
Correct the auto (self-coupling) elements of the linear collocation matrix.
| [in] | surf | The BEM surface. |
| [in,out] | mat | The coefficient matrix to correct (modified in-place). |
Definition at line 645 of file fwd_bem_model.cpp.
|
static |
Compute the geometry integrals for the magnetic field from a triangle.
| [in] | from | Source point. |
| [in] | to | Destination triangle. |
| [out] | I1p | Monopolar integral. |
| [out] | T | Integral T. |
| [out] | S1 | Integral S1. |
| [out] | S2 | Integral S2. |
| [out] | f0 | Integral f0. |
| [out] | fx | Integral fx. |
| [out] | fy | Integral fy. |
Definition at line 1575 of file fwd_bem_model.cpp.
|
static |
Verify that solid-angle sums match the expected value.
| [in] | angles | Solid-angle matrix. |
| [in] | ntri1 | Row count. |
| [in] | ntri2 | Column count. |
| [in] | desired | Expected solid-angle sum per row. |
Definition at line 959 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_compute_solution | ( | int | bem_method | ) |
Compute the BEM solution matrix using the specified method.
| [in] | bem_method | BEM method (FWD_BEM_CONSTANT_COLL or FWD_BEM_LINEAR_COLL). |
Definition at line 1112 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_constant_collocation_solution | ( | ) |
Compute the constant-collocation BEM solution for this model.
Definition at line 1044 of file fwd_bem_model.cpp.
|
static |
Return a human-readable label for a BEM method.
| [in] | method | BEM method constant (FWD_BEM_CONSTANT_COLL / FWD_BEM_LINEAR_COLL). |
Definition at line 244 of file fwd_bem_model.cpp.
|
static |
Return a human-readable label for a BEM surface kind.
| [in] | kind | FIFF surface ID (e.g. FIFFV_BEM_SURF_ID_BRAIN). |
Definition at line 231 of file fwd_bem_model.cpp.
|
static |
Callback: compute BEM magnetic fields at coils for a dipole.
Dispatches to fwd_bem_field_calc or fwd_bem_lin_field_calc based on the current BEM method. Matches the fwdFieldFunc signature.
| [in] | rd | Dipole position (3-element array). |
| [in] | Q | Dipole orientation (3-element array). |
| [in] | coils | MEG coil descriptors. |
| [out] | B | Output magnetic fields. |
| [in] | client | Opaque pointer to the FwdBemModel instance. |
Definition at line 2344 of file fwd_bem_model.cpp.
| void FwdBemModel::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.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | coils | MEG coil set. |
| [out] | B | Output magnetic fields (one value per coil). |
Definition at line 2090 of file fwd_bem_model.cpp.
| Eigen::MatrixXf FwdBemModel::fwd_bem_field_coeff | ( | FwdCoilSet * | coils | ) |
Assemble the constant-collocation magnetic field coefficient matrix.
| [in] | coils | MEG coil set. |
Definition at line 1716 of file fwd_bem_model.cpp.
|
static |
Callback: compute BEM magnetic fields and position gradients at coils.
Matches the fwdFieldGradFunc signature for use in forward computation threads.
| [in] | rd | Dipole position (3-element array). |
| [in] | Q | Dipole orientation (3-element array). |
| [in] | coils | MEG coil definitions. |
| [out] | Bval | Output magnetic fields. |
| [out] | xgrad | Gradient with respect to x. |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
| [in] | client | Opaque pointer to the FwdBemModel instance. |
Definition at line 2377 of file fwd_bem_model.cpp.
| void FwdBemModel::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).
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | coils | MEG coil set. |
| [out] | xgrad | Gradient with respect to x (one value per coil). |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
Definition at line 2154 of file fwd_bem_model.cpp.
| MNESurface * FwdBemModel::fwd_bem_find_surface | ( | int | kind | ) |
Find a surface of the given kind in this BEM model.
| [in] | kind | FsSurface ID to look for. |
Definition at line 277 of file fwd_bem_model.cpp.
| void FwdBemModel::fwd_bem_free_solution | ( | ) |
Release the potential solution matrix and associated workspace.
Resets solution, v0, sol_name, nsol, and bem_method to their default (empty / unknown) state.
Definition at line 204 of file fwd_bem_model.cpp.
|
static |
Compute the homogeneous (single-layer) BEM solution.
| [in] | solids | Solid-angle coefficient matrix. |
| [in] | ntri | Number of triangles. |
Definition at line 889 of file fwd_bem_model.cpp.
|
static |
Compute the infinite-medium magnetic field at a single point.
Returns the component of the magnetic field along the given direction, without the mu_0 / (4 pi) prefactor.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole moment. |
| [in] | rp | Field point. |
| [in] | dir | Field direction of interest (unit vector). |
Definition at line 1160 of file fwd_bem_model.cpp.
|
static |
Compute the derivative of the infinite-medium magnetic field with respect to dipole position.
Returns the field derivative without the mu_0 / (4 pi) prefactor.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole moment. |
| [in] | rp | Field point. |
| [in] | dir | Field direction of interest (unit vector). |
| [in] | comp | Gradient component direction (unit vector). |
Definition at line 2232 of file fwd_bem_model.cpp.
|
static |
Compute the infinite-medium electric potential at a single point.
Returns the potential without the 1 / (4 pi sigma) prefactor.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole moment. |
| [in] | rp | Potential evaluation point. |
Definition at line 1175 of file fwd_bem_model.cpp.
|
static |
Compute the derivative of the infinite-medium electric potential with respect to dipole position.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole moment. |
| [in] | rp | Potential evaluation point. |
| [in] | comp | Gradient component direction (unit vector). |
Definition at line 2250 of file fwd_bem_model.cpp.
|
static |
Modify the BEM solution with the isolated-problem (IP) approach.
Applies the correction for the innermost surface conductivity jump (the "isolated problem" approach of Hamalainen and Sarvas, 1989).
| [in,out] | solution | The original solution matrix (modified in-place). |
| [in] | ip_solution | The isolated-problem solution matrix. |
| [in] | ip_mult | Conductivity ratio for the IP correction. |
| [in] | nsurf | Number of surfaces. |
| [in] | ntri | Triangle or node count per surface. |
Definition at line 902 of file fwd_bem_model.cpp.
| void FwdBemModel::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.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | coils | MEG coil set. |
| [out] | B | Output magnetic fields (one value per coil). |
Definition at line 2028 of file fwd_bem_model.cpp.
| Eigen::MatrixXf FwdBemModel::fwd_bem_lin_field_coeff | ( | FwdCoilSet * | coils, |
| int | method ) |
Assemble the linear-collocation magnetic field coefficient matrix.
| [in] | coils | MEG coil set. |
| [in] | method | Integration method (FWD_BEM_LIN_FIELD_SIMPLE, _FERGUSON, or _URANKAR). |
Definition at line 1900 of file fwd_bem_model.cpp.
| void FwdBemModel::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).
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | coils | MEG coil set. |
| [out] | xgrad | Gradient with respect to x (one value per coil). |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
Definition at line 2267 of file fwd_bem_model.cpp.
| void FwdBemModel::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.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | els | Electrode set. |
| [in] | all_surfs | If non-zero, compute on all surfaces. |
| [out] | pot | Output potentials (one value per electrode). |
Definition at line 1324 of file fwd_bem_model.cpp.
|
static |
Assemble the full linear-collocation potential coefficient matrix.
| [in] | surfs | Vector of BEM surfaces. |
Definition at line 713 of file fwd_bem_model.cpp.
| void FwdBemModel::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).
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | els | Electrode set. |
| [in] | all_surfs | If non-zero, compute on all surfaces. |
| [out] | xgrad | Gradient with respect to x (one value per electrode). |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
Definition at line 1367 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_linear_collocation_solution | ( | ) |
Compute the linear-collocation BEM solution for this model.
Definition at line 779 of file fwd_bem_model.cpp.
|
static |
Load a single-layer (homogeneous) BEM model from a FIFF file.
Convenience wrapper that loads only the inner skull surface.
| [in] | name | Path to the BEM FIFF file. |
Definition at line 356 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_load_recompute_solution | ( | const QString & | name, |
| int | bem_method, | ||
| int | force_recompute ) |
Load a BEM solution from file, recomputing if necessary.
Attempts to read the pre-computed solution; if it is missing or force_recompute is set, computes a fresh solution.
| [in] | name | Path to the BEM model file. |
| [in] | bem_method | Required BEM method. |
| [in] | force_recompute | If non-zero, always recompute the solution. |
Definition at line 1132 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_load_solution | ( | const QString & | name, |
| int | bem_method ) |
Load a pre-computed BEM solution from a FIFF file.
Reads the solution matrix from disk and stores it in this model. The solution must match the requested BEM method.
| [in] | name | Path to the solution FIFF file. |
| [in] | bem_method | Required BEM method (FWD_BEM_CONSTANT_COLL or FWD_BEM_LINEAR_COLL). |
Definition at line 376 of file fwd_bem_model.cpp.
|
static |
Load BEM surfaces of specified kinds from a FIFF file.
| [in] | name | Path to the BEM FIFF file. |
| [in] | kinds | FsSurface IDs to load (e.g. FIFFV_BEM_SURF_ID_BRAIN). |
Definition at line 288 of file fwd_bem_model.cpp.
|
static |
Load a three-layer BEM model (scalp, outer skull, inner skull) from a FIFF file.
| [in] | name | Path to the BEM FIFF file. |
Definition at line 366 of file fwd_bem_model.cpp.
|
static |
Build a standard BEM solution file name from a model name.
| [in] | name | Base BEM file name. |
Definition at line 215 of file fwd_bem_model.cpp.
|
static |
Compute the multi-surface BEM solution from solid-angle coefficients.
Applies the deflation technique and LU decomposition to produce the final BEM solution matrix for a multi-compartment model.
| [in] | solids | Solid-angle coefficient matrix. |
| [in] | gamma | Conductivity-ratio coupling matrix (nullptr for homogeneous). |
| [in] | nsurf | Number of surfaces. |
| [in] | ntri | Triangle or node count per surface. |
Definition at line 848 of file fwd_bem_model.cpp.
|
static |
Compute linear field coefficients using the Ferguson method.
| [in] | dest | Field point. |
| [in] | dir | Field direction of interest (unit vector). |
| [in] | tri | Destination triangle. |
| [out] | res | Output coefficients for the three triangle vertices. |
Definition at line 1794 of file fwd_bem_model.cpp.
|
static |
Compute linear field coefficients using the simple (direct) method.
| [in] | dest | Destination field point. |
| [in] | normal | Field direction of interest (unit vector). |
| [in] | source | Source triangle. |
| [out] | res | Output coefficients for the three triangle vertices. |
Definition at line 1884 of file fwd_bem_model.cpp.
|
static |
Compute linear field coefficients using the Urankar method.
| [in] | dest | Field point. |
| [in] | dir | Field direction of interest (unit vector). |
| [in] | tri | Destination triangle. |
| [out] | res | Output coefficients for the three triangle vertices. |
Definition at line 1856 of file fwd_bem_model.cpp.
| void FwdBemModel::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.
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | els | Electrode set. |
| [in] | all_surfs | If non-zero, compute on all surfaces. |
| [out] | pot | Output potentials (one value per electrode). |
Definition at line 1420 of file fwd_bem_model.cpp.
|
static |
Callback: compute BEM potentials at electrodes for a dipole.
Matches the fwdFieldFunc signature for use in forward computation threads.
| [in] | rd | Dipole position (3-element array). |
| [in] | Q | Dipole orientation (3-element array). |
| [in] | els | Electrode descriptors. |
| [out] | pot | Output potentials. |
| [in] | client | Opaque pointer to the FwdBemModel instance. |
Definition at line 1463 of file fwd_bem_model.cpp.
| void FwdBemModel::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).
| [in] | rd | Dipole position. |
| [in] | Q | Dipole orientation. |
| [in] | els | Electrode set. |
| [in] | all_surfs | If non-zero, compute on all surfaces. |
| [out] | xgrad | Gradient with respect to x (one value per electrode). |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
Definition at line 1270 of file fwd_bem_model.cpp.
|
static |
Callback: compute BEM potentials and position gradients at electrodes.
Matches the fwdFieldGradFunc signature for use in forward computation threads.
| [in] | rd | Dipole position (3-element array). |
| [in] | Q | Dipole orientation (3-element array). |
| [in] | els | Electrode descriptors. |
| [out] | pot | Output potentials. |
| [out] | xgrad | Gradient with respect to x. |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
| [in] | client | Opaque pointer to the FwdBemModel instance. |
Definition at line 1498 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_set_head_mri_t | ( | const FIFFLIB::FiffCoordTrans & | t | ) |
Set the Head-to-MRI coordinate transform for this BEM model.
| [in] | t | The head-to-MRI coordinate transformation. |
Definition at line 467 of file fwd_bem_model.cpp.
|
static |
Compute the solid-angle matrix for all BEM surfaces.
| [in] | surfs | Vector of BEM surfaces. |
Definition at line 993 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_specify_coils | ( | FwdCoilSet * | coils | ) |
Precompute the coil-specific BEM solution for MEG.
Builds the coil-specific solution matrix by multiplying the BEM solution with the field coefficients.
| [in] | coils | MEG coil set to prepare. |
Definition at line 1990 of file fwd_bem_model.cpp.
| int FwdBemModel::fwd_bem_specify_els | ( | FwdCoilSet * | els | ) |
Precompute the electrode-specific BEM solution.
Builds the coil-specific solution matrix for EEG electrodes by multiplying the BEM solution with infinite-medium potentials.
| [in] | els | Electrode (coil) set to prepare. |
Definition at line 1187 of file fwd_bem_model.cpp.
|
static |
Callback: compute the magnetic field of a magnetic dipole at coils.
| [in] | rm | Dipole position (in the same coordinate system as the coils). |
| [in] | M | Dipole moment components (xyz). |
| [in] | coils | MEG coil definitions. |
| [out] | Bval | Output magnetic fields. |
| [in] | client | Opaque pointer to client data (unused, may be nullptr). |
Definition at line 3338 of file fwd_bem_model.cpp.
|
static |
Callback: compute the vector magnetic field of a magnetic dipole at coils.
Returns one row per cardinal dipole direction (x, y, z).
| [in] | rm | Dipole position (3-element array). |
| [in] | coils | MEG coil definitions. |
| [out] | Bval | Output fields (3 x ncoil matrix, row-major). |
| [in] | client | Opaque pointer to client data (unused, may be nullptr). |
Definition at line 3375 of file fwd_bem_model.cpp.
|
static |
Callback: compute the spherical-model magnetic field at coils.
Matches the fwdFieldFunc signature.
| [in] | rd | Dipole position (3-element array). |
| [in] | Q | Dipole components (xyz). |
| [in] | coils | MEG coil definitions. |
| [out] | Bval | Output magnetic fields. |
| [in] | client | Opaque pointer to client data (sphere model origin). |
Definition at line 3006 of file fwd_bem_model.cpp.
|
static |
Callback: compute the spherical-model magnetic field and its position gradient at coils.
Matches the fwdFieldGradFunc signature.
| [in] | rd | Dipole position (3-element array). |
| [in] | Q | Dipole components (xyz). |
| [in] | coils | MEG coil definitions. |
| [out] | Bval | Output magnetic fields. |
| [out] | xgrad | Gradient with respect to x. |
| [out] | ygrad | Gradient with respect to y. |
| [out] | zgrad | Gradient with respect to z. |
| [in] | client | Opaque pointer to client data. |
Definition at line 3206 of file fwd_bem_model.cpp.
|
static |
Callback: compute the spherical-model vector magnetic field at coils.
Returns one row per cardinal dipole direction (x, y, z). Matches the fwdVecFieldFunc signature.
| [in] | rd | Dipole position (3-element array). |
| [in] | coils | MEG coil definitions. |
| [out] | Bval | Output fields (3 x ncoil matrix, row-major). |
| [in] | client | Opaque pointer to client data. |
Definition at line 3102 of file fwd_bem_model.cpp.
|
static |
Read an integer tag from a FIFF node.
Definition at line 258 of file fwd_bem_model.cpp.
|
static |
Compute the linear potential coefficients for one source-destination pair.
| [in] | from | Source point. |
| [in] | to | Destination triangle. |
| [out] | omega | Output coefficients for the three triangle vertices. |
Definition at line 550 of file fwd_bem_model.cpp.
|
static |
Generate a set of dipole guess locations inside a boundary surface.
Creates an evenly-spaced grid of candidate source locations, optionally excluding points too close to the center of mass or outside the boundary.
| [in] | guess_surf | Predefined boundary surface for the guesses (may be nullptr). |
| [in] | guessrad | Radius for a spherical boundary if guess_surf is nullptr. |
| [in] | guess_r0 | Origin for the spherical boundary. |
| [in] | grid | Spacing between guess points (meters). |
| [in] | exclude | Exclude points closer than this to the CM of the boundary. |
| [in] | mindist | Minimum distance from the boundary surface. |
Definition at line 488 of file fwd_bem_model.cpp.
|
static |
Thread worker: compute the forward solution for one source space.
Used as a thread entry point; the argument is cast to the appropriate worker struct internally.
| [in] | arg | Per-thread work descriptor. |
Definition at line 2419 of file fwd_bem_model.cpp.
|
static |
Compute the constant-collocation magnetic field coefficient for one triangle.
| [in] | dest | Destination field point. |
| [in] | normal | Field direction of interest (unit vector). |
| [in] | tri | Source triangle. |
Definition at line 1691 of file fwd_bem_model.cpp.
| int FWDLIB::FwdBemModel::bem_method |
Approximation method (FWD_BEM_CONSTANT_COLL or FWD_BEM_LINEAR_COLL).
Definition at line 1037 of file fwd_bem_model.h.
| Eigen::VectorXf FWDLIB::FwdBemModel::field_mult |
Magnetic-field multipliers (length nsurf).
Definition at line 1035 of file fwd_bem_model.h.
| Eigen::MatrixXf FWDLIB::FwdBemModel::gamma |
Conductivity-ratio coupling matrix (nsurf x nsurf).
Definition at line 1033 of file fwd_bem_model.h.
| FIFFLIB::FiffCoordTrans FWDLIB::FwdBemModel::head_mri_t |
Head-to-MRI coordinate transform.
Definition at line 1044 of file fwd_bem_model.h.
| float FWDLIB::FwdBemModel::ip_approach_limit |
Threshold for isolated-problem approach.
Definition at line 1046 of file fwd_bem_model.h.
|
staticconstexpr |
Magnetic constant mu_0 / (4 * pi).
Definition at line 746 of file fwd_bem_model.h.
| Eigen::VectorXi FWDLIB::FwdBemModel::np |
Vertex count per surface (length nsurf).
Definition at line 1029 of file fwd_bem_model.h.
| int FWDLIB::FwdBemModel::nsol |
Dimension of the solution matrix.
Definition at line 1042 of file fwd_bem_model.h.
| int FWDLIB::FwdBemModel::nsurf |
Number of interface surfaces.
Definition at line 1030 of file fwd_bem_model.h.
| Eigen::VectorXi FWDLIB::FwdBemModel::ntri |
Triangle count per surface (length nsurf).
Definition at line 1028 of file fwd_bem_model.h.
| Eigen::VectorXf FWDLIB::FwdBemModel::sigma |
Conductivity of each layer (length nsurf).
Definition at line 1032 of file fwd_bem_model.h.
| QString FWDLIB::FwdBemModel::sol_name |
File from which the solution was loaded.
Definition at line 1038 of file fwd_bem_model.h.
| Eigen::MatrixXf FWDLIB::FwdBemModel::solution |
Potential solution matrix (nsol x nsol).
Definition at line 1040 of file fwd_bem_model.h.
| Eigen::VectorXf FWDLIB::FwdBemModel::source_mult |
Infinite-medium potential multipliers (length nsurf).
Definition at line 1034 of file fwd_bem_model.h.
| QString FWDLIB::FwdBemModel::surf_name |
File from which surfaces were loaded.
Definition at line 1024 of file fwd_bem_model.h.
| std::vector<std::shared_ptr<MNELIB::MNESurface> > FWDLIB::FwdBemModel::surfs |
Interface surfaces, outermost first.
Definition at line 1026 of file fwd_bem_model.h.
| bool FWDLIB::FwdBemModel::use_ip_approach |
Whether the isolated-problem approach is active.
Definition at line 1047 of file fwd_bem_model.h.
| Eigen::VectorXf FWDLIB::FwdBemModel::v0 |
Workspace for infinite-medium potentials (length nsol).
Definition at line 1041 of file fwd_bem_model.h.