v2.0.0
Loading...
Searching...
No Matches
fwd_coil.cpp
Go to the documentation of this file.
1//=============================================================================================================
14
15//=============================================================================================================
16// INCLUDES
17//=============================================================================================================
18
19#include "fwd_coil.h"
20#include <fiff/fiff_ch_info.h>
21#include <stdio.h>
22#include <algorithm>
23
24//=============================================================================================================
25// QT INCLUDES
26//=============================================================================================================
27
28#include <QDebug>
29
30//=============================================================================================================
31// USED NAMESPACES
32//=============================================================================================================
33
34using namespace Eigen;
35using namespace FIFFLIB;
36using namespace FWDLIB;
37
38
39
40//=============================================================================================================
41// DEFINE MEMBER METHODS
42//=============================================================================================================
43
45{
48 base = 0.0;
49 size = 0.0;
50 np = p_np;
51 rmag = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>::Zero(np, 3);
52 cosmag = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>::Zero(np, 3);
53 w = Eigen::VectorXf::Zero(np);
54 /*
55 * Reasonable defaults
56 */
57 for (int k = 0; k < 3; k++) {
58 r0[k] = 0.0;
59 ex[k] = 0.0;
60 ey[k] = 0.0;
61 ez[k] = 0.0;
62 }
63 ex[0] = 1.0;
64 ey[1] = 1.0;
65 ez[2] = 1.0;
66}
67
68//=============================================================================================================
69
70FwdCoil::FwdCoil(const FwdCoil& p_FwdCoil)
71{
72 if (!p_FwdCoil.chname.isEmpty())
73 this->chname = p_FwdCoil.chname;
74 if (!p_FwdCoil.desc.isEmpty())
75 this->desc = p_FwdCoil.desc;
76 this->coil_class = p_FwdCoil.coil_class;
77 this->accuracy = p_FwdCoil.accuracy;
78 this->base = p_FwdCoil.base;
79 this->size = p_FwdCoil.size;
80 this->np = p_FwdCoil.np;
81 this->type = p_FwdCoil.type;
82
83 rmag = p_FwdCoil.rmag;
84 cosmag = p_FwdCoil.cosmag;
85 w = p_FwdCoil.w;
86
87 this->r0 = p_FwdCoil.r0;
88 this->ex = p_FwdCoil.ex;
89 this->ey = p_FwdCoil.ey;
90 this->ez = p_FwdCoil.ez;
91
92 this->coord_frame = p_FwdCoil.coord_frame;
93}
94
95//=============================================================================================================
96
100
101//=============================================================================================================
102
104{
105 if (ch.kind != FIFFV_EEG_CH) {
106 qWarning() << ch.ch_name << "is not an EEG channel. Cannot create an electrode definition.";
107 return nullptr;
108 }
109 if (!t.isEmpty() && t.from != FIFFV_COORD_HEAD) {
110 qWarning("Inappropriate coordinate transformation in fwd_create_eeg_el");
111 return nullptr;
112 }
113
114 FwdCoil::UPtr res;
115 if (ch.chpos.ex.norm() < 1e-4)
116 res = std::make_unique<FwdCoil>(1); /* No reference electrode */
117 else
118 res = std::make_unique<FwdCoil>(2); /* Reference electrode present */
119
120 res->chname = ch.ch_name;
121 res->desc = "EEG electrode";
122 res->coil_class = FWD_COILC_EEG;
123 res->accuracy = FWD_COIL_ACCURACY_NORMAL;
124 res->type = ch.chpos.coil_type;
125 res->r0 = ch.chpos.r0;
126 res->ex = ch.chpos.ex;
127 /*
128 * Optional coordinate transformation
129 */
130 if (!t.isEmpty()) {
131 FiffCoordTrans::apply_trans(res->r0.data(),t,FIFFV_MOVE);
132 FiffCoordTrans::apply_trans(res->ex.data(),t,FIFFV_MOVE);
133 res->coord_frame = t.to;
134 }
135 else
136 res->coord_frame = FIFFV_COORD_HEAD;
137 /*
138 * The electrode location
139 */
140 res->rmag.row(0) = res->r0.transpose();
141 res->cosmag.row(0) = res->r0.transpose();
142 res->cosmag.row(0).normalize();
143 res->w[0] = 1.0;
144 /*
145 * Add the reference electrode, if appropriate
146 */
147 if (res->np == 2) {
148 res->rmag.row(1) = res->ex.transpose();
149 res->cosmag.row(1) = res->ex.transpose();
150 res->cosmag.row(1).normalize();
151 res->w[1] = -1.0;
152 }
153 return res;
154}
155
156//=============================================================================================================
157
159{
160 return (this->coil_class == FWD_COILC_MAG ||
163}
164
165//=============================================================================================================
166
168{
169 return this->coil_class == FWD_COILC_MAG;
170}
171
172//=============================================================================================================
173
175{
176 return this->coil_class == FWD_COILC_PLANAR_GRAD;
177}
178
179//=============================================================================================================
180
182{
183 return this->coil_class == FWD_COILC_EEG;
184}
Single MEG sensor coil or EEG electrode described by a set of weighted integration points in its own ...
#define FIFFV_EEG_CH
#define FIFFV_COORD_HEAD
#define FIFFV_MOVE
FIFF channel descriptor record (FIFF_CH_INFO): per-channel logical/scanner numbers,...
FIFF file I/O, in-memory data structures and high-level readers/writers.
Forward modelling — BEM solver, spherical models, sensor/coil definitions and the lead-field assembly...
Definition compute_fwd.h:83
constexpr int FWD_COIL_ACCURACY_NORMAL
Definition fwd_coil.h:76
constexpr int FWD_COILC_EEG
Definition fwd_coil.h:69
constexpr int FWD_COIL_ACCURACY_POINT
Definition fwd_coil.h:75
constexpr int FWD_COILC_PLANAR_GRAD
Definition fwd_coil.h:72
constexpr int FWD_COILC_UNKNOWN
Definition fwd_coil.h:68
constexpr int FWD_COILC_AXIAL_GRAD2
Definition fwd_coil.h:73
constexpr int FWD_COILC_AXIAL_GRAD
Definition fwd_coil.h:71
constexpr int FWD_COILC_MAG
Definition fwd_coil.h:70
Per-channel FIFF descriptor: identifiers, kind, calibration, coil type, channel-frame coil position a...
Eigen::Vector3f r0
fiff_int_t coil_type
Eigen::Vector3f ex
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
std::unique_ptr< FwdCoil > UPtr
Definition fwd_coil.h:90
Eigen::Vector3f ey
Definition fwd_coil.h:167
QString chname
Definition fwd_coil.h:157
FwdCoil(int p_np)
Definition fwd_coil.cpp:44
bool is_eeg_electrode() const
Definition fwd_coil.cpp:181
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > cosmag
Definition fwd_coil.h:171
static FwdCoil::UPtr create_eeg_el(const FIFFLIB::FiffChInfo &ch, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
Definition fwd_coil.cpp:103
bool is_planar_coil() const
Definition fwd_coil.cpp:174
bool is_axial_coil() const
Definition fwd_coil.cpp:158
Eigen::Vector3f ex
Definition fwd_coil.h:166
Eigen::Vector3f r0
Definition fwd_coil.h:165
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > rmag
Definition fwd_coil.h:170
bool is_magnetometer_coil() const
Definition fwd_coil.cpp:167
Eigen::Vector3f ez
Definition fwd_coil.h:168
Eigen::VectorXf w
Definition fwd_coil.h:172