| 12 |
|
|
| 13 |
|
#include "glare.h" |
| 14 |
|
|
| 15 |
< |
#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"}; |
| 20 |
< |
int rtargc = 4; |
| 19 |
> |
char *rtargv[64] = {"rtrace", "-h-", "-ov", "-fff", "-ld-", "-i-", "-I-"}; |
| 20 |
> |
int rtargc = 7; |
| 21 |
|
|
| 22 |
|
VIEW ourview = STDVIEW; /* our view */ |
| 23 |
|
VIEW pictview = STDVIEW; /* picture view */ |
| 36 |
|
int nglarangs = 0; |
| 37 |
|
double maxtheta; /* maximum angle (in radians) */ |
| 38 |
|
int hsize; /* horizontal size */ |
| 39 |
– |
int hlim; /* central limit of horizontal */ |
| 39 |
|
|
| 40 |
|
struct illum *indirect; /* array of indirect illuminances */ |
| 41 |
|
|
| 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", |
| 112 |
|
combine = !combine; |
| 113 |
|
break; |
| 114 |
|
case 'd': |
| 115 |
+ |
rtargv[rtargc++] = argv[i]; |
| 116 |
+ |
if (argv[i][2] != 'v') |
| 117 |
+ |
rtargv[rtargc++] = argv[++i]; |
| 118 |
+ |
break; |
| 119 |
|
case 'l': |
| 120 |
+ |
if (argv[i][2] == 'd') |
| 121 |
+ |
break; |
| 122 |
+ |
/* FALL THROUGH */ |
| 123 |
+ |
case 's': |
| 124 |
+ |
case 'P': |
| 125 |
|
rtargv[rtargc++] = argv[i]; |
| 126 |
|
rtargv[rtargc++] = argv[++i]; |
| 127 |
|
break; |
| 128 |
+ |
case 'w': |
| 129 |
+ |
rtargv[rtargc++] = argv[i]; |
| 130 |
+ |
break; |
| 131 |
|
case 'a': |
| 132 |
|
rtargv[rtargc++] = argv[i]; |
| 133 |
|
if (argv[i][2] == 'v') { |
| 149 |
|
} |
| 150 |
|
/* get view */ |
| 151 |
|
if (picture != NULL) { |
| 152 |
< |
rval = viewfile(picture, &pictview, 0, 0); |
| 152 |
> |
rval = viewfile(picture, &pictview, NULL); |
| 153 |
|
if (rval < 0) { |
| 154 |
|
fprintf(stderr, "%s: cannot open picture file \"%s\"\n", |
| 155 |
|
progname, picture); |
| 205 |
|
absorb_specks(); /* eliminate tiny sources */ |
| 206 |
|
cleanup(); /* tidy up */ |
| 207 |
|
/* print header */ |
| 208 |
+ |
newheader("RADIANCE", stdout); |
| 209 |
|
printargs(argc, argv, stdout); |
| 210 |
|
fputs(VIEWSTR, stdout); |
| 211 |
|
fprintview(&ourview, stdout); |
| 212 |
< |
printf("\n\n"); |
| 212 |
> |
printf("\n"); |
| 213 |
> |
fputformat("ascii", stdout); |
| 214 |
> |
printf("\n"); |
| 215 |
|
printsources(); /* print glare sources */ |
| 216 |
|
printillum(); /* print illuminances */ |
| 217 |
|
exit(0); |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
|
| 226 |
+ |
int |
| 227 |
+ |
angcmp(ap1, ap2) /* compare two angles */ |
| 228 |
+ |
ANGLE *ap1, *ap2; |
| 229 |
+ |
{ |
| 230 |
+ |
register int a1, a2; |
| 231 |
+ |
|
| 232 |
+ |
a1 = *ap1; |
| 233 |
+ |
a2 = *ap2; |
| 234 |
+ |
if (a1 == a2) { |
| 235 |
+ |
fprintf(stderr, "%s: duplicate glare angle (%d)\n", |
| 236 |
+ |
progname, a1); |
| 237 |
+ |
exit(1); |
| 238 |
+ |
} |
| 239 |
+ |
return(a1-a2); |
| 240 |
+ |
} |
| 241 |
+ |
|
| 242 |
+ |
|
| 243 |
|
init() /* initialize global variables */ |
| 244 |
|
{ |
| 245 |
|
double d; |
| 251 |
|
/* set direction vectors */ |
| 252 |
|
for (i = 0; glarang[i] != AEND; i++) |
| 253 |
|
; |
| 254 |
< |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
| 255 |
< |
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
| 254 |
> |
qsort(glarang, i, sizeof(ANGLE), angcmp); |
| 255 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) { |
| 256 |
> |
fprintf(stderr, "%s: glare angles must be between 1 and 180\n", |
| 257 |
|
progname); |
| 258 |
|
exit(1); |
| 259 |
|
} |
| 264 |
|
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
| 265 |
|
else |
| 266 |
|
maxtheta = 0.0; |
| 267 |
< |
hlim = sampdens*maxtheta; |
| 229 |
< |
hsize = hlim + sampdens - 1; |
| 267 |
> |
hsize = hlim(0) + sampdens - 1; |
| 268 |
|
if (hsize > (int)(PI*sampdens)) |
| 269 |
|
hsize = PI*sampdens; |
| 270 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
| 325 |
|
if (octree != NULL) |
| 326 |
|
done_rtrace(); |
| 327 |
|
if (npixinvw < 100*npixmiss) |
| 328 |
< |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
| 329 |
< |
progname, 100L*npixmiss/npixinvw); |
| 328 |
> |
fprintf(stderr, "%s: warning -- missing %d%% of samples\n", |
| 329 |
> |
progname, (int)(100L*npixmiss/npixinvw)); |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
|
| 333 |
< |
compdir(vd, x, y, se) /* compute direction for x,y */ |
| 333 |
> |
compdir(vd, x, y) /* compute direction for x,y */ |
| 334 |
|
FVECT vd; |
| 335 |
|
int x, y; |
| 298 |
– |
SPANERR *se; |
| 336 |
|
{ |
| 337 |
+ |
int hl; |
| 338 |
|
FVECT org; /* dummy variable */ |
| 339 |
|
|
| 340 |
< |
if (x <= -hlim) /* left region */ |
| 340 |
> |
hl = hlim(y); |
| 341 |
> |
if (x <= -hl) { /* left region */ |
| 342 |
> |
if (x <= -hl-sampdens) |
| 343 |
> |
return(-1); |
| 344 |
|
return(viewray(org, vd, &leftview, |
| 345 |
< |
(double)(x+hlim)/(2*sampdens)+.5, |
| 345 |
> |
(double)(x+hl)/(2*sampdens)+.5, |
| 346 |
|
(double)y/(2*sampdens)+.5)); |
| 347 |
< |
if (x >= hlim) /* right region */ |
| 347 |
> |
} |
| 348 |
> |
if (x >= hl) { /* right region */ |
| 349 |
> |
if (x >= hl+sampdens) |
| 350 |
> |
return(-1); |
| 351 |
|
return(viewray(org, vd, &rightview, |
| 352 |
< |
(double)(x-hlim)/(2*sampdens)+.5, |
| 352 |
> |
(double)(x-hl)/(2*sampdens)+.5, |
| 353 |
|
(double)y/(2*sampdens)+.5)); |
| 310 |
– |
/* central region */ |
| 311 |
– |
if (se != NULL) { /* avoid over-counting of poles */ |
| 312 |
– |
se->err += se->prob; |
| 313 |
– |
if (se->err <= 0.5) |
| 314 |
– |
return(-1); |
| 315 |
– |
se->err -= 1.0; |
| 354 |
|
} |
| 355 |
+ |
/* central region */ |
| 356 |
|
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
| 357 |
|
return(-1); |
| 358 |
< |
spinvector(vd, vd, ourview.vup, h_theta(x)); |
| 358 |
> |
spinvector(vd, vd, ourview.vup, h_theta(x,y)); |
| 359 |
|
return(0); |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
|
| 363 |
< |
setspanerr(se, y) /* initialize span error at y */ |
| 364 |
< |
register SPANERR *se; |
| 365 |
< |
int y; |
| 363 |
> |
double |
| 364 |
> |
pixsize(x, y) /* return the solid angle of pixel at (x,y) */ |
| 365 |
> |
int x, y; |
| 366 |
|
{ |
| 367 |
< |
se->err = 0.0; |
| 368 |
< |
se->prob = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); |
| 367 |
> |
register int hl, xo; |
| 368 |
> |
double disc; |
| 369 |
> |
|
| 370 |
> |
hl = hlim(y); |
| 371 |
> |
if (x < -hl) |
| 372 |
> |
xo = x+hl; |
| 373 |
> |
else if (x > hl) |
| 374 |
> |
xo = x-hl; |
| 375 |
> |
else |
| 376 |
> |
xo = 0; |
| 377 |
> |
disc = 1. - (double)((long)xo*xo + (long)y*y)/((long)sampdens*sampdens); |
| 378 |
> |
if (disc <= FTINY*FTINY) |
| 379 |
> |
return(0.); |
| 380 |
> |
return(1./(sampdens*sampdens*sqrt(disc))); |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
|