[comp.windows.x] strip-chart display

kens@JARGON.WHOI.EDU (Ken Stewart) (12/28/90)

Howdy Folks --

	I'm writing a simple strip-chart application to display various
real-time data streams under X. I'm developing under XView 2.0 but using
Xlib calls for display functions. I've tried two approaches to "scroll" the
display: 1) copy an area of the drawable then draw one new line to connect
the new data point; 2) xor the old polyline to clear then xor the updated
polyline.

	The bitblt approach gives the smoothest scrolling. The xor polyline
approach runs about 4 times faster on a SPARC-GX, but flickers annoyingly;
bracketing the drawing calls with server grab/ungrab doesn't help. Relative
speed would depend on the drawable area, but we need reasonably large
displayed areas for good viewable resolution (say, 1024x256).

	I've included skeleton examples below. My questions are: 1) is there
a more efficient approach? 2) does anyone have a similar working application
or can point me to a PD source? 3) are there any comments on efficiency/
portability for other X environments? (our applications run mostly on Suns, 
but must support remote displays on PC's, Mac's, and other workstations).
Thanks for any help.

Ken Stewart

Deep Submergence Laboratory              voice: (508) 457-2000 x2644
Woods Hole Oceanographic Institution       fax: (508) 457-2191
WHOI, Blake 109                       internet: kens@jargon.whoi.edu
Woods Hole, MA  02543                    omnet: k.stewart

**************************************************************************

1) BITBLT
    .
    .
    /* scroll the display right */
    XCopyArea( dpy, xwin, xwin, gc, 0, 0, 
                canvas_width - horiz_incr, canvas_height, horiz_incr, 0 );

    /* clear a small region at left */
    XClearArea( dpy, xwin, 0, 0, horiz_incr, canvas_height, False );

    new_y = ...

    /* connect the new data point */
    XDrawLine( dpy, xwin, gc, horiz_incr, last_y, 0, new_y );

    last_y = new_y;
    .
    .

2) XOR POLYLINE
    .
    .
    XGrabServer( dpy );

    /* clear last displayed polyline */
    XDrawLines( dpy, xwin, xorgc, points, num_points, CoordModeOrigin );

    /* code omitted here to shift y values in array of points */
    .
    . 
    points[0].y = ...

    XDrawLines( dpy, xwin, xorgc, points, num_points, CoordModeOrigin );

    XFlush( dpy );

    XUngrabServer( dpy );
    .
    .

**************************************************************************

stripes@eng.umd.edu (Joshua Osborne) (12/29/90)

In article <9012281317.AA10469@jargon.whoi.edu>, kens@JARGON.WHOI.EDU (Ken Stewart) writes:

[...]
You may wel get some more speed from this:

> **************************************************************************
> 
> 1) BITBLT
>     .
>     .
>     /* scroll the display right */
>     XCopyArea( dpy, xwin, xwin, gc, 0, min_height, 
>                 canvas_width - horiz_incr, canvas_height, horiz_incr, 0 );
[replce w/]       canvas_width - horiz_incr,    max_height, horiz_incr, 0 );
> 
>     /* clear a small region at left */
>     XClearArea( dpy, xwin, 0, 0, horiz_incr, canvas_height, False );     
[replace w/]
      XClearArea( dpy, xwin, 0, min_height, horiz_incr, max_height, False );     
> 
>     new_y = ...
> 
>     /* connect the new data point */
>     XDrawLine( dpy, xwin, gc, horiz_incr, last_y, 0, new_y );
> 
>     last_y = new_y;
>     .
>     .

Less bits to blt most of the time.  Should end up being faster.  (but you will
have to track the max/min values correctly)


-- 
           stripes@eng.umd.edu          "Security for Unix is like
      Josh_Osborne@Real_World,The          Multitasking for MS-DOS"
      "The dyslexic porgramer"                  - Kevin Lockwood
"Don't over-comment"     - p151 The Elements of Programming Style 2nd Edition
                                   Kernighan and Plauger

mouse@LIGHTNING.MCRCIM.MCGILL.EDU (12/31/90)

> I'm writing a simple strip-chart application to display various
> real-time data streams under X.  I'm [...] using Xlib calls for
> display functions.  I've tried two approaches to "scroll" the
> display: 1) copy an area of the drawable then draw one new line to
> connect the new data point; 2) xor the old polyline to clear then xor
> the updated polyline.

> The bitblt approach gives the smoothest scrolling.  The xor polyline
> approach runs about 4 times faster on a SPARC-GX, but flickers
> annoyingly [...].

> 2) XOR POLYLINE
>     XGrabServer( dpy );
>     /* clear last displayed polyline */
>     XDrawLines( dpy, xwin, xorgc, points, num_points, CoordModeOrigin );
>     /* code omitted here to shift y values in array of points */
>     XDrawLines( dpy, xwin, xorgc, points, num_points, CoordModeOrigin );
>     XFlush( dpy );
>     XUngrabServer( dpy );

You might try doing the polylines a bit differently.  It would mean a
little reworking of your code, but it should produce much less flicker
to shift the lines one line at a time instead of erasing the old thing
completely before drawing any of the new lines.

You would need to use XDrawSegments for this, since the lines would no
longer be connected, but I would expect it to reduce the flickering
drastically.  (I haven't tried it.  You didn't provide enough to build
a compilable program and I am not up to building a test program for it
just now.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

kens@jargon.whoi.EDU (Ken Stewart) (01/04/91)

> > 	I'm writing a simple strip-chart application ...
 
>   I have helped some of our customers with a similar problem, although they
> didn't use X.  If you maintain a max and a min, and assuming your 
> fluctuations aren't too great, you can bitblt only the part of the window 
> which changes ...

Dave --

	Thanks for the reply; good suggestion. Unless I misunderstood you,
though, it's a bit more complicated to keep track of min/max than a simple
increment/decrement. If the current min or max scrolls off the end, you 
probably have to traverse the list of displayed values to replace it; easy
to do, though, and not a big performance penalty compared with blitting.

	I couldn't get through to the return address on your message, so
I'm posting this reply back to the net.

-Ken

pete@iris49.UUCP (Pete Ware) (01/05/91)

When I was at SAIC I wrote some fairly nice widgets for displaying
waveform data (i.e. stripchart like information).  It dealt gracefully
with displaying 24 hours (7 Mbytes) down to 1/100 of a second.
Horizontal and vertical scales can be changed interactively.

Contact jim@esosun.css.gov to see if it might be available.  The
following is from the README file.

----------------------------------------------------------------------
This is a set of widgets for displaying waveforms under the X Window
System Version 11 Release 4.  The following widgets implement display
of a waveform with an optional scale on the left side and optional
detections overlaying the waveform.  The display may be scrolled left
or right.  An arbitrary number of waveform widgets may be created and
displayed.

The widgets handle color or monochrome screens of any resolution.
Flexibility in selecting colors, fonts and other appropriate
attributes make it easy to customize waveform display on an
application by application and user by user basis.  Each widget
follows the X Toolkit Intrinsics and is compatible with any other
widgets based on the Intrinsics.

----------------------------------------------------------------------
--pete
Pete Ware / Biosym / San Diego CA / (619) 546-5532
uucp:	  scripps.edu!bioc1!pete
Internet: bioc1!pete@scripps.edu