| 19 |
|
char *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"}; |
| 20 |
|
int rtargc = 4; |
| 21 |
|
|
| 22 |
< |
VIEW ourview; /* our view */ |
| 22 |
> |
VIEW ourview = STDVIEW; /* our view */ |
| 23 |
|
VIEW pictview = STDVIEW; /* picture view */ |
| 24 |
|
VIEW leftview, rightview; /* leftmost and rightmost views */ |
| 25 |
|
|
| 29 |
|
int verbose = 0; /* verbose reporting */ |
| 30 |
|
char *progname; /* global argv[0] */ |
| 31 |
|
|
| 32 |
+ |
double threshold = 0.; /* glare threshold */ |
| 33 |
+ |
|
| 34 |
|
int sampdens = SAMPDENS; /* sample density */ |
| 35 |
|
ANGLE glarang[180] = {AEND}; /* glare calculation angles */ |
| 36 |
|
int nglarangs = 0; |
| 40 |
|
|
| 41 |
|
struct illum *indirect; /* array of indirect illuminances */ |
| 42 |
|
|
| 43 |
+ |
long npixinvw; /* number of pixels in view */ |
| 44 |
+ |
long npixmiss; /* number of pixels missed */ |
| 45 |
|
|
| 46 |
+ |
|
| 47 |
|
main(argc, argv) |
| 48 |
|
int argc; |
| 49 |
|
char *argv[]; |
| 50 |
|
{ |
| 51 |
+ |
int combine = 1; |
| 52 |
|
int gotview = 0; |
| 53 |
|
int rval, i; |
| 54 |
|
char *err; |
| 63 |
|
continue; |
| 64 |
|
} |
| 65 |
|
switch (argv[i][1]) { |
| 66 |
+ |
case 't': |
| 67 |
+ |
threshold = atof(argv[++i]); |
| 68 |
+ |
break; |
| 69 |
|
case 'r': |
| 70 |
|
sampdens = atoi(argv[++i])/2; |
| 71 |
|
break; |
| 102 |
|
case 'p': |
| 103 |
|
picture = argv[++i]; |
| 104 |
|
break; |
| 105 |
+ |
case 'c': |
| 106 |
+ |
combine = !combine; |
| 107 |
+ |
break; |
| 108 |
|
case 'd': |
| 109 |
|
case 'l': |
| 110 |
|
rtargv[rtargc++] = argv[i]; |
| 180 |
|
exit(1); |
| 181 |
|
} |
| 182 |
|
init(); /* initialize program */ |
| 183 |
< |
comp_thresh(); /* compute glare threshold */ |
| 183 |
> |
if (threshold <= FTINY) |
| 184 |
> |
comp_thresh(); /* compute glare threshold */ |
| 185 |
|
analyze(); /* analyze view */ |
| 186 |
+ |
if (combine) |
| 187 |
+ |
absorb_specks(); /* eliminate tiny sources */ |
| 188 |
|
cleanup(); /* tidy up */ |
| 189 |
|
/* print header */ |
| 190 |
|
printargs(argc, argv, stdout); |
| 213 |
|
/* set direction vectors */ |
| 214 |
|
for (i = 0; glarang[i] != AEND; i++) |
| 215 |
|
; |
| 216 |
< |
if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) { |
| 216 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
| 217 |
|
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
| 218 |
|
progname); |
| 219 |
|
exit(1); |
| 220 |
|
} |
| 221 |
|
nglarangs = i; |
| 222 |
|
/* nglardirs = 2*nglarangs + 1; */ |
| 223 |
< |
/* vsize = sampdens; */ |
| 223 |
> |
/* vsize = sampdens - 1; */ |
| 224 |
|
if (nglarangs > 0) |
| 225 |
|
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
| 226 |
|
else |
| 227 |
|
maxtheta = 0.0; |
| 228 |
|
hlim = sampdens*maxtheta; |
| 229 |
< |
hsize = sampdens + hlim; |
| 229 |
> |
hsize = hlim + sampdens - 1; |
| 230 |
|
if (hsize > (int)(PI*sampdens)) |
| 231 |
|
hsize = PI*sampdens; |
| 232 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
| 233 |
|
if (indirect == NULL) |
| 234 |
|
memerr("indirect illuminances"); |
| 235 |
+ |
npixinvw = npixmiss = 0L; |
| 236 |
|
copystruct(&leftview, &ourview); |
| 237 |
|
copystruct(&rightview, &ourview); |
| 238 |
|
spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); |
| 241 |
|
setview(&rightview); |
| 242 |
|
indirect[nglarangs].lcos = |
| 243 |
|
indirect[nglarangs].rcos = cos(maxtheta); |
| 244 |
< |
indirect[nglarangs].lsin = |
| 245 |
< |
-(indirect[nglarangs].rsin = sin(maxtheta)); |
| 244 |
> |
indirect[nglarangs].rsin = |
| 245 |
> |
-(indirect[nglarangs].lsin = sin(maxtheta)); |
| 246 |
|
indirect[nglarangs].theta = 0.0; |
| 247 |
|
for (i = 0; i < nglarangs; i++) { |
| 248 |
|
d = (glarang[nglarangs-1] - glarang[i])*(PI/180.); |
| 249 |
|
indirect[nglarangs-i-1].lcos = |
| 250 |
|
indirect[nglarangs+i+1].rcos = cos(d); |
| 251 |
< |
indirect[nglarangs-i-1].lsin = |
| 252 |
< |
-(indirect[nglarangs+i+1].rsin = sin(d)); |
| 251 |
> |
indirect[nglarangs+i+1].rsin = |
| 252 |
> |
-(indirect[nglarangs-i-1].lsin = sin(d)); |
| 253 |
|
d = (glarang[nglarangs-1] + glarang[i])*(PI/180.); |
| 254 |
|
indirect[nglarangs-i-1].rcos = |
| 255 |
|
indirect[nglarangs+i+1].lcos = cos(d); |
| 256 |
< |
indirect[nglarangs+i+1].lsin = |
| 257 |
< |
-(indirect[nglarangs-i-1].rsin = sin(d)); |
| 258 |
< |
indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i]; |
| 259 |
< |
indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i]; |
| 256 |
> |
indirect[nglarangs-i-1].rsin = |
| 257 |
> |
-(indirect[nglarangs+i+1].lsin = sin(d)); |
| 258 |
> |
indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i]; |
| 259 |
> |
indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i]; |
| 260 |
|
} |
| 261 |
|
/* open picture */ |
| 262 |
|
if (picture != NULL) { |
| 286 |
|
close_pict(); |
| 287 |
|
if (octree != NULL) |
| 288 |
|
done_rtrace(); |
| 289 |
+ |
if (npixinvw < 100*npixmiss) |
| 290 |
+ |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
| 291 |
+ |
progname, 100L*npixmiss/npixinvw); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
|
| 296 |
|
FVECT vd; |
| 297 |
|
int x, y; |
| 298 |
|
{ |
| 299 |
+ |
static int cury = 10000; |
| 300 |
+ |
static double err, cmpval; |
| 301 |
+ |
long t; |
| 302 |
|
FVECT org; /* dummy variable */ |
| 303 |
|
|
| 304 |
|
if (x <= -hlim) /* left region */ |
| 305 |
|
return(viewray(org, vd, &leftview, |
| 306 |
< |
(x+hlim)/(2.*sampdens)+.5, |
| 307 |
< |
y/(2.*sampdens)+.5)); |
| 306 |
> |
(double)(x+hlim)/(2*sampdens)+.5, |
| 307 |
> |
(double)y/(2*sampdens)+.5)); |
| 308 |
|
if (x >= hlim) /* right region */ |
| 309 |
|
return(viewray(org, vd, &rightview, |
| 310 |
< |
(x-hlim)/(2.*sampdens)+.5, |
| 311 |
< |
y/(2.*sampdens)+.5)); |
| 312 |
< |
/* central region */ |
| 313 |
< |
if (viewray(org, vd, &ourview, .5, y/(2.*sampdens)+.5) < 0) |
| 310 |
> |
(double)(x-hlim)/(2*sampdens)+.5, |
| 311 |
> |
(double)y/(2*sampdens)+.5)); |
| 312 |
> |
/* central region */ |
| 313 |
> |
/* avoid over-counting of poles */ |
| 314 |
> |
if (cury != y) { |
| 315 |
> |
err = 0.0; |
| 316 |
> |
cmpval = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); |
| 317 |
> |
cury = y; |
| 318 |
> |
} |
| 319 |
> |
err += cmpval; |
| 320 |
> |
if (err <= 0.5) |
| 321 |
|
return(-1); |
| 322 |
+ |
err -= 1.0; |
| 323 |
+ |
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
| 324 |
+ |
return(-1); |
| 325 |
|
spinvector(vd, vd, ourview.vup, h_theta(x)); |
| 326 |
|
return(0); |
| 327 |
|
} |
| 328 |
|
|
| 329 |
|
|
| 298 |
– |
spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ |
| 299 |
– |
FVECT vres, vorig, vnorm; |
| 300 |
– |
double theta; |
| 301 |
– |
{ |
| 302 |
– |
extern double sin(), cos(); |
| 303 |
– |
double sint, cost, dotp; |
| 304 |
– |
FVECT vperp; |
| 305 |
– |
register int i; |
| 306 |
– |
|
| 307 |
– |
sint = sin(theta); |
| 308 |
– |
cost = cos(theta); |
| 309 |
– |
dotp = DOT(vorig, vnorm); |
| 310 |
– |
fcross(vperp, vnorm, vorig); |
| 311 |
– |
for (i = 0; i < 3; i++) |
| 312 |
– |
vres[i] = vnorm[i]*dotp*(1.-cost) + |
| 313 |
– |
vorig[i]*cost + vperp[i]*sint; |
| 314 |
– |
} |
| 315 |
– |
|
| 316 |
– |
|
| 330 |
|
memerr(s) /* malloc failure */ |
| 331 |
|
char *s; |
| 332 |
|
{ |
| 333 |
< |
fprintf(stderr, "%s: out of memory for %s\n", s); |
| 333 |
> |
fprintf(stderr, "%s: out of memory for %s\n", progname, s); |
| 334 |
|
exit(1); |
| 335 |
|
} |
| 336 |
|
|
| 354 |
|
|
| 355 |
|
printf("BEGIN indirect illuminance\n"); |
| 356 |
|
for (i = 0; i < nglardirs; i++) |
| 357 |
< |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
| 358 |
< |
PI * indirect[i].sum / (double)indirect[i].n); |
| 357 |
> |
if (indirect[i].n > FTINY) |
| 358 |
> |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
| 359 |
> |
PI * indirect[i].sum / indirect[i].n); |
| 360 |
|
printf("END indirect illuminance\n"); |
| 361 |
|
} |