ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/glarendx.c
(Generate patch)

Comparing ray/src/util/glarendx.c (file contents):
Revision 1.1 by greg, Tue Apr 16 16:40:22 1991 UTC vs.
Revision 1.8 by greg, Thu May 2 13:17:41 1991 UTC

# Line 7 | Line 7 | static char SCCSid[] = "$SunId$ LBL";
7   /*
8   * Compute Glare Index given by program name:
9   *
10 < *      gnuth_dgr -     Gnuth discomfort glare rating
11 < *      gnuth_vcp -     Gnuth visual comfort probability
10 > *      guth_dgr -      Guth discomfort glare rating
11 > *      guth_vcp -      Guth visual comfort probability
12 > *      cie_cgi -       CIE Glare Index (1983)
13   *
14   *              12 April 1991   Greg Ward       EPFL
15   */
# Line 21 | Line 22 | extern double  erfc();
22   double  posindex();
23   int     headline();
24  
25 < double  direct(), gnuth_dgr(), gnuth_vcp();
25 > double  direct(), guth_dgr(), guth_vcp(), cie_cgi();
26  
27   struct named_func {
28          char    *name;
29          double  (*func)();
30   } all_funcs[] = {
31          {"direct", direct},
32 <        {"gnuth_dgr", gnuth_dgr},
33 <        {"gnuth_vcp", gnuth_vcp},
32 >        {"guth_dgr", guth_dgr},
33 >        {"guth_vcp", guth_vcp},
34 >        {"cie_cgi", cie_cgi},
35          {NULL}
36   };
37  
# Line 53 | Line 55 | int    print_header = 1;
55  
56   VIEW    midview = STDVIEW;
57  
58 + int     wrongformat = 0;
59  
60 +
61   main(argc, argv)
62   int     argc;
63   char    *argv[];
# Line 89 | Line 93 | char   *argv[];
93                          exit(1);
94                  }
95                                          /* read header */
96 <        getheader(stdin, headline);
96 >        getheader(stdin, headline, NULL);
97 >        if (wrongformat) {
98 >                fprintf(stderr, "%s: bad input format\n", progname);
99 >                exit(1);
100 >        }
101          if (print_header) {             /* add to header */
102                  printargs(i, argv, stdout);
103                  putchar('\n');
104          }
105                                          /* set view */
106          if (setview(&midview) != NULL) {
107 <                fprintf(stderr, "%s: bad view information in input\n");
107 >                fprintf(stderr, "%s: bad view information in input\n",
108 >                                progname);
109                  exit(1);
110          }
111                                          /* get findglare data */
# Line 119 | Line 128 | userr:
128   headline(s)                     /* get line from header */
129   char    *s;
130   {
131 +        char    fmt[32];
132 +
133          if (print_header)               /* copy to output */
134                  fputs(s, stdout);
135          if (!strncmp(s, VIEWSTR, VIEWSTRL))
136                  sscanview(&midview, s+VIEWSTRL);
137 +        else if (isformat(s)) {
138 +                formatval(fmt, s);
139 +                wrongformat = strcmp(fmt, "ascii");
140 +        }
141   }
142  
143  
# Line 155 | Line 170 | read_input()                   /* read glare sources from stdin */
170                                          &gs->dir[0], &gs->dir[1], &gs->dir[2],
171                                          &gs->dom, &gs->lum) != 5)
172                                  goto readerr;
173 +                        normalize(gs->dir);
174                          gs->next = all_srcs;
175                          all_srcs = gs;
176                          break;
# Line 225 | Line 241 | struct glare_dir       *gd;
241   * All vectors are assumed to be normalized.
242   * This function is an implementation of the method proposed by
243   * Robert Levin in his 1975 JIES article.
244 + * This calculation presumes the view direction and up vectors perpendicular.
245   * We return a value less than zero for improper positions.
246   */
247  
# Line 238 | Line 255 | FVECT  sd, vd, vu;
255          d = DOT(sd,vd);
256          if (d <= 0.0)
257                  return(-1.0);
258 +        if (d >= 1.0)
259 +                return(1.0);
260          sigma = acos(d) * (180./PI);
261 <        tau = acos(DOT(sd,vu)/sqrt(1.0-d*d)) * (180./PI);
261 >        d = DOT(sd,vu)/sqrt(1.0-d*d);
262 >        if (d >= 1.0)
263 >                tau = 0.0;
264 >        else
265 >                tau = acos(d) * (180./PI);
266          return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3
267                          + sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 )
268                  ) );
# Line 247 | Line 270 | FVECT  sd, vd, vu;
270  
271  
272   double
273 < gnuth_dgr(gd)           /* compute Gnuth discomfort glare rating */
273 > guth_dgr(gd)            /* compute Guth discomfort glare rating */
274   struct glare_dir        *gd;
275   {
276   #define q(w)    (20.4*w+1.52*pow(w,.2)-.075)
277          register struct glare_src       *gs;
278 +        FVECT   mydir;
279          double  p;
280          double  sum;
281 +        double  wtot, brsum;
282          int     n;
283  
284 <        sum = 0.0; n = 0;
284 >        spinvector(mydir, midview.vdir, midview.vup, gd->ang);
285 >        sum = wtot = brsum = 0.0; n = 0;
286          for (gs = all_srcs; gs != NULL; gs = gs->next) {
287 <                p = posindex(gs->dir, midview.vdir, midview.vup);
287 >                p = posindex(gs->dir, mydir, midview.vup);
288                  if (p <= FTINY)
289                          continue;
290                  sum += gs->lum * q(gs->dom) / p;
291 +                brsum += gs->lum * gs->dom;
292 +                wtot += gs->dom;
293                  n++;
294          }
295          if (n == 0)
296                  return(0.0);
297 <        else
298 <                return( pow(
271 <                        .5*sum/pow(direct(gd)+gd->indirect,.44),
297 >
298 >        return( pow(.5*sum/pow((brsum+(5.-wtot)*gd->indirect/PI)/5.,.44),
299                          pow((double)n, -.0914) ) );
300   #undef q
301   }
# Line 284 | Line 311 | extern double  erf(), erfc();
311  
312  
313   double
314 < gnuth_vcp(gd)           /* compute Gnuth visual comfort probability */
314 > guth_vcp(gd)            /* compute Guth visual comfort probability */
315   struct glare_dir        *gd;
316   {
317 <        return(100.*norm_integral(-6.374+1.3227*log(gnuth_dgr(gd))));
317 >        double  dgr;
318 >
319 >        dgr = guth_dgr(gd);
320 >        if (dgr <= FTINY)
321 >                return(100.0);
322 >        return(100.*norm_integral(6.374-1.3227*log(dgr)));
323 > }
324 >
325 >
326 > double
327 > cie_cgi(gd)             /* compute CIE Glare Index */
328 > struct glare_dir        *gd;
329 > {
330 >        register struct glare_src       *gs;
331 >        FVECT   mydir;
332 >        double  dillum;
333 >        double  p;
334 >        double  sum;
335 >
336 >        spinvector(mydir, midview.vdir, midview.vup, gd->ang);
337 >        sum = 0.0;
338 >        for (gs = all_srcs; gs != NULL; gs = gs->next) {
339 >                p = posindex(gs->dir, mydir, midview.vup);
340 >                if (p <= FTINY)
341 >                        continue;
342 >                sum += gs->lum*gs->lum * gs->dom / (p*p);
343 >        }
344 >        if (sum <= FTINY)
345 >                return(0.0);
346 >        dillum = direct(gd);
347 >        return(8.*log10(2.*sum*(1.+dillum/500.)/(dillum+gd->indirect)));
348   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines