#define PROG_NAME "TestTopology" #define PROG_DESC "Tests the topology of a 3D map" #define PROG_VERS "1.0" /* Last edited on 2007-02-03 18:47:32 by stolfi */ #define TestTopology_C_COPYRIGHT \ "Copyright © 1999 Universidade Estadual de Campinas (UNICAMP) " #define PROG_INFO \ "This program to test the characteristics of the Star and Link for all\n" \ "node, as well as, if every node is internal and if every wall if\n" \ "internal (The input file must be contain one Triangulation not degene-\n" \ "rate.\n" \ "\n" \ "Also include some procedures for tests if every cell on the star\n" \ "for one node are differents as well as every cell is contained\n" \ "on the list of cell of \".tp\" topology.." #include #include #include #include #define _GNU_SOURCE #include #include typedef struct Options_t { char *inFile; /* Input file name (minus ".tp") */ bool_t listStar; /* TRUE prints out the cell list around each node. */ } Options_t; typedef struct ThreeNums_t { uint n[3]; } ThreeNums_t; typedef struct TwoNums_t { uint n[2]; } TwoNums_t; typedef struct ThreeByTwoNums_t { uint n[3][2]; } ThreeByTwoNums_t; Options_t *GetOptions(int argc, char **argv); int main(int argc, char **argv) { Options_t *o = GetOptions(argc, argv); char *topo_cmt = jsprintf("Created by %s on %s", PROG_NAME, Today()); /* Random_t coins = MakeRandomSource(4615); */ TopCom_t tc = Triangulation.ReadToMa(o->inFile); ElemTableRec_t top = tc.top; int_vec_t v; int i; for (i = 0; i < top->node.nel; i++) { Place_t a = top->node[i]; ??? poly = Triangulation.StarOfNode(a; with (top), double dg = Triangulation.DegreeOfNode(a); double np = Triangulation->numberPolyOfStar(poly); double nvs = dg; double nfs = np; double nes = @{Edge->?}sOnThe@{Link->?}(a,poly,np) ){ /* ===> (2) condition : For All "v", degree(v) <= NV.top */ assert(dg <= top->node.nel); /* ===> (3) condition : Test the property (ii) of combinatorics description of 3-manifolds without boundary, i.e: All 0-simplex in the triangulation K is a internal node: One internal node is every 0-simplex that have one @{link->?} homeomorphic to sphere S^{2}, so must to perform the euler's formula: nv-ne+nf == 2. */ if ((top->bdr == 0) && (top->node.nel-top->NE+top->wall.nel-top->cell.nel == 0)) { assert(nvs-nes+nfs == 2); } /* ===> (4) condition : Test the property (i) of combinatorics description of 3-manifolds without boundary, i.e: All 2-simplex in the triangulation K is a internal wall: One internal wall is every 2-simplex that incident in exactly two 3-simplex. */ if (top->bdr == 0) { for (i = 0; i < top->wall.nel; i++) { ??? f = top->wall[i]; ??? a = f.pa; ??? p1 = PposP(a); Cell_t p2 = PnegP(a); { assert(p1!=p2); } } } if (o->listStar) { ??? star = Triangulation.Neighbors(a; with (top), double nv = Triangulation->numberNeighborNode(star) ){ assert(nv == dg); fprintf(stderr, "OrgV->num: " & Fmt.Int(OrgV(a)->num) & " "); fprintf(stderr, " Degree : " & Fmt.Int(dg) & "\n"); fprintf(stderr, "Nodes belong to star of node: " \ Fmt.Int(OrgV(a)->num) & ":\n"); v = NEW(REF ARRAY OF INTEGER, nv); for (k = 0; k < nv; k++) { v[k] = star[k]->num; } /*Mis.InsertionSort(nv-1,v);*/ for (k = 0; k < nv; k++) { fprintf(stderr, Fmt.Int(v[k]) & " "); } fprintf(stderr, "\n"); } fprintf(stderr, "\n"); } } } fprintf(stderr, "Condition 2 OK\n"); if (top->bdr == 0) { fprintf(stderr, "Condition 3 OK\n"); fprintf(stderr, "Condition 4 OK\n"); } return 0; } PROCEDURE @{Edge->?}sOnThe@{Link->?}( Place_t @p; *poly: REF ARRAY OF FourNodes_t; uint *np; ) : uint == CONST INIT_STACK_SIZE == 10000; VAR uint c; tri : REF ARRAY OF TheeNums_t; bi : REF ARRAY OF ThreeByTwoNums_t; stack = NEW(REF ARRAY OF TwoNums_t, INIT_STACK_SIZE); nstack : uint = 0; bool_t Present(c: TwoNums_t) /* retorna verdadeiro se "c" esta na pilha, FALSE c.c */ uint nstack1 = nstack; VAR { while (nstack1 > 0) { nstack1 = nstack1 - 1; if (stack.el[nstack1] == c){ return TRUE; } } return FALSE; } Present; { tri = NEW(REF ARRAY OF TheeNums_t, np); bi = NEW(REF ARRAY OF ThreeByTwoNums_t, np); /* As arestas da cinta do vertice */ for(i = 0; i < poly.nel; i++) { c = 0; for (j = 0; j < 4; j++) { if (( poly[i][j]->num!=OrgV(a)->num )){ tri[i,c] = poly[i][j]->num; c++; } } /* As arestas para cada wall, ordenadas */ for (l = 0; l < 3; l++) { if (( tri[i,l] < tri[i,(l+1) % 3] )){ bi[i,l,0] = tri[i,l]; bi[i,l,1] = tri[i,(l+1) % 3]; } else { bi[i,l,0] = tri[i,(l+1) % 3]; bi[i,l,1] = tri[i,l]; } } } /* Achando o numero de arestas sob a superficie da vizinhanca */ for(j = 0; j < poly.nel; j++) { for (l = 0; l < 3; l++) { if ((! Present(bi[j,l]) )){ stack.el[nstack] = bi[j,l]; nstack++; } } } return nstack; } /* END @{Edge->?}sOnThe@{Link->?} */ Options_t GetOptions () { 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, "-inFile"); o->inFile = argparser_get_next(pp); o->listStar = argparser_keyword_present(pp, "-listStar"); argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: TestTopology" \ " -inFile " \ " [ -listStar ]\n" \ "\n"); END¦ } } return o; } /* END GetOptions */ { DoIt() } TestTopology. /* */ /* UNUSED */ INTEGER Order(char *name) <* FATAL FloatMode.Trap, Lex.Error); { ??? n = Text.FindChar(name; with ( '-'), double o = Scan.Int(Text.Sub(name, n+1, 2)) ){ return o; } } /* END Order */ /* UNUSED */ PROCEDURE TestePolyDif(ElemDataRec_t *top) p,q : REF ARRAY OF INTEGER; { for (i = 0; i < top->node.nel; i++){ ??? a = top->node[i]; ??? poly = Triangulation.StarOfNode(a; with (top) ){ for(j = 0; j < poly.nel; j++) { p = NEW(REF ARRAY OF INTEGER, 4); p[0] = poly[j][0]->num; p[1] = poly[j][1]->num; p[2] = poly[j][2]->num; p[3] = poly[j][3]->num; Mis.InsertionSort(3,p); for (i = j+1 TO LAST(poly^)) { q = NEW(REF ARRAY OF INTEGER, 4); q[0] = poly[i][0]->num; q[1] = poly[i][1]->num; q[2] = poly[i][2]->num; q[3] = poly[i][3]->num; Mis.InsertionSort(3,q); if ((p[0]==q[0]) && (p[1]==q[1]) && (p[2]==q[2]) && ((p[3]==q[3]) )){ fprintf(stderr, "ERRO ESTA NA LISTA<====\n"); } } } } } } /* END TestePolyDif */ /* UNUSED */ PROCEDURE TestePolyExist(ElemDataRec_t *top) bool_t saiu = FALSE; p : REF ARRAY OF INTEGER; { /* realiza teste si poliedro esta na lista */ for (i = 0; i < top->node.nel; i++) { ??? a = top->node[i]; ??? poly = Triangulation.StarOfNode(a; with (top) ){ for(j = 0; j < poly.nel; j++) { p = NEW(REF ARRAY OF INTEGER, 4); p[0] = poly[j][0]->num; p[1] = poly[j][1]->num; p[2] = poly[j][2]->num; p[3] = poly[j][3]->num; Mis.InsertionSort(3,p); while (NOT saiu) { for (l = 0; l < top->cell.nel; l++) { ??? q = top->cell[l]; ??? q1 = q.node[0]->num; ??? q2 = q.node[1]->num; ??? q3 = q.node[2]->num; ??? q4 = q.node[3]->num; { if ((p[0]==q1) && (p[1]==q2) && (p[2]==q3) && ((p[3]==q4) )){ saiu = TRUE; } } } } } } } } /* END TestePolyExist */ #define TestTopology_C_author \ "Created by L. P. Lozada, 1999-2000\n" \ "Modified by L.A.P.Lozada on 99-08-27."