ContoursComposeImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, December 14, 1986 1:32:37 pm PST
DIRECTORY Commander, Controls, Controls3d, Contours, Draw2d, Draw3d, Imager, IO, Matrix3d, Spline3d, SplineStructure, Vector3d, ViewerOps;
ContoursComposeImpl: CEDAR PROGRAM
IMPORTS Commander, Controls, Controls3d, Draw2d, Draw3d, Spline3d, SplineStructure, ViewerOps
~ BEGIN
Triple:    TYPE ~ Vector3d.Triple;
Coeffs:    TYPE ~ Spline3d.Coeffs;
Bezier:    TYPE ~ Spline3d.Bezier;
SplineData:   TYPE ~ SplineStructure.SplineData;
ProgramData:   TYPE ~ REF ProgramDataRec;
ProgramDataRec:  TYPE ~ RECORD [
out:     IO.STREAMNIL,
outer, graphics:  Controls.Viewer ← NIL,
entries:    LIST OF Controls.Entry ← NIL,
cam:     Controls3d.Camera,    -- camera
c:      Coeffs ← NIL,
composed:   BOOLFALSE,
graphicsData:  Controls.GraphicsData ← NIL,
view:     Matrix3d.Matrix ← NIL
];
ContoursCompose: Commander.CommandProc ~ {
d: ProgramData ← NEW[ProgramDataRec];
d.out ← cmd.err;
d.view ← NEW[Matrix3d.MatrixRep];
d.cam ← Controls3d.InitCamera[scale: 3.0, proc: Controller, data: d];
d.c ← Spline3d.CoeffsFromHermite[[[-0.5,0.,0.], [1.,1.,0.], [0.5,0.,0.], [1.,-1.,0.]]];
Controls.ControlRow[d.cam.pan, 2];
d.outer ← Controls.OuterViewer[
name: "Cotour Composer",
column: left,
entries: LIST[["Compose", Compose], ["Reset", Reset]],
controls: LIST[
d.cam.xRot, d.cam.yRot, d.cam.zRot, d.cam.scale, d.cam.x, d.cam.y, d.cam.z, d.cam.fov],
graphicsHeight: 300,
graphicsShow: Display,
data: d];
d.entries ← NARROW[d.outer.data, Controls.OuterData].entries;
d.graphics ← NARROW[d.outer.data, Controls.OuterData].graphics;
d.graphicsData ← NARROW[d.graphics.data];
};
Controller: PUBLIC Controls.ControlProc ~ {
d: ProgramData ← NARROW[control.data];
SELECT control FROM
d.cam.pan, d.cam.tilt, d.cam.roll, d.cam.zoom, d.cam.dx, d.cam.dy, d.cam.dz, d.cam.fov => Controls3d.SetCamera[d.cam];
ENDCASE => NULL;
ViewerOps.PaintViewer[control.graphics, client, FALSE, control];
};
Reset: Controls.ClickProc ~ {
d: ProgramData ← NARROW[NARROW[clientData, Controls.OuterData].data];
d.c ← Spline3d.CoeffsFromHermite[[[-0.5,0.,0.], [1.,1.,0.], [0.5,0.,0.], [1.,-1.,0.]]];
ViewerOps.PaintViewer[d.graphics, client, FALSE, d];
};
Compose: Controls.ClickProc ~ {
d: ProgramData ← NARROW[NARROW[clientData, Controls.OuterData].data];
d.composed ← TRUE;
ViewerOps.PaintViewer[d.graphics, client, FALSE, d];
d.composed ← FALSE;
};
Display: Controls.GraphicsShow ~ {
d: ProgramData ← NARROW[data];
Action: PROC ~ {
d.view ← Controls3d.InitPix[context, w, h];
IF NOT d.composed
THEN FOR s: SplineData ← SplineStructure.contour, s.next WHILE s # NIL DO
Draw3d.DrawBezierPolygon[Spline3d.BezierFromCoeffs[s.c], context, d.view, dot];
Draw3d.DrawCurve[s.c, context, d.view];
ENDLOOP
ELSE Draw3d.DrawCurve[d.c, context, d.view];
};
Draw2d.DoWithBuffer[context, Action, w, h]
};
Commander.Register["ContoursCompose", ContoursCompose, "\nCompose two contours."];
END.
..