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
107 case 1:
108 return QString("%1").arg("Original name");
109
110 case 2:
111 return QString("%1").arg("Alias");
112
113 case 3:
114 return QString("%1").arg("Mapped layout name");
115
116 case 4:
117 return QString("%1").arg("Channel kind");
118
119 case 5:
120 return QString("%1").arg("MEG type");
121
122 case 6:
123 return QString("%1").arg("Unit");
124
125 case 7:
126 return QString("%1").arg("Position");
127
128 case 8:
129 return QString("%1").arg("Digitizer (cm)");
130
131 case 9:
132 return QString("%1").arg("Active filter");
133
134 case 10:
135 return QString("%1").arg("Coil Type");
136
137 case 11:
138 return QString("%1").arg("Bad channel");
139
140 case 12:
141 return QString("%1").arg("# of Compensators");
142 }
143 }
144 }
145 }
146
147 return QVariant();
148}
149
150//=============================================================================================================
151
152QVariant ChannelInfoModel::data(const QModelIndex& index, int role) const
153{
154 if (index.row() >= m_pFiffInfo->chs.size())
155 return QVariant();
156
157 if (index.isValid()) {
158 //******** first column (channel number - corresponds to row in fiff data matrix) ********
159 if (index.column() == 0) {
160 QVariant v;
161
162 switch (role) {
163 case Qt::DisplayRole:
164 v.setValue(index.row());
165 return v;
166
168 v.setValue(index.row());
169 return v;
170
171 case Qt::TextAlignmentRole:
172 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
173 return QVariant(a);
174 }
175 } //end column check
176
177 //******** second column (original channel name) ********
178 if (index.column() == 1) {
179 QVariant v;
180
181 switch (role) {
182 case Qt::DisplayRole:
183 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).ch_name));
184 return v;
185
187 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).ch_name));
188 return v;
189
190 case Qt::TextAlignmentRole:
191 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
192 return QVariant(a);
193 }
194 } //end column check
195
196 //******** third column (channel alias) ********
197 if (index.column() == 2) {
198 QVariant v;
199
200 switch (role) {
201 case Qt::DisplayRole:
202 if (index.row() < m_aliasNames.size())
203 v.setValue(QString("%1").arg(m_aliasNames.at(index.row())));
204 return v;
205
207 if (index.row() < m_aliasNames.size())
208 v.setValue(QString("%1").arg(m_aliasNames.at(index.row())));
209 return v;
210
211 case Qt::TextAlignmentRole:
212 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
213 return QVariant(a);
214 }
215 } //end column check
216
217 //******** fourth column (mapped layout channel name) ********
218 if (index.column() == 3) {
219 QVariant v;
220
221 switch (role) {
222 case Qt::DisplayRole:
223 if (index.row() < m_mappedLayoutChNames.size())
224 v.setValue(QString("%1").arg(m_mappedLayoutChNames.at(index.row())));
225 return v;
226
228 if (index.row() < m_mappedLayoutChNames.size())
229 v.setValue(QString("%1").arg(m_mappedLayoutChNames.at(index.row())));
230 return v;
231
232 case Qt::TextAlignmentRole:
233 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
234 return QVariant(a);
235 }
236 } //end column check
237
238 //******** fifth column (channel kind - MEG, EEG, etc) ********
239 if (index.column() == 4) {
240 QVariant v;
241
242 switch (role) {
243 case Qt::DisplayRole:
244 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).kind));
245 return v;
246
248 v.setValue(m_pFiffInfo->chs.at(index.row()).kind);
249 return v;
250
251 case Qt::TextAlignmentRole:
252 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
253 return QVariant(a);
254 }
255 } //end column check
256
257 //******** sixth column (MEG type) ********
258 if (index.column() == 5) {
259 QVariant v;
260
261 v.setValue(QString("%1").arg("non_MEG"));
262
263 if (m_pFiffInfo->chs.at(index.row()).kind == FIFFV_MEG_CH) {
264 qint32 unit = m_pFiffInfo->chs.at(index.row()).unit;
265 if (unit == FIFF_UNIT_T_M)
266 v.setValue(QString("MEG_grad"));
267 else if (unit == FIFF_UNIT_T)
268 v.setValue(QString("MEG_mag"));
269 }
270
271 switch (role) {
272 case Qt::DisplayRole:
273 return v;
274
276 return v;
277
278 case Qt::TextAlignmentRole:
279 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
280 return QVariant(a);
281 }
282 } //end column check
283
284 //******** seventh column (channel unit) ********
285 if (index.column() == 6) {
286 QVariant v;
287
288 switch (role) {
289 case Qt::DisplayRole:
290 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).unit));
291 return v;
292
294 v.setValue(m_pFiffInfo->chs.at(index.row()).unit);
295 return v;
296
297 case Qt::TextAlignmentRole:
298 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
299 return QVariant(a);
300 }
301 } //end column check
302
303 //******** eigth column (channel layout position) ********
304 if (index.column() == 7) {
305 QVariant v;
306
307 QPointF point = m_layoutMap[m_mappedLayoutChNames.at(index.row())];
308
309 switch (role) {
310 case Qt::DisplayRole:
311 v.setValue(QString("(%1|%2)").arg(point.x()).arg(point.y()));
312 return v;
313
315 v.setValue(point);
316 return v;
317
318 case Qt::TextAlignmentRole:
319 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
320 return QVariant(a);
321 }
322 } //end column check
323
324 //******** ninth column (channel digitizer position) ********
325 if (index.column() == 8) {
326 QVariant v;
327
328 QVector3D point3D(m_pFiffInfo->chs.at(index.row()).chpos.r0[0] * 100, //convert to cm
329 m_pFiffInfo->chs.at(index.row()).chpos.r0[1] * 100,
330 m_pFiffInfo->chs.at(index.row()).chpos.r0[2] * 100);
331
332 switch (role) {
333 case Qt::DisplayRole:
334 v.setValue(QString("(%1|%2|%3)").arg(point3D.x()).arg(point3D.y()).arg(point3D.z()));
335 return v;
336
338 v.setValue(point3D);
339 return v;
340
341 case Qt::TextAlignmentRole:
342 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
343 return QVariant(a);
344 }
345 } //end column check
346
347 //******** tenth column (active channel filter type) ********
348 if (index.column() == 9) {
349 QVariant v;
350
351 // //Check if mne operator is a filter operator
352 // QSharedPointer<MNEOperator> operatorPtr = m_assignedOperators.value(index.row(), QSharedPointer<MNEOperator>(new MNEOperator()));
353 // QSharedPointer<FilterOperator> filterOperator;
354
355 switch (role) {
356 case Qt::DisplayRole: {
357 return v;
358 }
359 // if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
360 // filterOperator = operatorPtr.staticCast<FilterOperator>();
361 // }
362 // else {
363 // v.setValue(QString("%1").arg("none"));
364 // return v;
365 // }
366
367 // switch(filterOperator->m_Type) {
368 // case FilterOperator::LPF: {
369 // v.setValue(QString("%1 | %2").arg("LP").arg(filterOperator->m_dCenterFreq*m_pFiffInfo->sfreq/2));
370 // return v;
371 // }
372
373 // case FilterOperator::HPF: {
374 // v.setValue(QString("%1 | %2").arg("HP").arg(filterOperator->m_dCenterFreq*m_pFiffInfo->sfreq/2));
375 // return v;
376 // }
377
378 // case FilterOperator::BPF: {
379 // double fsample = m_pFiffInfo->sfreq;
380 // 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
381 // double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
382 // v.setValue(QString("%1 | %2 | %3").arg("BP").arg(low).arg(high));
383 // return v;
384 // }
385
386 // case FilterOperator::NOTCH: {
387 // double fsample = m_pFiffInfo->sfreq;
388 // double low = (filterOperator->m_dCenterFreq*fsample/2) - (filterOperator->m_dBandwidth*fsample/4);
389 // double high = (filterOperator->m_dCenterFreq*fsample/2) + (filterOperator->m_dBandwidth*fsample/4);
390 // v.setValue(QString("%1 | %2 | %3").arg("NOTCH").arg(low).arg(high));
391 // return v;
392 // }
393 // }
394 // }
395
396 // case ChannelInfoModelRoles::GetChActiveFilter: {
397 // if(operatorPtr->m_OperatorType == MNEOperator::FILTER) {
398 // filterOperator = operatorPtr.staticCast<FilterOperator>();
399 // }
400 // else {
401 // v.setValue(QString("%1").arg("none"));
402 // return v;
403 // }
404
405 // v.setValue(operatorPtr);
406 // return v;
407 // }
408
409 case Qt::TextAlignmentRole:
410 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
411 return QVariant(a);
412 }
413 }
414
415 //******** eleventh column (coil type) ********
416 if (index.column() == 10) {
417 QVariant v;
418
419 switch (role) {
420 case Qt::DisplayRole:
421 v.setValue(QString("%1").arg(m_pFiffInfo->chs.at(index.row()).chpos.coil_type));
422 return v;
423
425 v.setValue(m_pFiffInfo->chs.at(index.row()).chpos.coil_type);
426 return v;
427
428 case Qt::TextAlignmentRole:
429 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
430 return QVariant(a);
431 }
432 } //end column check
433
434 //******** twelve column (channel bad) ********
435 if (index.column() == 11) {
436 QVariant v;
437 bool isBad = false;
438 QString chName = m_pFiffInfo->chs.at(index.row()).ch_name;
439
440 switch (role) {
441 case Qt::DisplayRole:
442 isBad = m_pFiffInfo->bads.contains(chName);
443 v.setValue(isBad);
444 return v;
445
447 isBad = m_pFiffInfo->bads.contains(chName);
448 v.setValue(isBad);
449 return v;
450
451 case Qt::TextAlignmentRole:
452 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
453 return QVariant(a);
454 }
455 } //end column check
456
457 //******** twelve column (compensators bad) ********
458 if (index.column() == 12) {
459 QVariant v;
460
461 switch (role) {
462 case Qt::DisplayRole:
463 v.setValue(m_pFiffInfo->comps.size());
464 return v;
465
466 case Qt::TextAlignmentRole:
467 Qt::Alignment a = Qt::AlignHCenter | Qt::AlignVCenter;
468 return QVariant(a);
469 }
470 } //end column check
471 } // end index.valid() check
472
473 return QVariant();
474}
475
476//=============================================================================================================
477
478bool ChannelInfoModel::insertRows(int position, int span, const QModelIndex& parent)
479{
480 Q_UNUSED(position);
481 Q_UNUSED(span);
482 Q_UNUSED(parent);
483
484 return true;
485}
486
487//=============================================================================================================
488
489bool ChannelInfoModel::removeRows(int position, int span, const QModelIndex& parent)
490{
491 Q_UNUSED(position);
492 Q_UNUSED(span);
493 Q_UNUSED(parent);
494
495 return true;
496}
497
498//=============================================================================================================
499
500Qt::ItemFlags ChannelInfoModel::flags(const QModelIndex& index) const
501{
502 Q_UNUSED(index);
503 return Qt::ItemIsEnabled | Qt::ItemIsSelectable /*| Qt::ItemIsEditable*/;
504}
505
506//=============================================================================================================
507
508bool ChannelInfoModel::setData(const QModelIndex& index, const QVariant& value, int role)
509{
510 Q_UNUSED(index);
511 Q_UNUSED(value);
512 Q_UNUSED(role);
513
514 return true;
515}
516
517//=============================================================================================================
518
520{
521 beginResetModel();
522
523 m_pFiffInfo = pFiffInfo;
524 m_aliasNames = m_pFiffInfo->ch_names;
526
528
529 endResetModel();
530
531 emit dataChanged(createIndex(0, 0), createIndex(rowCount(), columnCount()));
532}
533
534//=============================================================================================================
535
536void ChannelInfoModel::assignedOperatorsChanged(const QMultiMap<int, QSharedPointer<MNEOperator>>& assignedOperators)
537{
538 beginResetModel();
539
540 m_assignedOperators = assignedOperators;
541
542 endResetModel();
543
544 emit dataChanged(createIndex(0, 0), createIndex(rowCount(), columnCount()));
545}
546
547//=============================================================================================================
548
549void ChannelInfoModel::layoutChanged(const QMap<QString, QPointF>& layoutMap)
550{
551 beginResetModel();
552
553 m_layoutMap = layoutMap;
554 m_aliasNames = m_pFiffInfo->ch_names;
556
558
559 endResetModel();
560
561 emit dataChanged(createIndex(0, 0), createIndex(rowCount(), columnCount()));
562}
563
564//=============================================================================================================
565
567{
569}
570
571//=============================================================================================================
572
574{
575 return m_pFiffInfo->ch_names.indexOf(chName);
576}
577
578//=============================================================================================================
579
581{
582 return m_mappedLayoutChNames.indexOf(chName);
583}
584
585//=============================================================================================================
586
588{
589 return m_pFiffInfo->bads;
590}
591
592//=============================================================================================================
593
595{
596 //Map channels to layout
597 QList<FiffChInfo> channelList = m_pFiffInfo->chs;
598 for (int i = 0; i < channelList.size(); i++) {
599 //Get current channel information
600 FiffChInfo chInfo = channelList.at(i);
601 QString chName = chInfo.ch_name;
602 QRegularExpression regExpRemove;
603
604 switch (chInfo.kind) {
605 case FIFFV_MEG_CH:
606 //Scan for MEG string and other characters
607 regExpRemove = QRegularExpression("(MEG|-|_|/|\\| )");
608 chName.remove(regExpRemove);
609
610 //After cleaning the string try to convert the residual to an int number
611 m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("MEG").arg(chName));
612
613 break;
614
615 case FIFFV_EEG_CH: {
616 //Scan for EEG string and other characters
617 regExpRemove = QRegularExpression("(EEG|-|_|/|\\| )");
618 chName.remove(regExpRemove);
619
620 //After cleaning the string try to convert the residual to an int number
621 m_mappedLayoutChNames.replace(i, QString("%1 %2").arg("EEG").arg(chName));
622
623 break;
624 }
625 }
626 } //end fiff chs
627
629}
630
631//=============================================================================================================
632
634{
635 beginResetModel();
636
638 m_layoutMap.clear();
639 m_aliasNames.clear();
640 m_mappedLayoutChNames.clear();
641
642 endResetModel();
643
644 qDebug("ChannelInfoModel cleared.");
645}
#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...
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...
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)
QMultiMap< int, QSharedPointer< MNEOperator > > m_assignedOperators
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)
QMap< QString, QPointF > m_layoutMap
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()
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:90
QSharedPointer< FiffInfo > SPtr
Definition fiff_info.h:92