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{
62class FiffInfo;
63}
64
65//=============================================================================================================
66// DEFINE NAMESPACE DISPLIB
67//=============================================================================================================
68
69namespace DISPLIB
70{
71
72//=============================================================================================================
73// DISPLIB FORWARD DECLARATIONS
74//=============================================================================================================
75
76//=============================================================================================================
77// DEFINE TYPEDEFS
78//=============================================================================================================
79
80typedef QPair<const double*, qint32> RowVectorPair;
81typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixXdR;
82
83//=============================================================================================================
92class DISPSHARED_EXPORT RtFiffRawViewModel : public QAbstractTableModel
93{
94 Q_OBJECT
95
96public:
97 typedef QSharedPointer<RtFiffRawViewModel> SPtr;
98 typedef QSharedPointer<const RtFiffRawViewModel> ConstSPtr;
99
100 //=========================================================================================================
106 RtFiffRawViewModel(QObject* parent = 0);
107
108 //=========================================================================================================
113
115 //=========================================================================================================
123 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
124
125 //=========================================================================================================
133 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
134
135 //=========================================================================================================
144 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
145
146 //=========================================================================================================
156 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
157
158 //=========================================================================================================
164 void setFiffInfo(QSharedPointer<FIFFLIB::FiffInfo>& p_pFiffInfo);
165
166 //=========================================================================================================
174 void setSamplingInfo(float sps, int T, bool bSetZero = false);
175
176 //=========================================================================================================
182 Eigen::MatrixXd getLastBlock();
183
184 //=========================================================================================================
190 void addData(const QList<Eigen::MatrixXd>& data);
191
192 //=========================================================================================================
200 FIFFLIB::fiff_int_t getKind(qint32 row) const;
201
202 //=========================================================================================================
210 FIFFLIB::fiff_int_t getUnit(qint32 row) const;
211
212 //=========================================================================================================
220 FIFFLIB::fiff_int_t getCoil(qint32 row) const;
221
222 //=========================================================================================================
228 inline qint32 getMaxSamples() const;
229
230 //=========================================================================================================
236 inline qint32 getCurrentSampleIndex() const;
237
238 //=========================================================================================================
246 inline double getLastBlockFirstValue(int row) const;
247
248 //=========================================================================================================
254 inline const QMap<qint32, qint32>& getIdxSelMap() const;
255
256 //=========================================================================================================
262 void selectRows(const QList<qint32>& selection);
263
264 //=========================================================================================================
270 void hideRows(const QList<qint32>& selection);
271
272 //=========================================================================================================
276 void resetSelection();
277
278 //=========================================================================================================
284 void toggleFreeze(const QModelIndex& index);
285
286 //=========================================================================================================
292 void setScaling(const QMap<qint32, float>& p_qMapChScaling);
293
294 //=========================================================================================================
300 void updateProjection(const QList<FIFFLIB::FiffProj>& projs);
301
302 //=========================================================================================================
308 void updateCompensator(int to);
309
310 //=========================================================================================================
316 void updateSpharaActivation(bool state);
317
318 //=========================================================================================================
326 void updateSpharaOptions(const QString& sSytemType, int nBaseFctsFirst, int nBaseFctsSecond);
327
328 //=========================================================================================================
334 void setFilter(QList<UTILSLIB::FilterKernel> filterData);
335
336 //=========================================================================================================
342 void setFilterActive(bool state);
343
344 //=========================================================================================================
350 void setBackgroundColor(const QColor& color);
351
352 //=========================================================================================================
358 void setFilterChannelType(const QString& channelType);
359
360 //=========================================================================================================
366 void createFilterChannelList(QStringList channelNames);
367
368 //=========================================================================================================
375 void markChBad(QModelIndex ch, bool status);
376
377 //=========================================================================================================
384 void markChBad(QModelIndexList chlist, bool status);
385
386 //=========================================================================================================
395 void triggerInfoChanged(const QMap<double, QColor>& colorMap, bool active, QString triggerCh, double threshold);
396
397 //=========================================================================================================
403 void distanceTimeSpacerChanged(int value);
404
405 //=========================================================================================================
409 void resetTriggerCounter();
410
411 //=========================================================================================================
417 inline qint32 numVLines() const;
418
419 //=========================================================================================================
425 inline bool isFreezed() const;
426
427 //=========================================================================================================
433 inline const QMap<qint32, float>& getScaling() const;
434
435 //=========================================================================================================
441 inline QList<QPair<int, double>> getDetectedTriggers() const;
442
443 //=========================================================================================================
449 inline QList<QPair<int, double>> getDetectedTriggersOld() const;
450
451 //=========================================================================================================
457 inline QMap<double, QColor> getTriggerColor() const;
458
459 //=========================================================================================================
465 inline int getNumberOfTimeSpacers() const;
466
467 //=========================================================================================================
473 inline double getTriggerThreshold() const;
474
475 //=========================================================================================================
481 inline QString getTriggerName() const;
482
483 //=========================================================================================================
489 inline int getCurrentTriggerIndex() const;
490
491 //=========================================================================================================
497 inline bool triggerDetectionActive() const;
498
499 //=========================================================================================================
505 inline int getCurrentOverlapAddDelay() const;
506
507 //=========================================================================================================
513 inline int getFirstSampleOffset() const;
514
515 //=========================================================================================================
523 int getSampleAtColumn(int iColumn) const;
524
525 //=========================================================================================================
534 double getValueAtColumn(int iRow, int iColumn) const;
535
536 //=========================================================================================================
543 double getMaxValueFromRawViewModel(int row) const;
544
545 //=========================================================================================================
551 void addEvent(int iSample);
552
553 //=========================================================================================================
562 std::vector<int> getEventsToDisplay(int iBegin, int iEnd) const;
563
564 //=========================================================================================================
571 void setEventCallbacks(std::function<void(int)> addFn,
572 std::function<std::vector<int>(int, int)> getFn);
573
574private:
575 //=========================================================================================================
579 void initSphara();
580
581 static void doFilterPerChannelRTMSA(QPair<QList<UTILSLIB::FilterKernel>, QPair<int, Eigen::RowVectorXd>>& channelDataTime);
582
583 //=========================================================================================================
587 void filterDataBlock();
588
589 //=========================================================================================================
596 void filterDataBlock(const Eigen::MatrixXd& data, int iDataIndex);
597
598 //=========================================================================================================
602 void startNewSweep();
603
604 //=========================================================================================================
608 void clearModel();
609
610 bool m_bProjActivated;
611 bool m_bCompActivated;
612 bool m_bSpharaActivated;
613 bool m_bIsFreezed;
614 bool m_bDrawFilterFront;
615 bool m_bPerformFiltering;
616 bool m_bTriggerDetectionActive;
617 float m_fSps;
618 double m_dTriggerThreshold;
619 qint32 m_iT;
620 qint32 m_iDownsampling;
621 qint32 m_iMaxSamples;
622 qint32 m_iCurrentSample;
623 qint32 m_iCurrentStartingSample;
624 qint32 m_iCurrentSampleFreeze;
625 qint32 m_iMaxFilterLength;
626 qint32 m_iCurrentBlockSize;
627 int m_iCurrentTriggerChIndex;
628 int m_iDistanceTimerSpacer;
629 int m_iDetectedTriggers;
630
631 QString m_sCurrentTriggerCh;
632 QString m_sFilterChannelType;
633
634 QSharedPointer<FIFFLIB::FiffInfo> m_pFiffInfo;
635
636 Eigen::RowVectorXi m_vecBadIdcs;
637 Eigen::VectorXd m_vecLastBlockFirstValuesFiltered;
638 Eigen::VectorXd m_vecLastBlockFirstValuesRaw;
639
640 MatrixXdR m_matDataRaw;
641 MatrixXdR m_matDataFiltered;
642 MatrixXdR m_matDataRawFreeze;
643 MatrixXdR m_matDataFilteredFreeze;
644 Eigen::MatrixXd m_matOverlap;
645
646 Eigen::VectorXi m_vecIndicesFirstVV;
647 Eigen::VectorXi m_vecIndicesSecondVV;
648 Eigen::VectorXi m_vecIndicesFirstBabyMEG;
649 Eigen::VectorXi m_vecIndicesSecondBabyMEG;
650 Eigen::VectorXi m_vecIndicesFirstEEG;
651
652 Eigen::SparseMatrix<double> m_matSparseSpharaMult;
653 Eigen::SparseMatrix<double> m_matSparseProjCompMult;
654 Eigen::SparseMatrix<double> m_matSparseProjMult;
655 Eigen::SparseMatrix<double> m_matSparseCompMult;
656
657 Eigen::MatrixXd m_matProj;
658 Eigen::MatrixXd m_matComp;
659
660 Eigen::MatrixXd m_matSpharaVVGradLoaded;
661 Eigen::MatrixXd m_matSpharaVVMagLoaded;
662 Eigen::MatrixXd m_matSpharaBabyMEGInnerLoaded;
663 Eigen::MatrixXd m_matSpharaBabyMEGOuterLoaded;
664 Eigen::MatrixXd m_matSpharaEEGLoaded;
665
666 QMap<double, QColor> m_qMapTriggerColor;
667 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTrigger;
668 QList<int> m_lTriggerChannelIndices;
669 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTriggerFreeze;
670 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTriggerOld;
671 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTriggerOldFreeze;
672 QMap<qint32, float> m_qMapChScaling;
673 QList<UTILSLIB::FilterKernel> m_filterKernel;
674 QStringList m_filterChannelList;
675 QStringList m_visibleChannelList;
676 QMap<qint32, qint32> m_qMapIdxRowSelection;
677
678 QColor m_colBackground;
679
680 std::function<void(int)> m_fnAddEvent;
681 std::function<std::vector<int>(int, int)> m_fnGetEventSamples;
682
683signals:
684 //=========================================================================================================
690 void newSelection(const QList<qint32>& selection);
691
692 //=========================================================================================================
698 void windowSizeChanged(int windowSize);
699
700 //=========================================================================================================
704 void triggerDetected(int numberDetectedTriggers, const QMap<int, QList<QPair<int, double>>>& mapDetectedTriggers);
705};
706
707//=============================================================================================================
708// INLINE DEFINITIONS
709//=============================================================================================================
710
712{
713 return m_iMaxSamples;
714}
715
716//=============================================================================================================
717
719{
720 if (m_bIsFreezed) {
721 return m_iCurrentSampleFreeze;
722 }
723
724 if (!m_filterKernel.isEmpty() && m_bPerformFiltering) {
725 return m_iCurrentSample - m_iMaxFilterLength / 2;
726 }
727
728 return m_iCurrentSample;
729}
730
731//=============================================================================================================
732
734{
735 if (row > m_vecLastBlockFirstValuesFiltered.rows() || row > m_vecLastBlockFirstValuesRaw.rows())
736 return 0;
737
738 if (!m_filterKernel.isEmpty())
739 return m_vecLastBlockFirstValuesFiltered[row];
740
741 return m_vecLastBlockFirstValuesRaw[row];
742}
743
744//=============================================================================================================
745
746inline const QMap<qint32, qint32>& RtFiffRawViewModel::getIdxSelMap() const
747{
748 return m_qMapIdxRowSelection;
749}
750
751//=============================================================================================================
752
753inline qint32 RtFiffRawViewModel::numVLines() const
754{
755 return (m_iT - 1);
756}
757
758//=============================================================================================================
759
761{
762 return m_bIsFreezed;
763}
764
765//=============================================================================================================
766
767inline const QMap<qint32, float>& RtFiffRawViewModel::getScaling() const
768{
769 return m_qMapChScaling;
770}
771
772//=============================================================================================================
773
774inline QMap<double, QColor> RtFiffRawViewModel::getTriggerColor() const
775{
776 if (m_bTriggerDetectionActive) {
777 return m_qMapTriggerColor;
778 }
779
780 QMap<double, QColor> map;
781 return map;
782}
783
784//=============================================================================================================
785
786inline QList<QPair<int, double>> RtFiffRawViewModel::getDetectedTriggers() const
787{
788 QList<QPair<int, double>> triggerIndices;
789
790 if (m_bIsFreezed)
791 return m_qMapDetectedTriggerFreeze[m_iCurrentTriggerChIndex];
792
793 if (m_bTriggerDetectionActive) {
794 return m_qMapDetectedTrigger[m_iCurrentTriggerChIndex];
795 } else
796 return triggerIndices;
797}
798
799//=============================================================================================================
800
801inline QList<QPair<int, double>> RtFiffRawViewModel::getDetectedTriggersOld() const
802{
803 QList<QPair<int, double>> triggerIndices;
804
805 if (m_bIsFreezed)
806 return m_qMapDetectedTriggerOldFreeze[m_iCurrentTriggerChIndex];
807
808 if (m_bTriggerDetectionActive) {
809 return m_qMapDetectedTriggerOld[m_iCurrentTriggerChIndex];
810 } else
811 return triggerIndices;
812}
813
814//=============================================================================================================
815
817{
818 //qDebug()<<((m_iT*1000)/m_iDistanceTimerSpacer)-1;
819 return ((1000) / m_iDistanceTimerSpacer) - 1;
820}
821
822//=============================================================================================================
823
825{
826 return m_dTriggerThreshold;
827}
828
829//=============================================================================================================
830
832{
833 return m_sCurrentTriggerCh;
834}
835
836//=============================================================================================================
837
839{
840 return m_iCurrentTriggerChIndex;
841}
842
843//=============================================================================================================
844
846{
847 return m_bTriggerDetectionActive;
848}
849
850//=============================================================================================================
851
853{
854 if (!m_filterKernel.isEmpty())
855 return m_iMaxFilterLength / 2;
856 else
857 return 0;
858}
859
860//=============================================================================================================
861
863{
864 return m_iCurrentStartingSample;
865}
866} // NAMESPACE
867
868#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
869#ifndef metatype_rowvectorpair
870#define metatype_rowvectorpair
872#endif
873#endif
874
875#endif // RTFIFFRAWVIEWMODEL_H
Q_DECLARE_METATYPE(Eigen::MatrixXf)
MatrixXi selectRows(const MatrixXi &events, const std::vector< bool > &keep)
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.
Export macros and build-info hooks for the DISPLIB shared library.
#define DISPSHARED_EXPORT
Definition disp_global.h:38
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.
qint32 fiff_int_t
Definition fiff_types.h:86
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 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)
double getValueAtColumn(int iRow, int iColumn) const
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
int getSampleAtColumn(int iColumn) 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:90