Directions, Edges, Faces, Octants
There are six basic directions:
l: left (lesser in x), r: right (greater in x),
b: bottom (lesser in y), t: top (greater in y),
n: near (lesser in z), f: far (greater in z)
Axis: TYPE ~ {x, y, z}; -- edge alignment
Face: TYPE ~ {l, r, b, t, n, f};
TwoFaces: TYPE ~ RECORD [f0, f1: Face];
ActiveFaces: TYPE ~ ARRAY Face OF BOOL ¬ ALL[FALSE];
Edge: TYPE ~ {lb, lt, ln, lf, rb, rt, rn, rf, bn, bf, tn, tf};
ThreeEdges: TYPE ~ RECORD [e0, e1, e2: Edge];
Direction:
TYPE ~ {
l, r, b, t, n, f, -- faces
lb, lt, ln, lf, rb, rt, rn, rf, bn, bf, tn, tf, -- edges
lbn, lbf, ltn, ltf, rbn, rbf, rtn, rtf, -- corners
c, none -- center, none
};
DirectionType: TYPE ~ {none, face, edge, corner};
DirectionSelect: TYPE ~ {x, y, z, xy, xz, yz, xyz, none};
DirectionPairs: TYPE ~ ARRAY Direction OF Pair;
TwoDirections: TYPE ~ RECORD [d0, d1: Direction];
ThreeDirections: TYPE ~ RECORD [d0, d1, d2: Direction];
FourDirections:
TYPE ~
RECORD [d0, d1, d2, g3d: Direction];
Octant:
TYPE ~
MACHINE
DEPENDENT {
lbn(0), lbf(1), ltn(2), ltf(3), -- left corners
rbn(4), rbf(5), rtn(6), rtf(7) -- right corners
};
OctantPairs: TYPE ~ ARRAY Octant OF Pair;
TwoOctants: TYPE ~ RECORD [o0, o1: Octant];
FourOctants:
TYPE ~
RECORD [o0, o1, o2, o3: Octant];
FaceNeighborInfo: TYPE ~ RECORD [nOctant: Octant, recurse: BOOL];
Corners
Corner: TYPE ~ REF CornerRep;
CornerRep:
TYPE ~
RECORD [
point: Triple ¬ [], -- location of corner
outOfRange: BOOL ¬ FALSE, -- corner not in function domain
valueSet: BOOL ¬ FALSE, -- true if value computed
value: REAL ¬ 0.0, -- surface value at corner
inside: BOOL ¬ FALSE, -- if valueSet & value > 0
nearestSet: BOOL ¬ FALSE, -- true iff nearest computed
nearest: Triple ¬ [], -- surface point nearest to corner
squareDistance: REAL ¬ 0.0, -- square-distance to nearest
lCross: Cross ¬ NIL, -- leftward surface intersection
bCross: Cross ¬ NIL, -- bottomward surface intersection
nCross: Cross ¬ NIL -- nearward surface intersection
];
TwoCorners: TYPE ~ RECORD [c0, c1: Corner];
FourCorners: TYPE ~ RECORD [c0, c1, c2, c3: Corner];
Corners: TYPE ~ ARRAY Octant OF Corner;
DirectionCorners: TYPE ~ ARRAY Direction OF Corner;
Cubes, Cube Sequences, and CubeStacks
Cube: TYPE ~ REF CubeRep;
CubeRep:
TYPE ~
RECORD [
parent: Cube ¬ NIL, -- parent cube
size: REAL ¬ 1.0, -- length of an edge
octant: Octant ¬ lbn, -- relation to parent cube
level: INT ¬ 0, -- recursion depth
terminal: BOOL ¬ FALSE, -- if true, leaf node
corners: Corners ¬ ALL[NIL], -- corner locations and info
kids: Kids ¬ ALL[NIL], -- subdivided cube
crossesComputed: BOOL ¬ FALSE, -- true if
surfaceCrossed: BOOL ¬ FALSE, -- true iff surface crosses cube
refAny: REF ANY ¬ NIL]; -- a potentially useful pointer
Kids: TYPE ~ ARRAY Octant OF Cube;
Neighborhood: TYPE ~ ARRAY Direction OF Cube ¬ ALL[NIL]; -- neighbors of a cube
TwoCubes: TYPE ~ RECORD [c0, c1: Cube];
ThreeCubes:
TYPE ~
RECORD [c0, c1, c2: Cube];
CubeStack: TYPE ~ REF CubeStackRep;
CubeStackRep:
TYPE ~
RECORD [
top: INT ¬ 0,
bottom: INT ¬ 0,
size: INT ¬ 0,
maxSize: INT ¬ 0,
element: SEQUENCE maxLength: INT OF Cube];
CubeSequence: TYPE ~ REF CubeSequenceRep;
CubeSequenceRep:
TYPE ~
RECORD [
length: INT ¬ 0,
element: SEQUENCE maxLength: INT OF Cube];
Octrees
OctreeMode:
TYPE ~
RECORD [
postAdaptMax: INT ¬ 0, -- max subdivs beyond terminal, given octree
flatness: REAL ¬ 30.0, -- criterion in degrees for adaptive subdivision
tolerance: REAL ¬ 0.0001, -- tolerance for edge convergence
type:
SELECT OctreeType: OctreeType
FROM
converge => [
rootSize: REAL, -- size of octree
recurseMin: INT ¬ 1, -- min # of subdivisions of octree
recurseMax: INT ¬ 5], -- max # of subdivisions of octree
track => [
cubeSize: REAL ¬ 0.05, -- size of initial cube
surfacePoint: Triple ¬ [], -- a point on the surface
duringAdaptMax: INT ¬ 0], -- max # subdivisions during tracking
ENDCASE];
OctreeType:
TYPE ~ {track, converge};
Octree: TYPE ~ REF OctreeRep;
OctreeRep:
TYPE ~
RECORD [
root: Cube ¬ NIL, -- the octree root
mode: OctreeMode ¬ [,,, track[]], -- way octree was constructed
depth: INT ¬ 0, -- level of most deeply recursed
name: ROPE ¬ NIL, -- name of octree
errorMsg: ROPE ¬ NIL, -- error message during creation
radius, terminalRadius: REAL ¬ 0.0, -- half edge length of root, leaf
diameter, terminalDiameter: REAL ¬ 0.0, -- edge length of root, leaf
nCubes, nTerminalCubes: CARD ¬ 0, -- # of cubes and terminal cubes
truncated: BOOL ¬ FALSE, -- if octree truncates a surface
completed: BOOL ¬ FALSE, -- if octree creation not aborted
nFaceDepthChanges: INT ¬ 0, -- # terminal faces/non-terminal
nRecursiveTrackFailures: INT ¬ 0, -- # anomalies: facedepth changes
refAny: REF ANY ¬ NIL] ; -- a potentially useful pointer
Cube Crossing a Surface
Cross: TYPE ~ REF CrossRep;
CrossRep:
TYPE ~
RECORD [
id: INT ¬ -1, -- vertex id
value: REAL ¬ 0.0, -- spatial value
point: Triple ¬ [], -- location of surface vertex
normal: Triple ¬ [], -- if not origin, normal at point
ok: BOOL ¬ TRUE]; -- FALSE if subsequently rejected
CrossArray:
TYPE ~
ARRAY Edge
OF Cross;
CrossSequence: TYPE ~ REF CrossSequenceRep;
CrossSequenceRep:
TYPE ~
RECORD [
length: INT ¬ 0,
element: SEQUENCE maxLength: INT OF Cross];
CrossedEdge:
TYPE ~
RECORD [
-- a surface-crossedEdge edge
cIn, cOut: Corner ¬ NIL, -- inside and outside corners
oIn, oOut: Octant]; -- and their octants
CrossedEdges: TYPE ~ ARRAY Edge OF CrossedEdge; -- possible edge-surface inter.
Corner Operations
EdgeCorners:
PROC [cube: Cube, edge: Edge]
RETURNS [TwoCorners];
Return the two corners at cube's edge.
In the TwoCorners record, l precedes r, b precedes t, and n precedes f.
FaceCorners:
PROC [cube: Cube, face: Face]
RETURNS [FourCorners];
Return the four corners along cube's face. Corners are clockwise if viewed from outside.
NewCorners:
PROC [size:
REAL, center: Triple, cornerDataProc: CornerDataProc ¬
NIL]
RETURNS [Corners];
Compute the corners of a cube given its center and size.
GetDirectionCorner:
PROC [cube: Cube, d: Direction]
RETURNS [c: Corner];
Return the corner lying in the given direction.
GetDirectionCorners:
PROC [cube: Cube]
RETURNS [DirectionCorners];
Return the 27 corners of cube's children.
An error may occur if any of cube.kids is undefined.
Axis, Edge, Face, Octant, Direction Operations
EdgesFromOctant:
PROC [octant: Octant]
RETURNS [ThreeEdges];
Return the three edges that emanate from octant.
DirectionsFromOctant:
PROC [octant: Octant]
RETURNS [ThreeDirections];
Return the three Directions that create octant.
FaceFromEdgeOctant:
PROC [edge: Edge, octant: Octant]
RETURNS [Face];
face traversed cw by edge starting at octant; no checking that octant agrees with edge.
NextCWEdge:
PROC [edge: Edge, face: Face]
RETURNS [Edge];
Return the next edge clockwise around face; no checking that edge and face agree.
NextCCWEdge:
PROC [edge: Edge, face: Face]
RETURNS [Edge];
Return the next edge counter-clockwise around face; no checking that edge and face agree.
EdgeDirections:
PROC [edge: Edge]
RETURNS [ThreeDirections];
Return the three directions that cubes can lie around an edge.
EdgeFaces:
PROC [edge: Edge]
RETURNS [TwoFaces];
Return the two faces around a cube's edge.
EdgeOctants:
PROC [edge: Edge]
RETURNS [TwoOctants];
Return the two octants at a cube's edge.
In the TwoOctants record, l precedes r, b precedes t, and n precedes f.
FaceOctants:
PROC [face: Face]
RETURNS [FourOctants];
Return the four octants along face. Octants are clockwise if viewed from outside.
OppositeEdge:
PROC [edge: Edge, face: Face]
RETURNS [Edge];
Return the edge on the opposite side of face.
InverseEdge:
PROC [edge: Edge, face: Face]
RETURNS [Edge];
Return the edge as shared by a cube with face adjacency.
DiagonalEdge:
PROC [edge: Edge]
RETURNS [Edge];
Return the edge diagonally across the cube.
OtherFace:
PROC [edge: Edge, face: Face]
RETURNS [Face];
Return the face on the other side of edge from face.
AxisFromEdge:
PROC [edge: Edge]
RETURNS [Axis];
Return the axis aligned with the edge.
DirectionTypeFromDirection:
PROC [direction: Direction]
RETURNS [DirectionType];
Return the direction type given the direction.
DirectionFromFace:
PROC [face: Face]
RETURNS [Direction];
Return the direction that is the face.
DirectionFromEdge:
PROC [edge: Edge]
RETURNS [Direction];
Return the direction that is the edge.
DirectionFromOctant:
PROC [octant: Octant]
RETURNS [Direction];
Return the direction that is the octant.
DirectionFromOctants:
PROC [octant0, octant1: Octant]
RETURNS [Direction];
Return the direction which takes octant0 to octant1.
DirectionFromPoints:
PROC [point0, point1: Triple]
RETURNS [Direction];
Return direction taking point0 to point1 (none if the points aren't aligned on the grid).
OppositeOctant:
PROC [octant: Octant]
RETURNS [Octant] ~
INLINE {
RETURN[VAL[ORD[LAST[Octant]]-ORD[octant]]]};
Return the opposite octant.
OppositeFace:
PROC [face: Face]
RETURNS [Face];
Return the face opposite face.
OppositeDirection:
PROC [direction: Direction]
RETURNS [Direction];
Return the opposite direction of direction.
AddDirection:
PROC [d0, d1: Direction]
RETURNS [Direction];
Return the result of applying d1 to d0
(eg., return none if d0 = l and d1 = r; return lb if d0 = l and d1 = b).
EdgeFromDirection:
PROC [d: Direction]
RETURNS [Edge];
Return the edge that is the direction d; ERROR raised if d is not an edge direction.
OctantFromDirection:
PROC [d: Direction]
RETURNS [Octant];
Return the octant that is the direction d; ERROR raised if d is not an octant direction.
OctantFromThreeDirections:
PROC [d0, d1, d2: Direction]
RETURNS [Octant];
Return the octant that is in the direction given by the sum of d0, d1, and d2.
FaceFromDirection:
PROC [d: Direction]
RETURNS [Face];
Return the face that is the direction d; ERROR raised if d is not an face direction.
FaceDirections:
PROC [face: Face]
RETURNS [FourDirections];
Return the directions associated with the four corners of face.
NormalFromFace:
PROC [face: Face]
RETURNS [Triple];
Return the face normal.
Cube Stack Support Procedures
NewCubeStack:
PROC [length:
INT]
RETURNS [CubeStack];
Create a new stack of cubes capable of storing length cubes
WriteBottomOfCubeStack:
PROC [cube: Cube, cubeStack: CubeStack];
Add cube to the bottom of the stack; may raise ERROR StackOverflow.
ReadTopOfCubeStack:
PROC [cubeStack: CubeStack]
RETURNS [cube: Cube];
Read a cube from the top of the stack; may raise ERROR StackUnderflow.
CubeStackSize:
PROC [cubeStack: CubeStack]
RETURNS [
INT];
Return the current number of cubes in the stack.
MaxCubeStackSize:
PROC [cubeStack: CubeStack]
RETURNS [
INT];
Return the maximum size obtained by cubeStack.
CubeStackEmpty:
PROC [cubeStack: CubeStack]
RETURNS [
BOOL];
Return true iff there are no cubes in the stack.
LengthenCubeStack:
PROC [cubeStack: CubeStack, amount:
REAL ¬ 1.3]
RETURNS [CubeStack];
Return a copy of the input CubeStack whose maxLength is amount*input.maxLength.