| 12 |
|
|
| 13 |
|
#include "glare.h" |
| 14 |
|
|
| 15 |
< |
#include "random.h" |
| 16 |
< |
|
| 17 |
< |
#define FEQ(a,b) ((a)-(b)<=FTINY&&(a)-(b)<=FTINY) |
| 15 |
> |
#define FEQ(a,b) ((a)-(b)<=FTINY&&(b)-(a)<=FTINY) |
| 16 |
|
#define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ |
| 17 |
|
&&FEQ((v1)[2],(v2)[2])) |
| 18 |
|
|
| 19 |
< |
char *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"}; |
| 19 |
> |
char *rtargv[32] = {"rtrace", "-h-", "-ov", "-fff"}; |
| 20 |
|
int rtargc = 4; |
| 21 |
|
|
| 22 |
|
VIEW ourview = STDVIEW; /* our view */ |
| 36 |
|
int nglarangs = 0; |
| 37 |
|
double maxtheta; /* maximum angle (in radians) */ |
| 38 |
|
int hsize; /* horizontal size */ |
| 41 |
– |
int hlim; /* central limit of horizontal */ |
| 39 |
|
|
| 40 |
|
struct illum *indirect; /* array of indirect illuminances */ |
| 41 |
|
|
| 47 |
|
int argc; |
| 48 |
|
char *argv[]; |
| 49 |
|
{ |
| 50 |
+ |
int combine = 1; |
| 51 |
|
int gotview = 0; |
| 52 |
|
int rval, i; |
| 53 |
|
char *err; |
| 55 |
|
progname = argv[0]; |
| 56 |
|
/* process options */ |
| 57 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
| 58 |
+ |
/* expand arguments */ |
| 59 |
+ |
while (rval = expandarg(&argc, &argv, i)) |
| 60 |
+ |
if (rval < 0) { |
| 61 |
+ |
fprintf(stderr, "%s: cannot expand '%s'", |
| 62 |
+ |
argv[0], argv[i]); |
| 63 |
+ |
exit(1); |
| 64 |
+ |
} |
| 65 |
|
rval = getviewopt(&ourview, argc-i, argv+i); |
| 66 |
|
if (rval >= 0) { |
| 67 |
|
i += rval; |
| 82 |
|
} |
| 83 |
|
if (argv[i][2] != 'f') |
| 84 |
|
goto userr; |
| 85 |
< |
rval = viewfile(argv[++i], &ourview, 0, 0); |
| 85 |
> |
rval = viewfile(argv[++i], &ourview, NULL); |
| 86 |
|
if (rval < 0) { |
| 87 |
|
fprintf(stderr, |
| 88 |
|
"%s: cannot open view file \"%s\"\n", |
| 108 |
|
case 'p': |
| 109 |
|
picture = argv[++i]; |
| 110 |
|
break; |
| 111 |
+ |
case 'c': |
| 112 |
+ |
combine = !combine; |
| 113 |
+ |
break; |
| 114 |
|
case 'd': |
| 115 |
+ |
if (argv[i][2] == 'v') { |
| 116 |
+ |
rtargv[rtargc++] = argv[i]; |
| 117 |
+ |
break; |
| 118 |
+ |
} |
| 119 |
+ |
/* FALL THROUGH */ |
| 120 |
|
case 'l': |
| 121 |
+ |
case 's': |
| 122 |
+ |
case 'P': |
| 123 |
|
rtargv[rtargc++] = argv[i]; |
| 124 |
|
rtargv[rtargc++] = argv[++i]; |
| 125 |
|
break; |
| 126 |
+ |
case 'w': |
| 127 |
+ |
rtargv[rtargc++] = argv[i]; |
| 128 |
+ |
break; |
| 129 |
|
case 'a': |
| 130 |
|
rtargv[rtargc++] = argv[i]; |
| 131 |
|
if (argv[i][2] == 'v') { |
| 147 |
|
} |
| 148 |
|
/* get view */ |
| 149 |
|
if (picture != NULL) { |
| 150 |
< |
rval = viewfile(picture, &pictview, 0, 0); |
| 150 |
> |
rval = viewfile(picture, &pictview, NULL); |
| 151 |
|
if (rval < 0) { |
| 152 |
|
fprintf(stderr, "%s: cannot open picture file \"%s\"\n", |
| 153 |
|
progname, picture); |
| 199 |
|
if (threshold <= FTINY) |
| 200 |
|
comp_thresh(); /* compute glare threshold */ |
| 201 |
|
analyze(); /* analyze view */ |
| 202 |
+ |
if (combine) |
| 203 |
+ |
absorb_specks(); /* eliminate tiny sources */ |
| 204 |
|
cleanup(); /* tidy up */ |
| 205 |
|
/* print header */ |
| 206 |
+ |
newheader("RADIANCE", stdout); |
| 207 |
|
printargs(argc, argv, stdout); |
| 208 |
|
fputs(VIEWSTR, stdout); |
| 209 |
|
fprintview(&ourview, stdout); |
| 210 |
< |
printf("\n\n"); |
| 210 |
> |
printf("\n"); |
| 211 |
> |
fputformat("ascii", stdout); |
| 212 |
> |
printf("\n"); |
| 213 |
|
printsources(); /* print glare sources */ |
| 214 |
|
printillum(); /* print illuminances */ |
| 215 |
|
exit(0); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
|
| 224 |
+ |
int |
| 225 |
+ |
angcmp(ap1, ap2) /* compare two angles */ |
| 226 |
+ |
ANGLE *ap1, *ap2; |
| 227 |
+ |
{ |
| 228 |
+ |
register int a1, a2; |
| 229 |
+ |
|
| 230 |
+ |
a1 = *ap1; |
| 231 |
+ |
a2 = *ap2; |
| 232 |
+ |
if (a1 == a2) { |
| 233 |
+ |
fprintf(stderr, "%s: duplicate glare angle (%d)\n", |
| 234 |
+ |
progname, a1); |
| 235 |
+ |
exit(1); |
| 236 |
+ |
} |
| 237 |
+ |
return(a1-a2); |
| 238 |
+ |
} |
| 239 |
+ |
|
| 240 |
+ |
|
| 241 |
|
init() /* initialize global variables */ |
| 242 |
|
{ |
| 243 |
|
double d; |
| 249 |
|
/* set direction vectors */ |
| 250 |
|
for (i = 0; glarang[i] != AEND; i++) |
| 251 |
|
; |
| 252 |
< |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
| 253 |
< |
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
| 252 |
> |
qsort(glarang, i, sizeof(ANGLE), angcmp); |
| 253 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) { |
| 254 |
> |
fprintf(stderr, "%s: glare angles must be between 1 and 180\n", |
| 255 |
|
progname); |
| 256 |
|
exit(1); |
| 257 |
|
} |
| 262 |
|
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
| 263 |
|
else |
| 264 |
|
maxtheta = 0.0; |
| 265 |
< |
hlim = sampdens*maxtheta; |
| 225 |
< |
hsize = hlim + sampdens - 1; |
| 265 |
> |
hsize = hlim(0) + sampdens - 1; |
| 266 |
|
if (hsize > (int)(PI*sampdens)) |
| 267 |
|
hsize = PI*sampdens; |
| 268 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
| 317 |
|
cleanup() /* close files, wait for children */ |
| 318 |
|
{ |
| 319 |
|
if (verbose) |
| 320 |
< |
fprintf(stderr, "%s: cleaning up...\n", progname); |
| 320 |
> |
fprintf(stderr, "%s: cleaning up... \n", progname); |
| 321 |
|
if (picture != NULL) |
| 322 |
|
close_pict(); |
| 323 |
|
if (octree != NULL) |
| 324 |
|
done_rtrace(); |
| 325 |
|
if (npixinvw < 100*npixmiss) |
| 326 |
< |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
| 327 |
< |
progname, 100L*npixmiss/npixinvw); |
| 326 |
> |
fprintf(stderr, "%s: warning -- missing %d%% of samples\n", |
| 327 |
> |
progname, (int)(100L*npixmiss/npixinvw)); |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
|
| 332 |
|
FVECT vd; |
| 333 |
|
int x, y; |
| 334 |
|
{ |
| 335 |
< |
long t; |
| 335 |
> |
int hl; |
| 336 |
|
FVECT org; /* dummy variable */ |
| 337 |
|
|
| 338 |
< |
if (x <= -hlim) /* left region */ |
| 338 |
> |
hl = hlim(y); |
| 339 |
> |
if (x <= -hl) { /* left region */ |
| 340 |
> |
if (x <= -hl-sampdens) |
| 341 |
> |
return(-1); |
| 342 |
|
return(viewray(org, vd, &leftview, |
| 343 |
< |
(double)(x+hlim)/(2*sampdens)+.5, |
| 343 |
> |
(double)(x+hl)/(2*sampdens)+.5, |
| 344 |
|
(double)y/(2*sampdens)+.5)); |
| 345 |
< |
if (x >= hlim) /* right region */ |
| 345 |
> |
} |
| 346 |
> |
if (x >= hl) { /* right region */ |
| 347 |
> |
if (x >= hl+sampdens) |
| 348 |
> |
return(-1); |
| 349 |
|
return(viewray(org, vd, &rightview, |
| 350 |
< |
(double)(x-hlim)/(2*sampdens)+.5, |
| 350 |
> |
(double)(x-hl)/(2*sampdens)+.5, |
| 351 |
|
(double)y/(2*sampdens)+.5)); |
| 352 |
+ |
} |
| 353 |
|
/* central region */ |
| 307 |
– |
/* avoid over-counting of poles */ |
| 308 |
– |
t = random() % vsize; |
| 309 |
– |
if (t*t >= (long)vsize*vsize - (long)y*y) |
| 310 |
– |
return(-1); |
| 354 |
|
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
| 355 |
|
return(-1); |
| 356 |
< |
spinvector(vd, vd, ourview.vup, h_theta(x)); |
| 356 |
> |
spinvector(vd, vd, ourview.vup, h_theta(x,y)); |
| 357 |
|
return(0); |
| 358 |
+ |
} |
| 359 |
+ |
|
| 360 |
+ |
|
| 361 |
+ |
double |
| 362 |
+ |
pixsize(x, y) /* return the solid angle of pixel at (x,y) */ |
| 363 |
+ |
int x, y; |
| 364 |
+ |
{ |
| 365 |
+ |
register int hl, xo; |
| 366 |
+ |
double disc; |
| 367 |
+ |
|
| 368 |
+ |
hl = hlim(y); |
| 369 |
+ |
if (x < -hl) |
| 370 |
+ |
xo = x+hl; |
| 371 |
+ |
else if (x > hl) |
| 372 |
+ |
xo = x-hl; |
| 373 |
+ |
else |
| 374 |
+ |
xo = 0; |
| 375 |
+ |
disc = 1. - (double)((long)xo*xo + (long)y*y)/((long)sampdens*sampdens); |
| 376 |
+ |
if (disc <= FTINY*FTINY) |
| 377 |
+ |
return(0.); |
| 378 |
+ |
return(1./(sampdens*sampdens*sqrt(disc))); |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
|