FilterImpl.mesa
Last modified by Maureen Stone February 14, 1985 5:13:30 pm PST
Last modified by Michael Plass August 20, 1982 2:55 pm
DIRECTORY
DynFit,
Vector,
Seq,
FitState USING [Handle],
FitBasic USING [SampleHandle],
FitStateUtils USING [SampleProc, ForAllSamples, PrevSa, NextSa, AtEnd],
Filters;
FiltersImpl: CEDAR PROGRAM
IMPORTS DynFit, FitStateUtils
EXPORTS Filters = {
AveFilter: PUBLIC PROC[samples: Seq.ComplexSequence, closed: BOOLEAN, skips: Seq.NatSequence ← NIL] RETURNS [Seq.ComplexSequence]= {
length: NAT ← samples.length;
nextSkip: NAT ← 0;
prev,current,next: Vector.Vec;
prev ← IF closed THEN samples[length-1] ELSE samples[0];
FOR i: NAT IN [0..length) DO
current ← samples[i];
IF i=length-1 THEN {IF closed THEN next ← samples[0]} --else just leave next at end
ELSE next ← samples[i+1];
IF skips#NIL AND i = skips[nextSkip] THEN
IF nextSkip < skips.length-1 THEN nextSkip ← nextSkip+1
ELSE {IF closed THEN nextSkip ← 0}
ELSE {
samples[i].x ← (prev.x+2*current.x+next.x)/4;
samples[i].y ← (prev.y+2*current.y+next.y)/4;
};
prev ← current;
ENDLOOP;
RETURN[samples];
};
AveFilterHandle: PUBLIC PROC[handle: FitState.Handle, skipForced: BOOLEANTRUE] = {
This filters the current samples in the FitState Handle directly. IF skipForced=TRUE the samples marked as forced joints will not be moved.
closed: BOOLEAN ← handle.closed;
prev,current,next: Vector.Vec;
do: FitStateUtils.SampleProc = {
current ← s.xy;
next ← FitStateUtils.NextSa[handle.slist, s, closed ! FitStateUtils.AtEnd => {
next ← s.xy; CONTINUE}].xy;
IF NOT skipForced OR s.jointType#forced THEN {
s.xy.x ← (prev.x+2*current.x+next.x)/4;
s.xy.y ← (prev.y+2*current.y+next.y)/4;
};
prev ← current;
};
prev ← FitStateUtils.PrevSa[handle.slist, handle.slist.first, closed ! FitStateUtils.AtEnd => {
prev ← handle.slist.first.xy; CONTINUE}].xy;
FitStateUtils.ForAllSamples[handle.slist, do];
};
Dynfilter: PUBLIC PROCEDURE[samples: Seq.ComplexSequence, closed: BOOLEAN, tolerance: REAL] RETURNS [new: Seq.ComplexSequence, totalBadness: REAL] = {
segments: DynFit.Segments;
len: NAT;
[segments,totalBadness] ← DynFit.FitSegments[samples, closed,tolerance];
len ← IF closed THEN segments.length-1 ELSE segments.length; --remove duplicate
new ← NEW [Seq.ComplexSequenceRec[len]];
FOR i: NAT IN [0..new.length) DO new[i] ← samples[segments[i]]; ENDLOOP;
RETURN[new, totalBadness];
};
}.