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; |
37 |
|
double maxtheta; /* maximum angle (in radians) */ |
38 |
|
int hsize; /* horizontal size */ |
37 |
– |
int hlim; /* central limit of horizontal */ |
39 |
|
|
40 |
|
struct illum *indirect; /* array of indirect illuminances */ |
41 |
|
|
42 |
+ |
long npixinvw; /* number of pixels in view */ |
43 |
+ |
long npixmiss; /* number of pixels missed */ |
44 |
|
|
45 |
+ |
|
46 |
|
main(argc, argv) |
47 |
|
int argc; |
48 |
|
char *argv[]; |
49 |
|
{ |
50 |
+ |
int combine = 1; |
51 |
|
int gotview = 0; |
52 |
|
int rval, i; |
53 |
|
char *err; |
62 |
|
continue; |
63 |
|
} |
64 |
|
switch (argv[i][1]) { |
65 |
+ |
case 't': |
66 |
+ |
threshold = atof(argv[++i]); |
67 |
+ |
break; |
68 |
|
case 'r': |
69 |
|
sampdens = atoi(argv[++i])/2; |
70 |
|
break; |
101 |
|
case 'p': |
102 |
|
picture = argv[++i]; |
103 |
|
break; |
104 |
+ |
case 'c': |
105 |
+ |
combine = !combine; |
106 |
+ |
break; |
107 |
|
case 'd': |
108 |
|
case 'l': |
109 |
|
rtargv[rtargc++] = argv[i]; |
179 |
|
exit(1); |
180 |
|
} |
181 |
|
init(); /* initialize program */ |
182 |
< |
comp_thresh(); /* compute glare threshold */ |
182 |
> |
if (threshold <= FTINY) |
183 |
> |
comp_thresh(); /* compute glare threshold */ |
184 |
|
analyze(); /* analyze view */ |
185 |
+ |
if (combine) |
186 |
+ |
absorb_specks(); /* eliminate tiny sources */ |
187 |
|
cleanup(); /* tidy up */ |
188 |
|
/* print header */ |
189 |
|
printargs(argc, argv, stdout); |
190 |
|
fputs(VIEWSTR, stdout); |
191 |
|
fprintview(&ourview, stdout); |
192 |
< |
printf("\n\n"); |
192 |
> |
printf("\n"); |
193 |
> |
fputformat("ascii", stdout); |
194 |
> |
printf("\n"); |
195 |
|
printsources(); /* print glare sources */ |
196 |
|
printillum(); /* print illuminances */ |
197 |
|
exit(0); |
214 |
|
/* set direction vectors */ |
215 |
|
for (i = 0; glarang[i] != AEND; i++) |
216 |
|
; |
217 |
< |
if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) { |
217 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
218 |
|
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
219 |
|
progname); |
220 |
|
exit(1); |
221 |
|
} |
222 |
|
nglarangs = i; |
223 |
|
/* nglardirs = 2*nglarangs + 1; */ |
224 |
< |
/* vsize = sampdens; */ |
224 |
> |
/* vsize = sampdens - 1; */ |
225 |
|
if (nglarangs > 0) |
226 |
|
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
227 |
|
else |
228 |
|
maxtheta = 0.0; |
229 |
< |
hlim = sampdens*maxtheta; |
214 |
< |
hsize = sampdens + hlim; |
229 |
> |
hsize = hlim(0) + 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) { |
281 |
|
cleanup() /* close files, wait for children */ |
282 |
|
{ |
283 |
|
if (verbose) |
284 |
< |
fprintf(stderr, "%s: cleaning up...\n", progname); |
284 |
> |
fprintf(stderr, "%s: cleaning up... \n", progname); |
285 |
|
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 |
+ |
int hl; |
300 |
|
FVECT org; /* dummy variable */ |
301 |
|
|
302 |
< |
if (x <= -hlim) /* left region */ |
302 |
> |
hl = hlim(y); |
303 |
> |
if (x <= -hl) /* left region */ |
304 |
|
return(viewray(org, vd, &leftview, |
305 |
< |
(x+hlim)/(2.*sampdens)+.5, |
306 |
< |
y/(2.*sampdens)+.5)); |
307 |
< |
if (x >= hlim) /* right region */ |
305 |
> |
(double)(x+hl)/(2*sampdens)+.5, |
306 |
> |
(double)y/(2*sampdens)+.5)); |
307 |
> |
if (x >= hl) /* right region */ |
308 |
|
return(viewray(org, vd, &rightview, |
309 |
< |
(x-hlim)/(2.*sampdens)+.5, |
310 |
< |
y/(2.*sampdens)+.5)); |
311 |
< |
/* central region */ |
312 |
< |
if (viewray(org, vd, &ourview, .5, y/(2.*sampdens)+.5) < 0) |
309 |
> |
(double)(x-hl)/(2*sampdens)+.5, |
310 |
> |
(double)y/(2*sampdens)+.5)); |
311 |
> |
/* central region */ |
312 |
> |
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
313 |
|
return(-1); |
314 |
< |
spinvector(vd, vd, ourview.vup, h_theta(x)); |
314 |
> |
spinvector(vd, vd, ourview.vup, h_theta(x,y)); |
315 |
|
return(0); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
< |
spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ |
320 |
< |
FVECT vres, vorig, vnorm; |
321 |
< |
double theta; |
319 |
> |
double |
320 |
> |
pixsize(x, y) /* return the solid angle of pixel at (x,y) */ |
321 |
> |
int x, y; |
322 |
|
{ |
323 |
< |
extern double sin(), cos(); |
324 |
< |
double sint, cost, dotp; |
325 |
< |
FVECT vperp; |
326 |
< |
register int i; |
327 |
< |
|
328 |
< |
sint = sin(theta); |
329 |
< |
cost = cos(theta); |
330 |
< |
dotp = DOT(vorig, vnorm); |
331 |
< |
fcross(vperp, vnorm, vorig); |
332 |
< |
for (i = 0; i < 3; i++) |
333 |
< |
vres[i] = vnorm[i]*dotp*(1.-cost) + |
334 |
< |
vorig[i]*cost + vperp[i]*sint; |
323 |
> |
register int hl, xo; |
324 |
> |
double disc; |
325 |
> |
|
326 |
> |
hl = hlim(y); |
327 |
> |
if (x < -hl) |
328 |
> |
xo = x+hl; |
329 |
> |
else if (x > hl) |
330 |
> |
xo = x-hl; |
331 |
> |
else |
332 |
> |
xo = 0; |
333 |
> |
disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); |
334 |
> |
if (disc <= FTINY) |
335 |
> |
return(0.); |
336 |
> |
return(1./(sampdens*sampdens*sqrt(disc))); |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
|
memerr(s) /* malloc failure */ |
341 |
|
char *s; |
342 |
|
{ |
343 |
< |
fprintf(stderr, "%s: out of memory for %s\n", s); |
343 |
> |
fprintf(stderr, "%s: out of memory for %s\n", progname, s); |
344 |
|
exit(1); |
345 |
|
} |
346 |
|
|
364 |
|
|
365 |
|
printf("BEGIN indirect illuminance\n"); |
366 |
|
for (i = 0; i < nglardirs; i++) |
367 |
< |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
368 |
< |
PI * indirect[i].sum / (double)indirect[i].n); |
367 |
> |
if (indirect[i].n > FTINY) |
368 |
> |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
369 |
> |
PI * indirect[i].sum / indirect[i].n); |
370 |
|
printf("END indirect illuminance\n"); |
371 |
|
} |