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