FiltersJaM.mesa
JaM interfaces for Filters
Maureen Stone November 28, 1984 12:00:02 pm PST
DIRECTORY
Seq,
Complex USING [Vec],
Filters,
FitState USING [AddSample, CurrentSamples, SetClosed, GetClosed, CurrentJoints, ResetData],
FitJaM USING [RegisterInit, InitProc, defaultFitState],
JaM;
FiltersJaM:
CEDAR
PROGRAM
IMPORTS JaM, FitState, Filters, FitJaM = {
GetSamples:
PROC RETURNS [samples: Seq.ComplexSequence, closed:
BOOLEAN] = {
samples ← FitState.CurrentSamples[FitJaM.defaultFitState];
closed ← FitState.GetClosed[FitJaM.defaultFitState];
RETURN[samples, closed];
};
SetSamples:
PROC [samples: Seq.ComplexSequence, closed:
BOOLEAN] = {
tangents: Seq.ComplexSequence;
joints: Seq.JointSequence;
nj: NAT ← 0;
[joints, tangents] ← FitState.CurrentJoints[FitJaM.defaultFitState];
FitState.ResetData[FitJaM.defaultFitState, samples];
FOR i:
NAT
IN [0..samples.length)
DO
IF joints#
NIL
AND joints[nj].index=i
THEN {
FitState.AddSample[
handle: FitJaM.defaultFitState,
x: samples[i].x, y: samples[i].y,
joint: IF joints[nj].forced THEN forced ELSE potential,
tanIn: tangents[2*nj],
tanOut: tangents[2*nj+1]
];
nj ← nj+1;
}
ELSE FitState.AddSample[FitJaM.defaultFitState, samples[i].x,samples[i].y];
ENDLOOP;
FitState.SetClosed[FitJaM.defaultFitState, closed];
};
Dynfilter:
PROC [state: JaM.State] = {
samples: Seq.ComplexSequence;
closed: BOOLEAN;
tolerance: REAL ← JaM.PopReal[state];
badness: REAL;
[samples,closed] ← GetSamples[];
IF samples=NIL THEN RETURN;
[samples, badness] ← Filters.Dynfilter[samples, closed, tolerance];
SetSamples[samples, closed];
JaM.PushReal[state, badness];
};
AveFilter:
PROC [state: JaM.State] = {
Filters.AveFilterHandle[FitJaM.defaultFitState, JaM.PopBool[state]];
};
Init: FitJaM.InitProc = {
JaM.Register[state, ".dynfilter",Dynfilter];
JaM.Register[state, ".avefilter",AveFilter]; --boolean => if TRUE skips joints marked forced
};
FitJaM.RegisterInit[id: $FiltersJaM, proc: Init];
}.