Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
glare.h File Reference
#include "standard.h"
#include "view.h"
#include "color.h"
#include "setscan.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  illum
struct  srcspan
struct  source

Defines

#define GLAREBR   7.0 /* glare source is this * avg. lum. */
#define SAMPDENS   75 /* default samples per unit in image */
#define TSAMPSTEP   10 /* sample step to compute threshold */
#define SEPS   1 /* sources this close ==> contig. */
#define SAMIN   .005 /* minimum solid angle for source */
#define MAXBUDDY   (4.*sqrt(SAMIN/PI)) /* max separation for pairing */
#define TOOSMALL(s)   ((s)->brt*(s)->dom < threshold*SAMIN)
#define SABIG   .025 /* solid angle of splittable source */
#define LCORR   .12 /* linearity of splittable source */
#define nglardirs   (2*nglarangs+1)
#define vsize   (sampdens-1)
#define hscale(v)   sqrt((double)(sampdens*sampdens - (v)*(v)))
#define hlim(v)   (int)(maxtheta*hscale(v))
#define h_theta(h, v)   (-(h)/hscale(v))

Functions

void memerr (char *s)
int compdir (FVECT vd, int x, int y)
double pixsize (int x, int y)
void comp_thresh (void)
void analyze (void)
void absorb_specks (void)
void open_pict (char *fn)
void fork_rtrace (char *av[])
void close_pict (void)
void done_rtrace (void)
void getviewspan (int vv, float *vb)
double getviewpix (int vh, int vv)

Variables

VIEW ourview
VIEW pictview
VIEW leftview
VIEW rightview
int verbose
char * progname
double threshold
int sampdens
ANGLE glarang []
int nglarangs
double maxtheta
int hsize
struct illumindirect
struct sourcedonelist
long npixinvw
long npixmiss

Class Documentation

struct illum

Definition at line 53 of file glare.h.

Class Members
float lcos
float lsin
double n
float rcos
float rsin
double sum
float theta
struct srcspan

Definition at line 61 of file glare.h.

Collaboration diagram for srcspan:
Class Members
float brsum
short l
struct srcspan * next
short r
short v
struct source

Definition at line 68 of file glare.h.

Collaboration diagram for source:
Class Members
double brt
FVECT dir
double dom
struct srcspan * first
struct source * next

Define Documentation

#define GLAREBR   7.0 /* glare source is this * avg. lum. */

Definition at line 17 of file glare.h.

#define h_theta (   h,
  v 
)    (-(h)/hscale(v))

Definition at line 51 of file glare.h.

#define hlim (   v)    (int)(maxtheta*hscale(v))

Definition at line 50 of file glare.h.

#define hscale (   v)    sqrt((double)(sampdens*sampdens - (v)*(v)))

Definition at line 49 of file glare.h.

#define LCORR   .12 /* linearity of splittable source */

Definition at line 30 of file glare.h.

#define MAXBUDDY   (4.*sqrt(SAMIN/PI)) /* max separation for pairing */

Definition at line 25 of file glare.h.

#define nglardirs   (2*nglarangs+1)

Definition at line 47 of file glare.h.

#define SABIG   .025 /* solid angle of splittable source */

Definition at line 29 of file glare.h.

#define SAMIN   .005 /* minimum solid angle for source */

Definition at line 24 of file glare.h.

#define SAMPDENS   75 /* default samples per unit in image */

Definition at line 19 of file glare.h.

#define SEPS   1 /* sources this close ==> contig. */

Definition at line 22 of file glare.h.

#define TOOSMALL (   s)    ((s)->brt*(s)->dom < threshold*SAMIN)

Definition at line 27 of file glare.h.

#define TSAMPSTEP   10 /* sample step to compute threshold */

Definition at line 20 of file glare.h.

#define vsize   (sampdens-1)

Definition at line 48 of file glare.h.


Function Documentation

void absorb_specks ( void  )

Definition at line 459 of file glaresrc.c.

{
       struct source head, *buddy;
       register struct source      *last, *this;

       if (verbose)
              fprintf(stderr, "%s: absorbing small sources...\n", progname);
       head.next = donelist;
       last = &head;
       for (this = head.next; this != NULL; this = this->next)
              if (TOOSMALL(this)) {
                     last->next = this->next;
                     buddy = findbuddy(this, head.next);
                     if (buddy != NULL)
                            mergesource(buddy, this);
                     else
                            absorb(this);
                     this = last;
              } else
                     last = this;
       donelist = head.next;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void analyze ( void  )

Definition at line 59 of file glaresrc.c.

{
       int    h, v;
       int    left;
       float  *spanbr;

       spanbr = (float *)malloc((2*hsize+1)*sizeof(float));
       if (spanbr == NULL)
              memerr("view span brightness buffer");
       for (v = vsize; v >= -vsize; v--) {
              close_sources(v);
#ifndef DEBUG
              if (verbose) {
                     fprintf(stderr, "%s: analyzing... %3ld%%\r",
                            progname, 100L*(vsize-v)/(2*vsize));
                     fflush(stderr);
              }
#endif
              getviewspan(v, spanbr);
              left = hsize + 1;
              for (h = -hsize; h <= hsize; h++) {
                     if (spanbr[h+hsize] < 0.0) {       /* off view */
                            if (left < h) {
                                   addsrcspan(newspan(left,h,v,spanbr));
                                   left = hsize + 1;
                            }
                            continue;
                     }
                     if (spanbr[h+hsize] > threshold) { /* in source */
                            if (left > h)
                                   left = h;
                     } else {                    /* out of source */
                            if (left < h) {
                                   addsrcspan(newspan(left,h,v,spanbr));
                                   left = hsize + 1;
                            }
                            addindirect(h, v, spanbr[h+hsize]);
                     }
              }
              if (left < h)
                     addsrcspan(newspan(left,h,v,spanbr));
       }
       free((void *)spanbr);
       close_allsrcs();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void close_pict ( void  )

Definition at line 333 of file glareval.c.

{
       if (pictfp == NULL)
              return;
       fclose(pictfp);
       donescans();
       pictfp = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void comp_thresh ( void  )

Definition at line 158 of file glaresrc.c.

{
       int    h, v;
       int    nsamps;
       double brsum, br;

       if (verbose)
              fprintf(stderr, "%s: computing glare threshold...\n",
                            progname);
       brsum = 0.0;
       nsamps = 0;
       for (v = vsize; v >= -vsize; v -= TSAMPSTEP) {
              for (h = -hsize; h <= hsize; h += TSAMPSTEP) {
                     if ((br = getviewpix(h, v)) < 0.0)
                            continue;
                     brsum += br;
                     nsamps++;
              }
       }
       if (nsamps == 0) {
              fprintf(stderr, "%s: no viewable scene!\n", progname);
              exit(1);
       }
       threshold = GLAREBR * brsum / nsamps;
       if (threshold <= FTINY) {
              fprintf(stderr, "%s: threshold zero!\n", progname);
              exit(1);
       }
       if (verbose) {
#ifdef DEBUG
              pict_stats();
#endif
              fprintf(stderr,
                     "%s: threshold set to %f cd/m2 from %d samples\n",
                            progname, threshold, nsamps);
       }
}

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:

void done_rtrace ( void  )

Definition at line 290 of file rholo2.c.

{
       int    status;
                                   /* already closed? */
       if (!nprocs)
              return(0);
                                   /* flush beam queue */
       done_packets(flush_queue());
                                   /* sync holodeck */
       hdsync(NULL, 1);
                                   /* close rtrace */
       if ((status = end_rtrace()))
              error(WARNING, "bad exit status from rtrace");
       if (vdef(REPORT)) {         /* report time */
              eputs("rtrace process closed\n");
              report(0);
       }
       return(status);                    /* return status */
}

Here is the call graph for this function:

void fork_rtrace ( char *  av[])

Definition at line 344 of file glareval.c.

{
       int    rval;

       rval = open_process(&rt_pd, av);
       if (rval < 0) {
              perror(progname);
              exit(1);
       }
       if (rval == 0) {
              fprintf(stderr, "%s: command not found\n", av[0]);
              exit(1);
       }
       maxpix = rval/(6*sizeof(float));
       if (maxpix > MAXPIX)
              maxpix = MAXPIX;
       maxpix--;
}

Here is the call graph for this function:

double getviewpix ( int  vh,
int  vv 
)

Definition at line 189 of file glareval.c.

{
       FVECT  dir;
       float  rt_buf[12];
       double res;

       if (compdir(dir, vh, vv) < 0)
              return(-1.0);
       npixinvw++;
       if ((res = pict_val(dir)) >= 0.0)
              return(res);
       if (rt_pd.r == -1) {
              npixmiss++;
              return(-1.0);
       }
       rt_buf[0] = ourview.vp[0];
       rt_buf[1] = ourview.vp[1];
       rt_buf[2] = ourview.vp[2];
       rt_buf[3] = dir[0];
       rt_buf[4] = dir[1];
       rt_buf[5] = dir[2];
       rt_compute(rt_buf, 1);
       return(luminance(rt_buf));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void getviewspan ( int  vv,
float *  vb 
)

Definition at line 219 of file glareval.c.

{
       float  rt_buf[6*MAXPIX];    /* rtrace send/receive buffer */
       register int  n;            /* number of pixels in buffer */
       short  buf_vh[MAXPIX];             /* pixel positions */
       FVECT  dir;
       register int  vh;

#ifdef DEBUG
       if (verbose)
              fprintf(stderr, "%s: computing view span at %d...\n",
                            progname, vv);
#endif
       n = 0;
       for (vh = -hsize; vh <= hsize; vh++) {
              if (compdir(dir, vh, vv) < 0) {           /* not in view */
                     vb[vh+hsize] = -1.0;
                     continue;
              }
              npixinvw++;
              if ((vb[vh+hsize] = pict_val(dir)) >= 0.0)
                     continue;
              if (rt_pd.r == -1) {        /* missing information */
                     npixmiss++;
                     continue;
              }
                                          /* send to rtrace */
              if (n >= maxpix) {                 /* flush */
                     rt_compute(rt_buf, n);
                     while (n-- > 0)
                            vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
              }
              rt_buf[6*n] = ourview.vp[0];
              rt_buf[6*n+1] = ourview.vp[1];
              rt_buf[6*n+2] = ourview.vp[2];
              rt_buf[6*n+3] = dir[0];
              rt_buf[6*n+4] = dir[1];
              rt_buf[6*n+5] = dir[2];
              buf_vh[n++] = vh;
       }
#ifdef DEBUG
       if (verbose)
              pict_stats();
#endif
       if (n > 0) {                       /* process pending buffer */
              rt_compute(rt_buf, n);
              while (n-- > 0)
                     vb[buf_vh[n]+hsize] = luminance(rt_buf+3*n);
       }
}

Here is the call graph for this function:

Here is the caller 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);
}
void open_pict ( char *  fn)

Definition at line 314 of file glareval.c.

{
       if ((pictfp = fopen(fn, "r")) == NULL) {
              fprintf(stderr, "%s: cannot open\n", fn);
              exit(1);
       }
       exposure = 1.0;
       getheader(pictfp, getexpos, NULL);
       if (wrongformat || !fscnresolu(&pxsiz, &pysiz, pictfp)) {
              fprintf(stderr, "%s: incompatible picture format\n", fn);
              exit(1);
       }
       initscans();
}

Here is the call graph for this function:

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:


Variable Documentation

struct source * donelist

Definition at line 32 of file findglare.c.

int hsize

Definition at line 474 of file ra_gif.c.

struct illum * indirect

Definition at line 21 of file findglare.c.

double maxtheta

Definition at line 34 of file findglare.c.

int nglarangs

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.

Definition at line 29 of file pcond.c.

Definition at line 20 of file findglare.c.

char* progname

Definition at line 21 of file histo.c.

Definition at line 21 of file findglare.c.

int sampdens

Definition at line 31 of file findglare.c.

double threshold

Definition at line 29 of file findglare.c.

int verbose

Definition at line 264 of file 3ds2mgf.c.