PDA

View Full Version : Persistence with QwtPlot



MSUdom5
20th April 2015, 16:13
I'd like to add persistence to my QwtPlot. For instance, when I plot a QwtPlotCurve, I'd like the original curve to fade at some rate when I plot new data. I can see a couple ways to do this:

- I could keep up with N plot items, where item 0 has the highest intensity, and N-1 has the lowest, but then I have to keep all of the plotted data in memory, and this could get prohibitive if I want to fade very slowly (which would require a large number of plot items).

- I could reimplement the appropriate methods in QwtPlot to draw everything to an image, then manipulate the image (gradually fade to background color each time replot is called with new data), and apply this cached image image to the canvas. Not quite how much work would be involved with this option.

Has anyone implemented this type of plot behavior before? Any tips would be appreciated.

Thanks!

Uwe
21st April 2015, 08:01
Not sure if I completely got what you are trying to do, but let's try: at some rate - let's say every second - you receive a data set from somewhere, that you need to display as a curve. Then you have some period in time - let's say 10 seconds - where you want to display previous curves. To indicate that data is from the past you decrease the alpha value of the corresponding curve pen, right ?

Implementation for this would be easy - simply store the date of each data set and start a timer, that updates the curve pen each second and removes curves, when the alpha value goes below 0.

You wrote about expecting performance/memory issues, because of having too many curves with this approach. Here you need to be more specific about what refresh rate and amount of lines we are talking about.

Concerning your idea of rendering curves to an image: you would have to iterate over all pixels of this image for each replot decrementing the alpha values, before drawing the new curve on top. Implementation is not very difficult and could be done multithreaded, but of course only doable if there is nothing else on the plot ( like grid lines ). Advantage of this approach is that you have a known penalty for updating the alpha values - independend from the number of curves/samples. Disadvantage is of course, that you always have this penalty and for environments, where you don't run the raster paint engine you would turn vector graphics into raster graphics, what means: no hardware acceleration in case of OpenGL or Qt4/X11 ( remote X11 will just suck ), and unscalable output in case of PDF.

Uwe

MSUdom5
21st April 2015, 15:29
Uwe,

Yep, that's exactly what I want to do.

As far as update rate, I'm looking at 10-30 updates a second, and a 10-20 second persistence. I guess I could limit the update rate and persistence time to make option 1 more feasible. I'll give it a shot.

Eventually, however, I'd like to implement something of this sort:

11114

for spectrum monitoring. I can do this with a raster plot, but not efficiently.