/* See {TestSubdivide@{Edge->?}.h} */ #include ?}.h> /* Last edited on 2007-02-03 23:24:20 by stolfi */ /* This program subdivides an @{edge->?} and propagates the subdivision for the star of this @{edge->?}. Teste with success in the subdivision of bipyramids and in the Refine- Triang program. */ #include #include #define _GNU_SOURCE #include #include #include #include #include uint NVE = 0; TYPE typedef struct Options_t { char *inFile; /* Initial guess file name (minus ".tp") */ char *outFile; /* Output file name prefix */ } 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); */ ??? tc = Triangulation.ReadToMa(o->inFile); ??? top = tc.top; ??? e = top->edge[0]; ??? a = e.pa; ??? dfr = Octf.DegreeOfWall(a); { Subdivide@{Edge->?}(a,dfr,top); ??? newtop = MakeElemTable(a); ??? nc = GenCoords(newtop)^; ??? cmt = " "; { WriteTopology(o->outFile, newtop, cmt); WriteState(o->outFile, newtop, nc, cmt); WriteMaterials(o->outFile, newtop, cmt); } return 0; } PROCEDURE Subdivide@{Edge->?}( Place_t @pn; uint n; ElemTableRec_t *top; ) == VAR @{Node->?} x; a,bn,m1,m2,m3,t0,t1,Place_vec_t t2; wn,p: REF ARRAY OF @{Node->?}; { a = NEW(REF Place_vec_t,n); bn = NEW(REF Place_vec_t,n); m1 = NEW(REF Place_vec_t,n); m2 = NEW(REF Place_vec_t,n); m3 = NEW(REF Place_vec_t,n); t0 = NEW(REF Place_vec_t,n); t1 = NEW(REF Place_vec_t,n); t2 = NEW(REF Place_vec_t,n); /* save the @places */ a = NEW(REF Place_vec_t,n); a[0] = an; ??? f = PWedge(a[0]).wall; ??? e = PEdge(a[0]); ??? ee = PEdge(NextE(a[0])); ??? ee_ = PEdge(PrevE(a[0])); { if (top->wall[f->num]->exists ){ f->exists = TRUE; } else { f->exists = FALSE; } f.color = top->wall[f->num].color; f.transp = top->wall[f->num].transp; if (top->edge[e->num]->exists ){ e->exists = TRUE; } else { e->exists = FALSE; } e.color = top->edge[e->num].color; e.transp = top->edge[e->num].transp; e.radius = top->edge[e->num].radius; if (top->edge[ee->num]->exists ){ ee->exists = TRUE; } else { ee->exists = FALSE; } ee.color = top->edge[ee->num].color; ee.transp = top->edge[ee->num].transp; ee.radius = top->edge[ee->num].radius; if (top->edge[ee_->num]->exists ){ ee_->exists = TRUE; } else { ee_->exists = FALSE; } ee_.color = top->edge[ee_->num].color; ee_.transp = top->edge[ee_->num].transp; ee_.radius = top->edge[ee_->num].radius; } for (i = 1; i < n; i++) { a[i] = NextF(a[i-1]); ??? f = PWedge(a[i]).wall; ??? ee = PEdge(NextE(a[i])); ??? ee_ = PEdge(PrevE(a[i])); { if (top->wall[f->num]->exists ){ f->exists = TRUE; } else { f->exists = FALSE; } f.color = top->wall[f->num].color; f.transp = top->wall[f->num].transp; if (top->edge[ee->num]->exists ){ ee->exists = TRUE; } else { ee->exists = FALSE; } ee.color = top->edge[ee->num].color; ee.transp = top->edge[ee->num].transp; ee.radius = top->edge[ee->num].radius; if (top->edge[ee_->num]->exists ){ ee_->exists = TRUE; } else { ee_->exists = FALSE; } ee_.color = top->edge[ee_->num].color; ee_.transp = top->edge[ee_->num].transp; ee_.radius = top->edge[ee_->num].radius; } } /* save the nodes */ wn = NEW(REF ARRAY OF @{Node->?},n); for (i = 0; i < n; i++) { wn[i] = OrgV(PrevE(a[i])); } /* save the tetrahedra */ p = NEW(REF ARRAY OF @{Node->?},n); for (i = 0; i < n; i++) { p[i] = PnegP(a[i]); } /* save other @places */ bn = NEW(REF Place_vec_t,n); for (i = 0; i < n; i++) { bn[i] = Clock(PrevE(NextF(PrevE(a[i])))); ??? e = PEdge(bn[i]); ??? f = PWedge(bn[i]).wall; { if (top->edge[e->num]->exists ){ e->exists = TRUE; } else { e->exists = FALSE; } e.color = top->edge[e->num].color; e.transp = top->edge[e->num].transp; e.radius = top->edge[e->num].radius; if (top->wall[f->num]->exists ){ f->exists = TRUE; } else { f->exists = FALSE; } f.color = top->wall[f->num].color; f.transp = top->wall[f->num].transp; } } /* insert wedges and edges */ for (i = 0; i < n; i++) { m1[i] = MakeWedge(); m2[i] = MakeWedge(); m3[i] = MakeWedge(); t0[i] = MakeTriangle(); t1[i] = NextE(t0[i]); t2[i] = NextE(t1[i]); ??? f = PWedge(t0[i]).wall; ??? e0 = PEdge(t0[i]); ??? e1 = PEdge(t1[i]); ??? e2 = PEdge(t2[i]); { f->exists = FALSE; f.transp = (frgb_t){1.0,1.0,1.0}; e1->exists = FALSE; e2->exists = FALSE; e1.radius = 0.003; e1.transp = (frgb_t){1.0,1.0,1.0}; e2.radius = 0.003; e2.transp = (frgb_t){1.0,1.0,1.0}; if ((PEdge(bn[i])->exists )){ e0->exists = TRUE; } else { e0->exists = FALSE; } } } /* Now, subdivide @{edge->?} and extend the subdivision on the edge's stars */ x = MakeNode(0); ??? v = (Node_t)(x); { ){ v.label = "VE"; if ((PEdge(a[0])->exists)) { v.radius = PEdge(a[0]).radius; v.color = PEdge(a[0]).color; v.transp = PEdge(a[0]).transp; } else { v.radius = 0.00; v.color = (frgb_t){1.0,1.0,1.0}; v.transp = (frgb_t){1.0,1.0,1.0}; } v->num = NVE; NVE++; } for (j = 0; j < n; j++) { Place_t b = NextE(a[j]); Edge_t be = PEdge(b); Place_t c = NextE(b); Edge_t ce = PEdge(c); ??? u = OrgV(a[j]); ??? v = OrgV(b); ??? w = OrgV(c); with ( /* save the attributes of the edge-wall component of the @place a[j] */ double f = PWedge(a[j]).wall; double fe = f->exists; double fc = f.color; double ft = f.transp; double g = PWedge(m3[j]).wall; double ge = g->exists; double gc = g.color; double gt = g.transp; double h = PEdge(m3[j]) ){ SetNextE(a[j],m1[j]); SetNextE(m1[j],c); SetNextE(m2[j],m3[j]); SetNextE(m3[j],Clock(b)); SetOrg(a[j], u); SetOrg(Clock(a[j]), x); SetOrg(m2[j],v); SetOrg(Clock(m2[j]), x); SetOrg(m3[j], x); SetOrg(Clock(m3[j]), w); SetOrg(m1[j], x); SetOrg(Clock(m1[j]), w); SetNextF(m1[j],m3[j]); /* set the attributes for the wall component */ SetRingWallInfo(a[j],f); SetRingWallInfo(m3[j],g); if (fe) { ge = TRUE; } else { ge = FALSE; } gc = fc; gt = ft; SetRingEdgeInfo(m3[j],h); SetRingEdgeInfo(b,be); SetRingEdgeInfo(c,ce); SetRingWallInfo(bn[j],PWedge(bn[j]).wall); SetRingWallInfo(NextF(bn[j]),PWedge(NextF(bn[j])).wall); } } for (j = 0; j < n; j++) { SetNextF(Clock(m2[j]),Clock(m2[(j+1) % n])); } ??? k = PEdge(m2[0]); ??? e = PEdge(a[0]); ??? ee = e->exists; ??? er = e.radius; ??? ec = e.color; ??? et = e.transp; ??? ke = k->exists; ??? kr = k.radius; ??? kc = k.color; ??? kt = k.transp; { if (ee){ ke = TRUE; }else{ ke = FALSE; } kr = er; kc = ec; kt = et; SetRingEdgeInfo(a[0],e); SetRingEdgeInfo(m2[0],k); } for (j = 0; j < n; j++) { Place_t cn = NextF(bn[j]); ??? e1 = PEdge(t1[j]); ??? e2 = PEdge(t2[j]); Wall_t cnf = PWall(cn); Edge_t cne = PEdge(cn); { if (top->wall[cnf->num]->exists ){ cnf->exists = TRUE; } else { cnf->exists = FALSE; } cnf.color = top->wall[cnf->num].color; cnf.transp = top->wall[cnf->num].transp; if (top->edge[cne->num]->exists ){ cne->exists = TRUE; } else { cne->exists = FALSE; } cne.color = top->edge[cne->num].color; cne.transp = top->edge[cne->num].transp; cne.radius = top->edge[cne->num].radius; /* set the origins */ SetOrgAll(t0[j],wn[j]); SetOrgAll(t1[j],wn[(j+1) % n]); SetOrgAll(t2[j],x); SetNextF(bn[j], t0[j]); SetNextF(t0[j],cn); SetNextF(m1[j],t2[j]); SetNextF(t2[j],m3[j]); SetNextF(Clock(m1[(j+1) % n]), t1[j]); SetNextF(t1[j],Clock(m3[(j+1) % n])); SetRingEdgeInfo(t0[j],PEdge(cn)); SetRingEdgeInfo(t1[j],e1); SetRingEdgeInfo(t2[j],e2); } } /* insert cells */ for (j = 0; j < n; j++) { ??? q = Triangulation.MakeCell(0); { SetPnegOfNearbyWalls(a[j],p[j]); SetPnegOfNearbyWalls(m2[j],q); } } } /* END Subdivide@{Edge->?} */ 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, "-inFile"); o->inFile = argparser_get_next(pp); argparser_get_keyword(pp, "-outFile"); o->outFile = argparser_get_next(pp); argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: TestSubdivide@{Edge->?}" \ " -inFile -outFile \n"); END¦ } } return o; } /* END GetOptions */ { DoIt() } TestSubdivide@{Edge->?}. /* Copyright © 2000 Universidade Estadual de Campinas (UNICAMP) */