/* Draws a list of curve segments. */ /* Last edited on 2015-01-20 16:45:41 by stolfilocal */ /* Output file names are "XXX-NNNNN.eps" if "-epsFormat" is given, or "XXX.ps" otherwise; where XXX is the "-output" parameter, and "NNNNN" is the candidate's index in the file. */ #include #include #include #include #include #include #include #include TYPE Options = struct ??? { char *input; /* Input segment file name. */ unsigned firstSeg; /* Index of first segment to plot. */ unsigned lastSeg; /* Index of last segment to plot. */ char *chainDir; /* Directory where chains can be found. */ char *chainPrefix; /* Chain file name prefix. */ unsigned band; /* Filtering scale ID for file names. */ double step; /* Nominal input sampling step (pixels). */ char *extension; /* Extension for geometric chains (".flc" usually) */ char *output; /* Output plot file (without ".ps"/".eps") */ /* Plotting options */ bool_t segsOnly; /* TRUE does not draw curve outside segment. */ bool_t drawAllSamples; /* TRUE plot all samples, FALSE only every 0.1mm. */ bool_t sampleDots; /* Plot a dot at each sample position. */ bool_t noPointers; /* TRUE omits the arrowheads at the segment ends. */ bool_t noFrame; /* TRUE omits the frame around each segment. */ bool_t noColors; /* TRUE uses only black, FALSE uses red/blue for segs. */ bool_t noThicker; /* TRUE draws segments like rest of curve, FALSE thicker. */ double labelSize; /* Curve label size in points (0 = no labels). */ double grid; /* Coordinate grid spacing (0 = no grid). */ /* Options for output file format and scale: */ pz_plot.DrawFmtOptions drawFmt; /* Options that control the scale bar and/or icon at corner: */ pz_plot.ScaleIconOptions scaleIconOptions; /* Icon style options. */ double scaleIconLambda; /* Basic length for scale/icon */ } ???; int main(int argc, char **argv ) { { /* with */ ??? o = pz_get_options(int argc, char **argv); /* do */ if (( o.lastSeg >= o.firstSeg )){ { /* with */ ??? inpData = ReadSegs(o.input); ??? inpSeg = inpData.s^; ??? chainUsed = ChainsReallyUsed(inpSeg, o)^; chAllData = pz_r3_chain_read_all( o.chainPrefix, o.band, o.extension, sel := chainUsed; dir := o.chainDir, header_only := FALSE, recenter := pz_ctr_NONE ); /* do */ DrawSegments(inpSeg, chAllData.chData^, o);; };; };; }; } /* Main */ pz_segment_read_data ReadSegs( char *name ) { { /* with */ ??? fileName = txtcat(name , ".seg"); /* do */ fprintf(stderr, "reading %s ...\n", fileName ); return pz_segment_read(open_read(fileName, TRUE)); } } /* ReadSegs */ bool_vec_t *ChainsReallyUsed( pz_segment_vec_t *seg, Options *o ) { { /* with */ ??? nSegs = MIN(o.lastSeg, (seg.ne - 1)) - o.firstSeg + 1; /* do */ return pz_segment_chains_used(SUBARRAY(seg, o.firstSeg, nSegs)); } } /* ChainsReallyUsed */ void DrawSegments( pz_segment_vec_t *seg, ARRAY *OF pz_r3_chain_read_data flc, Options *o ) VAR nInFile: unsigned; { { /* with */ ??? firstSeg = o.firstSeg; ??? lastSeg = MIN(o.lastSeg, (seg.ne - 1)); /* do */ fprintf(stderr, "Drawing segments from " & Fmt.Int(firstSeg) & " to " & Fmt.Int(lastSeg) & "\n" ); for ( iSeg = firstSeg TO lastSeg ){ { /* with */ ??? id = Fmt.Pad(Fmt.Int(iSeg), 5, '0'); /* do */ pz_plot.BeginNewDrawing(f, o.output, id, o.drawFmt, nInFile); }; DrawSegment(f, seg[iSeg], flc, o); }; }; pz_plot.NoMoreDrawings(f, o.drawFmt, nInFile); fprintf(stderr, "Drawings finished.\n") } /* DrawSegments */ void DrawSegment( PSPlot.File f, pz_segment_t *seg, ARRAY *OF pz_r3_chain_read_data flc, Options *o ) VAR color: PSPlot.Color; { if (( o.grid > 0.0e0 )){ pz_plot.Grid(f, o.grid) ;}; if (( NOT o.noFrame )){ pz_plot.Frame(f) ;}; { /* with */ ??? chainNum = seg.cvx; ??? chain = flc[chainNum].c^; m = pz_pose.PlaceSegment( seg, chain; tilt := 0.0e0, shift := LR2.T{0.0e0, 0.0e0}; flip := FALSE ); ??? mappedChain = pz_r3_chain_map(chain, m)^; /* do */ if (( o.noColors )){ color = PSPlot.Black }else{ color = PSPlot.Red ;}; pz_plot.HalfCandidate( f, seg, mappedChain, whole = NOT o.segsOnly, closed = TRUE, color = color, thicker = NOT o.noThicker, dots = o.sampleDots, pointers = NOT o.noPointers, labelSize = o.labelSize, drawEvery = pz_plot.ComputeDrawEvery(f, 0.2, o.step, all = o.drawAllSamples) );; }; if (( o.scaleIconLambda > 0.0e0 ) || ( o.scaleIconOptions.barCount > 0 )){ pz_plot.ScaleIcon(f, lambda = o.scaleIconLambda, o = o.scaleIconOptions); }; } /* DrawSegment */ 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, "-band"); o.band = argparser_get_next_int(pp); if (( argparser_keyword_present(pp, "-extension") )){ o.extension= argparser_get_next(pp); }else{ o.extension = ".flc";; }; argparser_get_keyword(pp, "-step"); o.step = argparser_get_next_double(pp, 0.0e0, 1024.0e0); argparser_get_keyword(pp, "-output"); o.output = argparser_get_next(pp); if (( argparser_keyword_present(pp, "-maxSegs") )){ o.firstSeg = 0; o.lastSeg = argparser_get_next_int(pp, 1) - 1 }else if (( argparser_keyword_present(pp, "-segsRange") )){ o.firstSeg = argparser_get_next_int(pp, 0); o.lastSeg = argparser_get_next_int(pp, o.firstSeg) }else{ o.firstSeg = 0; o.lastSeg = 239; }; o.drawAllSamples = argparser_keyword_present(pp, "-drawAllSamples"); o.segsOnly = argparser_keyword_present(pp, "-segsOnly"); o.sampleDots = argparser_keyword_present(pp, "-sampleDots"); o.noPointers = argparser_keyword_present(pp, "-noPointers"); o.noFrame = argparser_keyword_present(pp, "-noFrame"); o.noColors = argparser_keyword_present(pp, "-noColors"); o.noThicker = argparser_keyword_present(pp, "-noThicker"); if (( argparser_keyword_present(pp, "-labelSize") )){ o.labelSize = pp.getNextReal(0.0, 100.0) }else{ o.labelSize = 12.0; }; if (( argparser_keyword_present(pp, "-grid") )){ o.grid = argparser_get_next_double(pp, 1.0e-10, 1.0e+10) }else{ o.grid = 0.0e0; }; o.drawFmt = pz_plot.ParseDrawFmtOptions( pp, single = FALSE, defaultWidth = 40.0e0, defaultHeight = 40.0e0 ); o.scaleIconOptions = pz_plot.ParseScaleIconOptions(pp); if (( argparser_keyword_present(pp, "-scaleBarStep") ) || ( argparser_keyword_present(pp, "-scaleIconLambda") )){ o.scaleIconLambda = argparser_get_next_double(pp, 0.0e0); }else{ if (( o.scaleIconOptions.style != pz_plot.ScaleIconStyle.None ) || ( o.scaleIconOptions.barCount > 0 )){ argparser_error(pp, "scale icon/bar requires \"-scaleBarStep\" or \"-scaleIconLambda\""); }; o.scaleIconLambda = 0.0e0; }; argparser_finish(pp); EXCEPT | ParseParams.Error ==> fprintf(stderr, "Usage: pz_draw_segs \\\n"); fprintf(stderr, " -input NAME \\\n"); fprintf(stderr, " [ -chainDir DIR ] -chainPrefix NAME \\\n"); fprintf(stderr, " -band NUMBER [ -extension EXT ] -step NUM \\\n"); fprintf(stderr, " -output NAME \\\n"); fprintf(stderr, " [ -maxSegs NUMBER | -segsRange FIRSTNUM LASTNUM ] \\\n"); fprintf(stderr, " [ -segsOnly ] [ -sampleDots ] [ -noColors ] \\\n"); fprintf(stderr, " [ -noPointers ] [ -noFrame ] [ -noThicker ] \\\n"); fprintf(stderr, " [ -grid SPACING ] [ -labelSize POINTS ] \\\n"); fprintf(stderr, " [ -drawAllSamples ] \\\n"); fprintf(stderr, pz_plot.ScaleIconOptionsHelp & " \\\n"); fprintf(stderr, " [ -scaleBarStep NUM | -scaleIconLambda NUM ] \\\n"); fprintf(stderr, pz_plot.DrawFmtOptionsHelp & " \n"); Process.Exit(1);; };; }; return o } /* GetOptions */ { /* 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. */