v2.0.0
Loading...
Searching...
No Matches
rtfiffrawviewmodel.h
Go to the documentation of this file.
1//=============================================================================================================
23
24#ifndef RTFIFFRAWVIEWMODEL_H
25#define RTFIFFRAWVIEWMODEL_H
26
27//=============================================================================================================
28// INCLUDES
29//=============================================================================================================
30
31#include "../../disp_global.h"
32
33#include <fiff/fiff_types.h>
34#include <fiff/fiff_proj.h>
35
36#include <dsp/filterkernel.h>
37
38//=============================================================================================================
39// QT INCLUDES
40//=============================================================================================================
41
42#include <QAbstractTableModel>
43#include <QSharedPointer>
44#include <QColor>
45
46#include <functional>
47#include <vector>
48
49//=============================================================================================================
50// EIGEN INCLUDES
51//=============================================================================================================
52
53#include <Eigen/Core>
54#include <Eigen/SparseCore>
55
56//=============================================================================================================
57// FORWARD DECLARATIONS
58//=============================================================================================================
59
60namespace FIFFLIB {
61 class FiffInfo;
62}
63
64//=============================================================================================================
65// DEFINE NAMESPACE DISPLIB
66//=============================================================================================================
67
68namespace DISPLIB
69{
70
71//=============================================================================================================
72// DISPLIB FORWARD DECLARATIONS
73//=============================================================================================================
74
75//=============================================================================================================
76// DEFINE TYPEDEFS
77//=============================================================================================================
78
79typedef QPair<const double*,qint32> RowVectorPair;
80typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> MatrixXdR;
81
82//=============================================================================================================
91class DISPSHARED_EXPORT RtFiffRawViewModel : public QAbstractTableModel
92{
93 Q_OBJECT
94
95public:
96 typedef QSharedPointer<RtFiffRawViewModel> SPtr;
97 typedef QSharedPointer<const RtFiffRawViewModel> ConstSPtr;
98
99 //=========================================================================================================
105 RtFiffRawViewModel(QObject *parent = 0);
106
107 //=========================================================================================================
112
114 //=========================================================================================================
122 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const ;
123
124 //=========================================================================================================
132 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
133
134 //=========================================================================================================
143 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
144
145 //=========================================================================================================
155 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
156
157 //=========================================================================================================
163 void setFiffInfo(QSharedPointer<FIFFLIB::FiffInfo>& p_pFiffInfo);
164
165 //=========================================================================================================
173 void setSamplingInfo(float sps, int T, bool bSetZero = false);
174
175 //=========================================================================================================
181 Eigen::MatrixXd getLastBlock();
182
183 //=========================================================================================================
189 void addData(const QList<Eigen::MatrixXd> &data);
190
191 //=========================================================================================================
199 FIFFLIB::fiff_int_t getKind(qint32 row) const;
200
201 //=========================================================================================================
209 FIFFLIB::fiff_int_t getUnit(qint32 row) const;
210
211 //=========================================================================================================
219 FIFFLIB::fiff_int_t getCoil(qint32 row) const;
220
221 //=========================================================================================================
227 inline qint32 getMaxSamples() const;
228
229 //=========================================================================================================
235 inline qint32 getCurrentSampleIndex() const;
236
237 //=========================================================================================================
245 inline double getLastBlockFirstValue(int row) const;
246
247 //=========================================================================================================
253 inline const QMap<qint32,qint32>& getIdxSelMap() const;
254
255 //=========================================================================================================
261 void selectRows(const QList<qint32> &selection);
262
263 //=========================================================================================================
269 void hideRows(const QList<qint32> &selection);
270
271 //=========================================================================================================
275 void resetSelection();
276
277 //=========================================================================================================
283 void toggleFreeze(const QModelIndex &index);
284
285 //=========================================================================================================
291 void setScaling(const QMap< qint32,float >& p_qMapChScaling);
292
293 //=========================================================================================================
299 void updateProjection(const QList<FIFFLIB::FiffProj>& projs);
300
301 //=========================================================================================================
307 void updateCompensator(int to);
308
309 //=========================================================================================================
315 void updateSpharaActivation(bool state);
316
317 //=========================================================================================================
325 void updateSpharaOptions(const QString& sSytemType, int nBaseFctsFirst, int nBaseFctsSecond);
326
327 //=========================================================================================================
333 void setFilter(QList<UTILSLIB::FilterKernel> filterData);
334
335 //=========================================================================================================
341 void setFilterActive(bool state);
342
343 //=========================================================================================================
349 void setBackgroundColor(const QColor& color);
350
351 //=========================================================================================================
357 void setFilterChannelType(const QString &channelType);
358
359 //=========================================================================================================
365 void createFilterChannelList(QStringList channelNames);
366
367 //=========================================================================================================
374 void markChBad(QModelIndex ch, bool status);
375
376 //=========================================================================================================
383 void markChBad(QModelIndexList chlist, bool status);
384
385 //=========================================================================================================
394 void triggerInfoChanged(const QMap<double, QColor>& colorMap, bool active, QString triggerCh, double threshold);
395
396 //=========================================================================================================
402 void distanceTimeSpacerChanged(int value);
403
404 //=========================================================================================================
408 void resetTriggerCounter();
409
410 //=========================================================================================================
416 inline qint32 numVLines() const;
417
418 //=========================================================================================================
424 inline bool isFreezed() const;
425
426 //=========================================================================================================
432 inline const QMap< qint32,float >& getScaling() const;
433
434 //=========================================================================================================
440 inline QList<QPair<int,double> > getDetectedTriggers() const;
441
442 //=========================================================================================================
448 inline QList<QPair<int, double> > getDetectedTriggersOld() const;
449
450 //=========================================================================================================
456 inline QMap<double, QColor> getTriggerColor() const;
457
458 //=========================================================================================================
464 inline int getNumberOfTimeSpacers() const;
465
466 //=========================================================================================================
472 inline double getTriggerThreshold() const;
473
474 //=========================================================================================================
480 inline QString getTriggerName() const;
481
482 //=========================================================================================================
488 inline int getCurrentTriggerIndex() const;
489
490 //=========================================================================================================
496 inline bool triggerDetectionActive() const;
497
498 //=========================================================================================================
504 inline int getCurrentOverlapAddDelay() const;
505
506 //=========================================================================================================
512 inline int getFirstSampleOffset() const;
513
514 //=========================================================================================================
521 double getMaxValueFromRawViewModel(int row) const;
522
523 //=========================================================================================================
529 void addEvent(int iSample);
530
531 //=========================================================================================================
540 std::vector<int> getEventsToDisplay(int iBegin, int iEnd) const;
541
542 //=========================================================================================================
549 void setEventCallbacks(std::function<void(int)> addFn,
550 std::function<std::vector<int>(int, int)> getFn);
551
552private:
553 //=========================================================================================================
557 void initSphara();
558
559 static void doFilterPerChannelRTMSA(QPair<QList<UTILSLIB::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;
603
604 QString m_sCurrentTriggerCh;
605 QString m_sFilterChannelType;
606
607 QSharedPointer<FIFFLIB::FiffInfo> m_pFiffInfo;
608
609 Eigen::RowVectorXi m_vecBadIdcs;
610 Eigen::VectorXd m_vecLastBlockFirstValuesFiltered;
611 Eigen::VectorXd m_vecLastBlockFirstValuesRaw;
612
613 MatrixXdR m_matDataRaw;
614 MatrixXdR m_matDataFiltered;
615 MatrixXdR m_matDataRawFreeze;
616 MatrixXdR m_matDataFilteredFreeze;
617 Eigen::MatrixXd m_matOverlap;
618
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;
624
625 Eigen::SparseMatrix<double> m_matSparseSpharaMult;
626 Eigen::SparseMatrix<double> m_matSparseProjCompMult;
627 Eigen::SparseMatrix<double> m_matSparseProjMult;
628 Eigen::SparseMatrix<double> m_matSparseCompMult;
629
630 Eigen::MatrixXd m_matProj;
631 Eigen::MatrixXd m_matComp;
632
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;
638
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<UTILSLIB::FilterKernel>m_filterKernel;
647 QStringList m_filterChannelList;
648 QStringList m_visibleChannelList;
649 QMap<qint32,qint32> m_qMapIdxRowSelection;
650
651 QColor m_colBackground;
652
653 std::function<void(int)> m_fnAddEvent;
654 std::function<std::vector<int>(int, int)> m_fnGetEventSamples;
655
656signals:
657 //=========================================================================================================
663 void newSelection(const QList<qint32>& selection);
664
665 //=========================================================================================================
671 void windowSizeChanged(int windowSize);
672
673 //=========================================================================================================
677 void triggerDetected(int numberDetectedTriggers, const QMap<int,QList<QPair<int,double> > >& mapDetectedTriggers);
678};
679
680//=============================================================================================================
681// INLINE DEFINITIONS
682//=============================================================================================================
683
685{
686 return m_iMaxSamples;
687}
688
689//=============================================================================================================
690
692{
693 if(m_bIsFreezed) {
694 return m_iCurrentSampleFreeze;
695 }
696
697 if(!m_filterKernel.isEmpty() && m_bPerformFiltering) {
698 return m_iCurrentSample-m_iMaxFilterLength/2;
699 }
700
701 return m_iCurrentSample;
702}
703
704//=============================================================================================================
705
707{
708 if(row>m_vecLastBlockFirstValuesFiltered.rows() || row>m_vecLastBlockFirstValuesRaw.rows())
709 return 0;
710
711 if(!m_filterKernel.isEmpty())
712 return m_vecLastBlockFirstValuesFiltered[row];
713
714 return m_vecLastBlockFirstValuesRaw[row];
715}
716
717//=============================================================================================================
718
719inline const QMap<qint32,qint32>& RtFiffRawViewModel::getIdxSelMap() const
720{
721 return m_qMapIdxRowSelection;
722}
723
724//=============================================================================================================
725
726inline qint32 RtFiffRawViewModel::numVLines() const
727{
728 return (m_iT - 1);
729}
730
731//=============================================================================================================
732
734{
735 return m_bIsFreezed;
736}
737
738//=============================================================================================================
739
740inline const QMap<qint32,float>& RtFiffRawViewModel::getScaling() const
741{
742 return m_qMapChScaling;
743}
744
745//=============================================================================================================
746
747inline QMap<double, QColor> RtFiffRawViewModel::getTriggerColor() const
748{
749 if(m_bTriggerDetectionActive) {
750 return m_qMapTriggerColor;
751 }
752
753 QMap<double, QColor> map;
754 return map;
755}
756
757//=============================================================================================================
758
759inline QList<QPair<int,double> > RtFiffRawViewModel::getDetectedTriggers() const
760{
761 QList<QPair<int,double> > triggerIndices;
762
763 if(m_bIsFreezed)
764 return m_qMapDetectedTriggerFreeze[m_iCurrentTriggerChIndex];
765
766 if(m_bTriggerDetectionActive) {
767 return m_qMapDetectedTrigger[m_iCurrentTriggerChIndex];
768 }
769 else
770 return triggerIndices;
771}
772
773//=============================================================================================================
774
775inline QList<QPair<int,double> > RtFiffRawViewModel::getDetectedTriggersOld() const
776{
777 QList<QPair<int,double> > triggerIndices;
778
779 if(m_bIsFreezed)
780 return m_qMapDetectedTriggerOldFreeze[m_iCurrentTriggerChIndex];
781
782 if(m_bTriggerDetectionActive) {
783 return m_qMapDetectedTriggerOld[m_iCurrentTriggerChIndex];
784 }
785 else
786 return triggerIndices;
787}
788
789//=============================================================================================================
790
792{
793 //qDebug()<<((m_iT*1000)/m_iDistanceTimerSpacer)-1;
794 return ((1000)/m_iDistanceTimerSpacer)-1;
795}
796
797//=============================================================================================================
798
800{
801 return m_dTriggerThreshold;
802}
803
804//=============================================================================================================
805
807{
808 return m_sCurrentTriggerCh;
809}
810
811//=============================================================================================================
812
814{
815 return m_iCurrentTriggerChIndex;
816}
817
818//=============================================================================================================
819
821{
822 return m_bTriggerDetectionActive;
823}
824
825//=============================================================================================================
826
828{
829 if(!m_filterKernel.isEmpty())
830 return m_iMaxFilterLength/2;
831 else
832 return 0;
833}
834
835//=============================================================================================================
836
838{
839 return m_iCurrentStartingSample;
840}
841} // NAMESPACE
842
843#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
844#ifndef metatype_rowvectorpair
845#define metatype_rowvectorpair
847#endif
848#endif
849
850#endif // RTFIFFRAWVIEWMODEL_H
Q_DECLARE_METATYPE(Eigen::MatrixXf)
Export macros and build-info hooks for the DISPLIB shared library.
#define DISPSHARED_EXPORT
Definition disp_global.h:38
SSP projection item: a named projection vector set with active/desired flags, parsed from FIFFB_PROJ_...
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
Linear-phase FIR filter kernel with overlap-add FFT convolution back-end.
FIFF file I/O, in-memory data structures and high-level readers/writers.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixXdR
QPair< const double *, qint32 > RowVectorPair
double getLastBlockFirstValue(int row) const
const QMap< qint32, float > & getScaling() const
void setBackgroundColor(const QColor &color)
void setFilter(QList< UTILSLIB::FilterKernel > filterData)
void selectRows(const QList< qint32 > &selection)
void newSelection(const QList< qint32 > &selection)
FIFFLIB::fiff_int_t getKind(qint32 row) const
QSharedPointer< RtFiffRawViewModel > SPtr
QSharedPointer< const RtFiffRawViewModel > ConstSPtr
void setSamplingInfo(float sps, int T, bool bSetZero=false)
void markChBad(QModelIndex ch, bool status)
RtFiffRawViewModel(QObject *parent=0)
void windowSizeChanged(int windowSize)
void createFilterChannelList(QStringList channelNames)
void setFilterChannelType(const QString &channelType)
void setFiffInfo(QSharedPointer< FIFFLIB::FiffInfo > &p_pFiffInfo)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
QList< QPair< int, double > > getDetectedTriggers() const
void toggleFreeze(const QModelIndex &index)
void hideRows(const QList< qint32 > &selection)
void setEventCallbacks(std::function< void(int)> addFn, std::function< std::vector< int >(int, int)> getFn)
void updateSpharaOptions(const QString &sSytemType, int nBaseFctsFirst, int nBaseFctsSecond)
void setScaling(const QMap< qint32, float > &p_qMapChScaling)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
FIFFLIB::fiff_int_t getCoil(qint32 row) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
const QMap< qint32, qint32 > & getIdxSelMap() const
void triggerDetected(int numberDetectedTriggers, const QMap< int, QList< QPair< int, double > > > &mapDetectedTriggers)
QMap< double, QColor > getTriggerColor() const
FIFFLIB::fiff_int_t getUnit(qint32 row) const
std::vector< int > getEventsToDisplay(int iBegin, int iEnd) const
void triggerInfoChanged(const QMap< double, QColor > &colorMap, bool active, QString triggerCh, double threshold)
void updateProjection(const QList< FIFFLIB::FiffProj > &projs)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QList< QPair< int, double > > getDetectedTriggersOld() const
void addData(const QList< Eigen::MatrixXd > &data)
double getMaxValueFromRawViewModel(int row) const
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:88