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#include <memory>
36
37//=============================================================================================================
38// EIGEN INCLUDES
39//=============================================================================================================
40
41//=============================================================================================================
42// USED NAMESPACES
43//=============================================================================================================
44
45using namespace DISPLIB;
46using namespace FIFFLIB;
47
48//=============================================================================================================
49// DEFINE MEMBER METHODS
50//=============================================================================================================
51
52ArtifactSettingsView::ArtifactSettingsView(const QString& sSettingsPath,
53 const QList<FiffChInfo>& fiffChInfoList,
54 QWidget* parent)
55: AbstractView(parent)
56, m_fiffChInfoList(fiffChInfoList)
57{
58 m_sSettingsPath = sSettingsPath;
59 qRegisterMetaType<QMap<QString, double>>("QMap<QString,double>");
60
61 this->setWindowTitle("Artifact Rejection Settings");
62 this->setMinimumWidth(330);
63 this->setMaximumWidth(330);
64
66 redrawGUI();
67}
68
69//=============================================================================================================
70
75
76//=============================================================================================================
77
78void ArtifactSettingsView::setChInfo(const QList<FIFFLIB::FiffChInfo>& fiffChInfoList)
79{
80 m_fiffChInfoList = fiffChInfoList;
81
82 redrawGUI();
84}
85
86//=============================================================================================================
87
89{
90 return m_mapThresholds;
91}
92
93//=============================================================================================================
94
95void ArtifactSettingsView::setThresholdMap(const QMap<QString, double>& mapThresholds)
96{
97 m_mapThresholds = mapThresholds;
98
99 redrawGUI();
101}
102
103//=============================================================================================================
104
106{
108 return m_pArtifactRejectionCheckBox->isChecked();
109 }
110
111 return false;
112}
113
114//=============================================================================================================
115
117{
118 if (m_sSettingsPath.isEmpty()) {
119 return;
120 }
121
122 // Save Settings
123 QSettings settings("MNECPP");
124
125 settings.setValue(m_sSettingsPath + QString("/ArtifactSettingsView/doArtifactThresholdReduction"), m_bDoArtifactThresholdReduction);
126
127 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsFirst"));
128 QMap<QString, double>::const_iterator itrFirst = m_mapThresholdsFirst.constBegin();
129 while (itrFirst != m_mapThresholdsFirst.constEnd()) {
130 settings.setValue(itrFirst.key(), itrFirst.value());
131 ++itrFirst;
132 }
133 settings.endGroup();
134
135 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsSecond"));
136 QMap<QString, int>::const_iterator itrSecond = m_mapThresholdsSecond.constBegin();
137 while (itrSecond != m_mapThresholdsSecond.constEnd()) {
138 settings.setValue(itrSecond.key(), itrSecond.value());
139 ++itrSecond;
140 }
141 settings.endGroup();
142}
143
144//=============================================================================================================
145
147{
148 m_mapThresholdsFirst["grad"] = 1.0;
149 m_mapThresholdsFirst["mag"] = 1.0;
150 m_mapThresholdsFirst["eeg"] = 1.0;
151 m_mapThresholdsFirst["ecg"] = 1.0;
152 m_mapThresholdsFirst["emg"] = 1.0;
153 m_mapThresholdsFirst["eog"] = 1.0;
154
155 m_mapThresholdsSecond["grad"] = -1;
156 m_mapThresholdsSecond["mag"] = -1;
157 m_mapThresholdsSecond["eeg"] = -1;
158 m_mapThresholdsSecond["ecg"] = -1;
159 m_mapThresholdsSecond["emg"] = -1;
160 m_mapThresholdsSecond["eog"] = -1;
161
162 if (m_sSettingsPath.isEmpty()) {
163 m_mapThresholds["Active"] = m_bDoArtifactThresholdReduction ? 1.0 : 0.0;
164 return;
165 }
166
167 // Load Settings
168 QSettings settings("MNECPP");
169
170 m_bDoArtifactThresholdReduction = settings.value(m_sSettingsPath + QString("/ArtifactSettingsView/doArtifactThresholdReduction"), false).toBool();
171 m_mapThresholds["Active"] = m_bDoArtifactThresholdReduction ? 1.0 : 0.0;
172
173 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsFirst"));
174 QStringList keys = settings.childKeys();
175 foreach (QString key, keys) {
176 m_mapThresholdsFirst.insert(key, settings.value(key, 1.0).toDouble());
177 }
178 settings.endGroup();
179
180 settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsSecond"));
181 keys = settings.childKeys();
182 foreach (QString key, keys) {
183 m_mapThresholdsSecond.insert(key, settings.value(key, -1).toInt());
184 }
185 settings.endGroup();
186}
187
188//=============================================================================================================
189
191{
192 switch (mode) {
194 break;
195 default: // default is research mode
196 break;
197 }
198}
199
200//=============================================================================================================
201
203{
204 switch (mode) {
206 break;
207 default: // default is realtime mode
208 break;
209 }
210}
211
212//=============================================================================================================
213
215{
216 if (QLayout* layout = this->layout()) {
217 // Deleting a layout leaves its widgets on the view
218 while (std::unique_ptr<QLayoutItem> pItem{layout->takeAt(0)}) {
219 std::unique_ptr<QWidget> pWidget{pItem->widget()};
220 }
221 delete layout;
222 }
225
226 QGridLayout* pGroupBoxArtifactRejection = new QGridLayout();
227 this->setLayout(pGroupBoxArtifactRejection);
228
229 //Artifact rejection
230 if (!m_fiffChInfoList.isEmpty()) {
231 QStringList channelTypes;
232 int kind, unit;
233
234 for (int i = 0; i < m_fiffChInfoList.size(); ++i) {
235 kind = m_fiffChInfoList.at(i).kind;
236 unit = m_fiffChInfoList.at(i).unit;
237
238 if (kind == FIFFV_MEG_CH && unit == FIFF_UNIT_T_M && !channelTypes.contains("grad")) {
239 channelTypes << "grad";
240 }
241 if (kind == FIFFV_MEG_CH && unit == FIFF_UNIT_T && !channelTypes.contains("mag")) {
242 channelTypes << "mag";
243 }
244 if (kind == FIFFV_EEG_CH && !channelTypes.contains("eeg", Qt::CaseInsensitive)) {
245 channelTypes << "eeg";
246 }
247 if (kind == FIFFV_EOG_CH && !channelTypes.contains("eog", Qt::CaseInsensitive)) {
248 channelTypes << "eog";
249 }
250 if (kind == FIFFV_EMG_CH && !channelTypes.contains("emg", Qt::CaseInsensitive)) {
251 channelTypes << "emg";
252 }
253 if (kind == FIFFV_ECG_CH && !channelTypes.contains("ecg", Qt::CaseInsensitive)) {
254 channelTypes << "ecg";
255 }
256 }
257
258 if (!channelTypes.isEmpty()) {
259 m_pArtifactRejectionCheckBox = new QCheckBox("Activate artifact rejection");
260 pGroupBoxArtifactRejection->addWidget(m_pArtifactRejectionCheckBox, 0, 0, 1, 2);
262 connect(m_pArtifactRejectionCheckBox.data(), &QCheckBox::clicked,
264
265 for (int i = 0; i < channelTypes.size(); ++i) {
266 QLabel* pLabel = new QLabel(channelTypes.at(i));
267 pGroupBoxArtifactRejection->addWidget(pLabel, i + 1, 0);
268
269 QDoubleSpinBox* pDoubleSpinBox = new QDoubleSpinBox();
270 pDoubleSpinBox->setPrefix("+/-");
271 pDoubleSpinBox->setMinimum(0.0);
272 pDoubleSpinBox->setMaximum(100000.0);
273 pDoubleSpinBox->setValue(m_mapThresholdsFirst[channelTypes.at(i)]);
274 pGroupBoxArtifactRejection->addWidget(pDoubleSpinBox, i + 1, 1);
275 connect(pDoubleSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
277 m_mapChThresholdsDoubleSpinBoxes[channelTypes.at(i)] = pDoubleSpinBox;
278
279 QSpinBox* pSpinBox = new QSpinBox();
280 pSpinBox->setPrefix("e");
281 pSpinBox->setMaximum(0);
282 pSpinBox->setMinimum(-10000);
283 pSpinBox->setValue(m_mapThresholdsSecond[channelTypes.at(i)]);
284 pGroupBoxArtifactRejection->addWidget(pSpinBox, i + 1, 2);
285 connect(pSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
287 m_mapChThresholdsSpinBoxes[channelTypes.at(i)] = pSpinBox;
288 }
289 }
290 }
291}
292
293//=============================================================================================================
294
296{
297 m_mapThresholds.clear();
298 m_mapThresholdsFirst.clear();
299 m_mapThresholdsSecond.clear();
300
302 if (m_pArtifactRejectionCheckBox->isChecked()) {
303 m_mapThresholds["Active"] = 1.0;
305 } else {
306 m_mapThresholds["Active"] = 0.0;
308 }
309 }
310
311 QMapIterator<QString, QDoubleSpinBox*> i(m_mapChThresholdsDoubleSpinBoxes);
312
313 while (i.hasNext()) {
314 i.next();
315 if (i.value()) {
316 m_mapThresholdsFirst[i.key()] = i.value()->value();
317 m_mapThresholdsSecond[i.key()] = m_mapChThresholdsSpinBoxes[i.key()]->value();
318
319 if (i.key().contains("grad", Qt::CaseInsensitive)) {
320 m_mapThresholds["grad"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
321 }
322 if (i.key().contains("mag", Qt::CaseInsensitive)) {
323 m_mapThresholds["mag"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
324 }
325 if (i.key().contains("eeg", Qt::CaseInsensitive)) {
326 m_mapThresholds["eeg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
327 }
328 if (i.key().contains("ecg", Qt::CaseInsensitive)) {
329 m_mapThresholds["ecg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
330 }
331 if (i.key().contains("eog", Qt::CaseInsensitive)) {
332 m_mapThresholds["eog"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
333 }
334 if (i.key().contains("emg", Qt::CaseInsensitive)) {
335 m_mapThresholds["emg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
336 }
337 }
338 }
339
341
342 saveSettings();
343}
344
345//=============================================================================================================
346
FIFF channel descriptor record (FIFF_CH_INFO): per-channel logical/scanner numbers,...
#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
Per-modality artefact-rejection threshold panel (mag, grad, EEG, ECG, EOG).
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, int > m_mapThresholdsSecond
QList< FIFFLIB::FiffChInfo > m_fiffChInfoList
QMap< QString, double > m_mapThresholdsFirst
QMap< QString, double > getThresholdMap()
void changeArtifactThreshold(const QMap< QString, double > &mapThresholds)
ArtifactSettingsView(const QString &sSettingsPath="", const QList< FIFFLIB::FiffChInfo > &fiffChInfoList=QList< FIFFLIB::FiffChInfo >(), QWidget *parent=nullptr)
QMap< QString, double > m_mapThresholds
void setThresholdMap(const QMap< QString, double > &mapThresholds)
void setChInfo(const QList< FIFFLIB::FiffChInfo > &fiffChInfoList)
QMap< QString, QSpinBox * > m_mapChThresholdsSpinBoxes
void updateProcessingMode(ProcessingMode mode)
QPointer< QCheckBox > m_pArtifactRejectionCheckBox
QMap< QString, QDoubleSpinBox * > m_mapChThresholdsDoubleSpinBoxes