Next: Usage of Sphere Drawing, Previous: Sphere Drawing, Up: Sphere Drawing
The basic algorithm for generating the images is known the Z-buffer algorithm. The image is composed of an array of pixels, and each pixel has a height (a Z value) associated with it. Before the picture is constructed, the Z value is set to minus infinity. As pixels are set during the image generation, the height of each newly generated pixel is compared with that of the image already constructed, and if it will obscure the previous pixel (new Z is greater than that of the pixel), it is overwritten. Otherwise, it is left alone. This takes care of hidden surface removal trivially.
To generate a picture of spheres, we orthographically project each sphere in turn onto the pixel array, and determine the intensity for each such pixel. No anti-aliasing is done to reduce boundary effects.
The intensity of the pixels for the sphere is determined using Phong shading (Communications of the Association for Computing Machinery 18, 311 (1975)) which is a simple shading model involving two types of reflectance, diffuse and specular. Diffuse reflectance means uniform scattering, so that the surface will scatter light the same regardless of its orientation. The only determinant is what the projected area of the surface the observer can see. Specular reflectance takes into account the reflection of light off the surface, with the intensity the viewer sees being proportional to some power of the cosine of the reflected light vector and the observer. The higher the power, the more plastic the surface appears. The observer is presumed to be at z=infinity; the light source can be anywhere; however, shadows are not computed, so some of the lighting effects can be weird especially for side lighting. All the shading parameters can be varied, see Sphere Lighting.
The color of the atoms is determined by what combination of primary colors; red, green, or blue; are used. The program predefines these three primary colors, three secondary colors (yellow, magenta, cyan), and orange, black, gray and white. Any number of additional colors may be defined by the user.
For efficiency, the spheres are sorted with the spheres closest to the observer being processed first. Additional sorting on X and Y is done to minimize paging into the pixel arrays.
There are several transformations that must take place in going from the atomic representation stored in CONGEN to a picture on the display device. The first transformation is from CONGEN coordinates to display device coordinates. The second transformation is from these atomic coordinates into pixels which can be stored in a image file.
The first transformation depends on the coordinates of the display device. The process of generating the image operates in a space where two of the dimensions are those of the display device. The third dimension must be scaled to match that of the screen, and so must the radii of the atoms. Therefore, the first transformation prepares a listing of the atoms along with their radii in coordinates appropriate for the display device. The color of each atom is also included. The user is free to select any atom in the PSF to be displayed. Finally, there is an 80 character title associated with the picture to identify it.
The atomic transformation in this first step is performed on the atoms selected by the user and consists of the following steps:
The resulting list of atomic coordinates, radii, and colors is
called the spheres list. It is expected that these lists can be
concatenated to produce complex images. The spheres list can be written
to a file in formatted form so that it can edited if desired. The first
line of the file contains the title; the rest are atoms stored as X, Y,
Z, radii, color codes, IUPAC name, residue name, residue identifier, and
segment identifier with a format of (4F10.5,I5,4(1X,A4))
.
The next transformation into an image is done by the Z-buffer algorithm described earlier. This image can be written to a file in unformatted, run-length encoded form.
One special purpose option provided is the ability to change the coloring of pixels based on their accessibility. When this option is used, the program checks to see if the surface point corresponding to a pixel is accessible to a probe sphere of given radius as in the Lee and Richards accessible surface algorithm.
It is possible to go backwards in a crude sense from a spheres list back into some PSF arrays so that new transformations are possible. The spheres lists can be read in with the coordinates therein overwriting the coordinates in CONGEN and also resetting the number of atoms and all the arrays which partition atoms in residues and residues into segments as well redefining the residue names, residue identifiers, and segment identifiers. See Data Flows for Drawing Spheres, and the RS command for details.