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.12 by greg, Mon Apr 2 16:45:41 2018 UTC vs.
Revision 2.16 by greg, Fri Jul 24 16:58:16 2020 UTC

# Line 22 | Line 22 | static const char      RCSid[] = "$Id$";
22   #include <string.h>
23  
24   #include "standard.h"
25 + #include "paths.h"
26   #include "view.h"
27  
28  
# Line 91 | Line 92 | main(
92   )
93   {
94          struct named_func       *funp;
94        char    *progtail;
95          int     i;
96                                          /* get program name */
97 <        progname = argv[0];
98 <        progtail = strrchr(progname, '/');      /* final component */
99 <        if (progtail == NULL)
100 <                progtail = progname;
101 <        else
102 <                progtail++;
97 >        progname = fixargv0(argv[0]);
98                                          /* get options */
99          for (i = 1; i < argc && argv[i][0] == '-'; i++)
100                  switch (argv[i][1]) {
101                  case 't':
102 <                        progtail = argv[++i];
102 >                        progname = argv[++i];
103                          break;
104                  case 'h':
105                          print_header = 0;
# Line 121 | Line 116 | main(
116                  }
117                                          /* find and run calculation */
118          for (funp = all_funcs; funp->name != NULL; funp++)
119 <                if (!strcmp(funp->name, progtail)) {
119 >                if (!strcmp(funp->name, progname)) {
120                          init();
121                          read_input();
122                          if (print_header) {
# Line 147 | Line 142 | headline(                      /* get line from header */
142          void    *p
143   )
144   {
145 <        char    fmt[32];
145 >        char    fmt[MAXFMTLEN];
146  
147          if (print_header)               /* copy to output */
148                  fputs(s, stdout);
# Line 164 | Line 159 | headline(                      /* get line from header */
159   static void
160   init(void)                              /* initialize calculation */
161   {
162 +        char    *err;
163                                          /* read header */
164          getheader(stdin, headline, NULL);
165          if (wrongformat) {
# Line 171 | Line 167 | init(void)                             /* initialize calculation */
167                  exit(1);
168          }
169                                          /* set view */
170 <        if (setview(&midview) != NULL) {
171 <                fprintf(stderr, "%s: bad view information in input\n",
170 >        if ((err = setview(&midview)) != NULL) {
171 >                fprintf(stderr, "%s: %s\n",
172 >                                progname, err);
173 >                exit(1);
174 >        }
175 >        if (fabs(DOT(midview.vdir, midview.vup)) > 1e-4) {
176 >                fprintf(stderr,
177 >                "%s: Input view direction not perpendicular to up vector\n",
178                                  progname);
179                  exit(1);
180          }
# Line 319 | Line 321 | posindex(                      /* compute position index */
321          d = DOT(sd,vd);
322          if (d <= 0.0)
323                  return(-1.0);
324 <        if (d >= 1.0)
324 >        if (d >= 1.0-FTINY)
325                  return(1.0);
326          sigma = acos(d) * (180./PI);
327          d = fabs(DOT(sd,vu)/sqrt(1.0-d*d));
328 <        if (d >= 1.0)
327 <                tau = 0.0;
328 <        else
329 <                tau = acos(d) * (180./PI);
328 >        tau = Acos(d) * (180./PI);
329          return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3
330                          + sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 )
331                  ) );
# Line 341 | Line 340 | dgi(           /* compute Daylight Glare Index */
340          struct glare_src        *gs;
341          FVECT   mydir,testdir[7],vhor;
342          double  r,posn,omega,p[7],sum;
343 <        int     i,n;
343 >        int     i;
344  
345          spinvector(mydir, midview.vdir, midview.vup, gd->ang);
346 <        sum = 0.0; n = 0;
346 >        sum = 0.0;
347          for (gs = all_srcs; gs != NULL; gs = gs->next) {
348  
349                  /* compute 1/p^2 weighted solid angle of the source */
350 <                r = sqrt(1 - pow(1.-gs->dom/2./PI,2.));
350 >                r = 1. - gs->dom*(.5/PI);
351 >                r = sqrt(1. - r*r);
352                  fcross(vhor,gs->dir,midview.vup);
353 <                normalize(vhor);
353 >                if (normalize(vhor) == 0.)
354 >                        continue;
355                  VCOPY(testdir[0],gs->dir);
356                  fvsum(testdir[1],gs->dir,vhor,r);
357                  fvsum(testdir[2],gs->dir,vhor,0.5*r);
# Line 361 | Line 362 | dgi(           /* compute Daylight Glare Index */
362                  fvsum(testdir[6],testdir[4],midview.vup,0.866*r);
363                  fvsum(testdir[4],testdir[4],midview.vup,-0.866*r);
364                  for (i = 0; i < 7; i++) {
365 <                        normalize(testdir[i]);
365 >                        p[i] = 0.0;
366 >                        if (normalize(testdir[i]) == 0.)
367 >                                continue;
368                          posn = posindex(testdir[i],mydir,midview.vup);
369 <                        if (posn <= FTINY)
367 <                                p[i] = 0.0;
368 <                        else
369 >                        if (posn > FTINY)
370                                  p[i] = 1./(posn*posn);
371                  }
372 <                r = 1-gs->dom/2./PI;
372 >                r = 1. - gs->dom*(.5/PI);
373                  omega = gs->dom*p[0];
374 <                omega += (r*PI*(1+1/r/r)-2*PI)*(-p[0]+(p[1]+p[2])*0.5);
375 <                omega += (2*PI-r*PI*(1+1/r/r))*(-p[0]-0.1667*(p[1]+p[3])
374 >                omega += (r*PI*(1.+1./(r*r))-2.*PI)*(-p[0]+(p[1]+p[2])*0.5);
375 >                omega += (2.*PI-r*PI*(1.+1./(r*r)))*(-p[0]-0.1667*(p[1]+p[3])
376                            +0.3334*(p[2]+p[4]+p[5]+p[6]));
377 <
377 >                if (omega <= 0.)
378 >                        continue;
379                  sum += pow(gs->lum,1.6) * pow(omega,0.8) /
380 <                       (gd->indirect/PI + 0.07*sqrt(gs->dom)*gs->lum);
379 <                n++;
380 >                       (gd->indirect*(1./PI) + 0.07*sqrt(gs->dom)*gs->lum);
381          }
382 <        if (n == 0)
382 >        if (sum <= FTINY)
383                  return(0.0);
384 <        return( 10*log10(0.478*sum) );
384 >        return( 10.*log10(0.478*sum) );
385   }
386  
387  
# Line 404 | Line 405 | brs_gi(                /* compute BRS Glare Index */
405          }
406          if (sum <= FTINY)
407                  return(0.0);
408 <        sum /= gd->indirect/PI;
408 >        sum *= PI/gd->indirect;
409          return(10*log10(0.478*sum));
410   }
411  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines