v2.0.0
Loading...
Searching...
No Matches
fwd_coil.cpp
Go to the documentation of this file.
1//=============================================================================================================
36
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "fwd_coil.h"
42#include <fiff/fiff_ch_info.h>
43#include <stdio.h>
44#include <algorithm>
45
46//=============================================================================================================
47// QT INCLUDES
48//=============================================================================================================
49
50#include <QDebug>
51
52//=============================================================================================================
53// USED NAMESPACES
54//=============================================================================================================
55
56using namespace Eigen;
57using namespace FIFFLIB;
58using namespace FWDLIB;
59
60
61
62//=============================================================================================================
63// DEFINE MEMBER METHODS
64//=============================================================================================================
65
67{
70 base = 0.0;
71 size = 0.0;
72 np = p_np;
73 rmag = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>::Zero(np, 3);
74 cosmag = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>::Zero(np, 3);
75 w = Eigen::VectorXf::Zero(np);
76 /*
77 * Reasonable defaults
78 */
79 for (int k = 0; k < 3; k++) {
80 r0[k] = 0.0;
81 ex[k] = 0.0;
82 ey[k] = 0.0;
83 ez[k] = 0.0;
84 }
85 ex[0] = 1.0;
86 ey[1] = 1.0;
87 ez[2] = 1.0;
88}
89
90//=============================================================================================================
91
92FwdCoil::FwdCoil(const FwdCoil& p_FwdCoil)
93{
94 if (!p_FwdCoil.chname.isEmpty())
95 this->chname = p_FwdCoil.chname;
96 if (!p_FwdCoil.desc.isEmpty())
97 this->desc = p_FwdCoil.desc;
98 this->coil_class = p_FwdCoil.coil_class;
99 this->accuracy = p_FwdCoil.accuracy;
100 this->base = p_FwdCoil.base;
101 this->size = p_FwdCoil.size;
102 this->np = p_FwdCoil.np;
103 this->type = p_FwdCoil.type;
104
105 rmag = p_FwdCoil.rmag;
106 cosmag = p_FwdCoil.cosmag;
107 w = p_FwdCoil.w;
108
109 this->r0 = p_FwdCoil.r0;
110 this->ex = p_FwdCoil.ex;
111 this->ey = p_FwdCoil.ey;
112 this->ez = p_FwdCoil.ez;
113
114 this->coord_frame = p_FwdCoil.coord_frame;
115}
116
117//=============================================================================================================
118
122
123//=============================================================================================================
124
126{
127 if (ch.kind != FIFFV_EEG_CH) {
128 qWarning() << ch.ch_name << "is not an EEG channel. Cannot create an electrode definition.";
129 return nullptr;
130 }
131 if (!t.isEmpty() && t.from != FIFFV_COORD_HEAD) {
132 qWarning("Inappropriate coordinate transformation in fwd_create_eeg_el");
133 return nullptr;
134 }
135
136 FwdCoil::UPtr res;
137 if (ch.chpos.ex.norm() < 1e-4)
138 res = std::make_unique<FwdCoil>(1); /* No reference electrode */
139 else
140 res = std::make_unique<FwdCoil>(2); /* Reference electrode present */
141
142 res->chname = ch.ch_name;
143 res->desc = "EEG electrode";
144 res->coil_class = FWD_COILC_EEG;
145 res->accuracy = FWD_COIL_ACCURACY_NORMAL;
146 res->type = ch.chpos.coil_type;
147 res->r0 = ch.chpos.r0;
148 res->ex = ch.chpos.ex;
149 /*
150 * Optional coordinate transformation
151 */
152 if (!t.isEmpty()) {
153 FiffCoordTrans::apply_trans(res->r0.data(),t,FIFFV_MOVE);
154 FiffCoordTrans::apply_trans(res->ex.data(),t,FIFFV_MOVE);
155 res->coord_frame = t.to;
156 }
157 else
158 res->coord_frame = FIFFV_COORD_HEAD;
159 /*
160 * The electrode location
161 */
162 res->rmag.row(0) = res->r0.transpose();
163 res->cosmag.row(0) = res->r0.transpose();
164 res->cosmag.row(0).normalize();
165 res->w[0] = 1.0;
166 /*
167 * Add the reference electrode, if appropriate
168 */
169 if (res->np == 2) {
170 res->rmag.row(1) = res->ex.transpose();
171 res->cosmag.row(1) = res->ex.transpose();
172 res->cosmag.row(1).normalize();
173 res->w[1] = -1.0;
174 }
175 return res;
176}
177
178//=============================================================================================================
179
181{
182 return (this->coil_class == FWD_COILC_MAG ||
185}
186
187//=============================================================================================================
188
190{
191 return this->coil_class == FWD_COILC_MAG;
192}
193
194//=============================================================================================================
195
197{
198 return this->coil_class == FWD_COILC_PLANAR_GRAD;
199}
200
201//=============================================================================================================
202
204{
205 return this->coil_class == FWD_COILC_EEG;
206}
#define FIFFV_EEG_CH
#define FIFFV_COORD_HEAD
#define FIFFV_MOVE
FiffChInfo class declaration.
FwdCoil class declaration.
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Forward modelling (BEM, MEG/EEG lead fields).
Definition compute_fwd.h:91
constexpr int FWD_COIL_ACCURACY_NORMAL
Definition fwd_coil.h:81
constexpr int FWD_COILC_EEG
Definition fwd_coil.h:74
constexpr int FWD_COIL_ACCURACY_POINT
Definition fwd_coil.h:80
constexpr int FWD_COILC_PLANAR_GRAD
Definition fwd_coil.h:77
constexpr int FWD_COILC_UNKNOWN
Definition fwd_coil.h:73
constexpr int FWD_COILC_AXIAL_GRAD2
Definition fwd_coil.h:78
constexpr int FWD_COILC_AXIAL_GRAD
Definition fwd_coil.h:76
constexpr int FWD_COILC_MAG
Definition fwd_coil.h:75
Channel info descriptor.
Eigen::Vector3f r0
fiff_int_t coil_type
Eigen::Vector3f ex
Coordinate transformation description.
std::unique_ptr< FwdCoil > UPtr
Definition fwd_coil.h:95
Eigen::Vector3f ey
Definition fwd_coil.h:172
QString chname
Definition fwd_coil.h:162
FwdCoil(int p_np)
Definition fwd_coil.cpp:66
bool is_eeg_electrode() const
Definition fwd_coil.cpp:203
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > cosmag
Definition fwd_coil.h:176
static FwdCoil::UPtr create_eeg_el(const FIFFLIB::FiffChInfo &ch, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
Definition fwd_coil.cpp:125
bool is_planar_coil() const
Definition fwd_coil.cpp:196
bool is_axial_coil() const
Definition fwd_coil.cpp:180
Eigen::Vector3f ex
Definition fwd_coil.h:171
Eigen::Vector3f r0
Definition fwd_coil.h:170
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > rmag
Definition fwd_coil.h:175
bool is_magnetometer_coil() const
Definition fwd_coil.cpp:189
Eigen::Vector3f ez
Definition fwd_coil.h:173
Eigen::VectorXf w
Definition fwd_coil.h:177
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const