<> <> <> <> 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: BOOLEAN _ FALSE; fill: BOOLEAN _ FALSE; 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: REAL _ MAX[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.