v2.0.0
Loading...
Searching...
No Matches
averagesceneitem.cpp
Go to the documentation of this file.
1//=============================================================================================================
35
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "averagesceneitem.h"
41#include "../scalingview.h"
42
43#include <fiff/fiff_types.h>
44
45//=============================================================================================================
46// QT INCLUDES
47//=============================================================================================================
48
49#include <QPainter>
50#include <QDebug>
51#include <QStaticText>
52
53//=============================================================================================================
54// EIGEN INCLUDES
55//=============================================================================================================
56
57//=============================================================================================================
58// USED NAMESPACES
59//=============================================================================================================
60
61using namespace DISPLIB;
62
63//=============================================================================================================
64// DEFINE MEMBER METHODS
65//=============================================================================================================
66
67AverageSceneItem::AverageSceneItem(const QString& channelName,
68 int channelNumber,
69 const QPointF &channelPosition,
70 int channelKind,
71 int channelUnit,
72 const QColor &color)
73: m_sChannelName(channelName)
74, m_iChannelNumber(channelNumber)
75, m_iChannelKind(channelKind)
76, m_iChannelUnit(channelUnit)
79, m_iMaxWidth(120)
80, m_iMaxHeigth(60)
81, m_bIsBad(false)
82, m_qpChannelPosition(channelPosition)
83, m_colorDefault(color)
84{
86}
87
88//=============================================================================================================
89
91{
92 return m_rectBoundingRect;
93}
94
95//=============================================================================================================
96
97void AverageSceneItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
98{
99 Q_UNUSED(event)
100 m_iFontTextSize = 6;
102}
103
104//=============================================================================================================
105
106void AverageSceneItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
107{
108 Q_UNUSED(event)
109 m_iFontTextSize = 3;
111}
112
113//=============================================================================================================
114
115void AverageSceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
116{
117 Q_UNUSED(option);
118 Q_UNUSED(widget);
119
120 painter->setRenderHint(QPainter::Antialiasing, true);
121
122 if(m_bIsBad) {
123 painter->setOpacity(0.20);
124 }
125
126// //Plot bounding rect / drawing region of this item
127// painter->drawRect(this->boundingRect());
128
129 //Plot stim time
130 painter->save();
131 paintStimLine(painter);
132 painter->restore();
133
134 //Plot average data
135 painter->save();
136 paintAveragePath(painter);
137 painter->restore();
138
139 // Plot channel name
140 QStaticText staticElectrodeName = QStaticText(m_sChannelName);
141 painter->save();
142 QPen pen;
143 pen.setColor(Qt::red);
144 pen.setWidthF(0);
145 pen.setCosmetic(true);
146
147 QFont f = painter->font();
148 f.setPointSizeF(m_iFontTextSize);
149 painter->setFont(f);
150
151 painter->setPen(pen);
152 painter->drawStaticText(boundingRect().x(), boundingRect().y() - m_iFontTextSize, staticElectrodeName);
153 painter->restore();
154
155 //Plot bounding rect
156// painter->save();
157// pen.setColor(Qt::red);
158// painter->setPen(pen);
159// painter->drawRect(this->boundingRect());
160// painter->restore();
161}
162
163//=============================================================================================================
164
166{
167 if(m_lAverageData.size() == 0)
168 return;
169
170 //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
171
173
174 //Plot averaged data
175 QRectF boundingRect = this->boundingRect();
176 double dScaleY = (boundingRect.height())/(2*fMaxValue);
177
178 //do for all currently stored evoked set data
179 for(int dataIndex = 0; dataIndex < m_lAverageData.size(); ++dataIndex) {
180 QString sAvrComment = m_lAverageData.at(dataIndex).first;
181
182 // Default to active when no activation map has been configured
183 if(!m_qMapAverageActivation.contains(sAvrComment) || m_qMapAverageActivation[sAvrComment]) {
184 const double* averageData = m_lAverageData.at(dataIndex).second.first;
185 int totalCols = m_lAverageData.at(dataIndex).second.second;
186 if(totalCols <= 0)
187 continue;
188
189 //Calculate X step to fill the full bounding rect width
190 double xStep = boundingRect.width() / static_cast<double>(totalCols);
191
192 //Create path starting at the left-center of the bounding rect
193 double centerY = boundingRect.y() + boundingRect.height() / 2.0;
194 QPainterPath path(QPointF(boundingRect.x(), centerY));
195 QPen pen;
196 pen.setStyle(Qt::SolidLine);
197 pen.setColor(m_colorDefault);
198
199 if(m_qMapAverageColor.contains(sAvrComment)) {
200 pen.setColor(m_qMapAverageColor[sAvrComment]);
201 }
202
203 pen.setWidthF(0);
204 pen.setCosmetic(true);
205 painter->setPen(pen);
206
207 for(int i = 0; i < totalCols; ++i) {
208 //evoked matrix is stored in column major
209 double val = (*(averageData + (i * m_iTotalNumberChannels) + m_iChannelNumber)) * dScaleY;
210
211 //Clamp to bounding rect height
212 double halfH = boundingRect.height() / 2.0;
213 if(val > halfH) val = halfH;
214 else if(val < -halfH) val = -halfH;
215
216 double xPos = boundingRect.x() + i * xStep;
217 path.lineTo(QPointF(xPos, centerY - val));
218 }
219
220 painter->drawPath(path);
221 }
222 }
223}
224
225//=============================================================================================================
226
227void AverageSceneItem::paintStimLine(QPainter *painter)
228{
229 if(m_lAverageData.size() == 0)
230 return;
231
232 //Plot vertical and horizontal lines
233 QRectF boundingRect = this->boundingRect();
234 int totalCols = m_lAverageData.first().second.second;
235 if(totalCols <= 0)
236 return;
237
238 double xStep = boundingRect.width() / static_cast<double>(totalCols);
239
240 QPen pen;
241 pen.setStyle(Qt::SolidLine);
242 pen.setColor(Qt::red);
243 pen.setWidthF(0);
244 pen.setCosmetic(true);
245 painter->setPen(pen);
246
247 QPainterPath path;
248
249 //Stim line (at sample index corresponding to time=0)
250 double stimX = boundingRect.x() + std::abs(m_firstLastSample.first) * xStep;
251 path.moveTo(stimX, boundingRect.y());
252 path.lineTo(stimX, boundingRect.y() + boundingRect.height());
253
254 //Zero line
255 double centerY = boundingRect.y() + boundingRect.height() / 2.0;
256 path.moveTo(boundingRect.x(), centerY);
257 path.lineTo(boundingRect.x() + boundingRect.width(), centerY);
258
259 painter->drawPath(path);
260}
261
262//=============================================================================================================
263
264void AverageSceneItem::setDefaultColor(const QColor &viewColor)
265{
266 m_colorDefault = viewColor;
267}
268
269//=============================================================================================================
Contains the declaration of the AverageSceneItem class.
Declaration of the ScalingView Class.
Old fiff_type declarations - replace them.
2-D display widgets and visualisation helpers (charts, topography, colour maps).
float getScalingValue(const QMap< qint32, float > &qMapChScaling, int iChannelKind, int iChannelUnit)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void mousePressEvent(QGraphicsSceneMouseEvent *event)
void paintStimLine(QPainter *painter)
QList< QPair< QString, RowVectorPair > > m_lAverageData
QMap< qint32, float > m_scaleMap
void paintAveragePath(QPainter *painter)
QPair< int, int > m_firstLastSample
AverageSceneItem(const QString &channelName, int channelNumber, const QPointF &channelPosition, int channelKind, int channelUnit, const QColor &color=Qt::yellow)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QMap< QString, bool > m_qMapAverageActivation
void setDefaultColor(const QColor &viewColor)
QMap< QString, QColor > m_qMapAverageColor