MNE-CPP  beta 1.0
averagesceneitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "averagesceneitem.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 AverageSceneItem::AverageSceneItem(QString channelName, int channelNumber, QPointF channelPosition, int channelKind, int channelUnit, QColor defaultColors)
60 : m_sChannelName(channelName)
61 , m_iChannelNumber(channelNumber)
62 , m_qpChannelPosition(channelPosition)
63 , m_iChannelKind(channelKind)
64 , m_iChannelUnit(channelUnit)
65 {
66  //Init m_scaleMap
67  m_scaleMap["MEG_grad"] = 400 * 1e-15 * 100; //*100 because data in fiff files is stored as fT/m not fT/cm
68  m_scaleMap["MEG_mag"] = 1.2 * 1e-12;
69  m_scaleMap["MEG_EEG"] = 30 * 1e-06;
70  m_scaleMap["MEG_EOG"] = 150 * 1e-06;
71  m_scaleMap["MEG_EMG"] = 1 * 1e-03;
72  m_scaleMap["MEG_ECG"] = 1 * 1e-03;
73  m_scaleMap["MEG_MISC"] = 1 * 1;
74  m_scaleMap["MEG_STIM"] = 5 * 1;
75 }
76 
77 
78 //*************************************************************************************************************
79 
81 {
82  int height = 80;
83  int width = 500;
84  return QRectF(-width/2, -height/2, width, height);
85 }
86 
87 
88 //*************************************************************************************************************
89 
90 void AverageSceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
91 {
92  Q_UNUSED(option);
93  Q_UNUSED(widget);
94 
95  //set posistion
96  this->setPos(60*m_qpChannelPosition.x(), -60*m_qpChannelPosition.y());
97 
98  // Plot channel name
99  QStaticText staticElectrodeName = QStaticText(m_sChannelName);
100  QSizeF sizeText = staticElectrodeName.size();
101  painter->drawStaticText(-15+((30-sizeText.width())/2), -32, staticElectrodeName);
102 
103 // //Plot bounding rect / drawing region of this item
104 // painter->drawRect(this->boundingRect());
105 
106  //Plot average data
107  painter->save();
108  paintAveragePath(painter);
109  painter->restore();
110 }
111 
112 
113 //*************************************************************************************************************
114 
115 void AverageSceneItem::paintAveragePath(QPainter *painter)
116 {
117  double dMaxValue = 1e-09;
118 
119  switch(m_iChannelKind) {
120  case FIFFV_MEG_CH: {
122  dMaxValue = m_scaleMap["MEG_grad"];
123  }
124  else if(m_iChannelUnit == FIFF_UNIT_T)
125  dMaxValue = m_scaleMap["MEG_mag"];
126  break;
127  }
128  case FIFFV_EEG_CH: {
129  dMaxValue = m_scaleMap["MEG_EEG"];
130  break;
131  }
132  case FIFFV_EOG_CH: {
133  dMaxValue = m_scaleMap["MEG_EOG"];
134  break;
135  }
136  case FIFFV_STIM_CH: {
137  dMaxValue = m_scaleMap["MEG_STIM"];
138  break;
139  }
140  case FIFFV_EMG_CH: {
141  dMaxValue = m_scaleMap["MEG_EMG"];
142  break;
143  }
144  case FIFFV_MISC_CH: {
145  dMaxValue = m_scaleMap["MEG_MISC"];
146  break;
147  }
148  }
149 
150  //Plot averaged data
151  QRectF boundingRect = this->boundingRect();
152  double dScaleY = (boundingRect.height()*10)/(2*dMaxValue);
153  QPointF qSamplePosition;
154 
155  //do for all currently stored evoked set data
156  for(int dataIndex = 0; dataIndex<m_lAverageData.size(); dataIndex++) {
157  //plot data from averaged data m_lAverageData with the calulacted downsample factor
158  const double* averageData = m_lAverageData.at(dataIndex).first;
159  int totalCols = m_lAverageData.at(dataIndex).second;
160 
161  //Calculate downsampling factor of averaged data in respect to the items width
162  int dsFactor;
163  totalCols / boundingRect.width()<1 ? dsFactor = 1 : dsFactor = totalCols / boundingRect.width();
164 
165  //Create path
166  QPainterPath path = QPainterPath(QPointF(boundingRect.x(), boundingRect.y() + boundingRect.height()/2));
167  QPen pen;
168  pen.setStyle(Qt::SolidLine);
169  if(!m_cAverageColors.isEmpty() && !(dataIndex<m_cAverageColors.size()))
170  pen.setColor(m_cAverageColors.at(dataIndex));
171  pen.setWidthF(2);
172  painter->setPen(pen);
173 
174  for(int i = 0; i < totalCols && path.elementCount() <= boundingRect.width(); i += dsFactor) {
175  //evoked matrix is stored in column major
176  double val = (*(averageData+(i*m_iTotalNumberChannels)+m_iChannelNumber) * dScaleY);
177 
178  qSamplePosition.setY(-val);
179  qSamplePosition.setX(path.currentPosition().x()+1);
180 
181  path.lineTo(qSamplePosition);
182  }
183 
184  painter->drawPath(path);
185  }
186 }
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
void paintAveragePath(QPainter *painter)
QList< RowVectorPair > m_lAverageData
AverageSceneItem(QString channelName, int channelNumber, QPointF channelPosition, int channelKind, int channelUnit, QColor defaultColors=Qt::red)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
#define FIFF_UNIT_T_M
QMap< QString, double > m_scaleMap
Contains the declaration of the AverageSceneItem class.