Routines (alphabetical) > Routines: P > POLYSHADE Procedure

# POLYSHADE

The POLYSHADE function creates a shaded-surface representation of one or more solids described by a set of polygons. This function accepts, as arguments, an array of three-dimensional vertices and a list of the indices of the vertices that describe each polygon.

Shading values are determined from one of three sources: a light source model, a user-specified array containing vertex shade values, or a user-specified array containing polygon shade values.

The shaded surface is constructed using the scan line algorithm. The default shading model is a combination of diffuse reflection and depth cueing. With this shading model, polygons are shaded using either constant shading, in which each polygon is given a constant intensity, or with Gouraud shading where the intensity is computed at each vertex and then interpolated over the polygon. Use the SET_SHADING procedure to control the direction of the light source and other shading parameters.

User-specified shading arrays allow “4-dimensional” displays that consist of a surface defined by a set of polygons, shaded with values from another variable.

## Examples

POLYSHADE is often used in conjunction with SHADE_VOLUME for volume visualization. The following example creates a spherical volume dataset and renders an isosurface from that dataset:

; Create an empty, 3-D array:
SPHERE = FLTARR(20, 20, 20)
; Create the spherical dataset:
FOR X=0,19 DO FOR Y=0,19 DO FOR Z=0,19 DO $
SPHERE(X, Y, Z) = SQRT((X-10)^2 + (Y-10)^2 + (Z-10)^2)
; Find the vertices and polygons for a density level of 8:
SHADE_VOLUME, SPHERE, 8, V, P
; Set up an appropriate 3-D transformation so we can see the
; sphere. This step is very important:
SCALE3, XRANGE=[0,20], YRANGE=[0,20], ZRANGE=[0,20]
; Render the image. Note that the T3D keyword has been set so that
; the previously-established 3-D transformation is used:
image = POLYSHADE(V, P, /T3D)
; Display the image:
TV, image

## Syntax

Result = POLYSHADE( Vertices, Polygons)

or

Result = POLYSHADE(X, Y, Z, Polygons)

Keywords: [, /DATA | , /NORMAL] [, POLY_SHADES=array] [, SHADES=array] [, /T3D] [, TOP=value] [, XSIZE=columns] [, YSIZE=rows]

## Return Value

Returns a shaded-surface representation. Output is a two-dimensional byte array containing the shaded image unless the current graphics output device is the Z-buffer. If the current output device is the Z-buffer, the results are merged with the Z-buffer’s contents and the function result contains a dummy value. See Z-Buffer for information and examples.

## Arguments

### Vertices

A (3, n) array containing the X, Y, and Z coordinates of each vertex. Coordinates can be in either data or normalized coordinates, depending on which keywords are present.

### X, Y, Z

The X, Y, and Z coordinates of each vertex can, alternatively, be specified as three array expressions of the same dimensions.

### Polygons

An integer or longword array containing the indices of the vertices for each polygon. The vertices of each polygon should be listed in counterclockwise order when observed from outside the surface. The vertex description of each polygon is a vector of the form: [n, i0, i1, ..., in-1] and the array Polygons is the concatenation of the lists of each polygon. For example, to render a pyramid consisting of four triangles, Polygons would contain 16 elements, made by concatenating four, four-element vectors of the form [3, V0, V1, V2]. V0, V1, and V2 are the indices of the vertices describing each triangle.

## Keywords

### DATA

Set this keyword to indicate that the vertex coordinates are in data units, the default coordinate system.

### NORMAL

Set this keyword to indicate that coordinates are in normalized units, within the three dimensional (0,1) cube.

### POLY_SHADES

An array expression, with the same number of elements as there are polygons defined in the Polygons array, containing the color index used to render each polygon. No interpolation is performed if all pixels within a given polygon have the same shade value. For most displays, this parameter should be scaled into the range of bytes.

### SHADES

An array expression, with the same number of elements as Vertices, containing the color index at each vertex. The shading of each pixel is interpolated from the surrounding SHADE values. For most displays, this parameter should be scaled into the range of bytes.

Note: When using the SHADES keyword on TrueColor devices, we recommend that decomposed color support be turned off by setting DECOMPOSED=0 for DEVICE Procedure.

### T3D

Set this keyword to use the three-dimensional to two-dimensional transformation contained in the homogeneous 4 by 4 matrix !P.T. Note that if T3D is set, !P.T must contain a valid transformation matrix. The SURFACE, SCALE3, and T3D procedures (and others) can all be used to set up transformations.

### TOP

The maximum shading value when light source shading is in effect. The default value is one less than the number of colors available in the currently selected graphics device.

### XSIZE

The number of columns in the output image array. If this parameter is omitted, the number of columns is equal to the X size of the currently selected display device.

Warning: The size parameters should be explicitly specified when the current graphics device is PostScript or any other high-resolution device. Making the output image the default full device size is likely to cause an insufficient memory error.

### YSIZE

The number of rows in the output image array. If this parameter is omitted, the number of rows is equal to the Y resolution of the currently selected display device.

## Version History

Original | Introduced

## See Also

PROJECT_VOL Procedure, RECON3, SET_SHADING Procedure, SHADE_SURF Procedure, SHADE_VOLUME Procedure, VOXEL_PROJ