<> <> <> 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]; }.