How to plot large time series with QCustomPlot efficiently?

眉间皱痕 提交于 2019-12-07 12:22:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27417703/how-to-plot-large-time-series-with-qcustomplot-efficiently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!