FitStateEditJaM.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
FitState,
FitIO,
FitBasic USING [Handle, Rec, SampleHandle],
Cubic,
Complex,
IO,
FS
JaMImager USING [Painter],
JaM,
Imager,
Real,
Rope USING [ROPE],
Seq,
Vector;
FitStateEditJaM: CEDAR PROGRAM
IMPORTS Complex, JaMImager, JaM, IO, FS, Imager, Real, Rope, Vector, FitState, FitIO
EXPORTS =
BEGIN OPEN FitState;
all: BOOLEANFALSE;
fill: BOOLEANFALSE;
State: TYPE = JaM.State;
handle: FitState.Handle ← NEW[FitBasic.Rec];
defaultFitIO: FitIO.Context ← NEW[FitIO.ContextRec ← [
imager: NIL, --set in paint proc
magnify: 1,
position: [0,0],
feedback: Feedback ← NEW[FitIO.Feedback ← [
color: Imager.black,
sampleSize: 1,
jointSize: 2,
nodeLength: 2,
nodeLineWidth: 0,
lineWidth: 0--for DrawSamples and DrawContour
]],
logActions: FALSE,
log: NIL
]];
DrawSamples: PROC[state: State]= {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.DrawSamples[handle: defaultHandle, all: all, fill: fill];
};
JaMImager.Painter[Paint];
};
MarkSamples: PROC[state: State]= {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.MarkSamples[defaultHandle, all];
};
JaMImager.Painter[Paint];
};
MarkNodes: PROC[state: State] = {
Paint: PROC[dc: Imager.Context] = {
defaultFitIO.imager ← dc;
FitIO.SetContext[defaultFitIO];
FitIO.MarkNodes[defaultHandle, all];
};
JaMImager.Painter[Paint];
};
MarkLinks: PROC[state: State] = {
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.SetContext[defaultFitIO];
FitIO.MagnifyData[JaM.PopReal[state]];
};
SetOffset: PROC[state: JaM.State] = {
y: REAL ← JaM.PopReal[state];
x: REAL ← JaM.PopReal[state];
FitIO.SetContext[defaultFitIO];
FitIO.PositionData[[x,y]];
};
ResetSa: PROC[state: State] = {FitState.ResetSamples[defaultHandle]};
StartSa: PROC[state: State] = {
y: REAL ← JaM.PopReal[state];
x: REAL ← JaM.PopReal[state];
FitState.StartSamples[defaultHandle, x,y];
};
AddSa: PROC[state: State] = {
y: REAL ← JaM.PopReal[state];
x: REAL ← JaM.PopReal[state];
FitState.AddSample[defaultHandle, x,y];
};
CountSa: PROC[state: State] = {OPEN defaultHandle^;
s: FitBasic.SampleHandle;
n: NAT ← 0;
FOR s ← slist.header.next, s.next UNTIL s=slist.header DO
n ← n+1;
ENDLOOP;
JaM.PushInt[state,n];
};
ForAllLinks: PROC[state: State] = {
body: JaM.Any ← JaM.Pop[state];
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];
JaM.Execute[state, body ! JaM.Stop => CONTINUE];
ENDLOOP;
};
ResetCon: PROC[state: State] = {FitState.ResetContours[defaultHandle]};
CountCon: PROC[state: State] = {JaM.PushInt[state, CountContours[defaultHandle]]};
AddCon: PROC[state: State] = {FitState.AddContour[defaultHandle]};
NextCon: PROC[state: State] = {FitState.NextContour[defaultHandle]};
InterpolateSa: PROC[state: State] = {OPEN defaultHandle^;
mindelta: REALMAX[JaM.PopReal[state], 0.00001];
s: FitBasic.SampleHandle ← slist.header.next;
UNTIL s=slist.header DO
nexts: FitBasic.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
v: Complex.Vec ← Complex.Add[s.xy, Vector.Mul[delta, i/(k+1)]]
FitState.InsertBefore[defaultHandle, v.x,v.y, nexts];
ENDLOOP;
s ← nexts;
ENDLOOP;
};
SetSLen: PROC[state: State] = {[] ← FitState.SetMinDist[defaultHandle,JaM.PopReal[state]]};
SetFill: PROC[state: State] = {fill ← PopBool[state]};
OpenLogFile: PROC[JaM.state] = {
ls: Rope.ROPE ← PopRope[state];
stream: IO.STREAM;
IF rope.Length[] > 0 THEN stream ← FS.StreamOpen[rope, append];
FitIO.SetContext[defaultFitIO];
FitIO.StartLog[stream];
};
CloseLogFile: PROC[state: State] = {
FitIO.SetContext[defaultFitIO];
FitIO.StopLog[close: TRUE];
};
SetTypescript: PROC[state: State] = {
IF PopBool[state] THEN {
FitIO.SetContext[defaultFitIO];
FitIO.StartLog[! FitIO.NoLog =>
JaM.ExecuteRope["(no log file) .print" ! JaM.Stop => CONTINUE];
};
};
Note: PROC[state: State] = {
c: ROPE ← PopRope[state];
IF defaultFitIO.logActions THEN PrintRope[c];
};
Notes: PROC[state: State] = {
c: ROPE ← PopRope[state];
IF defaultFitIO.logActions THEN {PrintRope[c]; PrintRope[" "]};
};
Noter: PROC[state: State] = {
c: ROPE ← PopRope[state];
IF defaultFitIO.logActions THEN {PrintLine[c]; defaultFitIO.log.Flush[]};
};
Time: PROC[state: State] = {
IF defaultFitIO.logActions THEN {IO.Put[stream,IO.time[]]; defaultFitIO.log.Flush[]};
};
PrintRope: PROC[s: Rope.ROPE] = {OPEN IO; Put[defaultFitIO.log,rope[s]]};
PrintLine: PROC[s: Rope.ROPE] = {OPEN IO; Put[defaultFitIO.log,rope[s],char[CR]]};
CollectGarbage: PROC[state: State] = {
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.