MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
rtfiffrawviewmodel.h
Go to the documentation of this file.
1//=============================================================================================================
38#ifndef RTFIFFRAWVIEWMODEL_H
39#define RTFIFFRAWVIEWMODEL_H
40
41//=============================================================================================================
42// INCLUDES
43//=============================================================================================================
44
45#include "../../disp_global.h"
46
47#include <fiff/fiff_types.h>
48#include <fiff/fiff_proj.h>
49
51
52#include <events/eventmanager.h>
53
54//=============================================================================================================
55// QT INCLUDES
56//=============================================================================================================
57
58#include <QAbstractTableModel>
59#include <QSharedPointer>
60#include <QColor>
61
62//=============================================================================================================
63// EIGEN INCLUDES
64//=============================================================================================================
65
66#include <Eigen/Core>
67#include <Eigen/SparseCore>
68
69//=============================================================================================================
70// FORWARD DECLARATIONS
71//=============================================================================================================
72
73namespace FIFFLIB {
74 class FiffInfo;
75}
76
77//=============================================================================================================
78// DEFINE NAMESPACE DISPLIB
79//=============================================================================================================
80
81namespace DISPLIB
82{
83
84//=============================================================================================================
85// DISPLIB FORWARD DECLARATIONS
86//=============================================================================================================
87
88//=============================================================================================================
89// DEFINE TYPEDEFS
90//=============================================================================================================
91
92typedef QPair<const double*,qint32> RowVectorPair;
93typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> MatrixXdR;
94
95//=============================================================================================================
101class DISPSHARED_EXPORT RtFiffRawViewModel : public QAbstractTableModel
102{
103 Q_OBJECT
104
105public:
106 typedef QSharedPointer<RtFiffRawViewModel> SPtr;
107 typedef QSharedPointer<const RtFiffRawViewModel> ConstSPtr;
109 //=========================================================================================================
115 RtFiffRawViewModel(QObject *parent = 0);
116
117 //=========================================================================================================
124 //=========================================================================================================
132 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const ;
133
134 //=========================================================================================================
142 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
143
144 //=========================================================================================================
153 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
154
155 //=========================================================================================================
165 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
166
167 //=========================================================================================================
173 void setFiffInfo(QSharedPointer<FIFFLIB::FiffInfo>& p_pFiffInfo);
174
175 //=========================================================================================================
183 void setSamplingInfo(float sps, int T, bool bSetZero = false);
184
185 //=========================================================================================================
191 Eigen::MatrixXd getLastBlock();
192
193 //=========================================================================================================
199 void addData(const QList<Eigen::MatrixXd> &data);
200
201 //=========================================================================================================
209 FIFFLIB::fiff_int_t getKind(qint32 row) const;
210
211 //=========================================================================================================
219 FIFFLIB::fiff_int_t getUnit(qint32 row) const;
220
221 //=========================================================================================================
229 FIFFLIB::fiff_int_t getCoil(qint32 row) const;
230
231 //=========================================================================================================
237 inline qint32 getMaxSamples() const;
238
239 //=========================================================================================================
245 inline qint32 getCurrentSampleIndex() const;
246
247 //=========================================================================================================
255 inline double getLastBlockFirstValue(int row) const;
256
257 //=========================================================================================================
263 inline const QMap<qint32,qint32>& getIdxSelMap() const;
264
265 //=========================================================================================================
271 void selectRows(const QList<qint32> &selection);
272
273 //=========================================================================================================
279 void hideRows(const QList<qint32> &selection);
280
281 //=========================================================================================================
285 void resetSelection();
286
287 //=========================================================================================================
293 void toggleFreeze(const QModelIndex &index);
294
295 //=========================================================================================================
301 void setScaling(const QMap< qint32,float >& p_qMapChScaling);
302
303 //=========================================================================================================
309 void updateProjection(const QList<FIFFLIB::FiffProj>& projs);
310
311 //=========================================================================================================
317 void updateCompensator(int to);
318
319 //=========================================================================================================
325 void updateSpharaActivation(bool state);
326
327 //=========================================================================================================
335 void updateSpharaOptions(const QString& sSytemType, int nBaseFctsFirst, int nBaseFctsSecond);
336
337 //=========================================================================================================
343 void setFilter(QList<RTPROCESSINGLIB::FilterKernel> filterData);
344
345 //=========================================================================================================
351 void setFilterActive(bool state);
352
353 //=========================================================================================================
359 void setBackgroundColor(const QColor& color);
360
361 //=========================================================================================================
367 void setFilterChannelType(const QString &channelType);
368
369 //=========================================================================================================
375 void createFilterChannelList(QStringList channelNames);
376
377 //=========================================================================================================
384 void markChBad(QModelIndex ch, bool status);
385
386 //=========================================================================================================
393 void markChBad(QModelIndexList chlist, bool status);
394
395 //=========================================================================================================
404 void triggerInfoChanged(const QMap<double, QColor>& colorMap, bool active, QString triggerCh, double threshold);
405
406 //=========================================================================================================
412 void distanceTimeSpacerChanged(int value);
413
414 //=========================================================================================================
418 void resetTriggerCounter();
419
420 //=========================================================================================================
426 inline qint32 numVLines() const;
427
428 //=========================================================================================================
434 inline bool isFreezed() const;
435
436 //=========================================================================================================
442 inline const QMap< qint32,float >& getScaling() const;
443
444 //=========================================================================================================
450 inline QList<QPair<int,double> > getDetectedTriggers() const;
451
452 //=========================================================================================================
458 inline QList<QPair<int, double> > getDetectedTriggersOld() const;
459
460 //=========================================================================================================
466 inline QMap<double, QColor> getTriggerColor() const;
467
468 //=========================================================================================================
474 inline int getNumberOfTimeSpacers() const;
475
476 //=========================================================================================================
482 inline double getTriggerThreshold() const;
483
484 //=========================================================================================================
490 inline QString getTriggerName() const;
491
492 //=========================================================================================================
498 inline int getCurrentTriggerIndex() const;
499
500 //=========================================================================================================
506 inline bool triggerDetectionActive() const;
507
508 //=========================================================================================================
514 inline int getCurrentOverlapAddDelay() const;
515
516 //=========================================================================================================
522 inline int getFirstSampleOffset() const;
523
524 //=========================================================================================================
531 double getMaxValueFromRawViewModel(int row) const;
532
533 //=========================================================================================================
539 void addEvent(int iSample);
540
541 //=========================================================================================================
550 std::unique_ptr<std::vector<EVENTSLIB::Event> > getEventsToDisplay(int iBegin, int iEnd) const;
551
552private:
553 //=========================================================================================================
557 void initSphara();
558
559 static void doFilterPerChannelRTMSA(QPair<QList<RTPROCESSINGLIB::FilterKernel>,QPair<int,Eigen::RowVectorXd> > &channelDataTime);
560
561 //=========================================================================================================
565 void filterDataBlock();
566
567 //=========================================================================================================
574 void filterDataBlock(const Eigen::MatrixXd &data, int iDataIndex);
575
576 //=========================================================================================================
580 void clearModel();
581
582 bool m_bProjActivated;
583 bool m_bCompActivated;
584 bool m_bSpharaActivated;
585 bool m_bIsFreezed;
586 bool m_bDrawFilterFront;
587 bool m_bPerformFiltering;
588 bool m_bTriggerDetectionActive;
589 float m_fSps;
590 double m_dTriggerThreshold;
591 qint32 m_iT;
592 qint32 m_iDownsampling;
593 qint32 m_iMaxSamples;
594 qint32 m_iCurrentSample;
595 qint32 m_iCurrentStartingSample;
596 qint32 m_iCurrentSampleFreeze;
597 qint32 m_iMaxFilterLength;
598 qint32 m_iCurrentBlockSize;
599 qint32 m_iResidual;
600 int m_iCurrentTriggerChIndex;
601 int m_iDistanceTimerSpacer;
602 int m_iDetectedTriggers;
604 QString m_sCurrentTriggerCh;
605 QString m_sFilterChannelType;
607 QSharedPointer<FIFFLIB::FiffInfo> m_pFiffInfo;
609 Eigen::RowVectorXi m_vecBadIdcs;
610 Eigen::VectorXd m_vecLastBlockFirstValuesFiltered;
611 Eigen::VectorXd m_vecLastBlockFirstValuesRaw;
613 MatrixXdR m_matDataRaw;
614 MatrixXdR m_matDataFiltered;
615 MatrixXdR m_matDataRawFreeze;
616 MatrixXdR m_matDataFilteredFreeze;
617 Eigen::MatrixXd m_matOverlap;
619 Eigen::VectorXi m_vecIndicesFirstVV;
620 Eigen::VectorXi m_vecIndicesSecondVV;
621 Eigen::VectorXi m_vecIndicesFirstBabyMEG;
622 Eigen::VectorXi m_vecIndicesSecondBabyMEG;
623 Eigen::VectorXi m_vecIndicesFirstEEG;
625 Eigen::SparseMatrix<double> m_matSparseSpharaMult;
626 Eigen::SparseMatrix<double> m_matSparseProjCompMult;
627 Eigen::SparseMatrix<double> m_matSparseProjMult;
628 Eigen::SparseMatrix<double> m_matSparseCompMult;
630 Eigen::MatrixXd m_matProj;
631 Eigen::MatrixXd m_matComp;
633 Eigen::MatrixXd m_matSpharaVVGradLoaded;
634 Eigen::MatrixXd m_matSpharaVVMagLoaded;
635 Eigen::MatrixXd m_matSpharaBabyMEGInnerLoaded;
636 Eigen::MatrixXd m_matSpharaBabyMEGOuterLoaded;
637 Eigen::MatrixXd m_matSpharaEEGLoaded;
639 QMap<double, QColor> m_qMapTriggerColor;
640 QMap<int,QList<QPair<int,double> > >m_qMapDetectedTrigger;
641 QList<int> m_lTriggerChannelIndices;
642 QMap<int,QList<QPair<int,double> > >m_qMapDetectedTriggerFreeze;
643 QMap<int,QList<QPair<int,double> > >m_qMapDetectedTriggerOld;
644 QMap<int,QList<QPair<int,double> > >m_qMapDetectedTriggerOldFreeze;
645 QMap<qint32,float> m_qMapChScaling;
646 QList<RTPROCESSINGLIB::FilterKernel>m_filterKernel;
647 QStringList m_filterChannelList;
648 QStringList m_visibleChannelList;
649 QMap<qint32,qint32> m_qMapIdxRowSelection;
651 QColor m_colBackground;
653 static EVENTSLIB::EventManager m_EventManager;
655signals:
656 //=========================================================================================================
662 void newSelection(const QList<qint32>& selection);
663
664 //=========================================================================================================
670 void windowSizeChanged(int windowSize);
671
672 //=========================================================================================================
676 void triggerDetected(int numberDetectedTriggers, const QMap<int,QList<QPair<int,double> > >& mapDetectedTriggers);
677};
678
679//=============================================================================================================
680// INLINE DEFINITIONS
681//=============================================================================================================
682
684{
685 return m_iMaxSamples;
686}
687
688//=============================================================================================================
689
691{
692 if(m_bIsFreezed) {
693 return m_iCurrentSampleFreeze;
694 }
695
696 if(!m_filterKernel.isEmpty() && m_bPerformFiltering) {
697 return m_iCurrentSample-m_iMaxFilterLength/2;
698 }
699
700 return m_iCurrentSample;
701}
702
703//=============================================================================================================
704
706{
707 if(row>m_vecLastBlockFirstValuesFiltered.rows() || row>m_vecLastBlockFirstValuesRaw.rows())
708 return 0;
709
710 if(!m_filterKernel.isEmpty())
711 return m_vecLastBlockFirstValuesFiltered[row];
712
713 return m_vecLastBlockFirstValuesRaw[row];
714}
715
716//=============================================================================================================
717
718inline const QMap<qint32,qint32>& RtFiffRawViewModel::getIdxSelMap() const
719{
720 return m_qMapIdxRowSelection;
721}
722
723//=============================================================================================================
724
725inline qint32 RtFiffRawViewModel::numVLines() const
726{
727 return (m_iT - 1);
728}
729
730//=============================================================================================================
731
733{
734 return m_bIsFreezed;
735}
736
737//=============================================================================================================
738
739inline const QMap<qint32,float>& RtFiffRawViewModel::getScaling() const
740{
741 return m_qMapChScaling;
742}
743
744//=============================================================================================================
745
746inline QMap<double, QColor> RtFiffRawViewModel::getTriggerColor() const
747{
748 if(m_bTriggerDetectionActive) {
749 return m_qMapTriggerColor;
750 }
751
752 QMap<double, QColor> map;
753 return map;
754}
755
756//=============================================================================================================
757
758inline QList<QPair<int,double> > RtFiffRawViewModel::getDetectedTriggers() const
759{
760 QList<QPair<int,double> > triggerIndices;
761
762 if(m_bIsFreezed)
763 return m_qMapDetectedTriggerFreeze[m_iCurrentTriggerChIndex];
764
765 if(m_bTriggerDetectionActive) {
766 return m_qMapDetectedTrigger[m_iCurrentTriggerChIndex];
767 }
768 else
769 return triggerIndices;
770}
771
772//=============================================================================================================
773
774inline QList<QPair<int,double> > RtFiffRawViewModel::getDetectedTriggersOld() const
775{
776 QList<QPair<int,double> > triggerIndices;
777
778 if(m_bIsFreezed)
779 return m_qMapDetectedTriggerOldFreeze[m_iCurrentTriggerChIndex];
780
781 if(m_bTriggerDetectionActive) {
782 return m_qMapDetectedTriggerOld[m_iCurrentTriggerChIndex];
783 }
784 else
785 return triggerIndices;
786}
787
788//=============================================================================================================
789
791{
792 //qDebug()<<((m_iT*1000)/m_iDistanceTimerSpacer)-1;
793 return ((1000)/m_iDistanceTimerSpacer)-1;
794}
795
796//=============================================================================================================
797
799{
800 return m_dTriggerThreshold;
801}
802
803//=============================================================================================================
804
806{
807 return m_sCurrentTriggerCh;
808}
809
810//=============================================================================================================
811
813{
814 return m_iCurrentTriggerChIndex;
815}
816
817//=============================================================================================================
818
820{
821 return m_bTriggerDetectionActive;
822}
823
824//=============================================================================================================
825
827{
828 if(!m_filterKernel.isEmpty())
829 return m_iMaxFilterLength/2;
830 else
831 return 0;
832}
833
834//=============================================================================================================
835
837{
838 return m_iCurrentStartingSample;
839}
840} // NAMESPACE
841
842#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
843#ifndef metatype_rowvectorpair
844#define metatype_rowvectorpair
845Q_DECLARE_METATYPE(DISPLIB::RowVectorPair);
846#endif
847#endif
848
849#endif // RTFIFFRAWVIEWMODEL_H
The FilterKernel class represents a filter object that generates the FIR filter coefficients using Pa...
#define DISPSHARED_EXPORT
Definition disp_global.h:55
FiffProj class declaration.
Definitions for describing the objects in a FIFF file.
Q_DECLARE_METATYPE(Eigen::MatrixXf)
EventManager declaration.
The RtFiffRawViewModel class implements the data access model for a real-time multi sample array data...
double getLastBlockFirstValue(int row) const
const QMap< qint32, float > & getScaling() const
void newSelection(const QList< qint32 > &selection)
QSharedPointer< RtFiffRawViewModel > SPtr
QSharedPointer< const RtFiffRawViewModel > ConstSPtr
void windowSizeChanged(int windowSize)
QList< QPair< int, double > > getDetectedTriggers() const
const QMap< qint32, qint32 > & getIdxSelMap() const
void triggerDetected(int numberDetectedTriggers, const QMap< int, QList< QPair< int, double > > > &mapDetectedTriggers)
QMap< double, QColor > getTriggerColor() const
QList< QPair< int, double > > getDetectedTriggersOld() const