v2.0.0
Loading...
Searching...
No Matches
inv_hpi_data_updater.cpp
Go to the documentation of this file.
1//=============================================================================================================
20
21//=============================================================================================================
22// INCLUDES
23//=============================================================================================================
24
26#include <fiff/fiff_ch_info.h>
27#include <fiff/fiff_info.h>
28#include <iostream>
29
30//=============================================================================================================
31// QT INCLUDES
32//=============================================================================================================
33
34//=============================================================================================================
35// EIGEN INCLUDES
36//=============================================================================================================
37
38#include <Eigen/Dense>
39
40//=============================================================================================================
41// USED NAMESPACES
42//=============================================================================================================
43
44using namespace INVLIB;
45using namespace FIFFLIB;
46using namespace Eigen;
47
48//=============================================================================================================
49// DEFINE GLOBAL METHODS
50//=============================================================================================================
51
52//=============================================================================================================
53// DEFINE MEMBER METHODS
54//=============================================================================================================
55
56//=============================================================================================================
57
59: m_sensors(InvSensorSet())
60{
61 updateBadChannels(pFiffInfo);
62 updateChannels(pFiffInfo);
63 updateHpiDigitizer(pFiffInfo->dig);
64 updateSensors(m_lChannels);
65}
66
67//=============================================================================================================
68
69void InvHpiDataUpdater::updateBadChannels(FiffInfo::SPtr pFiffInfo)
70{
71 m_lBads = pFiffInfo->bads;
72}
73
74//=============================================================================================================
75
76void InvHpiDataUpdater::updateChannels(FiffInfo::SPtr pFiffInfo)
77{
78 // Get the indices of inner layer channels and exclude bad channels and create channellist
79 const int iNumCh = pFiffInfo->nchan;
80 m_lChannels.clear();
81 m_vecInnerind.clear();
82 for (int i = 0; i < iNumCh; ++i) {
83 if (pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_BABY_MAG ||
84 pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_VV_PLANAR_T1 ||
85 pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_VV_PLANAR_T2 ||
86 pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_VV_PLANAR_T3) {
87 // Check if the sensor is bad, if not append to innerind
88
89 if (!(pFiffInfo->bads.contains(pFiffInfo->ch_names.at(i)))) {
90 m_vecInnerind.append(i);
91 m_lChannels.append(pFiffInfo->chs[i]);
92 }
93 }
94 }
95}
96
97//=============================================================================================================
98
99void InvHpiDataUpdater::updateSensors(const QList<FIFFLIB::FiffChInfo>& lChannels)
100{
101 const Accuracy accuracy = Accuracy::high;
102 m_sensors = m_sensorSetCreator.updateSensorSet(lChannels, accuracy);
103}
104
105//=============================================================================================================
106
107void InvHpiDataUpdater::updateHpiDigitizer(const QList<FiffDigPoint>& lDig)
108{
109 // extract hpi coils from digitizer
110 QList<FiffDigPoint> lHPIPoints;
111 int iNumCoils = 0;
112
113 for (int i = 0; i < lDig.size(); ++i) {
114 if (lDig[i].kind == FIFFV_POINT_HPI) {
115 iNumCoils++;
116 lHPIPoints.append(lDig[i]);
117 }
118 }
119
120 // convert to matrix iNumCoils x 3
121 if (lHPIPoints.size() > 0) {
122 m_matHpiDigitizer = MatrixXd(iNumCoils, 3);
123 for (int i = 0; i < lHPIPoints.size(); ++i) {
124 m_matHpiDigitizer(i, 0) = lHPIPoints.at(i).r[0];
125 m_matHpiDigitizer(i, 1) = lHPIPoints.at(i).r[1];
126 m_matHpiDigitizer(i, 2) = lHPIPoints.at(i).r[2];
127 }
128 } else {
129 std::cout << "InvHpiFit::updateHpiDigitizer - No HPI coils digitized. Returning." << std::endl;
130 return;
131 }
132}
133
134//=============================================================================================================
135
137{
138 const bool bUpdate = checkIfChanged(pFiffInfo->bads, pFiffInfo->chs);
139 if (bUpdate) {
140 updateBadChannels(pFiffInfo);
141 updateChannels(pFiffInfo);
142 updateHpiDigitizer(pFiffInfo->dig);
143 updateSensors(m_lChannels);
144 }
145}
146
147//=============================================================================================================
148
149bool InvHpiDataUpdater::checkIfChanged(const QList<QString>& lBads, const QList<FIFFLIB::FiffChInfo>& lChannels)
150{
151 bool bUpdate = false;
152 if (!(m_lBads == lBads) || !(m_lChannels == lChannels)) {
153 bUpdate = true;
154 }
155 return bUpdate;
156}
157
158//=============================================================================================================
159
160void InvHpiDataUpdater::prepareDataAndProjectors(const MatrixXd& matData, const MatrixXd& matProjectors)
161{
162 prepareData(matData);
163 prepareProjectors(matProjectors);
164 m_matDataProjected = m_matProjectors * m_matInnerdata;
165}
166
167//=============================================================================================================
168
169void InvHpiDataUpdater::prepareData(const Eigen::MatrixXd& matData)
170{
171 // extract data for channels to use
172 m_matInnerdata = MatrixXd(m_vecInnerind.size(), matData.cols());
173
174 for (int j = 0; j < m_vecInnerind.size(); ++j) {
175 m_matInnerdata.row(j) << matData.row(m_vecInnerind[j]);
176 }
177}
178
179//=============================================================================================================
180
181void InvHpiDataUpdater::prepareProjectors(const Eigen::MatrixXd& matProjectors)
182{
183 // check if m_vecInnerInd is alreadz initialized
184 if (m_vecInnerind.size() == 0) {
185 std::cout << "InvHpiFit::updateProjectors - No channels. Returning." << std::endl;
186 return;
187 }
188
189 //Create new projector based on the excluded channels, first exclude the rows then the columns
190 MatrixXd matProjectorsRows(m_vecInnerind.size(), matProjectors.cols());
191 MatrixXd matProjectorsInnerind(m_vecInnerind.size(), m_vecInnerind.size());
192
193 for (int i = 0; i < matProjectorsRows.rows(); ++i) {
194 matProjectorsRows.row(i) = matProjectors.row(m_vecInnerind.at(i));
195 }
196
197 for (int i = 0; i < matProjectorsInnerind.cols(); ++i) {
198 matProjectorsInnerind.col(i) = matProjectorsRows.col(m_vecInnerind.at(i));
199 }
200 m_matProjectors = matProjectorsInnerind;
201 return;
202}
FIFF channel descriptor record (FIFF_CH_INFO): per-channel logical/scanner numbers,...
#define FIFFV_COIL_BABY_MAG
#define FIFFV_COIL_VV_PLANAR_T1
#define FIFFV_COIL_VV_PLANAR_T2
#define FIFFV_COIL_VV_PLANAR_T3
#define FIFFV_POINT_HPI
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Pre-processing front-end for HPI fitting — re-shapes raw MEG data, projectors and digitised coils int...
FIFF file I/O, in-memory data structures and high-level readers/writers.
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
QSharedPointer< FiffInfo > SPtr
Definition fiff_info.h:92
void checkForUpdate(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
void prepareDataAndProjectors(const Eigen::MatrixXd &matData, const Eigen::MatrixXd &matProjectors)
InvHpiDataUpdater(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
Stores MEG sensor geometry (positions, orientations, weights, coil count) for a single sensor type.