G3dPlaneImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Ken Fishkin, August 20, 1992 4:16 pm PDT
Jules Bloomenthal July 14, 1992 3:56 pm PDT
DIRECTORY G3dBasic, G3dIO, G3dMatrix, G3dTetrahedron, IO, Rope;
G3dTetrahedronImpl: CEDAR PROGRAM
IMPORTS G3dIO, G3dMatrix, IO
EXPORTS G3dTetrahedron
~ BEGIN
Error:  PUBLIC ERROR [reason: ROPE] ~ CODE;
debug:  IO.STREAM ¬ NIL;
ROPE:   TYPE ~ Rope.ROPE;
Tetrahedron: TYPE ~ G3dTetrahedron.Tetrahedron;
TetrahedronRep: TYPE ~ G3dTetrahedron.TetrahedronRep;
Creation
Create: PUBLIC PROC [p0, p1,p2,p3: G3dBasic.Triple] RETURNS [Tetrahedron] ~ {
ans: Tetrahedron ¬ NEW[TetrahedronRep];
ans.fromBary ¬ NEW[G3dMatrix.MatrixRep];
ans.fromBary[0] ¬ [p0.x,p0.y,p0.z,1.0];
ans.fromBary[1] ¬ [p1.x,p1.y,p1.z,1.0];
ans.fromBary[2] ¬ [p2.x,p2.y,p2.z,1.0];
ans.fromBary[3] ¬ [p3.x,p3.y,p3.z,1.0];
ans.from3d ¬ G3dMatrix.Invert[ans.fromBary];
RETURN [ans];
};
Copy: PUBLIC PROC [t: Tetrahedron] RETURNS [Tetrahedron] ~ {
ans: Tetrahedron;
IF t = NIL THEN RETURN[NIL];
ans ¬ NEW[TetrahedronRep];
ans.from3d ¬ G3dMatrix.CopyMatrix[t.from3d];
ans.fromBary ¬ G3dMatrix.CopyMatrix[t.fromBary];
RETURN [ans];
};
Operation
MapFrom3D: PUBLIC PROC [t: Tetrahedron, pt: G3dBasic.Quad] RETURNS [G3dBasic.Quad] ~ {
IF t = NIL THEN ERROR Error["null Tetrahedron"];
RETURN [G3dMatrix.TransformQuad[pt, t.from3d]];
};
MapFromBarycentric: PUBLIC PROC [t: Tetrahedron, pt: G3dBasic.Quad] RETURNS [G3dBasic.Quad] ~ {
IF t = NIL THEN ERROR Error["null Tetrahedron"];
RETURN [G3dMatrix.TransformQuad[pt, t.fromBary]];
};
IsInside: PUBLIC PROC [t: Tetrahedron, pt: G3dBasic.Quad, tol: REAL ¬ 0.001] RETURNS [BOOL] ~ {
bary: G3dBasic.Quad ¬ MapFrom3D[t,pt];
sum: REAL;
IF debug # NIL THEN {
IO.PutFL[debug,"Tet.IsInside: [%g,%g,%g,%g]",
LIST[IO.real[pt.x], IO.real[pt.y], IO.real[pt.z], IO.real[pt.w]]];
IO.PutFL[debug," maps to [%g,%g,%g,%g]\n",
LIST[IO.real[bary.x], IO.real[bary.y], IO.real[bary.z], IO.real[bary.w]]];
};
IF bary.x + tol < 0.0 THEN {
RETURN [FALSE];
};
IF bary.y + tol < 0.0 THEN {
RETURN [FALSE];
};
IF bary.z + tol < 0.0 THEN {
RETURN [FALSE];
};
IF bary.w + tol < 0.0 THEN {
RETURN [FALSE];
};
sum ¬ bary.x + bary.y + bary.z + bary.w;
RETURN [IF sum < 1.0 THEN sum+tol >= 1.0 ELSE sum-tol <= 1.0];
};
BoundingBox: PUBLIC PROC [t: Tetrahedron] RETURNS [ans: G3dBasic.Box] ~ {
mins: ARRAY[0 .. 3) OF REAL;
maxes: ARRAY[0 .. 3) OF REAL;
FOR col: INT IN [0 .. 3) DO
mins[col] ¬ t.fromBary[0][col];
maxes[col] ¬ mins[col];
ENDLOOP;
FOR row: INT IN [1.. 4) DO
FOR col: INT IN [0.. 3) DO
IF t.fromBary[row][col] < mins[col] THEN mins[col] ¬ t.fromBary[row][col];
IF t.fromBary[row][col] > maxes[col] THEN maxes[col] ¬ t.fromBary[row][col];
ENDLOOP;
ENDLOOP;
ans.min ¬ [mins[0], mins[1], mins[2]];
ans.max ¬ [maxes[0], maxes[1], maxes[2]];
RETURN [ans];
};
I/O
Read: PUBLIC PROC [s: IO.STREAM] RETURNS [Tetrahedron] ~ {
ans: Tetrahedron ¬ NEW[TetrahedronRep];
ans.from3d ¬ G3dIO.ReadMatrix[s];
ans.fromBary ¬ G3dIO.ReadMatrix[s];
RETURN [ans];
};
Write: PUBLIC PROC [t: Tetrahedron, s: IO.STREAM] ~ {
G3dIO.WriteMatrix[s, t.from3d];
G3dIO.WriteMatrix[s, t.fromBary];
};
Debug
Debug: PUBLIC PROC [dbg: IO.STREAM] ~ {
debug ¬ dbg;
};
END.