Types
Triple: TYPE ~ G3dBasic.Triple;
IntTriple: TYPE ~ G3dTriangle.IntTriple;
IntTriples: TYPE ~ G3dTriangle.IntTriples;
Segments: TYPE ~ G3dTriangle.Segments;
Triangle: TYPE ~ G3dTriangle.Triangle;
Triangles: TYPE ~ G3dTriangle.Triangles;
CornerState:
TYPE ~ {unset, positive, negative};
Corner:
TYPE ~
RECORD [
id: IntTriple,
pos: Triple,
value: REAL ¬ 0,
state: CornerState,
on: BOOL ¬ FALSE];
TwoCorners: TYPE ~ RECORD [a, b: REF Corner];
ThreeCorners: TYPE ~ RECORD [a, b, c: REF Corner];
ThreeEdges:
TYPE ~
RECORD [a, b, c: TetEdge];
Cube:
TYPE ~
RECORD [
id: IntTriple, -- corresponds with cube.lbn.id
lbn, lbf, ltn, ltf: REF Corner,
rbn, rbf, rtn, rtf: REF Corner,
l, r, b, t, n, f, diag: REAL];
CubeProc:
TYPE ~
PROC
[cube:
REF
Cube,
inCube:
REF
Triangles]
--
incube
intersect
cube
RETURNS [continue: BOOL ¬ TRUE];
TetFace: TYPE ~ {abc, abd, acd, bcd};
TetEdge: TYPE ~ {ab, ac, ad, bc, bd, cd};
TetProc:
TYPE ~
PROC [tet:
REF Tetrahedron]
RETURNS [continue:
BOOL ¬
TRUE];
Tetrahedron:
TYPE ~
RECORD
[
a, b, c, d: REF Corner ¬ NIL, -- b, c, d to appear cw viewed from a
cube: REF Cube ¬ NIL, -- the "parent" cube
triangles: ARRAY TetFace OF REF Triangle,
which: INT -- relation to cube, should be IN [0..5)
];
TetIntersection: TYPE ~ RECORD [point: Triple, inside: BOOL, face: TetFace];
TetIntersections: TYPE ~ RECORD [length:INT¬0,s:SEQUENCE maxLength:INT OF TetIntersection];
TetIntersectProc:
TYPE ~
PROC [nEdges:
INT, e1, e2, e3, e4: TetEdge];
EventType: TYPE ~ {entry, exit, inside, graze};
Event: TYPE ~ RECORD [p: Triple, type: EventType, face: TetFace, seg: INT];
Events: TYPE ~ RECORD [length: INT ¬ 0, s: SEQUENCE maxLength: INT OF Event];
Tetrahedra
BoundaryIntersectTet:
PROC
[
tet: REF Tetrahedron,
segments: REF Segments,
insideToo: BOOL ¬ TRUE,
scratch: REF TetIntersections ¬ NIL]
RETURNS [REF TetIntersections];
Return intersections of segments with tet and intervening (internal to tet) points, in order.
GetEvents:
PROC
[
tet: REF Tetrahedron,
segments: REF Segments,
epsilon: REAL,
insideToo: BOOL,
scratch: REF Events ¬ NIL]
RETURNS [REF Events];
Return the events that occur when segments is intersected with tet.
TetCenter:
PROC [tet:
REF Tetrahedron]
RETURNS [Triple];
Return the center of the tetrahedron.
ObtainTetIntersections:
PROC
RETURNS [
REF TetIntersections];
Obtain a sequence from a scratch pool.
ReleaseTetIntersections:
PROC [scratch:
REF TetIntersections];
Return the scratch sequence to the scratch ool.
IntersectWithSurface:
PROC [tet:
REF Tetrahedron,
action:
TetIntersectProc];
Call action according to the polarities of tet.
FaceName:
PROC [f: TetFace]
RETURNS [
ROPE];
Return the name of the face.
EdgeName:
PROC [e: TetEdge]
RETURNS [
ROPE];
Return the name of the edge.
CornerName:
PROC [c:
REF Corner, tet:
REF Tetrahedron]
RETURNS [
ROPE];
Return the name of the corner.
EventName:
PROC [e: Event]
RETURNS [
ROPE];
Return the name of the event type.
MakeTetrahedron:
PROC [a, b, c, d:
REF Corner, which:
INT, scratch:
REF Tetrahedron ¬
NIL]
RETURNS [REF Tetrahedron];
Construct a tetrahedron from the four points; which should be IN [0..5).
TriangleInTetrahedron:
PROC [t:
REF Triangle, tet:
REF Tetrahedron]
RETURNS [
BOOL];
Check if triangle penetrates the tetrahedron; t presumed to intersect cube containing tet.
TrianglesInTetrahedron:
PROC [
candidates: REF Triangles,
tet: REF Tetrahedron,
scratch: REF Triangles ¬ NIL]
RETURNS [REF Triangles];
Return those candidate triangles that intersect the tetrahedron.
InsideTetrahedron:
PROC [t:
REF Tetrahedron, p: Triple]
RETURNS [
BOOL];
Test if the point is inside the tetrahedron.
EdgesFromFace:
PROC [f: TetFace]
RETURNS [ThreeEdges];
Return the three edges constituting the given face.
CornersFromFace:
PROC [f: TetFace, t:
REF Tetrahedron]
RETURNS [ThreeCorners];
Return the three corners constituting the given face of the tetrahedron.
CornersFromEdge:
PROC [e: TetEdge, t:
REF Tetrahedron]
RETURNS [TwoCorners];
Return the two corners constituting the given edge of the tetrahedron.
MidEdge:
PROC [tet:
REF Tetrahedron, e: TetEdge]
RETURNS [Triple];
Return the point midway along the given edge of the given tetrahedron.
LRFaces:
PROC [e: TetEdge]
RETURNS [l, r: TetFace];
Return the left and right face of the given directed edge.
LFace:
PROC [e: TetEdge]
RETURNS [f: TetFace];
Return the left face of the given directed edge.
RFace:
PROC [e: TetEdge]
RETURNS [f: TetFace];
Return the right face of the given directed edge.
Cubes
Decompose:
PROC [c:
REF Cube, action: TetProc, scratch:
REF Tetrahedron ¬
NIL];
Decompose the cube into five tetrahedra, calling proc for each.
GetTetN:
PROC [c:
REF Cube, which:
INT, scratch:
REF Tetrahedron ¬
NIL]
RETURNS [REF Tetrahedron];
Return the specified tetrahedron of the decomposed cube; which should be IN [0..5).
IDFromPoint:
PROC [p: Triple, size:
REAL, offset: Triple ¬ []]
RETURNS [IntTriple];
Return the cube center ID given the cube center and size.
PointFromID:
PROC [id: IntTriple, size:
REAL]
RETURNS [p: Triple];
Return the lattice point given its integer coordinates and grid size.
SetCube:
PROC [
id: IntTriple,
lbn, lbf, ltn, ltf, rbn, rbf, rtn, rtf: REF Corner,
offset: Triple ¬ [],
scratch: REF Cube ¬ NIL]
RETURNS [REF Cube];
Return a cube given its id and eight corners.
MakeCube:
PROC [id: IntTriple, size:
REAL, offset: Triple ¬ [], scratch:
REF Cube ¬
NIL]
RETURNS [REF Cube];
Create a cube given its id and size; reuse scratch if non-NIL.
TriangleInCube:
PROC [t:
REF Triangle, c:
REF Cube]
RETURNS [
BOOL];
Check if the given triangle penetrates the cube.
TrianglesInCube:
PROC [
candidates: REF Triangles,
cube: REF Cube,
scratch: REF Triangles ¬ NIL]
RETURNS [REF Triangles];
Return those candidate triangles that intersect the cube.