/*****************************************************************************/ /* */ /* Copyright (C) 1999-2025 M. Held */ /* */ /* This code is not in the public domain. All rights reserved! Please make */ /* sure to read the full copyright statement contained in "README.txt" or in */ /* the "main" file of this code, such as "main.cc". */ /* */ /*****************************************************************************/ /* */ /* Written by: Martin Held */ /* */ /* E-Mail: held@cs.sbg.ac.at */ /* Fax Mail: (+43 662) 8044-611 */ /* Voice Mail: (+43 662) 8044-6304 */ /* Snail Mail: Martin Held */ /* FB Informatik */ /* Universitaet Salzburg */ /* A-5020 Salzburg, Austria */ /* */ /*****************************************************************************/ /* */ /* get standard libraries */ /* */ #include #include #include #include #include #include #include "vronivector.h" /* */ /* get my header files */ /* */ #include "vroni_object.h" #include "fpkernel.h" #include "defs.h" #include "ext_appl_defs.h" /* */ /* this function parses the command-line arguments */ /* */ vr_bool vroniObject::ArgEval(int argc, char *argv[], vr_bool *color_graphics, vr_bool *graphics, vr_bool *save_data, char *output_file, vr_bool *read_input, char *input_file, vr_bool *read_poly, int *step_size, vr_bool *verbose, vr_bool *write_ipe, vr_bool *help, vr_bool *time, vr_bool *statistics, vr_bool *print_copy, vr_bool *quiet, int *bound, int *sample, vr_bool *scale, int *approx, vr_bool *read_sites, vr_bool *read_xdr, vr_bool *read_graphml, vr_bool *discard_dupl_s, int *p_step_size, vr_bool *read_e00, vr_bool *read_dxf, vr_bool *read_polylines, double *t_offset, double *d_offset, vr_bool *write_off, char *off_file, int *o_step_size, vr_bool *auto_offset, vr_bool *full_screen, vr_bool *read_usgs, vr_bool *left_offset, vr_bool *right_offset, vr_bool *compute_wmat, double *wmat_angle, double *wmat_dist, vr_bool *auto_wmat, vr_bool *pnts_only, vr_bool *compute_mic, int *a_step_size, vr_bool *check_data, vr_bool *write_vd_dt, char *vd_dt_file, vr_bool *read_pnts, vr_bool *dxf_format, vr_bool *read_file, vr_bool *write_ma, char *ma_file, vr_bool *clean_up, vr_bool *write_vd, char *vd_file, double *vd_apx_dist, vr_bool *left_vd, vr_bool *right_vd, vr_bool *vr_incr, char *vr_file, int *inputprec, int *mpfr_prec, int *seed, vr_bool *compute_path, double *tool_rad, double *angle, double *step_over, vr_bool *write_path, char *path_file) { int count = 1; vr_bool success = true; vr_bool ext_appl_success = false; /* */ /* let the user call some application-specific function */ /* */ ExtApplFuncArgEvalInit; /* */ /* default initializations */ /* */ *seed = 0; *color_graphics = true; *save_data = false; *read_input = false; *read_poly = false; *read_sites = false; *read_xdr = false; *read_graphml = false; *read_polylines = false; *read_e00 = false; *read_usgs = false; *read_dxf = false; *read_pnts = false; *read_file = false; *graphics = false; *step_size = INT_MAX; *p_step_size = INT_MAX; *o_step_size = INT_MAX; *a_step_size = INT_MAX; *verbose = false; *write_ipe = false; *help = false; *time = false; *statistics = false; *print_copy = true; *quiet = false; *sample = 0; *bound = 3; *scale = true; *approx = 0; *discard_dupl_s = false; *t_offset = 0.0; *d_offset = 0.0; *write_off = false; *auto_offset = false; *full_screen = false; *left_offset = false; *right_offset = false; *compute_wmat = false; *wmat_angle = 0.0; *wmat_dist = 0.0; *auto_wmat = false; *pnts_only = false; *compute_mic = false; *check_data = true; *dxf_format = false; *write_ma = false; *clean_up = false; *write_vd = false; *left_vd = false; *right_vd = false; *vr_incr = false; *vd_apx_dist = 0.0; *inputprec = -1; *mpfr_prec = 23; *compute_path = false; *tool_rad = 0.0; *angle = 360.0; *step_over = 0.0; *write_path = false; strcpy(vd_file, ""); strcpy(vd_dt_file, ""); strcpy(output_file, ""); strcpy(input_file, ""); strcpy(vr_file, ""); strcpy(path_file, ""); /* */ /* parse the command-line arguments */ /* */ while ((count < argc) && success) { if (strcmp(argv[count],"--duplicate") == 0) { *discard_dupl_s = true; } else if (strcmp(argv[count],"--no_check") == 0) { *check_data = false; } else if (strcmp(argv[count],"--quiet") == 0) { *quiet = true; } else if (strcmp(argv[count],"--verbose") == 0) { *verbose = true; } else if (strcmp(argv[count],"--b+w") == 0) { *color_graphics = false; } #ifdef GRAPHICS else if (strcmp(argv[count],"--OGL") == 0) { *graphics = true; } else if (strcmp(argv[count],"--Ipe") == 0) { if(! *save_data) { *write_ipe = true; ++count; if ((success = (count < argc))) strcpy(output_file, argv[count]); } } #endif else if (strcmp(argv[count],"--seed") == 0) { ++count; if ((success = (count < argc))) *seed = atoi(argv[count]); if (*seed < 0) *seed = 0; } else if (strcmp(argv[count],"--step") == 0) { *graphics = true; ++count; if ((success = (count < argc))) *step_size = atoi(argv[count]); if (*step_size < 1) *step_size = 1; } else if (strcmp(argv[count],"--pstep") == 0) { *graphics = true; ++count; if ((success = (count < argc))) *p_step_size = atoi(argv[count]); if (*p_step_size < 1) *p_step_size = 1; } else if (strcmp(argv[count],"--ostep") == 0) { *graphics = true; ++count; if ((success = (count < argc))) *o_step_size = atoi(argv[count]); if (*o_step_size < 1) *o_step_size = 1; } else if (strcmp(argv[count],"--astep") == 0) { *graphics = true; ++count; if ((success = (count < argc))) *a_step_size = atoi(argv[count]); if (*a_step_size < 1) *a_step_size = 1; } else if (strcmp(argv[count],"--full") == 0) { *full_screen = true; } else if (strcmp(argv[count],"--pnts_only") == 0) { *pnts_only = true; } else if (strcmp(argv[count],"--stat") == 0) { *statistics = true; } else if (strcmp(argv[count],"--copy") == 0) { *print_copy = false; } else if (strcmp(argv[count],"--time") == 0) { *time = true; } else if (strcmp(argv[count],"--help") == 0) { *help = true; } else if (strcmp(argv[count],"--noscale") == 0) { *scale = false; } else if (strcmp(argv[count],"--auto_offset") == 0) { *auto_offset = true; } #ifdef MAT else if (strcmp(argv[count],"--wmat") == 0) { *compute_wmat = true; } #endif #ifdef WMAT else if (strcmp(argv[count],"--auto_wmat") == 0) { *auto_wmat = true; *compute_wmat = true; } else if (strcmp(argv[count],"--wmat_angle") == 0) { ++count; if ((success = (count < argc))) *wmat_angle = atof(argv[count]); if (*wmat_angle < 0.0) *wmat_angle = 0.0; *compute_wmat = true; } else if (strcmp(argv[count],"--wmat_dist") == 0) { ++count; if ((success = (count < argc))) *wmat_dist = atof(argv[count]); if (*wmat_dist < 0.0) *wmat_dist = 0.0; *compute_wmat = true; } #endif else if (strcmp(argv[count],"--left_offset") == 0) { *left_offset = true; } else if (strcmp(argv[count],"--right_offset") == 0) { *right_offset = true; } else if (strcmp(argv[count],"--mic") == 0) { #ifdef MIC *compute_mic = true; #endif } else if (strcmp(argv[count],"--save") == 0) { if(! *write_ipe) { *save_data = true; ++count; if ((success = (count < argc))) strcpy(output_file, argv[count]); } } else if (strcmp(argv[count],"--vd_dt") == 0) { *write_vd_dt = true; ++count; if ((success = (count < argc))) strcpy(vd_dt_file, argv[count]); } else if (strcmp(argv[count],"--vr_incr") == 0) { *vr_incr = true; ++count; if ((success = (count < argc))) strcpy(vr_file, argv[count]); } else if (strcmp(argv[count],"--approx") == 0) { ++count; if ((success = (count < argc))) *approx = atoi(argv[count]); if (*approx < 0) *approx = 0; } else if (strcmp(argv[count],"--bound") == 0) { ++count; if ((success = (count < argc))) *bound = atoi(argv[count]); if (*bound < 3) *bound = 3; } else if (strcmp(argv[count],"--file") == 0) { *read_file = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--input") == 0) { *read_input = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--poly") == 0) { *read_poly = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--pnts") == 0) { *read_pnts = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--polylines") == 0) { *read_polylines = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--xdr") == 0) { *read_xdr = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--usgs") == 0) { *read_usgs = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--e00") == 0) { *read_e00 = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--dxf") == 0) { *read_dxf = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--sites") == 0) { *read_sites = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--graphml") == 0) { *read_graphml = true; ++count; if ((success = (count < argc))) strcpy(input_file, argv[count]); } else if (strcmp(argv[count],"--offset") == 0) { ++count; if ((success = (count < argc))) *t_offset = atof(argv[count]); if (*t_offset < 0.0) *t_offset = 0.0; } else if (strcmp(argv[count],"--doffset") == 0) { ++count; if ((success = (count < argc))) *d_offset = atof(argv[count]); if (*t_offset < 0.0) *d_offset = 0.0; } else if (strcmp(argv[count],"--off") == 0) { *write_off = true; ++count; if ((success = (count < argc))) strcpy(off_file, argv[count]); } else if (strcmp(argv[count],"--ma") == 0) { *write_ma = true; ++count; if ((success = (count < argc))) strcpy(ma_file, argv[count]); } else if (strcmp(argv[count],"--off_dxf") == 0) { *write_off = true; *dxf_format = true; ++count; if ((success = (count < argc))) strcpy(off_file, argv[count]); } else if (strcmp(argv[count],"--clean") == 0) { *clean_up = true; } #ifdef WRITE_VD else if (strcmp(argv[count],"--vd") == 0) { *write_vd = true; ++count; if ((success = (count < argc))) strcpy(vd_file, argv[count]); } else if (strcmp(argv[count],"--vd_apx_dist") == 0) { ++count; if ((success = (count < argc))) *vd_apx_dist = atof(argv[count]); } else if (strcmp(argv[count],"--left_vd") == 0) { *left_vd = true; } else if (strcmp(argv[count],"--right_vd") == 0) { *right_vd = true; } #endif #ifdef TRACE else if (strcmp(argv[count],"--write") == 0) { write_debug = true; } else if (strcmp(argv[count],"--center") == 0) { center = true; } else if (strcmp(argv[count],"--proto") == 0) { proto = true; } else if (strcmp(argv[count],"--cntr") == 0) { ++count; if ((success = (count < argc))) max_cntr = atoi(argv[count]); if (max_cntr < 1) max_cntr = 0; } #endif #ifdef WITH_COREBACKEND else if (strcmp(argv[count],"--inputprec") == 0) { ++count; if ((success = (count < argc))) *inputprec = atoi(argv[count]); if (*inputprec < -1) *inputprec = -1; } #elif defined(WITH_MPFRBACKEND) else if (strcmp(argv[count],"--mpfr-prec") == 0) { ++count; *mpfr_prec = 0; if ((success = (count < argc))) *mpfr_prec = atoi(argv[count]); if (*mpfr_prec < 23) *mpfr_prec = 23; //TODO: Appropriate warning } #endif #ifdef OTHER else if (strcmp(argv[count],"--cgal") == 0) { cgal = true; } #endif #ifdef HSM else if (strcmp(argv[count],"--mathsm") == 0) { *compute_path = true; } else if (strcmp(argv[count],"--radius") == 0) { ++count; if ((success = (count < argc))) *tool_rad = atof(argv[count]); } else if (strcmp(argv[count],"--step_over") == 0) { ++count; if ((success = (count < argc))) *step_over = atof(argv[count]); } else if (strcmp(argv[count],"--angle") == 0) { ++count; if ((success = (count < argc))) *angle = atof(argv[count]); } else if (strcmp(argv[count],"--path_dxf") == 0) { *write_path = true; ++count; if ((success = (count < argc))) strcpy(path_file, argv[count]); } #endif else { /* */ /* perhaps this is a user-supplied run-time option? let the user */ /* call some application-specific function. make sure to set the */ /* vr_bool flag ext_appl_success appropriately when using this */ /* application-specific function! */ /* */ ExtApplFuncArgEvalParse; success = ext_appl_success; } ++count; } if (*read_pnts) *pnts_only = true; if (*pnts_only && (*bound < 5)) *bound = 5; if (!*graphics) { *step_size = INT_MAX; *p_step_size = INT_MAX; *o_step_size = INT_MAX; } /* */ /* let the user call some application-specific function */ /* */ ExtApplFuncArgEvalDone; return success; } void vroniObject::EvalError(void) { fprintf(stderr, "\nUsage: vroni [--help] [--stat] "); fprintf(stderr,"[--bound NNN] [--noscale] [--duplicate] [--time]\n"); fprintf(stderr, " [--no_check] [--pnts_only] [--vd_dt XXX]"); fprintf(stderr, " [--file XXX] [--save XXX]\n"); /* fprintf(stderr, " [--poly XXX] [--input XXX] [--sites XXX]"); fprintf(stderr, " [--usgs XXX] [--dxf XXX]\n"); fprintf(stderr, " [--polylines XXX] [--xdr XXX] [--e00 XXX]"); fprintf(stderr, " [--pnts XXX]\n"); */ #ifdef OGL_GRAPHICS fprintf(stderr, " [--OGL] [--b+w] [--step NNN] [--pstep NNN]"); fprintf(stderr, " [--ostep NNN]\n"); fprintf(stderr, " [--astep NNN] [--Ipe XXX] [--full] [--clean]\n"); #elif defined(GRAPHICS) fprintf(stderr, " [--Ipe XXX]\n"); #endif /* fprintf(stderr, " [--approx NNN]\n"); */ fprintf(stderr, " [--mic] [--auto_offset] [--offset FFF] [--doffset FFF]\n"); fprintf(stderr, " [--off XXX | --off_dxf XXX] [--left_offset] [--right_offset]\n"); #ifdef MAT #ifdef WMAT fprintf(stderr, " [--wmat] [--wmat_angle FFF] [--wmat_dist FFF]"); fprintf(stderr, " [--auto_wmat]\n"); #else fprintf(stderr, " [--wmat]\n"); #endif #endif #ifdef WRITE_VD fprintf(stderr, " [--vd] [--vd_apx_dist] [--left_vd] [--right_vd]\n"); #endif #ifdef VRONI_INFO fprintf(stderr, " [--quiet] [--verbose]\n"); #endif #ifdef TRACE fprintf(stderr, " [--center] [--write] [--proto] [--cntr]\n"); #endif #ifdef OTHER fprintf(stderr, " [--cgal]\n"); #endif #ifdef WITH_MPFRBACKEND fprintf(stderr, " [--mpfr-prec NNN]\n"); #elif defined(WITH_COREBACKEND) fprintf(stderr, " [--inputprec NNN]\n"); #endif #ifdef HSM fprintf(stderr, " [--mathsm] [--radius FFF] [--step_over FFF] [--angle FFF]\n"); fprintf(stderr, " [--path_dxf XXX]\n"); #endif /* */ /* let the user call some application-specific function */ /* */ ExtApplFuncEvalErrorOption; fprintf(stderr, "\n"); fprintf(stderr, "--help: causes the program to print this help message\n"); #ifdef VRONI_INFO fprintf(stderr, "--verbose: write warning and informatory messages to stdout\n"); fprintf(stderr, "--quiet: do not output warning or informatory messages\n"); #endif #ifdef GRAPHICS #ifdef OGL_GRAPHICS fprintf(stderr, "--OGL: enable an interactive OGL display\n"); #endif fprintf(stderr, "--full: full-screen graphics window\n"); fprintf(stderr, "--Ipe XXX: write data in Ipe 7.0 (.ipe) format to file `XXX'\n"); fprintf(stderr, "--b+w: b/w rather than color graphics\n"); fprintf(stderr, "--step NNN: insert NNN input segments before redrawing\n"); fprintf(stderr, "--pstep NNN: insert NNN input points before redrawing\n"); fprintf(stderr, "--astep NNN: insert NNN input arcs before redrawing\n"); fprintf(stderr, "--ostep NNN: compute NNN offsets before redrawing\n"); #endif fprintf(stderr, "--pnts_only: consider only points/vertices and compute only point VD/DT\n"); fprintf(stderr, "--vd_dt XXX: output point VD/DT to file `XXX'; only used in\n"); fprintf(stderr, " conjunction with option \"--pnts_only\"\n"); fprintf(stderr, "--vr_incr XXX: output Voronoi regions file `XXX', one after the other;\n"); fprintf(stderr, " only used in conjunction with option \"--pnts_only\"\n"); fprintf(stderr, "--save XXX: save data in Martin's `sites' format to file `XXX'\n"); #ifdef WRITE_VD fprintf(stderr, "--vd XXX: output approximate VD faces to file `XXX' in OBJ format\n"); fprintf(stderr, "--vd_apx_dist d: sampling distance for approxmating conic VD edges\n"); fprintf(stderr, "--left_vd: output VD only on left side of input segments\n"); fprintf(stderr, "--right_vd: output VD only on right side of input segments\n"); #endif #ifdef WITH_COREBACKEND fprintf(stderr, "--inputprec NNN: Input precision (CORE library). -1 for CORE_INFTY\n"); #elif defined(WITH_MPFRBACKEND) fprintf(stderr, "--mpfr-prec NNN: Precision to use in MPFR backend, must be at least 23\n"); #endif fprintf(stderr, "--bound NNN: compute the VD only in a region whose width is\n"); fprintf(stderr, " (2NNN+1) times the width of the bounding box of the\n"); fprintf(stderr, " input data; similar for the height. default: NNN = 3.\n"); /* fprintf(stderr, "--approx NNN: integer approximation factor for approximating arcs\n"); */ fprintf(stderr, "--noscale: do not scale the input data in order to convert it to `nice'\n"); fprintf(stderr, " coordinates. (default: scale the data.)\n"); fprintf(stderr, " strongly recommended not to use this option!\n"); fprintf(stderr, "--duplicate: check for duplicate segs/arcs prior to running the\n"); fprintf(stderr, " VD code. (default: check during computation.)\n"); fprintf(stderr, " time-consuming!!\n"); fprintf(stderr, "--no_check: do not apply a time-consuming all-pairs check if\n"); fprintf(stderr, " self-intersections are suspected.\n"); fprintf(stderr, "--time: time the computation of the Voronoi diagram\n"); fprintf(stderr, "--stat: compute and output some statistics\n"); fprintf(stderr, "--offset t: compute offset curves for offset distance t.\n"); fprintf(stderr, "--doffset d: compute offset pattern for offsets t, t+d, t+2d,...\n"); fprintf(stderr, "--auto_offset: compute offset pattern according to `nice' offsets\n"); fprintf(stderr, " automatically determined by the program\n"); fprintf(stderr, "--left_offset: compute offset pattern only on left side of input segments\n"); fprintf(stderr, "--right_offset: compute offset pattern only on right side of input segments\n"); fprintf(stderr, "--off XXX: output the offset data in my .dat format to file `XXX'\n"); fprintf(stderr, "--off_dxf XXX: output the offset data in .dxf format to file `XXX'\n"); fprintf(stderr, "--mic: compute the maximum inscribed/empty circle.\n"); #ifdef MAT #ifdef WMAT fprintf(stderr, "--wmat: compute (weighted) medial axis\n"); fprintf(stderr, "--wmat_angle a: angle threshold for WMAT computation\n"); fprintf(stderr, "--wmat_dist d: distance threshold for WMAT computation\n"); fprintf(stderr, "--auto_wmat: compute WMAT according to `nice' thresholds\n"); fprintf(stderr, " automatically determined by the program\n"); #else fprintf(stderr, "--wmat: compute medial axis\n"); #endif #endif fprintf(stderr, "--file XXX: read input data from file `XXX'; the appropriate input\n"); fprintf(stderr, " function is selected automatically based on the extension\n"); fprintf(stderr, " of the file.\n"); fprintf(stderr, " The following input formats are supported:\n"); fprintf(stderr, " *.dat: read data in Martin's format from file `*.dat';\n"); fprintf(stderr, " *.poly: read polygon in simplified format from file `*.poly';\n"); fprintf(stderr, " *.site: read sites (pnts, segs, arcs) from file `*.site';\n"); fprintf(stderr, " *.line: read polygonal chains from file `*.line';\n"); fprintf(stderr, " *.usgs: read data in USGS format from file `*.usgs';\n"); fprintf(stderr, " *.xdr: read data in Facet_XDR format from file `*.xdr';\n"); fprintf(stderr, " *.e00: read data in ArcInfo export format from file `*.e00';\n"); fprintf(stderr, " *.dxf: read data in AutoCAD's dxf format from file `*.dxf';\n"); fprintf(stderr, " *.pnt: read point data from file `*.pnt';\n"); fprintf(stderr, " *.xml: read data in Ipe 6 .xml format from file `*.xml'.\n"); fprintf(stderr, " *.ipe: read data in Ipe 6 XML format from file `*.ipe'.\n"); fprintf(stderr, " *.bdm: read polygons in .bdm format from file `*.bdm'.\n"); #ifdef OTHER fprintf(stderr, "--cgal: write data to `cgal.cin' as input for CGAL's VD code\n"); #endif fprintf(stderr, "--clean: clean up the data by looking for intersections prior to\n"); fprintf(stderr, " the VD computation\n"); #ifdef HSM fprintf(stderr, "--mathsm: compute MATHSM path\n"); fprintf(stderr, "--radius FFF: tool radius\n"); fprintf(stderr, "--step_over FFF: maximum step-over distance\n"); fprintf(stderr, "--angle FFF: maximum engagement angle\n"); fprintf(stderr, "--path_dxf XXX: output file for tool path; path is written in .dxf format\n"); #endif /* */ /* let the user call some application-specific function */ /* */ ExtApplFuncEvalErrorExplain; return; } #include "ext_appl_arg_eval.cc"