G2dInterpolateCmdImpl.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 20, 1992 1:10 pm PDT
Glassner, May 30, 1986 12:32:04 pm PDT
DIRECTORY Commander, CommanderOps, Controls, Draw2d, FileNames, G2dBasic, G2dImagerGraphCapture, G2dSpline, G2dTool, Imager, InterpressInterpreter, Real, Rope, ViewerOps;
G2dInterpolateCmdImpl: CEDAR PROGRAM
IMPORTS CommanderOps, Controls, Draw2d, FileNames, G2dImagerGraphCapture, G2dSpline, G2dTool, InterpressInterpreter, Real, Rope, ViewerOps
~ BEGIN
Graphs: TYPE ~ RECORD [SEQUENCE maxLength: CARDINAL OF G2dImagerGraphCapture.Graph];
Data:  TYPE ~ RECORD [
zip:    Draw2d.Zip,
frame:    Controls.Control,
outer:    Controls.Viewer,
outerData:  Controls.OuterData,
knots:    G2dBasic.PairSequence,
vertices:   G2dBasic.PairSequence,
spline:   G2dSpline.Spline2dSequence,
graphs:   REF Graphs
];
G2dInterpolate: Commander.CommandProc ~ {
argv: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
IF argv .argc < 3
THEN RETURN[$Failure, "need at least two interpress files"]
ELSE {
d: REF Data ¬ NEW[Data];
d.knots ¬ NEW[G2dBasic.PairSequenceRep[argv.argc-1]];
d.graphs ¬ NEW[Graphs[d.knots.length ¬ argv.argc-1]];
FOR n: NAT IN [0..d.knots.length) DO
context: Imager.Context ¬ G2dImagerGraphCapture.CreateContext[1.0];
name: Rope.ROPE ¬ FileNames.ResolveRelativePath[argv[n+1]];
master: InterpressInterpreter.Master ¬ InterpressInterpreter.Open[name, NIL];
IF master = NIL THEN RETURN[$Failure, Rope.Concat["Can't open ", argv[n]]];
InterpressInterpreter.DoPage[master, 1, context, NIL];
InterpressInterpreter.Close[master];
d.graphs[n] ¬ G2dImagerGraphCapture.GetGraph[context];
ENDLOOP;
d.vertices ¬ NEW[G2dBasic.PairSequenceRep[d.graphs[0].size]];
d.vertices.length ¬ d.graphs[0].size;
FOR n: NAT IN [2..d.knots.length) DO
IF d.graphs[n].size # d.vertices.length THEN RETURN[$Failure, "Size Mismatched"];
ENDLOOP;
d.frame ¬ Controls.NewControl["Frame", hSlider, d, 0, 1, 0, Frame];
d.outerData ¬ Controls.OuterViewer[
name: "2d Interpolate",
graphicsHeight: 300,
drawProc: DrawProc,
controls: LIST[d.frame],
clientData: d];
d.outer ¬ d.outerData.parent;
};
};
Frame: Controls.ControlProc ~ {
d: REF Data ¬ NARROW[control.clientData];
t: REAL ¬ d.frame.value;
f: REAL ¬ 1.0/REAL[d.knots.length-1];
segment: NAT ¬ Real.Round[t/f];
FOR n: NAT IN [0..d.vertices.length) DO
FOR nn: NAT IN [0..d.knots.length) DO
d.knots[n] ¬ d.graphs[nn][n].pos;
ENDLOOP;
d.spline ¬ G2dSpline.Interpolate2d[d.knots, d.spline];
d.vertices[n] ¬ G2dSpline.Position2d[d.spline[segment], t-f*segment];
ENDLOOP;
ViewerOps.PaintViewer[d.outerData.graphics, client];
};
DrawProc: Controls.DrawProc ~ {
d: REF Data ¬ NARROW[clientData];
d.zip ¬ Draw2d.GetZip[context, d.zip];
FOR n: NAT IN [1..d.vertices.length) DO
Draw2d.Line[context, d.vertices[n-1], d.vertices[n]];
ENDLOOP;
};
G2dTool.Register["Interpolate", G2dInterpolate, "\nInterpolate <ip #1> <ip #2> . . ."];
END.