--- ray/src/cv/rad2mgf.c 1994/07/08 16:10:06 2.2 +++ ray/src/cv/rad2mgf.c 1994/12/12 12:09:28 2.8 @@ -15,6 +15,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" #include "lookup.h" +#define PI 3.14159265358979323846 + int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); int o_instance(), o_source(), o_illum(); int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); @@ -33,7 +35,27 @@ double unit_mult = 1.; /* units multiplier */ #define hasmult (unit_mult < .999 || unit_mult > 1.001) +/* + * Stuff for tracking and reusing vertices: + */ +char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; +#define VKLEN 64 + +#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) + +#define NVERTS 256 + +long vclock; /* incremented at each vertex request */ + +struct vert { + long lused; /* when last used (0 if unassigned) */ + FVECT p; /* track point position only */ +} vert[NVERTS]; /* our vertex cache */ + +LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ + + main(argc, argv) int argc; char **argv; @@ -60,6 +82,8 @@ char **argv; goto unkopt; } break; + default: + goto unkopt; } init(); if (i >= argc) @@ -244,6 +268,7 @@ char *id; init() /* initialize dispatch table and output */ { + lu_init(&vertab, NVERTS); lu_init(&rdispatch, 22); add2dispatch("polygon", o_face); add2dispatch("cone", o_cone); @@ -281,9 +306,21 @@ uninit() /* mark end of MGF file */ puts("# End of data converted from Radiance scene input"); lu_done(&rdispatch); lu_done(&rmats); + lu_done(&vertab); } +clrverts() /* clear vertex table */ +{ + register int i; + + lu_done(&vertab); + for (i = 0; i < NVERTS; i++) + vert[i].lused = 0; + lu_init(&vertab, NVERTS); +} + + add2dispatch(name, func) /* add function to dispatch table */ char *name; int (*func)(); @@ -301,27 +338,6 @@ int (*func)(); } -/* - * Stuff for tracking and reusing vertices: - */ - -char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; -#define VKLEN 64 - -#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) - -#define NVERTS 256 - -long clock; /* incremented at each vertex request */ - -struct vert { - long lused; /* when last used (0 if unassigned) */ - FVECT p; /* track point position only */ -} vert[NVERTS]; - -LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ - - char * getvertid(vname, vp) /* get/set vertex ID for this point */ char *vname; @@ -331,9 +347,7 @@ FVECT vp; register LUENT *lp; register int i, vndx; - if (!vertab.tsiz && !lu_init(&vertab, NVERTS)) - goto memerr; - clock++; /* increment counter */ + vclock++; /* increment counter */ mkvkey(vkey, vp); if ((lp = lu_find(&vertab, vkey)) == NULL) goto memerr; @@ -353,13 +367,13 @@ FVECT vp; mkvkey(vkey, vert[vndx].p); lu_delete(&vertab, vkey); } - vert[vndx].lused = clock; /* assign it */ - VCOPY(vert[vndx].p, vp); + VCOPY(vert[vndx].p, vp); /* assign it */ printf("v v%d =\n\tp %.15g %.15g %.15g\n", /* print it */ vndx, vp[0], vp[1], vp[2]); lp->data = (char *)&vert[vndx]; /* set it */ } else vndx = (struct vert *)lp->data - vert; + vert[vndx].lused = vclock; /* record this use */ sprintf(vname, "v%d", vndx); return(vname); memerr: @@ -512,6 +526,7 @@ FUNARGS *fa; fputs(fa->sarg[i], stdout); } putchar('\n'); + clrverts(); /* vertex id's no longer reliable */ return(0); } @@ -715,6 +730,6 @@ register FUNARGS *fa; puts("\tc"); if (d > FTINY) printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); - printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY); + printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); return(0); }