--- ray/src/gen/mkillum3.c 1991/07/25 10:59:09 1.2 +++ ray/src/gen/mkillum3.c 2004/09/28 17:54:18 2.10 @@ -1,29 +1,39 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: mkillum3.c,v 2.10 2004/09/28 17:54:18 greg Exp $"; #endif - /* * Routines to print mkillum objects */ #include "mkillum.h" -#define brt(col) (.295*(col)[0] + .636*(col)[1] + .070*(col)[2]) +#define brt(col) (.263*(col)[0]+.655*(col)[1]+.082*(col)[2]) char DATORD[] = "RGB"; /* data ordering */ char DATSUF[] = ".dat"; /* data file suffix */ char DSTSUF[] = ".dist"; /* distribution suffix */ char FNCFNM[] = "illum.cal"; /* function file name */ +void compinv(float *rinv, float *rp, int m); +void colorout(int p, float *da, int n, int m, double mult, FILE *fp); +void fputnum(double d, FILE *fp); +void brightout(float *da, int n, int m, double mult, FILE *fp); +void fputeol(FILE *fp); +void compavg(float col[3], float *da, int n); +char * dfname(struct illum_args *il, int c); +FILE * dfopen(struct illum_args *il, int c); -printobj(mod, obj) /* print out an object */ -char *mod; -register OBJREC *obj; + +void +printobj( /* print out an object */ + char *mod, + register OBJREC *obj +) { register int i; + if (issurface(obj->otype) && !strcmp(mod, VOIDID)) + return; /* don't print void surfaces */ printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname); printf("\n%d", obj->oargs.nsargs); for (i = 0; i < obj->oargs.nsargs; i++) @@ -46,11 +56,11 @@ register OBJREC *obj; char * -dfname(il, c) /* return data file name */ -struct illum_args *il; -int c; +dfname( /* return data file name */ + struct illum_args *il, + int c +) { - extern char *getpath(), *strcpy(); char fname[MAXSTR]; register char *s; @@ -67,9 +77,10 @@ int c; FILE * -dfopen(il, c) /* open data file */ -register struct illum_args *il; -int c; +dfopen( /* open data file */ + register struct illum_args *il, + int c +) { char *fn; FILE *fp; @@ -87,34 +98,50 @@ int c; } -flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */ -struct illum_args *il; -float *da; -int n, m; -FVECT u, v, w; +extern void +flatout( /* write hemispherical distribution */ + struct illum_args *il, + float *da, + int n, + int m, + FVECT u, + FVECT v, + FVECT w +) { + float *Ninv; FILE *dfp; int i; - average(il, da, n*m); + if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL) + error(SYSTEM, "out of memory in flatout"); + compinv(Ninv, da, m); if (il->flags & IL_COLDST) { printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, il->matname, DSTSUF); printf("\n9 red green blue"); for (i = 0; i < 3; i++) { dfp = dfopen(il, DATORD[i]); - fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m); - colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp); + fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", + 1.+.5/n, .5/n, n+1, + 0., 2.*PI, m+1); + colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); + colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); + fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, DATORD[i])); } } else { printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, il->matname, DSTSUF); - printf("\n5 noop"); + printf("\n5 noneg"); dfp = dfopen(il, 0); - fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m); - brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp); + fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", + 1.+.5/n, .5/n, n+1, + 0., 2.*PI, m+1); + brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); + brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); + fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, 0)); } @@ -124,53 +151,79 @@ FVECT u, v, w; printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); il->dfnum++; + free((void *)Ninv); } -roundout(il, da, n, m) /* write spherical distribution */ -struct illum_args *il; -float *da; -int n, m; +extern void +roundout( /* write spherical distribution */ + struct illum_args *il, + float *da, + int n, + int m +) { + float *Ninv, *Sinv; FILE *dfp; int i; - average(il, da, n*m); + if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL || + (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL) + error(SYSTEM, "out of memory in roundout"); + compinv(Ninv, da, m); + compinv(Sinv, da+3*m*(n-1), m); if (il->flags & IL_COLDST) { printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, il->matname, DSTSUF); printf("\n9 red green blue"); for (i = 0; i < 3; i++) { dfp = dfopen(il, DATORD[i]); - fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m); - colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp); + fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", + 1.+1./n, -1.-1./n, n+2, + 0., 2.*PI, m+1); + colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); + colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); + colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp); + fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, DATORD[i])); } } else { printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, il->matname, DSTSUF); - printf("\n5 noop"); + printf("\n5 noneg"); dfp = dfopen(il, 0); - fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m); - brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp); + fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", + 1.+1./n, -1.-1./n, n+2, + 0., 2.*PI, m+1); + brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); + brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); + brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp); + fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, 0)); } printf("\n\t%s il_alt il_azi", FNCFNM); printf("\n0\n0\n"); il->dfnum++; + free((void *)Ninv); + free((void *)Sinv); } -illumout(il, ob) /* print illum object */ -register struct illum_args *il; -OBJREC *ob; +extern void +illumout( /* print illum object */ + register struct illum_args *il, + OBJREC *ob +) { double cout[3]; - printf("\n%s%s %s %s", il->matname, DSTSUF, - ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame, + if (il->sampdens <= 0) + printf("\n%s ", VOIDID); + else + printf("\n%s%s ", il->matname, DSTSUF); + printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame, il->matname); if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID)) printf("\n0"); @@ -183,66 +236,131 @@ OBJREC *ob; } else { cout[0] = cout[1] = cout[2] = brt(il->col); } - if (il->flags & IL_LIGHT) - printf("\n3 %f %f %f\n", cout[0], cout[1], cout[2]); - else - printf("\n4 %f %f %f 0\n", cout[0], cout[1], cout[2]); + printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); printobj(il->matname, ob); } -average(il, da, n) /* compute average value for distribution */ -register struct illum_args *il; -register float *da; -int n; +void +compavg( /* compute average for set of data values */ + float col[3], + register float *da, + int n +) { register int i; - il->col[0] = il->col[1] = il->col[2] = 0.; + col[0] = col[1] = col[2] = 0.; i = n; while (i-- > 0) { - il->col[0] += *da++; - il->col[1] += *da++; - il->col[2] += *da++; + col[0] += *da++; + col[1] += *da++; + col[2] += *da++; } for (i = 0; i < 3; i++) - il->col[i] /= (double)n*il->nsamps; + col[i] /= (double)n; } -colorout(p, da, n, mult, fp) /* put out color distribution data */ -int p; -register float *da; -int n; -double mult; -FILE *fp; +void +compinv( /* compute other side of row average */ + register float *rinv, + register float *rp, + int m +) { - register int i; + float avg[3]; - for (i = 0; i < n; i++) { - if (i%6 == 0) - putc('\n', fp); - fprintf(fp, " %11e", mult*da[p]); - da += 3; + compavg(avg, rp, m); /* row average */ + while (m-- > 0) { + *rinv++ = 2.*avg[0] - *rp++; + *rinv++ = 2.*avg[1] - *rp++; + *rinv++ = 2.*avg[2] - *rp++; } +} + + +extern int +average( /* evaluate average value for distribution */ + register struct illum_args *il, + float *da, + int n +) +{ + compavg(il->col, da, n); /* average */ + if (il->nsamps > 1) { + il->col[0] /= (double)il->nsamps; + il->col[1] /= (double)il->nsamps; + il->col[2] /= (double)il->nsamps; + } + /* brighter than minimum? */ + return(brt(il->col) > il->minbrt+FTINY); +} + + +static int colmcnt = 0; /* count of columns written */ + +void +fputnum( /* put out a number to fp */ + double d, + FILE *fp +) +{ + if (colmcnt++ % 5 == 0) + putc('\n', fp); + fprintf(fp, " %11e", d); +} + + +void +fputeol( /* write end of line to fp */ + register FILE *fp +) +{ putc('\n', fp); + colmcnt = 0; } -brightout(da, n, mult, fp) /* put out brightness distribution data */ -register float *da; -int n; -double mult; -FILE *fp; +void +colorout( /* put out color distribution data */ + int p, + register float *da, + int n, + int m, + double mult, + FILE *fp +) { - register int i; + register int i, j; for (i = 0; i < n; i++) { - if (i%6 == 0) - putc('\n', fp); - fprintf(fp, " %11e", mult*brt(da)); - da += 3; + for (j = 0; j < m; j++) { + fputnum(mult*da[p], fp); + da += 3; + } + fputnum(mult*da[p-3*m], fp); /* wrap phi */ } - putc('\n', fp); +} + + +void +brightout( /* put out brightness distribution data */ + register float *da, + int n, + int m, + double mult, + FILE *fp +) +{ + register int i, j; + + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + fputnum(mult*brt(da), fp); + da += 3; + } + fputnum(mult*brt(da-3*m), fp); /* wrap phi */ + } }