MNE-CPP  0.1.9
A Framework for Electrophysiology
artifactsettingsview.cpp
Go to the documentation of this file.
1 //=============================================================================================================
35 //=============================================================================================================
36 // INCLUDES
37 //=============================================================================================================
38 
39 #include "artifactsettingsview.h"
40 
41 #include <fiff/fiff_ch_info.h>
42 
43 //=============================================================================================================
44 // QT INCLUDES
45 //=============================================================================================================
46 
47 #include <QSettings>
48 #include <QLabel>
49 #include <QGridLayout>
50 #include <QCheckBox>
51 #include <QDoubleSpinBox>
52 #include <QSpinBox>
53 #include <QDebug>
54 
55 //=============================================================================================================
56 // EIGEN INCLUDES
57 //=============================================================================================================
58 
59 //=============================================================================================================
60 // USED NAMESPACES
61 //=============================================================================================================
62 
63 using namespace DISPLIB;
64 using namespace FIFFLIB;
65 
66 //=============================================================================================================
67 // DEFINE MEMBER METHODS
68 //=============================================================================================================
69 
70 ArtifactSettingsView::ArtifactSettingsView(const QString& sSettingsPath,
71  const QList<FiffChInfo>& fiffChInfoList,
72  QWidget *parent)
73 : AbstractView(parent)
74 , m_fiffChInfoList(fiffChInfoList)
75 {
76  m_sSettingsPath = sSettingsPath;
77  qRegisterMetaType<QMap<QString,double> >("QMap<QString,double>");
78 
79  this->setWindowTitle("Artifact Rejection Settings");
80  this->setMinimumWidth(330);
81  this->setMaximumWidth(330);
82 
83  loadSettings();
84  redrawGUI();
85 }
86 
87 //=============================================================================================================
88 
90 {
91 
92  saveSettings();
93 }
94 
95 //=============================================================================================================
96 
97 void ArtifactSettingsView::setChInfo(const QList<FIFFLIB::FiffChInfo>& fiffChInfoList)
98 {
99  m_fiffChInfoList = fiffChInfoList;
100 
101  redrawGUI();
102  onChangeArtifactThreshold();
103 }
104 
105 //=============================================================================================================
106 
107 QMap<QString,double> ArtifactSettingsView::getThresholdMap()
108 {
109  return m_mapThresholds;
110 }
111 
112 //=============================================================================================================
113 
114 void ArtifactSettingsView::setThresholdMap(const QMap<QString,double>& mapThresholds)
115 {
116  m_mapThresholds = mapThresholds;
117 
118  redrawGUI();
119  onChangeArtifactThreshold();
120 }
121 
122 //=============================================================================================================
123 
124 bool ArtifactSettingsView::getDoArtifactThresholdRejection()
125 {
126  if (m_pArtifactRejectionCheckBox) {
127  return m_pArtifactRejectionCheckBox->isChecked();
128  }
129 
130  return false;
131 }
132 
133 //=============================================================================================================
134 
136 {
137  if(m_sSettingsPath.isEmpty()) {
138  return;
139  }
140 
141  // Save Settings
142  QSettings settings("MNECPP");
143 
144  settings.setValue(m_sSettingsPath + QString("/ArtifactSettingsView/doArtifactThresholdReduction"), m_bDoArtifactThresholdReduction);
145 
146  settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsFirst"));
147  QMap<QString, double>::const_iterator itrFirst = m_mapThresholdsFirst.constBegin();
148  while (itrFirst != m_mapThresholdsFirst.constEnd()) {
149  settings.setValue(itrFirst.key(), itrFirst.value());
150  ++itrFirst;
151  }
152  settings.endGroup();
153 
154  settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsSecond"));
155  QMap<QString, int>::const_iterator itrSecond = m_mapThresholdsSecond.constBegin();
156  while (itrSecond != m_mapThresholdsSecond.constEnd()) {
157  settings.setValue(itrSecond.key(), itrSecond.value());
158  ++itrSecond;
159  }
160  settings.endGroup();
161 }
162 
163 //=============================================================================================================
164 
166 {
167  if(m_sSettingsPath.isEmpty()) {
168  return;
169  }
170 
171  // Load Settings
172  QSettings settings("MNECPP");
173 
174  m_bDoArtifactThresholdReduction = settings.value(m_sSettingsPath + QString("/ArtifactSettingsView/doArtifactThresholdReduction"), false).toBool();
175 
176  if(m_bDoArtifactThresholdReduction) {
177  m_mapThresholds["Active"] = 1.0;
178  } else {
179  m_mapThresholds["Active"] = 0.0;
180  }
181 
182  m_mapThresholdsFirst["grad"] = 1.0;
183  m_mapThresholdsFirst["mag"] = 1.0;
184  m_mapThresholdsFirst["eeg"] = 1.0;
185  m_mapThresholdsFirst["ecg"] = 1.0;
186  m_mapThresholdsFirst["emg"] = 1.0;
187  m_mapThresholdsFirst["eog"] = 1.0;
188 
189  m_mapThresholdsSecond["grad"] = -1;
190  m_mapThresholdsSecond["mag"] = -1;
191  m_mapThresholdsSecond["eeg"] = -1;
192  m_mapThresholdsSecond["ecg"] = -1;
193  m_mapThresholdsSecond["emg"] = -1;
194  m_mapThresholdsSecond["eog"] = -1;
195 
196  settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsFirst"));
197  QStringList keys = settings.childKeys();
198  foreach (QString key, keys) {
199  m_mapThresholdsFirst.insert(key, settings.value(key, 1.0).toDouble());
200  }
201  settings.endGroup();
202 
203  settings.beginGroup(m_sSettingsPath + QString("/ArtifactSettingsView/artifactThresholdsSecond"));
204  keys = settings.childKeys();
205  foreach (QString key, keys) {
206  m_mapThresholdsSecond.insert(key, settings.value(key, -1).toInt());
207  }
208  settings.endGroup();
209 }
210 
211 //=============================================================================================================
212 
214 {
215  switch(mode) {
216  case GuiMode::Clinical:
217  break;
218  default: // default is research mode
219  break;
220  }
221 }
222 
223 //=============================================================================================================
224 
226 {
227  switch(mode) {
228  case ProcessingMode::Offline:
229  break;
230  default: // default is realtime mode
231  break;
232  }
233 }
234 
235 //=============================================================================================================
236 
238 {
239  if(QLayout* layout = this->layout()) {
240  delete layout;
241  }
242 
243  QGridLayout* pGroupBoxArtifactRejection = new QGridLayout();
244  this->setLayout(pGroupBoxArtifactRejection);
245 
246  //Artifact rejection
247  if(!m_fiffChInfoList.isEmpty()) {
248  QStringList channelTypes;
249  int kind, unit;
250 
251  for(int i = 0; i < m_fiffChInfoList.size(); ++i) {
252  kind = m_fiffChInfoList.at(i).kind;
253  unit = m_fiffChInfoList.at(i).unit;
254 
255  if(kind == FIFFV_MEG_CH && unit == FIFF_UNIT_T_M && !channelTypes.contains("grad")) {
256  channelTypes << "grad";
257  }
258  if(kind == FIFFV_MEG_CH && unit == FIFF_UNIT_T && !channelTypes.contains("mag")) {
259  channelTypes << "mag";
260  }
261  if(kind == FIFFV_EEG_CH && !channelTypes.contains("eeg", Qt::CaseInsensitive)) {
262  channelTypes << "eeg";
263  }
264  if(kind == FIFFV_EOG_CH && !channelTypes.contains("eog", Qt::CaseInsensitive)) {
265  channelTypes << "eog";
266  }
267  if(kind == FIFFV_EMG_CH && !channelTypes.contains("emg", Qt::CaseInsensitive)) {
268  channelTypes << "emg";
269  }
270  if(kind == FIFFV_ECG_CH && !channelTypes.contains("ecg", Qt::CaseInsensitive)) {
271  channelTypes << "ecg";
272  }
273  }
274 
275  if(!channelTypes.isEmpty()) {
276  m_pArtifactRejectionCheckBox = new QCheckBox("Activate artifact rejection");
277  pGroupBoxArtifactRejection->addWidget(m_pArtifactRejectionCheckBox,0,0,1,2);
278  m_pArtifactRejectionCheckBox->setChecked(m_bDoArtifactThresholdReduction);
279  connect(m_pArtifactRejectionCheckBox.data(), &QCheckBox::clicked,
280  this, &ArtifactSettingsView::onChangeArtifactThreshold);
281 
282  for(int i = 0; i < channelTypes.size(); ++i) {
283  QLabel* pLabel = new QLabel(channelTypes.at(i));
284  pGroupBoxArtifactRejection->addWidget(pLabel,i+1,0);
285 
286  QDoubleSpinBox* pDoubleSpinBox = new QDoubleSpinBox();
287  pDoubleSpinBox->setPrefix("+/-");
288  pDoubleSpinBox->setMinimum(0.0);
289  pDoubleSpinBox->setMaximum(100000.0);
290  pDoubleSpinBox->setValue(m_mapThresholdsFirst[channelTypes.at(i)]);
291  pGroupBoxArtifactRejection->addWidget(pDoubleSpinBox,i+1,1);
292  connect(pDoubleSpinBox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
293  this, &ArtifactSettingsView::onChangeArtifactThreshold);
294  m_mapChThresholdsDoubleSpinBoxes[channelTypes.at(i)] = pDoubleSpinBox;
295 
296  QSpinBox* pSpinBox = new QSpinBox();
297  pSpinBox->setPrefix("e");
298  pSpinBox->setMaximum(0);
299  pSpinBox->setMinimum(-10000);
300  pSpinBox->setValue(m_mapThresholdsSecond[channelTypes.at(i)]);
301  pGroupBoxArtifactRejection->addWidget(pSpinBox,i+1,2);
302  connect(pSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
303  this, &ArtifactSettingsView::onChangeArtifactThreshold);
304  m_mapChThresholdsSpinBoxes[channelTypes.at(i)] = pSpinBox;
305  }
306  }
307  }
308 }
309 
310 //=============================================================================================================
311 
312 void ArtifactSettingsView::onChangeArtifactThreshold()
313 {
314  m_mapThresholds.clear();
315  m_mapThresholdsFirst.clear();
316  m_mapThresholdsSecond.clear();
317 
318  if(m_pArtifactRejectionCheckBox) {
319  if(m_pArtifactRejectionCheckBox->isChecked()) {
320  m_mapThresholds["Active"] = 1.0;
321  m_bDoArtifactThresholdReduction = true;
322  } else {
323  m_mapThresholds["Active"] = 0.0;
324  m_bDoArtifactThresholdReduction = false;
325  }
326  }
327 
328  QMapIterator<QString, QDoubleSpinBox*> i(m_mapChThresholdsDoubleSpinBoxes);
329 
330  while (i.hasNext()) {
331  i.next();
332  if(i.value()) {
333  m_mapThresholdsFirst[i.key()] = i.value()->value();
334  m_mapThresholdsSecond[i.key()] = m_mapChThresholdsSpinBoxes[i.key()]->value();
335 
336  if(i.key().contains("grad", Qt::CaseInsensitive)) {
337  m_mapThresholds["grad"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
338  }
339  if(i.key().contains("mag", Qt::CaseInsensitive)) {
340  m_mapThresholds["mag"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
341  }
342  if(i.key().contains("eeg", Qt::CaseInsensitive)) {
343  m_mapThresholds["eeg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
344  }
345  if(i.key().contains("ecg", Qt::CaseInsensitive)) {
346  m_mapThresholds["ecg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
347  }
348  if(i.key().contains("eog", Qt::CaseInsensitive)) {
349  m_mapThresholds["eog"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
350  }
351  if(i.key().contains("emg", Qt::CaseInsensitive)) {
352  m_mapThresholds["emg"] = i.value()->value() * pow(10, m_mapChThresholdsSpinBoxes[i.key()]->value());
353  }
354  }
355  }
356 
357  emit changeArtifactThreshold(m_mapThresholds);
358 
359  saveSettings();
360 }
361 
362 //=============================================================================================================
363 
365 {
366 
367 }
DISPLIB::ArtifactSettingsView::clearView
void clearView()
Definition: artifactsettingsview.cpp:364
DISPLIB::AbstractView
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
DISPLIB::ArtifactSettingsView::~ArtifactSettingsView
~ArtifactSettingsView()
Definition: artifactsettingsview.cpp:89
DISPLIB::ArtifactSettingsView::updateProcessingMode
void updateProcessingMode(ProcessingMode mode)
Definition: artifactsettingsview.cpp:225
DISPLIB::ArtifactSettingsView::redrawGUI
void redrawGUI()
Definition: artifactsettingsview.cpp:237
DISPLIB::ArtifactSettingsView::saveSettings
void saveSettings()
Definition: artifactsettingsview.cpp:135
fiff_ch_info.h
FiffChInfo class declaration.
DISPLIB::ApplyToView::loadSettings
void loadSettings()
Definition: applytoview.cpp:86
DISPLIB::ArtifactSettingsView::updateGuiMode
void updateGuiMode(GuiMode mode)
Definition: artifactsettingsview.cpp:213
DISPLIB::AbstractView::m_sSettingsPath
QString m_sSettingsPath
Definition: abstractview.h:169
artifactsettingsview.h
Declaration of the ArtifactSettingsView class.
DISPLIB::ArtifactSettingsView::loadSettings
void loadSettings()
Definition: artifactsettingsview.cpp:165