CurveImpl.mesa
Last Edited by July 17, 1982 5:05 pm
Last Edited by Michael Plass December 7, 1982 10:25 am
Last Edited by: Stone, November 21, 1983 11:33 am
DIRECTORY
Cubic,
Curve,
Complex,
ConvertUnsafe,
IO,
FileIO,
TJaMGraphics USING [Painter],
JaM,
JaMBasic,
JaMOps,
Graphics,
Real,
Rope,
Seq,
Vector;
CurveImpl: CEDAR PROGRAM
IMPORTS Complex, ConvertUnsafe, TJaMGraphics, JaM, JaMOps, IO, FileIO, Graphics, Real, Rope, Vector
EXPORTS Curve =
BEGIN OPEN JaM, Curve;
all: BOOLEANFALSE;
fill: BOOLEANFALSE;
DrawSamples: PROC= {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
DrawSamples[handle: defaultHandle, all: all, fill: fill];
};
JaMImager.Painter[Paint];
};
MarkSamples: PROC= {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.MarkSamples[defaultHandle, all];
};
JaMImager.Painter[Paint];
};
MarkNodes: PROC = {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.MarkNodes[defaultHandle, all];
};
JaMImager.Painter[Paint];
};
MarkLinks: PROC = {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.MarkJoints[defaultHandle, all];
};
JaMImager.Painter[Paint];
};
DrawLinks: PROC[state: JaM.State] = {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.DrawContour[defaultHandle, all, fill];
};
JaMImager.Painter[Paint];
};
SetMarkSize: PROC[state: JaM.State] = {
defaultHandle.feedback.sampleSize ← JaM.PopReal[state];
};
SetScale: PROC[state: JaM.State] = {
FitIO.MagnifyData[JaM.PopReal[state]];
};
SetOffset: PROC[state: JaM.State] = {
y: REAL ← JaM.PopReal[state];
x: REAL ← JaM.PopReal[state];
FitIO.PositionData[[x,y]];
};
ResetSa: PROC = {ResetSamples[defaultHandle]};
StartSa: PROC = {y: REAL ← GetReal[]; x: REAL ← GetReal[]; StartSamples[defaultHandle, x,y]};
AddSa: PROC = {y: REAL ← GetReal[]; x: REAL ← GetReal[]; AddSample[defaultHandle, x,y]};
CountSa: PROC = {OPEN defaultHandle^;
s: SampleHandle;
n: NAT ← 0;
FOR s ← slist.header.next, s.next UNTIL s=slist.header DO
n ← n+1;
ENDLOOP;
PushInteger[n];
};
ForAllLinks: PROC = {
body: JaMBasic.Object ← JaMOps.Pop[JaMOps.defaultFrame.opstk];
FOR l: LinkHandle ← defaultHandle.traj.links, l.next UNTIL l=NIL DO
PushReal[l.cubic.b0.x];
PushReal[l.cubic.b0.y];
PushReal[l.cubic.b1.x];
PushReal[l.cubic.b1.y];
PushReal[l.cubic.b2.x];
PushReal[l.cubic.b2.y];
PushReal[l.cubic.b3.x];
PushReal[l.cubic.b3.y];
JaMOps.Execute[JaMOps.defaultFrame, body];
ENDLOOP;
};
ResetCon: PUBLIC PROC[] = {ResetContours[defaultHandle]};
CountCon: PUBLIC PROC[] = {PushInteger[CountContours[defaultHandle]]};
AddCon: PUBLIC PROC[] = {AddContour[defaultHandle]};
NextCon: PUBLIC PROC[] = {NextContour[defaultHandle]};
GetVec: PROC RETURNS [z:Complex.Vec] = {z.y ← GetReal[]; z.x ← GetReal[]};
InterpolateSa: PROC = {OPEN defaultHandle^;
mindelta: REALMAX[GetReal[], 0.00001];
s: SampleHandle ← slist.header.next;
UNTIL s=slist.header DO
nexts: SampleHandle ← s.next;
nextxy: Complex.Vec ← (IF s.next = slist.header THEN slist.header.next ELSE s.next).xy;
delta: Complex.Vec ← Complex.Sub[nextxy, s.xy];
k: REAL ← Real.RoundLI[Complex.Abs[delta]/mindelta];
FOR i: REAL ← 1, i+1 UNTIL i>k DO
InsertBefore[Complex.Add[s.xy, Vector.Mul[delta, i/(k+1)]], nexts];
ENDLOOP;
s ← nexts;
ENDLOOP;
};
SetSLen: PROC = {[] ← FitState.SetMinDist[defaultHandle,GetReal[]]};
fill: BOOLEANFALSE;
SetFill: PROC = {fill ← PopBoolean[]};
OpenLogFile: PROC[JaM.state] = {
ls: Rope.ROPE ← PopRope[state];
stream: IO.STREAM;
IF rope.Length[] > 0 THEN stream ← FileIO.Open[rope, append];
FitIO.StartLog[stream];
};
CloseLogFile: PROC = {
FitIO.StopLog[close: TRUE];
};
SetTypescript: PROC = {
typescript ← PopBoolean[];
IF typescript AND stream=NIL THEN {
typescript ← FALSE;
JaM.JaMExec["(no log file) .print"];
};
};
Note: PROC = {
c: LONG STRING ← [80];
PopString[c];
IF typescript THEN PrintString[c];
};
Notes: PROC = {
c: LONG STRING ← [80];
PopString[c];
IF typescript THEN {PrintString[c]; PrintString[" "]};
};
Noter: PROC = {
c: LONG STRING ← [80];
PopString[c];
IF typescript THEN {PrintLine[c]; stream.Flush[]};
};
Time: PROC = {
IF typescript THEN {IO.Put[stream,IO.time[]]; stream.Flush[]};
};
CollectGarbage: PROC = {
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: TRUE];
};
JaM.Register[".startsa", StartSa];
JaM.Register[".resetsa", ResetSa];
JaM.Register[".addsa", AddSa];
JaM.Register[".countsa", CountSa];
JaM.Register[".foralllinks", ForAllLinks];
JaM.Register[".nextcon", NextCon];
JaM.Register[".resetcon", ResetCon];
JaM.Register[".addcon", AddCon];
JaM.Register[".countcon", CountCon];
JaM.Register[".interpolatesa", InterpolateSa]; -- d => . Interpolates samples to make deltas no larger than about d
JaM.Register[".drawsa", DrawSamples];
JaM.Register[".marksa", MarkSamples];
JaM.Register[".drawli", DrawLinks];
JaM.Register[".markli", MarkLinks];
JaM.Register[".marknodes", MarkNodes];
JaM.Register[".setslen", SetSLen];
JaM.Register[".setfill", SetFill];
JaM.Register[".setlog", SetTypescript];
JaM.Register[".setscale", SetScale];
JaM.Register[".setoffset", SetOffset];
JaM.Register[".setmarksize", SetMarkSize];
JaM.Register[".note", Note];
JaM.Register[".notes", Notes];
JaM.Register[".noter", Noter];
JaM.Register[".time", Time];
JaM.Register[state,".openlogfile", OpenLogFile]; -- filename => . Switches the log file.
JaM.Register[state,".closelogfile", CloseLogFile]; -- => . Closes the log file.
JaM.Register[state,".collectgarbage", CollectGarbage];
END.
Michael Plass August 13, 1982 9:48 am: Added multiple sample sets, InsertBetween.
Michael Plass August 13, 1982 10:29 am: Added CornerSa.
Michael Plass August 23, 1982 9:59 am: Added ForAllLinks.
Michael Plass August 23, 1982 2:31 pm: Sent Curve.Log to file.
Michael Plass August 23, 1982 2:34 pm: CornerSa moved out because of Storage overflow in Pass 3.
CornerSa: PROC = {OPEN Vector;
samp: SampleHandle ← IF defaultHandle.slist.selectedSample = defaultHandle.slist.header THEN defaultHandle.slist.selectedSample.next ELSE defaultHandle.slist.selectedSample;
p: SampleHandle ← IF samp.prev = defaultHandle.slist.header THEN samp.prev.prev ELSE samp.prev;
pp: SampleHandle ← IF p.prev = defaultHandle.slist.header THEN p.prev.prev ELSE p.prev;
n: SampleHandle ← IF samp.next = defaultHandle.slist.header THEN samp.next.next ELSE samp.next;
nn: SampleHandle ← IF n.next = defaultHandle.slist.header THEN n.next.next ELSE n.next;
a: Vec ← pp.xy;
b: Vec ← p.xy;
c: Vec ← nn.xy;
d: Vec ← n.xy;
coeffMat: Matrix ← [a.y-b.y, b.x-a.x, c.y-d.y, d.x-c.x];
r: Vec ← [Det[[b.x, b.y, a.x, a.y]], Det[[d.x, d.y, c.x, c.y]]];
denom: REAL ← Det[coeffMat];
xTimesDenom: REAL ← Det[[r.x, coeffMat.a12, r.y, coeffMat.a22]];
yTimesDenom: REAL ← Det[[coeffMat.a11, r.x, coeffMat.a21, r.y]];
IF denom=0 THEN RETURN;
samp.xy.x ← xTimesDenom/denom;
samp.xy.y ← yTimesDenom/denom;
};
JaM.Register[".cornersa", CornerSa]; -- => . moves the selected sample so it is colinear with its two left neightbors and with its two right neighbors
Michael Plass August 24, 1982 9:48 am: Removed Curve.Log typescript.
Michael Plass August 27, 1982 7:21 pm: Bulletproofed against empty links.
Michael Plass August 30, 1982 1:33 pm: Added OpenLogFile.
Michael Plass September 28, 1982 12:26 pm: Added CloseLogFile.
Michael Plass December 7, 1982 10:25 am: Took out Transaction import for 3.5.