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
- December 2013 Issue of Linux Journal: Readers' Choice
- IBM Will Minimize Impact of Future Disasters
- Raspberry Pi: the Perfect Home Server
- Sublime Text: One Editor to Rule Them All?
- Linux Systems Administrator
- RSS Feeds
- Senior Perl Developer
- Technical Support Rep
- Tech Tip: Really Simple HTTP Server with Python
- Reply to comment | Linux Journal
6 hours 31 min ago
- It's Jupiter
7 hours 31 min ago
- GIMP is certainly a graphic
8 hours 33 min ago
- Thanks For Your Sharing
13 hours 19 min ago
- Studying linux, and looking
16 hours 44 min ago
- voting for Best Linux Distribution
1 day 1 hour ago
- tizen vs android
1 day 5 hours ago
- i switch my choice from KDE
1 day 5 hours ago
1 day 8 hours ago
- Belanja Online
1 day 11 hours ago