I haven't tested how well Qwt will perform in this case.
If you want to try Qwt here's simple example how to use it:
#include "mainwindow.h"
#include <QTime>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
MainWindow
::MainWindow(QWidget *parent
){
plot->setAutoReplot(false);
qsrand
(QTime::currentTime().
msec());
int count = 100;
for(int i = 0; i < count; ++i)
{
QPointF start
(qrand
()%300, qrand
()%300
);
poly << start;
poly <<
QPointF(qrand
()%300, qrand
()%300
);
poly <<
QPointF(qrand
()%300, qrand
()%300
);
poly << start;
c->setData(poly);
c->attach(plot);
}
this->setCentralWidget(plot);
}
#include "mainwindow.h"
#include <QTime>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QwtPlot* plot = new QwtPlot(this);
plot->setAutoReplot(false);
qsrand(QTime::currentTime().msec());
int count = 100;
for(int i = 0; i < count; ++i)
{
QPointF start(qrand()%300, qrand()%300);
QPolygonF poly;
poly << start;
poly << QPointF(qrand()%300, qrand()%300);
poly << QPointF(qrand()%300, qrand()%300);
poly << start;
QwtPlotCurve* c = new QwtPlotCurve();
c->setData(poly);
c->attach(plot);
}
this->setCentralWidget(plot);
}
To copy to clipboard, switch view to plain text mode
But you may need to do some optimization for 1M triangles to get acceptable performance.
Here's how I've done the paint event test:
//testcanvas.h
#ifndef TESTCANVAS_H
#define TESTCANVAS_H
#include <QWidget>
{
Q_OBJECT
public:
explicit testcanvas
(QWidget *parent
= 0);
protected:
private:
QList<QPolygon> poly_list;
};
#endif // TESTCANVAS_H
//testcanvas.h
#ifndef TESTCANVAS_H
#define TESTCANVAS_H
#include <QWidget>
class testcanvas : public QWidget
{
Q_OBJECT
public:
explicit testcanvas(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *);
private:
QList<QPolygon> poly_list;
};
#endif // TESTCANVAS_H
To copy to clipboard, switch view to plain text mode
//testcanvas.cpp
#include "testcanvas.h"
#include <QTime>
#include <QDebug>
#include <QPainter>
testcanvas
::testcanvas(QWidget *parent
) : poly_list( QList<QPolygon>() )
{
this->setMinimumSize(500, 500);
int count = 1000000;
qsrand
(QTime::currentTime().
msec());
t.start();
for(int i = 0; i < count; ++i)
{
poly.
append(QPoint(qrand
()%500, qrand
()%500
));
poly.
append(QPoint(qrand
()%500, qrand
()%500
));
poly.
append(QPoint(qrand
()%500, qrand
()%500
));
poly_list.append(poly);
}
qDebug() << "Generating " << count << " polys took " << t.elapsed() << "ms.";
}
{
p.fillRect(this->rect(), Qt::green);
t.start();
int count = poly_list.size();
for(int i = 0; i < count; ++i)
{
p.drawPolygon(poly_list[i]);
}
qDebug() << "Drawing " << count << " polys took " << t.elapsed() << "ms.";
}
//testcanvas.cpp
#include "testcanvas.h"
#include <QTime>
#include <QDebug>
#include <QPainter>
testcanvas::testcanvas(QWidget *parent) :
QWidget(parent),
poly_list( QList<QPolygon>() )
{
this->setMinimumSize(500, 500);
int count = 1000000;
qsrand(QTime::currentTime().msec());
QTime t;
t.start();
for(int i = 0; i < count; ++i)
{
QPolygon poly;
poly.append(QPoint(qrand()%500, qrand()%500));
poly.append(QPoint(qrand()%500, qrand()%500));
poly.append(QPoint(qrand()%500, qrand()%500));
poly_list.append(poly);
}
qDebug() << "Generating " << count << " polys took " << t.elapsed() << "ms.";
}
void testcanvas::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(this->rect(), Qt::green);
QTime t;
t.start();
int count = poly_list.size();
for(int i = 0; i < count; ++i)
{
p.drawPolygon(poly_list[i]);
}
qDebug() << "Drawing " << count << " polys took " << t.elapsed() << "ms.";
}
To copy to clipboard, switch view to plain text mode
//mainwindow.cpp
#include "mainwindow.h"
#include "testcanvas.h"
MainWindow
::MainWindow(QWidget *parent
){
this->setCentralWidget(new testcanvas());
}
//mainwindow.cpp
#include "mainwindow.h"
#include "testcanvas.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->setCentralWidget(new testcanvas());
}
To copy to clipboard, switch view to plain text mode
Generating 1000000 polys took 842 ms.
Drawing 1000000 polys took 26380 ms.
Memory footprint ~87MB
Generating 1000000 polys took 842 ms.
Drawing 1000000 polys took 26380 ms.
Memory footprint ~87MB
To copy to clipboard, switch view to plain text mode
Bookmarks