#define PROG_NAME "JSNewExplode" #define PROG_DESC "???" #define PROG_VERS "1.0" #define JSNewExplode_C_COPYRIGHT \ "" #define PROG_INFO \ "" \ " " /* This program recieves as input a topology and geometry of a 3D map with border and produces a ".inc" file for the PovRay. The cells are presented in the exploding way. Revisions: 27-01-2001 : Modified for exploding cubic cells. */ #include #include #include #define _GNU_SOURCE #include #include #include #include #include TYPE typedef struct Options_t { char *inFileTp; /* Input file name (minus ".tp" extension) */ inFileSt3: char *; /* Input file name (minus ".st3" extension) */ char *outFile; /* Output file name prefix */ REAL opacity; /* opacity factor */ REAL radius; /* radius drawing */ REAL factor; /* factor exploding */ } Options_t *GetOptions(int argc, char **argv); int main(int argc, char **argv) <* FATAL OSError.E); VAR c : REF Tridimensional.Coord3D; inc: Wr.T; void DrawDisplacedNode(e: Place_t; *delta: r3_t; ra: REAL; frgb_t color; tr: REAL) /* Draws the node OrgV(e) displaced by delta */ { ??? v = (Node_t)(OrgV(e)); { double p = Add(c[v->num], delta) ){ WritePOVSphere(inc,p,ra,color,tr,TRUE) } } DrawDisplacedNode; PROCEDURE DrawDisplaced@{Edge->?}(e: Place_t; *delta: r3_t; ra: REAL; frgb_t color; tr: REAL) == /* Draws the edge @{Edge->?}(e) displaced by delta */ { ??? u = (Node_t)(OrgV(e)); { double v = (Node_t)(OrgV(Clock(e))); double p = Add(c[u->num], delta); double q = Add(c[v->num], delta) ){ WritePOVCylinder(inc,p,q,ra,color,tr,TRUE) } } DrawDisplaced@{Edge->?}; void DrawDisplacedWall(e: Place_t; *delta: r3_t; frgb_t color; tr: REAL) /* Draws the wall ``PWall(e)'' (polygonal wall) displaced by delta */ Place_t *b, d; { b = NextE(e); d = NextE(b); do { ??? u = OrgV(e); ??? v = OrgV(b); ??? w = OrgV(d); ??? p = Add(c[u->num]; with (delta), double q = Add(c[v->num], delta); double r = Add(c[w->num], delta) DO WritePOVTriangle(inc,p,q,r,color,tr,TRUE); b = d; d = NextE(d) } } while (d != e); } DrawDisplacedWall; { 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; with ( double pink = (frgb_t){1.000, 0.745, 0.745}; double black = (frgb_t){0.0, 0.0, 0.0} ){ inc = FileWr.Open(o->outFile & "-Ex.inc"); c = Tridimensional.ReadState3D(o->inFileSt3); for (i = 0; i < top->cell.nel; i++) { ??? ptop = Triangulation.MakeCellTopology(Srot(top.cell[i])); ??? pi = top->cell[i]; ??? pv = pi.node^; ??? bar = ComputeBarycenter(c; with (pv), double delta = Scale(FLOAT(o->factor,double), bar) DO /* Write nodes: */ for (i = 0; i < ptop.node.nel; i++) { ??? e = ptop.vRef[i]; { DrawDisplacedNode(e, delta, o->radius, black, 0.0) } } /* Write @{edge->?}s: */ for (i = 0; i < ptop.edge.nel; i++) { ??? e = ptop.eRef[i]; { DrawDisplaced@{Edge->?}(e, delta, o->radius, black, 0.0) } } /* Write Walls: */ for (i = 0; i < ptop.wall.nel; i++) { ??? e = ptop.fRef[i]; { DrawDisplacedWall(e, delta, pink, o->opacity) } } } } return 0; } r3_t ComputeBarycenter(*c: REF Tridimensional.Coord3D; *pv : ARRAY OF @{Node->?}) B: r3_t = (r3_t){0.0, ..}; uint n = 0; { for (i = 0; i < pv->nel; i++)-1){ B = r3_add(B, c[i]); N++; } return r3_scale(1.0/n, B); } /* END ComputeBarycenter */ 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); { ¦TRY argparser_get_keyword(pp, "-inFileTp"); o->inFileTp = argparser_get_next(pp); argparser_get_keyword(pp, "-inFileSt3"); o->inFileSt3 = argparser_get_next(pp); argparser_get_keyword(pp, "-outFile"); o->outFile = argparser_get_next(pp); if ((argparser_keyword_present(pp, "-opacity"))) { o->opacity = pp.getNextReal(0.0, 1.0); } else { o->opacity = 0.65; }; if ((argparser_keyword_present(pp, "-radius"))) { o->radius = pp.getNextReal(0.0, 0.1); } else { o->radius = 0.005; }; if ((argparser_keyword_present(pp, "-factor"))) { o->factor = pp.getNextReal(1.0, 6400.0); }; argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: NewExplode \\\n" \ " -inFileTp \\\n" \ " -inFileSt3 \\\n" \ " -outFile \\\n" \ " [-opacity ] [-radius ] \\\n" \ " [-factor ]\n"); END¦ } } return o; } /* END GetOptions */ { DoIt() } JSNewExplode. /* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP) */