ShapeUtilities.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last Edited by: Crow, March 29, 1988 6:01:24 pm PST
DIRECTORY
ThreeDBasics  USING [ ClipState, Context, FacingDir, OutCode, Patch, Pixel, PtrPatch,
        PtrPatchSequence, RGB, ShapeInstance, ShadingSequence, Triple,
        VertexInfo, VertexInfoSequence, VertexInfoProc, Xfm3D ];
ShapeUtilities: CEDAR DEFINITIONS
~ BEGIN
Basic Types
Pixel: TYPE ~ ThreeDBasics.Pixel;          -- [ r, g, b, a, z: CARDINAL]
Triple: TYPE ~ ThreeDBasics.Triple;         -- [ x, y, z: REAL];
RGB: TYPE ~ ThreeDBasics.RGB;
Xfm3D: TYPE ~ ThreeDBasics.Xfm3D;
OutCode: TYPE ~ ThreeDBasics.OutCode;
ClipState: TYPE ~ ThreeDBasics.ClipState;
Context: TYPE ~ ThreeDBasics.Context;
VertexInfoSequence: TYPE ~ ThreeDBasics.VertexInfoSequence;
ShapeInstance: TYPE ~ ThreeDBasics.ShapeInstance;
ShadingSequence: TYPE ~ ThreeDBasics.ShadingSequence;
Patch Definitions
FacingDir: TYPE ~ ThreeDBasics.FacingDir;
VertexInfo: TYPE ~ ThreeDBasics.VertexInfo;
Patch: TYPE ~ ThreeDBasics.Patch;
 RECORD[type: ATOMNIL, oneSided: BOOLEANTRUE, nVtces: NAT ← 0,
    clipState: ClipState ← in, props: Atom.PropList ← NIL,
   vtx: SEQUENCE maxLength: NAT OF VertexInfo];
PtrPatch: TYPE ~ ThreeDBasics.PtrPatch;
RECORD[type: ATOMNIL, oneSided: BOOLEANTRUE, nVtces: NAT ← 0,
   clipState: ClipState ← in, props: Atom.PropList ← NIL,
   vtxPtr: SEQUENCE length: NAT OF NAT];
PtrPatchSequence: TYPE ~ ThreeDBasics.PtrPatchSequence;
RECORD[SEQUENCE length: CARDINAL OF REF PtrPatch];
ShapePatch: TYPE ~ RECORD[
shape: REF ShapeInstance, patch, next, prev: INT, awayness: REAL
];
SortSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF ShapePatch];
Caching Procedures
GetVertexInfo: PROC[] RETURNS[REF VertexInfo];
Gets vertex from automatically expanding pool
ReleaseVertexInfo: PROC[vtx: REF VertexInfo];
Returns vertex to pool
GetPatch: PROC[size: NAT] RETURNS[REF Patch];
Gets patch from automatically expanding pool
ReleasePatch: PROC[p: REF Patch];
Returns patch to pool
Utility Procedures
ShapePatchToPatch: PROC[ context: REF Context, sPatch: REF ShapePatch ]
       RETURNS
[patch: REF Patch];
Converts pointers to vertices into self-contained patch data
Procedures for Manipulating Shapes
XfmToEyeSpace: PROC[context: REF Context, shape: REF ShapeInstance] RETURNS[ClipState];
Calculate eyespace coords for all vertices, get clip state of vertices and whole shape
XfmToDisplay: PROC[context: REF Context, shape: REF ShapeInstance, getBox: BOOLFALSE];
Calculate display coords for all vertices, get screen extent whole shape
GetPolyShades: PROC[context: REF Context, shape: REF ShapeInstance];
Calculate shading for all polygons in shape, get polygon normals if not done
GetVtxNmls: PROC[context: REF Context, shape: REF ShapeInstance];
Sum normals for vertices given by adjacent polygon corners, only for polygons!
GetVtxShades: PROC[ context: REF Context, shape: REF ShapeInstance ];
Calculate shading for all vertices in shape, get vertex normals if not done
Procedures for Transformations and Clipping
ClipPoly: PROC[ context: REF Context, poly: REF Patch] RETURNS [REF Patch];
Clips one polygon (or polyline) to current state of context
GetPatchClipState: PROC[ patch: REF Patch];
Clips one polygon (or polyline) to current state of context
GetClipCodeForPt: PROC[context: REF Context, pt: Triple] RETURNS[clip: OutCode];
Evaluates clip codes for vertices (for easy acceptance and rejection tests)
XfmPtToEyeSpace: PROC[context: REF Context, pt: Triple, xfm: Xfm3D ← NIL]
      RETURNS[Triple, OutCode];
Transforms triple from object space to eyespace
XfmPtToDisplay: PROC[context: REF Context, pt: Triple, shape: REF ShapeInstance ← NIL]
      RETURNS[Triple];
Transforms triple from eyespace to display coordinates
Procedures for expansion of/to polygons
RegisterStandardSurface: PROC[context: REF Context, type: ATOM];
Procedures for Shading Patches
BackFacing: PROC[ context: REF Context, poly: REF Patch, useEyeSpace: BOOLEANFALSE]
    RETURNS [FacingDir];
Tests if polygon faces away from viewer, thus on back side of object
ShadePoly: PROC[ context: REF Context, poly: REF Patch];
ShadeVtx: ThreeDBasics.VertexInfoProc;
PROC[ context: REF Context, vtx: VertexInfo, data: REF ANYNIL ] RETURNS[VertexInfo]
Calculate shade at vertices of polygon
END.