ImplicitSolidCmdImpl.mesa
Copyright Ó 1985, 1990 by Xerox Corporation. All rights reserved.
Bloomenthal, March 15, 1991 6:01 pm PST
DIRECTORY CedarProcess, CtBasic, Commander, Controls, Draw2d, G3dBasic, G3dControl, G3dDraw, G3dMatrix, MessageWindow, Real, Rope, ViewerClasses, ViewerOps;
ImplicitSolidImpl:
CEDAR
PROGRAM
IMPORTS CedarProcess, CtBasic, Commander, Controls, Draw2d, G3dControl, G3dDraw, G3dMatrix, MessageWindow, Real, ViewerOps
~ BEGIN
Type Declarations
ForkableProc: TYPE ~ CedarProcess.ForkableProc;
Process: TYPE ~ CedarProcess.Process;
CommandProc: TYPE ~ Commander.CommandProc;
OuterData: TYPE ~ Controls.OuterData;
IntegerPair: TYPE ~ CtBasic.IntegerPair;
SampleMaps: TYPE ~ CtBasic.SampleMaps;
SampleMap: TYPE ~ CtBasic.SampleMap;
DrawProc: TYPE ~ Draw2d.DrawProc;
Pair: TYPE ~ G3dBasic.Pair;
Triple: TYPE ~ G3dBasic.Triple;
TripleSequence: TYPE ~ G3dBasic.TripleSequence;
TripleSequenceRep: TYPE ~ G3dBasic.TripleSequenceRep;
CameraControl: TYPE ~ G3dControl.CameraControl;
Matrix: TYPE ~ G3dMatrix.Matrix;
ROPE: TYPE ~ Rope.ROPE;
ClickProc: TYPE ~ ViewerClasses.ClickProc;
Viewer: TYPE ~ ViewerClasses.Viewer;
Tool
Tool: TYPE ~ REF ToolRep;
ToolRep:
TYPE ~
RECORD [
resolution: REAL ← 40.0,
radius: REAL ← 0.25,
sphere: TripleSequence ← NIL,
process: Process ← NIL, -- the current, forked process
camera: CameraControl ← NIL, -- viewing control
outer: Viewer ← NIL, -- parent viewer
outerData: OuterData ← NIL, -- associated data
graphics: Viewer ← NIL, -- graphics viewer
view: Matrix ← NIL -- view transformation
];
ImplicitSolidCommand: CommandProc ~ {
t: Tool ← NEW[ToolRep];
NewPoints[t];
t.camera ← G3dControl.InitCameraControl[proc: CameraControlProc, clientData: t];
t.outerData ← Controls.OuterViewer[
name: "Implicit Solid",
buttons:
LIST[
Controls.ClickButton["Stop", StopButton, t],
Controls.ClickButton["Render", RenderButton, t],
Controls.ClickButton["Radius", RadiusButton, t]],
controls:
LIST[
t.camera.proxySelect,
t.camera.proxy.xMov, t.camera.proxy.yMov, t.camera.proxy.zMov,
t.camera.proxy.xRot, t.camera.proxy.yRot, t.camera.proxy.zRot,
t.camera.scale, t.camera.fieldOfView],
graphicsHeight: 300,
drawProc: Draw,
typescriptHeight: 18,
clientData: t];
t.outer ← t.outerData.parent;
t.graphics ← t.outerData.graphics;
};
NewPoints:
PROC [t: Tool] ~ {
t.sphere ← G3dDraw.GetSpherePoints[[0.0, 0.0, 0.0], t.radius, sphereRes];
};
CameraControlProc: Controls.ControlProc ~ {
t: Tool ~ NARROW[clientData];
IF control.whatChanged = $TypedIn
OR
(control.mouse.button = right AND control.mouse.state # up) THEN Repaint[t];
};
Destroy: Controls.DestroyProc ~ {Stop[NARROW[clientData]]};
Buttons
Blink:
PROC [message:
ROPE] ~ {
MessageWindow.Append[message, TRUE];
MessageWindow.Blink[];
};
RadiusButton: ClickProc ~ {
t: Tool ← NARROW[clientData];
t.radius ← Controls.TypescriptReadValue[t.outerData.typescript, "Radius", t.radius
! Controls.ControlError => {Blink["Bad Value"]; CONTINUE}];
NewPoints[t];
};
ResolutionButton: ClickProc ~ {
t: Tool ← NARROW[clientData];
t.resolution ← Controls.TypescriptReadValue[t.outerData.typescript, "Res", t.resolution
! Controls.ControlError => {Blink["Bad Value"]; CONTINUE}];
};
RenderButton: ClickProc ~ {
t: Tool ← NARROW[clientData];
MaybeFork[t, ForkRender];
};
StopButton: ClickProc ~ {Stop[
NARROW[clientData], " . . . aborted\n"]};
Stop:
PROC [t: Tool, reason:
ROPE ←
NIL] ~ {
CedarProcess.Abort[t.process];
IF reason # NIL THEN TSWrite[t, reason];
};
Render
ForkRender: ForkableProc ~ {
t: Tool ← NARROW[data];
maps: SampleMaps ← CtBasic.GetColorDisplayMaps[];
map: SampleMap ← IF maps.bpp = 8 THEN maps[0].map ELSE maps[1].map;
stepSize: REAL ← 4.0*t.radius/REAL[t.resolution];
CtBasic.FillMaps[maps, 0, 0, 0];
FOR z:
REAL ← -2.0*t.radius, z+stepSize
WHILE z <= 2.0*t.radius
DO
FOR y:
REAL ← -2.0*t.radius, y+stepSize
WHILE y <= 2.0*t.radius
DO
FOR x:
REAL ← -2.0*t.radius, x+stepSize
WHILE x <= 2.0*t.radius
DO
value: REAL ← x*x+y*y+z*z;
p: Pair ← G3dMatrix.TransformD[[x, y, z], t.camera.matrix];
m: IntegerPair ← CtBasic.MapCoordsFromPair[[p.x, 1.33333*p.y], map];
oVal: CARDINAL ← CtBasic.GetBWPixel[map, m.x, m.y];
pVal: CARDINAL ← Real.Round[MIN[255.0, MAX[0., 255.0*value]]];
IF oVal # 0 THEN pVal ← (oVal+pVal)/2;
CedarProcess.CheckAbort[];
SELECT maps.bpp
FROM
8 => CtBasic.PutBWPixel[maps[0].map, m.x, m.y, pVal];
24 => CtBasic.PutRGBPixel[maps, m.x, m.y, [pVal, pVal, pVal]];
ENDCASE;
ENDLOOP;
ENDLOOP;
ENDLOOP;
};
Display
Repaint:
PROC [t: Tool, whatChanged:
REF
ANY ←
NIL] ~ {
ViewerOps.PaintViewer[t.graphics, client, FALSE, whatChanged];
};
Draw: DrawProc ~ {
t: Tool ~ NARROW[data];
Action:
PROC ~ {
IF whatChanged =
NIL
THEN t.view ← G3dControl.InitContext[context, t.camera, viewer,, t.view];
G3dDraw.DrawSphere[context, [0, 0, 0], t.radius, sphereRes, t.view, viewport, t.sphere];
G3dDraw.DrawCube[context, [0, 0, 0], 2.0*t.radius, t.view, viewport];
};
viewport: G3dMatrix.Viewport ← G3dView.GetViewport[viewer];
Draw2d.DoWithBuffer[context, Action];
};
Support
MaybeFork:
PROC [t: Tool, proc: ForkableProc] ~ {
IF CedarProcess.GetStatus[t.process] = busy
THEN TSWrite[t, "Tool is busy!\n"]
ELSE t.process ← CedarProcess.Fork[proc, t, [background, TRUE]];
};
TSWrite: PROC [t: Tool, rope: ROPE] ~ {Controls.TypescriptWrite[t.outerData.typescript, rope]};
Start Code
Commander.Register["ImplicitSolid", ImplicitSolidCommand];
END.