Commit 5667766d authored by Oliver Bock's avatar Oliver Bock
Browse files

Fix performance regression: increased efficiency for data passing and plotting (one loop call only)

parent 5f3c4985
......@@ -27,11 +27,13 @@ QT += core \
HEADERS += src/pulsaranimationwidget.h \
src/pulsescopewidget.h \
src/pulsatingscience.h \
src/common.h
src/common.h \
src/plotdata.h
SOURCES += src/pulsaranimationwidget.cpp \
src/pulsescopewidget.cpp \
src/pulsatingscience.cpp \
src/main.cpp
src/main.cpp \
src/plotdata.cpp
FORMS += src/pulsatingscience.ui
RESOURCES += src/pulsatingscience.qrc
TS_DIR = src/resources
......
#include "plotdata.h"
PlotData::PlotData() :
m_dataLHO(360*PERIODS, 0.0),
m_dataLLO(360*PERIODS, 0.0),
m_dataVirgo(360*PERIODS, 0.0)
{
m_colorLHO = "blue";
m_colorLLO = "red";
m_colorVirgo = "green";
}
#ifndef PLOTDATA_H
#define PLOTDATA_H
#include <QObject>
#include <QVector>
#include <QString>
#include "common.h"
class PlotData : public QObject
{
Q_OBJECT
public:
PlotData();
// let's make these private and add getters/setters later :-p
QVector<double> m_dataLHO;
QVector<double> m_dataLLO;
QVector<double> m_dataVirgo;
double m_AmpLHO;
double m_AmpLLO;
double m_AmpVirgo;
double m_phiLHO;
double m_phiLLO;
double m_phiVirgo;
double m_dtLHO;
double m_dtLLO;
double m_dtVirgo;
QString m_colorLHO;
QString m_colorLLO;
QString m_colorVirgo;
};
#endif // PLOTDATA_H
......@@ -23,10 +23,7 @@
const double PulsarAnimationWidget::deg2rad = PI/180.0;
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers), parent),
m_curveLHO(360*PERIODS, 0.0),
m_curveLLO(360*PERIODS, 0.0),
m_curveVirgo(360*PERIODS, 0.0)
QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers), parent)
{
QString msgThis = tr("3D animation");
if(!format().directRendering()) {
......@@ -571,11 +568,11 @@ void PulsarAnimationWidget::resetCameraPosition(const double angleH, const doubl
void PulsarAnimationWidget::updatePulseProfile()
{
for(int x = 0; x < 360*PERIODS; ++x) {
m_curveLHO[x] = 2.960124 * sin(x*deg2rad) + -0.494787 * cos(x*deg2rad);
m_curveLLO[x] = -3.533299 * sin(x*deg2rad) + -0.414445 * cos(x*deg2rad);
m_curveVirgo[x] = -0.984298 * sin(x*deg2rad) + 0.695593 * cos(x*deg2rad);
m_plotData.m_dataLHO[x] = 2.960124 * sin(x*deg2rad) + -0.494787 * cos(x*deg2rad);
m_plotData.m_dataLLO[x] = -3.533299 * sin(x*deg2rad) + -0.414445 * cos(x*deg2rad);
m_plotData.m_dataVirgo[x] = -0.984298 * sin(x*deg2rad) + 0.695593 * cos(x*deg2rad);
}
// propagate new profile
emit pulseProfileUpdated(m_curveLHO, m_curveLLO, m_curveVirgo);
emit pulseProfileUpdated(m_plotData);
}
......@@ -35,6 +35,7 @@
#endif
#include "common.h"
#include "plotdata.h"
#define PI 3.14159265
......@@ -55,7 +56,7 @@ public:
void resetCameraPosition(const double angleH, const double angleV, const double zoom);
signals:
void pulseProfileUpdated(const QVector<double>& dataLHO, const QVector<double>& dataLLO, const QVector<double>& dataVirgo);
void pulseProfileUpdated(const PlotData& data);
private:
void initializeGL();
......@@ -90,6 +91,8 @@ private:
double m_sourceIota;
double m_sourceInclination;
PlotData m_plotData;
bool m_cameraInteraction;
int m_mouseLastX;
......@@ -103,10 +106,6 @@ private:
double m_cameraPosY;
double m_cameraPosZ;
QVector<double> m_curveLHO;
QVector<double> m_curveLLO;
QVector<double> m_curveVirgo;
static const double deg2rad;
};
......
......@@ -19,6 +19,8 @@
******************************************************************************/
#include "pulsatingscience.h"
#include "plotdata.h"
#include <QSettings>
......@@ -58,8 +60,8 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
m_hiddenShortcut = new QShortcut(QKeySequence(Qt::SHIFT + Qt::ALT + Qt::Key_D), this);
// establish object communications
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<double>&, const QVector<double>&, const QVector<double>&)),
ui.pulseScopeWidget, SLOT(plot(const QVector<double>&, const QVector<double>&, const QVector<double>&)), Qt::DirectConnection);
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const PlotData&)),
ui.pulseScopeWidget, SLOT(plot(const PlotData&)));
connect(m_hiddenShortcut, SIGNAL(activated()),
this, SLOT(toggleHiddenDemoMode()));
......
......@@ -77,24 +77,25 @@ void PulseScopeWidget::resizeEvent(QResizeEvent *event)
fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
}
void PulseScopeWidget::plot(const QVector<double>& dataLHO, const QVector<double>& dataLLO, const QVector<double>& dataVirgo)
void PulseScopeWidget::plot(const PlotData& data)
{
drawCurve(m_pathLHO, dataLHO, "blue");
drawCurve(m_pathLLO, dataLLO, "red");
drawCurve(m_pathVirgo, dataVirgo, "green");
}
QPainterPath pulsePathLHO(QPointF(0.0, m_scopeSizeV - data.m_dataLHO.at(0) - m_scopeSizeV/2.0));
QPainterPath pulsePathLLO(QPointF(0.0, m_scopeSizeV - data.m_dataLLO.at(0) - m_scopeSizeV/2.0));
QPainterPath pulsePathVirgo(QPointF(0.0, m_scopeSizeV - data.m_dataVirgo.at(0) - m_scopeSizeV/2.0));
void PulseScopeWidget::drawCurve(QGraphicsPathItem* path, const QVector<double>& vector, QString color)
{
QPainterPath pulsePath(QPointF(0.0, m_scopeSizeV - vector.at(0) - m_scopeSizeV/2.0));
for(int i = 1; i < m_scopeSizeH; ++i) {
pulsePath.lineTo(i, m_scopeSizeV - vector.at(i) - m_scopeSizeV/2.0);
pulsePathLHO.lineTo(i, m_scopeSizeV - data.m_dataLHO.at(i) - m_scopeSizeV/2.0);
pulsePathLLO.lineTo(i, m_scopeSizeV - data.m_dataLLO.at(i) - m_scopeSizeV/2.0);
pulsePathVirgo.lineTo(i, m_scopeSizeV - data.m_dataVirgo.at(i) - m_scopeSizeV/2.0);
}
if(path == NULL) {
path = m_scene.addPath(pulsePath, QPen(QColor(color)));
if(m_pathLHO == NULL) {
m_pathLHO = m_scene.addPath(pulsePathLHO, QPen(data.m_colorLHO));
m_pathLLO = m_scene.addPath(pulsePathLLO, QPen(data.m_colorLLO));
m_pathVirgo = m_scene.addPath(pulsePathVirgo, QPen(data.m_colorVirgo));
}
else {
path->setPen(QPen(QColor(color)));
path->setPath(pulsePath);
m_pathLHO->setPath(pulsePathLHO);
m_pathLLO->setPath(pulsePathLLO);
m_pathVirgo->setPath(pulsePathVirgo);
}
}
......@@ -31,6 +31,7 @@
#include <QDebug>
#include "common.h"
#include "plotdata.h"
class PulseScopeWidget : public QGraphicsView
{
......@@ -43,11 +44,9 @@ public:
void resizeEvent(QResizeEvent *event);
public slots:
void plot(const QVector<double>& dataLHO, const QVector<double>& dataLLO, const QVector<double>& dataVirgo);
void plot(const PlotData& data);
private:
void drawCurve(QGraphicsPathItem* path, const QVector<double>& vector, QString color);
QGraphicsScene m_scene;
QVector<double> m_data;
QGraphicsPathItem *m_pathZero;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment