PDA

View Full Version : qwt.6.0.0-svn oscilloscope example and QwtSeriesData



kachofool
17th June 2010, 17:15
Hey,

I want to create an updating plot very similar to the oscilloscope example provided with the latest qwt. I'm trying to follow through the source code for the example but I'm a bit lost with QwtSeriesData, and its many subclasses. My application has a couple of threads. A child thread pushes (x,y) data at a fairly high frequency through signals to the parent (gui) thread. The entire series of data sent over the duration of the program needs to be available so I have the child thread signal only the latest data, which is appended to (x,y) vectors in the main thread.

To plot the data, I tried following bits of the oscilloscope example. Instead of having a timer invoke QwtPlotDirectPainter, I have it setup so the incoming signal with the new (x,y) data will do it. But I'm stuck with which data points object to store my data in and pass over to the QwtPlotCurve object. I have two C++ lib vectors storing the data right now (and they keep increasing in size).

Also one more quick question -- what exactly does the 'attach' function call do for a lot of the classes in the example? ie. create plot, create grid/attach to plot, create curve/attach to plot, etc.

Thanks,
kif

Uwe
18th June 2010, 11:21
Before starting to copy code it might be worth to spend some time with basic thoughts:

1) Painting is a slow operation ( compared with recording) - maybe too slow to be done in a recording cycle. To avoid, that you miss recording cycles or your user interface becomes unresponsive you should always decouple sampling and refresh rates. ( f.e. your proposed design might flood the event queue followed by hanging updates and an unresponsive GUI ).

So I strongly recommend to implement the following design:

a) A sampling thread that does nothing beside recording and storing samples
b) The user interface periodically updates itsself according to the stored samples

2) Even if the painting performance doesn't affect the recording anymore you might want to see at least a minimum refresh rate.

The first thing you should do is to start the refreshtest example to see how many replots per second you can do for a curve with a number of points, that is comparable to your situation. If you are happy with this rate simply call replot() periodically.

Only if the rate is too low you have to find a strategy to improve the painting performance. The most obvious way is to reduce what needs to be painted. F.e you could reduce the number of points using QwtWeedingCurveFitter ( = Douglas Peucker ). Another option is to paint only new points ( this is what the oscilloscope example does and what QwtPlotDirectPainter is about).

Note, that the design of your application has an important impact on what is possible or not. F.e. the bottom scale of the oscilloscope example is incremented in fixed time intervals only. Only this way it is possible to paint incrementally. In opposite the cpuplot example always shows the last minute, what requires a full repaint for each update.

Uwe