LSCurveJaM.mesa
JaM Module for playing with LSCurve, LSPiece and LSFit directly
Michael Plass November 30, 1982 9:16 am
Maureen Stone May 30, 1984 8:56:15 pm PDT
DIRECTORY
Cubic,
Curve,
JaM,
FitJaM,
LSCurve,
LSFit,
LSPiece,
Real,
Seq,
Vector;
LSCurveJaM:
CEDAR
PROGRAM
IMPORTS Cubic, Curve, JaM, LSCurve, LSFit, Real, FitJaM =
BEGIN
lsHandle: LSFit.Handle ← NIL;
lscurve: LSCurve.Handle ← NIL;
LinksFromPatches:
PROC [x, y: LSFit.PatchSequence] =
BEGIN
Curve.ResetLinks[Curve.defaultHandle];
FOR i:
NAT
IN [0..x.length)
DO
Curve.AddLink[Curve.defaultHandle, Cubic.CoeffsToBezier[[
c0: [x[i].c0, y[i].c0],
c1: [x[i].c1, y[i].c1],
c2: [x[i].c2, y[i].c2],
c3: [x[i].c3, y[i].c3]]]];
ENDLOOP;
END;
GetPoint:
PROC [state: JaM.State]
RETURNS [v: Vector.Vec] = {
v.y ← JaM.PopReal[state];
v.x ← JaM.PopReal[state];
};
BezierGet:
PROC [state: JaM.State] = {
OPEN Vector;
x,y: INTEGER ← 0;
b: Cubic.Bezier;
addSample: PROC [v: Vector.Vec] = {Curve.AddSample[Curve.defaultHandle, v.x,v.y]};
b.b3 ← GetPoint[state];
b.b2 ← GetPoint[state];
b.b1 ← GetPoint[state];
b.b0 ← GetPoint[state];
Curve.ResetSamples[Curve.defaultHandle];
Cubic.BezierPolygon[b,0.5,addSample];
};
InitialSpline:
PROCEDURE [state: JaM.State] =
BEGIN
ENABLE Real.RealException =>
TRUSTED {JaM.ExecuteRope[state,"(Real Exception) .print"]; CONTINUE};
nknots: INTEGER ← JaM.PopInt[state];
lsHandle ← LSFit.Create[Curve.CurrentSamples[Curve.defaultHandle]];
lsHandle.closedCurve ← FALSE;
LSFit.InitialKnots[lsHandle,nknots];
LSFit.InitialTValues[lsHandle];
LSFit.FitXAndY[lsHandle];
LinksFromPatches[lsHandle.xPatches, lsHandle.yPatches];
END;
InitialClosedSpline:
PROCEDURE [state: JaM.State] =
BEGIN
ENABLE Real.RealException =>
TRUSTED {JaM.ExecuteRope[state,"(Real Exception) .print"]; CONTINUE};
nknots: INTEGER ← JaM.PopInt[state];
lsHandle ← LSFit.Create[Curve.CurrentSamples[Curve.defaultHandle]];
lsHandle.closedCurve ← TRUE;
LSFit.InitialKnots[lsHandle,nknots+1];
LSFit.InitialTValues[lsHandle];
LSFit.FitXAndY[lsHandle];
LinksFromPatches[lsHandle.xPatches, lsHandle.yPatches];
END;
ImproveSpline:
PROCEDURE [state: JaM.State] =
BEGIN
LSFit.ImproveParametricSpline[lsHandle];
LinksFromPatches[lsHandle.xPatches, lsHandle.yPatches];
END;
Lsamples:
PROC [state: JaM.State] =
BEGIN
lscurve ← LSCurve.Create[Curve.CurrentSamples[Curve.defaultHandle]];
END;
Lresults:
PROC [state: JaM.State] =
BEGIN
x,y: LSCurve.PatchSequence;
[x:x, y:y] ← LSCurve.PatchesOf[lscurve];
LinksFromPatches[x,y];
END;
Lsmoothbasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.SmoothBasis[lscurve,JaM.PopInt[state]];
END;
Lbsplinebasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.BSplineBasis[lscurve,JaM.PopInt[state]];
END;
Lcubicbasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.CubicBasis[lscurve];
END;
Lcubicpiecebasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.CubicPieceBasis[lscurve];
END;
Lparabolabasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.ParabolaBasis[lscurve];
END;
Lcirclebasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.CircleBasis[lscurve];
END;
Lellipsebasis:
PROC [state: JaM.State] =
BEGIN
LSCurve.EllipseBasis[lscurve];
END;
Lpointslope:
PROC [state: JaM.State] =
BEGIN
bezier: Cubic.Bezier;
bezier.b3 ← GetPoint[state];
bezier.b2 ← GetPoint[state];
bezier.b1 ← GetPoint[state];
bezier.b0 ← GetPoint[state];
LSCurve.PointSlopeBasis[lscurve,bezier];
END;
Larclen:
PROC [state: JaM.State] =
BEGIN
LSCurve.ArcLengthInitialTValues[lscurve];
END;
Lunit:
PROC [state: JaM.State] =
BEGIN ENABLE ABORTED => GOTO Quit;
LSCurve.UnitInitialTValues[lscurve];
EXITS Quit => {}
END;
Langle:
PROC [state: JaM.State] =
BEGIN
LSCurve.AngleInitialTValues[lscurve];
END;
Lsolve:
PROC [state: JaM.State] =
BEGIN
LSCurve.SolveCurve[lscurve];
END;
Ladjust:
PROC [state: JaM.State] =
BEGIN
JaM.PushReal[state, LSCurve.AdjustTValues[lscurve]];
END;
Laccel:
PROC [state: JaM.State] =
BEGIN
r,d: REAL;
[r,d] ← LSCurve.AccelTValues[lscurve];
JaM.PushReal[state,d];
JaM.PushReal[state,r];
END;
Lfree:
PROC [state: JaM.State] =
BEGIN
n: INTEGER ← JaM.PopInt[state];
IF lscurve=
NIL
OR lscurve.free=
NIL
OR n<0
OR n>=lscurve.free.length
THEN {
JaM.ExecuteRope[state,"(bad basis function index) .print"];
RETURN};
lscurve.free[n] ← TRUE;
END;
Lfix:
PROC [state: JaM.State] =
BEGIN
n: INTEGER ← JaM.PopInt[state];
IF lscurve=
NIL
OR lscurve.free=
NIL
OR n<0
OR n>=lscurve.free.length
THEN {
JaM.ExecuteRope[state,"(bad basis function index) .print"];
RETURN};
lscurve.free[n] ← FALSE;
END;
LShowT:
PROC [state: JaM.State] = {
IF lscurve=NIL THEN RETURN;
FOR i:
NAT
IN [lscurve.l..lscurve.n]
DO
Curve.DrawLine[lscurve.z[i], LSCurve.XYat[lscurve,lscurve.t[i]]];
ENDLOOP;
};
LSort:
PROC [state: JaM.State] = {
IF lscurve=NIL THEN RETURN;
LSFit.Sort[lscurve.t];
};
Init: FitJaM.InitProc = {
JaM.Register[state,".bezierget",BezierGet];
LSFit calls
JaM.Register[state,".initspline",InitialSpline];
JaM.Register[state,".initclosedspline",InitialClosedSpline];
JaM.Register[state,".improvespline",ImproveSpline];
LSCurve calls
JaM.Register[state,".lsamples",Lsamples];
JaM.Register[state,".lresults",Lresults];
JaM.Register[state,".lpointslope",Lpointslope];
JaM.Register[state,".lsmoothbasis",Lsmoothbasis];
JaM.Register[state,".lbsplinebasis",Lbsplinebasis];
JaM.Register[state,".lcubicbasis",Lcubicbasis];
JaM.Register[state,".lcubicpiecebasis",Lcubicpiecebasis];
JaM.Register[state,".lparabolabasis",Lparabolabasis];
JaM.Register[state,".lcirclebasis",Lcirclebasis];
JaM.Register[state,".lellipsebasis",Lellipsebasis];
JaM.Register[state,".larclen",Larclen];
JaM.Register[state,".lunit",Lunit];
JaM.Register[state,".langle",Langle];
JaM.Register[state,".lsolve",Lsolve];
JaM.Register[state,".ladjust",Ladjust];
JaM.Register[state,".laccel",Laccel];
JaM.Register[state,".lfree",Lfree];
JaM.Register[state,".lfix",Lfix];
JaM.Register[state,".lshowt",LShowT];
JaM.Register[state,".lsort",LSort];
};
FitJaM.RegisterInit[$LSCurveJaM,Init];
END.