#define PROG_NAME "RandomShape" #define PROG_DESC "???" #define PROG_VERS "1.0" #define RandomShape_C_COPYRIGHT \ "" #define PROG_INFO \ "" \ " " /* This module generates N random variations (trials) of a given ".tp" file. Reused without extensive modifications, created originally by J. Stolfi and R. Marcone. */ #define RandomShape_C_author \ "Created originally by J. Stolfi and R. M. Rosi for 2D maps.\n" \ "Modified by L.A.P.Lozada on 02-12-1999." #include #include #include #define _GNU_SOURCE #include #include TYPE typedef struct Options_t { char *input; /* Input file name (minus ".tp" extension) */ char *output; /* Output file name prefix */ uint trialMin; /* Number of first configuration to generate */ uint trialMax; /* Number of last configuration to generate */ REAL jitter; /* Magnitude of random perturbation */ bool_t normalize; /* TRUE to normalize the node coordinates */ } Options_t *GetOptions(int argc, char **argv); int main(int argc, char **argv) char **cmt; { Options_t *o = GetOptions(argc, argv); char *topo_cmt = jsprintf("Created by %s on %s", PROG_NAME, Today()); /* Random_t coins = MakeRandomSource(4615); */ ??? coins = NEW(Random.Default).init(TRUE); ??? tc = Triangulation.ReadToMa(o->input); ??? top = tc.top; ??? rc = Triangulation.ReadState(o->input); ??? cOld = rc^; ??? cNew = NEW(REF Coords_t; with ( top->node.nel)^ ){ if (o->normalize) { Triangulation.NormalizeNodeDistances(top, cOld, TRUE) } for (k = o->trialMin; k <= (o->trialMax); k++) { cNew = cOld; PerturbCoords(top, cNew, coins, ((double)o->jitter)); if (o->normalize) { Triangulation.NormalizeNodeDistances(top, cNew, TRUE) } cmt = " Random variation Number: " & Fmt.Int(k) & "\n" \ " Randomizing from: " & o->input & ".top\n" & " Created by RandomShape: " & o->output & "-" \ Fmt.Pad(Fmt.Int(k), 2, '0') & ".tp\n"; WriteState(o->output & "-" & Fmt.Pad(Fmt.Int(k),2,'0'), top,cNew,cmt & "\nRandom Geometry") } return 0; } PROCEDURE PerturbCoords(ElemTableRec_t *top, Coords_t *c, rand_t *coins; double jitter; ) { for (i = 0 TO (c.nel-1)){ if ((OrgV(top->node.el[i])->exists) && (NOT top->node[i].fixed)) { ??? ci = c[i]; with ( double p = (r4_t) { jitter * coins.longreal(-1.0, +1.0), jitter * coins.longreal(-1.0, +1.0), jitter * coins.longreal(-1.0, +1.0), jitter * coins.longreal(-1.0, +1.0) } ){ ci = r4_Add(ci, p); } } } } /* END PerturbCoords */ Options_t *GetOptions(int argc, char **argv) { Options_t *o = (Options_t *)malloc(sizeof(Options_t)); 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); { ¦TRY argparser_get_keyword(pp, "-input"); o->input = argparser_get_next(pp); argparser_get_keyword(pp, "-output"); o->output = argparser_get_next(pp); argparser_get_keyword(pp, "-trials"); o->trialMin = argparser_get_next_int(pp, 0); o->trialMax = argparser_get_next_int(pp, o->trialMin); o->normalize = argparser_keyword_present(pp, "-normalize"); if ((argparser_keyword_present(pp, "-jitter"))) { o->jitter = pp.getNextReal(0.0); } else { o->jitter = 1.0 } argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: RandomShape \\\n" \ " -input -output \\\n" \ " -trials \\\n" \ " [ -normalize ] [ -jitter ]\n"); END¦ } } return o; } /* END GetOptions */ { DoIt() } RandomShape. /* Comments -------- The procedure "Triangulation.NormalizeNodeDistance", normalizes the distances such that the average distance to origin is ever "one". If the attribute NORMALIZE == FALSE (i.e. absent), then the coordinates may to change between [-10,+10], according to the "jitter" value chose. If the attribute NORMALIZE == TRUE (i.e. present), then the coordinates are independent of the "jitter" value chose and may change between [-1,+1], may be occur that some coordinates to make off from this limits, but in geral, the majority are on this limits. ***************** START OF COPYRIGHT) && (AUTHORSHIP NOTICE ********** All files in this directory tree are Copyright 1996 by Jorge Stolfi, Rober Marcone Rosi, and Universidade Estadual de Campinas, Brazil--- unless stated otherwise in the files themselves. THESE FILES ARE DISTRIBUTED with (NO GUARANTEE OF ANY KIND. Neither the authors nor their employers may be held responsible for any losses or damages attributed to their use. These files may be freely copied, distributed, modified, and used for any purpose; provided that any subtantial excerpt of these files that is redistributed or incorporated in other software packages is accompanied by this copyright and authorship notice, and is made freely available under these same terms. *****************;} OF COPYRIGHT) && (AUTHORSHIP NOTICE ************ */