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 //=========================================================================================================
367 void markChBad(QModelIndex ch, bool status);
368
369 //=========================================================================================================
376 void markChBad(QModelIndexList chlist, bool status);
377
378 //=========================================================================================================
387 void triggerInfoChanged(const QMap<double, QColor>& colorMap, bool active, QString triggerCh, double threshold);
388
389 //=========================================================================================================
395 void distanceTimeSpacerChanged(int value);
396
397 //=========================================================================================================
401 void resetTriggerCounter();
402
403 //=========================================================================================================
409 inline qint32 numVLines() const;
410
411 //=========================================================================================================
417 inline bool isFreezed() const;
418
419 //=========================================================================================================
425 inline const QMap<qint32, float>& getScaling() const;
426
427 //=========================================================================================================
433 inline QList<QPair<int, double>> getDetectedTriggers() const;
434
435 //=========================================================================================================
441 inline QList<QPair<int, double>> getDetectedTriggersOld() const;
442
443 //=========================================================================================================
449 inline QMap<double, QColor> getTriggerColor() const;
450
451 //=========================================================================================================
457 inline int getNumberOfTimeSpacers() const;
458
459 //=========================================================================================================
465 inline double getTriggerThreshold() const;
466
467 //=========================================================================================================
473 inline QString getTriggerName() const;
474
475 //=========================================================================================================
481 inline int getCurrentTriggerIndex() const;
482
483 //=========================================================================================================
489 inline bool triggerDetectionActive() const;
490
491 //=========================================================================================================
497 inline int getCurrentOverlapAddDelay() const;
498
499 //=========================================================================================================
505 inline int getFirstSampleOffset() const;
506
507 //=========================================================================================================
515 int getSampleAtColumn(int iColumn) const;
516
517 //=========================================================================================================
526 double getValueAtColumn(int iRow, int iColumn) const;
527
528 //=========================================================================================================
535 double getMaxValueFromRawViewModel(int row) const;
536
537 //=========================================================================================================
543 void addEvent(int iSample);
544
545 //=========================================================================================================
554 std::vector<int> getEventsToDisplay(int iBegin, int iEnd) const;
555
556 //=========================================================================================================
563 void setEventCallbacks(std::function<void(int)> addFn,
564 std::function<std::vector<int>(int, int)> getFn);
565
566private:
567 //=========================================================================================================
571 void initSphara();
572
573 static void doFilterPerChannelRTMSA(QPair<QList<UTILSLIB::FilterKernel>, QPair<int, Eigen::RowVectorXd>>& channelDataTime);
574
575 //=========================================================================================================
582 void filterDataBlock(const Eigen::MatrixXd& data, int iDataIndex);
583
584 //=========================================================================================================
588 void startNewSweep();
589
590 //=========================================================================================================
594 void clearModel();
595
596 bool m_bProjActivated;
597 bool m_bCompActivated;
598 bool m_bSpharaActivated;
599 bool m_bIsFreezed;
600 bool m_bDrawFilterFront;
601 bool m_bPerformFiltering;
602 bool m_bTriggerDetectionActive;
603 float m_fSps;
604 double m_dTriggerThreshold;
605 qint32 m_iT;
606 qint32 m_iDownsampling;
607 qint32 m_iMaxSamples;
608 qint32 m_iCurrentSample;
609 qint32 m_iCurrentStartingSample;
610 qint32 m_iCurrentSampleFreeze;
611 qint32 m_iMaxFilterLength;
612 qint32 m_iCurrentBlockSize;
613 int m_iCurrentTriggerChIndex;
614 int m_iDistanceTimerSpacer;
615 int m_iDetectedTriggers;
616
617 QString m_sCurrentTriggerCh;
618 QString m_sFilterChannelType;
619
620 QSharedPointer<FIFFLIB::FiffInfo> m_pFiffInfo;
621
622 Eigen::RowVectorXi m_vecBadIdcs;
623 Eigen::VectorXd m_vecLastBlockFirstValuesFiltered;
624 Eigen::VectorXd m_vecLastBlockFirstValuesRaw;
625
626 MatrixXdR m_matDataRaw;
627 MatrixXdR m_matDataFiltered;
628 MatrixXdR m_matDataRawFreeze;
629 MatrixXdR m_matDataFilteredFreeze;
630 Eigen::MatrixXd m_matOverlap;
631
632 Eigen::VectorXi m_vecIndicesFirstVV;
633 Eigen::VectorXi m_vecIndicesSecondVV;
634 Eigen::VectorXi m_vecIndicesFirstBabyMEG;
635 Eigen::VectorXi m_vecIndicesSecondBabyMEG;
636 Eigen::VectorXi m_vecIndicesFirstEEG;
637
638 Eigen::SparseMatrix<double> m_matSparseSpharaMult;
639 Eigen::SparseMatrix<double> m_matSparseProjCompMult;
640 Eigen::SparseMatrix<double> m_matSparseProjMult;
641 Eigen::SparseMatrix<double> m_matSparseCompMult;
642
643 Eigen::MatrixXd m_matProj;
644 Eigen::MatrixXd m_matComp;
645
646 Eigen::MatrixXd m_matSpharaVVGradLoaded;
647 Eigen::MatrixXd m_matSpharaVVMagLoaded;
648 Eigen::MatrixXd m_matSpharaBabyMEGInnerLoaded;
649 Eigen::MatrixXd m_matSpharaBabyMEGOuterLoaded;
650 Eigen::MatrixXd m_matSpharaEEGLoaded;
651
652 QMap<double, QColor> m_qMapTriggerColor;
653 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTrigger;
654 QList<int> m_lTriggerChannelIndices;
655 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTriggerFreeze;
656 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTriggerOld;
657 QMap<int, QList<QPair<int, double>>> m_qMapDetectedTriggerOldFreeze;
658 QMap<qint32, float> m_qMapChScaling;
659 QList<UTILSLIB::FilterKernel> m_filterKernel;
660 QStringList m_filterChannelList;
661 QMap<qint32, qint32> m_qMapIdxRowSelection;
662
663 QColor m_colBackground;
664
665 std::function<void(int)> m_fnAddEvent;
666 std::function<std::vector<int>(int, int)> m_fnGetEventSamples;
667
668signals:
669 //=========================================================================================================
675 void newSelection(const QList<qint32>& selection);
676
677 //=========================================================================================================
683 void windowSizeChanged(int windowSize);
684
685 //=========================================================================================================
689 void triggerDetected(int numberDetectedTriggers, const QMap<int, QList<QPair<int, double>>>& mapDetectedTriggers);
690};
691
692//=============================================================================================================
693// INLINE DEFINITIONS
694//=============================================================================================================
695
697{
698 return m_iMaxSamples;
699}
700
701//=============================================================================================================
702
704{
705 if (m_bIsFreezed) {
706 return m_iCurrentSampleFreeze;
707 }
708
709 if (!m_filterKernel.isEmpty() && m_bPerformFiltering) {
710 return m_iCurrentSample - m_iMaxFilterLength / 2;
711 }
712
713 return m_iCurrentSample;
714}
715
716//=============================================================================================================
717
719{
720 if (row > m_vecLastBlockFirstValuesFiltered.rows() || row > m_vecLastBlockFirstValuesRaw.rows())
721 return 0;
722
723 if (!m_filterKernel.isEmpty())
724 return m_vecLastBlockFirstValuesFiltered[row];
725
726 return m_vecLastBlockFirstValuesRaw[row];
727}
728
729//=============================================================================================================
730
731inline const QMap<qint32, qint32>& RtFiffRawViewModel::getIdxSelMap() const
732{
733 return m_qMapIdxRowSelection;
734}
735
736//=============================================================================================================
737
738inline qint32 RtFiffRawViewModel::numVLines() const
739{
740 return (m_iT - 1);
741}
742
743//=============================================================================================================
744
746{
747 return m_bIsFreezed;
748}
749
750//=============================================================================================================
751
752inline const QMap<qint32, float>& RtFiffRawViewModel::getScaling() const
753{
754 return m_qMapChScaling;
755}
756
757//=============================================================================================================
758
759inline QMap<double, QColor> RtFiffRawViewModel::getTriggerColor() const
760{
761 if (m_bTriggerDetectionActive) {
762 return m_qMapTriggerColor;
763 }
764
765 QMap<double, QColor> map;
766 return map;
767}
768
769//=============================================================================================================
770
771inline QList<QPair<int, double>> RtFiffRawViewModel::getDetectedTriggers() const
772{
773 QList<QPair<int, double>> triggerIndices;
774
775 if (m_bIsFreezed)
776 return m_qMapDetectedTriggerFreeze[m_iCurrentTriggerChIndex];
777
778 if (m_bTriggerDetectionActive) {
779 return m_qMapDetectedTrigger[m_iCurrentTriggerChIndex];
780 } else
781 return triggerIndices;
782}
783
784//=============================================================================================================
785
786inline QList<QPair<int, double>> RtFiffRawViewModel::getDetectedTriggersOld() const
787{
788 QList<QPair<int, double>> triggerIndices;
789
790 if (m_bIsFreezed)
791 return m_qMapDetectedTriggerOldFreeze[m_iCurrentTriggerChIndex];
792
793 if (m_bTriggerDetectionActive) {
794 return m_qMapDetectedTriggerOld[m_iCurrentTriggerChIndex];
795 } else
796 return triggerIndices;
797}
798
799//=============================================================================================================
800
802{
803 //qDebug()<<((m_iT*1000)/m_iDistanceTimerSpacer)-1;
804 return ((1000) / m_iDistanceTimerSpacer) - 1;
805}
806
807//=============================================================================================================
808
810{
811 return m_dTriggerThreshold;
812}
813
814//=============================================================================================================
815
817{
818 return m_sCurrentTriggerCh;
819}
820
821//=============================================================================================================
822
824{
825 return m_iCurrentTriggerChIndex;
826}
827
828//=============================================================================================================
829
831{
832 return m_bTriggerDetectionActive;
833}
834
835//=============================================================================================================
836
838{
839 if (!m_filterKernel.isEmpty())
840 return m_iMaxFilterLength / 2;
841 else
842 return 0;
843}
844
845//=============================================================================================================
846
848{
849 return m_iCurrentStartingSample;
850}
851} // NAMESPACE
852
853#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
854#ifndef metatype_rowvectorpair
855#define metatype_rowvectorpair
857#endif
858#endif
859
860#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 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