/* Last edited on 2015-01-20 16:56:32 by stolfilocal */ /* Maps a list of chain segments to another scale */ #include #include #include #include #include #include TYPE Options = struct ??? { char *input; /* Input segment file name. */ unsigned inBand; /* Input nominal filtering bandwidth. */ char *chainDir; /* Directory where to find chain data */ char *chainPrefix; /* Chain file name prefix. */ char *output; /* Output segment file name. */ unsigned outBand; /* Output nominal filtering bandwidth. */ double outStep; /* Sampling step of output chains. */ double blurFactor; /* Corner broadening factor (may be negative). */ double extraLength; /* Extra length to add at each segment end. */ } ???; int main(int argc, char **argv ) { { /* with */ ??? o = pz_get_options(int argc, char **argv); ??? sData = pz_segment_read(open_read(o.input & ".seg", TRUE)); ??? oldSeg = sData.s^; ??? chainUsed = pz_segment_chains_used(oldSeg)^; oldLabels = pz_double_chain_read_all( o.chainPrefix, o.inBand, ".lbl", sel := chainUsed, dir := o.chainDir; header_only := FALSE ); newLabels = pz_double_chain_read_all( o.chainPrefix, o.outBand, ".lbl", sel := chainUsed, dir := o.chainDir; header_only := FALSE ); newCvc = pz_symbol_chain_read_all( o.chainPrefix, o.outBand, ".cvc", sel := chainUsed, dir := o.chainDir; header_only := TRUE ); newSeg = MapAllSegments( oldSeg; oldLabels.chData^; newLabels.chData^, newCvc.chData^; o.inBand, o.outBand; newStep := o.outStep; blurFactor := o.blurFactor; extraLength := o.extraLength )^; ??? wr = open_write(o.output & ".seg", TRUE); /* do */ pz_segment_write(wr, sData.cmt & MapComments(o), newSeg);; }; } /* Main */ Options pz_get_options(int argc, char **argv ) VAR o: Options; { argparser_t *pp = argparser_new(stderr, argc, argv); argparser_set_help(pp, PROG_NAME " version " PROG_VERS ", usage:\n" PROG_HELP); argparser_set_info(pp, PROG_INFO); argparser_process_help_info_options(pp); { /* with */ /* do */ TRY if (( argparser_keyword_present(pp, "-chainDir") )){ o.chainDir = argparser_get_next(pp) }else{ o.chainDir = "."; }; argparser_get_keyword(pp, "-chainPrefix"); o.chainPrefix = argparser_get_next(pp); argparser_get_keyword(pp, "-input"); o.input = argparser_get_next(pp); argparser_get_keyword(pp, "-inBand"); o.inBand = argparser_get_next_int(pp); argparser_get_keyword(pp, "-output"); o.output = argparser_get_next(pp); argparser_get_keyword(pp, "-outBand"); o.outBand = argparser_get_next_int(pp); argparser_get_keyword(pp, "-outStep"); o.outStep = argparser_get_next_double(pp, 0.0e0, 1024.0e0); argparser_get_keyword(pp, "-blurFactor"); o.blurFactor = argparser_get_next_double(pp, -5.0e0, 5.0e0); argparser_get_keyword(pp, "-extraLength"); o.extraLength = argparser_get_next_double(pp, 0.0e0); argparser_finish(pp); EXCEPT | ParseParams.Error ==> fprintf(stderr, "Usage: pz_map_segs \\\n"); fprintf(stderr, " -input NAME \\\n"); fprintf(stderr, " -inBand NUMBER \\\n"); fprintf(stderr, " [ -chainDir DIR ] -chainPrefix NAME \\\n"); fprintf(stderr, " -output NAME \\\n"); fprintf(stderr, " -outBand NUMBER \\\n"); fprintf(stderr, " -outStep NUMBER \\\n"); fprintf(stderr, " -blurFactor NUMBER \\\n"); fprintf(stderr, " -extraLength NUMBER \n"); Process.Exit(1);; };; }; return o } /* GetOptions */ pz_segment_vec_t *MapAllSegments( pz_segment_vec_t *seg, ARRAY *OF pz_double_chain_read_data oldLabel, ARRAY *OF pz_double_chain_read_data newLabel, ARRAY *OF pz_symbol_chain_read_data newCvc, unsigned oldBand, unsigned newBand, double newStep, double blurFactor, double extraLength ) VAR nSegNew: unsigned = 0; { { /* with */ ??? nSegOld = (seg.ne); ??? segNew = pz_segment_vec_new(nSegOld)^; ??? halfShrink = blurFactor * ((double)newBand - oldBand) / newStep; ??? halfStretch = extraLength / newStep; ??? extra = ROUND(halfStretch - halfShrink); /* do */ fprintf(stderr, "input segments == %s\n", Fmt.Int(nSegOld) ); for (i = 0; i <= nSegOld-1 ; i++){ { /* with */ ??? sOld = seg[i]; ??? mappable = newLabel[sOld.cvx].c # NIL AND newCvc[sOld.cvx].samples # 0; /* do */ affirm(oldLabel[sOld.cvx].stride == newLabel[sOld.cvx].stride ); if (( mappable )){ { /* with */ ??? stride = oldLabel[sOld.cvx].stride; ??? tOld = oldLabel[sOld.cvx].c^; ??? tNew = newLabel[sOld.cvx].c^; ??? sRaw = pz_double_chain_map_segment(sOld, tOld, tNew, stride); ??? sNew = pz_segment_expand(sRaw, extra, extra); /* do */ if (( sNew.ns > 1 )){ segNew[nSegNew] = sNew; nSegNew++; }; }; };; }; }; fprintf(stderr, "output segments == %s\n", Fmt.Int(nSegNew) ); { /* with */ ??? r = pz_segment_vec_new(nSegNew); /* do */ r^ = SUBARRAY(segNew, 0, nSegNew); return r;; };; }; } /* MapAllSegments */ char *MapComments( Options *o ) { { /* with */ ??? wr = NEW(TextFILE *).init(); /* do */ fprintf( wr, "pz_map_segs\n"); fprintf( wr, " input == \"" & o.input & "\"\n"); fprintf(wr, " inBand == %s\n", Fmt.Int(o.inBand) ); fprintf( wr, " chainDir == \"" & o.chainDir & "\"\n"); fprintf( wr, " chainPrefix == \"" & o.chainPrefix & "\"\n"); fprintf( wr, " output == \"" & o.output & "\n"); fprintf(wr, " outBand == %s\n", Fmt.Int(o.outBand) ); fprintf(wr, " blurFactor == %s\n", FLR(o.blurFactor,8,6) ); fprintf(wr, " extraLength == %s\n", FLR(o.extraLength,8,4) ); return(TextFILE *oText(wr)); } /* ){ */; } /* MapComments */ char *FLR( double x, unsigned w, unsigned p ) { return Fmt.Pad(Fmt.LongReal(x, Fmt.Style.Fix, prec = p), w) } /* FLR */ { /* 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. */