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 2.13 by greg, Thu Aug 2 18:33:50 2018 UTC vs.
Revision 2.14 by greg, Mon Feb 17 19:19:45 2020 UTC

# Line 164 | Line 164 | headline(                      /* get line from header */
164   static void
165   init(void)                              /* initialize calculation */
166   {
167 +        char    *err;
168                                          /* read header */
169          getheader(stdin, headline, NULL);
170          if (wrongformat) {
# Line 171 | Line 172 | init(void)                             /* initialize calculation */
172                  exit(1);
173          }
174                                          /* set view */
175 <        if (setview(&midview) != NULL) {
176 <                fprintf(stderr, "%s: bad view information in input\n",
175 >        if ((err = setview(&midview)) != NULL) {
176 >                fprintf(stderr, "%s: %s\n",
177 >                                progname, err);
178 >                exit(1);
179 >        }
180 >        if (fabs(DOT(midview.vdir, midview.vup)) > 1e-4) {
181 >                fprintf(stderr,
182 >                "%s: Input view direction not perpendicular to up vector\n",
183                                  progname);
184                  exit(1);
185          }
# Line 319 | Line 326 | posindex(                      /* compute position index */
326          d = DOT(sd,vd);
327          if (d <= 0.0)
328                  return(-1.0);
329 <        if (d >= 1.0)
329 >        if (d >= 1.0-FTINY)
330                  return(1.0);
331          sigma = acos(d) * (180./PI);
332          d = fabs(DOT(sd,vu)/sqrt(1.0-d*d));
333 <        if (d >= 1.0)
327 <                tau = 0.0;
328 <        else
329 <                tau = acos(d) * (180./PI);
333 >        tau = Acos(d) * (180./PI);
334          return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3
335                          + sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 )
336                  ) );
# Line 341 | Line 345 | dgi(           /* compute Daylight Glare Index */
345          struct glare_src        *gs;
346          FVECT   mydir,testdir[7],vhor;
347          double  r,posn,omega,p[7],sum;
348 <        int     i,n;
348 >        int     i;
349  
350          spinvector(mydir, midview.vdir, midview.vup, gd->ang);
351 <        sum = 0.0; n = 0;
351 >        sum = 0.0;
352          for (gs = all_srcs; gs != NULL; gs = gs->next) {
353  
354                  /* compute 1/p^2 weighted solid angle of the source */
355 <                r = sqrt(1 - pow(1.-gs->dom/2./PI,2.));
355 >                r = 1. - gs->dom*(.5/PI);
356 >                r = sqrt(1. - r*r);
357                  fcross(vhor,gs->dir,midview.vup);
358 <                normalize(vhor);
358 >                if (normalize(vhor) == 0.)
359 >                        continue;
360                  VCOPY(testdir[0],gs->dir);
361                  fvsum(testdir[1],gs->dir,vhor,r);
362                  fvsum(testdir[2],gs->dir,vhor,0.5*r);
# Line 361 | Line 367 | dgi(           /* compute Daylight Glare Index */
367                  fvsum(testdir[6],testdir[4],midview.vup,0.866*r);
368                  fvsum(testdir[4],testdir[4],midview.vup,-0.866*r);
369                  for (i = 0; i < 7; i++) {
370 <                        normalize(testdir[i]);
370 >                        p[i] = 0.0;
371 >                        if (normalize(testdir[i]) == 0.)
372 >                                continue;
373                          posn = posindex(testdir[i],mydir,midview.vup);
374 <                        if (posn <= FTINY)
367 <                                p[i] = 0.0;
368 <                        else
374 >                        if (posn > FTINY)
375                                  p[i] = 1./(posn*posn);
376                  }
377 <                r = 1-gs->dom/2./PI;
377 >                r = 1. - gs->dom*(.5/PI);
378                  omega = gs->dom*p[0];
379 <                omega += (r*PI*(1+1/r/r)-2*PI)*(-p[0]+(p[1]+p[2])*0.5);
380 <                omega += (2*PI-r*PI*(1+1/r/r))*(-p[0]-0.1667*(p[1]+p[3])
379 >                omega += (r*PI*(1.+1./(r*r))-2.*PI)*(-p[0]+(p[1]+p[2])*0.5);
380 >                omega += (2.*PI-r*PI*(1.+1./(r*r)))*(-p[0]-0.1667*(p[1]+p[3])
381                            +0.3334*(p[2]+p[4]+p[5]+p[6]));
382 <
382 >                if (omega <= 0.)
383 >                        omega = 0.;
384                  sum += pow(gs->lum,1.6) * pow(omega,0.8) /
385 <                       (gd->indirect/PI + 0.07*sqrt(gs->dom)*gs->lum);
379 <                n++;
385 >                       (gd->indirect*(1./PI) + 0.07*sqrt(gs->dom)*gs->lum);
386          }
387 <        if (n == 0)
387 >        if (sum <= FTINY)
388                  return(0.0);
389 <        return( 10*log10(0.478*sum) );
389 >        return( 10.*log10(0.478*sum) );
390   }
391  
392  
# Line 404 | Line 410 | brs_gi(                /* compute BRS Glare Index */
410          }
411          if (sum <= FTINY)
412                  return(0.0);
413 <        sum /= gd->indirect/PI;
413 >        sum *= PI/gd->indirect;
414          return(10*log10(0.478*sum));
415   }
416  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines