FilterImpl.mesa
Last modified by Maureen Stone March 21, 1984 8:04:55 pm PST
Last modified by Michael Plass August 20, 1982 2:55 pm
DIRECTORY
DynFit,
Vector,
Seq,
Filters;
FilterImpl:
CEDAR
PROGRAM
IMPORTS DynFit
EXPORTS Filters = {
AveFilter:
PUBLIC
PROC[samples: Seq.ComplexSequence, closed:
BOOLEAN]
RETURNS [Seq.ComplexSequence]= {
length: NAT ← samples.length;
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 (closed
AND i=length-1)
THEN next ← samples[0] ELSE {IF i<= length-1 THEN next ← samples[i+1]};
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];
};
AveFilterLeavingCorners:
PUBLIC
PROC[samples: Seq.ComplexSequence, closed:
BOOLEAN, corners: Seq.NatSequence ←
NIL]
RETURNS [Seq.ComplexSequence]= {
length: NAT ← samples.length;
nextCorner: 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 (closed
AND i=length-1)
THEN next ← samples[0] ELSE {IF i<= length-1 THEN next ← samples[i+1]};
IF corners#NIL AND i = corners[nextCorner] THEN nextCorner ← nextCorner+1
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];
};
Dynfilter:
PUBLIC
PROCEDURE[samples: Seq.ComplexSequence, closed:
BOOLEAN, tolerance:
REAL]
RETURNS [new: Seq.ComplexSequence, totalBadness:
REAL] = {
segments: DynFit.Segments;
newSamples,z: Seq.ComplexSequence;
len: NAT;
IF closed
THEN {
z ← NEW[Seq.ComplexSequenceRec[samples.length+1]];
FOR i: NAT IN[0..z.length) DO z[i] ← samples[i]; ENDLOOP;
}
ELSE z ← samples;
[segments,totalBadness] ← DynFit.FitSegments[z,tolerance];
[newSamples,len] ← DynFit.SampleSegments[segments,samples];
new ← NEW [Seq.ComplexSequenceRec[len]];
FOR i: NAT IN [0..len) DO new[i] ← newSamples[i]; ENDLOOP;
RETURN[new, totalBadness];
};
}.