MNE-CPP  beta 1.0
realtimeevokedwidget.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //ToDo Paint to render area
37 
38 //*************************************************************************************************************
39 //=============================================================================================================
40 // INCLUDES
41 //=============================================================================================================
42 
43 #include "realtimeevokedwidget.h"
44 //#include "annotationwindow.h"
45 
46 #include <xMeas/realtimeevoked.h>
47 
48 
49 //*************************************************************************************************************
50 //=============================================================================================================
51 // Eigen INCLUDES
52 //=============================================================================================================
53 
54 #include <Eigen/Core>
55 
56 
57 //*************************************************************************************************************
58 //=============================================================================================================
59 // STL INCLUDES
60 //=============================================================================================================
61 
62 #include <math.h>
63 
64 
65 //*************************************************************************************************************
66 //=============================================================================================================
67 // QT INCLUDES
68 //=============================================================================================================
69 
70 #include <QPaintEvent>
71 #include <QPainter>
72 #include <QHeaderView>
73 #include <QMenu>
74 #include <QMessageBox>
75 #include <QScroller>
76 #include <QSettings>
77 
78 #include <QDebug>
79 
80 
81 //*************************************************************************************************************
82 //=============================================================================================================
83 // USED NAMESPACES
84 //=============================================================================================================
85 
86 using namespace XDISPLIB;
87 using namespace XMEASLIB;
88 
89 
90 //=============================================================================================================
94 enum Tool
95 {
96  Freeze = 0,
98 };
99 
100 
101 //*************************************************************************************************************
102 //=============================================================================================================
103 // DEFINE MEMBER METHODS
104 //=============================================================================================================
105 
106 RealTimeEvokedWidget::RealTimeEvokedWidget(QSharedPointer<RealTimeEvoked> pRTE, QSharedPointer<QTime> &pTime, QWidget* parent)
107 : NewMeasurementWidget(parent)
108 , m_pRTEModel(Q_NULLPTR)
109 , m_pButterflyPlot(Q_NULLPTR)
110 , m_pRTE(pRTE)
111 , m_bInitialized(false)
112 {
113  Q_UNUSED(pTime)
114 
115  m_pActionSelectModality = new QAction(QIcon(":/images/evokedSettings.png"), tr("Shows the covariance modality selection widget (F12)"),this);
116  m_pActionSelectModality->setShortcut(tr("F12"));
117  m_pActionSelectModality->setStatusTip(tr("Shows the covariance modality selection widget (F12)"));
118  connect(m_pActionSelectModality, &QAction::triggered, this, &RealTimeEvokedWidget::showModalitySelectionWidget);
119  addDisplayAction(m_pActionSelectModality);
120 
121  m_pActionSelectModality->setVisible(false);
122 
123  m_pActionSelectSensors = new QAction(QIcon(":/images/selectSensors.png"), tr("Shows the region selection widget (F12)"),this);
124  m_pActionSelectSensors->setShortcut(tr("F12"));
125  m_pActionSelectSensors->setStatusTip(tr("Shows the region selection widget (F12)"));
126  m_pActionSelectSensors->setVisible(false);
127  connect(m_pActionSelectSensors, &QAction::triggered, this, &RealTimeEvokedWidget::showSensorSelectionWidget);
128  addDisplayAction(m_pActionSelectSensors);
129 
130  //set vertical layout
131  m_pRteLayout = new QVBoxLayout(this);
132 
133  m_pLabelInit= new QLabel;
134  m_pLabelInit->setText("Acquiring Data");
135  m_pLabelInit->setAlignment(Qt::AlignCenter);
136  QFont font;font.setBold(true);font.setPointSize(20);
137  m_pLabelInit->setFont(font);
138  m_pRteLayout->addWidget(m_pLabelInit);
139 
140  if(m_pButterflyPlot)
141  delete m_pButterflyPlot;
142  m_pButterflyPlot = new RealTimeButterflyPlot;
143  m_pButterflyPlot->hide();
144 
145  m_pRteLayout->addWidget(m_pButterflyPlot);
146 
147  //set layouts
148  this->setLayout(m_pRteLayout);
149 
150  //Create pointers for selection manager
151  m_pChInfoModel = QSharedPointer<ChInfoModel>(new ChInfoModel(this));
152  m_pSelectionManagerWindow = QSharedPointer<SelectionManagerWindow>(new SelectionManagerWindow(this, m_pChInfoModel.data()));
153 
154  getData();
155 }
156 
157 
158 //*************************************************************************************************************
159 
161 {
162  //
163  // Store Settings
164  //
165  if(!m_pRTE->getName().isEmpty())
166  {
167  QString t_sRTEWName = m_pRTE->getName();
168 
169  QSettings settings;
170 
171  for(qint32 i = 0; i < m_qListModalities.size(); ++i)
172  {
173  settings.setValue(QString("RTEW/%1/%2/active").arg(t_sRTEWName).arg(m_qListModalities[i].m_sName), m_qListModalities[i].m_bActive);
174  settings.setValue(QString("RTEW/%1/%2/norm").arg(t_sRTEWName).arg(m_qListModalities[i].m_sName), m_qListModalities[i].m_fNorm);
175  }
176  }
177 }
178 
179 
180 //*************************************************************************************************************
181 
183 {
184  m_pButterflyPlot->setSettings(m_qListModalities);
185 
186 }
187 
188 
189 //*************************************************************************************************************
190 
192 {
193  getData();
194 }
195 
196 
197 //*************************************************************************************************************
198 
200 {
201  if(!m_bInitialized)
202  {
203  if(m_pRTE->isInitialized())
204  {
205 // QFile file(m_pRTE->getXMLLayoutFile());
206 // if (!file.open(QFile::ReadOnly | QFile::Text))
207 // {
208 // qDebug() << QString("Cannot read file %1:\n%2.").arg(m_pRTE->getXMLLayoutFile()).arg(file.errorString());
209 // m_pSensorModel = new SensorModel(this);
210 // m_pSensorModel->mapChannelInfo(m_qListChInfo);
211 // }
212 // else
213 // {
214 // m_pSensorModel = new SensorModel(&file, this);
215 // m_pSensorModel->mapChannelInfo(m_qListChInfo);
216 // m_pActionSelectSensors->setVisible(true);
217 // }
218 
219  m_qListChInfo = m_pRTE->chInfo();
220  m_fiffInfo = m_pRTE->info();
221 
222  init();
223 
224  m_pRTEModel->updateData();
225  }
226  }
227  else
228  m_pRTEModel->updateData();
229 }
230 
231 
232 //*************************************************************************************************************
233 
235 {
236  if(m_pRTE->isInitialized())
237  {
238  QString t_sRTEWName = m_pRTE->getName();
239  m_pRteLayout->removeWidget(m_pLabelInit);
240  m_pLabelInit->hide();
241 
242  m_pButterflyPlot->show();
243 
244  if(m_pRTEModel)
245  delete m_pRTEModel;
246  m_pRTEModel = new RealTimeEvokedModel(this);
247 
248  m_pRTEModel->setRTE(m_pRTE);
249 
250  m_pButterflyPlot->setModel(m_pRTEModel);
251 
252  m_qListModalities.clear();
253  bool hasMag = false;
254  bool hasGrad = false;
255  bool hasEEG = false;
256  bool hasEOG = false;
257  bool hasMISC = false;
258  for(qint32 i = 0; i < m_pRTE->info().nchan; ++i)
259  {
260  if(m_pRTE->info().chs[i].kind == FIFFV_MEG_CH)
261  {
262  if(!hasMag && m_pRTE->info().chs[i].unit == FIFF_UNIT_T)
263  hasMag = true;
264  else if(!hasGrad && m_pRTE->info().chs[i].unit == FIFF_UNIT_T_M)
265  hasGrad = true;
266  }
267  else if(!hasEEG && m_pRTE->info().chs[i].kind == FIFFV_EEG_CH)
268  hasEEG = true;
269  else if(!hasEOG && m_pRTE->info().chs[i].kind == FIFFV_EOG_CH)
270  hasEOG = true;
271  else if(!hasMISC && m_pRTE->info().chs[i].kind == FIFFV_MISC_CH)
272  hasMISC = true;
273  }
274  QSettings settings;
275  bool sel = false;
276  float val = 1e-11f;
277  if(hasMag)
278  {
279  sel = settings.value(QString("RTEW/%1/MAG/active").arg(t_sRTEWName), true).toBool();
280  val = settings.value(QString("RTEW/%1/MAG/norm").arg(t_sRTEWName), 1e-11f).toFloat();
281  m_qListModalities.append(Modality("MAG",sel,val));
282  }
283  if(hasGrad)
284  {
285  sel = settings.value(QString("RTEW/%1/GRAD/active").arg(t_sRTEWName), true).toBool();
286  val = settings.value(QString("RTEW/%1/GRAD/norm").arg(t_sRTEWName), 1e-10f).toFloat();
287  m_qListModalities.append(Modality("GRAD",sel,val));
288  }
289  if(hasEEG)
290  {
291  sel = settings.value(QString("RTEW/%1/EEG/active").arg(t_sRTEWName), true).toBool();
292  val = settings.value(QString("RTEW/%1/EEG/norm").arg(t_sRTEWName), 1e-4f).toFloat();
293  m_qListModalities.append(Modality("EEG",sel,val));
294  }
295  if(hasEOG)
296  {
297  sel = settings.value(QString("RTEW/%1/EOG/active").arg(t_sRTEWName), true).toBool();
298  val = settings.value(QString("RTEW/%1/EOG/norm").arg(t_sRTEWName), 1e-3f).toFloat();
299  m_qListModalities.append(Modality("EOG",sel,val));
300  }
301  if(hasMISC)
302  {
303  sel = settings.value(QString("RTEW/%1/MISC/active").arg(t_sRTEWName), true).toBool();
304  val = settings.value(QString("RTEW/%1/MISC/norm").arg(t_sRTEWName), 1e-3f).toFloat();
305  m_qListModalities.append(Modality("MISC",sel,val));
306  }
307 
308  m_pButterflyPlot->setSettings(m_qListModalities);
309 
310  m_pActionSelectModality->setVisible(true);
311  m_pActionSelectSensors->setVisible(true);
312 
313  //Set up selection manager
314  connect(m_pSelectionManagerWindow.data(), &SelectionManagerWindow::showSelectedChannelsOnly,
315  this, &RealTimeEvokedWidget::showSelectedChannelsOnly);
316 
317  //Connect channel info model
318  connect(m_pSelectionManagerWindow.data(), &SelectionManagerWindow::loadedLayoutMap,
319  m_pChInfoModel.data(), &ChInfoModel::layoutChanged);
320 
321  connect(m_pChInfoModel.data(), &ChInfoModel::channelsMappedToLayout,
322  m_pSelectionManagerWindow.data(), &SelectionManagerWindow::setCurrentlyMappedFiffChannels);
323 
324  m_pChInfoModel->fiffInfoChanged(m_fiffInfo);
325 
326  // Initialized
327  m_bInitialized = true;
328  }
329 }
330 
331 
332 //*************************************************************************************************************
333 
334 void RealTimeEvokedWidget::showModalitySelectionWidget()
335 {
336  if(!m_pEvokedModalityWidget)
337  {
338  m_pEvokedModalityWidget = QSharedPointer<EvokedModalityWidget>(new EvokedModalityWidget(this, this));
339 
340  m_pEvokedModalityWidget->setWindowTitle("Modality Selection");
341 
342  connect(m_pEvokedModalityWidget.data(), &EvokedModalityWidget::settingsChanged, this, &RealTimeEvokedWidget::broadcastSettings);
343  }
344  m_pEvokedModalityWidget->show();
345 }
346 
347 
348 //*************************************************************************************************************
349 
350 void RealTimeEvokedWidget::showSensorSelectionWidget()
351 {
352  if(!m_pSelectionManagerWindow) {
353  m_pSelectionManagerWindow = QSharedPointer<SelectionManagerWindow>(new SelectionManagerWindow);
354  }
355 
356  m_pSelectionManagerWindow->show();
357 }
358 
359 
360 //*************************************************************************************************************
361 
362 void RealTimeEvokedWidget::applySelection()
363 {
364 // m_pRTMSAModel->selectRows(m_qListCurrentSelection);
365 
366 // m_pSensorModel->silentUpdateSelection(m_qListCurrentSelection);
367 }
368 
369 
370 //*************************************************************************************************************
371 
372 void RealTimeEvokedWidget::resetSelection()
373 {
374 // // non C++11 alternative
375 // m_qListCurrentSelection.clear();
376 // for(qint32 i = 0; i < m_qListChInfo.size(); ++i)
377 // m_qListCurrentSelection.append(i);
378 
379 // applySelection();
380 }
381 
382 
383 //*************************************************************************************************************
384 
385 void RealTimeEvokedWidget::showSelectedChannelsOnly(QStringList selectedChannels)
386 {
387  QList<int> selectedChannelsIndexes;
388 
389  for(int i = 0; i<selectedChannels.size(); i++)
390  selectedChannelsIndexes<<m_pChInfoModel->getIndexFromOrigChName(selectedChannels.at(i));
391 
392  m_pButterflyPlot->setSelectedChannels(selectedChannelsIndexes);
393 }
Free surfer annotation.
Definition: annotation.h:97
void setCurrentlyMappedFiffChannels(const QStringList &mappedLayoutChNames)
void showSelectedChannelsOnly(QStringList selectedChannels)
The SelectionManagerWindow class provides a channel selection window.
RealTimeEvokedWidget(QSharedPointer< RealTimeEvoked > pRTE, QSharedPointer< QTime > &pTime, QWidget *parent=0)
void loadedLayoutMap(const QMap< QString, QPointF > &layoutMap)
Contains the declaration of the RealTimeEvoked class.
#define FIFF_UNIT_T_M
void layoutChanged(const QMap< QString, QPointF > &layoutMap)
QSharedPointer< NewMeasurement > SPtr
The EvokedModalityWidget class provides the sensor selection widget.
Declaration of the RealTimeEvokedWidget Class.
The MeasurementWidget class is the base class of all measurement widgets.
The RealTimeEvokedModel class implements the data access model for a real-time multi sample array dat...
void addDisplayAction(QAction *pAction)
void setRTE(QSharedPointer< RealTimeEvoked > &pRTE)
virtual void update(XMEASLIB::NewMeasurement::SPtr pMeasurement)
void channelsMappedToLayout(const QStringList &mappedLayoutChNames)