v2.0.0
Loading...
Searching...
No Matches
inv_dipole_fit_data.h
Go to the documentation of this file.
1//=============================================================================================================
23
24#ifndef INV_DIPOLE_FIT_DATA_H
25#define INV_DIPOLE_FIT_DATA_H
26
27//=============================================================================================================
28// INCLUDES
29//=============================================================================================================
30
31#include "../inv_global.h"
32
33#include <fiff/fiff_types.h>
34#include <fwd/fwd_types.h>
36#include <fwd/fwd_bem_model.h>
37#include <fwd/fwd_comp_data.h>
38#include "inv_dipole_forward.h"
39
40//=============================================================================================================
41// EIGEN INCLUDES
42//=============================================================================================================
43
44#include <Eigen/Core>
45
46//=============================================================================================================
47// QT INCLUDES
48//=============================================================================================================
49
50#include <QSharedPointer>
51#include <QTextStream>
52
53#include <memory>
54
55namespace FIFFLIB
56{
57class FiffCoordTrans;
58}
59namespace MNELIB
60{
61class MNEMeasData;
62}
63
64constexpr int COLUMN_NORM_NONE = 0;
65constexpr int COLUMN_NORM_COMP = 1;
66constexpr int COLUMN_NORM_LOC = 2;
67
68//=============================================================================================================
69// DEFINE NAMESPACE INVLIB
70//=============================================================================================================
71
72namespace INVLIB
73{
74
75// (Replaces *dipoleFitFuncs,dipoleFitFuncsRec struct of MNE-C fit_types.h).
76
81{
84 void* meg_client = nullptr;
85 std::unique_ptr<FWDLIB::FwdCompData> meg_comp;
86
89 void* eeg_client = nullptr;
90};
91
96
101{
102 float limit;
104 float* B;
105 double B2;
106 std::unique_ptr<InvDipoleForward> fwd;
107};
108
109//=============================================================================================================
110// FORWARD DECLARATIONS
111//=============================================================================================================
112
113class InvGuessData;
114class InvEcd;
115
116//=============================================================================================================
133{
134public:
135 typedef QSharedPointer<InvDipoleFitData> SPtr;
136 typedef QSharedPointer<const InvDipoleFitData> ConstSPtr;
137
138 //=========================================================================================================
142 explicit InvDipoleFitData();
143
144 //=========================================================================================================
149 virtual ~InvDipoleFitData();
150
151 //=========================================================================================================
167
168 //=========================================================================================================
185 static std::unique_ptr<MNELIB::MNECovMatrix> ad_hoc_noise(FWDLIB::FwdCoilSet* meg,
187 float grad_std,
188 float mag_std,
189 float eeg_std);
190
191 //=========================================================================================================
204 static int scale_noise_cov(InvDipoleFitData* f, int nave);
205
206 //=========================================================================================================
220
221 //=========================================================================================================
243 int nave,
244 const int* sels);
245
246 //=========================================================================================================
277 const QString& mriname,
278 const QString& measname,
279 const QString& bemname,
280 Eigen::Vector3f* r0,
282 int accurate_coils,
283 const QString& badname,
284 const QString& noisename,
285 float grad_std,
286 float mag_std,
287 float eeg_std,
288 float mag_reg,
289 float grad_reg,
290 float eeg_reg,
291 int diagnoise,
292 const QList<QString>& projnames,
293 int include_meg,
294 int include_eeg);
295
296 //=========================================================================================================
311 static bool fit_one(InvDipoleFitData* fit, InvGuessData* guess, float time, Eigen::Ref<Eigen::VectorXf> B, int verbose, InvEcd& res);
312
313 //=========================================================================================================
329 static int compute_dipole_field(InvDipoleFitData& d, const Eigen::Vector3f& rd, int whiten, Eigen::Ref<Eigen::MatrixXf> fwd);
330
331 //=========================================================================================================
350 static bool print_fields(const Eigen::Vector3f& rd,
351 const Eigen::Vector3f& Q,
352 float time,
353 float integ,
354 InvDipoleFitData& fit,
355 const MNELIB::MNEMeasData& data,
356 QTextStream& out);
357
358 //=========================================================================================================
374 static std::unique_ptr<InvDipoleForward> dipole_forward_one(InvDipoleFitData* d,
375 const Eigen::Vector3f& rd,
376 std::unique_ptr<InvDipoleForward> old);
377
378public:
379 std::unique_ptr<FIFFLIB::FiffCoordTrans> mri_head_t;
380 std::unique_ptr<FIFFLIB::FiffCoordTrans> meg_head_t;
382 QList<FIFFLIB::FiffChInfo> chs;
383 int nmeg;
384 int neeg;
385 QStringList ch_names;
386 std::unique_ptr<FIFFLIB::FiffSparseMatrix> pick;
387 std::unique_ptr<FWDLIB::FwdCoilSet> meg_coils;
388 std::unique_ptr<FWDLIB::FwdCoilSet> eeg_els;
389 Eigen::Vector3f r0;
390 QString bemname;
391
392 std::unique_ptr<FWDLIB::FwdEegSphereModel> eeg_model;
393 std::unique_ptr<FWDLIB::FwdBemModel> bem_model;
394
395 std::unique_ptr<dipoleFitFuncsRec> sphere_funcs;
396 std::unique_ptr<dipoleFitFuncsRec> bem_funcs;
398 std::unique_ptr<dipoleFitFuncsRec> mag_dipole_funcs;
399
401 std::unique_ptr<MNELIB::MNECovMatrix> noise_orig;
402 std::unique_ptr<MNELIB::MNECovMatrix> noise;
403 int nave;
404 std::unique_ptr<MNELIB::MNEProjOp> proj;
408};
409
410//=============================================================================================================
411// INLINE DEFINITIONS
412//=============================================================================================================
413} //NAMESPACE
414
415#endif // INV_DIPOLE_FIT_DATA_H
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
Software-gradiometer compensation wrapper that subtracts the reference-channel contribution from the ...
Multi-shell spherical head model with Berg-Scherg equivalent-source approximation for fast EEG forwar...
Boundary Element Method (BEM) volume-conductor model — layered triangulated surfaces,...
std::function aliases for the generic dipole field / potential / field-gradient callbacks driving the...
std::function< int(const Eigen::Vector3f &rd, FWDLIB::FwdCoilSet &coils, Eigen::Ref< Eigen::MatrixXf > res, void *client)> fwdVecFieldFunc
Definition fwd_types.h:49
std::function< int(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FWDLIB::FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > res, void *client)> fwdFieldFunc
Definition fwd_types.h:47
Per-iteration forward-field cache (forward matrix, SVD, column normalisation) used by the dipole-fit ...
constexpr int COLUMN_NORM_NONE
constexpr int COLUMN_NORM_COMP
constexpr int COLUMN_NORM_LOC
INVLIB library export/import macros, build-info accessors, and namespace docstring for the inverse-so...
#define INVSHARED_EXPORT
Definition inv_global.h:38
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O, in-memory data structures and high-level readers/writers.
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
dipoleFitFuncsRec * dipoleFitFuncs
Pointer alias for dipoleFitFuncsRec, used throughout the dipole fitting module.
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
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...
Forward field computation function pointers and client data for MEG and EEG dipole fitting.
std::unique_ptr< FWDLIB::FwdCompData > meg_comp
Workspace for the dipole fitting objective function, holding forward model, measured field,...
std::unique_ptr< InvDipoleForward > fwd
std::unique_ptr< FWDLIB::FwdEegSphereModel > eeg_model
QSharedPointer< const InvDipoleFitData > ConstSPtr
std::unique_ptr< FWDLIB::FwdCoilSet > meg_coils
static InvDipoleFitData * setup_dipole_fit_data(const QString &mriname, const QString &measname, const QString &bemname, Eigen::Vector3f *r0, FWDLIB::FwdEegSphereModel *eeg_model, int accurate_coils, const QString &badname, const QString &noisename, float grad_std, float mag_std, float eeg_std, float mag_reg, float grad_reg, float eeg_reg, int diagnoise, const QList< QString > &projnames, int include_meg, int include_eeg)
Master setup: read all inputs and build a ready-to-use fit workspace.
std::unique_ptr< FIFFLIB::FiffCoordTrans > mri_head_t
static int scale_dipole_fit_noise_cov(InvDipoleFitData *f, int nave)
Scale dipole-fit noise covariance for a given number of averages.
std::unique_ptr< MNELIB::MNEProjOp > proj
static bool print_fields(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, float time, float integ, InvDipoleFitData &fit, const MNELIB::MNEMeasData &data, QTextStream &out)
Write the measured and the predicted field of a dipole, channel by channel.
QSharedPointer< InvDipoleFitData > SPtr
std::unique_ptr< MNELIB::MNECovMatrix > noise
std::unique_ptr< dipoleFitFuncsRec > bem_funcs
static int scale_noise_cov(InvDipoleFitData *f, int nave)
Scale the noise-covariance matrix for a given number of averages.
std::unique_ptr< FIFFLIB::FiffSparseMatrix > pick
std::unique_ptr< dipoleFitFuncsRec > sphere_funcs
static std::unique_ptr< InvDipoleForward > dipole_forward_one(InvDipoleFitData *d, const Eigen::Vector3f &rd, std::unique_ptr< InvDipoleForward > old)
Compute the forward solution for a single dipole position.
static bool fit_one(InvDipoleFitData *fit, InvGuessData *guess, float time, Eigen::Ref< Eigen::VectorXf > B, int verbose, InvEcd &res)
Fit a single dipole to the given data.
static int compute_dipole_field(InvDipoleFitData &d, const Eigen::Vector3f &rd, int whiten, Eigen::Ref< Eigen::MatrixXf > fwd)
Compute the forward field for a dipole at the given location.
static int setup_forward_model(InvDipoleFitData *d, MNELIB::MNECTFCompDataSet *comp_data, FWDLIB::FwdCoilSet *comp_coils)
Set up the sphere-model and (optionally) BEM forward functions.
QList< FIFFLIB::FiffChInfo > chs
std::unique_ptr< FWDLIB::FwdBemModel > bem_model
static int select_dipole_fit_noise_cov(InvDipoleFitData *f, MNELIB::MNEMeasData *meas, int nave, const int *sels)
Select and weight the noise-covariance for the active channel set.
std::unique_ptr< FWDLIB::FwdCoilSet > eeg_els
std::unique_ptr< dipoleFitFuncsRec > mag_dipole_funcs
static std::unique_ptr< MNELIB::MNECovMatrix > ad_hoc_noise(FWDLIB::FwdCoilSet *meg, FWDLIB::FwdCoilSet *eeg, float grad_std, float mag_std, float eeg_std)
Create an ad-hoc diagonal noise-covariance matrix.
std::unique_ptr< MNELIB::MNECovMatrix > noise_orig
std::unique_ptr< FIFFLIB::FiffCoordTrans > meg_head_t
Single equivalent current dipole with position, orientation, amplitude, and goodness-of-fit.
Definition inv_ecd.h:58
Precomputed guess point grid with forward fields for initial dipole position candidates.
Collection of CTF third-order gradient compensation operators.
Measurement data container for MNE inverse and dipole-fit computations.