| 53 |
|
|
| 54 |
|
VIEW midview = STDVIEW; |
| 55 |
|
|
| 56 |
+ |
int wrongformat = 0; |
| 57 |
|
|
| 58 |
+ |
|
| 59 |
|
main(argc, argv) |
| 60 |
|
int argc; |
| 61 |
|
char *argv[]; |
| 91 |
|
exit(1); |
| 92 |
|
} |
| 93 |
|
/* read header */ |
| 94 |
< |
getheader(stdin, headline); |
| 94 |
> |
getheader(stdin, headline, NULL); |
| 95 |
> |
if (wrongformat) { |
| 96 |
> |
fprintf(stderr, "%s: bad input format\n", progname); |
| 97 |
> |
exit(1); |
| 98 |
> |
} |
| 99 |
|
if (print_header) { /* add to header */ |
| 100 |
|
printargs(i, argv, stdout); |
| 101 |
|
putchar('\n'); |
| 102 |
|
} |
| 103 |
|
/* set view */ |
| 104 |
|
if (setview(&midview) != NULL) { |
| 105 |
< |
fprintf(stderr, "%s: bad view information in input\n"); |
| 105 |
> |
fprintf(stderr, "%s: bad view information in input\n", |
| 106 |
> |
progname); |
| 107 |
|
exit(1); |
| 108 |
|
} |
| 109 |
|
/* get findglare data */ |
| 126 |
|
headline(s) /* get line from header */ |
| 127 |
|
char *s; |
| 128 |
|
{ |
| 129 |
+ |
char fmt[32]; |
| 130 |
+ |
|
| 131 |
|
if (print_header) /* copy to output */ |
| 132 |
|
fputs(s, stdout); |
| 133 |
|
if (!strncmp(s, VIEWSTR, VIEWSTRL)) |
| 134 |
|
sscanview(&midview, s+VIEWSTRL); |
| 135 |
+ |
else if (isformat(s)) { |
| 136 |
+ |
formatval(fmt, s); |
| 137 |
+ |
wrongformat = strcmp(fmt, "ascii"); |
| 138 |
+ |
} |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 239 |
|
* All vectors are assumed to be normalized. |
| 240 |
|
* This function is an implementation of the method proposed by |
| 241 |
|
* Robert Levin in his 1975 JIES article. |
| 242 |
+ |
* This calculation presumes the view direction and up vectors perpendicular. |
| 243 |
|
* We return a value less than zero for improper positions. |
| 244 |
|
*/ |
| 245 |
|
|
| 253 |
|
d = DOT(sd,vd); |
| 254 |
|
if (d <= 0.0) |
| 255 |
|
return(-1.0); |
| 256 |
+ |
if (d >= 1.0) |
| 257 |
+ |
return(1.0); |
| 258 |
|
sigma = acos(d) * (180./PI); |
| 259 |
< |
tau = acos(DOT(sd,vu)/sqrt(1.0-d*d)) * (180./PI); |
| 259 |
> |
d = DOT(sd,vu)/sqrt(1.0-d*d); |
| 260 |
> |
if (d >= 1.0) |
| 261 |
> |
tau = 0.0; |
| 262 |
> |
else |
| 263 |
> |
tau = acos(d) * (180./PI); |
| 264 |
|
return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3 |
| 265 |
|
+ sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 ) |
| 266 |
|
) ); |
| 275 |
|
register struct glare_src *gs; |
| 276 |
|
double p; |
| 277 |
|
double sum; |
| 278 |
+ |
double wtot, brsum; |
| 279 |
|
int n; |
| 280 |
|
|
| 281 |
< |
sum = 0.0; n = 0; |
| 281 |
> |
sum = wtot = brsum = 0.0; n = 0; |
| 282 |
|
for (gs = all_srcs; gs != NULL; gs = gs->next) { |
| 283 |
|
p = posindex(gs->dir, midview.vdir, midview.vup); |
| 284 |
|
if (p <= FTINY) |
| 285 |
|
continue; |
| 286 |
|
sum += gs->lum * q(gs->dom) / p; |
| 287 |
+ |
brsum += gs->lum * gs->dom; |
| 288 |
+ |
wtot += gs->dom; |
| 289 |
|
n++; |
| 290 |
|
} |
| 291 |
|
if (n == 0) |
| 292 |
|
return(0.0); |
| 293 |
|
else |
| 294 |
|
return( pow( |
| 295 |
< |
.5*sum/pow(direct(gd)+gd->indirect,.44), |
| 295 |
> |
.5*sum/pow((brsum+(5.-wtot)*gd->indirect/PI)/5.,.44), |
| 296 |
|
pow((double)n, -.0914) ) ); |
| 297 |
|
#undef q |
| 298 |
|
} |
| 311 |
|
guth_vcp(gd) /* compute Guth visual comfort probability */ |
| 312 |
|
struct glare_dir *gd; |
| 313 |
|
{ |
| 314 |
< |
return(100.*norm_integral(-6.374+1.3227*log(guth_dgr(gd)))); |
| 314 |
> |
return(100.*norm_integral(6.374-1.3227*log(guth_dgr(gd)))); |
| 315 |
|
} |