Back to index

radiance  4R0+20100331
Defines | Functions | Variables
findglare.c File Reference
#include "glare.h"

Go to the source code of this file.

Defines

#define FEQ(a, b)   ((a)-(b)<=FTINY&&(b)-(a)<=FTINY)
#define VEQ(v1, v2)

Functions

static int angcmp (const void *ap1, const void *ap2)
static void init (void)
static void cleanup (void)
static void printsources (void)
static void printillum (void)
int main (int argc, char *argv[])
int compdir (FVECT vd, int x, int y)
double pixsize (int x, int y)
void memerr (char *s)

Variables

static const char RCSid [] = "$Id: findglare.c,v 2.13 2009/02/07 05:40:47 greg Exp $"
char * rtargv [64] = {"rtrace", "-h-", "-ov", "-fff", "-ld-", "-i-", "-I-"}
int rtargc = 7
VIEW ourview = STDVIEW
VIEW pictview = STDVIEW
VIEW leftview
VIEW rightview
char * picture = NULL
char * octree = NULL
int verbose = 0
char * progname
double threshold = 0.
int sampdens = SAMPDENS
ANGLE glarang [180] = {AEND}
int nglarangs = 0
double maxtheta
int hsize
struct illumindirect
long npixinvw
long npixmiss

Define Documentation

#define FEQ (   a,
 
)    ((a)-(b)<=FTINY&&(b)-(a)<=FTINY)

Definition at line 12 of file findglare.c.

#define VEQ (   v1,
  v2 
)
Value:
(FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \
                            &&FEQ((v1)[2],(v2)[2]))

Definition at line 13 of file findglare.c.


Function Documentation

static int angcmp ( const void *  ap1,
const void *  ap2 
) [static]

Definition at line 234 of file findglare.c.

{
       register int  a1, a2;

       a1 = *(ANGLE *)ap1;
       a2 = *(ANGLE *)ap2;
       if (a1 == a2) {
              fprintf(stderr, "%s: duplicate glare angle (%d)\n",
                            progname, a1);
              exit(1);
       }
       return(a1-a2);
}
static void cleanup ( void  ) [static]

Definition at line 330 of file findglare.c.

{
       if (verbose)
              fprintf(stderr, "%s: cleaning up...        \n", progname);
       if (picture != NULL)
              close_pict();
       if (octree != NULL)
              done_rtrace();
       if (npixinvw < 100*npixmiss)
              fprintf(stderr, "%s: warning -- missing %d%% of samples\n",
                            progname, (int)(100L*npixmiss/npixinvw));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int compdir ( FVECT  vd,
int  x,
int  y 
)

Definition at line 345 of file findglare.c.

{
       int    hl;
       FVECT  org;                 /* dummy variable */

       hl = hlim(y);
       if (x <= -hl) {                    /* left region */
              if (x <= -hl-sampdens)
                     return(-1);
              return(viewray(org, vd, &leftview,
                            (double)(x+hl)/(2*sampdens)+.5,
                            (double)y/(2*sampdens)+.5));
       }
       if (x >= hl) {                     /* right region */
              if (x >= hl+sampdens)
                     return(-1);
              return(viewray(org, vd, &rightview,
                            (double)(x-hl)/(2*sampdens)+.5,
                            (double)y/(2*sampdens)+.5));
       }
                                   /* central region */
       if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0)
              return(-1);
       spinvector(vd, vd, ourview.vup, h_theta(x,y));
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init ( void  ) [static]
int main ( int  argc,
char *  argv[] 
)

Definition at line 51 of file findglare.c.

{
       int    combine = 1;
       int    gotview = 0;
       int    rval, i;
       char   *err;

       progname = argv[0];
                                   /* process options */
       for (i = 1; i < argc && argv[i][0] == '-'; i++) {
                                          /* expand arguments */
              while ((rval = expandarg(&argc, &argv, i)) > 0)
                     ;
              if (rval < 0) {
                     fprintf(stderr, "%s: cannot expand '%s'\n",
                                   argv[0], argv[i]);
                     exit(1);
              }
              rval = getviewopt(&ourview, argc-i, argv+i);
              if (rval >= 0) {
                     i += rval;
                     gotview++;
                     continue;
              }
              switch (argv[i][1]) {
              case 't':
                     threshold = atof(argv[++i]);
                     break;
              case 'r':
                     sampdens = atoi(argv[++i])/2;
                     break;
              case 'v':
                     if (argv[i][2] == '\0') {
                            verbose++;
                            break;
                     }
                     if (argv[i][2] != 'f')
                            goto userr;
                     rval = viewfile(argv[++i], &ourview, NULL);
                     if (rval < 0) {
                            fprintf(stderr,
                            "%s: cannot open view file \"%s\"\n",
                                          progname, argv[i]);
                            exit(1);
                     } else if (rval == 0) {
                            fprintf(stderr,
                                   "%s: bad view file \"%s\"\n",
                                          progname, argv[i]);
                            exit(1);
                     } else
                            gotview++;
                     break;
              case 'g':
                     if (argv[i][2] != 'a')
                            goto userr;
                     if (setscan(glarang, argv[++i]) < 0) {
                            fprintf(stderr, "%s: bad angle spec \"%s\"\n",
                                   progname, argv[i]);
                            exit(1);
                     }
                     break;
              case 'p':
                     picture = argv[++i];
                     break;
              case 'c':
                     combine = !combine;
                     break;
              case 'd':
                     rtargv[rtargc++] = argv[i];
                     if (argv[i][2] != 'v')
                            rtargv[rtargc++] = argv[++i];
                     break;
              case 'l':
                     if (argv[i][2] == 'd')
                            break;
                     /* FALL THROUGH */
              case 's':
              case 'P':
                     rtargv[rtargc++] = argv[i];
                     rtargv[rtargc++] = argv[++i];
                     break;
              case 'w':
                     rtargv[rtargc++] = argv[i];
                     break;
              case 'a':
                     rtargv[rtargc++] = argv[i];
                     if (argv[i][2] == 'v') {
                            rtargv[rtargc++] = argv[++i];
                            rtargv[rtargc++] = argv[++i];
                     }
                     rtargv[rtargc++] = argv[++i];
                     break;
              default:
                     goto userr;
              }
       }
                                          /* get octree */
       if (i < argc-1)
              goto userr;
       if (i == argc-1) {
              rtargv[rtargc++] = octree = argv[i];
              rtargv[rtargc] = NULL;
       }
                                          /* get view */
       if (picture != NULL) {
              rval = viewfile(picture, &pictview, NULL);
              if (rval < 0) {
                     fprintf(stderr, "%s: cannot open picture file \"%s\"\n",
                                   progname, picture);
                     exit(1);
              } else if (rval == 0) {
                     fprintf(stderr,
                            "%s: cannot get view from picture \"%s\"\n",
                                   progname, picture);
                     exit(1);
              }
              if (pictview.type == VT_PAR) {
                     fprintf(stderr, "%s: %s: cannot use parallel view\n",
                                   progname, picture);
                     exit(1);
              }
              if ((err = setview(&pictview)) != NULL) {
                     fprintf(stderr, "%s: %s\n", picture, err);
                     exit(1);
              }
       }
       if (!gotview) {
              if (picture == NULL) {
                     fprintf(stderr, "%s: must have view or picture\n",
                                   progname);
                     exit(1);
              }
              ourview = pictview;
       } else if (picture != NULL && !VEQ(ourview.vp, pictview.vp)) {
              fprintf(stderr, "%s: picture must have same viewpoint\n",
                            progname);
              exit(1);
       }
       ourview.type = VT_HEM;
       ourview.horiz = ourview.vert = 180.0;
       ourview.hoff = ourview.voff = 0.0;
       fvsum(ourview.vdir, ourview.vdir, ourview.vup,
                     -DOT(ourview.vdir,ourview.vup));
       if ((err = setview(&ourview)) != NULL) {
              fprintf(stderr, "%s: %s\n", progname, err);
              exit(1);
       }
       if (octree == NULL && picture == NULL) {
              fprintf(stderr,
              "%s: must specify at least one of picture or octree\n",
                            progname);
              exit(1);
       }
       init();                                   /* initialize program */
       if (threshold <= FTINY)
              comp_thresh();                     /* compute glare threshold */
       analyze();                         /* analyze view */
       if (combine)
              absorb_specks();            /* eliminate tiny sources */
       cleanup();                         /* tidy up */
                                          /* print header */
       newheader("RADIANCE", stdout);
       printargs(argc, argv, stdout);
       fputs(VIEWSTR, stdout);
       fprintview(&ourview, stdout);
       printf("\n");
       fputformat("ascii", stdout);
       printf("\n");
       printsources();                           /* print glare sources */
       printillum();                      /* print illuminances */
       exit(0);
userr:
       fprintf(stderr,
"Usage: %s [view options][-ga angles][-p picture][[rtrace options] octree]\n",
                     progname);
       exit(1);
}

Here is the call graph for this function:

void memerr ( char *  s)

Definition at line 401 of file findglare.c.

{
       fprintf(stderr, "%s: out of memory for %s\n", progname, s);
       exit(1);
}
double pixsize ( int  x,
int  y 
)

Definition at line 378 of file findglare.c.

{
       register int  hl, xo;
       double disc;

       hl = hlim(y);
       if (x < -hl)
              xo = x+hl;
       else if (x > hl)
              xo = x-hl;
       else
              xo = 0;
       disc = 1. - (double)((long)xo*xo + (long)y*y)/((long)sampdens*sampdens);
       if (disc <= FTINY*FTINY)
              return(0.);
       return(1./(sampdens*sampdens*sqrt(disc)));
}

Here is the caller graph for this function:

static void printillum ( void  ) [static]

Definition at line 425 of file findglare.c.

{
       register int  i;

       printf("BEGIN indirect illuminance\n");
       for (i = 0; i < nglardirs; i++)
              if (indirect[i].n > FTINY)
                     printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta,
                                   PI * indirect[i].sum / indirect[i].n);
       printf("END indirect illuminance\n");
}

Here is the caller graph for this function:

static void printsources ( void  ) [static]

Definition at line 411 of file findglare.c.

{
       register struct source      *sp;

       printf("BEGIN glare source\n");
       for (sp = donelist; sp != NULL; sp = sp->next)
              printf("\t%f %f %f\t%f\t%f\n",
                            sp->dir[0], sp->dir[1], sp->dir[2],
                            sp->dom, sp->brt);
       printf("END glare source\n");
}

Here is the caller graph for this function:


Variable Documentation

ANGLE glarang[180] = {AEND}

Definition at line 32 of file findglare.c.

int hsize

Definition at line 35 of file findglare.c.

struct illum* indirect

Definition at line 37 of file findglare.c.

Definition at line 21 of file findglare.c.

double maxtheta

Definition at line 34 of file findglare.c.

int nglarangs = 0

Definition at line 33 of file findglare.c.

long npixinvw

Definition at line 39 of file findglare.c.

long npixmiss

Definition at line 40 of file findglare.c.

char* octree = NULL

Definition at line 24 of file findglare.c.

Definition at line 19 of file findglare.c.

char* picture = NULL

Definition at line 23 of file findglare.c.

Definition at line 20 of file findglare.c.

char* progname

Definition at line 27 of file findglare.c.

const char RCSid[] = "$Id: findglare.c,v 2.13 2009/02/07 05:40:47 greg Exp $" [static]

Definition at line 2 of file findglare.c.

Definition at line 21 of file findglare.c.

int rtargc = 7

Definition at line 17 of file findglare.c.

char* rtargv[64] = {"rtrace", "-h-", "-ov", "-fff", "-ld-", "-i-", "-I-"}

Definition at line 16 of file findglare.c.

Definition at line 31 of file findglare.c.

double threshold = 0.

Definition at line 29 of file findglare.c.

int verbose = 0

Definition at line 26 of file findglare.c.