Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
glarendx.c File Reference
#include <string.h>
#include "standard.h"
#include "view.h"

Go to the source code of this file.

Classes

struct  glare_src
struct  glare_dir
struct  named_func

Defines

#define newp(type)   (type *)malloc(sizeof(type))
#define S_SEARCH   0
#define S_SOURCE   1
#define S_DIREC   2
#define q(w)   (20.4*w+1.52*pow(w,.2)-.075)
#define M_SQRT2   1.41421356237309504880
#define norm_integral(z)   (1.-.5*erfc((z)/M_SQRT2))

Typedefs

typedef double gdfun (struct glare_dir *gd)

Functions

static void init (void)
static void read_input (void)
static void print_values (gdfun *func)
static double posindex (FVECT sd, FVECT vd, FVECT vu)
int main (int argc, char *argv[])
static int headline (char *s, void *p)
static double direct (struct glare_dir *gd)
static double indirect (struct glare_dir *gd)
static double total (struct glare_dir *gd)
static double dgi (struct glare_dir *gd)
static double brs_gi (struct glare_dir *gd)
static double guth_dgr (struct glare_dir *gd)
static double guth_vcp (struct glare_dir *gd)
static double cie_cgi (struct glare_dir *gd)
static double ugr (struct glare_dir *gd)

Variables

static const char RCSid [] = "$Id: glarendx.c,v 2.10 2004/01/02 12:48:36 schorsch Exp $"
struct glare_srcall_srcs
struct glare_dirall_dirs
static gdfun dgi
static gdfun brs_gi
static gdfun ugr
static gdfun guth_dgr
static gdfun guth_vcp
static gdfun cie_cgi
static gdfun direct
static gdfun indirect
static gdfun total
static gethfunc headline
struct named_func all_funcs []
char * progname
int print_header = 1
VIEW midview = STDVIEW
int wrongformat = 0

Class Documentation

struct glare_src

Definition at line 28 of file glarendx.c.

Collaboration diagram for glare_src:
Class Members
FVECT dir
double dom
double lum
struct glare_src * next
struct glare_dir

Definition at line 35 of file glarendx.c.

Collaboration diagram for glare_dir:
Class Members
double ang
double indirect
struct glare_dir * next
struct named_func

Definition at line 60 of file glarendx.c.

Class Members
char * descrip
gdfun * func
char * name

Define Documentation

#define M_SQRT2   1.41421356237309504880

Definition at line 444 of file glarendx.c.

#define newp (   type)    (type *)malloc(sizeof(type))

Definition at line 77 of file glarendx.c.

#define norm_integral (   z)    (1.-.5*erfc((z)/M_SQRT2))

Definition at line 447 of file glarendx.c.

#define q (   w)    (20.4*w+1.52*pow(w,.2)-.075)
#define S_DIREC   2
#define S_SEARCH   0
#define S_SOURCE   1

Typedef Documentation

typedef double gdfun(struct glare_dir *gd)

Definition at line 41 of file glarendx.c.


Function Documentation

static double brs_gi ( struct glare_dir gd) [static]

Definition at line 387 of file glarendx.c.

{
       register struct glare_src   *gs;
       FVECT  mydir;
       double p;
       double sum;

       spinvector(mydir, midview.vdir, midview.vup, gd->ang);
       sum = 0.0;
       for (gs = all_srcs; gs != NULL; gs = gs->next) {
              p = posindex(gs->dir, mydir, midview.vup);
              if (p <= FTINY)
                     continue;
              sum += pow(gs->lum/p,1.6) * pow(gs->dom,0.8);
       }
       if (sum <= FTINY)
              return(0.0);
       sum /= gd->indirect/PI;
       return(10*log10(0.478*sum));
}

Here is the call graph for this function:

static double cie_cgi ( struct glare_dir gd) [static]

Definition at line 466 of file glarendx.c.

{
       register struct glare_src   *gs;
       FVECT  mydir;
       double dillum;
       double p;
       double sum;

       spinvector(mydir, midview.vdir, midview.vup, gd->ang);
       sum = 0.0;
       for (gs = all_srcs; gs != NULL; gs = gs->next) {
              p = posindex(gs->dir, mydir, midview.vup);
              if (p <= FTINY)
                     continue;
              sum += gs->lum*gs->lum * gs->dom / (p*p);
       }
       if (sum <= FTINY)
              return(0.0);
       dillum = direct(gd);
       return(8.*log10(2.*sum*(1.+dillum/500.)/(dillum+gd->indirect)));
}

Here is the call graph for this function:

static double dgi ( struct glare_dir gd) [static]

Definition at line 336 of file glarendx.c.

{
       register struct glare_src   *gs;
       FVECT  mydir,testdir[7],vhor;
       double r,posn,omega,p[7],sum;
       int    i,n;

       spinvector(mydir, midview.vdir, midview.vup, gd->ang);
       sum = 0.0; n = 0;
       for (gs = all_srcs; gs != NULL; gs = gs->next) {

              /* compute 1/p^2 weighted solid angle of the source */
              r = sqrt(1 - pow(1.-gs->dom/2./PI,2.));
              fcross(vhor,gs->dir,midview.vup);
              normalize(vhor);
              VCOPY(testdir[0],gs->dir);
              fvsum(testdir[1],gs->dir,vhor,r);
              fvsum(testdir[2],gs->dir,vhor,0.5*r);
              fvsum(testdir[5],testdir[2],midview.vup,-0.866*r);
              fvsum(testdir[2],testdir[2],midview.vup,0.866*r);
              fvsum(testdir[3],gs->dir,vhor,-r);
              fvsum(testdir[4],gs->dir,vhor,-0.5*r);
              fvsum(testdir[6],testdir[4],midview.vup,0.866*r);
              fvsum(testdir[4],testdir[4],midview.vup,-0.866*r);
              for (i = 0; i < 7; i++) {
                     normalize(testdir[i]);
                     posn = posindex(testdir[i],mydir,midview.vup);
                     if (posn <= FTINY)
                            p[i] = 0.0;
                     else
                            p[i] = 1./(posn*posn);
              }
              r = 1-gs->dom/2./PI;
              omega = gs->dom*p[0];
              omega += (r*PI*(1+1/r/r)-2*PI)*(-p[0]+(p[1]+p[2])*0.5);
              omega += (2*PI-r*PI*(1+1/r/r))*(-p[0]-0.1667*(p[1]+p[3])
                       +0.3334*(p[2]+p[4]+p[5]+p[6]));

              sum += pow(gs->lum,1.6) * pow(omega,0.8) /
                     (gd->indirect/PI + 0.07*sqrt(gs->dom)*gs->lum);
              n++;
       }
       if (n == 0)
              return(0.0);
       return( 10*log10(0.478*sum) );
}

Here is the call graph for this function:

static double direct ( struct glare_dir gd) [static]

Definition at line 257 of file glarendx.c.

{
       FVECT  mydir;
       double d, dval;
       register struct glare_src   *gs;

       spinvector(mydir, midview.vdir, midview.vup, gd->ang);
       dval = 0.0;
       for (gs = all_srcs; gs != NULL; gs = gs->next) {
              d = DOT(mydir,gs->dir);
              if (d > FTINY)
                     dval += d * gs->dom * gs->lum;
       }
       return(dval);
}

Here is the call graph for this function:

static double guth_dgr ( struct glare_dir gd) [static]

Definition at line 412 of file glarendx.c.

{
#define q(w)  (20.4*w+1.52*pow(w,.2)-.075)
       register struct glare_src   *gs;
       FVECT  mydir;
       double p;
       double sum;
       double wtot, brsum;
       int    n;

       spinvector(mydir, midview.vdir, midview.vup, gd->ang);
       sum = wtot = brsum = 0.0; n = 0;
       for (gs = all_srcs; gs != NULL; gs = gs->next) {
              p = posindex(gs->dir, mydir, midview.vup);
              if (p <= FTINY)
                     continue;
              sum += gs->lum * q(gs->dom) / p;
              brsum += gs->lum * gs->dom;
              wtot += gs->dom;
              n++;
       }
       if (n == 0)
              return(0.0);
       return( pow(.5*sum/pow((brsum+(5.-wtot)*gd->indirect/PI)/5.,.44),
                     pow((double)n, -.0914) ) );
#undef q
}

Here is the call graph for this function:

static double guth_vcp ( struct glare_dir gd) [static]

Definition at line 451 of file glarendx.c.

{
       extern double erfc();
       double dgr;

       dgr = guth_dgr(gd);
       if (dgr <= FTINY)
              return(100.0);
       return(100.*norm_integral(6.374-1.3227*log(dgr)));
}

Here is the call graph for this function:

static int headline ( char *  s,
void *  p 
) [static]

Definition at line 145 of file glarendx.c.

{
       char   fmt[32];

       if (print_header)           /* copy to output */
              fputs(s, stdout);
       if (isview(s))
              sscanview(&midview, s);
       else if (isformat(s)) {
              formatval(fmt, s);
              wrongformat = strcmp(fmt, "ascii");
       }
       return(0);
}

Here is the call graph for this function:

static double indirect ( struct glare_dir gd) [static]

Definition at line 277 of file glarendx.c.

{
       return(gd->indirect);
}
static void init ( void  ) [static]
int main ( int  argc,
char *  argv[] 
)

Definition at line 88 of file glarendx.c.

{
       struct named_func    *funp;
       char   *progtail;
       int    i;
                                   /* get program name */
       progname = argv[0];
       progtail = strrchr(progname, '/'); /* final component */
       if (progtail == NULL)
              progtail = progname;
       else
              progtail++;
                                   /* get options */
       for (i = 1; i < argc && argv[i][0] == '-'; i++)
              switch (argv[i][1]) {
              case 't':
                     progtail = argv[++i];
                     break;
              case 'h':
                     print_header = 0;
                     break;
              default:
                     goto userr;
              }
       if (i < argc-1)
              goto userr;
       if (i == argc-1)            /* open file */
              if (freopen(argv[i], "r", stdin) == NULL) {
                     perror(argv[i]);
                     exit(1);
              }
                                   /* find and run calculation */
       for (funp = all_funcs; funp->name != NULL; funp++)
              if (!strcmp(funp->name, progtail)) {
                     init();
                     read_input();
                     if (print_header) {
                            printargs(i, argv, stdout);
                            putchar('\n');
                     }
                     print_values(funp->func);
                     exit(0);             /* we're done */
              }
                                   /* invalid function */
userr:
       fprintf(stderr, "Usage: %s -t type [-h] [input]\n", progname);
       fprintf(stderr, "\twhere 'type' is one of the following:\n");
       for (funp = all_funcs; funp->name != NULL; funp++)
              fprintf(stderr, "\t%12s\t%s\n", funp->name, funp->descrip);
       exit(1);
}

Here is the call graph for this function:

static double posindex ( FVECT  sd,
FVECT  vd,
FVECT  vu 
) [static]

Definition at line 309 of file glarendx.c.

{
       double sigma, tau;
       double d;

       d = DOT(sd,vd);
       if (d <= 0.0)
              return(-1.0);
       if (d >= 1.0)
              return(1.0);
       sigma = acos(d) * (180./PI);
       d = fabs(DOT(sd,vu)/sqrt(1.0-d*d));
       if (d >= 1.0)
              tau = 0.0;
       else
              tau = acos(d) * (180./PI);
       return( exp( sigma*( (35.2 - tau*.31889 - 1.22*exp(-.22222*tau))*1e-3
                     + sigma*(21. + tau*(.26667 + tau*-.002963))*1e-5 )
              ) );
}

Here is the caller graph for this function:

static void print_values ( gdfun func) [static]

Definition at line 245 of file glarendx.c.

{
       register struct glare_dir   *gd;

       for (gd = all_dirs; gd != NULL; gd = gd->next)
              printf("%f\t%f\n", gd->ang*(180.0/PI), (*func)(gd));
}

Here is the caller graph for this function:

static void read_input ( void  ) [static]

Definition at line 183 of file glarendx.c.

{
#define       S_SEARCH      0
#define S_SOURCE     1
#define S_DIREC             2
       int    state = S_SEARCH;
       char   buf[128];
       register struct glare_src   *gs;
       register struct glare_dir   *gd;

       while (fgets(buf, sizeof(buf), stdin) != NULL)
              switch (state) {
              case S_SEARCH:
                     if (!strcmp(buf, "BEGIN glare source\n"))
                            state = S_SOURCE;
                     else if (!strcmp(buf, "BEGIN indirect illuminance\n"))
                            state = S_DIREC;
                     break;
              case S_SOURCE:
                     if (!strncmp(buf, "END", 3)) {
                            state = S_SEARCH;
                            break;
                     }
                     if ((gs = newp(struct glare_src)) == NULL)
                            goto memerr;
                     if (sscanf(buf, "%lf %lf %lf %lf %lf",
                                   &gs->dir[0], &gs->dir[1], &gs->dir[2],
                                   &gs->dom, &gs->lum) != 5)
                            goto readerr;
                     normalize(gs->dir);
                     gs->next = all_srcs;
                     all_srcs = gs;
                     break;
              case S_DIREC:
                     if (!strncmp(buf, "END", 3)) {
                            state = S_SEARCH;
                            break;
                     }
                     if ((gd = newp(struct glare_dir)) == NULL)
                            goto memerr;
                     if (sscanf(buf, "%lf %lf",
                                   &gd->ang, &gd->indirect) != 2)
                            goto readerr;
                     gd->ang *= PI/180.0; /* convert to radians */
                     gd->next = all_dirs;
                     all_dirs = gd;
                     break;
              }
       return;
memerr:
       perror(progname);
       exit(1);
readerr:
       fprintf(stderr, "%s: read error on input\n", progname);
       exit(1);
#undef S_SEARCH
#undef S_SOURCE
#undef S_DIREC
}

Here is the call graph for this function:

Here is the caller graph for this function:

static double total ( struct glare_dir gd) [static]

Definition at line 286 of file glarendx.c.

{
       return(direct(gd)+gd->indirect);
}
static double ugr ( struct glare_dir gd) [static]

Definition at line 492 of file glarendx.c.

{
       register struct glare_src   *gs;
       FVECT  mydir;
       double p;
       double sum;

       spinvector(mydir, midview.vdir, midview.vup, gd->ang);
       sum = 0.0;
       for (gs = all_srcs; gs != NULL; gs = gs->next) {
              p = posindex(gs->dir, mydir, midview.vup);
              if (p <= FTINY)
                     continue;
              sum += gs->lum*gs->lum * gs->dom / (p*p);
       }
       if (sum <= FTINY)
              return(0.0);
       return(8.*log10(0.25*sum*PI/gd->indirect));
}

Here is the call graph for this function:


Variable Documentation

struct glare_dir * all_dirs
struct glare_src * all_srcs
gdfun brs_gi [static]

Definition at line 44 of file glarendx.c.

gdfun cie_cgi [static]

Definition at line 48 of file glarendx.c.

gdfun dgi [static]

Definition at line 43 of file glarendx.c.

gdfun direct [static]

Definition at line 49 of file glarendx.c.

gdfun guth_dgr [static]

Definition at line 46 of file glarendx.c.

gdfun guth_vcp [static]

Definition at line 47 of file glarendx.c.

gethfunc headline [static]

Definition at line 53 of file glarendx.c.

gdfun indirect [static]

Definition at line 50 of file glarendx.c.

Definition at line 82 of file glarendx.c.

int print_header = 1

Definition at line 80 of file glarendx.c.

char* progname

Definition at line 79 of file glarendx.c.

const char RCSid[] = "$Id: glarendx.c,v 2.10 2004/01/02 12:48:36 schorsch Exp $" [static]

Definition at line 2 of file glarendx.c.

gdfun total [static]

Definition at line 51 of file glarendx.c.

gdfun ugr [static]

Definition at line 45 of file glarendx.c.

int wrongformat = 0

Definition at line 84 of file glarendx.c.