v2.0.0
Loading...
Searching...
No Matches
averagesceneitem.cpp
Go to the documentation of this file.
1//=============================================================================================================
16
17//=============================================================================================================
18// INCLUDES
19//=============================================================================================================
20
21#include "averagesceneitem.h"
22#include "../scalingview.h"
23
24#include <fiff/fiff_types.h>
25
26//=============================================================================================================
27// QT INCLUDES
28//=============================================================================================================
29
30#include <QPainter>
31#include <QDebug>
32#include <QStaticText>
33
34//=============================================================================================================
35// EIGEN INCLUDES
36//=============================================================================================================
37
38//=============================================================================================================
39// USED NAMESPACES
40//=============================================================================================================
41
42using namespace DISPLIB;
43
44//=============================================================================================================
45// DEFINE MEMBER METHODS
46//=============================================================================================================
47
48AverageSceneItem::AverageSceneItem(const QString& channelName,
49 int channelNumber,
50 const QPointF &channelPosition,
51 int channelKind,
52 int channelUnit,
53 const QColor &color)
54: m_sChannelName(channelName)
55, m_iChannelNumber(channelNumber)
56, m_iChannelKind(channelKind)
57, m_iChannelUnit(channelUnit)
60, m_iMaxWidth(120)
61, m_iMaxHeigth(60)
62, m_bIsBad(false)
63, m_qpChannelPosition(channelPosition)
64, m_colorDefault(color)
65{
67}
68
69//=============================================================================================================
70
72{
73 return m_rectBoundingRect;
74}
75
76//=============================================================================================================
77
78void AverageSceneItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
79{
80 Q_UNUSED(event)
83}
84
85//=============================================================================================================
86
87void AverageSceneItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
88{
89 Q_UNUSED(event)
92}
93
94//=============================================================================================================
95
96void AverageSceneItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
97{
98 Q_UNUSED(option);
99 Q_UNUSED(widget);
100
101 painter->setRenderHint(QPainter::Antialiasing, true);
102
103 if(m_bIsBad) {
104 painter->setOpacity(0.20);
105 }
106
107// //Plot bounding rect / drawing region of this item
108// painter->drawRect(this->boundingRect());
109
110 //Plot stim time
111 painter->save();
112 paintStimLine(painter);
113 painter->restore();
114
115 //Plot average data
116 painter->save();
117 paintAveragePath(painter);
118 painter->restore();
119
120 // Plot channel name
121 QStaticText staticElectrodeName = QStaticText(m_sChannelName);
122 painter->save();
123 QPen pen;
124 pen.setColor(Qt::red);
125 pen.setWidthF(0);
126 pen.setCosmetic(true);
127
128 QFont f = painter->font();
129 f.setPointSizeF(m_iFontTextSize);
130 painter->setFont(f);
131
132 painter->setPen(pen);
133 painter->drawStaticText(boundingRect().x(), boundingRect().y() - m_iFontTextSize, staticElectrodeName);
134 painter->restore();
135
136 //Plot bounding rect
137// painter->save();
138// pen.setColor(Qt::red);
139// painter->setPen(pen);
140// painter->drawRect(this->boundingRect());
141// painter->restore();
142}
143
144//=============================================================================================================
145
147{
148 if(m_lAverageData.size() == 0)
149 return;
150
151 //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
152
154
155 //Plot averaged data
156 QRectF boundingRect = this->boundingRect();
157 double dScaleY = (boundingRect.height())/(2*fMaxValue);
158
159 //do for all currently stored evoked set data
160 for(int dataIndex = 0; dataIndex < m_lAverageData.size(); ++dataIndex) {
161 QString sAvrComment = m_lAverageData.at(dataIndex).first;
162
163 // Default to active when no activation map has been configured
164 if(!m_qMapAverageActivation.contains(sAvrComment) || m_qMapAverageActivation[sAvrComment]) {
165 const double* averageData = m_lAverageData.at(dataIndex).second.first;
166 int totalCols = m_lAverageData.at(dataIndex).second.second;
167 if(totalCols <= 0)
168 continue;
169
170 //Calculate X step to fill the full bounding rect width
171 double xStep = boundingRect.width() / static_cast<double>(totalCols);
172
173 //Create path starting at the left-center of the bounding rect
174 double centerY = boundingRect.y() + boundingRect.height() / 2.0;
175 QPainterPath path(QPointF(boundingRect.x(), centerY));
176 QPen pen;
177 pen.setStyle(Qt::SolidLine);
178 pen.setColor(m_colorDefault);
179
180 if(m_qMapAverageColor.contains(sAvrComment)) {
181 pen.setColor(m_qMapAverageColor[sAvrComment]);
182 }
183
184 pen.setWidthF(0);
185 pen.setCosmetic(true);
186 painter->setPen(pen);
187
188 for(int i = 0; i < totalCols; ++i) {
189 //evoked matrix is stored in column major
190 double val = (*(averageData + (i * m_iTotalNumberChannels) + m_iChannelNumber)) * dScaleY;
191
192 //Clamp to bounding rect height
193 double halfH = boundingRect.height() / 2.0;
194 if(val > halfH) val = halfH;
195 else if(val < -halfH) val = -halfH;
196
197 double xPos = boundingRect.x() + i * xStep;
198 path.lineTo(QPointF(xPos, centerY - val));
199 }
200
201 painter->drawPath(path);
202 }
203 }
204}
205
206//=============================================================================================================
207
208void AverageSceneItem::paintStimLine(QPainter *painter)
209{
210 if(m_lAverageData.size() == 0)
211 return;
212
213 //Plot vertical and horizontal lines
214 QRectF boundingRect = this->boundingRect();
215 int totalCols = m_lAverageData.first().second.second;
216 if(totalCols <= 0)
217 return;
218
219 double xStep = boundingRect.width() / static_cast<double>(totalCols);
220
221 QPen pen;
222 pen.setStyle(Qt::SolidLine);
223 pen.setColor(Qt::red);
224 pen.setWidthF(0);
225 pen.setCosmetic(true);
226 painter->setPen(pen);
227
228 QPainterPath path;
229
230 //Stim line (at sample index corresponding to time=0)
231 double stimX = boundingRect.x() + std::abs(m_firstLastSample.first) * xStep;
232 path.moveTo(stimX, boundingRect.y());
233 path.lineTo(stimX, boundingRect.y() + boundingRect.height());
234
235 //Zero line
236 double centerY = boundingRect.y() + boundingRect.height() / 2.0;
237 path.moveTo(boundingRect.x(), centerY);
238 path.lineTo(boundingRect.x() + boundingRect.width(), centerY);
239
240 painter->drawPath(path);
241}
242
243//=============================================================================================================
244
245void AverageSceneItem::setDefaultColor(const QColor &viewColor)
246{
247 m_colorDefault = viewColor;
248}
249
250//=============================================================================================================
Per-modality vertical-scale spinbox panel (one spin per channel type).
QGraphicsObject painting one channel's averaged evoked trace at its sensor position.
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
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