IF cube #
NIL
AND cube.terminal
THEN {
FaceTry:
PROC [d: Direction]
RETURNS [corner: Corner ¬
NIL] ~ {
KidsTry:
PROC [o0a, o0b, o1a, o1b: Octant]
RETURNS [corner: Corner ¬
NIL] ~ {
IF c.kids[o0a] # NIL THEN RETURN[c.kids[o0a].corners[o0b]];
IF c.kids[o0b] # NIL THEN RETURN[c.kids[o0b].corners[o0a]];
IF c.kids[o1a] # NIL THEN RETURN[c.kids[o1a].corners[o1b]];
IF c.kids[o1b] # NIL THEN RETURN[c.kids[o1b].corners[o1a]];
};
c: Cube ~ neighbors[d];
IF c #
NIL
AND
NOT c.terminal
THEN corner ¬
SELECT d
FROM
l => KidsTry[rbn, rtf, rbf, rtn],
r => KidsTry[lbn, ltf, lbf, ltn],
b => KidsTry[ltn, rtf, ltf, rtn],
t => KidsTry[lbn, rbf, lbf, rbn],
n => KidsTry[lbf, rtf, ltf, rbf],
f => KidsTry[lbn, rtn, ltn, rbn]
ENDCASE => NIL;
};
EdgeTry:
PROC [d0, d1, d2: Direction, e0, e1, e2: Edge]
RETURNS [corner: Corner] ~ {
NeighborTry:
PROC [d: Direction, e: Edge]
RETURNS [corner: Corner ¬
NIL] ~ {
KidsTry:
PROC [o0, o1: Octant]
RETURNS [corner: Corner ¬
NIL] ~ {
IF c.kids[o0] # NIL THEN RETURN[c.kids[o0].corners[o1]];
IF c.kids[o1] # NIL THEN RETURN[c.kids[o1].corners[o0]];
};
c: Cube ~ neighbors[d];
IF c #
NIL
AND
NOT c.terminal
THEN corner ¬
SELECT e
FROM
lb => KidsTry[lbn, lbf],
lt => KidsTry[ltn, ltf],
ln => KidsTry[lbn, ltn],
lf => KidsTry[lbf, ltf],
rb => KidsTry[rbn, rbf],
rt => KidsTry[rtn, rtf],
rn => KidsTry[rbn, rtn],
rf => KidsTry[rbf, rtf],
bn => KidsTry[lbn, rbn],
bf => KidsTry[lbf, rbf],
tn => KidsTry[ltn, rtn],
tf => KidsTry[ltf, rtf],
ENDCASE => NIL;
};
corner ¬ NeighborTry[d0, e0];
IF corner = NIL THEN corner ¬ NeighborTry[d1, e1];
IF corner = NIL THEN corner ¬ NeighborTry[d2, e2];
};
SubCube:
PROC [octant: Octant, corners: Corners] ~ {
kid: Cube ~ cube.kids[octant] ¬ NewKid[cube, kSize, octant, kidLevel, corners];
kid.terminal ¬ TRUE;
kid.size ¬ kSize;
};
kSize: REAL ~ 0.5*Size[cube];
kidLevel: INT ~ cube.level+1;
c: Triple ~ Center[cube];
neighbors: Neighborhood ~ Neighbors[cube];
cornerDataProc: CornerDataProc ¬ NIL;
ccc: Corner ~ NewCorner[c, cornerDataProc];
lbn: Corner ~ cube.corners[lbn];
lbf: Corner ~ cube.corners[lbf];
ltn: Corner ~ cube.corners[ltn];
ltf: Corner ~ cube.corners[ltf];
rbn: Corner ~ cube.corners[rbn];
rbf: Corner ~ cube.corners[rbf];
rtn: Corner ~ cube.corners[rtn];
rtf: Corner ~ cube.corners[rtf];
lb: Corner ¬ EdgeTry[l, lb, b, rb, rt, lt];
lt: Corner ¬ EdgeTry[l, lt, t, rt, rb, lb];
ln: Corner ¬ EdgeTry[l, ln, n, rn, rf, lf];
lf: Corner ¬ EdgeTry[l, lf, f, rf, rn, ln];
rb: Corner ¬ EdgeTry[r, rb, b, lb, lt, rt];
rt: Corner ¬ EdgeTry[r, rt, t, lt, lb, rb];
rn: Corner ¬ EdgeTry[r, rn, n, ln, lf, rf];
rf: Corner ¬ EdgeTry[r, rf, f, lf, ln, rn];
bn: Corner ¬ EdgeTry[b, bn, n, tn, tf, bf];
bf: Corner ¬ EdgeTry[b, bf, f, tf, tn, bn];
tn: Corner ¬ EdgeTry[t, tn, n, bn, bf, tf];
tf: Corner ¬ EdgeTry[t, tf, f, bf, bn, tn];
l: Corner ¬ FaceTry[l];
r: Corner ¬ FaceTry[r];
b: Corner ¬ FaceTry[b];
t: Corner ¬ FaceTry[t];
n: Corner ¬ FaceTry[n];
f: Corner ¬ FaceTry[f];
IF lb = NIL THEN lb ¬ NewCorner[[c.x-kSize, c.y-kSize, c.z], cornerDataProc];
IF lt = NIL THEN lt ¬ NewCorner[[c.x-kSize, c.y+kSize, c.z], cornerDataProc];
IF ln = NIL THEN ln ¬ NewCorner[[c.x-kSize, c.y, c.z-kSize], cornerDataProc];
IF lf = NIL THEN lf ¬ NewCorner[[c.x-kSize, c.y, c.z+kSize], cornerDataProc];
IF rb = NIL THEN rb ¬ NewCorner[[c.x+kSize, c.y-kSize, c.z], cornerDataProc];
IF rt = NIL THEN rt ¬ NewCorner[[c.x+kSize, c.y+kSize, c.z], cornerDataProc];
IF rn = NIL THEN rn ¬ NewCorner[[c.x+kSize, c.y, c.z-kSize], cornerDataProc];
IF rf = NIL THEN rf ¬ NewCorner[[c.x+kSize, c.y, c.z+kSize], cornerDataProc];
IF bn = NIL THEN bn ¬ NewCorner[[c.x, c.y-kSize, c.z-kSize], cornerDataProc];
IF bf = NIL THEN bf ¬ NewCorner[[c.x, c.y-kSize, c.z+kSize], cornerDataProc];
IF tn = NIL THEN tn ¬ NewCorner[[c.x, c.y+kSize, c.z-kSize], cornerDataProc];
IF tf = NIL THEN tf ¬ NewCorner[[c.x, c.y+kSize, c.z+kSize], cornerDataProc];
IF l = NIL THEN l ¬ NewCorner[[c.x-kSize, c.y, c.z], cornerDataProc];
IF r = NIL THEN r ¬ NewCorner[[c.x+kSize, c.y, c.z], cornerDataProc];
IF b = NIL THEN b ¬ NewCorner[[c.x, c.y-kSize, c.z], cornerDataProc];
IF t = NIL THEN t ¬ NewCorner[[c.x, c.y+kSize, c.z], cornerDataProc];
IF n = NIL THEN n ¬ NewCorner[[c.x, c.y, c.z-kSize], cornerDataProc];
IF f = NIL THEN f ¬ NewCorner[[c.x, c.y, c.z+kSize], cornerDataProc];
cube.terminal ¬ FALSE;
SubCube[lbn, [lbn, lb, ln, l, bn, b, n, ccc]];
SubCube[lbf, [lb, lbf, l, lf, b, bf, ccc, f]];
SubCube[ltn, [ln, l, ltn, lt, n, ccc, tn, t]];
SubCube[ltf, [l, lf, lt, ltf, ccc, f, t, tf]];
SubCube[rbn, [bn, b, n, ccc, rbn, rb, rn, r]];
SubCube[rbf, [b, bf, ccc, f, rb, rbf, r, rf]];
SubCube[rtn, [n, ccc, tn, t, rn, r, rtn, rt]];
SubCube[rtf, [ccc, f, t, tf, r, rf, rt, rtf]];
};