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); |
191 |
|
fputs(VIEWSTR, stdout); |
192 |
|
fprintview(&ourview, stdout); |
193 |
< |
printf("\n\n"); |
193 |
> |
printf("\n"); |
194 |
> |
fputformat("ASCII", stdout); |
195 |
> |
printf("\n"); |
196 |
|
printsources(); /* print glare sources */ |
197 |
|
printillum(); /* print illuminances */ |
198 |
|
exit(0); |
215 |
|
/* set direction vectors */ |
216 |
|
for (i = 0; glarang[i] != AEND; i++) |
217 |
|
; |
218 |
< |
if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) { |
218 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
219 |
|
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
220 |
|
progname); |
221 |
|
exit(1); |
234 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
235 |
|
if (indirect == NULL) |
236 |
|
memerr("indirect illuminances"); |
237 |
+ |
npixinvw = npixmiss = 0L; |
238 |
|
copystruct(&leftview, &ourview); |
239 |
|
copystruct(&rightview, &ourview); |
240 |
|
spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); |
243 |
|
setview(&rightview); |
244 |
|
indirect[nglarangs].lcos = |
245 |
|
indirect[nglarangs].rcos = cos(maxtheta); |
246 |
< |
indirect[nglarangs].lsin = |
247 |
< |
-(indirect[nglarangs].rsin = sin(maxtheta)); |
246 |
> |
indirect[nglarangs].rsin = |
247 |
> |
-(indirect[nglarangs].lsin = sin(maxtheta)); |
248 |
|
indirect[nglarangs].theta = 0.0; |
249 |
|
for (i = 0; i < nglarangs; i++) { |
250 |
|
d = (glarang[nglarangs-1] - glarang[i])*(PI/180.); |
251 |
|
indirect[nglarangs-i-1].lcos = |
252 |
|
indirect[nglarangs+i+1].rcos = cos(d); |
253 |
< |
indirect[nglarangs-i-1].lsin = |
254 |
< |
-(indirect[nglarangs+i+1].rsin = sin(d)); |
253 |
> |
indirect[nglarangs+i+1].rsin = |
254 |
> |
-(indirect[nglarangs-i-1].lsin = sin(d)); |
255 |
|
d = (glarang[nglarangs-1] + glarang[i])*(PI/180.); |
256 |
|
indirect[nglarangs-i-1].rcos = |
257 |
|
indirect[nglarangs+i+1].lcos = cos(d); |
258 |
< |
indirect[nglarangs+i+1].lsin = |
259 |
< |
-(indirect[nglarangs-i-1].rsin = sin(d)); |
260 |
< |
indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i]; |
261 |
< |
indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i]; |
258 |
> |
indirect[nglarangs-i-1].rsin = |
259 |
> |
-(indirect[nglarangs+i+1].lsin = sin(d)); |
260 |
> |
indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i]; |
261 |
> |
indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i]; |
262 |
|
} |
263 |
|
/* open picture */ |
264 |
|
if (picture != NULL) { |
283 |
|
cleanup() /* close files, wait for children */ |
284 |
|
{ |
285 |
|
if (verbose) |
286 |
< |
fprintf(stderr, "%s: cleaning up...\n", progname); |
286 |
> |
fprintf(stderr, "%s: cleaning up... \n", progname); |
287 |
|
if (picture != NULL) |
288 |
|
close_pict(); |
289 |
|
if (octree != NULL) |
290 |
|
done_rtrace(); |
291 |
+ |
if (npixinvw < 100*npixmiss) |
292 |
+ |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
293 |
+ |
progname, 100L*npixmiss/npixinvw); |
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
< |
compdir(vd, x, y) /* compute direction for x,y */ |
297 |
> |
compdir(vd, x, y, se) /* compute direction for x,y */ |
298 |
|
FVECT vd; |
299 |
|
int x, y; |
300 |
+ |
SPANERR *se; |
301 |
|
{ |
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 |
> |
if (se != NULL) { /* avoid over-counting of poles */ |
314 |
> |
se->err += se->prob; |
315 |
> |
if (se->err <= 0.5) |
316 |
> |
return(-1); |
317 |
> |
se->err -= 1.0; |
318 |
> |
} |
319 |
> |
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
320 |
|
return(-1); |
321 |
|
spinvector(vd, vd, ourview.vup, h_theta(x)); |
322 |
|
return(0); |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
+ |
setspanerr(se, y) /* initialize span error at y */ |
327 |
+ |
register SPANERR *se; |
328 |
+ |
int y; |
329 |
+ |
{ |
330 |
+ |
se->err = 0.0; |
331 |
+ |
se->prob = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); |
332 |
+ |
} |
333 |
+ |
|
334 |
+ |
|
335 |
|
memerr(s) /* malloc failure */ |
336 |
|
char *s; |
337 |
|
{ |
359 |
|
|
360 |
|
printf("BEGIN indirect illuminance\n"); |
361 |
|
for (i = 0; i < nglardirs; i++) |
362 |
< |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
363 |
< |
PI * indirect[i].sum / (double)indirect[i].n); |
362 |
> |
if (indirect[i].n > FTINY) |
363 |
> |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
364 |
> |
PI * indirect[i].sum / indirect[i].n); |
365 |
|
printf("END indirect illuminance\n"); |
366 |
|
} |