v2.0.0
Loading...
Searching...
No Matches
artifactsettingsview.cpp
Go to the documentation of this file.
1//=============================================================================================================
14
15//=============================================================================================================
16// INCLUDES
17//=============================================================================================================
18
20
21#include <fiff/fiff_ch_info.h>
22
23//=============================================================================================================
24// QT INCLUDES
25//=============================================================================================================
26
27#include <QSettings>
28#include <QLabel>
29#include <QGridLayout>
30#include <QCheckBox>
31#include <QDoubleSpinBox>
32#include <QSpinBox>
33#include <QDebug>
34
35//=============================================================================================================
36// EIGEN INCLUDES
37//=============================================================================================================
38
39//=============================================================================================================
40// USED NAMESPACES
41//=============================================================================================================
42
43using namespace DISPLIB;
44using namespace FIFFLIB;
45
46//=============================================================================================================
47// DEFINE MEMBER METHODS
48//=============================================================================================================
49
50ArtifactSettingsView::ArtifactSettingsView(const QString& sSettingsPath,
51 const QList<FiffChInfo>& fiffChInfoList,
52 QWidget *parent)
53: AbstractView(parent)
54, m_fiffChInfoList(fiffChInfoList)
55{
56 m_sSettingsPath = sSettingsPath;
57 qRegisterMetaType<QMap<QString,double> >("QMap<QString,double>");
58
59 this->setWindowTitle("Artifact Rejection Settings");
60 this->setMinimumWidth(330);
61 this->setMaximumWidth(330);
62
64 redrawGUI();
65}
66
67//=============================================================================================================
68
74
75//=============================================================================================================
76
77void ArtifactSettingsView::setChInfo(const QList<FIFFLIB::FiffChInfo>& fiffChInfoList)
78{
79 m_fiffChInfoList = fiffChInfoList;
80
81 redrawGUI();
83}
84
85//=============================================================================================================
86
88{
89 return m_mapThresholds;
90}
91
92//=============================================================================================================
93
94void ArtifactSettingsView::setThresholdMap(const QMap<QString,double>& mapThresholds)
95{
96 m_mapThresholds = mapThresholds;
97
98 redrawGUI();
100}
101
102//=============================================================================================================
103
105{
107 return m_pArtifactRejectionCheckBox->isChecked();
108 }
109
110 return false;
111}
112
113//=============================================================================================================
114
116{
117 if(m_sSettingsPath.isEmpty()) {
118 return;
119 }
120
121 // Save Settings
122 QSettings settings("MNECPP");
123
124 settings.setValue(m_sSettingsPath + QString("/ArtifactSettingsView/doArtifactThresholdReduction"), m_bDoArtifactThresholdReduction);
125
126 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsFirst"));
127 QMap<QString, double>::const_iterator itrFirst = m_mapThresholdsFirst.constBegin();
128 while (itrFirst != m_mapThresholdsFirst.constEnd()) {
129 settings.setValue(itrFirst.key(), itrFirst.value());
130 ++itrFirst;
131 }
132 settings.endGroup();
133
134 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsSecond"));
135 QMap<QString, int>::const_iterator itrSecond = m_mapThresholdsSecond.constBegin();
136 while (itrSecond != m_mapThresholdsSecond.constEnd()) {
137 settings.setValue(itrSecond.key(), itrSecond.value());
138 ++itrSecond;
139 }
140 settings.endGroup();
141}
142
143//=============================================================================================================
144
146{
147 if(m_sSettingsPath.isEmpty()) {
148 return;
149 }
150
151 // Load Settings
152 QSettings settings("MNECPP");
153
154 m_bDoArtifactThresholdReduction = settings.value(m_sSettingsPath + QString("/ArtifactSettingsView/doArtifactThresholdReduction"), false).toBool();
155
157 m_mapThresholds["Active"] = 1.0;
158 } else {
159 m_mapThresholds["Active"] = 0.0;
160 }
161
162 m_mapThresholdsFirst["grad"] = 1.0;
163 m_mapThresholdsFirst["mag"] = 1.0;
164 m_mapThresholdsFirst["eeg"] = 1.0;
165 m_mapThresholdsFirst["ecg"] = 1.0;
166 m_mapThresholdsFirst["emg"] = 1.0;
167 m_mapThresholdsFirst["eog"] = 1.0;
168
169 m_mapThresholdsSecond["grad"] = -1;
170 m_mapThresholdsSecond["mag"] = -1;
171 m_mapThresholdsSecond["eeg"] = -1;
172 m_mapThresholdsSecond["ecg"] = -1;
173 m_mapThresholdsSecond["emg"] = -1;
174 m_mapThresholdsSecond["eog"] = -1;
175
176 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsFirst"));
177 QStringList keys = settings.childKeys();
178 foreach (QString key, keys) {
179 m_mapThresholdsFirst.insert(key, settings.value(key, 1.0).toDouble());
180 }
181 settings.endGroup();
182
183 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsSecond"));
184 keys = settings.childKeys();
185 foreach (QString key, keys) {
186 m_mapThresholdsSecond.insert(key, settings.value(key, -1).toInt());
187 }
188 settings.endGroup();
189}
190
191//=============================================================================================================
192
194{
195 switch(mode) {
197 break;
198 default: // default is research mode
199 break;
200 }
201}
202
203//=============================================================================================================
204
206{
207 switch(mode) {
209 break;
210 default: // default is realtime mode
211 break;
212 }
213}
214
215//=============================================================================================================
216
218{
219 if(QLayout* layout = this->layout()) {
220 delete layout;
221 }
222
223 QGridLayout* pGroupBoxArtifactRejection = new QGridLayout();
224 this->setLayout(pGroupBoxArtifactRejection);
225
226 //Artifact rejection
227 if(!m_fiffChInfoList.isEmpty()) {
228 QStringList channelTypes;
229 int kind, unit;
230
231 for(int i = 0; i < m_fiffChInfoList.size(); ++i) {
232 kind = m_fiffChInfoList.at(i).kind;
233 unit = m_fiffChInfoList.at(i).unit;
234
235 if(kind == FIFFV_MEG_CH && unit == FIFF_UNIT_T_M && !channelTypes.contains("grad")) {
236 channelTypes << "grad";
237 }
238 if(kind == FIFFV_MEG_CH && unit == FIFF_UNIT_T && !channelTypes.contains("mag")) {
239 channelTypes << "mag";
240 }
241 if(kind == FIFFV_EEG_CH && !channelTypes.contains("eeg", Qt::CaseInsensitive)) {
242 channelTypes << "eeg";
243 }
244 if(kind == FIFFV_EOG_CH && !channelTypes.contains("eog", Qt::CaseInsensitive)) {
245 channelTypes << "eog";
246 }
247 if(kind == FIFFV_EMG_CH && !channelTypes.contains("emg", Qt::CaseInsensitive)) {
248 channelTypes << "emg";
249 }
250 if(kind == FIFFV_ECG_CH && !channelTypes.contains("ecg", Qt::CaseInsensitive)) {
251 channelTypes << "ecg";
252 }
253 }
254
255 if(!channelTypes.isEmpty()) {
256 m_pArtifactRejectionCheckBox = new QCheckBox("Activate artifact rejection");
257 pGroupBoxArtifactRejection->addWidget(m_pArtifactRejectionCheckBox,0,0,1,2);
259 connect(m_pArtifactRejectionCheckBox.data(), &QCheckBox::clicked,
261
262 for(int i = 0; i < channelTypes.size(); ++i) {
263 QLabel* pLabel = new QLabel(channelTypes.at(i));
264 pGroupBoxArtifactRejection->addWidget(pLabel,i+1,0);
265
266 QDoubleSpinBox* pDoubleSpinBox = new QDoubleSpinBox();
267 pDoubleSpinBox->setPrefix("+/-");
268 pDoubleSpinBox->setMinimum(0.0);
269 pDoubleSpinBox->setMaximum(100000.0);
270 pDoubleSpinBox->setValue(m_mapThresholdsFirst[channelTypes.at(i)]);
271 pGroupBoxArtifactRejection->addWidget(pDoubleSpinBox,i+1,1);
272 connect(pDoubleSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
274 m_mapChThresholdsDoubleSpinBoxes[channelTypes.at(i)] = pDoubleSpinBox;
275
276 QSpinBox* pSpinBox = new QSpinBox();
277 pSpinBox->setPrefix("e");
278 pSpinBox->setMaximum(0);
279 pSpinBox->setMinimum(-10000);
280 pSpinBox->setValue(m_mapThresholdsSecond[channelTypes.at(i)]);
281 pGroupBoxArtifactRejection->addWidget(pSpinBox,i+1,2);
282 connect(pSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
284 m_mapChThresholdsSpinBoxes[channelTypes.at(i)] = pSpinBox;
285 }
286 }
287 }
288}
289
290//=============================================================================================================
291
293{
294 m_mapThresholds.clear();
295 m_mapThresholdsFirst.clear();
296 m_mapThresholdsSecond.clear();
297
299 if(m_pArtifactRejectionCheckBox->isChecked()) {
300 m_mapThresholds["Active"] = 1.0;
302 } else {
303 m_mapThresholds["Active"] = 0.0;
305 }
306 }
307
308 QMapIterator<QString, QDoubleSpinBox*> i(m_mapChThresholdsDoubleSpinBoxes);
309
310 while (i.hasNext()) {
311 i.next();
312 if(i.value()) {
313 m_mapThresholdsFirst[i.key()] = i.value()->value();
314 m_mapThresholdsSecond[i.key()] = m_mapChThresholdsSpinBoxes[i.key()]->value();
315
316 if(i.key().contains("grad", Qt::CaseInsensitive)) {
317 m_mapThresholds["grad"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
318 }
319 if(i.key().contains("mag", Qt::CaseInsensitive)) {
320 m_mapThresholds["mag"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
321 }
322 if(i.key().contains("eeg", Qt::CaseInsensitive)) {
323 m_mapThresholds["eeg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
324 }
325 if(i.key().contains("ecg", Qt::CaseInsensitive)) {
326 m_mapThresholds["ecg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
327 }
328 if(i.key().contains("eog", Qt::CaseInsensitive)) {
329 m_mapThresholds["eog"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
330 }
331 if(i.key().contains("emg", Qt::CaseInsensitive)) {
332 m_mapThresholds["emg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
333 }
334 }
335 }
336
338
339 saveSettings();
340}
341
342//=============================================================================================================
343
Per-modality artefact-rejection threshold panel (mag, grad, EEG, ECG, EOG).
#define FIFFV_EOG_CH
#define FIFFV_EEG_CH
#define FIFFV_MEG_CH
#define FIFF_UNIT_T
#define FIFFV_EMG_CH
#define FIFFV_ECG_CH
#define FIFF_UNIT_T_M
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.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
AbstractView(QWidget *parent=0, Qt::WindowFlags f=Qt::Widget)
QMap< QString, QDoubleSpinBox * > m_mapChThresholdsDoubleSpinBoxes
QList< FIFFLIB::FiffChInfo > m_fiffChInfoList
QMap< QString, double > getThresholdMap()
QMap< QString, double > m_mapThresholds
void changeArtifactThreshold(const QMap< QString, double > &mapThresholds)
QMap< QString, int > m_mapThresholdsSecond
QMap< QString, QSpinBox * > m_mapChThresholdsSpinBoxes
QMap< QString, double > m_mapThresholdsFirst
ArtifactSettingsView(const QString &sSettingsPath="", const QList< FIFFLIB::FiffChInfo > &fiffChInfoList=QList< FIFFLIB::FiffChInfo >(), QWidget *parent=nullptr)
void setThresholdMap(const QMap< QString, double > &mapThresholds)
void setChInfo(const QList< FIFFLIB::FiffChInfo > &fiffChInfoList)
void updateProcessingMode(ProcessingMode mode)
QPointer< QCheckBox > m_pArtifactRejectionCheckBox