MNE-CPP  beta 1.0
rawmodel.h
Go to the documentation of this file.
1 //=============================================================================================================
65 #ifndef RAWMODEL_H
66 #define RAWMODEL_H
67 
68 
69 //*************************************************************************************************************
70 //=============================================================================================================
71 // INCLUDES
72 //=============================================================================================================
73 
74 #include "../Utils/types.h"
75 #include "../Utils/filteroperator.h"
76 #include "../Utils/rawsettings.h"
77 #include "../Utils/datapackage.h"
78 
79 
80 //*************************************************************************************************************
81 //=============================================================================================================
82 // Qt INCLUDES
83 //=============================================================================================================
84 
85 #include <QDebug>
86 #include <QAbstractTableModel>
87 #include <QMetaEnum>
88 
89 #include <QBrush>
90 #include <QPalette>
91 
92 #include <QtConcurrent>
93 
94 #include <QProgressDialog>
95 
96 
97 //*************************************************************************************************************
98 //=============================================================================================================
99 // Eigen INCLUDES
100 //=============================================================================================================
101 
102 #include <Eigen/Core>
103 #include <Eigen/SparseCore>
104 #include <unsupported/Eigen/FFT>
105 
106 #ifndef EIGEN_FFTW_DEFAULT
107 #define EIGEN_FFTW_DEFAULT
108 #endif
109 
110 
111 //*************************************************************************************************************
112 //=============================================================================================================
113 // MNE INCLUDES
114 //=============================================================================================================
115 
116 #include <fiff/fiff.h>
117 #include <mne/mne.h>
118 #include <utils/parksmcclellan.h>
119 
120 
121 //*************************************************************************************************************
122 //=============================================================================================================
123 // USED NAMESPACES
124 //=============================================================================================================
125 
126 using namespace Eigen;
127 using namespace MNELIB;
128 using namespace UTILSLIB;
129 using namespace FIFFLIB;
130 
131 
132 //*************************************************************************************************************
133 //=============================================================================================================
134 // DEFINE NAMESPACE MNEBrowseRawQt
135 //=============================================================================================================
136 
137 namespace MNEBrowseRawQt
138 {
139 
140 //=============================================================================================================
144 class RawModel : public QAbstractTableModel
145 {
146  Q_OBJECT
147 public:
148  RawModel(QObject *parent);
149  RawModel(QFile& qFile, QObject *parent);
150 
151  //=========================================================================================================
156  virtual int rowCount(const QModelIndex &parent = QModelIndex()) const ;
157  virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
158  virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
159  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
160 
161  //=========================================================================================================
167  bool loadFiffData(QFile *qFile);
168 
169  //=========================================================================================================
176  bool writeFiffData(QIODevice *p_IODevice);
177 
178  //VARIABLES
180  QList<FiffChInfo> m_chInfolist;
182  QSharedPointer<FiffIO> m_pfiffIO;
183  QMap<QString,QSharedPointer<MNEOperator> > m_Operators;
185 private:
186  //=========================================================================================================
190  void genStdFilterOps();
191 
192  //=========================================================================================================
197  void loadFiffInfos();
198 
199  //=========================================================================================================
203  void clearModel();
204 
205  //=========================================================================================================
211  void resetPosition(qint32 position);
212 
213  //=========================================================================================================
219  void reloadFiffData(bool before);
220 
221  //=========================================================================================================
229  QPair<MatrixXd,MatrixXd> readSegment(fiff_int_t from, fiff_int_t to);
230 
231  //VARIABLES
232  //Reload control
233  bool m_bStartReached;
234  bool m_bEndReached;
235  bool m_bReloadBefore;
237  //Concurrent reloading
238  QFutureWatcher<QPair<MatrixXd,MatrixXd> > m_reloadFutureWatcher;
239  bool m_bReloading;
241  //Concurrent processing
242 // QFutureWatcher<QPair<int,RowVectorXd> > m_operatorFutureWatcher; /**< QFutureWatcher for watching process of applying Operators to reloaded fiff data. */
243  QFutureWatcher<void> m_operatorFutureWatcher;
244  QList<QPair<int,RowVectorXd> > m_listTmpChData;
245  bool m_bProcessing;
246  QString m_filterChType;
247 
248  QMutex m_Mutex;
250  //Fiff data structure
251  QList<QSharedPointer<DataPackage> > m_data;
253  //Filter operators
254  QMap<int,QSharedPointer<MNEOperator> > m_assignedOperators;
256  qint32 m_iAbsFiffCursor;
257  qint32 m_iCurAbsScrollPos;
259  qint32 m_iWindowSize;
260  qint32 m_reloadPos;
261  qint8 m_maxWindows;
262  qint16 m_iFilterTaps;
263  int m_iCurrentFFTLength;
265 signals:
266  //=========================================================================================================
270  void dataReloaded();
271 
272  //=========================================================================================================
278  void fileLoaded(const FiffInfo&);
279 
280  //=========================================================================================================
286  void assignedOperatorsChanged(const QMap<int,QSharedPointer<MNEOperator> >&);
287 
288  void writeProgressChanged(int);
289 
290  void writeProgressRangeChanged(int,int);
291 
292 public slots:
293  //=========================================================================================================
299  void updateScrollPos(int value);
300 
301  //=========================================================================================================
308  void markChBad(QModelIndexList chlist, bool status);
309 
310  //=========================================================================================================
318  void applyOperator(QModelIndexList chlist, const QSharedPointer<MNEOperator>& operatorPtr, const QString &chType);
319 
320  //=========================================================================================================
327  void applyOperator(QModelIndexList chlist, const QSharedPointer<MNEOperator> &operatorPtr);
328 
329  //=========================================================================================================
335  void applyOperatorsConcurrently(QPair<int, RowVectorXd> &chdata) const;
336 
337  //=========================================================================================================
343  void updateOperators(QModelIndex chan);
344 
345  //=========================================================================================================
351  void updateOperators(QModelIndexList chlist);
352 
356  void updateOperators();
357 
358  //=========================================================================================================
365  void undoFilter(QModelIndexList chlist, const QSharedPointer<MNEOperator> &filterPtr);
366 
367  //=========================================================================================================
373  void undoFilter(QModelIndexList chlist);
374 
375  //=========================================================================================================
381  void undoFilter(const QString &chType);
382 
383  //=========================================================================================================
387  void undoFilter();
388 
389 private slots:
390  //=========================================================================================================
396  void insertReloadedData(QPair<MatrixXd,MatrixXd> dataTimesPair);
397 
398  //=========================================================================================================
402  void updateOperatorsConcurrently();
403 
404  //=========================================================================================================
410  void updateOperatorsConcurrently(int windowIndex);
411 
412  //=========================================================================================================
418  void insertProcessedDataRow(int rowIndex);
419 
420  //=========================================================================================================
426  void insertProcessedDataAll(int windowIndex);
427 
428  //=========================================================================================================
432  void insertProcessedDataAll();
433 
434  //=========================================================================================================
438  void performOverlapAdd();
439 
440  //=========================================================================================================
446  void performOverlapAdd(int windowIndex);
447 
448 public:
449  //=========================================================================================================
455  inline qint32 sizeOfFiffData();
456 
457  //=========================================================================================================
463  inline qint32 firstSample() const;
464 
465  //=========================================================================================================
471  inline qint32 lastSample() const;
472 
473  //=========================================================================================================
479  inline qint32 sizeOfPreloadedData() const;
480 
481  //=========================================================================================================
487  inline qint32 relFiffCursor() const;
488 
489  //=========================================================================================================
495  inline qint32 absFiffCursor() const;
496 };
497 
498 //*************************************************************************************************************
499 //=============================================================================================================
500 // INLINE DEFINITIONS
501 //=============================================================================================================
502 
503 inline qint32 RawModel::sizeOfFiffData() {
504  if(!m_pfiffIO->m_qlistRaw.empty())
505  return (m_pfiffIO->m_qlistRaw[0]->last_samp-m_pfiffIO->m_qlistRaw[0]->first_samp);
506  else return 0;
507 }
508 
509 
510 //*************************************************************************************************************
511 
512 inline qint32 RawModel::firstSample() const {
513  if(!m_pfiffIO->m_qlistRaw.empty())
514  return m_pfiffIO->m_qlistRaw[0]->first_samp;
515  else return 0;
516 }
517 
518 
519 //*************************************************************************************************************
520 
521 inline qint32 RawModel::lastSample() const {
522  if(!m_pfiffIO->m_qlistRaw.empty())
523  return m_pfiffIO->m_qlistRaw[0]->last_samp;
524  else return 0;
525 }
526 
527 
528 //*************************************************************************************************************
529 
530 inline qint32 RawModel::sizeOfPreloadedData() const {
531  if(!m_data.empty()) {
532  return m_data.size()*m_iWindowSize;
533  }
534  else return 0;
535 }
536 
537 
538 //*************************************************************************************************************
539 
540 inline qint32 RawModel::relFiffCursor() const {
541  return (m_iAbsFiffCursor - m_pfiffIO->m_qlistRaw[0]->first_samp);
542 }
543 
544 
545 //*************************************************************************************************************
546 
547 inline qint32 RawModel::absFiffCursor() const {
548  return m_iAbsFiffCursor;
549 }
550 
551 } // NAMESPACE
552 
553 #endif // RAWMODEL_H
QSharedPointer< FiffIO > m_pfiffIO
Definition: rawmodel.h:182
FIFF measurement file information.
Definition: fiff_info.h:96
QList< FiffChInfo > m_chInfolist
Definition: rawmodel.h:180
QMap< QString, QSharedPointer< MNEOperator > > m_Operators
Definition: rawmodel.h:183
Definition: fiff.h:98
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...