--- ray/src/gen/mkillum3.c 1991/10/30 12:30:32 1.7 +++ ray/src/gen/mkillum3.c 2023/12/16 18:35:27 2.15 @@ -1,29 +1,38 @@ -/* 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.15 2023/12/16 18:35:27 greg Exp $"; #endif - /* * Routines to print mkillum objects */ #include "mkillum.h" +#include "paths.h" -#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 */ +static void compinv(COLORV *rinv, COLORV *rp, int m); +static void colorout(int p, COLORV *da, int n, int m, double mult, FILE *fp); +static void fputnum(double d, FILE *fp); +static void brightout(COLORV *da, int n, int m, double mult, FILE *fp); +static void fputeol(FILE *fp); +static void compavg(COLOR col, COLORV *da, int n); +static char * dfname(struct illum_args *il, int c); +static 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, + OBJREC *obj +) { - register int i; + 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,13 +55,13 @@ 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; + char *s; s = strcpy(fname, il->datafile); s += strlen(s); @@ -66,10 +75,11 @@ int c; } -FILE * -dfopen(il, c) /* open data file */ -register struct illum_args *il; -int c; +static FILE * +dfopen( /* open data file */ + struct illum_args *il, + int c +) { char *fn; FILE *fp; @@ -87,15 +97,24 @@ 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; +void +flatout( /* write hemispherical distribution */ + struct illum_args *il, + COLORV *da, + int n, + int m, + FVECT u, + FVECT v, + FVECT w +) { + COLORV *Ninv; FILE *dfp; int i; + if ((Ninv = (COLORV *)malloc(3*m*sizeof(COLORV))) == 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); @@ -103,20 +122,25 @@ FVECT u, v, w; for (i = 0; i < 3; i++) { dfp = dfopen(il, DATORD[i]); fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", - 1.-.5/n, .5/n, 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\n%f %f %d\n%f %f %d\n", 1.-.5/n, .5/n, n, + 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(da, n, m, 1./il->nsamps/brt(il->col), dfp); + brightout(Ninv, 1, m, 1./il->nsamps/bright(il->col), dfp); + brightout(da, n, m, 1./il->nsamps/bright(il->col), dfp); + fputeol(dfp); fclose(dfp); printf(" %s", dfname(il, 0)); } @@ -126,17 +150,27 @@ 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(Ninv); } -roundout(il, da, n, m) /* write spherical distribution */ -struct illum_args *il; -float *da; -int n, m; +void +roundout( /* write spherical distribution */ + struct illum_args *il, + COLORV *da, + int n, + int m +) { + COLORV *Ninv, *Sinv; FILE *dfp; int i; + if ((Ninv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL || + (Sinv = (COLORV *)malloc(3*m*sizeof(COLORV))) == 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); @@ -144,32 +178,43 @@ int n, m; for (i = 0; i < 3; i++) { dfp = dfopen(il, DATORD[i]); fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", - 1.-1./n, -1.+1./n, 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\n%f %f %d\n%f %f %d\n", 1.-1./n, -1.+1./n, n, + 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(da, n, m, 1./il->nsamps/brt(il->col), dfp); + brightout(Ninv, 1, m, 1./il->nsamps/bright(il->col), dfp); + brightout(da, n, m, 1./il->nsamps/bright(il->col), dfp); + brightout(Sinv, 1, m, 1./il->nsamps/bright(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(Ninv); + free(Sinv); } -illumout(il, ob) /* print illum object */ -register struct illum_args *il; -OBJREC *ob; +void +illumout( /* print illum object */ + struct illum_args *il, + OBJREC *ob +) { double cout[3]; @@ -188,7 +233,7 @@ OBJREC *ob; cout[1] = il->col[1]; cout[2] = il->col[2]; } else { - cout[0] = cout[1] = cout[2] = brt(il->col); + cout[0] = cout[1] = cout[2] = bright(il->col); } printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); @@ -196,55 +241,96 @@ OBJREC *ob; } -average(il, da, n) /* compute average value for distribution */ -register struct illum_args *il; -register float *da; -int n; +static void +compavg( /* compute average for set of data values */ + COLOR col, + COLORV *da, + int n +) { - register int i; + int i; - il->col[0] = il->col[1] = il->col[2] = 0.; + setcolor(col, 0.0, 0.0, 0.0); i = n; while (i-- > 0) { - il->col[0] += *da++; - il->col[1] += *da++; - il->col[2] += *da++; + addcolor(col, da); + da += 3; } - for (i = 0; i < 3; i++) - il->col[i] /= (double)n*il->nsamps; + scalecolor(col, 1./(double)n); +} - return(brt(il->col) > il->minbrt+FTINY); + +static void +compinv( /* compute other side of row average */ + COLORV *rinv, + COLORV *rp, + int m +) +{ + COLOR avg; + + compavg(avg, rp, m); /* row average */ + while (m-- > 0) { + *rinv++ = 2.*avg[0] - *rp++; + *rinv++ = 2.*avg[1] - *rp++; + *rinv++ = 2.*avg[2] - *rp++; + } } +int +average( /* evaluate average value for distribution */ + struct illum_args *il, + COLORV *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(bright(il->col) > il->minbrt+FTINY); +} + + static int colmcnt = 0; /* count of columns written */ -fputnum(d, fp) /* put out a number to fp */ -double d; -FILE *fp; +static void +fputnum( /* put out a number to fp */ + double d, + FILE *fp +) { - if (colmcnt++ % 6 == 0) + if (colmcnt++ % 5 == 0) putc('\n', fp); fprintf(fp, " %11e", d); } -fputeol(fp) /* write end of line to fp */ -register FILE *fp; +static void +fputeol( /* write end of line to fp */ + FILE *fp +) { putc('\n', fp); colmcnt = 0; } -colorout(p, da, n, m, mult, fp) /* put out color distribution data */ -int p; -register float *da; -int n, m; -double mult; -FILE *fp; +static void +colorout( /* put out color distribution data */ + int p, + COLORV *da, + int n, + int m, + double mult, + FILE *fp +) { - register int i, j; + int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { @@ -253,24 +339,25 @@ FILE *fp; } fputnum(mult*da[p-3*m], fp); /* wrap phi */ } - fputeol(fp); } -brightout(da, n, m, mult, fp) /* put out brightness distribution data */ -register float *da; -int n, m; -double mult; -FILE *fp; +static void +brightout( /* put out brightness distribution data */ + COLORV *da, + int n, + int m, + double mult, + FILE *fp +) { - register int i, j; + int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { - fputnum(mult*brt(da), fp); + fputnum(mult*bright(da), fp); da += 3; } - fputnum(mult*brt(da-3*m), fp); /* wrap phi */ + fputnum(mult*bright(da-3*m), fp); /* wrap phi */ } - fputeol(fp); }