Back to index

radiance  4R0+20100331
Defines | Functions | Variables
rhdisp2.c File Reference
#include "rholo.h"
#include "rhdisp.h"
#include "rhdriver.h"

Go to the source code of this file.

Defines

#define MEYERNG   0.2 /* target mean eye range (rel. to grid) */
#define CBEAMBLK   1024 /* cbeam allocation block size */

Functions

static int newcbeam (void)
static int cbeamcmp (const void *cb1, const void *cb2)
static int cbeamcmp2 (const void *cb1, const void *cb2)
static int findcbeam (int hd, int bi)
static int getcbeam (int hd, int bi)
static void cbeamsort (int adopt)
static int getcbeam (register int hd, int bi)
void beam_init (int fresh)
int16 * beam_view (VIEW *vn, int hr, int vr)
int beam_sync (int all)
void gridlines (void(*f)(FVECT wp[2]))

Variables

static const char RCSid [] = "$Id: rhdisp2.c,v 3.37 2004/01/01 11:21:55 schorsch Exp $"
static PACKHEADcbeam = NULL
static int ncbeams = 0
static int xcbeams = 0
static int maxcbeam = 0
VIEWPOINT cureye

Define Documentation

#define CBEAMBLK   1024 /* cbeam allocation block size */

Definition at line 16 of file rhdisp2.c.

#define MEYERNG   0.2 /* target mean eye range (rel. to grid) */

Definition at line 13 of file rhdisp2.c.


Function Documentation

void beam_init ( int  fresh)

Definition at line 153 of file rhdisp2.c.

{
       register int  i;

       if (fresh)                  /* discard old beams? */
              ncbeams = xcbeams = 0;
       else                        /* else clear sample requests */
              for (i = ncbeams+xcbeams; i--; )
                     cbeam[i].nr = 0;
       cureye.rng = 0.;
}

Here is the caller graph for this function:

int beam_sync ( int  all)

Definition at line 220 of file rhdisp2.c.

{
                                   /* set new eye position */
       serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye);
                                   /* sort list (put orphans at end) */
       cbeamsort(all < 0);
                                   /* send beam request */
       if (all) {
              if (ncbeams > 0)
                     serv_request(DR_NEWSET,
                                   ncbeams*sizeof(PACKHEAD), (char *)cbeam);
       } else {
              if (ncbeams+xcbeams > 0)
                     serv_request(DR_ADJSET,
                            (ncbeams+xcbeams)*sizeof(PACKHEAD), (char *)cbeam);
       }
       xcbeams = 0;                /* truncate our list */
       return(ncbeams);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int16* beam_view ( VIEW vn,
int  hr,
int  vr 
)

Definition at line 169 of file rhdisp2.c.

{
       int16  *slist;
       BEAMLIST      blist;
       double eravg, d;
       register HOLO *hp;
       register int  i, n;
                                   /* compute beams for view */
       slist = viewbeams(vn, hr, vr, &blist);
       if (*slist < 0) {
              error(COMMAND, "no sections visible from this view");
              return(NULL);
       }
                                   /* sort current beam list */
       cbeamsort(1);
                                   /* add new beams to list */
       for (i = blist.nb; i--; ) {
              n = getcbeam(blist.bl[i].hd, blist.bl[i].bi);
              if (blist.bl[i].nr > cbeam[n].nr)
                     cbeam[n].nr = blist.bl[i].nr;
       }
       free((void *)blist.bl);            /* free list */
       if (MEYERNG <= FTINY)
              return(slist);
                                   /* compute average eye range */
       eravg = 0.;
       for (n = 0; slist[n] >= 0; n++) {
              hp = hdlist[slist[n]];
              eravg +=      MEYERNG/3. / VLEN(hp->wg[0]) +
                            MEYERNG/3. / VLEN(hp->wg[1]) +
                            MEYERNG/3. / VLEN(hp->wg[2]) ;
       }
       eravg /= (double)n;
                                   /* add to current eye position */
       if (cureye.rng <= FTINY) {
              VCOPY(cureye.vpt, vn->vp);
              cureye.rng = eravg;
       } else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + eravg > cureye.rng) {
              for (i = 3; i--; )
                     cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]);
              cureye.rng = 0.5*(cureye.rng + eravg + d);
       }
       return(slist);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int cbeamcmp ( const void *  cb1,
const void *  cb2 
) [static]

Definition at line 54 of file rhdisp2.c.

{
       register int  c;

       if ((c = ((PACKHEAD*)cb1)->bi - ((PACKHEAD*)cb2)->bi))  /* sort on beam index first */
              return(c);
       return(((PACKHEAD*)cb1)->hd - ((PACKHEAD*)cb2)->hd);    /* use hd to resolve matches */
}

Here is the caller graph for this function:

static int cbeamcmp2 ( const void *  cb1,
const void *  cb2 
) [static]

Definition at line 68 of file rhdisp2.c.

{
       register int  c;

       if (!((PACKHEAD*)cb1)->nr)                /* put orphans at the end, unsorted */
              return(((PACKHEAD*)cb2)->nr);
       if (!((PACKHEAD*)cb2)->nr)
              return(-1);
       if ((c = ((PACKHEAD*)cb1)->bi - ((PACKHEAD*)cb2)->bi))  /* sort on beam index first */
              return(c);
       return(((PACKHEAD*)cb1)->hd - ((PACKHEAD*)cb2)->hd);    /* use hd to resolve matches */
}

Here is the caller graph for this function:

static void cbeamsort ( int  adopt) [static]

Definition at line 131 of file rhdisp2.c.

{
       register int  i;

       if (!(ncbeams += xcbeams))
              return;
       xcbeams = 0;
       qsort((char *)cbeam, ncbeams, sizeof(PACKHEAD),
                     adopt ? cbeamcmp : cbeamcmp2);
       if (adopt)
              return;
       for (i = ncbeams; i--; )    /* identify orphans */
              if (cbeam[i].nr)
                     break;
       xcbeams = ncbeams - ++i;    /* put orphans after ncbeams */
       ncbeams = i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int findcbeam ( int  hd,
int  bi 
) [static]

Definition at line 86 of file rhdisp2.c.

{
       PACKHEAD      cb;
       register PACKHEAD    *p;

       if (ncbeams <= 0)
              return(-1);
       cb.hd = hd; cb.bi = bi; cb.nr = cb.nc = 0;
       p = (PACKHEAD *)bsearch((char *)&cb, (char *)cbeam, ncbeams,
                     sizeof(PACKHEAD), cbeamcmp);
       if (p == NULL)
              return(-1);
       return(p - cbeam);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int getcbeam ( int  hd,
int  bi 
) [static]

Here is the caller graph for this function:

static int getcbeam ( register int  hd,
int  bi 
) [static]

Definition at line 106 of file rhdisp2.c.

{
       register int  n;
                            /* first, look in sorted list */
       if ((n = findcbeam(hd, bi)) >= 0)
              return(n);
                            /* linear search through xcbeams to be sure */
       for (n = ncbeams+xcbeams; n-- > ncbeams; )
              if (cbeam[n].bi == bi && cbeam[n].hd == hd)
                     return(n);
                            /* check legality */
       if ((hd < 0) | (hd >= HDMAX) || hdlist[hd] == NULL)
              error(INTERNAL, "illegal holodeck number in getcbeam");
       if ((bi < 1) | (bi > nbeams(hdlist[hd])))
              error(INTERNAL, "illegal beam index in getcbeam");
       n = newcbeam();             /* allocate and assign */
       cbeam[n].hd = hd; cbeam[n].bi = bi; cbeam[n].nr = cbeam[n].nc = 0;
       return(n);
}

Here is the call graph for this function:

void gridlines ( void(*)(FVECT wp[2])  f)

Definition at line 244 of file rhdisp2.c.

{
       register int  hd, w, i;
       int    g0, g1;
       FVECT  wp[2], mov;
       double d;
                                   /* do each wall on each section */
       for (hd = 0; hdlist[hd] != NULL; hd++)
              for (w = 0; w < 6; w++) {
                     g0 = hdwg0[w];
                     g1 = hdwg1[w];
                     d = 1.0/hdlist[hd]->grid[g0];
                     mov[0] = d * hdlist[hd]->xv[g0][0];
                     mov[1] = d * hdlist[hd]->xv[g0][1];
                     mov[2] = d * hdlist[hd]->xv[g0][2];
                     if (w & 1) {
                            VSUM(wp[0], hdlist[hd]->orig,
                                          hdlist[hd]->xv[w>>1], 1.);
                            VSUM(wp[0], wp[0], mov, 1.);
                     } else
                            VCOPY(wp[0], hdlist[hd]->orig);
                     VSUM(wp[1], wp[0], hdlist[hd]->xv[g1], 1.);
                     for (i = hdlist[hd]->grid[g0]; ; ) {      /* g0 lines */
                            (*f)(wp);
                            if (!--i) break;
                            wp[0][0] += mov[0]; wp[0][1] += mov[1];
                            wp[0][2] += mov[2]; wp[1][0] += mov[0];
                            wp[1][1] += mov[1]; wp[1][2] += mov[2];
                     }
                     d = 1.0/hdlist[hd]->grid[g1];
                     mov[0] = d * hdlist[hd]->xv[g1][0];
                     mov[1] = d * hdlist[hd]->xv[g1][1];
                     mov[2] = d * hdlist[hd]->xv[g1][2];
                     if (w & 1)
                            VSUM(wp[0], hdlist[hd]->orig,
                                          hdlist[hd]->xv[w>>1], 1.);
                     else
                            VSUM(wp[0], hdlist[hd]->orig, mov, 1.);
                     VSUM(wp[1], wp[0], hdlist[hd]->xv[g0], 1.);
                     for (i = hdlist[hd]->grid[g1]; ; ) {      /* g1 lines */
                            (*f)(wp);
                            if (!--i) break;
                            wp[0][0] += mov[0]; wp[0][1] += mov[1];
                            wp[0][2] += mov[2]; wp[1][0] += mov[0];
                            wp[1][1] += mov[1]; wp[1][2] += mov[2];
                     }
              }
}
static int newcbeam ( void  ) [static]

Definition at line 34 of file rhdisp2.c.

{
       int    i;

       if ((i = ncbeams + xcbeams++) >= maxcbeam) {     /* grow array */
              maxcbeam += CBEAMBLK;
              if (cbeam == NULL)
                     cbeam = (PACKHEAD *)malloc(
                                   maxcbeam*sizeof(PACKHEAD) );
              else
                     cbeam = (PACKHEAD *)realloc((void *)cbeam,
                                   maxcbeam*sizeof(PACKHEAD) );
              if (cbeam == NULL)
                     error(SYSTEM, "out of memory in newcbeam");
       }
       return(i);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

PACKHEAD* cbeam = NULL [static]

Definition at line 18 of file rhdisp2.c.

Definition at line 23 of file rhdisp2.c.

int maxcbeam = 0 [static]

Definition at line 21 of file rhdisp2.c.

int ncbeams = 0 [static]

Definition at line 19 of file rhdisp2.c.

const char RCSid[] = "$Id: rhdisp2.c,v 3.37 2004/01/01 11:21:55 schorsch Exp $" [static]

Definition at line 2 of file rhdisp2.c.

int xcbeams = 0 [static]

Definition at line 20 of file rhdisp2.c.