MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
fwd_eeg_sphere_model.h
Go to the documentation of this file.
1//=============================================================================================================
37#ifndef FWDEEGSPHEREMODEL_H
38#define FWDEEGSPHEREMODEL_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 <QSharedPointer>
59#include <QList>
60#include <QDebug>
61
62//=============================================================================================================
63// DEFINE NAMESPACE FWDLIB
64//=============================================================================================================
65
66namespace FWDLIB
67{
68
69/*
70 * This is the beginning of the specific code
71 */
72typedef struct {
73 double *y;
74 double *resi;
75 double **M;
76 double **uu;
77 double **vv;
78 double *sing;
79 double *fn;
80 double *w;
81 int nfit;
82 int nterms;
84
85//=============================================================================================================
92{
93public:
94 typedef QSharedPointer<FwdEegSphereModel> SPtr;
95 typedef QSharedPointer<const FwdEegSphereModel> ConstSPtr;
97 //=========================================================================================================
103 explicit FwdEegSphereModel();
104
105 //=========================================================================================================
112 explicit FwdEegSphereModel(const FwdEegSphereModel& p_FwdEegSphereModel);
113
114 /*
115 * Produce a new sphere model structure
116 */
117 static FwdEegSphereModel* fwd_create_eeg_sphere_model(const QString& name,
118 int nlayer,
119 const Eigen::VectorXf& rads,
120 const Eigen::VectorXf& sigmas);
121
122 //=========================================================================================================
127 virtual ~FwdEegSphereModel();
128
129 //=========================================================================================================
140 static FwdEegSphereModel* setup_eeg_sphere_model(const QString& eeg_model_file, QString eeg_model_name, float eeg_sphere_rad);
141
142 static fitUser new_fit_user(int nfit, int nterms);
143
144 //=========================================================================================================
154 double fwd_eeg_get_multi_sphere_model_coeff(int n);
155
156 static void next_legen (int n,
157 double x,
158 double *p0, /* Input: P0(n-1) Output: P0(n) */
159 double *p01, /* Input: P0(n-2) Output: P0(n-1) */
160 double *p1, /* Input: P1(n-1) Output: P1(n) */
161 double *p11);
162
163 static void calc_pot_components(double beta, /* rd/r */
164 double cgamma, /* Cosine of the angle between
165 * the source and field points */
166 double *Vrp, /* Potential component for the radial dipole */
167 double *Vtp, /* Potential component for the tangential dipole */
168 const Eigen::VectorXd& fn,
169 int nterms);
170
171 static int fwd_eeg_multi_spherepot(float *rd, /* Dipole position */
172 float *Q, /* Dipole moment */
173 float **el, /* Electrode positions */
174 int neeg, /* Number of electrodes */
175 float *Vval, /* The potential values */
176 void *client);
177
178 static int fwd_eeg_multi_spherepot_coil1(float *rd, /* Dipole position */
179 float *Q, /* Dipole moment */
180 FwdCoilSet* els, /* Electrode positions */
181 float *Vval, /* The potential values */
182 void *client);
183
184 //=========================================================================================================
209 static bool fwd_eeg_spherepot_vec (float *rd, float **el, int neeg, float **Vval_vec, void *client);
210
211 //=========================================================================================================
229 static int fwd_eeg_spherepot_coil_vec(float *rd, FwdCoilSet* els, float **Vval_vec, void *client);
230
231 static int fwd_eeg_spherepot_grad_coil( float *rd, /* The dipole location */
232 float Q[], /* The dipole components (xyz) */
233 FwdCoilSet* coils, /* The coil definitions */
234 float Vval[], /* Results */
235 float xgrad[], /* The derivatives with respect to */
236 float ygrad[], /* the dipole position coordinates */
237 float zgrad[],
238 void *client);
239
240 //=========================================================================================================
258 static int fwd_eeg_spherepot( float *rd, float *Q, float **el, int neeg, Eigen::VectorXf& Vval, void *client);
259
260 //=========================================================================================================
275 static int fwd_eeg_spherepot_coil(float *rd, float *Q, FwdCoilSet* els, float *Vval, void *client);
276
277 //=========================================================================================================
289 bool fwd_setup_eeg_sphere_model(float rad, bool fit_berg_scherg, int nfit);
290
291 // fwd_fit_berg_scherg.c
292
293 static void compose_linear_fitting_data(const Eigen::VectorXd& mu,fitUser u);
294
295 // fwd_fit_berg_scherg.c
296 /*
297 * Compute the best-fitting linear parameters
298 * Return the corresponding RV
299 */
300 static double compute_linear_parameters(const Eigen::VectorXd& mu, Eigen::VectorXd& lambda, fitUser u);
301
302 // fwd_fit_berg_scherg.c
303 /*
304 * Evaluate the residual sum of squares fit for one set of
305 * mu values
306 */
307 static double one_step (const Eigen::VectorXd& mu, const void *user_data);
308
309 /*
310 * This routine fits the Berg-Scherg equivalent spherical model
311 * dipole parameters by minimizing the difference between the
312 * actual and approximative series expansions
313 */
314 bool fwd_eeg_fit_berg_scherg(int nterms, /* Number of terms to use in the series expansion
315 * when fitting the parameters */
316 int nfit, /* Number of equivalent dipoles to fit */
317 float &rv);
318
320 int nlayer() const
321 {
322 return layers.size();
323 }
324
325public:
326 QString name;
327 QList<FwdEegSphereLayer> layers;
328 Eigen::Vector3f r0;
330 Eigen::VectorXd fn;
331 int nterms;
333 Eigen::VectorXf mu;
334 Eigen::VectorXf lambda;
335 int nfit;
338// ### OLD STRUCT ###
339// typedef struct {
340// char *name; /* Textual identifier */
341// int nlayer; /* Number of layers */
342// fwdEegSphereLayer layers; /* An array of layers */
343// float r0[3]; /* The origin */
344
345// double *fn; /* Coefficients saved to speed up the computations */
346// int nterms; /* How many? */
347
348// float *mu; /* The Berg-Scherg equivalence parameters */
349// float *lambda;
350// int nfit; /* How many? */
351// int scale_pos; /* Scale the positions to the surface of the sphere? */
352// } *fwdEegSphereModel,fwdEegSphereModelRec;
353};
354
355//=============================================================================================================
356// INLINE DEFINITIONS
357//=============================================================================================================
358} // NAMESPACE FWDLIB
359
360#endif // FWDEEGSPHEREMODEL_H
forward library export/import macros.
#define FWDSHARED_EXPORT
Definition fwd_global.h:57
FwdCoilSet class declaration.
FwdEegSphereLayer class declaration.
FwdCoilSet description.
Electric Current Dipole description.
QList< FwdEegSphereLayer > layers
QSharedPointer< FwdEegSphereModel > SPtr
QSharedPointer< const FwdEegSphereModel > ConstSPtr