v2.0.0
Loading...
Searching...
No Matches
fwd_eeg_sphere_model.h
Go to the documentation of this file.
1//=============================================================================================================
36
37#ifndef FWD_EEG_SPHERE_MODEL_H
38#define FWD_EEG_SPHERE_MODEL_H
39
40//=============================================================================================================
41// INCLUDES
42//=============================================================================================================
43
44#include "fwd_global.h"
46#include "fwd_coil_set.h"
47
48//=============================================================================================================
49// EIGEN INCLUDES
50//=============================================================================================================
51
52#include <Eigen/Core>
53
54//=============================================================================================================
55// QT INCLUDES
56//=============================================================================================================
57
58#include <QDebug>
59
60#include <memory>
61#include <vector>
62
63//=============================================================================================================
64// DEFINE NAMESPACE FWDLIB
65//=============================================================================================================
66
67namespace FWDLIB
68{
69
70/*
71 * This is the beginning of the specific code
72 */
77{
78 Eigen::VectorXd y;
79 Eigen::VectorXd resi;
80 Eigen::MatrixXd M;
81 Eigen::MatrixXd uu;
82 Eigen::MatrixXd vv;
83 Eigen::VectorXd sing;
84 Eigen::VectorXd fn;
85 Eigen::VectorXd w;
86 int nfit;
87 int nterms;
88};
90
91//=============================================================================================================
100{
101public:
102 typedef std::unique_ptr<FwdEegSphereModel> UPtr;
103
104 //=========================================================================================================
109 explicit FwdEegSphereModel();
110
111 //=========================================================================================================
117 explicit FwdEegSphereModel(const FwdEegSphereModel& p_FwdEegSphereModel);
118
119 //=========================================================================================================
133 int nlayer,
134 const Eigen::VectorXf& rads,
135 const Eigen::VectorXf& sigmas);
136
137 //=========================================================================================================
141 virtual ~FwdEegSphereModel();
142
143 //=========================================================================================================
153 static FwdEegSphereModel::UPtr setup_eeg_sphere_model(const QString& eeg_model_file, QString eeg_model_name, float eeg_sphere_rad);
154
155 //=========================================================================================================
164 static fitUser new_fit_user(int nfit, int nterms);
165
166 //=========================================================================================================
176
177 //=========================================================================================================
189 static void next_legen(int n,
190 double x,
191 double& p0,
192 double& p01,
193 double& p1,
194 double& p11);
195
196 //=========================================================================================================
208 static void calc_pot_components(double beta,
209 double cgamma,
210 double& Vrp,
211 double& Vtp,
212 const Eigen::VectorXd& fn,
213 int nterms);
214
215 //=========================================================================================================
231 static int fwd_eeg_multi_spherepot(const Eigen::Vector3f& rd,
232 const Eigen::Vector3f& Q,
233 const Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>& el,
234 int neeg,
235 Eigen::VectorXf& Vval,
236 void* client);
237
238 //=========================================================================================================
251 static int fwd_eeg_multi_spherepot_coil1(const Eigen::Vector3f& rd,
252 const Eigen::Vector3f& Q,
253 FwdCoilSet& els,
254 Eigen::Ref<Eigen::VectorXf> Vval,
255 void* client);
256
257 //=========================================================================================================
282 static bool fwd_eeg_spherepot_vec(const Eigen::Vector3f& rd, const Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>& el, int neeg, Eigen::MatrixXf& Vval_vec, void* client);
283
284 //=========================================================================================================
302 static int fwd_eeg_spherepot_coil_vec(const Eigen::Vector3f& rd, FwdCoilSet& els, Eigen::Ref<Eigen::MatrixXf> Vval_vec, void* client);
303
304 //=========================================================================================================
320 static int fwd_eeg_spherepot_grad_coil(const Eigen::Vector3f& rd,
321 const Eigen::Vector3f& Q,
322 FwdCoilSet& coils,
323 Eigen::Ref<Eigen::VectorXf> Vval,
324 Eigen::Ref<Eigen::VectorXf> xgrad,
325 Eigen::Ref<Eigen::VectorXf> ygrad,
326 Eigen::Ref<Eigen::VectorXf> zgrad,
327 void* client);
328
329 //=========================================================================================================
347 static int fwd_eeg_spherepot(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, const Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>& el, int neeg, Eigen::VectorXf& Vval, void* client);
348
349 //=========================================================================================================
364 static int fwd_eeg_spherepot_coil(const Eigen::Vector3f& rd, const Eigen::Vector3f& Q, FwdCoilSet& els, Eigen::Ref<Eigen::VectorXf> Vval, void* client);
365
366 //=========================================================================================================
378 bool fwd_setup_eeg_sphere_model(float rad, bool fit_berg_scherg, int nFit);
379
380 //=========================================================================================================
388 static void compose_linear_fitting_data(const Eigen::VectorXd& mu, fitUser u);
389
390 //=========================================================================================================
401 static double compute_linear_parameters(const Eigen::VectorXd& mu, Eigen::VectorXd& lambda, fitUser u);
402
403 //=========================================================================================================
413 static double one_step(const Eigen::VectorXd& mu, const void* user_data);
414
415 //=========================================================================================================
429 bool fwd_eeg_fit_berg_scherg(int nTerms,
430 int nFit,
431 float& rv);
432
434 int nlayer() const
435 {
436 return static_cast<int>(layers.size());
437 }
438
439public:
440 QString name;
441 std::vector<FwdEegSphereLayer> layers;
442 Eigen::Vector3f r0;
443
444 Eigen::VectorXd fn;
445 int nterms;
446
447 Eigen::VectorXf mu;
448 Eigen::VectorXf lambda;
449 int nfit;
451};
452
453//=============================================================================================================
454// INLINE DEFINITIONS
455//=============================================================================================================
456} // NAMESPACE FWDLIB
457
458#endif // FWD_EEG_SPHERE_MODEL_H
Container of FwdCoil instances representing either a sensor-type template database or a concrete per-...
Symbol-visibility macro and build-info entry points for the FWDLIB (MEG/EEG forward-modelling) librar...
#define FWDSHARED_EXPORT
Definition fwd_global.h:44
Single concentric spherical shell (radius + conductivity) of a multi-layer EEG head model.
Forward modelling — BEM solver, spherical models, sensor/coil definitions and the lead-field assembly...
Definition compute_fwd.h:85
fitUserRec * fitUser
Container of FwdCoil instances acting both as the in-memory image of the coil_def....
Workspace for the linear least-squares fit of Berg-Scherg parameters in the EEG sphere model (SVD mat...
static double compute_linear_parameters(const Eigen::VectorXd &mu, Eigen::VectorXd &lambda, fitUser u)
static int fwd_eeg_multi_spherepot_coil1(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &els, Eigen::Ref< Eigen::VectorXf > Vval, void *client)
static FwdEegSphereModel::UPtr setup_eeg_sphere_model(const QString &eeg_model_file, QString eeg_model_name, float eeg_sphere_rad)
bool fwd_setup_eeg_sphere_model(float rad, bool fit_berg_scherg, int nFit)
static void calc_pot_components(double beta, double cgamma, double &Vrp, double &Vtp, const Eigen::VectorXd &fn, int nterms)
static fitUser new_fit_user(int nfit, int nterms)
static int fwd_eeg_spherepot(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, const Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > &el, int neeg, Eigen::VectorXf &Vval, void *client)
static bool fwd_eeg_spherepot_vec(const Eigen::Vector3f &rd, const Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > &el, int neeg, Eigen::MatrixXf &Vval_vec, void *client)
static void compose_linear_fitting_data(const Eigen::VectorXd &mu, fitUser u)
static int fwd_eeg_spherepot_grad_coil(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &coils, Eigen::Ref< Eigen::VectorXf > Vval, Eigen::Ref< Eigen::VectorXf > xgrad, Eigen::Ref< Eigen::VectorXf > ygrad, Eigen::Ref< Eigen::VectorXf > zgrad, void *client)
static int fwd_eeg_multi_spherepot(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, const Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > &el, int neeg, Eigen::VectorXf &Vval, void *client)
bool fwd_eeg_fit_berg_scherg(int nTerms, int nFit, float &rv)
static int fwd_eeg_spherepot_coil_vec(const Eigen::Vector3f &rd, FwdCoilSet &els, Eigen::Ref< Eigen::MatrixXf > Vval_vec, void *client)
static FwdEegSphereModel::UPtr fwd_create_eeg_sphere_model(const QString &name, int nlayer, const Eigen::VectorXf &rads, const Eigen::VectorXf &sigmas)
std::vector< FwdEegSphereLayer > layers
static void next_legen(int n, double x, double &p0, double &p01, double &p1, double &p11)
std::unique_ptr< FwdEegSphereModel > UPtr
static int fwd_eeg_spherepot_coil(const Eigen::Vector3f &rd, const Eigen::Vector3f &Q, FwdCoilSet &els, Eigen::Ref< Eigen::VectorXf > Vval, void *client)
double fwd_eeg_get_multi_sphere_model_coeff(int n)
static double one_step(const Eigen::VectorXd &mu, const void *user_data)