MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
plot.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "plot.h"
41
42//=============================================================================================================
43// QT INCLUDES
44//=============================================================================================================
45
46#include <QPoint>
47#include <QPainter>
48
49//=============================================================================================================
50// USED NAMESPACES
51//=============================================================================================================
52
53using namespace DISPLIB;
54using namespace Eigen;
55
56//=============================================================================================================
57// DEFINE MEMBER METHODS
58//=============================================================================================================
59
60Plot::Plot(QWidget *parent)
61: Graph(parent)
62, m_bHoldOn(false)
63{
64 init();
65}
66
67//=============================================================================================================
68
69Plot::Plot(VectorXd &p_dVec, QWidget *parent)
70: Graph(parent)
71, m_bHoldOn(false)
72{
73 init();
74 updateData(p_dVec);
75}
76
77//=============================================================================================================
78
80{
81}
82
83//=============================================================================================================
84
86{
87 //Parent init
89
91
92 m_dMinX = 0;
93 m_dMaxX = 0;
94 m_dMinY = 0;
95 m_dMaxY = 0;
96}
97
98//=============================================================================================================
99
100void Plot::updateData(VectorXd &p_dVec)
101{
102 if(p_dVec.size() > 0)
103 {
104 if(!m_bHoldOn)
105 init();
106
107 QVector<QPointF> t_qVecPointFPaths;
108 //No X data given
109 m_dMinX = 0 < m_dMinX ? 0 : m_dMinX;
110 m_dMaxX = p_dVec.size()-1 > m_dMaxX ? p_dVec.size()-1 : m_dMaxX;
111
112 m_dMinY = p_dVec.minCoeff() < m_dMinY ? p_dVec.minCoeff() : m_dMinY;
113 m_dMaxY = p_dVec.maxCoeff() > m_dMaxY ? p_dVec.maxCoeff() : m_dMaxY;
114
115 double t_dX = 0;
116 for(qint32 i = 0; i < p_dVec.size(); ++i)
117 {
118 t_qVecPointFPaths.append(QPointF(t_dX, p_dVec[i]));
119 t_dX += 1;
120 }
121
122 m_qListVecPointFPaths.append(t_qVecPointFPaths);
123
124 update();
125 }
126}
127
128//=============================================================================================================
129
130void Plot::paintEvent(QPaintEvent *event)
131{
132 Q_UNUSED(event);
133
134 QPainter painter(this);
135 if (m_qListVecPointFPaths.size() > 0)
136 {
137 QPoint t_qPointTopLeft(m_iBorderLeftRight,m_iBorderTopBottom);
138
139 QSize t_qSizePlot = m_qSizeWidget;
140
141 t_qSizePlot.setWidth(t_qSizePlot.width() - 2*m_iBorderLeftRight);
142 t_qSizePlot.setHeight(t_qSizePlot.height() - 2*m_iBorderTopBottom);
143
144 //Draw background
145 QPainter painter(this);
146 painter.fillRect(t_qPointTopLeft.x(), t_qPointTopLeft.y(), t_qSizePlot.width(), t_qSizePlot.height(), Qt::white);
147
148 //Draw border
149 painter.drawRect(t_qPointTopLeft.x()-1, t_qPointTopLeft.y()-1, t_qSizePlot.width()+1, t_qSizePlot.height()+1);
150
151 // -- Data --
152 painter.save();
153 QPen pen;
154 pen.setWidth(1);
155 pen.setBrush(Qt::blue);
156 painter.setPen(pen);
157 painter.translate(m_iBorderLeftRight-m_dMinX,m_iBorderTopBottom+t_qSizePlot.height()/2);
158 for(qint32 i = 0; i < m_qListVecPointFPaths.size(); ++i)
159 {
160 double scale_x = t_qSizePlot.width()/(m_dMaxX - m_dMinX);
161 double scale_y = (t_qSizePlot.height()-(t_qSizePlot.height()*0.1))/(m_dMaxY - m_dMinY);
162
163 //scale
164 QVector<QPointF> t_qVecPointFPath;
165 QVector<QPointF>::ConstIterator it;
166 for(it = m_qListVecPointFPaths[i].begin(); it != m_qListVecPointFPaths[i].end(); ++it)
167 t_qVecPointFPath.append(QPointF(it->x()*scale_x, it->y()*scale_y));
168
169 //draw
170 for(it = t_qVecPointFPath.begin()+1; it != t_qVecPointFPath.end(); ++it)
171 painter.drawLine(*(it-1), *it);
172 }
173 painter.restore();
174
175 //Draw title & axes
176 Graph::drawLabels(t_qSizePlot.width(), t_qSizePlot.height());
177 }
178}
179
Plot class declaration.
Base class for graphs.
Definition graph.h:81
void init()
Definition graph.cpp:72
QSize m_qSizeWidget
Definition graph.h:146
qint32 m_iBorderLeftRight
Definition graph.h:153
qint32 m_iBorderTopBottom
Definition graph.h:152
void drawLabels(qint32 p_iContentWidth, qint32 p_iContentHeight)
Definition graph.cpp:120
double m_dMaxY
Definition plot.h:138
double m_dMaxX
Definition plot.h:136
double m_dMinX
Definition plot.h:135
void init()
Definition plot.cpp:85
QList< QVector< QPointF > > m_qListVecPointFPaths
Definition plot.h:132
void updateData(Eigen::VectorXd &p_dVec)
Definition plot.cpp:100
void paintEvent(QPaintEvent *event)
Definition plot.cpp:130
double m_dMinY
Definition plot.h:137
bool m_bHoldOn
Definition plot.h:134
Plot(QWidget *parent=Q_NULLPTR)
Definition plot.cpp:60