View Volume

The view volume defines the three-dimensional volume in space that, once projected, is to fit within the viewport. There are two parts to the view volume: the viewplane rectangle and the near and far clipping planes.

Viewplane Rectangle

The viewplane rectangle defines the bounds in the X and Y directions that will be mapped into the viewport. Objects (or portions of objects) that lie outside the viewplane rectangle will not be rendered. The viewplane rectangle is always located at Z=0.

Use the VIEWPLANE_RECT keyword to the IDLgrView::Init method (or use the SetProperty method if you have already created the view object) to set the location and extent of the viewplane rectangle. Set the keyword equal to a four-element floating-point vector; the first two elements specify the X and Y location of the lower left corner of the rectangle, and the second two elements specify the width and height. The default rectangle is located at (-1.0, -1.0) and is two units wide and two units high ([–1.0, –1.0, 2.0, 2.0]). For example, the following command changes the viewplane rectangle to be located at (0.0, 0.0) and to be one unit square:

myView->SetProperty, VIEWPLANE_RECT = [0.0, 0.0, 1.0, 1.0] 

Note
See Panning in Object Graphics for an example that modifies the VIEWPLANE_RECT to control what portion of an image is displayed in a view.

Near and Far Clipping Planes

The near and far clipping planes define the bounds in the Z direction that will be mapped into the viewport. Objects (or portions of objects) that lie nearer to the eye than the near clipping plane or farther from the eye than the far clipping plane will not be rendered. The figure below shows near and far clipping planes.

Use the ZCLIP keyword to the IDLgrView::Init method (or use the SetProperty method if you have already created the view object) to set the near and far clipping planes. Set the keyword equal to a two-element floating-point vector that defines the positions of the two clipping planes: [near, far]. The default clipping planes are at Z = 1.0 and Z = –1.0 ([1.0, –1.0]). For example, the following command changes the near and far clipping planes to be located at Z = 2.0 and Z = –3.0, respectively.

myView->SetProperty, ZCLIP = [2.0, -3.0]  
 

Figure 3-5: Near and Far Clipping Planes. Object 2 is not rendered, because it does not lie between the near and far clipping planes.

objtran5.gif

Finding an Appropriate View Volume

Finding an appropriate view volume for a given object tree is relatively simple in theory. To find the appropriate viewplane rectangle, you must find the overall X and Y range of the object (usually a model or scene object) that contains the items drawn in the object tree, accounting for any transformations of objects contained in the tree. Similarly, to find the appropriate near and far clipping planes, you can find the Z range of the object that contains the items drawn in the object tree. In practice, however, finding, adding, and transforming the ranges for a large object tree can be complicated.

Example Code
Two routines contained in the IDL distribution provide an example of how the view volume can be computed in many cases. These routines are defined in the files set_view.pro and get_bounds.pro, located in the examples/doc/utilities subdirectory of the IDL distribution. Run these example procedures by entering set_view or get_bounds at the IDL command prompt or view the files in an IDL Editor window by entering .EDIT set_view.pro or .EDIT get_bounds.pro.

The SET_VIEW procedure accepts as arguments the object references of a view object and a destination object, computes an appropriate view volume for the view object, and sets the VIEWPLANE_RECT property of the view object accordingly. The SET_VIEW procedure calls the GET_BOUNDS procedure to compute the X, Y, and Z ranges of the objects contained in the view object.

The SET_VIEW and GET_BOUNDS routines are used in the examples in this volume, and are available for your use when creating and displaying object hierarchies. They are, however, example code, and are not truly generic in the situations they address. When you encounter a situation for which these routines do not produce the desired result, we encourage you to copy and alter the code to suit your own needs.

Inspect the SET_VIEW.PRO and GET_BOUNDS.PRO files for further details.