MNE-CPP  beta 1.0
butterflysceneitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "butterflysceneitem.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace MNEBrowseRawQt;
51 using namespace std;
52 
53 
54 //*************************************************************************************************************
55 //=============================================================================================================
56 // DEFINE MEMBER METHODS
57 //=============================================================================================================
58 
59 ButterflySceneItem::ButterflySceneItem(QString setName, int setKind, int setUnit, const QList<QColor> &defaultColors)
60 : m_sSetName(setName)
61 , m_iSetKind(setKind)
62 , m_iSetUnit(setUnit)
63 , m_cAverageColors(defaultColors)
64 {
65  //Init m_scaleMap
66  m_scaleMap["MEG_grad"] = 400 * 1e-15 * 100; //*100 because data in fiff files is stored as fT/m not fT/cm
67  m_scaleMap["MEG_mag"] = 1.2 * 1e-12;
68  m_scaleMap["MEG_EEG"] = 30 * 1e-06;
69  m_scaleMap["MEG_EOG"] = 150 * 1e-06;
70  m_scaleMap["MEG_EMG"] = 1 * 1e-03;
71  m_scaleMap["MEG_ECG"] = 1 * 1e-03;
72  m_scaleMap["MEG_MISC"] = 1 * 1;
73  m_scaleMap["MEG_STIM"] = 5 * 1;
74 }
75 
76 
77 //*************************************************************************************************************
78 
80 {
81  int height = 100;
82  int width = 500;
83  return QRectF(-width/2, -height/2, width, height);
84 }
85 
86 
87 //*************************************************************************************************************
88 
89 void ButterflySceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
90 {
91  Q_UNUSED(option);
92  Q_UNUSED(widget);
93 
94  //Plot bounding rect / drawing region of this item
95  //painter->drawRect(this->boundingRect());
96 
97  //Plot average data
98  painter->save();
99  paintAveragePaths(painter);
100  painter->restore();
101 }
102 
103 
104 //*************************************************************************************************************
105 
107 {
108  //Create path for all channels
109  for(int i = 0; i<m_pFiffInfo->chs.size() ;i++) {
110 
111  FiffChInfo fiffChInfoTemp = m_pFiffInfo->chs.at(i);
112 
113  if(m_pFiffInfo->bads.contains(fiffChInfoTemp.ch_name) == false) {
114  //Only plot EEG or MEG channels
115  if((fiffChInfoTemp.kind == FIFFV_MEG_CH && m_iSetKind == FIFFV_MEG_CH && fiffChInfoTemp.unit == FIFF_UNIT_T_M && m_iSetUnit == FIFF_UNIT_T_M) || //MEG grad
116  (fiffChInfoTemp.kind == FIFFV_MEG_CH && m_iSetKind == FIFFV_MEG_CH && fiffChInfoTemp.unit == FIFF_UNIT_T && m_iSetUnit == FIFF_UNIT_T) || //MEG mag
117  (fiffChInfoTemp.kind == FIFFV_EEG_CH && m_iSetKind == FIFFV_EEG_CH)) { //EEG
118  //Determine channel scaling
119  double dMaxValue = 1e-09;
120  switch(fiffChInfoTemp.kind) {
121  case FIFFV_MEG_CH: {
122  if(fiffChInfoTemp.unit == FIFF_UNIT_T_M) {
123  dMaxValue = m_scaleMap["MEG_grad"];
124  }
125  else if(fiffChInfoTemp.unit == FIFF_UNIT_T)
126  dMaxValue = m_scaleMap["MEG_mag"];
127  break;
128  }
129  case FIFFV_EEG_CH: {
130  dMaxValue = m_scaleMap["MEG_EEG"];
131  break;
132  }
133  }
134 
135  //Get data pointer for the current channel
136  const double* averageData = m_lAverageData.first;
137  int totalCols = m_lAverageData.second; //equals to the number of samples stored in the data matrix
138 
139  //Calculate downsampling factor of averaged data in respect to the items width
140  int dsFactor;
141  QRectF boundingRect = this->boundingRect();
142  totalCols / boundingRect.width()<1 ? dsFactor = 1 : dsFactor = totalCols / boundingRect.width();
143 
144  //Calculate scaling value
145  double dScaleY = (boundingRect.height())/(2*dMaxValue);
146 
147  //Setup the painter
148  QPainterPath path = QPainterPath(QPointF(boundingRect.x(), *(averageData+(0*m_pFiffInfo->chs.size())+i) * -dScaleY));
149  QPen pen;
150  pen.setStyle(Qt::SolidLine);
151  if(!m_cAverageColors.isEmpty() && i<m_cAverageColors.size())
152  pen.setColor(m_cAverageColors.at(i));
153  pen.setWidthF(0.25);
154  painter->setPen(pen);
155 
156  //Generate plot path
157  QPointF qSamplePosition;
158 
159  for(int u = 0; u < totalCols && path.elementCount() <= boundingRect.width(); u += dsFactor) {
160  //evoked matrix is stored in column major
161  double val = (*(averageData+(u*m_pFiffInfo->chs.size())+i) * dScaleY);
162 
163  qSamplePosition.setY(-val);
164  qSamplePosition.setX(path.currentPosition().x()+1);
165 
166  path.lineTo(qSamplePosition);
167  }
168 
169  //Paint the path
170  painter->drawPath(path);
171  }
172  }
173  }
174 }
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
ButterflySceneItem(QString setName, int setKind=FIFFV_MEG_CH, int setUnit=FIFF_UNIT_T_M, const QList< QColor > &defaultColors=QList< QColor >())
Contains the declaration of the ButterflySceneItem class.
#define FIFF_UNIT_T_M
Channel info descriptor.
Definition: fiff_ch_info.h:87
QList< FiffChInfo > chs
void paintAveragePaths(QPainter *painter)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)