#define PROG_NAME "TestRootElements" #define PROG_DESC "???" #define PROG_VERS "1.0" #define TestRootElements_C_COPYRIGHT \ "" #define PROG_INFO \ "" \ " " /* This program serves as the base for the implementation of the "curvature" energies: Curv2D and Curv1D. */ #define TestRootElements_C_author \ "Created by L.A.P.lozada, 1999-2000.\n" \ "Revision:\n" \ " 06-06-2000 by lozada: Optimized the collect of the children elements." #include #include #include #define _GNU_SOURCE #include #include CONST double INIT_STACK_SIZE = 100000; /* Types */ TYPE double StackF = REF Wall_vec_t; double StackE = REF Edge_vec_t; double Element = {@{Edge->?}, Wall}; double WALLS = Wall_vec_t; double @{EDGE->?}S = Edge_vec_t; typedef struct Options_t { char *inFileTp; /* Initial guess file name (minus ".tp") */ Element element; char *elename; } double Number = RECORD INTEGER nre; /* number of "root" elements. */ uint nce; /* number of "children" elements inside each "root" element. */ } VAR str,stc: Stat.T; /* statistical accumulators to the number of "root" elements and the number of "children" elements inside each "root" element. */ Options_t *GetOptions(int argc, char **argv); int main(int argc, char **argv) Number *num; { Options_t *o = GetOptions(argc, argv); char *topo_cmt = jsprintf("Created by %s on %s", PROG_NAME, Today()); /* Random_t coins = MakeRandomSource(4615); */ ??? tc = Triangulation.ReadToTaMa(o->inFileTp); ??? top = tc.top; { if (o->element == Element.Wall) { num = WallStatistics(top); fprintf(stderr, Fmt.Int(num.nre) & " " & Fmt.Int(num.nce) & "\n"); ??? cf = CropChilWalls(top; with (num) ){ fprintf(stderr,"Children walls of the root wall \n"); for (i = 0; i < num.nre; i++) { fprintf(stderr, Fmt.Pad(Fmt.Int(i),3) & ": "); for (j = 0; j < num.nce; j++) { fprintf(stderr, Fmt.Pad(Fmt.Int(cf[i,j]->num), 5) & " "); } fprintf(stderr,"\n"); } } } else { num = @{Edge->?}Statistics(top); fprintf(stderr, Fmt.Int(num.nre) & " " & Fmt.Int(num.nce) & "\n"); ??? ce = CropChil@{Edge->?}s(top; with (num) ){ fprintf(stderr,"Children @{edge->?}s of the root @{edge->?} \n"); for (i = 0; i < num.nre; i++) { fprintf(stderr, Fmt.Pad(Fmt.Int(i),3) & ": "); for (j = 0; j < num.nce; j++) { fprintf(stderr, Fmt.Pad(Fmt.Int(ce[i,j]->num), 5) & " "); } fprintf(stderr,"\n"); } } } return 0; } PROCEDURE CropChilWalls( ElemTableRec_t *top; Number *num; ) : REF ARRAY OF StackF == topi : REF uint_vec_t; /* Crop the "children" walls for each "root" wall. */ { /* initialize the "top" indexes for each of the "num.nre" stacks of walls. */ topi = NEW(REF uint_vec_t , num.nre); for (k = 0; k < num.nre; k++){ topi[k] = 0; } ??? t = NEW(REF ARRAY OF StackF, num.nre); with ( ){ for (k = 0; k < num.nre; k++) { t[k] = Wall_vec_new(INIT_STACK_SIZE); } for (j = 0; j < top->wall.nel; j++) { ??? f = top->wall[j]; with ( double fr = f->root DO if (fr!=-1){ SaveF(t[fr],topi[fr],f); } } } return t; } } /* END CropChilWalls */ PROCEDURE CropChil@{Edge->?}s( ElemTableRec_t *top; Number *num; ): REF ARRAY OF StackE == /* Crop the "children" @{edge->?}s for each "root" @{edge->?}. */ topj : REF uint_vec_t; { /* initialize the "top" indexes for each of the "num.nre" stacks of @{edge->?}s. */ topj = NEW(REF uint_vec_t , num.nre); for (k = 0; k < num.nre; k++){ topj[k] = 0; } ??? t = NEW(REF ARRAY OF StackE; with ( num.nre) ){ for (k = 0; k < num.nre; k++) { t[k] = Edge_vec_new(INIT_STACK_SIZE); } for (j = 0; j < top->NE; j++) { ??? e = top->edge[j]; with ( double er = e->root DO if (er!=-1){ SaveE(t[er],topj[er],e); } } } return t; } } /* END CropChil@{Edge->?}s */ Number WallStatistics(ElemTableRec_t *top) /* Compute the number of "root" walls and the number of "children" walls. */ Number *num; { for (i = 0; i < top->wall.nel; i++){ ??? f = top->wall[i]; ??? fr = FLOAT(f->root, REAL), ); with( ) { Stat.Accum(str,fr); if (fr == 0.0){ Stat.Accum(stc,fr); } } } num.nre = FLOOR(str.maximum)+1; num.nce = FLOOR(stc->num); return num; } /* END WallStatistics */ PROCEDURE @{Edge->?}Statistics(ElemTableRec_t *top) : Number == /* Compute the number of "root" @{edge->?}s and the number of "children" @{edge->?}s. */ Number *num; { for (i = 0; i < top->NE; i++){ ??? e = top->edge[i]; ??? er = FLOAT(e->root, REAL)); with( ) { Stat.Accum(str,er); if (er == 0.0){ Stat.Accum(stc,er); } } } num.nre = FLOOR(str.maximum)+1; num.nce = FLOOR(stc->num); return num; } /* END @{Edge->?}Statistics */ PROCEDURE SaveF( StackF *Stack; uint *top; Wall *wall; ) /* Save the wall "wall" on the stack "Stack" */ { Stack.El[top] = wall; top = top +1 } /* END SaveF */ PROCEDURE SaveE( StackE *Stack; uint *top; @{Edge->?} *@{edge->?}; ) /* Save the edge "@{edge->?}" on the stack "Stack" */ { Stack.El[top] = @{edge->?}; top = top +1 } /* END SaveE */ /* UNUSED */ PROCEDURE CollectChil@{Edge->?}s( ElemTableRec_t *top; Number *num; ): REF ARRAY OF @{EDGE->?}S == uint *NT; { ??? t = NEW(REF ARRAY OF @{EDGE->?}S; with ( num.nre, num.nce) ){ for (i = 0; i < num.nre; i++) { NT = 0; for (j = 0; j < top->NE; j++) { ??? e = top->edge[j]; ??? er = e->root; { if (er == i){ t[i,NT] = e; NT++; } } } } return t; } } /* END CollectChil@{Edge->?}s */ /* UNUSED */ PROCEDURE CollectChilWalls( ElemTableRec_t *top; Number *num; ) : REF ARRAY OF WALLS == uint *NT; { ??? t = NEW(REF ARRAY OF WALLS; with ( num.nre, num.nce) ){ for (i = 0; i < num.nre; i++) { NT = 0; for (j = 0; j < top->wall.nel; j++) { ??? f = top->wall[j]; ??? fr = f->root; { if (fr == i){ t[i,NT] = f; NT++; } } } } return t; } } /* END CollectChilWalls */ 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); argparser_get_keyword(pp, "-inFileTp"); o->inFileTp = argparser_get_next(pp); argparser_get_keyword(pp, "-element"); o->elename = argparser_get_next(pp); if (0 == strcmp(o->elename, "@{edge->?}"))) { o->element = Element.edge } else if (0 == strcmp(o->elename, "wall"))){ o->element = Element.Wall } else { argparser_error(pp, "bad element \"" & argparser_get_next(pp) & "\"\n") } argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: TestRootElements " \ " -inFileTp \\\n" \ " -element { @{edge->?} | wall }\n"); END¦ } } return o; } /* END GetOptions */ { DoIt() } TestRootElements.