A Real-Time Data Plotting Program
The class RtpRender (defined in rtpRender.c) handles the details of drawing the set of data points into a pixmap. Because rendering the entire set can take significant time, RtpRender sets up a QTimer object with zero timeout to give all available CPU time to rendering while maintaining snappy UI response. RtpRender::slotWorkAwhile, the QTimer callback, munches on points for a fixed interval (100 msec at present), and then returns. The code in Listing 2 is the guts of RtpRender::slotWorkAwhile (rtpRender.c, line 274).
There are two types of rendering operations. A pre-emptive or on-line rendering draws points directly into the pixmap used for repaint events. A new on-line rendering is started by calling RtpRender::newOnlineRender. When this is called, any rendering that may be in progress is cancelled and the new rendering starts from scratch, drawing all received points. The code is in Listing 3 (rtpRender.c, line 77).
When RtpRender::newOnlineRender is called, a pointer to the pixmap used for repaint is passed in as the buf argument. _map is a data structure that contains the scale and offset factors for the new rendering and is returned to the calling code, so that new points from STDIN can be directly plotted even as the rendering progresses.
A non-preemptive or private rendering first creates a private pixmap, then draws the points into it. A private rendering is requested by calling RtpRender::quePrivateRender. The private rendering does not cancel the current rendering operation if one is in progress. It waits until the current rendering is complete before starting. The code is in Listing 4 (rtpRender.c, line 97).
Because the queuing mechanism is just a boolean flag, the private rendering queue is only one deep. When RtpRender::quePrivateRender is called, it will destroy any pending private rendering operation, but will not interfere with one already in progress. Note that _timer is an object of type QTimer. If the timer is already active, it means a rendering is already in progress.
rtp uses private rendering to update the plot when new data points force a viewport change in either the auto-scale or auto-tracking mode. On-line rendering is used to update the plot in response to user-initiated viewport changes, such as zooming into a moused region. The theory is new points come in quickly enough that we don't want to start over each time we get one. However, when the user changes the viewport, he has no interest in anything but the latest and greatest plot.
David Watt can be reached via e-mail at firstname.lastname@example.org.
- Readers' Choice Awards 2013
- IBM Will Minimize Impact of Future Disasters
- December 2013 Issue of Linux Journal: Readers' Choice
- Sublime Text: One Editor to Rule Them All?
- RSS Feeds
- Raspberry Pi: the Perfect Home Server
- Tech Tip: Really Simple HTTP Server with Python
- Linux Systems Administrator
- New Products
- Senior Perl Developer
- yes it's Jupiter Broadcasting
1 hour 7 min ago
- nice to see PClinuxOS finally
3 hours 40 min ago
- Personally, I am no longer a
4 hours 37 min ago
- Reply to comment | Linux Journal
18 hours 2 min ago
- It's Jupiter
19 hours 1 min ago
- GIMP is certainly a graphic
20 hours 4 min ago
- Thanks For Your Sharing
1 day 49 min ago
- Studying linux, and looking
1 day 4 hours ago
- voting for Best Linux Distribution
1 day 12 hours ago
- tizen vs android
1 day 16 hours ago