Skip to main content

FwdFieldMap

Namespace: FWDLIB  ·  Library: Forward Library

#include <fwd/fwd_field_map.h>

class FWDLIB::FwdFieldMap

Computes the per-vertex sensor-to-surface mapping matrix used to render a continuous scalp/cortex field that exactly reproduces the recorded MEG/EEG values.

Uses Legendre-series lead-field dot products evaluated on a sphere fitted to the head together with an SVD-based pseudo-inverse with eigenvalue truncation — the classic MNE field-interpolation recipe.

Ported from MNE-Python (BSD-3-Clause): _do_self_dots, _do_surface_dots, _fast_sphere_dot_r0 (_lead_dots.py); _compute_mapping_matrix, _pinv_trunc (_field_interpolation.py).

src/examples/ex_fwd_api/main.cpp
auto normalCoils = templates->create_meg_coils(goodMeg, goodMeg.size(), FWD_COIL_ACCURACY_NORMAL, raw.info.dev_head_t);
const Vector3f origin(0.0f, 0.0f, 0.04f);
MatrixX3f surfRr(3, 3);
surfRr << 0.0f, 0.0f, 0.12f, 0.08f, 0.0f, 0.08f, 0.0f, -0.09f, 0.07f;
const MatrixX3f surfNn = (surfRr.rowwise() - origin.transpose()).rowwise().normalized();
auto mapping = FwdFieldMap::computeMegMapping(*normalCoils, surfRr, surfNn, origin); // nvert x nchan

Static Methods​

computeMegMapping(coils, vertices, normals, origin, intrad, miss)​

Compute MEG sensor-to-surface mapping matrix.

Parameters:

  • coils : const FwdCoilSet & MEG coils (already transformed to target coordinate frame).

  • vertices : const Eigen::MatrixX3f & FsSurface vertex positions (nvert × 3).

  • normals : const Eigen::MatrixX3f & FsSurface vertex normals (nvert × 3).

  • origin : const Eigen::Vector3f & Sphere origin in the target coordinate frame.

  • intrad : float Integration radius (default 0.06, matching MNE-Python _setup_dots).

  • miss : float Eigenvalue truncation threshold (default 1e-4, matching _make_surface_mapping).

Returns:

  • std::unique_ptr< Eigen::MatrixXf > — Mapping matrix (nvert × nchan), or null on failure.

computeMegMapping(coils, vertices, normals, origin, info, chNames, intrad, miss)​

Compute MEG sensor-to-surface mapping matrix with SSP projection.

Parameters:

  • coils : const FwdCoilSet & MEG coils (already transformed to target coordinate frame).

  • vertices : const Eigen::MatrixX3f & FsSurface vertex positions (nvert × 3).

  • normals : const Eigen::MatrixX3f & FsSurface vertex normals (nvert × 3).

  • origin : const Eigen::Vector3f & Sphere origin in the target coordinate frame.

  • info : const FiffInfo & FiffInfo with SSP projectors and channel names.

  • chNames : const QStringList & Channel names corresponding to the coils (for projector matching).

  • intrad : float Integration radius (default 0.06).

  • miss : float Eigenvalue truncation threshold (default 1e-4).

Returns:

  • std::unique_ptr< Eigen::MatrixXf > — Mapping matrix (nvert × nchan), or null on failure.

computeEegMapping(coils, vertices, origin, intrad, miss)​

Compute EEG electrode-to-surface mapping matrix.

The effective integration radius is intrad * 0.7, matching MNE-Python's internal scaling in _do_self_dots / _do_surface_dots for EEG.

Parameters:

  • coils : const FwdCoilSet & EEG electrodes (already transformed to target coordinate frame).

  • vertices : const Eigen::MatrixX3f & FsSurface vertex positions (nvert × 3).

  • origin : const Eigen::Vector3f & Sphere origin in the target coordinate frame.

  • intrad : float Base integration radius (default 0.06, matching MNE-Python _setup_dots).

  • miss : float Eigenvalue truncation threshold (default 1e-3, matching _make_surface_mapping).

Returns:

  • std::unique_ptr< Eigen::MatrixXf > — Mapping matrix (nvert × nchan), or null on failure.

computeEegMapping(coils, vertices, origin, info, chNames, intrad, miss)​

Compute EEG electrode-to-surface mapping matrix with SSP projection and average reference.

Parameters:

  • coils : const FwdCoilSet & EEG electrodes (already transformed to target coordinate frame).

  • vertices : const Eigen::MatrixX3f & FsSurface vertex positions (nvert × 3).

  • origin : const Eigen::Vector3f & Sphere origin in the target coordinate frame.

  • info : const FiffInfo & FiffInfo with SSP projectors and channel names.

  • chNames : const QStringList & Channel names corresponding to the coils (for projector matching).

  • intrad : float Base integration radius (default 0.06).

  • miss : float Eigenvalue truncation threshold (default 1e-3).

Returns:

  • std::unique_ptr< Eigen::MatrixXf > — Mapping matrix (nvert × nchan), or null on failure.

Example​

Used in examples​

ex_fwd_api​

Forward library: coil definitions, BEM and sphere models, field maps and forward solutions.

src/examples/ex_fwd_api/main.cpp, line 158
MatrixX3f surfRr(3, 3);
surfRr << 0.0f, 0.0f, 0.12f, 0.08f, 0.0f, 0.08f, 0.0f, -0.09f, 0.07f;
const MatrixX3f surfNn = (surfRr.rowwise() - origin.transpose()).rowwise().normalized();
auto mapping = FwdFieldMap::computeMegMapping(*normalCoils, surfRr, surfNn, origin); // nvert x nchan
// mne _make_surface_mapping(mode="accurate", origin=(0, 0, 0.04)), no projectors: row norms 10.0598, 1.88928, 0.69807
ok &= expect(mapping && mapping->rows() == 3 && mapping->cols() == 305 && near(mapping->row(0).norm(), 10.059843, 1e-3) && near(mapping->row(1).norm(), 1.8892755, 1e-3) && near(mapping->row(2).norm(), 0.69807071, 1e-3),
"FwdFieldMap maps 305 good MEG channels onto surface points like mne");

Authors of this file​