DIRECTORY G2dBasic, G3dBasic, RefTab, Rope; G3dVoxel: CEDAR DEFINITIONS ~ BEGIN 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 Error: SIGNAL [reason: ATOM]; 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]; Store: PROC [voxels: Voxels, address: Nat3, voxel: REF]; RetrieveFromVoxels: PROC [voxels: Voxels, address: Nat3] RETURNS [REF]; 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]; SetGridBox: PROC [grid: Grid, box: Box]; AllocateGridValues: PROC [res: Nat3] RETURNS[Reals3d]; PointFromIJK: PROC [grid: Grid, i, j, k: NAT] RETURNS [Triple]; RetrieveFromGrid: PROC [grid: Grid, q: Triple] RETURNS [REAL]; ReadGridFromFile: PROC [fileName: ROPE] RETURNS [Grid]; WriteGridToFile: PROC [grid: Grid, fileName: ROPE, comment: ROPE ¬ NIL]; GridFromVoxels: PROC [voxels: Voxels, realProc: RealProc] RETURNS [Grid]; END. φ G3dVoxel.mesa Copyright Σ 1985, 1992 by Xerox Corporation. All rights reserved. Bloomenthal, July 15, 1992 11:07 pm PDT Type Declarations Errors Storage and Retrieval of Voxel Data 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 a ref into voxels. ! Error[$addressOutOfRange] ! Error[$noVoxels] Retrieve a ref from voxels. ! Error[$addressOutOfRange] ! Error[$noVoxels] Storage and Retrieval of Function Values Within A Grid Create a grid. The indices x, y, and z must be in ascending order. Can raise Error[$badIndices]. Scale and offset grid.x, grid.y and grid.z sequences so that the grid occupies box. Allocate the refs. Return the point that maps to grid[i][j][k]. Retrieve a value from the grid. If q is out of grid's range, then Error[$outOfRange]. Read the grid data from a file, presumed to be formatted as: NumberOfIndices~ 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]. Write the grid data to the named file. Create a grid from the voxel array; a voxel value is determined by realProc. Κγ•NewlineDelimiter –"cedarcode" style™™ Jšœ Οeœ6™BJ™'J˜JšΟk œ"˜+J˜—šΠblœžœž ˜J˜—Jšœž˜headšΟl™šžœžœžœ˜J˜—Jšœž œ˜Jšœ žœ˜ Jšœ žœ˜ J˜Jšœ žœΟc˜:Jšœžœ‘˜?Jšœžœ˜2Jšœžœ‘˜2—š ™JšΟnœžœ žœ˜—š #™#Jš œž œžœžœ žœžœžœ˜?Jš œ žœžœžœ žœžœžœ˜Eš œžœžœžœ žœžœžœ˜GJ˜—Jšœ žœžœ ˜!šœ žœžœ˜Jšœ žœžœ‘˜.Jšœ‘˜/Jšœžœ‘ ˜1Jšœ"‘˜2Jšœžœ žœ‘˜*Jšœžœžœžœ‘˜;J˜J˜—š ’ œžœ žœžœ žœžœ˜RJšžœ ˜J™G™VJ™—J˜—š’œžœ(žœ˜8™J™J™—J˜—š’œžœ!žœžœ˜G™J™J™———š 6™6Jšœ žœžœ‘˜<šœ žœžœ‘˜?J˜—šœ žœžœ˜Jšœžœ˜Jšœžœ žœžœ˜>—šœ žœžœ˜Jšœžœ˜Jšœžœ žœžœ ˜9J˜—š œžœžœžœžœžœ žœ˜?J˜—Jšœ žœžœ ˜šœ žœžœ˜Jšœ‘˜0Jšœžœžœ‘˜;Jšœ‘˜;Jšœ‘˜.Jšœžœ‘˜CJšœžœ‘˜4Jšœžœžœ‘˜8J˜J˜—š’ œžœ˜Jšœ‘˜1Jšœ‘.˜AJšœžœ‘0˜MJšœ žœžœ˜Jšžœ˜JšœC™CJšœ™J˜—š’ œžœ˜(J™SJ™—š’œžœ žœ ˜6J™J™—š’ œžœžœžœ ˜?J™,J™—š’œžœžœžœ˜>J™VJ™—š’œžœ žœžœ˜7™