/* Last edited on 2015-01-20 16:55:53 by stolfilocal */ /* Maps a list of tentative pairings to another scale */ #include #include #include #include #include #include TYPE Options = struct ??? { char *input; /* Input candidate file name. */ unsigned inBand; /* Input band number. */ char *chainDir; /* Directory where to find chain files. */ char *chainPrefix; /* Chain file name prefix. */ char *output; /* Output candidate file name. */ unsigned outBand; /* Output filter band number. */ double outLambda; /* Output filtering bandwidth. */ double outStep; /* Sampling step of output chains. */ double blurFactor; /* Corner broadening factor. */ double extraLength; /* Extra length to add at each candidate end. */ /* Parameters that control the merging of overlapping cands: */ double maxMergeShift; /* Max shift btw pairings (pixels). */ double minMergeOverlap; /* Minimum overlap btw pairings (0 = don't merge). */ bool_t verbose; /* TRUE to mumble while working */ } ???; int main(int argc, char **argv ) { { /* with */ ??? o = pz_get_options(int argc, char **argv); ??? cData = pz_candidate_read(open_read(o.input & ".can", TRUE)); ??? oldCand = cData.c^; ??? oldLambda = cData.lambda; ??? chainUsed = pz_candidate_chains_used(oldCand)^; 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 ); newCand = MapAllCandidates( oldCand; oldLabels.chData^, oldLambda; newLabels.chData^, o.outLambda, o.outStep; blurFactor := o.blurFactor; extraLength := o.extraLength; tryToMerge := (o.minMergeOverlap > 0.0e0); maxShiftSteps := CEILING(o.maxMergeShift/o.outStep - 0.0001e0); minOverlapSteps := CEILING(o.minMergeOverlap/o.outStep - 0.0001e0); verbose := o.verbose )^; ??? wr = open_write(o.output & ".can", TRUE); ??? band = FLOAT(o.outBand,double); /* do */ pz_candidate_write(wr, cData.cmt & MapComments(o), newCand, band);; }; } /* 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 argparser_get_keyword(pp, "-input"); o.input = argparser_get_next(pp); 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, "-inBand"); o.inBand = argparser_get_next_int(pp, 0); argparser_get_keyword(pp, "-output"); o.output = argparser_get_next(pp); argparser_get_keyword(pp, "-outBand"); o.outBand = argparser_get_next_int(pp, 0); argparser_get_keyword(pp, "-outLambda"); o.outLambda = argparser_get_next_double(pp, 0.0e0); argparser_get_keyword(pp, "-outStep"); o.outStep = argparser_get_next_double(pp, 0.0e0); argparser_get_keyword(pp, "-blurFactor"); o.blurFactor = argparser_get_next_double(pp, 0.0e0, 5.0e0); argparser_get_keyword(pp, "-extraLength"); o.extraLength = argparser_get_next_double(pp); if (( argparser_keyword_present(pp, "-mergeCands") )){ o.maxMergeShift = argparser_get_next_double(pp, 0.0e0, 10000.0e0); o.minMergeOverlap = argparser_get_next_double(pp, 0.0e0, 10000.0e0); }else{ o.maxMergeShift = 0.0e0; o.minMergeOverlap = 0.0e0;; }; o.verbose = argparser_keyword_present(pp, "-verbose"); argparser_finish(pp); EXCEPT | ParseParams.Error ==> fprintf(stderr, "Usage: pz_map_cands \\\n"); fprintf(stderr, " -input NAME \\\n"); fprintf(stderr, " -inBand NUMBER \\\n"); fprintf(stderr, " -chainPrefix NAME [ -chainDir DIR ] \\\n"); fprintf(stderr, " -output NAME \\\n"); fprintf(stderr, " -outBand NUMBER -outLambda PIXELS \\\n"); fprintf(stderr, " -outStep PIXELS \\\n"); fprintf(stderr, " -blurFactor NUMBER -extraLength PIXELS \\\n"); fprintf(stderr, " [ -mergeCands MAXSHIFT MINOVERLAP ] \\\n"); fprintf(stderr, " [ -verbose ] \n"); Process.Exit(1);; };; }; return o } /* GetOptions */ pz_candidate.List *MapAllCandidates( pz_candidate.List *cand, ARRAY *OF pz_double_chain_read_data oldLabel, double oldLambda, ARRAY *OF pz_double_chain_read_data newLabel, double newLambda, double newStep, double blurFactor, double extraLength, bool_t tryToMerge, unsigned maxShiftSteps, unsigned minOverlapSteps, bool_t verbose ) VAR nCandNew: unsigned = 0; { { /* with */ ??? nCandOld = (cand.ne); ??? candNew = NEW(REF pz_candidate.List, nCandOld)^; /* do */ fprintf(stderr, "Candidates before mapping == %s\n", Fmt.Int(nCandOld) ); for (i = 0; i <= nCandOld-1 ; i++){ { /* with */ ??? cOld = cand[i]; ??? cvx0 = cOld.seg[0].cvx; ??? cvx1 = cOld.seg[1].cvx; mappable = newLabel[cvx0].c # NIL AND newLabel[cvx1].c # NIL; /* do */ affirm(oldLabel[cvx0].c != NULL ) ANDAND ( oldLabel[cvx1].c != NULL ); if (( verbose )){ fprintf(stderr, "candidate %s: ", Fmt.Pad(Fmt.Int(i), 6, '0') );; }; if (( mappable )){ { /* with */ ??? cNew = MapCandidate(cOld; oldLabel, oldLambda; newLabel, newLambda; newStep := newStep; blurFactor := blurFactor; extraLength := extraLength ); /* do */ if (( cNew.seg[0].ns > 1 ) ANDAND ( cNew.seg[1].ns > 1 )){ if (( verbose )){ fprintf(stderr, " mapped! \n") ;}; candNew[nCandNew] = cNew; nCandNew++ }else{ if (( verbose )){ fprintf(stderr, "segment(s) vanished!\n") ;};; }; } }else{ if (( verbose )){ fprintf(stderr, " chain(s) missing!\n") ;};; }; };; }; fprintf(stderr, "Candidates before Sort and Merge == "); fprintf(stderr, Fmt.Int(nCandNew) & "\n"); pz_candidate_sort(SUBARRAY(candNew, 0, nCandNew), pz_candidate_pair_mismatch_better); if (( tryToMerge )){ fprintf(stderr, "Merging cands with at least " & Fmt.Int(minOverlapSteps) & " steps within " & Fmt.Int(maxShiftSteps) & " steps of each other\n"); pz_candidate_merge_overlaps( candNew, nCandNew, minSteps = minOverlapSteps, maxAdjust = maxShiftSteps ); fprintf(stderr, "Candidates after Sort and Merge == "); fprintf(stderr, Fmt.Int(nCandNew) & "\n"); }else{ fprintf(stderr, "Merging phase skipped\n");; }; { /* with */ ??? r = NEW(REF pz_candidate.List, nCandNew); /* do */ if (( nCandNew > 0 )){ r^ = SUBARRAY(candNew, 0, nCandNew) ;}; return r;; };; }; } /* MapAllCandidates */ pz_candidate_t MapCandidate( pz_candidate_t *cOld, ARRAY *OF pz_double_chain_read_data oldLabel, double oldLambda, ARRAY *OF pz_double_chain_read_data newLabel, double newLambda, double newStep, double blurFactor, double extraLength ) VAR seg: pz_segment_pair; tOld: ARRAY [0..1] OF REF pz_double_chain_t; tNew: ARRAY [0..1] OF REF pz_double_chain_t; stride: r2_t; stepNew: r2_t; extra: i2_t; { for (j = 0; j <= 1 ; j++){ { /* with */ ??? s = cOld.seg[j]; ??? halfShrink = blurFactor * (newLambda - oldLambda) / newStep; ??? halfStretch = extraLength / newStep; /* do */ seg[j] = s; tOld[j] = oldLabel[s.cvx].c; tNew[j] = newLabel[s.cvx].c; stride[j] = oldLabel[s.cvx].stride; stepNew[j] = newStep; extra[j] = ROUND(halfStretch - halfShrink); /* fprintf(stderr, " label stride == %s\n", Fmt.LongReal(stride[j]) ); */ affirm(oldLabel[s.cvx].stride == newLabel[s.cvx].stride );; };; }; { /* with */ mapCand = pz_candidate_map( cOld, tOld[0]^, tOld[1]^, tNew[0]^, tNew[1]^, stride, stepNew, extra ); /* do */ return mapCand; } } /* MapCandidate */ char *MapComments( Options *o ) { { /* with */ ??? wr = NEW(TextFILE *).init(); /* do */ fprintf( wr, "pz_map_cands \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) ); fprintf(wr, " outStep == %s\n", FLR(o.outStep,8,4) ); fprintf(wr, " maxMergeShift == %s\n", FLR(o.maxMergeShift,8,4) ); fprintf(wr, " minMergeOverlap == %s\n", FLR(o.minMergeOverlap,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. */