v2.0.0
Loading...
Searching...
No Matches
channelinfomodel.cpp
Go to the documentation of this file.
1//=============================================================================================================
16
17//=============================================================================================================
18// INCLUDES
19//=============================================================================================================
20
21#include "channelinfomodel.h"
22#include "mneoperator.h"
23
24#include <fiff/fiff_info.h>
25
26//=============================================================================================================
27// QT INCLUDES
28//=============================================================================================================
29
30#include <QVector3D>
31#include <QRegularExpression>
32
33//=============================================================================================================
34// EIGEN INCLUDES
35//=============================================================================================================
36
37//=============================================================================================================
38// USED NAMESPACES
39//=============================================================================================================
40
41using namespace DISPLIB;
42using namespace Eigen;
43using namespace FIFFLIB;
44
45//=============================================================================================================
46// DEFINE MEMBER METHODS
47//=============================================================================================================
48
49ChannelInfoModel::ChannelInfoModel(FiffInfo::SPtr& pFiffInfo, QObject *parent)
50: QAbstractTableModel(parent)
51, m_pFiffInfo(pFiffInfo)
52{
53 setFiffInfo(m_pFiffInfo);
54}
55
56//=============================================================================================================
57
59: QAbstractTableModel(parent)
61{
62}
63
64//=============================================================================================================
65
66int ChannelInfoModel::rowCount(const QModelIndex & /*parent*/) const
67{
68 //Return number of stored evoked sets
69 if(!m_pFiffInfo->chs.isEmpty())
70 return m_pFiffInfo->chs.size();
71 else
72 return 0;
73}
74
75//=============================================================================================================
76
77int ChannelInfoModel::columnCount(const QModelIndex & /*parent*/) const
78{
79 return 13;
80}
81
82//=============================================================================================================
83
84QVariant ChannelInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
85{
86 if(role != Qt::DisplayRole && role != Qt::TextAlignmentRole)
87 return QVariant();
88
89 Qt::Alignment a;
90 switch(role) {
91 case Qt::TextAlignmentRole:
92 a = Qt::AlignHCenter | Qt::AlignVCenter;
93 return QVariant(a);
94
95 case Qt::DisplayRole: {
96 //Return the number and description/comment of the fiff evoked data in the set as vertical header
97 if(orientation == Qt::Vertical)
98 if(section<m_pFiffInfo->chs.size())
99 return QString("Ch %1").arg(section);
100
101 //Return the horizontal header
102 if(orientation == Qt::Horizontal) {
103 switch(section) {
104 case 0:
105 return QString("%1").arg("Data number");
106 break;
107
108 case 1:
109 return QString("%1").arg("Original name");
110 break;
111
112 case 2:
113 return QString("%1").arg("Alias");
114 break;
115
116 case 3:
117 return QString("%1").arg("Mapped layout name");
118 break;
119
120 case 4:
121 return QString("%1").arg("Channel kind");
122 break;
123
124 case 5:
125 return QString("%1").arg("MEG type");
126 break;
127
128 case 6:
129 return QString("%1").arg("Unit");
130 break;
131
132 case 7:
133 return QString("%1").arg("Position");
134 break;
135
136 case 8:
137 return QString("%1").arg("Digitizer (cm)");
138 break;
139
140 case 9:
141 return QString("%1").arg("Active filter");
142 break;
143
144 case 10:
145 return QString("%1").arg("Coil Type");
146 break;
147
148 case 11:
149 return QString("%1").arg("Bad channel");
150 break;
151
152 case 12:
153 return QString("%1").arg("# of Compensators");
154 break;
155 }
156 }
157 }
158 }
159
160 return QVariant();
161}
162
163//=============================================================================================================
164
165QVariant ChannelInfoModel::data(const QModelIndex &index, int role) const
166{
167 if(index.row() >= m_pFiffInfo->chs.size())
168 return QVariant();
169
170 if (index.isValid()) {
171 //******** first column (channel number - corresponds to row in fiff data matrix) ********
172 if(index.column()==0) {
173 QVariant v;
174
175 switch(role) {
176 case Qt::DisplayRole:
177 v.setValue(index.row());
178 return v;
179
181 v.setValue(index.row());
182 return v;
183
184 case Qt::TextAlignmentRole:
185 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
186 return QVariant(a);
187 }
188 }//end column check
189
190 //******** second column (original channel name) ********
191 if(index.column()==1) {
192 QVariant v;
193
194 switch(role) {
195 case Qt::DisplayRole:
196 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).ch_name));
197 return v;
198
200 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).ch_name));
201 return v;
202
203 case Qt::TextAlignmentRole:
204 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
205 return QVariant(a);
206 }
207 }//end column check
208
209 //******** third column (channel alias) ********
210 if(index.column()==2) {
211 QVariant v;
212
213 switch(role) {
214 case Qt::DisplayRole:
215 if(index.row()<m_aliasNames.size())
216 v.setValue(QString("%1").arg(m_aliasNames.at(index.row())));
217 return v;
218
220 if(index.row()<m_aliasNames.size())
221 v.setValue(QString("%1").arg(m_aliasNames.at(index.row())));
222 return v;
223
224 case Qt::TextAlignmentRole:
225 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
226 return QVariant(a);
227 }
228 }//end column check
229
230 //******** fourth column (mapped layout channel name) ********
231 if(index.column()==3) {
232 QVariant v;
233
234 switch(role) {
235 case Qt::DisplayRole:
236 if(index.row()<m_mappedLayoutChNames.size())
237 v.setValue(QString("%1").arg(m_mappedLayoutChNames.at(index.row())));
238 return v;
239
241 if(index.row()<m_mappedLayoutChNames.size())
242 v.setValue(QString("%1").arg(m_mappedLayoutChNames.at(index.row())));
243 return v;
244
245 case Qt::TextAlignmentRole:
246 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
247 return QVariant(a);
248 }
249 }//end column check
250
251 //******** fifth column (channel kind - MEG, EEG, etc) ********
252 if(index.column()==4) {
253 QVariant v;
254
255 switch(role) {
256 case Qt::DisplayRole:
257 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).kind));
258 return v;
259
261 v.setValue(m_pFiffInfo->chs.at(index.row()).kind);
262 return v;
263
264 case Qt::TextAlignmentRole:
265 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
266 return QVariant(a);
267 }
268 }//end column check
269
270 //******** sixth column (MEG type) ********
271 if(index.column()==5) {
272 QVariant v;
273
274 v.setValue(QString("%1").arg("non_MEG"));
275
276 if(m_pFiffInfo->chs.at(index.row()).kind == FIFFV_MEG_CH) {
277 qint32 unit = m_pFiffInfo->chs.at(index.row()).unit;
278 if(unit == FIFF_UNIT_T_M)
279 v.setValue(QString("MEG_grad"));
280 else if(unit == FIFF_UNIT_T)
281 v.setValue(QString("MEG_mag"));
282 }
283
284 switch(role) {
285 case Qt::DisplayRole:
286 return v;
287
289 return v;
290
291 case Qt::TextAlignmentRole:
292 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
293 return QVariant(a);
294 }
295 }//end column check
296
297 //******** seventh column (channel unit) ********
298 if(index.column()==6) {
299 QVariant v;
300
301 switch(role) {
302 case Qt::DisplayRole:
303 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).unit));
304 return v;
305
307 v.setValue(m_pFiffInfo->chs.at(index.row()).unit);
308 return v;
309
310 case Qt::TextAlignmentRole:
311 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
312 return QVariant(a);
313 }
314 }//end column check
315
316 //******** eigth column (channel layout position) ********
317 if(index.column()==7) {
318 QVariant v;
319
320 QPointF point = m_layoutMap[m_mappedLayoutChNames.at(index.row())];
321
322 switch(role) {
323 case Qt::DisplayRole:
324 v.setValue(QString("(%1|%2)").arg(point.x()).arg(point.y()));
325 return v;
326
328 v.setValue(point);
329 return v;
330
331 case Qt::TextAlignmentRole:
332 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
333 return QVariant(a);
334 }
335 }//end column check
336
337 //******** ninth column (channel digitizer position) ********
338 if(index.column()==8) {
339 QVariant v;
340
341 QVector3D point3D( m_pFiffInfo->chs.at(index.row()).chpos.r0[0] * 100, //convert to cm
342 m_pFiffInfo->chs.at(index.row()).chpos.r0[1] * 100,
343 m_pFiffInfo->chs.at(index.row()).chpos.r0[2] * 100 );
344
345 switch(role) {
346 case Qt::DisplayRole:
347 v.setValue(QString("(%1|%2|%3)").arg(point3D.x()).arg(point3D.y()).arg(point3D.z()));
348 return v;
349
351 v.setValue(point3D);
352 return v;
353
354 case Qt::TextAlignmentRole:
355 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
356 return QVariant(a);
357 }
358 }//end column check
359
360 //******** tenth column (active channel filter type) ********
361 if(index.column()==9) {
362 QVariant v;
363
364// //Check if mne operator is a filter operator
365// QSharedPointer<MNEOperator> operatorPtr = m_assignedOperators.value(index.row(), QSharedPointer<MNEOperator>(new MNEOperator()));
366// QSharedPointer<FilterOperator> filterOperator;
367
368 switch(role) {
369 case Qt::DisplayRole: {
370 return v;
371 }
372// if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
373// filterOperator = operatorPtr.staticCast<FilterOperator>();
374// }
375// else {
376// v.setValue(QString("%1").arg("none"));
377// return v;
378// }
379
380// switch(filterOperator->m_Type) {
381// case FilterOperator::LPF: {
382// v.setValue(QString("%1 | %2").arg("LP").arg(filterOperator->m_dCenterFreq*m_pFiffInfo->sfreq/2));
383// return v;
384// }
385
386// case FilterOperator::HPF: {
387// v.setValue(QString("%1 | %2").arg("HP").arg(filterOperator->m_dCenterFreq*m_pFiffInfo->sfreq/2));
388// return v;
389// }
390
391// case FilterOperator::BPF: {
392// double fsample = m_pFiffInfo->sfreq;
393// double low = (filterOperator->m_dCenterFreq*fsample/2) - (filterOperator->m_dBandwidth*fsample/4); // /4 because we also need to devide by 2 to get the nyquist freq
394// double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
395// v.setValue(QString("%1 | %2 | %3").arg("BP").arg(low).arg(high));
396// return v;
397// }
398
399// case FilterOperator::NOTCH: {
400// double fsample = m_pFiffInfo->sfreq;
401// double low = (filterOperator->m_dCenterFreq*fsample/2) - (filterOperator->m_dBandwidth*fsample/4);
402// double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
403// v.setValue(QString("%1 | %2 | %3").arg("NOTCH").arg(low).arg(high));
404// return v;
405// }
406// }
407// }
408
409// case ChannelInfoModelRoles::GetChActiveFilter: {
410// if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
411// filterOperator = operatorPtr.staticCast<FilterOperator>();
412// }
413// else {
414// v.setValue(QString("%1").arg("none"));
415// return v;
416// }
417
418// v.setValue(operatorPtr);
419// return v;
420// }
421
422 case Qt::TextAlignmentRole:
423 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
424 return QVariant(a);
425 }
426 }
427
428 //******** eleventh column (coil type) ********
429 if(index.column()==10) {
430 QVariant v;
431
432 switch(role) {
433 case Qt::DisplayRole:
434 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).chpos.coil_type));
435 return v;
436
438 v.setValue(m_pFiffInfo->chs.at(index.row()).chpos.coil_type);
439 return v;
440
441 case Qt::TextAlignmentRole:
442 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
443 return QVariant(a);
444 }
445 }//end column check
446
447 //******** twelve column (channel bad) ********
448 if(index.column()==11) {
449 QVariant v;
450 bool isBad = false;
451 QString chName = m_pFiffInfo->chs.at(index.row()).ch_name;
452
453 switch(role) {
454 case Qt::DisplayRole:
455 isBad = m_pFiffInfo->bads.contains(chName);
456 v.setValue(isBad);
457 return v;
458
460 isBad = m_pFiffInfo->bads.contains(chName);
461 v.setValue(isBad);
462 return v;
463
464 case Qt::TextAlignmentRole:
465 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
466 return QVariant(a);
467 }
468 }//end column check
469
470 //******** twelve column (compensators bad) ********
471 if(index.column()==12) {
472 QVariant v;
473
474 switch(role) {
475 case Qt::DisplayRole:
476 v.setValue(m_pFiffInfo->comps.size());
477 return v;
478
479 case Qt::TextAlignmentRole:
480 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
481 return QVariant(a);
482 }
483 }//end column check
484 } // end index.valid() check
485
486 return QVariant();
487}
488
489//=============================================================================================================
490
491bool ChannelInfoModel::insertRows(int position, int span, const QModelIndex & parent)
492{
493 Q_UNUSED(position);
494 Q_UNUSED(span);
495 Q_UNUSED(parent);
496
497 return true;
498}
499
500//=============================================================================================================
501
502bool ChannelInfoModel::removeRows(int position, int span, const QModelIndex & parent)
503{
504 Q_UNUSED(position);
505 Q_UNUSED(span);
506 Q_UNUSED(parent);
507
508 return true;
509}
510
511//=============================================================================================================
512
513Qt::ItemFlags ChannelInfoModel::flags(const QModelIndex & index) const
514{
515 Q_UNUSED(index);
516 return Qt::ItemIsEnabled | Qt::ItemIsSelectable /*| Qt::ItemIsEditable*/;
517}
518
519//=============================================================================================================
520
521bool ChannelInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
522{
523 Q_UNUSED(index);
524 Q_UNUSED(value);
525 Q_UNUSED(role);
526
527 return true;
528}
529
530//=============================================================================================================
531
533{
534 beginResetModel();
535
536 m_pFiffInfo = pFiffInfo;
537 m_aliasNames = m_pFiffInfo->ch_names;
539
541
542 endResetModel();
543
544 emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
545}
546
547//=============================================================================================================
548
549void ChannelInfoModel::assignedOperatorsChanged(const QMultiMap<int,QSharedPointer<MNEOperator> > &assignedOperators)
550{
551 beginResetModel();
552
553 m_assignedOperators = assignedOperators;
554
555 endResetModel();
556
557 emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
558}
559
560//=============================================================================================================
561
562void ChannelInfoModel::layoutChanged(const QMap<QString,QPointF> &layoutMap)
563{
564 beginResetModel();
565
566 m_layoutMap = layoutMap;
567 m_aliasNames = m_pFiffInfo->ch_names;
569
571
572 endResetModel();
573
574 emit dataChanged(createIndex(0,0), createIndex(rowCount(), columnCount()));
575}
576
577//=============================================================================================================
578
580{
581
583}
584
585//=============================================================================================================
586
588{
589 return m_pFiffInfo->ch_names.indexOf(chName);
590}
591
592//=============================================================================================================
593
595{
596 return m_mappedLayoutChNames.indexOf(chName);
597}
598
599//=============================================================================================================
600
602{
603 return m_pFiffInfo->bads;
604}
605
606//=============================================================================================================
607
609{
610 //Map channels to layout
611 QList<FiffChInfo> channelList = m_pFiffInfo->chs;
612 for(int i = 0; i<channelList.size(); i++) {
613 //Get current channel information
614 FiffChInfo chInfo = channelList.at(i);
615 QString chName = chInfo.ch_name;
616 QRegularExpression regExpRemove;
617 bool flagOk = false;
618
619 switch(chInfo.kind) {
620 case FIFFV_MEG_CH:
621 //Scan for MEG string and other characters
622 regExpRemove = QRegularExpression("(MEG|-|_|/|\\| )");
623 chName.remove(regExpRemove);
624
625 //After cleaning the string try to convert the residual to an int number
626 flagOk = false;
627 m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("MEG").arg(chName));
628
629 break;
630
631 case FIFFV_EEG_CH: {
632 //Scan for EEG string and other characters
633 regExpRemove = QRegularExpression("(EEG|-|_|/|\\| )");
634 chName.remove(regExpRemove);
635
636 //After cleaning the string try to convert the residual to an int number
637 flagOk = false;
638 m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("EEG").arg(chName));
639
640 break;
641 }
642 }
643 } //end fiff chs
644
646}
647
648//=============================================================================================================
649
651{
652 beginResetModel();
653
655 m_layoutMap.clear();
656 m_aliasNames.clear();
657 m_mappedLayoutChNames.clear();
658
659 endResetModel();
660
661 qDebug("ChannelInfoModel cleared.");
662}
QAbstractTableModel exposing per-channel FIFF metadata (name, type, unit, position,...
Light-weight wrapper describing one MNE pre-processing operator (FIR, SSP, compensation) inside a mod...
#define FIFFV_EEG_CH
#define FIFFV_MEG_CH
#define FIFF_UNIT_T
#define FIFF_UNIT_T_M
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
FIFF file I/O, in-memory data structures and high-level readers/writers.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
void channelsMappedToLayout(const QStringList &mappedLayoutChNames)
ChannelInfoModel(QSharedPointer< FIFFLIB::FiffInfo > &pFiffInfo, QObject *parent=0)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
void setFiffInfo(QSharedPointer< FIFFLIB::FiffInfo > &pFiffInfo)
void assignedOperatorsChanged(const QMultiMap< int, QSharedPointer< MNEOperator > > &assignedOperators)
QMultiMap< int, QSharedPointer< MNEOperator > > m_assignedOperators
virtual bool insertRows(int position, int span, const QModelIndex &parent=QModelIndex())
QSharedPointer< FIFFLIB::FiffInfo > m_pFiffInfo
QSharedPointer< ChannelInfoModel > SPtr
int getIndexFromMappedChName(QString chName)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void layoutChanged(const QMap< QString, QPointF > &layoutMap)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
int getIndexFromOrigChName(QString chName)
const QStringList & getMappedChannelsList()
QMap< QString, QPointF > m_layoutMap
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual bool removeRows(int position, int span, const QModelIndex &parent=QModelIndex())
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Per-channel FIFF descriptor: identifiers, kind, calibration, coil type, channel-frame coil position a...
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:88
QSharedPointer< FiffInfo > SPtr
Definition fiff_info.h:90