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 email@example.com.
- Two Pi R
- Readers' Choice Awards 2013
- AIDE—Developing for Android on Android
- A Handy U-Boot Trick
- The Geek's Guide to the Coolest 2013 Holiday Gifts
- Sublime Text: One Editor to Rule Them All?
- Raspberry Pi: the Perfect Home Server
- Tech Tip: Really Simple HTTP Server with Python
- RSS Feeds
- Linux Systems Administrator
- Reality is disapointing
7 hours 45 min ago
- Máy sấy quần áo
10 hours 31 min ago
- Services on GlusterFS
10 hours 40 min ago
- Reply to comment | Linux Journal
12 hours 21 min ago
- Definitely cool stuff here
13 hours 22 min ago
- thanks for the information
14 hours 33 min ago
- nice information thanks
15 hours 12 min ago
18 hours 7 min ago
- The lost opportunity of security
1 day 5 hours ago
- Andhra Pradesh has a variety
1 day 9 hours ago