#define PROG_NAME "pz_map_chain" #define PROG_DESC "applies a geometric transformation to a curve" #define PROG_VERS "1.0" /* Copyright © 2001 by the State University of Campinas (UNICAMP). */ /* See the copyright, authorship, and warranty notice at end of file. */ /* Last edited on 2023-10-15 03:23:00 by stolfi */ #define PROG_HELP \ " " PROG_NAME " \\\n" \ " [ -reverse ] [ -recenter {None|Area|Samples|Ends} ] [ -untilt ] \\\n" \ " -matName NAME \\\n" \ " [ -ticks | -extraDots [ -prec NUM ] ] \\\n" \ " [ -axes ] [ -grid NUM ] \\\n" \ " < INCHAIN \\\n" \ " > OUTCHAIN\n" #define PROG_INFO \ "NAME\n" \ " " PROG_NAME " - " PROG_DESC "\n" \ "\n" \ "SYNOPSIS\n" \ PROG_HELP "\n" \ "\n" \ "DESCRIPTION\n" \ " This program reads a pz_r3_chain_t from standard input," \ " applies a 4x4 matrix to it, writes the resulting" \ " pz_r3_chain_t to standard output.\n" \ "\n" \ "AUTHORS\n" \ " Created in 2001 by Helena C. G. Leitão and Jorge Stolfi at IC-UNICAMP.\n" \ " Converted from Modula-3 to C in 2004-2006 by Jorge Stolfi." #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include typedef struct options_t { char *inName; /* Input file name without extension, OR "-" */ char *matName; /* Matrix file name without extension. */ bool_t reverse; /* TRUE to reverse the curve */ pz_ctr_t recenter; /* Which center to use, or {pz_ctr_NONE} to omit centering. */ bool_t untilt; /* TRUE places the curve endpoints on the X-axis. */ char *outName; /* Output file name without extension, OR "-" */ } options_t; int main(int argc, char **argv); pz_matrix_t pzmc_read_matrix(char *matName); /* Reads a {pz_matrix_t} from file "{matName}.matrix" (or from {stdin}, if {matName} is "-"). */ options_t *pzmc_get_options(int argc, char **argv); int main(int argc, char **argv) { options_t *o = pzmc_get_options(argc, argv); pz_matrix_t m = pzmc_read_matrix(o->matName); pz_r3_chain_read_data_t aData = pz_r3_chain_read(stdin, FALSE, FALSE); pz_r3_chain_t a = aData.c; /* pz_matrix_write(stderr, &m); */ if (o->reverse) { pz_r3_chain_reverse(&a); } if (o->recenter != pz_ctr_NONE) { pz_r3_chain_recenter(&a, o->recenter); } if (o->untilt) { double pos = ( o->recenter == pz_ctr_ENDS ? 0.00 : 0.20 ); pz_r3_chain_untilt(&a, pz_ctr_NONE, pos); } pz_r3_chain_t b = pz_r3_chain_map(&a, &m); char *bCmt = txtcat(aData.cmt, "\n mapped by pz_map_chain\n"); pz_r3_chain_write(stdout, bCmt, &b, aData.unit); return 0; } pz_matrix_t pzmc_read_matrix(char *matName) { FILE *rd; char *fileName = add_ext(matName, ".matrix"); rd = open_read(fileName, TRUE); pz_matrix_t m = pz_matrix_read(rd); fclose(rd); free(fileName); return m; } options_t *pzmc_get_options(int argc, char **argv) { 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); options_t *o = malloc(sizeof(options_t)); o->reverse = argparser_keyword_present(pp, "-reverse"); if (argparser_keyword_present(pp, "-recenter")) { if (argparser_keyword_present_next(pp, "None")) { o->recenter = pz_ctr_AREA; } else if (argparser_keyword_present_next(pp, "Area")) { o->recenter = pz_ctr_AREA; } else if (argparser_keyword_present_next(pp, "Samples")) { o->recenter = pz_ctr_SMPS; } else if (argparser_keyword_present_next(pp, "Ends")) { o->recenter = pz_ctr_ENDS; } else { argparser_error(pp, "invalid center type for \"-recenter\""); } } else { o->recenter = pz_ctr_NONE; } o->untilt = argparser_keyword_present(pp, "-untilt"); argparser_get_keyword(pp, "-matName"); o->matName = argparser_get_next(pp); argparser_finish(pp); return o; } /* 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. */