MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
hpidataupdater.cpp
Go to the documentation of this file.
1//=============================================================================================================
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "hpidataupdater.h"
40#include <fiff/fiff_ch_info.h>
41#include <fiff/fiff_info.h>
42#include <iostream>
43
44//=============================================================================================================
45// QT INCLUDES
46//=============================================================================================================
47
48//=============================================================================================================
49// EIGEN INCLUDES
50//=============================================================================================================
51
52#include <Eigen/Dense>
53
54//=============================================================================================================
55// USED NAMESPACES
56//=============================================================================================================
57
58using namespace INVERSELIB;
59using namespace FIFFLIB;
60using namespace Eigen;
61
62//=============================================================================================================
63// DEFINE GLOBAL METHODS
64//=============================================================================================================
65
66//=============================================================================================================
67// DEFINE MEMBER METHODS
68//=============================================================================================================
69
70//=============================================================================================================
71
73 : m_sensors(SensorSet())
74{
75 updateBadChannels(pFiffInfo);
76 updateChannels(pFiffInfo);
77 updateHpiDigitizer(pFiffInfo->dig);
78 updateSensors(m_lChannels);
79}
80
81//=============================================================================================================
82
83void HpiDataUpdater::updateBadChannels(FiffInfo::SPtr pFiffInfo)
84{
85 m_lBads = pFiffInfo->bads;
86}
87
88//=============================================================================================================
89
90void HpiDataUpdater::updateChannels(FiffInfo::SPtr pFiffInfo)
91{
92 // Get the indices of inner layer channels and exclude bad channels and create channellist
93 const int iNumCh = pFiffInfo->nchan;
94 m_lChannels.clear();
95 m_vecInnerind.clear();
96 for (int i = 0; i < iNumCh; ++i) {
97 if(pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_BABY_MAG ||
98 pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_VV_PLANAR_T1 ||
99 pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_VV_PLANAR_T2 ||
100 pFiffInfo->chs[i].chpos.coil_type == FIFFV_COIL_VV_PLANAR_T3) {
101
102 // Check if the sensor is bad, if not append to innerind
103
104 if(!(pFiffInfo->bads.contains(pFiffInfo->ch_names.at(i)))) {
105 m_vecInnerind.append(i);
106 m_lChannels.append(pFiffInfo->chs[i]);
107 }
108 }
109 }
110}
111
112//=============================================================================================================
113
114void HpiDataUpdater::updateSensors(const QList<FIFFLIB::FiffChInfo>& lChannels)
115{
116 const Accuracy accuracy = Accuracy::high;
117 m_sensors = m_sensorSetCreator.updateSensorSet(lChannels,accuracy);
118}
119
120//=============================================================================================================
121
122void HpiDataUpdater::updateHpiDigitizer(const QList<FiffDigPoint>& lDig)
123{
124 // extract hpi coils from digitizer
125 QList<FiffDigPoint> lHPIPoints;
126 int iNumCoils = 0;
127
128 for(int i = 0; i < lDig.size(); ++i) {
129 if(lDig[i].kind == FIFFV_POINT_HPI) {
130 iNumCoils++;
131 lHPIPoints.append(lDig[i]);
132 }
133 }
134
135 // convert to matrix iNumCoils x 3
136 if (lHPIPoints.size() > 0) {
137 m_matHpiDigitizer = MatrixXd(iNumCoils,3);
138 for (int i = 0; i < lHPIPoints.size(); ++i) {
139 m_matHpiDigitizer(i,0) = lHPIPoints.at(i).r[0];
140 m_matHpiDigitizer(i,1) = lHPIPoints.at(i).r[1];
141 m_matHpiDigitizer(i,2) = lHPIPoints.at(i).r[2];
142 }
143 } else {
144 std::cout << "HPIFit::updateHpiDigitizer - No HPI coils digitized. Returning." << std::endl;
145 return;
146 }
147}
148
149//=============================================================================================================
150
152{
153 const bool bUpdate = checkIfChanged(pFiffInfo->bads,pFiffInfo->chs);
154 if(bUpdate)
155 {
156 updateBadChannels(pFiffInfo);
157 updateChannels(pFiffInfo);
158 updateHpiDigitizer(pFiffInfo->dig);
159 updateSensors(m_lChannels);
160 }
161}
162
163//=============================================================================================================
164
165bool HpiDataUpdater::checkIfChanged(const QList<QString>& lBads, const QList<FIFFLIB::FiffChInfo>& lChannels)
166{
167 bool bUpdate = false;
168 if(!(m_lBads == lBads) || !(m_lChannels == lChannels)) {
169 bUpdate = true;
170 }
171 return bUpdate;
172}
173
174//=============================================================================================================
175
176void HpiDataUpdater::prepareDataAndProjectors(const MatrixXd &matData, const MatrixXd &matProjectors)
177{
178 prepareData(matData);
179 prepareProjectors(matProjectors);
180 m_matDataProjected = m_matProjectors * m_matInnerdata;
181}
182
183//=============================================================================================================
184
185void HpiDataUpdater::prepareData(const Eigen::MatrixXd& matData)
186{
187 // extract data for channels to use
188 m_matInnerdata = MatrixXd(m_vecInnerind.size(), matData.cols());
189
190 for(int j = 0; j < m_vecInnerind.size(); ++j) {
191 m_matInnerdata.row(j) << matData.row(m_vecInnerind[j]);
192 }
193}
194
195//=============================================================================================================
196
197void HpiDataUpdater::prepareProjectors(const Eigen::MatrixXd& matProjectors)
198{
199 // check if m_vecInnerInd is alreadz initialized
200 if(m_vecInnerind.size() == 0) {
201 std::cout << "HPIFit::updateProjectors - No channels. Returning." << std::endl;
202 return;
203 }
204
205 //Create new projector based on the excluded channels, first exclude the rows then the columns
206 MatrixXd matProjectorsRows(m_vecInnerind.size(),matProjectors.cols());
207 MatrixXd matProjectorsInnerind(m_vecInnerind.size(),m_vecInnerind.size());
208
209 for (int i = 0; i < matProjectorsRows.rows(); ++i) {
210 matProjectorsRows.row(i) = matProjectors.row(m_vecInnerind.at(i));
211 }
212
213 for (int i = 0; i < matProjectorsInnerind.cols(); ++i) {
214 matProjectorsInnerind.col(i) = matProjectorsRows.col(m_vecInnerind.at(i));
215 }
216 m_matProjectors = matProjectorsInnerind;
217 return;
218}
FiffInfo class declaration.
#define FIFFV_COIL_BABY_MAG
FiffChInfo class declaration.
HpiDataUpdater class declaration.
QSharedPointer< FiffInfo > SPtr
Definition fiff_info.h:87
void prepareDataAndProjectors(const Eigen::MatrixXd &matData, const Eigen::MatrixXd &matProjectors)
void checkForUpdate(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
HpiDataUpdater(const QSharedPointer< FIFFLIB::FiffInfo > pFiffInfo)
SensorSet updateSensorSet(const QList< FIFFLIB::FiffChInfo > &channelList, const Accuracy &accuracy)