mardi 30 décembre 2014

QWT performance improvement for plot

I have a 2D dataset X, Y and an intensity value (but with some points missing). The data is stored in a sqlite database as X, Y, and Z for each row. I have about 1.5M rows for each plot. X range is about 4000pts wide and Y is about 1800 pts wide. So only approx 20% of the points in the plot actually have a specified value, the rest are initialized to a minimum value. Even less will be "visible" based on typical colorbar scale ranges (specified by user).


I am using QwtPlotSpectrogram to get the output I want. It takes a while to perform the SQL queries. Then it takes quite a while to do the plot. I'm looking for recommendations on how to improve the performance, especially on the plotting.


I've attached an excerpt of the code showing me pulling the data from the database then drawing the plot. I did some modifications so the code shown is more concise without pasting me entire program. Hope it makes sense.



QSqlQuery query(tsd_data);
int pl=plot_number;
query.exec("SELECT max(x), min(x), max(z), min(z) FROM database.plot_data WHERE pl="+QString::number(pl));
query.next();
int max_x = query.value(0).toInt();
int min_x = query.value(1).toInt();
int max_z = query.value(2).toInt();
int min_z = query.value(3).toInt();
int x_count = max_x-min_x;
QVector<double> dr_data(x_count*(y_count+1),-200);

query.exec("SELECT y, x, z FROM database.plot_data WHERE pl="+QString::number(pl));
while (query.next())
{
int y = query.value(0).toInt();
int x = query.value(1).toInt();
dr_data[y*x_count+(x-min_x)] = query.value(2).toDouble();
}

QwtMatrixRasterData *qwtm = new QwtMatrixRasterData();
qwtm->setInterval( Qt::XAxis, QwtInterval( min_x-zero, max_x-zero ) );
qwtm->setInterval( Qt::YAxis, QwtInterval( 0, 1800) );
qwtm->setInterval( Qt::ZAxis, QwtInterval( min_z, max_z ) );
qwtm->setValueMatrix(dr_data,bin_count);
QwtPlotSpectrogram *spec = new QwtPlotSpectrogram();
spec->setRenderThreadCount( 0 ); // use system specific thread count
spec->setCachePolicy( QwtPlotRasterItem::PaintCache );
QwtLinearColorMap *colormap = new QwtLinearColorMap(Qt::black, Qt::white);
colormap->addColorStop(0.1,Qt::blue);
colormap->addColorStop(.3,Qt::cyan);
colormap->addColorStop(.5,Qt::green);
colormap->addColorStop(.7,Qt::yellow);
colormap->addColorStop(.9,Qt::red);
spec->setColorMap(colormap);
spec->setData(qwtm);
spec->setDisplayMode( QwtPlotSpectrogram::ImageMode, true );
ui->dr_plot->setEnabled(true);
ui->dr_scale->setEnabled(true);
ui->dr_scale->setColorBarEnabled(true);
ui->dr_scale->setColorBarWidth(40);
QwtInterval zInterval = spec->data()->interval(Qt::ZAxis);
ui->dr_scale->setColorMap(zInterval,colormap);
spec->attach(ui->dr_plot);
ui->dr_plot->replot();

Aucun commentaire:

Enregistrer un commentaire