| 1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Routines to print mkillum objects |
| 6 |
|
*/ |
| 14 |
|
char DSTSUF[] = ".dist"; /* distribution suffix */ |
| 15 |
|
char FNCFNM[] = "illum.cal"; /* function file name */ |
| 16 |
|
|
| 17 |
+ |
void compinv(float *rinv, float *rp, int m); |
| 18 |
+ |
void colorout(int p, float *da, int n, int m, double mult, FILE *fp); |
| 19 |
+ |
void fputnum(double d, FILE *fp); |
| 20 |
+ |
void brightout(float *da, int n, int m, double mult, FILE *fp); |
| 21 |
+ |
void fputeol(FILE *fp); |
| 22 |
+ |
void compavg(float col[3], float *da, int n); |
| 23 |
+ |
char * dfname(struct illum_args *il, int c); |
| 24 |
+ |
FILE * dfopen(struct illum_args *il, int c); |
| 25 |
|
|
| 26 |
< |
printobj(mod, obj) /* print out an object */ |
| 27 |
< |
char *mod; |
| 28 |
< |
register OBJREC *obj; |
| 26 |
> |
|
| 27 |
> |
void |
| 28 |
> |
printobj( /* print out an object */ |
| 29 |
> |
char *mod, |
| 30 |
> |
register OBJREC *obj |
| 31 |
> |
) |
| 32 |
|
{ |
| 33 |
|
register int i; |
| 34 |
|
|
| 35 |
+ |
if (issurface(obj->otype) && !strcmp(mod, VOIDID)) |
| 36 |
+ |
return; /* don't print void surfaces */ |
| 37 |
|
printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname); |
| 38 |
|
printf("\n%d", obj->oargs.nsargs); |
| 39 |
|
for (i = 0; i < obj->oargs.nsargs; i++) |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
char * |
| 59 |
< |
dfname(il, c) /* return data file name */ |
| 60 |
< |
struct illum_args *il; |
| 61 |
< |
int c; |
| 59 |
> |
dfname( /* return data file name */ |
| 60 |
> |
struct illum_args *il, |
| 61 |
> |
int c |
| 62 |
> |
) |
| 63 |
|
{ |
| 53 |
– |
extern char *getpath(), *strcpy(); |
| 64 |
|
char fname[MAXSTR]; |
| 65 |
|
register char *s; |
| 66 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
FILE * |
| 80 |
< |
dfopen(il, c) /* open data file */ |
| 81 |
< |
register struct illum_args *il; |
| 82 |
< |
int c; |
| 80 |
> |
dfopen( /* open data file */ |
| 81 |
> |
register struct illum_args *il, |
| 82 |
> |
int c |
| 83 |
> |
) |
| 84 |
|
{ |
| 85 |
|
char *fn; |
| 86 |
|
FILE *fp; |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
< |
flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */ |
| 102 |
< |
struct illum_args *il; |
| 103 |
< |
float *da; |
| 104 |
< |
int n, m; |
| 105 |
< |
FVECT u, v, w; |
| 101 |
> |
extern void |
| 102 |
> |
flatout( /* write hemispherical distribution */ |
| 103 |
> |
struct illum_args *il, |
| 104 |
> |
float *da, |
| 105 |
> |
int n, |
| 106 |
> |
int m, |
| 107 |
> |
FVECT u, |
| 108 |
> |
FVECT v, |
| 109 |
> |
FVECT w |
| 110 |
> |
) |
| 111 |
|
{ |
| 112 |
+ |
float *Ninv; |
| 113 |
|
FILE *dfp; |
| 114 |
|
int i; |
| 115 |
|
|
| 116 |
+ |
if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL) |
| 117 |
+ |
error(SYSTEM, "out of memory in flatout"); |
| 118 |
+ |
compinv(Ninv, da, m); |
| 119 |
|
if (il->flags & IL_COLDST) { |
| 120 |
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
| 121 |
|
il->matname, DSTSUF); |
| 123 |
|
for (i = 0; i < 3; i++) { |
| 124 |
|
dfp = dfopen(il, DATORD[i]); |
| 125 |
|
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
| 126 |
< |
1.-.5/n, .5/n, n, |
| 126 |
> |
1.+.5/n, .5/n, n+1, |
| 127 |
|
0., 2.*PI, m+1); |
| 128 |
+ |
colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); |
| 129 |
|
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
| 130 |
+ |
fputeol(dfp); |
| 131 |
|
fclose(dfp); |
| 132 |
|
printf(" %s", dfname(il, DATORD[i])); |
| 133 |
|
} |
| 134 |
|
} else { |
| 135 |
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
| 136 |
|
il->matname, DSTSUF); |
| 137 |
< |
printf("\n5 noop"); |
| 137 |
> |
printf("\n5 noneg"); |
| 138 |
|
dfp = dfopen(il, 0); |
| 139 |
< |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-.5/n, .5/n, n, |
| 139 |
> |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
| 140 |
> |
1.+.5/n, .5/n, n+1, |
| 141 |
|
0., 2.*PI, m+1); |
| 142 |
+ |
brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); |
| 143 |
|
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
| 144 |
+ |
fputeol(dfp); |
| 145 |
|
fclose(dfp); |
| 146 |
|
printf(" %s", dfname(il, 0)); |
| 147 |
|
} |
| 151 |
|
printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); |
| 152 |
|
printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); |
| 153 |
|
il->dfnum++; |
| 154 |
+ |
free((void *)Ninv); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
< |
roundout(il, da, n, m) /* write spherical distribution */ |
| 159 |
< |
struct illum_args *il; |
| 160 |
< |
float *da; |
| 161 |
< |
int n, m; |
| 158 |
> |
extern void |
| 159 |
> |
roundout( /* write spherical distribution */ |
| 160 |
> |
struct illum_args *il, |
| 161 |
> |
float *da, |
| 162 |
> |
int n, |
| 163 |
> |
int m |
| 164 |
> |
) |
| 165 |
|
{ |
| 166 |
+ |
float *Ninv, *Sinv; |
| 167 |
|
FILE *dfp; |
| 168 |
|
int i; |
| 169 |
|
|
| 170 |
+ |
if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL || |
| 171 |
+ |
(Sinv = (float *)malloc(3*m*sizeof(float))) == NULL) |
| 172 |
+ |
error(SYSTEM, "out of memory in roundout"); |
| 173 |
+ |
compinv(Ninv, da, m); |
| 174 |
+ |
compinv(Sinv, da+3*m*(n-1), m); |
| 175 |
|
if (il->flags & IL_COLDST) { |
| 176 |
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
| 177 |
|
il->matname, DSTSUF); |
| 179 |
|
for (i = 0; i < 3; i++) { |
| 180 |
|
dfp = dfopen(il, DATORD[i]); |
| 181 |
|
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
| 182 |
< |
1.-1./n, -1.+1./n, n, |
| 182 |
> |
1.+1./n, -1.-1./n, n+2, |
| 183 |
|
0., 2.*PI, m+1); |
| 184 |
+ |
colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); |
| 185 |
|
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
| 186 |
+ |
colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp); |
| 187 |
+ |
fputeol(dfp); |
| 188 |
|
fclose(dfp); |
| 189 |
|
printf(" %s", dfname(il, DATORD[i])); |
| 190 |
|
} |
| 191 |
|
} else { |
| 192 |
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
| 193 |
|
il->matname, DSTSUF); |
| 194 |
< |
printf("\n5 noop"); |
| 194 |
> |
printf("\n5 noneg"); |
| 195 |
|
dfp = dfopen(il, 0); |
| 196 |
< |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-1./n, -1.+1./n, n, |
| 196 |
> |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
| 197 |
> |
1.+1./n, -1.-1./n, n+2, |
| 198 |
|
0., 2.*PI, m+1); |
| 199 |
+ |
brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); |
| 200 |
|
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
| 201 |
+ |
brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp); |
| 202 |
+ |
fputeol(dfp); |
| 203 |
|
fclose(dfp); |
| 204 |
|
printf(" %s", dfname(il, 0)); |
| 205 |
|
} |
| 206 |
|
printf("\n\t%s il_alt il_azi", FNCFNM); |
| 207 |
|
printf("\n0\n0\n"); |
| 208 |
|
il->dfnum++; |
| 209 |
+ |
free((void *)Ninv); |
| 210 |
+ |
free((void *)Sinv); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
|
| 214 |
< |
illumout(il, ob) /* print illum object */ |
| 215 |
< |
register struct illum_args *il; |
| 216 |
< |
OBJREC *ob; |
| 214 |
> |
extern void |
| 215 |
> |
illumout( /* print illum object */ |
| 216 |
> |
register struct illum_args *il, |
| 217 |
> |
OBJREC *ob |
| 218 |
> |
) |
| 219 |
|
{ |
| 220 |
|
double cout[3]; |
| 221 |
|
|
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
|
| 245 |
< |
average(il, da, n) /* compute average value for distribution */ |
| 246 |
< |
register struct illum_args *il; |
| 247 |
< |
register float *da; |
| 248 |
< |
int n; |
| 245 |
> |
void |
| 246 |
> |
compavg( /* compute average for set of data values */ |
| 247 |
> |
float col[3], |
| 248 |
> |
register float *da, |
| 249 |
> |
int n |
| 250 |
> |
) |
| 251 |
|
{ |
| 252 |
|
register int i; |
| 253 |
|
|
| 254 |
< |
il->col[0] = il->col[1] = il->col[2] = 0.; |
| 254 |
> |
col[0] = col[1] = col[2] = 0.; |
| 255 |
|
i = n; |
| 256 |
|
while (i-- > 0) { |
| 257 |
< |
il->col[0] += *da++; |
| 258 |
< |
il->col[1] += *da++; |
| 259 |
< |
il->col[2] += *da++; |
| 257 |
> |
col[0] += *da++; |
| 258 |
> |
col[1] += *da++; |
| 259 |
> |
col[2] += *da++; |
| 260 |
|
} |
| 261 |
|
for (i = 0; i < 3; i++) |
| 262 |
< |
il->col[i] /= (double)n*il->nsamps; |
| 262 |
> |
col[i] /= (double)n; |
| 263 |
> |
} |
| 264 |
|
|
| 265 |
+ |
|
| 266 |
+ |
void |
| 267 |
+ |
compinv( /* compute other side of row average */ |
| 268 |
+ |
register float *rinv, |
| 269 |
+ |
register float *rp, |
| 270 |
+ |
int m |
| 271 |
+ |
) |
| 272 |
+ |
{ |
| 273 |
+ |
float avg[3]; |
| 274 |
+ |
|
| 275 |
+ |
compavg(avg, rp, m); /* row average */ |
| 276 |
+ |
while (m-- > 0) { |
| 277 |
+ |
*rinv++ = 2.*avg[0] - *rp++; |
| 278 |
+ |
*rinv++ = 2.*avg[1] - *rp++; |
| 279 |
+ |
*rinv++ = 2.*avg[2] - *rp++; |
| 280 |
+ |
} |
| 281 |
+ |
} |
| 282 |
+ |
|
| 283 |
+ |
|
| 284 |
+ |
extern int |
| 285 |
+ |
average( /* evaluate average value for distribution */ |
| 286 |
+ |
register struct illum_args *il, |
| 287 |
+ |
float *da, |
| 288 |
+ |
int n |
| 289 |
+ |
) |
| 290 |
+ |
{ |
| 291 |
+ |
compavg(il->col, da, n); /* average */ |
| 292 |
+ |
if (il->nsamps > 1) { |
| 293 |
+ |
il->col[0] /= (double)il->nsamps; |
| 294 |
+ |
il->col[1] /= (double)il->nsamps; |
| 295 |
+ |
il->col[2] /= (double)il->nsamps; |
| 296 |
+ |
} |
| 297 |
+ |
/* brighter than minimum? */ |
| 298 |
|
return(brt(il->col) > il->minbrt+FTINY); |
| 299 |
|
} |
| 300 |
|
|
| 301 |
|
|
| 302 |
|
static int colmcnt = 0; /* count of columns written */ |
| 303 |
|
|
| 304 |
< |
fputnum(d, fp) /* put out a number to fp */ |
| 305 |
< |
double d; |
| 306 |
< |
FILE *fp; |
| 304 |
> |
void |
| 305 |
> |
fputnum( /* put out a number to fp */ |
| 306 |
> |
double d, |
| 307 |
> |
FILE *fp |
| 308 |
> |
) |
| 309 |
|
{ |
| 310 |
< |
if (colmcnt++ % 6 == 0) |
| 310 |
> |
if (colmcnt++ % 5 == 0) |
| 311 |
|
putc('\n', fp); |
| 312 |
|
fprintf(fp, " %11e", d); |
| 313 |
|
} |
| 314 |
|
|
| 315 |
|
|
| 316 |
< |
fputeol(fp) /* write end of line to fp */ |
| 317 |
< |
register FILE *fp; |
| 316 |
> |
void |
| 317 |
> |
fputeol( /* write end of line to fp */ |
| 318 |
> |
register FILE *fp |
| 319 |
> |
) |
| 320 |
|
{ |
| 321 |
|
putc('\n', fp); |
| 322 |
|
colmcnt = 0; |
| 323 |
|
} |
| 324 |
|
|
| 325 |
|
|
| 326 |
< |
colorout(p, da, n, m, mult, fp) /* put out color distribution data */ |
| 327 |
< |
int p; |
| 328 |
< |
register float *da; |
| 329 |
< |
int n, m; |
| 330 |
< |
double mult; |
| 331 |
< |
FILE *fp; |
| 326 |
> |
void |
| 327 |
> |
colorout( /* put out color distribution data */ |
| 328 |
> |
int p, |
| 329 |
> |
register float *da, |
| 330 |
> |
int n, |
| 331 |
> |
int m, |
| 332 |
> |
double mult, |
| 333 |
> |
FILE *fp |
| 334 |
> |
) |
| 335 |
|
{ |
| 336 |
|
register int i, j; |
| 337 |
|
|
| 342 |
|
} |
| 343 |
|
fputnum(mult*da[p-3*m], fp); /* wrap phi */ |
| 344 |
|
} |
| 256 |
– |
fputeol(fp); |
| 345 |
|
} |
| 346 |
|
|
| 347 |
|
|
| 348 |
< |
brightout(da, n, m, mult, fp) /* put out brightness distribution data */ |
| 349 |
< |
register float *da; |
| 350 |
< |
int n, m; |
| 351 |
< |
double mult; |
| 352 |
< |
FILE *fp; |
| 348 |
> |
void |
| 349 |
> |
brightout( /* put out brightness distribution data */ |
| 350 |
> |
register float *da, |
| 351 |
> |
int n, |
| 352 |
> |
int m, |
| 353 |
> |
double mult, |
| 354 |
> |
FILE *fp |
| 355 |
> |
) |
| 356 |
|
{ |
| 357 |
|
register int i, j; |
| 358 |
|
|
| 363 |
|
} |
| 364 |
|
fputnum(mult*brt(da-3*m), fp); /* wrap phi */ |
| 365 |
|
} |
| 275 |
– |
fputeol(fp); |
| 366 |
|
} |