MODULE PZEncodeCurvature EXPORTS Main; (* Compute chain EncodeCurvatureiants *) (* Last edited on 1999-11-08 05:40:49 by hcgl *) IMPORT ParseParams, Process, FileRd, Wr, FileWr; IMPORT OSError, Thread, Stdio, Fmt, TextWr; IMPORT PZSymbol, PZLRChain, PZSymbolChain; FROM Stdio IMPORT stderr; FROM PZTypes IMPORT LONG, NAT; <* FATAL Wr.Failure, Thread.Alerted, OSError.E *> TYPE Options = RECORD input: TEXT; (* Input float chain file (without ".flv") *) output: TEXT; (* Output float/curv chain file name (without ".flc") *) sigma: LONG; (* Filtering scale *) END; PROCEDURE Main() = BEGIN WITH o = GetOptions(), rcv = PZLRChain.Read(FileRd.Open(o.input & ".fcv"), headerOnly := FALSE), cv = rcv.c^, cmt = rcv.cmt & "\n" & PZEncodeCurvatureComments(o, NUMBER(cv)), cc = QuantizeInvariantChain(cv, o.sigma)^, ccCmt = cmt & "\n" & "Encoded Curvature - computed at filtered curve points" DO PZSymbolChain.Write(FileWr.Open(o.output & ".cvc"), ccCmt, cc, o.sigma); END END Main; PROCEDURE QuantizeInvariantChain( READONLY c: PZLRChain.T; sigma: LONG; ): REF PZSymbolChain.T = (* Given the invariant chain, converts it to a coded curvature chain. *) BEGIN WITH NP = NUMBER(c), rcvc = NEW(REF PZSymbolChain.T, NP), cvc = rcvc^ DO FOR i:= 0 TO NP-1 DO cvc[i] := PZSymbol.Encode(c[i], sigma) END; RETURN rcvc END END QuantizeInvariantChain; PROCEDURE GetOptions(): Options = VAR o: Options; BEGIN WITH pp = NEW(ParseParams.T).init(stderr) DO TRY pp.getKeyword("-input"); o.input := pp.getNext(); pp.getKeyword("-output"); o.output := pp.getNext(); pp.getKeyword("-sigma"); o.sigma := pp.getNextLongReal(); pp.finish(); EXCEPT | ParseParams.Error => Wr.PutText(stderr, "Usage: PZEncodeCurvature \\\n"); Wr.PutText(stderr, " -input FILE \\\n"); Wr.PutText(stderr, " -output FILE \\\n"); Wr.PutText(stderr, " -sigma NUMBER \n"); Process.Exit(1); END; END; RETURN o END GetOptions; PROCEDURE PZEncodeCurvatureComments(READONLY o: Options; nSamples: NAT):TEXT= BEGIN WITH wr = NEW(TextWr.T).init() DO Wr.PutText( wr, "PZEncodeCurvature:\n"); Wr.PutText( wr, " input: " & o.input & "\n"); Wr.PutText( wr, " output: " & o.output & "\n"); Wr.PutText( wr, " sigma: " & Fmt.LongReal(o.sigma) & "\n"); Wr.PutText( wr, " nSamples: " & Fmt.Int(nSamples)); RETURN(TextWr.ToText(wr)) END (* DO *); END PZEncodeCurvatureComments; BEGIN Main() END PZEncodeCurvature. (* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. *)