Results 1 to 7 of 7

Thread: Performance issues with many Samples and closestPoint()

  1. #1
    Join Date
    Jan 2019
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Performance issues with many Samples and closestPoint()

    Hello,

    i am drawing a QwtPlotCurve (curve) with many Samples. When i go with my Mouse over that curve, i use a QwtPlotPicker who plots a QwtPlotMarker (marker_curve) with a QwtSymbol who follows the curve.

    My Picker function calls at moved(QPoint):

    Qt Code:
    1. void CreateWave::moveSymbolOnCurve(QPoint point)
    2. {
    3. double x = curve->closestPoint(point, NULL);
    4. marker_curve->setValue(x,curve->sample(x).y());
    5. plot->replot();
    6. }
    To copy to clipboard, switch view to plain text mode 

    This works well. As long as the Samples are not much (<500 000). But some curves i draw have Samples ~10 000 000. When the samples are over 500 000 and i move my cursor over the plot, the drawn markers are delayed and its lagging pretty hard.
    The reason i guess is because closestPoint() and replot() take much time then.

    So i thought about to reduce the drawn samples with QwtWeedingCurveFitter. This worked and the drawn curve has less points, but the closesPoint() and replot() (as well as curve->sample(x).y())) uses all Samples so the performance is not better at all.
    Is there a posibility to draw the curve with a maximum amount of samples on which i can use closestpoint(), but when i zoom in, the amount of samples in that zoom should redraw to the same amount, so i can catch details?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,139
    Thanked 823 Times in 772 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Performance issues with many Samples and closestPoint()

    If your points are ordered in x or y direction you could use qwtUpperSampleIndex and then do a local search to find the closest point.
    When using QwtWeedingCurveFitter you have to reduce the points before passing them to the curve.

    Also have a look at playground/curvetracker. Beside showing how to use qwtUpperSampleIndex it implements a cursor as an overlay - what does not result in heavy replots, when moving it.

    Uwe

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

    AxelP (18th January 2019)

  4. #3
    Join Date
    Jan 2019
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Performance issues with many Samples and closestPoint()

    Thanks for your reply Uwe!
    I use qwtUpperSampleIndex now instead of closestPoint(). Now i have no snap to curve but always the y-coordinate to my x, which is okayish. What is the difference between qwtUpperSampleIndex and curve->sample(x).y() tho?
    I got this from your example playground/curvetracker. I do not get how to use a cursor/ marker as an overlay, but this sounds exactly what i need: Just a vertical cursor at x position with a symbol at the coresponding y position and this as an overlay, so i do not need to replot the curve with its heavy amount of samples. Can you tell me how/where in this example a marker is implemented as an overlay?

    Axel

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,139
    Thanked 823 Times in 772 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Performance issues with many Samples and closestPoint()

    I use qwtUpperSampleIndex now instead of closestPoint(). Now i have no snap to curve but always the y-coordinate to my x, which is okayish.
    When you have the upper index you also have the lower index - it is upper - 1. Then you can easily calculate the exact point - like it is done in the curvetracker example.

    As you wrote, that you have a huge number of points: if you are using QwtPlotCurve::Lines I recommend to use a branch >= 6.2, and enable QwtPlotCurve::FilterPointsAggressive. This is a fast algorithm, that works for data with increasing x or y by dropping lines you wouldn't see because they are rounded to the same pixel positions anyway.

    What is the difference between qwtUpperSampleIndex and curve->sample(x).y() tho?
    The first one finds an index for a position, while the second returns a point at a specific index.

    Beside when index and x coordinates are the same ( 0, 1, 2, 3 ... ) the second call would be wrong.

    But in case your data has this specific characteristic you would have faster options to find the closest sample than qwtUpperSampleIndex. Also have a look at QwtValuePointData from https://sourceforge.net/p/qwt/code/H...t_point_data.h then.

    I got this from your example playground/curvetracker. I do not get how to use a cursor/ marker as an overlay, but this sounds exactly what i need: Just a vertical cursor at x position with a symbol at the coresponding y position and this as an overlay, so i do not need to replot the curve with its heavy amount of samples. Can you tell me how/where in this example a marker is implemented as an overlay?
    The curve tracker example uses a QwtPlotPicker that uses overlays for curser and text - there is no marker ( QwtPlotMarker ) involved. But if your code is derived from this example - why don't you simply use the CurveTracker class as it is ?

    Uwe

  6. #5
    Join Date
    Jan 2019
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Performance issues with many Samples and closestPoint()

    Thanks for your Reply Uwe!

    I managed to get rid of these replots now. I did an overlay class how you eplained here :https://www.qtcentre.org/threads/584...688#post260688

    There i paint a cross (using QPainter) on the position which my picker sends to the overlay class, so i don't have to replot. Is this an elegant solution?

    Now i could use qwtUpperSampleIndex and all would be fine (performance wise), but i would like to have some kind of snap to the curve, when the cursor is near the curve. I am not totally happy with getting the sample coresponding the the x-coordinate of the cursor.
    Is there any way of getting a "snap" (besides closestPoint() ), maybe something like a closestPoint() of an smaler area of my x value?

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,139
    Thanked 823 Times in 772 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Performance issues with many Samples and closestPoint()

    Quote Originally Posted by AxelP View Post
    TI am not totally happy with getting the sample coresponding the the x-coordinate of the cursor.
    Is there any way of getting a "snap" (besides closestPoint() ), maybe something like a closestPoint() of an smaler area of my x value?
    You now find the upper index of the point corresponding to the current mouse position with a faster compare method and in O(log n) instead of O(n) - that's all.
    If you like to run some local algo over maybe n points below and above the index, why not ?

    F.e the curvetracker example interpolates between the adjacent points to guess a y coordinate for positions, where no sample exists.

    Uwe

  8. #7
    Join Date
    Jan 2019
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Performance issues with many Samples and closestPoint()

    I wrote a funktion like closestPoint() now, but let it search from 'x-position - 250000 samples' to 'x-position + 250000 samples', instead the whole curve. This makes the cursor also snap to edges at huge amount of samples, when the cursor comes close to the curve.
    I am pretty happy with this now. Thanks Uwe for all the help!

    Axel
    Last edited by AxelP; 21st January 2019 at 15:39.

Similar Threads

  1. Performance issues with detached QProcess
    By simon71717 in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2014, 11:07
  2. Performance issues QwtPlot
    By ghm in forum Qwt
    Replies: 3
    Last Post: 1st February 2012, 08:33
  3. QtWebKit and flash performance issues
    By caelestis in forum Qt Programming
    Replies: 0
    Last Post: 7th February 2010, 06:08
  4. Performance Issues in Qt-4.4.3 / Qwt-5.1.1
    By swamyonline in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2009, 18:50
  5. QAbstractProxyModel::mapToSource performance issues
    By maximAL in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 23:48

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.