58 #include <QCoreApplication>
59 #include <QtConcurrent>
71 using namespace DISPLIB;
72 using namespace UTILSLIB;
73 using namespace FIFFLIB;
74 using namespace Eigen;
75 using namespace RTPROCESSINGLIB;
84 : QAbstractTableModel(parent)
85 , m_bProjActivated(false)
86 , m_bCompActivated(false)
87 , m_bSpharaActivated(false)
89 , m_bDrawFilterFront(true)
90 , m_bPerformFiltering(false)
91 , m_bTriggerDetectionActive(false)
93 , m_dTriggerThreshold(0.01)
98 , m_iCurrentStartingSample(0)
99 , m_iCurrentSampleFreeze(0)
100 , m_iMaxFilterLength(128)
101 , m_iCurrentBlockSize(1024)
103 , m_iCurrentTriggerChIndex(0)
104 , m_iDistanceTimerSpacer(1000)
105 , m_iDetectedTriggers(0)
106 , m_sFilterChannelType(
"MEG")
108 , m_colBackground(Qt::white)
124 if(!m_pFiffInfo->chs.isEmpty()) {
125 return m_pFiffInfo->chs.size();
142 if(role != Qt::DisplayRole && role != Qt::BackgroundRole) {
146 if (role == Qt::BackgroundRole) {
147 return QVariant(QBrush(m_colBackground));
150 if (index.isValid()) {
151 qint32 row = m_qMapIdxRowSelection.value(index.row(),0);
154 if(index.column() == 0 && role == Qt::DisplayRole)
155 return QVariant(m_pFiffInfo->ch_names[row]);
158 if(index.column() == 1) {
160 RowVectorPair rowVectorPair;
163 case Qt::DisplayRole: {
166 if(!m_filterKernel.isEmpty() && m_bPerformFiltering) {
167 rowVectorPair.first = m_matDataFilteredFreeze.data() + row*m_matDataFilteredFreeze.cols();
168 rowVectorPair.second = m_matDataFilteredFreeze.cols();
169 v.setValue(rowVectorPair);
171 rowVectorPair.first = m_matDataRawFreeze.data() + row*m_matDataRawFreeze.cols();
172 rowVectorPair.second = m_matDataRawFreeze.cols();
173 v.setValue(rowVectorPair);
178 if(!m_filterKernel.isEmpty() && m_bPerformFiltering) {
179 rowVectorPair.first = m_matDataFiltered.data() + row*m_matDataFiltered.cols();
180 rowVectorPair.second = m_matDataFiltered.cols();
181 v.setValue(rowVectorPair);
183 rowVectorPair.first = m_matDataRaw.data() + row*m_matDataRaw.cols();
184 rowVectorPair.second = m_matDataRaw.cols();
185 v.setValue(rowVectorPair);
195 if(index.column() == 2 && role == Qt::DisplayRole) {
196 return QVariant(m_pFiffInfo->bads.contains(m_pFiffInfo->ch_names[row]));
208 if(role != Qt::DisplayRole && role != Qt::TextAlignmentRole)
211 if(orientation == Qt::Horizontal) {
217 case Qt::DisplayRole:
218 return QVariant(
"data plot");
219 case Qt::TextAlignmentRole:
220 return QVariant(Qt::AlignLeft);
222 return QVariant(
"data plot");
225 else if(orientation == Qt::Vertical) {
226 QModelIndex chname = createIndex(section,0);
228 case Qt::DisplayRole:
229 return QVariant(
data(chname).toString());
238 void RtFiffRawViewModel::initSphara()
241 IOUtils::read_eigen_matrix(m_matSpharaVVGradLoaded, QCoreApplication::applicationDirPath() + QString(
"/../resources/mne_scan/plugins/noisereduction/SPHARA/Vectorview_SPHARA_InvEuclidean_Grad.txt"));
242 IOUtils::read_eigen_matrix(m_matSpharaVVMagLoaded, QCoreApplication::applicationDirPath() + QString(
"/../resources/mne_scan/plugins/noisereduction/SPHARA/Vectorview_SPHARA_InvEuclidean_Mag.txt"));
244 IOUtils::read_eigen_matrix(m_matSpharaBabyMEGInnerLoaded, QCoreApplication::applicationDirPath() + QString(
"/../resources/mne_scan/plugins/noisereduction/SPHARA/BabyMEG_SPHARA_InvEuclidean_Inner.txt"));
245 IOUtils::read_eigen_matrix(m_matSpharaBabyMEGOuterLoaded, QCoreApplication::applicationDirPath() + QString(
"/../resources/mne_scan/plugins/noisereduction/SPHARA/BabyMEG_SPHARA_InvEuclidean_Outer.txt"));
247 IOUtils::read_eigen_matrix(m_matSpharaEEGLoaded, QCoreApplication::applicationDirPath() + QString(
"/../resources/mne_scan/plugins/noisereduction/SPHARA/Current_SPHARA_EEG.txt"));
250 m_vecIndicesFirstVV.resize(0);
251 m_vecIndicesSecondVV.resize(0);
253 for(
int r = 0; r < m_pFiffInfo->chs.size(); ++r) {
255 if(m_pFiffInfo->chs.at(r).chpos.coil_type == 3012) {
256 m_vecIndicesFirstVV.conservativeResize(m_vecIndicesFirstVV.rows()+1);
257 m_vecIndicesFirstVV(m_vecIndicesFirstVV.rows()-1) = r;
261 if(m_pFiffInfo->chs.at(r).chpos.coil_type == 3024) {
262 m_vecIndicesSecondVV.conservativeResize(m_vecIndicesSecondVV.rows()+1);
263 m_vecIndicesSecondVV(m_vecIndicesSecondVV.rows()-1) = r;
268 m_vecIndicesFirstBabyMEG.resize(0);
269 for(
int r = 0; r < m_pFiffInfo->chs.size(); ++r) {
271 if(m_pFiffInfo->chs.at(r).chpos.coil_type == 7002) {
272 m_vecIndicesFirstBabyMEG.conservativeResize(m_vecIndicesFirstBabyMEG.rows()+1);
273 m_vecIndicesFirstBabyMEG(m_vecIndicesFirstBabyMEG.rows()-1) = r;
280 m_vecIndicesFirstEEG.resize(0);
281 for(
int r = 0; r < m_pFiffInfo->chs.size(); ++r) {
283 if(m_pFiffInfo->chs.at(r).kind == FIFFV_EEG_CH) {
284 m_vecIndicesFirstEEG.conservativeResize(m_vecIndicesFirstEEG.rows()+1);
285 m_vecIndicesFirstEEG(m_vecIndicesFirstEEG.rows()-1) = r;
292 qDebug()<<
"RtFiffRawViewModel::initSphara - Read VectorView mag matrix "<<m_matSpharaVVMagLoaded.rows()<<m_matSpharaVVMagLoaded.cols()<<
"and grad matrix"<<m_matSpharaVVGradLoaded.rows()<<m_matSpharaVVGradLoaded.cols();
293 qDebug()<<
"RtFiffRawViewModel::initSphara - Read BabyMEG inner layer matrix "<<m_matSpharaBabyMEGInnerLoaded.rows()<<m_matSpharaBabyMEGInnerLoaded.cols()<<
"and outer layer matrix"<<m_matSpharaBabyMEGOuterLoaded.rows()<<m_matSpharaBabyMEGOuterLoaded.cols();
302 QStringList emptyExclude;
304 if(p_pFiffInfo->bads.size() > 0) {
305 sel = FiffInfoBase::pick_channels(p_pFiffInfo->ch_names, p_pFiffInfo->bads, emptyExclude);
310 m_pFiffInfo = p_pFiffInfo;
315 m_matDataRaw.conservativeResize(m_pFiffInfo->chs.size(), m_iMaxSamples);
316 m_matDataRaw.setZero();
318 m_matDataFiltered.conservativeResize(m_pFiffInfo->chs.size(), m_iMaxSamples);
319 m_matDataFiltered.setZero();
321 m_vecLastBlockFirstValuesFiltered.conservativeResize(m_pFiffInfo->chs.size());
322 m_vecLastBlockFirstValuesFiltered.setZero();
324 m_vecLastBlockFirstValuesRaw.conservativeResize(m_pFiffInfo->chs.size());
325 m_vecLastBlockFirstValuesRaw.setZero();
327 m_matOverlap.conservativeResize(m_pFiffInfo->chs.size(), m_iMaxFilterLength);
329 m_matSparseProjMult = SparseMatrix<double>(m_pFiffInfo->chs.size(),m_pFiffInfo->chs.size());
330 m_matSparseCompMult = SparseMatrix<double>(m_pFiffInfo->chs.size(),m_pFiffInfo->chs.size());
331 m_matSparseSpharaMult = SparseMatrix<double>(m_pFiffInfo->chs.size(),m_pFiffInfo->chs.size());
332 m_matSparseProjCompMult = SparseMatrix<double>(m_pFiffInfo->chs.size(),m_pFiffInfo->chs.size());
334 m_matSparseProjMult.setIdentity();
335 m_matSparseCompMult.setIdentity();
336 m_matSparseSpharaMult.setIdentity();
337 m_matSparseProjCompMult.setIdentity();
343 int visibleInit = 20;
344 QStringList filterChannels;
346 if(visibleInit > m_pFiffInfo->chs.size()) {
347 while(visibleInit>m_pFiffInfo->chs.size()) {
352 for(qint32
b = 0;
b < visibleInit; ++
b) {
353 filterChannels.append(m_pFiffInfo->ch_names.at(
b));
367 m_vecBadIdcs = RowVectorXi(0,0);
368 m_matProj = MatrixXd(0,0);
369 m_matComp = MatrixXd(0,0);
381 m_iMaxSamples = (qint32) ceil(sps * T);
384 m_matDataRaw.conservativeResize(m_pFiffInfo->chs.size(), m_iMaxSamples);
385 m_matDataFiltered.conservativeResize(m_pFiffInfo->chs.size(), m_iMaxSamples);
386 m_vecLastBlockFirstValuesRaw.conservativeResize(m_pFiffInfo->chs.size());
387 m_vecLastBlockFirstValuesFiltered.conservativeResize(m_pFiffInfo->chs.size());
390 m_matDataRaw.setZero();
391 m_matDataFiltered.setZero();
392 m_vecLastBlockFirstValuesRaw.setZero();
393 m_vecLastBlockFirstValuesFiltered.setZero();
396 if(m_iCurrentSample>m_iMaxSamples) {
397 m_iCurrentStartingSample += m_iCurrentSample;
398 m_iCurrentSample = 0;
408 if(!m_filterKernel.isEmpty() && m_bPerformFiltering) {
409 return m_matDataFiltered.block(0, m_iCurrentSample-m_iCurrentBlockSize, m_matDataFiltered.rows(), m_iCurrentBlockSize);
412 return m_matDataRaw.block(0, m_iCurrentSample-m_iCurrentBlockSize, m_matDataRaw.rows(), m_iCurrentBlockSize);
420 bool doProj = m_bProjActivated && m_matDataRaw.cols() > 0 && m_matDataRaw.rows() == m_matProj.cols() ? true :
false;
423 bool doComp = m_bCompActivated && m_matDataRaw.cols() > 0 && m_matDataRaw.rows() == m_matComp.cols() ? true :
false;
426 bool doSphara = m_bSpharaActivated && m_matSparseSpharaMult.cols() > 0 && m_matDataRaw.rows() == m_matSparseSpharaMult.cols() ? true :
false;
429 for(qint32
b = 0;
b <
data.size(); ++
b) {
430 int nCol =
data.at(
b).cols();
431 int nRow =
data.at(
b).rows();
433 if(nRow != m_matDataRaw.rows()) {
434 qDebug()<<
"incoming data does not match internal data row size. Returning...";
439 if(m_iCurrentSample+nCol > m_matDataRaw.cols()) {
440 m_iResidual = nCol - ((m_iCurrentSample+nCol) % m_matDataRaw.cols());
442 if(m_iResidual == nCol) {
454 m_matDataRaw.block(0, m_iCurrentSample, nRow, m_iResidual) = m_matSparseProjCompMult *
data.at(
b).block(0,0,nRow,m_iResidual);
457 m_matDataRaw.block(0, m_iCurrentSample, nRow, m_iResidual) = m_matSparseCompMult *
data.at(
b).block(0,0,nRow,m_iResidual);
463 m_matDataRaw.block(0, m_iCurrentSample, nRow, m_iResidual) = m_matSparseProjMult *
data.at(
b).block(0,0,nRow,m_iResidual);
466 m_matDataRaw.block(0, m_iCurrentSample, nRow, m_iResidual) =
data.at(
b).block(0,0,nRow,m_iResidual);
470 m_iCurrentStartingSample += m_iCurrentSample;
471 m_iCurrentStartingSample += m_iResidual;
473 m_iCurrentSample = 0;
476 m_vecLastBlockFirstValuesFiltered = m_matDataFiltered.col(0);
477 m_vecLastBlockFirstValuesRaw = m_matDataRaw.col(0);
481 m_qMapDetectedTriggerOld = m_qMapDetectedTrigger;
484 if(m_bTriggerDetectionActive) {
485 QMutableMapIterator<int,QList<QPair<int,double> > > i(m_qMapDetectedTrigger);
486 while (i.hasNext()) {
500 m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol) = m_matSparseProjCompMult *
data.at(
b);
503 m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol) = m_matSparseCompMult *
data.at(
b);
508 m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol) = m_matSparseProjMult *
data.at(
b);
511 m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol) =
data.at(
b);
516 if(!m_filterKernel.isEmpty() && m_bPerformFiltering) {
517 filterDataBlock(m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol), m_iCurrentSample);
521 if(m_iCurrentSample-m_iMaxFilterLength/2 >= 0) {
522 m_matDataFiltered.block(0, m_iCurrentSample-m_iMaxFilterLength/2, nRow, nCol) = m_matSparseSpharaMult * m_matDataFiltered.block(0, m_iCurrentSample-m_iMaxFilterLength/2, nRow, nCol);
525 if(m_iCurrentSample-m_iMaxFilterLength/2 < 0) {
526 m_matDataFiltered.block(0, 0, nRow, nCol) = m_matSparseSpharaMult * m_matDataFiltered.block(0, 0, nRow, nCol);
527 int iResidual = m_iResidual+m_iMaxFilterLength/2;
528 m_matDataFiltered.block(0, m_matDataFiltered.cols()-iResidual, nRow, iResidual) = m_matSparseSpharaMult * m_matDataFiltered.block(0, m_matDataFiltered.cols()-iResidual, nRow, iResidual);
533 m_matDataFiltered.block(0, m_iCurrentSample, nRow, nCol).setZero();
537 m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol) = m_matSparseSpharaMult * m_matDataRaw.block(0, m_iCurrentSample, nRow, nCol);
541 m_iCurrentSample += nCol;
542 m_iCurrentBlockSize = nCol;
545 if(m_bTriggerDetectionActive) {
546 int iOldDetectedTriggers = m_qMapDetectedTrigger[m_iCurrentTriggerChIndex].size();
552 m_qMapDetectedTrigger[m_iCurrentTriggerChIndex].append(qMapDetectedTrigger);
555 int newTriggers = m_qMapDetectedTrigger[m_iCurrentTriggerChIndex].size() - iOldDetectedTriggers;
558 m_iDetectedTriggers += newTriggers;
565 QModelIndex topLeft = this->index(0,1);
566 QModelIndex bottomRight = this->index(m_pFiffInfo->ch_names.size()-1,1);
567 QVector<int> roles; roles << Qt::DisplayRole;
569 emit dataChanged(topLeft, bottomRight, roles);
576 if(row < m_qMapIdxRowSelection.size()) {
577 qint32 chRow = m_qMapIdxRowSelection[row];
578 return m_pFiffInfo->chs.at(chRow).kind;
588 if(row < m_qMapIdxRowSelection.size()) {
589 qint32 chRow = m_qMapIdxRowSelection[row];
590 return m_pFiffInfo->chs.at(chRow).unit;
593 return FIFF_UNIT_NONE;
600 if(row < m_qMapIdxRowSelection.size()) {
601 qint32 chRow = m_qMapIdxRowSelection[row];
602 return m_pFiffInfo->chs.at(chRow).chpos.coil_type;
614 m_qMapIdxRowSelection.clear();
617 for(qint32 i = 0; i < selection.size(); ++i) {
618 if(selection[i] < m_pFiffInfo->chs.size()) {
619 m_qMapIdxRowSelection.insert(count,selection[i]);
635 for(qint32 i = 0; i < selection.size(); ++i) {
636 if(m_qMapIdxRowSelection.contains(selection.at(i))) {
637 m_qMapIdxRowSelection.remove(selection.at(i));
652 m_qMapIdxRowSelection.clear();
654 for(qint32 i = 0; i < m_pFiffInfo->chs.size(); ++i) {
655 m_qMapIdxRowSelection.insert(i,i);
665 m_bIsFreezed = !m_bIsFreezed;
668 m_matDataRawFreeze = m_matDataRaw;
669 m_matDataFilteredFreeze = m_matDataFiltered;
670 m_qMapDetectedTriggerFreeze = m_qMapDetectedTrigger;
671 m_qMapDetectedTriggerOldFreeze = m_qMapDetectedTriggerOld;
673 m_iCurrentSampleFreeze = m_iCurrentSample;
677 QModelIndex topLeft = this->index(0,1);
678 QModelIndex bottomRight = this->index(m_pFiffInfo->chs.size()-1,1);
679 QVector<int> roles; roles << Qt::DisplayRole;
681 emit dataChanged(topLeft, bottomRight, roles);
689 m_qMapChScaling = p_qMapChScaling;
700 m_bProjActivated =
false;
701 m_pFiffInfo->projs = projs;
703 for(qint32 i = 0; i < this->m_pFiffInfo->projs.size(); ++i) {
704 if(this->m_pFiffInfo->projs[i].active) {
705 m_bProjActivated =
true;
710 this->m_pFiffInfo->make_projector(m_matProj);
712 qDebug() <<
"RtFiffRawViewModel::updateProjection - New projection calculated.";
715 for(qint32 j = 0; j < m_vecBadIdcs.cols(); ++j) {
716 m_matProj.col(m_vecBadIdcs[j]).setZero();
726 qint32 nchan = this->m_pFiffInfo->nchan;
729 typedef Eigen::Triplet<double> T;
730 std::vector<T> tripletList;
731 tripletList.reserve(nchan);
734 tripletList.reserve(m_matProj.rows()*m_matProj.cols());
735 for(i = 0; i < m_matProj.rows(); ++i) {
736 for(
k = 0;
k < m_matProj.cols(); ++
k) {
737 if(m_matProj(i,
k) != 0) {
738 tripletList.push_back(T(i,
k, m_matProj(i,
k)));
743 m_matSparseProjMult = SparseMatrix<double>(m_matProj.rows(),m_matProj.cols());
744 if(tripletList.size() > 0) {
745 m_matSparseProjMult.setFromTriplets(tripletList.begin(), tripletList.end());
749 m_matSparseProjCompMult = m_matSparseProjMult * m_matSparseCompMult;
760 m_bCompActivated =
false;
762 m_bCompActivated =
true;
770 this->m_pFiffInfo->make_compensator(0, to, newComp);
775 m_matComp = newComp.
data->data;
780 qint32 nchan = this->m_pFiffInfo->nchan;
783 typedef Eigen::Triplet<double> T;
784 std::vector<T> tripletList;
785 tripletList.reserve(nchan);
788 tripletList.reserve(m_matComp.rows()*m_matComp.cols());
789 for(i = 0; i < m_matComp.rows(); ++i) {
790 for(
k = 0;
k < m_matComp.cols(); ++
k) {
791 if(m_matComp(i,
k) != 0) {
792 tripletList.push_back(T(i,
k, m_matComp(i,
k)));
797 m_matSparseCompMult = SparseMatrix<double>(m_matComp.rows(),m_matComp.cols());
798 if(tripletList.size() > 0) {
799 m_matSparseCompMult.setFromTriplets(tripletList.begin(), tripletList.end());
803 m_matSparseProjCompMult = m_matSparseProjMult * m_matSparseCompMult;
811 m_bSpharaActivated = state;
819 qDebug()<<
"RtFiffRawViewModel::updateSpharaOptions - Creating SPHARA operator for"<<sSytemType;
821 MatrixXd matSpharaMultFirst = MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size());
822 MatrixXd matSpharaMultSecond = MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size());
824 if(sSytemType ==
"VectorView" && m_matSpharaVVGradLoaded.size() != 0 && m_matSpharaVVMagLoaded.size() != 0) {
829 if(sSytemType ==
"BabyMEG" && m_matSpharaBabyMEGInnerLoaded.size() != 0) {
833 if(sSytemType ==
"EEG" && m_matSpharaEEGLoaded.size() != 0) {
845 qint32 nchan = this->m_pFiffInfo->nchan;
848 typedef Eigen::Triplet<double> T;
849 std::vector<T> tripletList;
850 tripletList.reserve(nchan);
854 tripletList.reserve(matSpharaMultFirst.rows()*matSpharaMultFirst.cols());
855 for(i = 0; i < matSpharaMultFirst.rows(); ++i) {
856 for(
k = 0;
k < matSpharaMultFirst.cols(); ++
k) {
857 if(matSpharaMultFirst(i,
k) != 0) {
858 tripletList.push_back(T(i,
k, matSpharaMultFirst(i,
k)));
863 Eigen::SparseMatrix<double> matSparseSpharaMultFirst = SparseMatrix<double>(m_pFiffInfo->chs.size(),m_pFiffInfo->chs.size());
865 matSparseSpharaMultFirst = SparseMatrix<double>(matSpharaMultFirst.rows(),matSpharaMultFirst.cols());
866 if(tripletList.size() > 0) {
867 matSparseSpharaMultFirst.setFromTriplets(tripletList.begin(), tripletList.end());
872 tripletList.reserve(matSpharaMultSecond.rows()*matSpharaMultSecond.cols());
874 for(i = 0; i < matSpharaMultSecond.rows(); ++i) {
875 for(
k = 0;
k < matSpharaMultSecond.cols(); ++
k) {
876 if(matSpharaMultSecond(i,
k) != 0) {
877 tripletList.push_back(T(i,
k, matSpharaMultSecond(i,
k)));
882 Eigen::SparseMatrix<double>matSparseSpharaMultSecond = SparseMatrix<double>(m_pFiffInfo->chs.size(),m_pFiffInfo->chs.size());
884 if(tripletList.size() > 0) {
885 matSparseSpharaMultSecond.setFromTriplets(tripletList.begin(), tripletList.end());
889 m_matSparseSpharaMult = matSparseSpharaMultFirst * matSparseSpharaMultSecond;
899 m_iMaxFilterLength = 1;
901 if(m_iMaxFilterLength<
filterData.at(i).getFilterOrder()) {
902 m_iMaxFilterLength =
filterData.at(i).getFilterOrder();
906 m_matOverlap.conservativeResize(m_pFiffInfo->chs.size(), m_iMaxFilterLength);
907 m_matOverlap.setZero();
909 m_bDrawFilterFront =
false;
919 m_bPerformFiltering = state;
926 m_colBackground = color;
933 m_sFilterChannelType = channelType;
934 m_filterChannelList = m_visibleChannelList;
938 m_filterChannelList.clear();
940 for(
int i = 0; i<m_pFiffInfo->chs.size(); ++i) {
941 if((m_pFiffInfo->chs.at(i).kind == FIFFV_MEG_CH || m_pFiffInfo->chs.at(i).kind == FIFFV_EEG_CH ||
942 m_pFiffInfo->chs.at(i).kind == FIFFV_EOG_CH || m_pFiffInfo->chs.at(i).kind == FIFFV_ECG_CH ||
943 m_pFiffInfo->chs.at(i).kind == FIFFV_EMG_CH)) {
944 if(m_sFilterChannelType ==
"All") {
945 m_filterChannelList << m_pFiffInfo->chs.at(i).ch_name;
946 }
else if(m_pFiffInfo->chs.at(i).ch_name.contains(m_sFilterChannelType)) {
947 m_filterChannelList << m_pFiffInfo->chs.at(i).ch_name;
972 m_filterChannelList.clear();
973 m_visibleChannelList = channelNames;
988 for(
int i = 0; i < m_pFiffInfo->chs.size(); ++i) {
989 if((m_pFiffInfo->chs.at(i).kind == FIFFV_MEG_CH || m_pFiffInfo->chs.at(i).kind == FIFFV_EEG_CH ||
990 m_pFiffInfo->chs.at(i).kind == FIFFV_EOG_CH || m_pFiffInfo->chs.at(i).kind == FIFFV_ECG_CH ||
991 m_pFiffInfo->chs.at(i).kind == FIFFV_EMG_CH)) {
992 if(m_sFilterChannelType ==
"All") {
993 m_filterChannelList << m_pFiffInfo->chs.at(i).ch_name;
994 }
else if(m_pFiffInfo->chs.at(i).ch_name.contains(m_sFilterChannelType)) {
995 m_filterChannelList << m_pFiffInfo->chs.at(i).ch_name;
1013 QList<FiffChInfo> chInfolist = m_pFiffInfo->chs;
1016 if(!m_pFiffInfo->bads.contains(chInfolist[ch.row()].ch_name))
1017 m_pFiffInfo->bads.append(chInfolist[ch.row()].ch_name);
1018 qDebug() <<
"RawModel:" << chInfolist[ch.row()].ch_name <<
"marked as bad.";
1019 }
else if(m_pFiffInfo->bads.contains(chInfolist[ch.row()].ch_name)) {
1020 int index = m_pFiffInfo->bads.indexOf(chInfolist[ch.row()].ch_name);
1021 m_pFiffInfo->bads.removeAt(index);
1022 qDebug() <<
"RawModel:" << chInfolist[ch.row()].ch_name <<
"marked as good.";
1026 QStringList channelNames;
1030 QStringList emptyExclude;
1031 m_vecBadIdcs = FiffInfoBase::pick_channels(m_pFiffInfo->ch_names, m_pFiffInfo->bads, emptyExclude);
1033 emit dataChanged(ch,ch);
1040 m_qMapTriggerColor = colorMap;
1041 m_bTriggerDetectionActive = active;
1042 m_dTriggerThreshold = threshold;
1045 if(m_sCurrentTriggerCh != triggerCh) {
1046 m_sCurrentTriggerCh = triggerCh;
1048 QList<QPair<int,double> > temp;
1049 m_qMapDetectedTrigger.clear();
1051 for(
int i = 0; i < m_pFiffInfo->chs.size(); ++i) {
1052 if(m_pFiffInfo->chs[i].ch_name == m_sCurrentTriggerCh) {
1053 m_iCurrentTriggerChIndex = i;
1054 m_qMapDetectedTrigger.insert(i, temp);
1060 m_sCurrentTriggerCh = triggerCh;
1068 m_iDistanceTimerSpacer = 1000;
1070 m_iDistanceTimerSpacer = value;
1078 m_iDetectedTriggers = 0;
1085 QList<FiffChInfo> chInfolist = m_pFiffInfo->chs;
1087 for(
int i = 0; i < chlist.size(); ++i) {
1089 if(!m_pFiffInfo->bads.contains(chInfolist[chlist[i].row()].ch_name))
1090 m_pFiffInfo->bads.append(chInfolist[chlist[i].row()].ch_name);
1092 if(m_pFiffInfo->bads.contains(chInfolist[chlist[i].row()].ch_name)) {
1093 int index = m_pFiffInfo->bads.indexOf(chInfolist[chlist[i].row()].ch_name);
1094 m_pFiffInfo->bads.removeAt(index);
1098 emit dataChanged(chlist[i],chlist[i]);
1102 QStringList emptyExclude;
1103 m_vecBadIdcs = FiffInfoBase::pick_channels(m_pFiffInfo->ch_names, m_pFiffInfo->bads, emptyExclude);
1108 void RtFiffRawViewModel::doFilterPerChannelRTMSA(QPair<QList<FilterKernel>,QPair<int,RowVectorXd> > &channelDataTime)
1110 for(
int i = 0; i < channelDataTime.first.size(); ++i) {
1112 channelDataTime.first[i].applyFftFilter(channelDataTime.second.second,
true);
1118 void RtFiffRawViewModel::filterDataBlock()
1122 if(m_filterKernel.isEmpty() || !m_bPerformFiltering) {
1127 QList<FilterKernel> tempFilterList;
1129 int fftLength = m_matDataRaw.row(0).cols() + 4 * m_iMaxFilterLength;
1130 int exp = ceil(MNEMath::log2(fftLength));
1131 fftLength = pow(2, exp) < 512 ? 512 : pow(2, exp);
1133 for(
int i = 0; i<m_filterKernel.size(); ++i) {
1134 FilterKernel tempFilter(m_filterKernel.at(i).getName(),
1135 FilterKernel::m_filterTypes.indexOf(m_filterKernel.at(i).getFilterType()),
1136 m_filterKernel.at(i).getFilterOrder(),
1137 m_filterKernel.at(i).getCenterFrequency(),
1138 m_filterKernel.at(i).getBandwidth(),
1139 m_filterKernel.at(i).getParksWidth(),
1140 m_filterKernel.at(i).getSamplingFrequency(),
1141 FilterKernel::m_designMethods.indexOf(m_filterKernel.at(i).getDesignMethod()));
1143 tempFilterList.append(tempFilter);
1147 QList<QPair<QList<FilterKernel>,QPair<int,RowVectorXd> > > timeData;
1148 QList<int> notFilterChannelIndex;
1151 for(qint32 i=0; i<m_matDataRaw.rows(); ++i) {
1152 if(m_filterChannelList.contains(m_pFiffInfo->chs.at(i).ch_name)) {
1153 RowVectorXd datTemp(m_matDataRaw.row(i).cols() + 2 * m_iMaxFilterLength);
1154 datTemp << m_matDataRaw.row(i).head(m_iMaxFilterLength).reverse(), m_matDataRaw.row(i), m_matDataRaw.row(i).tail(m_iMaxFilterLength).reverse();
1155 timeData.append(QPair<QList<FilterKernel>,QPair<int,RowVectorXd> >(tempFilterList,QPair<int,RowVectorXd>(i,datTemp)));
1157 notFilterChannelIndex.append(i);
1162 if(!timeData.isEmpty()) {
1163 QFuture<void> future = QtConcurrent::map(timeData,
1164 doFilterPerChannelRTMSA);
1166 future.waitForFinished();
1168 for(
int r = 0; r < timeData.size(); ++r) {
1169 m_matDataFiltered.row(timeData.at(r).second.first) = timeData.at(r).second.second.segment(m_iMaxFilterLength+m_iMaxFilterLength/2, m_matDataRaw.cols());
1170 m_matOverlap.row(timeData.at(r).second.first) = timeData.at(r).second.second.tail(m_iMaxFilterLength);
1175 for(
int i = 0; i < notFilterChannelIndex.size(); ++i) {
1176 m_matDataFiltered.row(notFilterChannelIndex.at(i)) = m_matDataRaw.row(notFilterChannelIndex.at(i));
1180 m_vecLastBlockFirstValuesFiltered = m_matDataFiltered.col(0);
1188 void RtFiffRawViewModel::filterDataBlock(
const MatrixXd &data,
int iDataIndex)
1192 if(iDataIndex >= m_matDataFiltered.cols() ||
data.cols() < m_iMaxFilterLength) {
1197 QList<QPair<QList<FilterKernel>,QPair<int,RowVectorXd> > > timeData;
1198 QList<int> notFilterChannelIndex;
1200 for(qint32 i = 0; i <
data.rows(); ++i) {
1201 if(m_filterChannelList.contains(m_pFiffInfo->chs.at(i).ch_name)) {
1202 timeData.append(QPair<QList<FilterKernel>,QPair<int,RowVectorXd> >(m_filterKernel,QPair<int,RowVectorXd>(i,
data.row(i))));
1204 notFilterChannelIndex.append(i);
1209 if(!timeData.isEmpty()) {
1210 QFuture<void> future = QtConcurrent::map(timeData,
1211 doFilterPerChannelRTMSA);
1213 future.waitForFinished();
1216 int iFilterDelay = m_iMaxFilterLength/2;
1217 int iFilteredNumberCols = timeData.at(0).second.second.cols();
1219 for(
int r = 0; r<timeData.size(); ++r) {
1220 if(iDataIndex+2*
data.cols() > m_matDataRaw.cols()) {
1224 if(m_bDrawFilterFront) {
1226 RowVectorXd tempData = timeData.at(r).second.second;
1229 tempData.head(m_iMaxFilterLength) += m_matOverlap.row(timeData.at(r).second.first);
1232 int start = iDataIndex-iFilterDelay < 0 ? 0 : iDataIndex-iFilterDelay;
1233 m_matDataFiltered.row(timeData.at(r).second.first).segment(start,iFilteredNumberCols-m_iMaxFilterLength) = tempData.head(iFilteredNumberCols-m_iMaxFilterLength);
1236 m_matDataFiltered.row(timeData.at(r).second.first).segment(iDataIndex-iFilterDelay,m_iMaxFilterLength) = timeData.at(r).second.second.segment(m_iMaxFilterLength,m_iMaxFilterLength);
1237 m_matDataFiltered.row(timeData.at(r).second.first).segment(iDataIndex+iFilterDelay,iFilteredNumberCols-2*m_iMaxFilterLength) = timeData.at(r).second.second.segment(m_iMaxFilterLength,iFilteredNumberCols-2*m_iMaxFilterLength);
1241 m_matOverlap.row(timeData.at(r).second.first) = timeData.at(r).second.second.tail(m_iMaxFilterLength);
1242 }
else if(iDataIndex == 0) {
1246 if(m_bDrawFilterFront) {
1248 RowVectorXd tempData = timeData.at(r).second.second;
1251 m_matDataFiltered.row(timeData.at(r).second.first).segment(m_matDataFiltered.cols()-iFilterDelay-m_iResidual, iFilterDelay) = tempData.head(iFilterDelay) + m_matOverlap.row(timeData.at(r).second.first).head(iFilterDelay);
1254 tempData.head(m_iMaxFilterLength) += m_matOverlap.row(timeData.at(r).second.first);
1255 m_matDataFiltered.row(timeData.at(r).second.first).head(iFilteredNumberCols-m_iMaxFilterLength-iFilterDelay) = tempData.segment(iFilterDelay,iFilteredNumberCols-m_iMaxFilterLength-iFilterDelay);
1258 m_matDataFiltered.row(timeData.at(r).second.first).tail(m_iResidual) = m_matDataFiltered.row(timeData.at(r).second.first).head(m_iResidual);
1261 m_matDataFiltered.row(timeData.at(r).second.first).head(m_iMaxFilterLength) = timeData.at(r).second.second.segment(m_iMaxFilterLength,m_iMaxFilterLength);
1262 m_matDataFiltered.row(timeData.at(r).second.first).segment(iFilterDelay,iFilteredNumberCols-2*m_iMaxFilterLength) = timeData.at(r).second.second.segment(m_iMaxFilterLength,iFilteredNumberCols-2*m_iMaxFilterLength);
1266 m_matOverlap.row(timeData.at(r).second.first) = timeData.at(r).second.second.tail(m_iMaxFilterLength);
1271 if(m_bDrawFilterFront) {
1273 RowVectorXd tempData = timeData.at(r).second.second;
1276 tempData.head(m_iMaxFilterLength) += m_matOverlap.row(timeData.at(r).second.first);
1279 m_matDataFiltered.row(timeData.at(r).second.first).segment(iDataIndex-iFilterDelay,iFilteredNumberCols-m_iMaxFilterLength) = tempData.head(iFilteredNumberCols-m_iMaxFilterLength);
1282 m_matDataFiltered.row(timeData.at(r).second.first).segment(iDataIndex-iFilterDelay,m_iMaxFilterLength).setZero();
1283 m_matDataFiltered.row(timeData.at(r).second.first).segment(iDataIndex+iFilterDelay,iFilteredNumberCols-2*m_iMaxFilterLength) = timeData.at(r).second.second.segment(m_iMaxFilterLength,iFilteredNumberCols-2*m_iMaxFilterLength);
1287 m_matOverlap.row(timeData.at(r).second.first) = timeData.at(r).second.second.tail(m_iMaxFilterLength);
1292 m_bDrawFilterFront =
true;
1295 for(
int i = 0; i < notFilterChannelIndex.size(); ++i) {
1296 m_matDataFiltered.row(notFilterChannelIndex.at(i)).segment(iDataIndex,
data.row(notFilterChannelIndex.at(i)).cols()) =
data.row(notFilterChannelIndex.at(i));
1304 void RtFiffRawViewModel::clearModel()
1308 m_matDataRaw.setZero();
1309 m_matDataFiltered.setZero();
1310 m_matDataRawFreeze.setZero();
1311 m_matDataFilteredFreeze.setZero();
1312 m_vecLastBlockFirstValuesFiltered.setZero();
1313 m_vecLastBlockFirstValuesRaw.setZero();
1314 m_matOverlap.setZero();
1327 case FIFFV_MEG_CH: {
1330 if(unit == FIFF_UNIT_T_M) {
1335 else if(unit == FIFF_UNIT_T)
1350 case FIFFV_EEG_CH: {
1356 case FIFFV_EOG_CH: {
1362 case FIFFV_STIM_CH: {
1368 case FIFFV_MISC_CH: {