Skip to main content

InvEcd

Namespace: INVLIB  ·  Library: Inverse Library

#include <inv/inv_ecd.h>

class INVLIB::InvEcd

Implements one Electric Current Dipole (Replaces *ecd,ecdRec struct of MNE-C fit_types.h).

Single equivalent current dipole with position, orientation, amplitude, and goodness-of-fit.

src/examples/ex_inv_dipole_fit/main.cpp
// MEG channels and SSP projectors from the sample file, sphere at (0, 0, 40) mm, ad-hoc noise
// (5e-13 T/m gradiometers, 20 fT magnetometers).
Vector3f r0(0.0f, 0.0f, 0.04f);
std::unique_ptr<InvDipoleFitData> fitData(InvDipoleFitData::setup_dipole_fit_data(
QString(), sampleAve, QString(), &r0, nullptr, false, QString(), QString(),
5e-13f, 20e-15f, 0.2e-6f, 0.1f, 0.1f, 0.1f, false, {sampleAve}, true, false));
MatrixXf gain(fitData->nmeg, 3);
const bool fieldOk = InvDipoleFitData::compute_dipole_field(*fitData, truePos, false, gain) == 0; // projected, not whitened
VectorXf field = gain * trueMoment;

InvGuessData guesses(QString(), QString(), 0.0f, 0.02f, 0.015f, fitData.get(), 0.08f); // 15 mm grid in an 80 mm sphere
std::unique_ptr<InvDipoleForward> atTruth(InvDipoleFitData::dipole_forward_one(fitData.get(), truePos, nullptr));
InvEcd dipole;
VectorXf b = field; // fit_one projects and whitens in place
const bool fitted = InvDipoleFitData::fit_one(fitData.get(), &guesses, 0.0f, b, false, dipole);

Public Methods​

InvEcd()​

Constructs the Electric Current Dipole.


InvEcd(p_ECD)​

Copy constructor.

Parameters:

  • p_ECD : const InvEcd & Electric Current Dipole which should be copied.

operator=(other)​

Copy assignment.

Every member has value semantics, so the compiler-generated member-wise assignment is correct. It is declared explicitly because declaring a copy constructor and/or a destructor deprecates the implicitly generated one.

Parameters:

  • other : const InvEcd & Object to assign from.

Returns:

  • InvEcd & — reference to this object.

~InvEcd()​

Destroys the Electric Current Dipole description.


print()​

Prints the InvEcd dipole information to the debug output.


Example​

Used in examples​

ex_disp3d_scene​

Disp3D scene data: sensor-to-surface interpolation, electrodes, MRI slices, video overlay and layers.

src/examples/ex_disp3d_scene/main.cpp, line 255
InvEcdSet dipoles;
InvEcd strong;
strong.rd = Vector3f(0.0f, 0.0f, 0.05f);
strong.Q = Vector3f(0.0f, 0.0f, 20e-9f);
InvEcd weak;
weak.rd = Vector3f(0.03f, 0.0f, 0.05f);
weak.Q = Vector3f(10e-9f, 0.0f, 0.0f);
dipoles.addEcd(strong);
dipoles.addEcd(weak);
DipoleObject dipoleGlyphs;
dipoleGlyphs.load(dipoles); // one cone per dipole, scaled by moment
float dipoleDistance = 0.0f;
const int pickedDipole = dipoleGlyphs.intersect(QVector3D(0.03f, 0.0f, 0.2f), QVector3D(0.0f, 0.0f, -1.0f), dipoleDistance);

ex_inv_dipole_fit​

Inverse library: equivalent current dipole fitting in a sphere model.

src/examples/ex_inv_dipole_fit/main.cpp, line 106
InvGuessData guesses(QString(), QString(), 0.0f, 0.02f, 0.015f, fitData.get(), 0.08f); // 15 mm grid in an 80 mm sphere
std::unique_ptr<InvDipoleForward> atTruth(InvDipoleFitData::dipole_forward_one(fitData.get(), truePos, nullptr));
InvEcd dipole;
VectorXf b = field; // fit_one projects and whitens in place
const bool fitted = InvDipoleFitData::fit_one(fitData.get(), &guesses, 0.0f, b, false, dipole);
ok &= expect(fieldOk && fitted && fitData->nmeg == 305 && guesses.nguess == 627 && atTruth && atTruth->sing.size() == 3 && dipole.valid && (dipole.rd - truePos).norm() < 1e-3f && (1e9 * dipole.Q.cast<double>() - mneMomentNAm).norm() < 0.02 * mneMomentNAm.norm() && dipole.good > 0.9999f,
"InvDipoleFitData/InvGuessData/InvDipoleForward/InvEcd: one sample fits the dipole like mne.fit_dipole");

Authors of this file​