Results 1 to 9 of 9

Thread: Speed of Qwt plotting slows with many points

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 Speed of Qwt plotting slows with many points

    Hello!

    I'm having a problem concerning the regularity of the speed in which points in a Qwt graph are being plotted, i.e. after some points, the speed decreases.

    My software contains a QTimer that is connecte through timeout() to a slot that reads the Y value to be plot in a QVector::front() and uses QwtPlotCurve::setData() and QwtPlot::replot() to plot it each timeout(). After reading the QVector, the first position is deleted.

    The problem is that the QVector is huge - at the end something like 90 000 Y-coordinates should be in it - and therefore the Qwt should plot a graf with 90 000 points, and this seems to be causing a delay in the speed of the plotting, so when it starts, the speed is OK and the QTimer seems to be firing in the correct speed, but when the size of the Qwt graph begins to grow significantly (that is over 13 000 - 15 000 points plotted, but more significantly after 18 000 - 20 000 points), the speed begins to slow a little bit and gradually, so when the 90 000 point arrives, the plotting speed is less than half of what is programmed.

    I and my friends imagine that this is maybe due to the internal buffer that Qwt possess that even allow me to stop the plotting and verify what has being plot - and I simply don't know if there is a function that allows to erase specific points in a QwtPlot; the only thing I know is QwtPlot::clear(), that doesn't work for this -. I think that the big size of this internal buffer is what is making the plotting "more difficult", i.e. more slow.

    So I have some questions related to this problem:

    1) Is truly the internal buffer what is creating the "slow" problem? yes or no, how could I solve this and force the plotting to occur always in the same speed - using the same functions that I use today?
    2) Is there any other way to plot the points in the graph without using the QwtPlotCurve::setData() function but that still produces the same type of graph? I imagine that if there is a function that can plot point by point instead of creating a line between points some of my problems would be solved; I could just erase the previous point after a pre-determined number of points have being plotted. That would disable the possibility to check back what was plotted, but at least would discard the buffer big size - if that is what is truly making this problem appears.


    Thanks very much,

    Momergil.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Speed of Qwt plotting slows with many points

    You didn't say which Qwt you're using and that's quite imrpotant.

    On Windows I've noticed significant difference between Qwt 6.x.x and 5.x.x where latter is faster.
    It was discussed on the forum.

    In the end I've managed to plot 5 milion points in less than 150ms.
    You can't rely on Qwt to do all the optimizations.
    In my case I'm 'compressing' my points to fit width of the screen and draw few hunderd lines instead of milions of points.
    No loss in details at all.

    Depending on your data you'll have to do something similar, otherwise the speed will degrade as Qwt draws every point every time you redraw, and you can't add/remove points without redrawing the whole thing.

    There's few other things you can try to improve speed:
    - polygon clipping,
    - use Qwt 5.x.x if you're using windows
    and few other things I can't remember at the moment :/

  3. #3
    Join Date
    Apr 2012
    Posts
    10
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Speed of Qwt plotting slows with many points

    Quote Originally Posted by Spitfire View Post
    You didn't say which Qwt you're using and that's quite imrpotant.

    On Windows I've noticed significant difference between Qwt 6.x.x and 5.x.x where latter is faster.
    It was discussed on the forum.

    In the end I've managed to plot 5 milion points in less than 150ms.
    You can't rely on Qwt to do all the optimizations.
    In my case I'm 'compressing' my points to fit width of the screen and draw few hunderd lines instead of milions of points.
    No loss in details at all.

    Depending on your data you'll have to do something similar, otherwise the speed will degrade as Qwt draws every point every time you redraw, and you can't add/remove points without redrawing the whole thing.

    There's few other things you can try to improve speed:
    - polygon clipping,
    - use Qwt 5.x.x if you're using windows
    and few other things I can't remember at the moment :/
    How could you compress millions of points to few hundred lines?
    could you tell me the data processing method?

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Speed of Qwt plotting slows with many points

    It's quite simple.

    Imagine you have 1M points and 1K pixels wide canvas (for sake of simplicity).
    You can't draw all 1M points, many of them will overlap in the same pixel.

    Divide amount of points you have by the width of the canvas (in pixels).
    In example above you'll end up with 1K points per canvas pixel (width-wise).
    All this 1K points can be represented using only two points as a single vertical line resulting in 98% compression.
    Just go through the points and record lowest and highest Y value, then create a line using those two values and X of the canvas pixel and you're done.
    Repeat it 1K times and you'll end up with 98% less data to draw.

    You have to do that every time data or canvas size changes. Also when you zoom in, you effectivley change the data available to draw so you have to recalculate.

  5. The following user says thank you to Spitfire for this useful post:

    Momergil (27th May 2014)

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Speed of Qwt plotting slows with many points

    The easiest way is to use QwtWeedingCurveFitter. It has to be used according to scale changes ( don't use QwtPlotCurve::setCurveFitter ). Depending on the tolerance parameter you can control the algorithm.

    Of course such an algorithm is for line plots and not very effective for scatter plots.

    Uwe

    PS: note that using Qwt from SVN trunk reintroduces several optimizations, that have been removed in Qwt 6.0. They should have a notable impact on the performance of a line plot with many, many points.

  7. The following user says thank you to Uwe for this useful post:

    Momergil (27th May 2014)

  8. #6
    Join Date
    Dec 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Speed of Qwt plotting slows with many points

    In my case it is not changing width of canvas.

    I check plot->canvas()->width(), but i am getting constant value.

    which parameter can i use for changing chunk size with respect to Zoom in and Zoom out?

    Quote Originally Posted by Spitfire View Post
    It's quite simple.

    Imagine you have 1M points and 1K pixels wide canvas (for sake of simplicity).
    You can't draw all 1M points, many of them will overlap in the same pixel.

    Divide amount of points you have by the width of the canvas (in pixels).
    In example above you'll end up with 1K points per canvas pixel (width-wise).
    All this 1K points can be represented using only two points as a single vertical line resulting in 98% compression.
    Just go through the points and record lowest and highest Y value, then create a line using those two values and X of the canvas pixel and you're done.
    Repeat it 1K times and you'll end up with 98% less data to draw.

    You have to do that every time data or canvas size changes. Also when you zoom in, you effectivley change the data available to draw so you have to recalculate.
    In my case it is not changing width of canvas.

    I check plot->canvas()->width(), but i am getting constant value.

    which parameter can i use for changing chunk size with respect to Zoom in and Zoom out?

  9. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Speed of Qwt plotting slows with many points

    Quote Originally Posted by Momergil View Post
    ... and I simply don't know if there is a function that allows to erase specific points in a QwtPlot;
    Just to have it clear for others reading the archive: you can't erase parts of a widget, all you can do is to repaint them. This is by design of Qt and has nothing to with Qwt. ( With Qt3 you were able to draw/erase with the XOR mode - but not with Qt4 anymore ).

    What you can do with Qwt is to paint new points/lines on top. But to make use of this you might have to design your plot widget like in the oscilloscope example. For a curve, where the points are shifted along an axis ( like in the cpuplot example ) you can't use this.

    Before complaining about performance issues always check the refreshtest example to see what is possible on your system. If you have high frame rates in this example ask yourself, what makes the difference to your application.

    Uwe

  10. The following user says thank you to Uwe for this useful post:

    deniska (28th November 2013)

  11. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Speed of Qwt plotting slows with many points

    Hmmm If i understood you correctly, you have a vector with lets say 50k points, but you want to plot only last 2k (or some other small part) and possibly scroll to any other part of the vector data, Similar to oscilloscope example but with keeping data off the screen, correct?

Similar Threads

  1. Replies: 4
    Last Post: 6th October 2010, 13:29
  2. QTcpSocket slows down in receiving after several minutes
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2009, 21:14
  3. rendering svg using QGraphicsSVGItem slows doen the performance
    By sanjayshelke in forum Qt Programming
    Replies: 4
    Last Post: 1st September 2009, 06:52
  4. Plotting specific points with qwt
    By byb810 in forum Qwt
    Replies: 0
    Last Post: 30th July 2009, 15:42
  5. Plotting points
    By afflictedd2 in forum Qt Programming
    Replies: 8
    Last Post: 26th February 2009, 08:20

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.