本文介绍了如何用QCustomPlot有效地绘制大的时间序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 QCustomPlot 在Qt中绘制数字信号,但似乎当样本数大于10000000时,操作变得非常慢。我有一个时间向量和数据向量,我设置的数据像这样:

  QCustomPlot * plot; 
QCPGraph * graph;
graph-> setData(time,data);任何机会使这更有效率?



QCPDataMap
(这是一个 typedef QMap< double,QCPData> )这意味着它正在使用一个映射来存储按 x (键)。不幸的是, QCPGraph :: setData(const QVector< double>& x,const QVector< double& y)< / code>方法不利用样本可以并且不使用插入提示,因此这显着改善了结果:

  QCPDataMap * data = new QCPDataMap(); 
size_t len = x.size();
auto xp = std :: begin(x);
auto yp = std :: begin(y);
while(len--)
data-> insertMulti(data-> constEnd(),* xp,QCPData(* xp ++,* yp ++));
graph-> setData(data);

我不认为 std :: map s或 QMap s是在X,Y图形上存储样本的最佳结构,因为对地图中的每个条目都进行了新的分配和释放,我们正在讨论数百万。 QCustomPlot应该实现一个自定义地图类与自定义分配器,以避免这些内存问题。


I am currently plotting a digital signal in Qt with QCustomPlot but it seems that when the number of samples is greater than 10000000 the operation becomes very slow. I have a time vector and a data vector and I'm setting the data like this:

QCustomPlot *plot;
QCPGraph *graph;
graph->setData(time, data);

Any chance to make this more efficient?

解决方案

Because QCustomPlot uses internally a QCPDataMap (which is a typedef of QMap<double, QCPData>) this means that it is using a map to store the actual data sorted by x coordinates (keys). Unfortunately the QCPGraph::setData(const QVector<double> &x, const QVector<double> &y) method doesn't take advantage of the fact that samples could be ordered and doesn't use the insertion hint, so this improved results significantly:

QCPDataMap *data = new QCPDataMap();
size_t len = x.size();
auto xp = std::begin(x);
auto yp = std::begin(y);
while (len--)
    data->insertMulti(data->constEnd(), *xp, QCPData(*xp++, *yp++));
graph->setData(data);

I don't think that std::maps or QMaps is the best structure to store samples on X,Y graphs because a new allocation and release is done for every entry in the map and we are talking about millions of them. QCustomPlot should implement a custom map class with a custom allocator to avoid these memory issues.

这篇关于如何用QCustomPlot有效地绘制大的时间序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:01