12 |
|
|
13 |
|
#include "glare.h" |
14 |
|
|
15 |
+ |
#include "random.h" |
16 |
+ |
|
17 |
|
#define FEQ(a,b) ((a)-(b)<=FTINY&&(a)-(b)<=FTINY) |
18 |
|
#define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ |
19 |
|
&&FEQ((v1)[2],(v2)[2])) |
21 |
|
char *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"}; |
22 |
|
int rtargc = 4; |
23 |
|
|
24 |
< |
VIEW ourview; /* our view */ |
24 |
> |
VIEW ourview = STDVIEW; /* our view */ |
25 |
|
VIEW pictview = STDVIEW; /* picture view */ |
26 |
|
VIEW leftview, rightview; /* leftmost and rightmost views */ |
27 |
|
|
31 |
|
int verbose = 0; /* verbose reporting */ |
32 |
|
char *progname; /* global argv[0] */ |
33 |
|
|
34 |
+ |
double threshold = 0.; /* glare threshold */ |
35 |
+ |
|
36 |
+ |
int sampdens = SAMPDENS; /* sample density */ |
37 |
|
ANGLE glarang[180] = {AEND}; /* glare calculation angles */ |
38 |
|
int nglarangs = 0; |
39 |
+ |
double maxtheta; /* maximum angle (in radians) */ |
40 |
|
int hsize; /* horizontal size */ |
41 |
|
int hlim; /* central limit of horizontal */ |
42 |
|
|
43 |
|
struct illum *indirect; /* array of indirect illuminances */ |
44 |
|
|
45 |
+ |
long npixinvw; /* number of pixels in view */ |
46 |
+ |
long npixmiss; /* number of pixels missed */ |
47 |
|
|
48 |
+ |
|
49 |
|
main(argc, argv) |
50 |
|
int argc; |
51 |
|
char *argv[]; |
64 |
|
continue; |
65 |
|
} |
66 |
|
switch (argv[i][1]) { |
67 |
+ |
case 't': |
68 |
+ |
threshold = atof(argv[++i]); |
69 |
+ |
break; |
70 |
+ |
case 'r': |
71 |
+ |
sampdens = atoi(argv[++i])/2; |
72 |
+ |
break; |
73 |
|
case 'v': |
74 |
|
if (argv[i][2] == '\0') { |
75 |
|
verbose++; |
178 |
|
exit(1); |
179 |
|
} |
180 |
|
init(); /* initialize program */ |
181 |
< |
comp_thresh(); /* compute glare threshold */ |
181 |
> |
if (threshold <= FTINY) |
182 |
> |
comp_thresh(); /* compute glare threshold */ |
183 |
|
analyze(); /* analyze view */ |
184 |
|
cleanup(); /* tidy up */ |
185 |
|
/* print header */ |
209 |
|
/* set direction vectors */ |
210 |
|
for (i = 0; glarang[i] != AEND; i++) |
211 |
|
; |
212 |
< |
if (glarang[0] <= 0 || glarang[i-1] >= 180) { |
212 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
213 |
|
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
214 |
|
progname); |
215 |
|
exit(1); |
216 |
|
} |
217 |
|
nglarangs = i; |
218 |
|
/* nglardirs = 2*nglarangs + 1; */ |
219 |
< |
/* maxtheta = (PI/180.)*glarang[nglarangs-1]; */ |
220 |
< |
/* vsize = SAMPDENS; */ |
221 |
< |
hlim = SAMPDENS*maxtheta; |
222 |
< |
hsize = SAMPDENS + hlim; |
223 |
< |
if (hsize > (int)(PI*SAMPDENS)) |
224 |
< |
hsize = PI*SAMPDENS; |
219 |
> |
/* vsize = sampdens - 1; */ |
220 |
> |
if (nglarangs > 0) |
221 |
> |
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
222 |
> |
else |
223 |
> |
maxtheta = 0.0; |
224 |
> |
hlim = sampdens*maxtheta; |
225 |
> |
hsize = hlim + sampdens - 1; |
226 |
> |
if (hsize > (int)(PI*sampdens)) |
227 |
> |
hsize = PI*sampdens; |
228 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
229 |
|
if (indirect == NULL) |
230 |
|
memerr("indirect illuminances"); |
231 |
+ |
npixinvw = npixmiss = 0L; |
232 |
|
copystruct(&leftview, &ourview); |
233 |
|
copystruct(&rightview, &ourview); |
234 |
< |
spinvector(leftview.vdir, ourview.vdir, ourview.vup, -maxtheta); |
235 |
< |
spinvector(rightview.vdir, ourview.vdir, ourview.vup, maxtheta); |
234 |
> |
spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); |
235 |
> |
spinvector(rightview.vdir, ourview.vdir, ourview.vup, -maxtheta); |
236 |
|
setview(&leftview); |
237 |
|
setview(&rightview); |
238 |
|
indirect[nglarangs].lcos = |
239 |
|
indirect[nglarangs].rcos = cos(maxtheta); |
240 |
< |
indirect[nglarangs].lsin = |
241 |
< |
-(indirect[nglarangs].rsin = sin(maxtheta)); |
240 |
> |
indirect[nglarangs].rsin = |
241 |
> |
-(indirect[nglarangs].lsin = sin(maxtheta)); |
242 |
|
indirect[nglarangs].theta = 0.0; |
243 |
|
for (i = 0; i < nglarangs; i++) { |
244 |
|
d = (glarang[nglarangs-1] - glarang[i])*(PI/180.); |
245 |
|
indirect[nglarangs-i-1].lcos = |
246 |
|
indirect[nglarangs+i+1].rcos = cos(d); |
247 |
< |
indirect[nglarangs-i-1].lsin = |
248 |
< |
-(indirect[nglarangs+i+1].rsin = sin(d)); |
247 |
> |
indirect[nglarangs+i+1].rsin = |
248 |
> |
-(indirect[nglarangs-i-1].lsin = sin(d)); |
249 |
|
d = (glarang[nglarangs-1] + glarang[i])*(PI/180.); |
250 |
|
indirect[nglarangs-i-1].rcos = |
251 |
|
indirect[nglarangs+i+1].lcos = cos(d); |
252 |
< |
indirect[nglarangs+i+1].lsin = |
253 |
< |
-(indirect[nglarangs-i-1].rsin = sin(d)); |
254 |
< |
indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i]; |
255 |
< |
indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i]; |
252 |
> |
indirect[nglarangs-i-1].rsin = |
253 |
> |
-(indirect[nglarangs+i+1].lsin = sin(d)); |
254 |
> |
indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i]; |
255 |
> |
indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i]; |
256 |
|
} |
257 |
|
/* open picture */ |
258 |
|
if (picture != NULL) { |
282 |
|
close_pict(); |
283 |
|
if (octree != NULL) |
284 |
|
done_rtrace(); |
285 |
+ |
if (npixinvw < 100*npixmiss) |
286 |
+ |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
287 |
+ |
progname, 100L*npixmiss/npixinvw); |
288 |
|
} |
289 |
|
|
290 |
|
|
292 |
|
FVECT vd; |
293 |
|
int x, y; |
294 |
|
{ |
295 |
+ |
long t; |
296 |
|
FVECT org; /* dummy variable */ |
297 |
|
|
298 |
|
if (x <= -hlim) /* left region */ |
299 |
|
return(viewray(org, vd, &leftview, |
300 |
< |
(x+hlim)/(2.*SAMPDENS)+.5, |
301 |
< |
y/(2.*SAMPDENS)+.5)); |
300 |
> |
(double)(x+hlim)/(2*sampdens)+.5, |
301 |
> |
(double)y/(2*sampdens)+.5)); |
302 |
|
if (x >= hlim) /* right region */ |
303 |
|
return(viewray(org, vd, &rightview, |
304 |
< |
(x-hlim)/(2.*SAMPDENS)+.5, |
305 |
< |
y/(2.*SAMPDENS)+.5)); |
306 |
< |
/* central region */ |
307 |
< |
if (viewray(org, vd, &ourview, .5, y/(2.*SAMPDENS)+.5) < 0) |
304 |
> |
(double)(x-hlim)/(2*sampdens)+.5, |
305 |
> |
(double)y/(2*sampdens)+.5)); |
306 |
> |
/* 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); |
311 |
+ |
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
312 |
+ |
return(-1); |
313 |
|
spinvector(vd, vd, ourview.vup, h_theta(x)); |
314 |
|
return(0); |
315 |
|
} |
316 |
|
|
317 |
|
|
290 |
– |
spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ |
291 |
– |
FVECT vres, vorig, vnorm; |
292 |
– |
double theta; |
293 |
– |
{ |
294 |
– |
extern double sin(), cos(); |
295 |
– |
double sint, cost, dotp; |
296 |
– |
FVECT vperp; |
297 |
– |
register int i; |
298 |
– |
|
299 |
– |
sint = sin(theta); |
300 |
– |
cost = cos(theta); |
301 |
– |
dotp = DOT(vorig, vnorm); |
302 |
– |
fcross(vperp, vnorm, vorig); |
303 |
– |
for (i = 0; i < 3; i++) |
304 |
– |
vres[i] = vnorm[i]*dotp*(1.-cost) + |
305 |
– |
vorig[i]*cost + vperp[i]*sint; |
306 |
– |
} |
307 |
– |
|
308 |
– |
|
318 |
|
memerr(s) /* malloc failure */ |
319 |
|
char *s; |
320 |
|
{ |
321 |
< |
fprintf(stderr, "%s: out of memory for %s\n", s); |
321 |
> |
fprintf(stderr, "%s: out of memory for %s\n", progname, s); |
322 |
|
exit(1); |
323 |
|
} |
324 |
|
|
342 |
|
|
343 |
|
printf("BEGIN indirect illuminance\n"); |
344 |
|
for (i = 0; i < nglardirs; i++) |
345 |
< |
printf("\t%f\t%f\n", (180.0/PI)*indirect[i].theta, |
346 |
< |
PI * indirect[i].sum / (double)indirect[i].n); |
347 |
< |
printf("END indirect illuminances\n"); |
345 |
> |
if (indirect[i].n > FTINY) |
346 |
> |
printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, |
347 |
> |
PI * indirect[i].sum / indirect[i].n); |
348 |
> |
printf("END indirect illuminance\n"); |
349 |
|
} |