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.11 by greg, Fri Apr 11 20:27:23 2014 UTC vs.
Revision 2.17 by greg, Tue Jun 3 21:31:51 2025 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 76 | Line 77 | struct named_func {
77  
78   #define newp(type)      (type *)malloc(sizeof(type))
79  
79 char    *progname;
80   int     print_header = 1;
81  
82   VIEW    midview = STDVIEW;
# Line 91 | Line 91 | main(
91   )
92   {
93          struct named_func       *funp;
94        char    *progtail;
94          int     i;
95                                          /* get program name */
96 <        progname = argv[0];
98 <        progtail = strrchr(progname, '/');      /* final component */
99 <        if (progtail == NULL)
100 <                progtail = progname;
101 <        else
102 <                progtail++;
96 >        progname = fixargv0(argv[0]);
97                                          /* get options */
98          for (i = 1; i < argc && argv[i][0] == '-'; i++)
99                  switch (argv[i][1]) {
100                  case 't':
101 <                        progtail = argv[++i];
101 >                        progname = argv[++i];
102                          break;
103                  case 'h':
104                          print_header = 0;
# Line 121 | Line 115 | main(
115                  }
116                                          /* find and run calculation */
117          for (funp = all_funcs; funp->name != NULL; funp++)
118 <                if (!strcmp(funp->name, progtail)) {
118 >                if (!strcmp(funp->name, progname)) {
119                          init();
120                          read_input();
121                          if (print_header) {
# Line 147 | Line 141 | headline(                      /* get line from header */
141          void    *p
142   )
143   {
144 <        char    fmt[32];
144 >        char    fmt[MAXFMTLEN];
145  
146          if (print_header)               /* copy to output */
147                  fputs(s, stdout);
# Line 164 | Line 158 | headline(                      /* get line from header */
158   static void
159   init(void)                              /* initialize calculation */
160   {
161 +        char    *err;
162                                          /* read header */
163          getheader(stdin, headline, NULL);
164          if (wrongformat) {
# Line 171 | Line 166 | init(void)                             /* initialize calculation */
166                  exit(1);
167          }
168                                          /* set view */
169 <        if (setview(&midview) != NULL) {
170 <                fprintf(stderr, "%s: bad view information in input\n",
169 >        if ((err = setview(&midview)) != NULL) {
170 >                fprintf(stderr, "%s: %s\n",
171 >                                progname, err);
172 >                exit(1);
173 >        }
174 >        if (fabs(DOT(midview.vdir, midview.vup)) > 1e-4) {
175 >                fprintf(stderr,
176 >                "%s: Input view direction not perpendicular to up vector\n",
177                                  progname);
178                  exit(1);
179          }
# Line 207 | Line 208 | read_input(void)                       /* read glare sources from stdin */
208                                  goto memerr;
209                          if (sscanf(buf, FVFORMAT, &gs->dir[0], &gs->dir[1],
210                                                  &gs->dir[2]) != 3 ||
211 <                                        sscanf(buf, "%lf %lf",
211 >                                        sscanf(sskip2(buf, 3), "%lf %lf",
212                                                  &gs->dom, &gs->lum) != 2)
213                                  goto readerr;
214                          normalize(gs->dir);
# Line 319 | Line 320 | posindex(                      /* compute position index */
320          d = DOT(sd,vd);
321          if (d <= 0.0)
322                  return(-1.0);
323 <        if (d >= 1.0)
323 >        if (d >= 1.0-FTINY)
324                  return(1.0);
325          sigma = acos(d) * (180./PI);
326          d = fabs(DOT(sd,vu)/sqrt(1.0-d*d));
327 <        if (d >= 1.0)
327 <                tau = 0.0;
328 <        else
329 <                tau = acos(d) * (180./PI);
327 >        tau = Acos(d) * (180./PI);
328          return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3
329                          + sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 )
330                  ) );
# Line 341 | Line 339 | dgi(           /* compute Daylight Glare Index */
339          struct glare_src        *gs;
340          FVECT   mydir,testdir[7],vhor;
341          double  r,posn,omega,p[7],sum;
342 <        int     i,n;
342 >        int     i;
343  
344          spinvector(mydir, midview.vdir, midview.vup, gd->ang);
345 <        sum = 0.0; n = 0;
345 >        sum = 0.0;
346          for (gs = all_srcs; gs != NULL; gs = gs->next) {
347  
348                  /* compute 1/p^2 weighted solid angle of the source */
349 <                r = sqrt(1 - pow(1.-gs->dom/2./PI,2.));
349 >                r = 1. - gs->dom*(.5/PI);
350 >                r = sqrt(1. - r*r);
351                  fcross(vhor,gs->dir,midview.vup);
352 <                normalize(vhor);
352 >                if (normalize(vhor) == 0.)
353 >                        continue;
354                  VCOPY(testdir[0],gs->dir);
355                  fvsum(testdir[1],gs->dir,vhor,r);
356                  fvsum(testdir[2],gs->dir,vhor,0.5*r);
# Line 361 | Line 361 | dgi(           /* compute Daylight Glare Index */
361                  fvsum(testdir[6],testdir[4],midview.vup,0.866*r);
362                  fvsum(testdir[4],testdir[4],midview.vup,-0.866*r);
363                  for (i = 0; i < 7; i++) {
364 <                        normalize(testdir[i]);
364 >                        p[i] = 0.0;
365 >                        if (normalize(testdir[i]) == 0.)
366 >                                continue;
367                          posn = posindex(testdir[i],mydir,midview.vup);
368 <                        if (posn <= FTINY)
367 <                                p[i] = 0.0;
368 <                        else
368 >                        if (posn > FTINY)
369                                  p[i] = 1./(posn*posn);
370                  }
371 <                r = 1-gs->dom/2./PI;
371 >                r = 1. - gs->dom*(.5/PI);
372                  omega = gs->dom*p[0];
373 <                omega += (r*PI*(1+1/r/r)-2*PI)*(-p[0]+(p[1]+p[2])*0.5);
374 <                omega += (2*PI-r*PI*(1+1/r/r))*(-p[0]-0.1667*(p[1]+p[3])
373 >                omega += (r*PI*(1.+1./(r*r))-2.*PI)*(-p[0]+(p[1]+p[2])*0.5);
374 >                omega += (2.*PI-r*PI*(1.+1./(r*r)))*(-p[0]-0.1667*(p[1]+p[3])
375                            +0.3334*(p[2]+p[4]+p[5]+p[6]));
376 <
376 >                if (omega <= 0.)
377 >                        continue;
378                  sum += pow(gs->lum,1.6) * pow(omega,0.8) /
379 <                       (gd->indirect/PI + 0.07*sqrt(gs->dom)*gs->lum);
379 <                n++;
379 >                       (gd->indirect*(1./PI) + 0.07*sqrt(gs->dom)*gs->lum);
380          }
381 <        if (n == 0)
381 >        if (sum <= FTINY)
382                  return(0.0);
383 <        return( 10*log10(0.478*sum) );
383 >        return( 10.*log10(0.478*sum) );
384   }
385  
386  
# Line 404 | Line 404 | brs_gi(                /* compute BRS Glare Index */
404          }
405          if (sum <= FTINY)
406                  return(0.0);
407 <        sum /= gd->indirect/PI;
407 >        sum *= PI/gd->indirect;
408          return(10*log10(0.478*sum));
409   }
410  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines