ComputeFwd
Namespace: FWDLIB · Library: Forward Library
mne.make_forward_solution in MNE-Python.
#include <fwd/compute_fwd.h>
class FWDLIB::ComputeFwd
Implements the forward-solution computation driver.
ComputeFwd is the worker/factory that takes a ComputeFwdSettings, initialises all required data structures (coil definitions, BEM or sphere model, source spaces, compensation data, coordinate transforms) and assembles the MEG/EEG lead-field matrix G one dipole column at a time. The computed MNEForwardSolution is returned by calculateFwd; updateHeadPos rebuilds only the MEG block after a new device-to-head transform.
Top-level driver for MEG/EEG forward-solution computation.
// mne_forward_solution --meg --eeg --accurate --label V1-lh.label with sphere models instead of a BEM
const QString label = tmp.filePath("V1-lh.label"); // the hemisphere is taken from the "-lh.label" suffix
QFile::copy(data + "/subjects/sample/label/lh.V1.label", label);
auto settings = std::make_shared<ComputeFwdSettings>();
settings->include_meg = true;
settings->include_eeg = true;
settings->accurate = true;
settings->srcname = data + "/subjects/sample/bem/sample-oct-6-src.fif";
settings->measname = rawFile.fileName();
settings->mriname = data + "/MEG/sample/all-trans.fif";
settings->r0 = origin;
settings->eeg_sphere_rad = 0.09f;
settings->mindist = 0.0f;
settings->filter_spaces = false;
settings->labels = {label};
settings->nlabel = 1;
settings->solname = tmp.filePath("V1-fwd.fif");
settings->pFiffInfo = QSharedPointer<FiffInfo>::create(raw.info);
settings->checkIntegrity();
auto fwd = std::make_shared<ComputeFwd>(settings)->calculateFwd();
QFile solFile(settings->solname);
fwd->write(solFile);
Public Methods
ComputeFwd(pSettings)
Constructs a ComputeFwd and initialises all data structures needed for the forward computation according to pSettings.
Parameters:
- pSettings : std::shared_ptr< ComputeFwdSettings > Shared pointer to the forward computation settings.
~ComputeFwd()
Destructor.
calculateFwd()
Perform the forward calculation.
Returns:
- std::unique_ptr< MNEForwardSolution > — The computed forward solution, or nullptr on error.
updateHeadPos(transDevHead, fwd)
Update the head position with a new device-to-head transform and recompute the MEG portion of the forward solution.
Parameters:
-
transDevHead : const FiffCoordTrans & The updated device-to-head coordinate transform.
-
fwd : MNEForwardSolution & The forward solution to update in place.
Returns:
- bool — True on success, false on error.
Example
- Full source:
src/examples/ex_fwd_api/main.cpp - Build target:
ex_fwd_api(runs under CTest) - Data: mne-cpp-test-data
Used in examples
ex_fwd_api
Forward library: coil definitions, BEM and sphere models, field maps and forward solutions.
settings->solname = tmp.filePath("V1-fwd.fif");
settings->pFiffInfo = QSharedPointer<FiffInfo>::create(raw.info);
settings->checkIntegrity();
auto fwd = std::make_shared<ComputeFwd>(settings)->calculateFwd();
QFile solFile(settings->solname);
fwd->write(solFile);
// mne _compute_forwards_meeg on the 78 V1 sources: |G| of source 0, x component, over 306 MEG channels
ok &= expect(fwd && fwd->nsource == 78 && fwd->sol->data.rows() == 366 && near(fwd->sol->data.col(0).head(306).norm(), 1.2455023232288232e-3, 1e-4),
"ComputeFwd: 78 V1 sources, 366 channels, sphere-model gain matches mne");
ex_compute_forward
This example shows how to compute the forward solution.
timer0.start();
std::shared_ptr<ComputeFwd> pFwdComputer = std::make_shared<ComputeFwd>(pSettings);
fTime0 = timer0.elapsed();
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>