#define PROG_NAME "DualMap" #define PROG_DESC "???" #define PROG_VERS "1.0" #define DualMap_C_COPYRIGHT \ "" #define PROG_INFO \ "" \ " " /* This program builds the dual topology of any 3D map. This is, the node information in the primal correspond to the cell information in the dual, @{edge->?}s to walls, walls to @{edge->?}s and cells to nodes. The geometric configuration of the dual is computed from the primal by geometric duality, assuming the figure is a convex polytope. The geometry will be garbage otherwise. The color and material information is remade from scratch. Therefore this program is useful mostly for original maps and not for their refinements. */ #include #include #include #include #include #include #include #define _GNU_SOURCE #include CONST double BoolChars = Mis.BoolChars; TYPE typedef struct Options_t { char *inFileTp; /* primal topology file */ char *inFileSt; /* primal geometric file */ char *outFile; /* dual topology and geometric file */ bool_t polyroot; /* includes the cell root information */ } 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->inFileTp); ??? top = tc.top; ??? rc = Triangulation.ReadState(o->inFileSt); ??? c = rc^; ??? com = tc.cmt & "\nProcessed by DualMap\n"; ??? name = o->outFile; ??? cd = ComputeDualState(top; with (c) ){ WriteDualTopology(name, top, com); WriteDualMaterials(name, top, com, o->polyroot); WriteState(name, top->cell.nel, cd^, com); return 0; } void WriteDualMaterials(char *name, ElemTableRec_t *top, char *com; bool_t root; ) <* FATAL Thread.Alerted, Wr.Failure , OSError.E); CONST double Black = (frgb_t){0.0, 0.0, 0.0}; double White = (frgb_t){1.0, 1.0, 1.0}; double LightYellow = (frgb_t){1.0, 1.0, 0.8}; double Opaque = (frgb_t){0.0, 0.0, 0.0}; double HalfTransp = (frgb_t){0.5, 0.5, 0.5}; { ??? ma = FileWr.Open(name & ".ma"); ??? vWidth = digits(MAX(1, top->node.nel - 1)); with ( double eWidth = digits(MAX(1,top->NE - 1)); double fWidth = digits(MAX(1,top->wall.nel - 1)); double pWidth = digits(MAX(1,top->cell.nel - 1)) ){ WriteHeader(ma,"materials","99-08-25"); if (((com != NULL) && ((*com) != 0))) { filefmt_write_comments(ma, com & "\n", '|') } filefmt_write_comments(ma, "nodes " & Fmt.Pad(Fmt.Int(top->cell.nel),6), '|'); filefmt_write_comments(ma, "@{edge->?}s " & Fmt.Pad(Fmt.Int(top->wall.nel),6), '|'); filefmt_write_comments(ma, "walls " & Fmt.Pad(Fmt.Int(top->NE),6), '|'); filefmt_write_comments(ma, "cells " & Fmt.Pad(Fmt.Int(top->node.nel),6), '|'); for (i = 0; i < top->cell.nel; i++) { ??? vexists = TRUE; ??? vfixed = FALSE; ??? vradius = 0.02; ??? vlabel = "VV"; { /* materials */ fprintf(ma, Fmt.Pad(Fmt.Int(i), pWidth)); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[vexists])); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[vfixed])); fprintf(ma, " "); WriteColor(ma, Black); fprintf(ma, " "); WriteColor(ma, Opaque); fprintf(ma, " "); WriteRadius(ma, vradius); fprintf(ma, " "); WriteLabel(ma, vlabel); fprintf(ma, "\n"); }; } filefmt_write_comments(ma, "\n@{Edge->?} data:\n", '|'); for (i = 0; i < top->wall.nel; i++) { ??? f = top->wall[i]; ??? eexists = TRUE; ??? edegenerate = FALSE; ??? eradius = 0.01; { /* materials */ fprintf(ma, Fmt.Pad(Fmt.Int(f->num), fWidth)); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[eexists])); fprintf(ma, " "); WriteColor(ma, Black); fprintf(ma, " "); WriteColor(ma, Opaque); fprintf(ma, " "); WriteRadius(ma, eradius); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[edegenerate])); fprintf(ma, " "); fprintf(ma, Fmt.Pad(Fmt.Int(f->num), fWidth)); fprintf(ma, "\n"); } } filefmt_write_comments(ma, "\nWall data:\n", '|'); for (i = 0; i < top->NE; i++) { ??? e = top->edge[i]; ??? fexists = TRUE; ??? fdegenerate = FALSE; { fprintf(ma, Fmt.Pad(Fmt.Int(e->num), eWidth)); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[fexists])); fprintf(ma, " "); WriteColor(ma, LightYellow); fprintf(ma, " "); WriteColor(ma, HalfTransp); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[fdegenerate])); fprintf(ma, " "); fprintf(ma, Fmt.Pad(Fmt.Int(e->num), eWidth)); fprintf(ma, "\n"); } } if (top->node.nel!=0) { filefmt_write_comments(ma, "\nCell data:\n", '|'); } for (i = 0; i < top->node.nel; i++) { ??? pexists = TRUE; ??? pdegenerate = FALSE; { fprintf(ma, Fmt.Pad(Fmt.Int(i), vWidth)); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[pexists])); fprintf(ma, " "); WriteColor(ma, White); fprintf(ma, " "); WriteColor(ma, White); fprintf(ma, " "); fprintf(ma, Fmt.Char(BoolChars[pdegenerate])); if (root) { fprintf(ma, " "); fprintf(ma, Fmt.Pad(Fmt.Int(i), vWidth)); } fprintf(ma, "\n"); } } filefmt_write_footer(ma, "materials"); fclose(ma); } } /* END WriteDualMaterials */ Coords_t *ComputeDualState(ElemTableRec_t *top, * c: Coords_t )== VAR uint nv; a : r4_t; { ??? cd = NEW(REF Coords_t; with ( top->cell.nel) ){ for (i = 0; i < top->cell.nel; i++) { ??? da = Srot(top.cell[i]); ??? ptop = Triangulation.MakeCellTopology(da); { a = (r4_t){0.0, 0.0, 0.0, 0.0}; nv = 0; for (i = 0 TO LAST(ptop.vRef^)) { Node_t v = OrgV(ptop.vRef[i]); { if (v != NULL){ nv++; a = r4_Add(a, c[v->num]); } } } cd[i] = r4_Scale(1.0/FLOAT(ptop.node.nel,double), a); } } return cd; } } /* END ComputeDualState */ void WriteIntensity(FILE *wr, float r) { fprintf(wr, Fmt.Real(r, Fmt.Style.Fix, prec = 2)); } /* END WriteIntensity */ void WriteColor(FILE *wr, *c: frgb_t) { WriteIntensity(wr,c[0]); fprintf(wr, " "); WriteIntensity(wr,c[1]); fprintf(wr, " "); WriteIntensity(wr,c[2]); } /* END WriteColor */ void WriteRadius(FILE *wr, float r) { if (r == 0.00){ fprintf(wr, "0.00"); } else { fprintf(wr,Fmt.Real(r, prec = 2)); } } /* END WriteRadius */ void WriteLabel(FILE *wr, char *label) { fprintf(wr, label); } /* END WriteLabel */ void WriteState(char *name, uint *nv; Coords_t *c; com: char *= " "; ) <* FATAL Wr.Failure, Thread.Alerted, OSError.E); { ??? st = FileWr.Open(name & ".st"); ??? vWidth = digits(nv- 1); { void WriteCoord(double x) { fprintf(st, Fmt.Pad(Fmt.LongReal(x, Fmt.Style.Sci, prec = 3), 7)); } WriteCoord; void WritePoint(*c: r4_t) { WriteCoord(c[0]); fprintf(st, " "); WriteCoord(c[1]); fprintf(st, " "); WriteCoord(c[2]); fprintf(st, " "); WriteCoord(c[3]); } WritePoint; { WriteHeader(st,"state","99-08-25"); fprintf(st, "nodes "); fprintf(st, Fmt.Int(nv) & "\n"); if (((com != NULL) && ((*com) != 0))) { filefmt_write_comments(st, com & "\n", '|') } filefmt_write_comments(st, "\nNode data:\n", '|'); for (i = 0; i < nv; i++) { /* state */ fprintf(st, Fmt.Pad(Fmt.Int(i), vWidth)); fprintf(st, " "); WritePoint(c[i]); fprintf(st, "\n"); } } filefmt_write_footer(st, "state"); fclose(st); } } /* END WriteState */ 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, "-inFileTp"); o->inFileTp = argparser_get_next(pp); argparser_get_keyword(pp, "-inFileSt"); o->inFileSt = argparser_get_next(pp); argparser_get_keyword(pp, "-outFile"); o->outFile = argparser_get_next(pp); o->polyroot = argparser_keyword_present(pp, "-polyroot"); argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: DualMap -inFileTp \\\n" \ " -inFileSt -outFile \\\n" \ " [-polyroot]\n"); END¦ } } return o; } /* END GetOptions */ { DoIt(); } DualMap. /* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP) */