DIRECTORY CedarProcess, Commander, Controls, Draw2d, G2dVector, G3dDraw, G3dShape, G3dTool, G3dVector, ImplicitDefs, ImplicitTet, IO;
ImplicitTestDesignImpl: CEDAR PROGRAM
IMPORTS CedarProcess, Commander, Controls, G2dVector, G3dDraw, G3dShape, G3dTool, G3dVector, ImplicitTet, IO
~ BEGIN
Data: TYPE ~ RECORD [tool3d: G3dTool.Tool, size: REAL ← 0.05, p1, p2, p3: G3dVector.Triple];
ImplicitTest: Commander.CommandProc ~ {
d: REF Data ← NEW[Data];
d.tool3d ← G3dTool.MakeTool[
"Implicit Test",
LIST[Controls.ClickButton["Size", Size, d], Controls.ClickButton["Triangles", Triangles, d]],,,,
[data: d, draw: Draw]];
};
Size: Controls.ClickProc ~ {
d: REF Data ← NARROW[clientData];
d.sizeControls.GetReal[d.tool3d.typescript, "Size", d.size];
};
Triangles: Controls.ClickProc ~ {
[] ← G3dTool.MaybeFork[NARROW[clientData, REF Data].tool3d, Triangulate, clientData];
};
Triangulate: CedarProcess.ForkableProc ~ {
Status: ImplicitTet.StatusProc ~ {
CedarProcess.CheckAbort[];
d.p1 ← vertices[i0].position;
d.p2 ← vertices[i1].position;
d.p3 ← vertices[i2].position;
G3dTool.Repaint[d.tool3d, $NewTriangle];
};
d: REF Data ← NARROW[data];
s: G3dShape.Shape ImplicitTet.ShapeFromFunction[Cylinder, 0.0, d.size, 0.01*d.size,, d, Status
! ImplicitTet.Error => {G3dTool.TSWrite[d.tool3d, reason]; GOTO Bad}];
e: G3dShape.EdgeSequence ← G3dShape.MakeEdges[s];
gTimes2: INTEGER ← 2+e.length-INTEGER[s.vertices.length+s.surfaces.length];
s.name ← "Imp";
s.selected ← TRUE;
G3dTool.AddShape[d.tool3d, s];
G3dTool.TSWrite[d.tool3d, IO.PutFR["%g points, %g triangles, 2*genus = %g\n",
IO.int[s.vertices.length], IO.int[s.surfaces.length], IO.int[gTimes2]]];
EXITS Bad => NULL;
};
Cylinder: ImplicitDefs.ValueProc ~ {
value ← .01-(SELECT point.x FROM
< -.2 => G3dVector.SquareDistance[point, [-.2, 0.0, 0.0]],
> .2 => G3dVector.SquareDistance[point, [ .2, 0.0, 0.0]],
ENDCASE => G2dVector.Square[[point.y, point.z]]);
};
Draw: Draw2d.DrawProc ~ {
d: REF Data ← NARROW[clientData];
v: G3dTool.View ← G3dTool.GetView[viewer];
IF v # NIL AND whatChanged = $NewTriangle THEN
G3dDraw.DrawTriangle[context, d.p1, d.p2, d.p3, v.camera.matrix, v.viewport];
};
Commander.Register["ImplicitTest", ImplicitTest];
END.