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):
Code:
void CreateWave
::moveSymbolOnCurve(QPoint point
) {
double x = curve->closestPoint(point, NULL);
marker_curve->setValue(x,curve->sample(x).y());
plot->replot();
}
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?
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
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
Re: Performance issues with many Samples and closestPoint()
Quote:
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.
Quote:
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.
Quote:
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
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?
Re: Performance issues with many Samples and closestPoint()
Quote:
Originally Posted by
AxelP
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
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