#define PROG_NAME "MakeObjectTriang" #define PROG_DESC "???" #define PROG_VERS "1.0" #define MakeObjectTriang_C_COPYRIGHT \ "" #define PROG_INFO \ "" \ " " /* Generates ".tp",".tb",".ma" and ".st" files for some simples triangulated and convex objects such as "sausage", bidimensional "torus" with and with out one twist in R^{4}. The node coordinates are random numbers in [-1..+1]. #define MakeObjectTriang_C_author \ "Modified by L.A.P.Lozada on 2000-03-19." #include #include #include #include #define _GNU_SOURCE #include #include #define _GNU_SOURCE #include CONST double order = 1; TYPE double @PLACES = ARRAY[0..3] OF Place_t; double Shape = {Torus2D, Torus2H, Sausage}; typedef struct Options_t { Shape shape; char *shapeName; uint gridOrder; } PROCEDURE Main() VAR top : Triangulation.Topology; { Options_t *o = GetOptions(argc, argv); char *topo_cmt = NULL; asprintf(&topo_cmt, "Created by %s on %s", PROG_NAME, Today()); /* Random_t coins = MakeRandomSource(4615); */ ??? m = MakeObject(o->shape; with ( o->gridOrder), double name = o->shapeName & "-" & Fmt.Int(o->gridOrder) ){ Octf.EnumWedges(m,SetOrgAll,FALSE); top = MakeTopology(m,1); if (0 == strcmp(o->shapeName, "torus2d"))) { assert(top->NV == 8 + (o->gridOrder-1) * 4 - 4); assert(top->NE == 19 + (o->gridOrder-1) * 14 - 5); assert(top->NF == 18 + (o->gridOrder-1) * 16 - 2); assert(top->NFE== 54 + (o->gridOrder-1) * 48 - 6); assert(top->NP == 6 * o->gridOrder); } else if (0 == strcmp(o->shapeName, "sausage"))){ assert(top->NV == 8 + (o->gridOrder-1) * 4); assert(top->NE == 19 + (o->gridOrder-1) * 14); assert(top->NF == 18 + (o->gridOrder-1) * 16); assert(top->NFE== 54 + (o->gridOrder-1) * 48); assert(top->NP == 6 * o->gridOrder); } ??? c = GenCoords(top)^; { WriteTopology( name, top, "Created by MakeObjectTriang: " & o->shapeName \ ".tp on " & Today()); WriteTable( name, top, "Created by MakeObjectTriang: " & o->shapeName \ ".tb on " & Today()); WriteState( name, top, c,"Created by MakeObjectTriang: " & o->shapeName \ ".st on " & Today() & "\nRandom Geometry"); WriteMaterials( name, top,"Created by MakeObject: " & o->shapeName \ ".ma on " & Today()); } } } /* END Main */ Place_t MakeObject(shape: Shape; order: uint) { CASE shape OF break; case Shape_Torus2D: return MakeTorus2D(order); break; case Shape_Torus2H: return MakeTorus2H(order); break; case Shape_Sausage: return MakeSausage(order); } } /* END MakeObject */ /* Shape builders: */ PROCEDURE MakeCubeT() : SixPlaces_t == Place_t co.el[5+1]; { ??? n = order; ??? ca = MakeTetraTopo(n; with (n), double cb = MakeTetraTopo(n,n); double cc = MakeTetraTopo(n,n); double cd = MakeTetraTopo(n,n); double ce = MakeTetraTopo(n,n); double cf = MakeTetraTopo(n,n) ){ Glue(Spin(cb.el[1]),ca.p[0],n); Glue(Spin(cc.el[1]),cb.el[0],n); Glue(Spin(cd[1]),cc.el[0],n); Glue(Spin(ce[1]),cd[0],n); Glue(Spin(cf[1]),ce[0],n); Glue(Spin(ca.p[1]),cf[0],n); co.el[0] = cb.el[3]; co.el[1] = cc.el[3]; co.el[2] = cd[3]; co.el[3] = ce[3]; co.el[4] = cf[3]; co.el[5] = ca.el[3]; return co; } } /* END MakeCubeT */ Place_t GlueCubeT(a, b : Place_t) /* This procedure allows to glue two squared walls that is the union of two triangular walls. */ ta,Place_t tb[1+1]; { ta[0] = a; tb[0] = b; ta[1] = Clock(PrevE(PrevF(NextE(ta[0])))); tb[1] = Clock(PrevE(NextF(NextE(tb[0])))); assert(ta[1]!=a); assert(tb[1]!=b); Meld(tb[0], ta[0]); /* Update the edge slots for i==0 */ SetRingEdgeInfo(ta[0], PEdge(ta[0])); SetRingEdgeInfo(NextE(ta[0]), PEdge(NextE(ta[0]))); SetRingEdgeInfo(PrevE(ta[0]), PEdge(PrevE(ta[0]))); /* Update the cell slots for i==0 */ SetPneg(ta[0], PnegP(tb[0])); SetPneg(NextE(ta[0]), PnegP(NextE(tb[0]))); SetPneg(NextE(NextE(ta[0])), PnegP(NextE(NextE(tb[0])))); Meld(tb[1],ta[1]); /* Update the edge slots */ SetRingEdgeInfo(ta[1], PEdge(ta[1])); SetRingEdgeInfo(NextE(ta[1]), PEdge(NextE(ta[1]))); SetRingEdgeInfo(PrevE(ta[1]), PEdge(PrevE(ta[1]))); /* Update the cell slots */ SetPneg(ta[1], PnegP(tb[1])); SetPneg(NextE(ta[1]), PnegP(NextE(tb[1]))); SetPneg(NextE(NextE(ta[1])), PnegP(NextE(NextE(tb[1])))); return a; } /* END GlueCubeT */ PROCEDURE Make1DCubearray(uint order) : REF ARRAY OF @PLACES == /* Builds one row of cubes with order "order". */ VAR ca : REF SixPlaces_vec_t; cb : REF ARRAY OF @PLACES; { ca = SixPlaces_vec_new(order); cb = NEW(REF ARRAY OF @PLACES, order); for (i = 0; i < order; i++) { ca.el[i] = MakeCubeT(); cb.el[i,0] = ca.el[i,2]; cb.el[i,1] = ca.el[i,3]; cb.el[i,2] = ca.el[i,4]; cb.el[i,3] = ca.el[i,5]; } /* gluing */ for (j = 0; j < (order-1); j++) { GlueCubeT(NextE(PrevF(ca.el[j+1,4])),ca.el[j,0]); } return cb; } /* END Make1DCubearray */ Place_t MakeSausage(uint order) { ??? s = Make1DCubearray(order); { fprintf(stderr, " Building topology of sausage: \n"); return s[0,0]; } } /* END MakeSausage */ Place_t MakeTorus2D(uint order) { ??? s = Make1DCubearray(order); Place_t a = NextE(PrevF(s[0; with (2])), double b = Clock(PrevF(PrevE(NextF(NextF(NextE(PrevF(s[order-1,3]))))))) ){ GlueCubeT(a,b); fprintf(stderr, " Building topology of 2D Torus: \n"); return s[0,3]; } } /* END MakeTorus2D */ Place_t MakeTorus2H(uint order) /* Builds a solid torus with two holes. This construction is based in the connected sum of two manifolds: a!=b */ { ??? a = MakeTorus2D(order); ??? b = MakeTorus2D(order); Place_t c = NextF(NextE(NextF(NextF(NextE(PrevF(b)))))); { EVAL Triangulation.Glue(Clock(a),Clock(c),2); assert(Octf.DegreeOfWall(a) == 4); assert(Octf.DegreeOfWall(NextE(a)) == 7); assert(Octf.DegreeOfWall(PrevE(a)) == 4); fprintf(stderr, " Building topology of 2D Torus with two holes: \n"); return a; } } /* END MakeTorus2H */ 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, "-shape"); o->shapeName = argparser_get_next(pp); if (0 == strcmp (o->shapeName, "torus2d"))) { o->shape = Shape_Torus2D } else if (0 == strcmp(o->shapeName, "torus2h"))){ o->shape = Shape_Torus2H } else if (0 == strcmp(o->shapeName, "sausage"))){ o->shape = Shape_Sausage } else { argparser_error(pp, "Bad shape \"" & argparser_get_next(pp) & "\"\n"); } argparser_get_keyword(pp, "-gridOrder"); o->gridOrder = argparser_get_next_int(pp, 3,30); argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: MakeObjectTriang \\\n" \ " -shape { torus2d | torus2h | sausage }\\\n" \ " -gridOrder \\\n"); END¦ } } return o; } /* END GetOptions */ PROCEDURE SetOrgAll(Place_t @p) /* Set alls places with the same origin that "a" (i.e with the @{node->?} {n}). */ void SetOrgAll(Place_t @p, Node_t n) Place_t t = a; VAR Place_t tn; { do { SetOrg(t,n); tn = Clock(PrevE(t)); do { SetOrg(tn,n); tn = NextF(tn); } while (!(( tn == Clock(PrevE(t))))); t = NextF(t); } while (t != a); } SetOrgAll; VAR Place_t an = a; Place_t ap = NextE(PrevF(PrevF(PrevE(a)))); { ??? n = Org(a); { do { SetOrgAll(an,n); an = Onext(an); } while (an != a); do { SetOrgAll(ap,n); ap = Oprev(ap); } while (!((ap == NextE(PrevF(PrevF(PrevE(a))))))); } } /* END SetOrgAll */ { Main(); } MakeObjectTriang. /* Copyright © 1999 Universidade Estadual de Campinas (UNICAMP) */