We present here some simple software that uses cheap hardware, originally designed for the game computer industry, to make full screen stereo available on Linux based PCs. The quality of the stereo vision is similar to the top of the line graphics workstations that are capable of quad-buffering. This stereo option has been incorporated in the X11 based version of WHAT IF , but the stereo source code is freely available and can easily be incorporated in other visualisation packages.
The most successful visualisation trick is undoubtedly stereo viewing. Not only does stereo vision give us an extra dimension so that more information can be represented (and understood!) in one picture, a stereo model of a molecule is also one dimension closer to reality than a 2D picture.
Figure 1. Principle of stereo vision.
The two eyes, represented by circles, see the boldface pyramid from a different location. The two small pyramids represent what the two eyes see. For stereo vision, the graphics system should present each of the two small pyramids to the corresponding eye.
The principle of stereo viewing is trivial (see figure 1 ). The left and right eye see an object from positions about six centimetres apart, and the brain combines these two pictures to create a stereo impression. In silico stereo vision is based on presenting each eye a slightly different picture, and each of these two pictures should represent as precisely as possible what the eye would have seen if the 3D model would really have been there. Much text has been written about how to project a 3D object as two mono pictures that can be viewed with special lenses or mirror boxes (see figure 2 ) to create a stereo impression. At first one would think that two projections, one before and one after a small rotation of the object around a vertical axis, is all that is needed, but it can easily be shown that this is not optimal [4,5,6] . A further discussion of this topic is beyond the scope of this article.
Figure 2. Principle of stereo vision from 2D images.
A. If the two pyramids from figure 1 are placed in front of the corresponding eyes, the pictures
overlap which makes stereo vision difficult and messy.
B. A stereo device with 4 mirrors allows the two pyramids to be drawn separately. The mirror system ensures that each picture is cleanly presented to the corresponding eye.
The more expensive solution for stereo viewing is to use a system where the whole screen alternately shows the picture for the left and the right eye, while spectacles are worn that alternately make the right or left lens non-transparent. If the screen refresh rate and the transparent/non-transparent swapping of the lenses are properly synchronised, the user will see stereo.
The most common spectacles use Liquid Crystals (LC) that can swap between transparent and non-transparent at a high frequency. These glasses "shut off" visibility for the one eye at the time that the screen is displaying the other eye's image and vice versa, hence they are called LC shutter glasses.
Because of the need to separate in time the images for each of the two eyes, a perfect synchronisation of the glasses to the graphics hardware is needed. This is handled in hardware by most modern graphic cards but the appropriate software drivers to use it, for example in Linux, are still missing.
The first and simplest of the methods is used in the less expensive devices like Tetratel's Eye-FX or VR Standard VR-Joy, and is done entirely by the device that scans the video signal alternatingly switching off the odd and the even lines. This is called "line blanking" or "synthetic interlace" and its main advantage is that works with every video card-monitor configuration without any need to modify the hardware setup.
The other two methods require the use of interlace modes that can easily be programmed for most of the current operating systems, by simple changes in their operating system setup. In the case of XFree 86 , the X11 server most used on Linux based PCs, some changes should be made in the configuration file (XF86Config ). In interlace mode the Cathode Ray Tube (CRT) controller of the graphics card, first draws the odd lines (i.e. 1,3,5 ....1023 ) and then returns to the top and draws the even lines (i.e. 2,4,6 ...1024 ). Each of this "draws" is called a field and the entire display is drawn in two separate fields (odd and even).
Using two different vertical sync signals the hardware can recognise which is the even and which the odd field. Systems like the NuVision 60GX NSR , Tetratel E ye FX or VR J oy can synchronise the shuttering of the lenses in the stereo glasses to these alternating fields.
StereoGraphics Corporation uses another trick to synchronise their CrystalEyes glasses. They use in the PC version (EPC-2) a procedure called White Line (WL) code. This implies that the transparency of the lenses is triggered using the last line of the display. StereoGraphics Corporation uses the convention that a line composed for about 4/5-th of pure white and further pure black pixels indicates the right eye picture, and a line composed for about 1/5-th of pure white and the rest black pixels indicates the left eye picture. To use the EPC-2 , our software draws the white lines in the last two lines of the root window. The major drawback of this method is that the last two lines of the display have to stay clear of overlap with other windows or desktop gadgets.
Silicon Graphics has a large line of graphics workstations (SGI stations). Their intermediately expensive workstations combined special hardware with a variety of visualisation techniques to create a good stereo perception. Basically by dividing the complete screen into top and bottom halves and doubling the monitor refresh rate SGI was able to drive the LC glasses in a way that the left eye sees only the top half of the framebuffer and the right only the bottom half. This same procedure can also be applied on PC s by using an external device that doubles the refresh rate, StereoGraphics and NuVision controllers provide this facility which is called above/below stereo or sync-doubling. The major disadvantage of this techniques is that the stereo pictures always cover the full screen. If one wants to see stereo in just one window while maintaining normal mono for the rest of the screen (stereo-in-a-window, which we call 'full-window-stereo') an SGI station is needed that can do quad-buffering. These quad-buffer capable SGI stations, unfortunately, are rather expensive.
For the WHAT IF implementation of stereo vision on the PC, we initially started evaluating the old full-screen (above/below or sync doubling) method. However, this method was discarded later in favour of the full-window interlaced method, because above/below showed no other advantages than the simplicity of the implementation .
Figure 3. The key fragments of the source code used for stereo vision in a window.
Figure 3 lists the most important parts of the X11 code used in WHAT IF to create full-window-stereo. The WHAT IF graphics code was modified to introduce the stereo multi-buffering scheme, the parallel camera model for the calculation of the viewing matrices, and the code that checks for eye reversal (see below).
The multi-buffering scheme consists of one buffer per eye, a combination buffer, and a screen buffer. When a change is needed at the screen, the pictures for the two eyes are drawn in the two separate eye-buffers, they are copied one after the other (the first in full, the second using a clipmask) to the combination buffer. The graphic context (GC) is updated using the XSetClipMask operation (figure 3 c)  . The clipmask (figure 3 a) is a pixmap of depth one, with the same root as the GC , and should for our application be of the same geometry as the drawable pixmap. The clipmask will make the X11C opyArea function (figure 3 c) work such that only the non masked lines will be copied.
When an eye reversal situation occurs, for example by moving the full-window-stereo window by an odd number of pixels in the vertical direction, the clipmask for the right eye is simply inverted (figure 3b) to avoid that the depth perceptions flips back to front.
After merging the two images the
combination buffer is copied into the screen buffer and thus to
(figure 3 d).
Of course this quad-buffering mode is a bit slower than non stereo
or double-buffer modes, but this is absolutely not a problem given
the speed of current CPU s,
graphics hardware and CRT s.
There are no special hardware limitations, other than that this type of stereo vision will work only if you have a real CRT monitor and not an LCD display. It is advisable to use a monitor that supports a very high refresh rate. In stereo the eye refresh rate will be half of the monitor refresh rate. If the eye refresh rate gets too low the picture will be flickering. Although this is a matter of taste (and money) we suggest to use CRT s with a monitor refresh rate of at least 120 H z.
We looked at a series of stereo devices ranging in price from $200,- up to $1200,- (see table 1) . All gadgets were easy to install and require no major modifications to the computer setup. Table 1 lists these devices and some of their characteristics, as well as some subjective remarks.
Company/device name(1) Price Principle(2) Quality Remarks
Tetratel/EyeFX NA LB, INT ++ (3) VRStandard/VR Joy $160.0 LB, INT + (4) StereoGraphics/EPC-2+CrystalEyes $1190.0 WLC +++ (5) NuVision 60GX NSR $399 .0 INT +++ (6) 1) WWW addresses of vendors: Tetratel : http://www.tetratel.com/ VR Standard: http://www.vrstandard.com/ StereoGraphics: http://www.stereographics.com/ NuVision: http://www.nuvision3d.com/ 2) LB = line blanking, INT = Interlace, WLC = White line code, (this table only shows those modes used by WHAT IF) 3) This system is discontinued, at present is being replaced by the EyeFX Pro, an infrared wireless system. 4) Wired system, two glasses per controller, small LCs. 5) Wireless glasses, large LCs, WLC makes software control possible. 6) Wireless glasses, large LCs, very good controller with eye reversal.
From the times when it was introduced to the PCs by IBM, interlaced modes gained a bad reputation. We have seen in the computer community a trend to believe that one should avoid the use of interlace modes at all costs, because they introduce flicker. Today's display technology, however, is much better than a decade ago, easily allowing for the flicker-free use of interlace modes.
The main advantage of the interlace stereo modes compared with the above/below method is that multiple stereo windows can be displayed at the same time, this is not very important for the computer game industry, but it is certainly crucial for science (see figure 4). A detailed comparison of these two methods is beyond the scope of this paper and has been described elsewhere .
The hardware discussed in this article represents the state of the art for stereo devices in summer 1999 . By the time you read this article some of the companies perhaps no longer exist, others might have designed different or better devices. We only tested a series of radically different hardware stereo devices to ensure that our software can cope with all possible stereo vision techniques.
Figure 4. Example of full-window-stereo.
In this screen dump one sees the two interlaced halves of a stereo picture in the left WHAT IF window, while the right WHAT IF window and all text windows are mono.
2.- Nicholls, A., Sharp, K.A., Honig, B. Protein folding and association: Insight from the interfacial and thermodynamic properties of hydrocarbons. Proteins. 1991, 11, 281-296
3.- Richardson, J.S. Schematics drawings of protein structures. Methods Enzymol. 1985, 115, 359-380
4.- Hodges, L.F., McAllister, D.F. Rotation algorithm artefacts in stereoscopic images. Optical Eng. 1990, 29, 973-976
5.- CrystalEyes Software Development Kit. StereoGraphics Corp. 1998.
6.- Akka, R. Converting existing applications to support high quality stereoscopy. StereoGraphics Corp. 1998.
7.- Thomas, D.J. Towards more reliable printed stereo. J. Mol. Graph. 1993, 11, 15-22
8.- Rodriguez, R. and Vriend, G. http://swift.embl-heidelberg.de/whatif/chap59.html
9.- Woo, M., Neider, J., Davis, T. OpenGL Programming Guide. Adison Wesley, 1997.
10.- Scheifler, R. and Gettys, J. X window System: Core Library and Standards, X version 11, releases 6 and 6.1, Digital Press, 1996.
11.- Brungert, C. http://www.stereo3d.com