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// DEFINE MEMBER METHODS
41//=============================================================================================================
42
44{
47 base = 0.0;
48 size = 0.0;
49 np = p_np;
50 rmag = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>::Zero(np, 3);
51 cosmag = Eigen::Matrix<float, Eigen::Dynamic, 3, Eigen::RowMajor>::Zero(np, 3);
52 w = Eigen::VectorXf::Zero(np);
53 /*
54 * Reasonable defaults
55 */
56 for (int k = 0; k < 3; k++) {
57 r0[k] = 0.0;
58 ex[k] = 0.0;
59 ey[k] = 0.0;
60 ez[k] = 0.0;
61 }
62 ex[0] = 1.0;
63 ey[1] = 1.0;
64 ez[2] = 1.0;
65}
66
67//=============================================================================================================
68
69FwdCoil::FwdCoil(const FwdCoil& p_FwdCoil)
70{
71 if (!p_FwdCoil.chname.isEmpty())
72 this->chname = p_FwdCoil.chname;
73 if (!p_FwdCoil.desc.isEmpty())
74 this->desc = p_FwdCoil.desc;
75 this->coil_class = p_FwdCoil.coil_class;
76 this->accuracy = p_FwdCoil.accuracy;
77 this->base = p_FwdCoil.base;
78 this->size = p_FwdCoil.size;
79 this->np = p_FwdCoil.np;
80 this->type = p_FwdCoil.type;
81
82 rmag = p_FwdCoil.rmag;
83 cosmag = p_FwdCoil.cosmag;
84 w = p_FwdCoil.w;
85
86 this->r0 = p_FwdCoil.r0;
87 this->ex = p_FwdCoil.ex;
88 this->ey = p_FwdCoil.ey;
89 this->ez = p_FwdCoil.ez;
90
91 this->coord_frame = p_FwdCoil.coord_frame;
92}
93
94//=============================================================================================================
95
99
100//=============================================================================================================
101
103{
104 if (ch.kind != FIFFV_EEG_CH) {
105 qWarning() << ch.ch_name << "is not an EEG channel. Cannot create an electrode definition.";
106 return nullptr;
107 }
108 if (!t.isEmpty() && t.from != FIFFV_COORD_HEAD) {
109 qWarning("Inappropriate coordinate transformation in fwd_create_eeg_el");
110 return nullptr;
111 }
112
113 FwdCoil::UPtr res;
114 if (ch.chpos.ex.norm() < 1e-4)
115 res = std::make_unique<FwdCoil>(1); /* No reference electrode */
116 else
117 res = std::make_unique<FwdCoil>(2); /* Reference electrode present */
118
119 res->chname = ch.ch_name;
120 res->desc = "EEG electrode";
121 res->coil_class = FWD_COILC_EEG;
122 res->accuracy = FWD_COIL_ACCURACY_NORMAL;
123 res->type = ch.chpos.coil_type;
124 res->r0 = ch.chpos.r0;
125 res->ex = ch.chpos.ex;
126 /*
127 * Optional coordinate transformation
128 */
129 if (!t.isEmpty()) {
130 FiffCoordTrans::apply_trans(res->r0.data(), t, FIFFV_MOVE);
131 FiffCoordTrans::apply_trans(res->ex.data(), t, FIFFV_MOVE);
132 res->coord_frame = t.to;
133 } else
134 res->coord_frame = FIFFV_COORD_HEAD;
135 /*
136 * The electrode location
137 */
138 res->rmag.row(0) = res->r0.transpose();
139 res->cosmag.row(0) = res->r0.transpose();
140 res->cosmag.row(0).normalize();
141 res->w[0] = 1.0;
142 /*
143 * Add the reference electrode, if appropriate
144 */
145 if (res->np == 2) {
146 res->rmag.row(1) = res->ex.transpose();
147 res->cosmag.row(1) = res->ex.transpose();
148 res->cosmag.row(1).normalize();
149 res->w[1] = -1.0;
150 }
151 return res;
152}
153
154//=============================================================================================================
155
157{
158 return (this->coil_class == FWD_COILC_MAG ||
161}
162
163//=============================================================================================================
164
166{
167 return this->coil_class == FWD_COILC_MAG;
168}
169
170//=============================================================================================================
171
173{
174 return this->coil_class == FWD_COILC_PLANAR_GRAD;
175}
176
177//=============================================================================================================
178
180{
181 return this->coil_class == FWD_COILC_EEG;
182}
FIFF channel descriptor record (FIFF_CH_INFO): per-channel logical/scanner numbers,...
#define FIFFV_EEG_CH
#define FIFFV_COORD_HEAD
#define FIFFV_MOVE
Single MEG sensor coil or EEG electrode described by a set of weighted integration points in its own ...
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:85
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:95
Eigen::Vector3f ey
Definition fwd_coil.h:174
QString chname
Definition fwd_coil.h:164
FwdCoil(int p_np)
Definition fwd_coil.cpp:43
bool is_eeg_electrode() const
Definition fwd_coil.cpp:179
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > cosmag
Definition fwd_coil.h:178
static FwdCoil::UPtr create_eeg_el(const FIFFLIB::FiffChInfo &ch, const FIFFLIB::FiffCoordTrans &t=FIFFLIB::FiffCoordTrans())
Definition fwd_coil.cpp:102
bool is_planar_coil() const
Definition fwd_coil.cpp:172
bool is_axial_coil() const
Definition fwd_coil.cpp:156
Eigen::Vector3f ex
Definition fwd_coil.h:173
Eigen::Vector3f r0
Definition fwd_coil.h:172
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > rmag
Definition fwd_coil.h:177
bool is_magnetometer_coil() const
Definition fwd_coil.cpp:165
Eigen::Vector3f ez
Definition fwd_coil.h:175
Eigen::VectorXf w
Definition fwd_coil.h:179