G3dVoxel.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 15, 1992 11:07 pm PDT
DIRECTORY G2dBasic, G3dBasic, RefTab, Rope;
G3dVoxel: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
ROPE:      TYPE ~ Rope.ROPE;
Table:      TYPE ~ RefTab.Ref;
Nat3:      TYPE ~ G2dBasic.Nat3;
Type:      TYPE ~ {hash, array};
Triple:     TYPE ~ G2dBasic.Triple;    -- a point in space
RealSequence:   TYPE ~ G2dBasic.RealSequence;  -- sequence of x
RealSequenceRep:  TYPE ~ G2dBasic.RealSequenceRep;
Box:      TYPE ~ G3dBasic.Box;     -- bounding box
Errors
Error: SIGNAL [reason: ATOM];
Storage and Retrieval of Voxel Data
Refs:      TYPE ~ RECORD [SEQUENCE maxLength: CARDINAL OF REF];
Refs2d:     TYPE ~ RECORD [SEQUENCE maxLength: CARDINAL OF REF Refs];
Refs3d:     TYPE ~ RECORD [SEQUENCE maxLength: CARDINAL OF REF Refs2d];
Voxels:     TYPE ~ REF VoxelsRep;
VoxelsRep:    TYPE ~ RECORD [
name:        ROPE ¬ NIL,     -- name of Voxels
type:        Type ¬ hash,    -- type of Voxels
hashTable:      RefTab.Ref ¬ NIL,   -- hash table
size:        Nat3 ¬ [0, 0, 0],    -- size of array
array:        REF Refs3d ¬ NIL,   -- array
clientData:      REF ANY ¬ NIL    -- for miscellaneous data
];
CreateVoxels: PROC [sparse: BOOL ¬ TRUE, size: Nat3 ¬ [0, 0, 0], name: ROPE ¬ NIL]
RETURNS [Voxels];
Initialize the voxels data structure. If sparse, a hash table is used.
Otherwise a three-dimensional array dimensioned size.i by size.j by size.k is created.
! Error[$sizeTooGreat].
Store: PROC [voxels: Voxels, address: Nat3, voxel: REF];
Store a ref into voxels.
! Error[$addressOutOfRange]
! Error[$noVoxels]
RetrieveFromVoxels: PROC [voxels: Voxels, address: Nat3] RETURNS [REF];
Retrieve a ref from voxels.
! Error[$addressOutOfRange]
! Error[$noVoxels]
Storage and Retrieval of Function Values Within A Grid
Reals2d:     TYPE ~ REF Reals2dRep;    -- sequence of [x][y]
Reals3d:     TYPE ~ REF Reals3dRep;    -- sequence of [x][y][z]
Reals2dRep:    TYPE ~ RECORD [
length:        CARDINAL ¬ 0,
element:        SEQUENCE maxLength: CARDINAL OF RealSequence];
Reals3dRep:    TYPE ~ RECORD [
length:        CARDINAL ¬ 0,
element:        SEQUENCE maxLength: CARDINAL OF Reals2d];
RealProc:     TYPE ~ PROC [ref: REF ANY] RETURNS [value: REAL];
Grid:      TYPE ~ REF GridRep;
GridRep:     TYPE ~ RECORD [
res:        Nat3 ¬ [],     -- resolution of data
evenlySpaced:     BOOL ¬ TRUE,    -- if spacing is constant
scale:        Triple ¬ [],     -- scale factor for indexing
box:        Box ¬ [],    -- domain of the grid
x, y, z:       RealSequence ¬ NIL,  -- indices along the three axes
values:       Reals3d ¬ NIL,    -- functional values
clientData:      REF ¬ NIL     -- for miscellaneous data
];
CreateGrid: PROC [
values: Reals3d,     -- values at the grid points
box: Box ¬ [],     -- domain of the grid, presuming equal spacing
x, y, z: RealSequence ¬ NIL, -- domain of the grid, presuming unequal spacing
clientData: REF ¬ NIL]
RETURNS [Grid];
Create a grid. The indices x, y, and z must be in ascending order.
Can raise Error[$badIndices].
SetGridBox: PROC [grid: Grid, box: Box];
Scale and offset grid.x, grid.y and grid.z sequences so that the grid occupies box.
AllocateGridValues: PROC [res: Nat3] RETURNS[Reals3d];
Allocate the refs.
PointFromIJK: PROC [grid: Grid, i, j, k: NAT] RETURNS [Triple];
Return the point that maps to grid[i][j][k].
RetrieveFromGrid: PROC [grid: Grid, q: Triple] RETURNS [REAL];
Retrieve a value from the grid. If q is out of grid's range, then Error[$outOfRange].
ReadGridFromFile: PROC [fileName: ROPE] RETURNS [Grid];
Read the grid data from a file, presumed to be formatted as:
NumberOfIndices~ <xRes> <yRes> <zRes>
XLocations~
sequence of reals (if only min and max specified, presumes even spacing)
YLocations~
sequence of reals (if only min and max specified, presumes even spacing)
ZLocations~
sequence of reals (if only min and max specified, presumes even spacing)
Values~
sequence of reals, looping most rapidly through zRes and most slowly through xRes.
! Error[$NoSuchFile].
! Error[$UnspecifiedDomain].
WriteGridToFile: PROC [grid: Grid, fileName: ROPE, comment: ROPE ¬ NIL];
Write the grid data to the named file.
GridFromVoxels: PROC [voxels: Voxels, realProc: RealProc] RETURNS [Grid];
Create a grid from the voxel array; a voxel value is determined by realProc.
END.