Results 1 to 2 of 2

Thread: Efficient way of performing replot of almost identical plots

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Efficient way of performing replot of almost identical plots

    Hello!

    In one graph of one of my applications, I have a QwtPlot showing some curves while the X axis is visible and should be size-fixed. The plot data is shown coming at real time (once per second) from right to left, showing data correspondent to the lest 600 seconds.

    Once the 600 is full (and technically even before that, but lets simplify), the situation I have is a graph that is almost always the same, with the only difference that once per second the first point (left to right) is deleted/not shown anymore, the last point is a new one (i.e. the y is different) and all other plot data is simply shifted one point to the left.

    Now, in order to do this, I'm calling QwtPlot::replot(), which means that the QPixmap canvas is completely erased and repainted (i.e. recalculated) again despite the fact that 99% of it is simply the same as before, only shifted in one position. This not to mention the huge vector operation I need to do backwards with a for that shifts all the points one position and add the new one:

    Qt Code:
    1. void newPointDynamic(const re8k_ict_graphical_data& yValue)
    2. {
    3. const int calculationLimit = d_samples.size() - 1;
    4.  
    5. for (int aaa = 0; aaa < calculationLimit; aaa++)
    6. d_samples[aaa].setY(d_samples[aaa+1].ry());
    7.  
    8. d_samples.last().setY(yValue);
    9. }
    To copy to clipboard, switch view to plain text mode 

    As you may notice, quite a huge amount of calculation and recalculation. My first question is: isn't there a improved way of doing this thing? :T

    For instance I thought about using the BackingStore (i.e. cache) paint attribute, but I'm not sure it's actually improving anything (doing backtests in my circumstances is quite odd). After all, since technically speaking the canvas is totally different on each new replot, saving something in the cache this way would be fruitless (isn't that truth?).

    Another option, based on what I read somewhere else, would be to cache the part of the canvas I know that would be the same in the new replot (1 to 600) and then just paint it over the left-most side of the canvas (0 to 599). That would leave only one point at the right to be updated, what I could do by using a QwtPlot with a specific repaint area (as shown by Uwe here: http://www.qtcentre.org/threads/5910...tPlot-replot()). The problem is that I have no idea about how to do it :P Not to mention I'm not sure it would be such an improvement...


    Any suggestions or answers will be appreciated. Thanks!

    Momergil
    May the Lord be with you. Always.

  2. #2
    Join Date
    May 2013
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Efficient way of performing replot of almost identical plots

    I can't answer your first question, but I can give some recommendations on your data structures.

    You need to read up on data structures, and particularly the list of functions supplied by Qt for their containers. QList/QVector provide removeFirst() and append() which will do what you want. If you look at their algorithm complexities it might be as bad as O(n) (http://qt-project.org/doc/qt-5/conta...mic-complexity). For your case, however, a circular buffer would seem to suffice. You can implement this in an array or a circular list and overload QwtPlotCurve::drawCurve. You would keep an index of your most current point and start plotting from there. Insertion time in a circular buffer is O(1). If you use an array instead of a list you also get O(1) random access.

Similar Threads

  1. Replies: 9
    Last Post: 17th May 2015, 17:46
  2. Replies: 1
    Last Post: 14th May 2014, 08:57
  3. Replies: 4
    Last Post: 8th September 2013, 13:35
  4. Replies: 3
    Last Post: 8th April 2013, 08:06
  5. QDir entryList performing slowly
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2009, 17:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.