Back to index

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

Go to the source code of this file.

Classes

struct  RAYVAL
struct  GCOORD
struct  BEAMI
struct  BEAM
struct  HDGRID
struct  holo
struct  HDBEAMI
struct  holo.dirseg

Defines

#define HDMAX   128 /* maximum active holodeck sections */
#define MAXDIRSE   32 /* maximum seeks per directory write */
#define DCINF   (unsigned)((1L<<16)-1) /* special value for infinity */
#define DCLIN   (unsigned)(1L<<11) /* linear depth limit */
#define hdbray(bp)   ((RAYVAL *)((bp)+1))
#define hdbsiz(nr)   (sizeof(BEAM)+(nr)*sizeof(RAYVAL))
#define nbeams(hp)   (((hp)->wi[5]-1)<<1)
#define biglob(hp)   ((hp)->bi)
#define blglob(hp)   (*(hp)->bl)
#define bnrays(hp, i)   ((hp)->bl[i]!=NULL ? (hp)->bl[i]->nrm : (hp)->bi[i].nrd)
#define hdflush(hp)   (hdfreebeam(hp,0), hdsync(hp,0))
#define hdclobber(hp)   (hdkillbeam(hp,0), hdsync(hp,0))
#define FF_NEVER   0 /* never free fragments */
#define FF_WRITE   01 /* free fragment on write */
#define FF_ALLOC   02 /* free fragment on ray alloc */
#define FF_READ   04 /* free fragment on read */
#define FF_KILL   010 /* free fragment on beam kill */
#define hddepth(hp, dc)
#define HOLOFMT   "Holodeck" /* file format identifier */
#define HOLOVERS   0 /* file format version number */
#define HOLOMAGIC   (323+sizeof(off_t)+8*HOLOVERS) /* file magic number */

Typedefs

typedef struct holo HOLO

Functions

void clumpbeams (HOLO *hp, int maxcnt, int maxsiz, int(*cf)(HOLO *hp, int *bqueue, int bqlen))
void hdcompgrid (HOLO *hp)
int hdbcoord (GCOORD gc[2], HOLO *hp, int i)
int hdbindex (HOLO *hp, GCOORD gc[2])
void hdcell (FVECT cp[4], HOLO *hp, GCOORD *gc)
int hdlseg (int lseg[2][3], HOLO *hp, GCOORD gc[2])
unsigned int hdcode (HOLO *hp, double d)
void hdgrid (FVECT gp, HOLO *hp, FVECT wp)
void hdworld (FVECT wp, HOLO *hp, FVECT gp)
double hdray (FVECT ro, FVECT rd, HOLO *hp, GCOORD gc[2], BYTE r[2][2])
double hdinter (GCOORD gc[2], BYTE r[2][2], double *ed, HOLO *hp, FVECT ro, FVECT rd)
HOLOhdinit (int fd, HDGRID *hproto)
void hddone (HOLO *hp)
int hdsync (HOLO *hp, int all)
off_t hdfilen (int fd)
off_t hdfiluse (int fd)
RAYVALhdnewrays (HOLO *hp, int i, int nr)
BEAMhdgetbeam (HOLO *hp, int i)
void hdloadbeams (HDBEAMI *hb, int n, void(*bf)(BEAM *bp, HDBEAMI *hb))
int hdfreebeam (HOLO *hp, int i)
int hdfreefrag (HOLO *hp, int i)
int hdfragOK (int fd, int *listlen, int32 *listsiz)
int hdkillbeam (HOLO *hp, int i)

Variables

int hdfragflags
unsigned hdcachesize
unsigned long hdclock
HOLOhdlist [HDMAX+1]
float hd_depthmap []
int hdwg0 [6]
int hdwg1 [6]

Class Documentation

struct RAYVAL

Definition at line 28 of file holo.h.

Class Members
uint16 d
BYTE r
COLR v
struct GCOORD

Definition at line 46 of file holo.h.

Class Members
short i
short w
struct BEAMI

Definition at line 51 of file holo.h.

Class Members
off_t fo
uint32 nrd
struct BEAM

Definition at line 56 of file holo.h.

Class Members
uint32 nrm
unsigned long tick
struct HDGRID

Definition at line 64 of file holo.h.

Class Members
int16 grid
FVECT orig
FVECT xv
struct holo

Definition at line 70 of file holo.h.

Collaboration diagram for holo:
Class Members
BEAMI bi
BEAM ** bl
struct holo dirseg
short dirty
int fd
int16 grid
FVECT orig
char * priv
double tlin
FVECT wg
int wi
FVECT xv
struct HDBEAMI

Definition at line 87 of file holo.h.

Collaboration diagram for HDBEAMI:
Class Members
int b
HOLO * h
struct holo.dirseg

Definition at line 75 of file holo.h.

Class Members
int n
int s

Define Documentation

#define biglob (   hp)    ((hp)->bi)

Definition at line 93 of file holo.h.

#define blglob (   hp)    (*(hp)->bl)

Definition at line 94 of file holo.h.

#define bnrays (   hp,
  i 
)    ((hp)->bl[i]!=NULL ? (hp)->bl[i]->nrm : (hp)->bi[i].nrd)

Definition at line 96 of file holo.h.

#define DCINF   (unsigned)((1L<<16)-1) /* special value for infinity */

Definition at line 25 of file holo.h.

#define DCLIN   (unsigned)(1L<<11) /* linear depth limit */

Definition at line 26 of file holo.h.

#define FF_ALLOC   02 /* free fragment on ray alloc */

Definition at line 114 of file holo.h.

#define FF_KILL   010 /* free fragment on beam kill */

Definition at line 116 of file holo.h.

#define FF_NEVER   0 /* never free fragments */

Definition at line 112 of file holo.h.

#define FF_READ   04 /* free fragment on read */

Definition at line 115 of file holo.h.

#define FF_WRITE   01 /* free fragment on write */

Definition at line 113 of file holo.h.

#define hdbray (   bp)    ((RAYVAL *)((bp)+1))

Definition at line 61 of file holo.h.

#define hdbsiz (   nr)    (sizeof(BEAM)+(nr)*sizeof(RAYVAL))

Definition at line 62 of file holo.h.

#define hdclobber (   hp)    (hdkillbeam(hp,0), hdsync(hp,0))

Definition at line 99 of file holo.h.

#define hddepth (   hp,
  dc 
)
Value:
( (dc) >= DCINF ? FHUGE : \
                            (hp)->tlin * ( (dc) >= DCLIN ? \
                                   hd_depthmap[(dc)-DCLIN] : \
                                   ((dc)+.5)/DCLIN ) )

Definition at line 128 of file holo.h.

#define hdflush (   hp)    (hdfreebeam(hp,0), hdsync(hp,0))

Definition at line 98 of file holo.h.

#define HDMAX   128 /* maximum active holodeck sections */

Definition at line 18 of file holo.h.

#define HOLOFMT   "Holodeck" /* file format identifier */

Definition at line 133 of file holo.h.

#define HOLOMAGIC   (323+sizeof(off_t)+8*HOLOVERS) /* file magic number */

Definition at line 135 of file holo.h.

#define HOLOVERS   0 /* file format version number */

Definition at line 134 of file holo.h.

#define MAXDIRSE   32 /* maximum seeks per directory write */

Definition at line 22 of file holo.h.

#define nbeams (   hp)    (((hp)->wi[5]-1)<<1)

Definition at line 92 of file holo.h.


Typedef Documentation

typedef struct holo HOLO

Function Documentation

void clumpbeams ( HOLO hp,
int  maxcnt,
int  maxsiz,
int(*)(HOLO *hp, int *bqueue, int bqlen)  cf 
)
int hdbcoord ( GCOORD  gc[2],
HOLO hp,
int  i 
)
int hdbindex ( HOLO hp,
GCOORD  gc[2] 
)
void hdcell ( FVECT  cp[4],
HOLO hp,
GCOORD gc 
)
unsigned int hdcode ( HOLO hp,
double  d 
)

Definition at line 190 of file holo.c.

{
       double tl = hp->tlin;
       register long c;

       if (d <= 0.)
              return(0);
       if (d >= .99*FHUGE)
              return(DCINF);
       if (d < tl)
              return((unsigned)(d*DCLIN/tl));
       c = (long)(log(d/tl)/logstep) + DCLIN;
       return(c > DCINF ? (unsigned)DCINF : (unsigned)c);
}

Here is the caller graph for this function:

void hdcompgrid ( HOLO hp)
void hddone ( HOLO hp)

Here is the caller graph for this function:

off_t hdfilen ( int  fd)

Definition at line 385 of file holofile.c.

{
       off_t  fpos, flen;

       if (fd < 0)
              return(-1);
       if (fd >= nhdfragls || !hdfragl[fd].nlinks) {
              if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0)
                     return(-1);
              flen = lseek(fd, (off_t)0, SEEK_END);
              lseek(fd, fpos, SEEK_SET);
              return(flen);
       }
       return(hdfragl[fd].flen);
}

Here is the caller graph for this function:

off_t hdfiluse ( int  fd)

Definition at line 405 of file holofile.c.

{
       off_t  total = 0;
       register int  j;

       for (j = 0; hdlist[j] != NULL; j++) {
              if (hdlist[j]->fd != fd)
                     continue;
              total += biglob(hdlist[j])->nrd * sizeof(RAYVAL);
              total += nbeams(hdlist[j])*sizeof(BEAMI) + sizeof(HDGRID);
#if 0
              for (i = nbeams(hdlist[j]); i > 0; i--)
                     if (hdlist[j]->bl[i] != NULL)
                            total += sizeof(RAYVAL) *
                                          (hdlist[j]->bl[i]->nrm -
                                          hdlist[j]->bi[i].nrd);
#endif
       }
       return(total);              /* doesn't include fragments, unflushed rays */
}

Here is the caller graph for this function:

int hdfragOK ( int  fd,
int *  listlen,
int32 *  listsiz 
)

Here is the caller graph for this function:

int hdfreebeam ( HOLO hp,
int  i 
)

Here is the caller graph for this function:

int hdfreefrag ( HOLO hp,
int  i 
)

Definition at line 575 of file holofile.c.

{
       register BEAMI       *bi = &hp->bi[i];
       register struct fraglist    *f;
       register int  j, k;

       if (bi->nrd <= 0)
              return(0);
       DCHECK(hp->fd < 0 | hp->fd >= nhdfragls || !hdfragl[hp->fd].nlinks,
                     CONSISTENCY, "bad file descriptor in hdfreefrag");
       f = &hdfragl[hp->fd];
       if (!f->writable)
              return(0);
       if (f->nfrags % FRAGBLK == 0) {    /* delete empty remnants */
              for (j = k = 0; k < f->nfrags; j++, k++) {
                     while (f->fi[k].nrd == 0)
                            if (++k >= f->nfrags)
                                   goto endloop;
                     if (k > j)
                            *(f->fi+j) = *(f->fi+k);
              }
       endloop:
              f->nfrags = j;
       }
       j = f->nfrags++;            /* allocate a slot in free list */
#if MAXFRAGB
       if (j >= MAXFRAGB*FRAGBLK) {
              f->nfrags = j--;     /* stop list growth */
              if (bi->nrd <= f->fi[j].nrd)
                     return(0);    /* new one no better than discard */
       }
#endif
       if (j % FRAGBLK == 0) {            /* more (or less) free list space */
              register BEAMI       *newp;
              if (f->fi == NULL)
                     newp = (BEAMI *)malloc((j+FRAGBLK)*sizeof(BEAMI));
              else
                     newp = (BEAMI *)realloc((void *)f->fi,
                                   (j+FRAGBLK)*sizeof(BEAMI));
              if (newp == NULL) {
                     f->nfrags--;  /* graceful failure */
                     return(0);
              }
              f->fi = newp;
       }
       for ( ; ; j--) {            /* insert in descending list */
              if (!j || bi->fo < f->fi[j-1].fo) {
                     f->fi[j].fo = bi->fo;
                     f->fi[j].nrd = bi->nrd;
                     break;
              }
              *(f->fi+j) = *(f->fi+(j-1));
       }
                                   /* coalesce adjacent fragments */
                                          /* successors never empty */
       if (j && f->fi[j-1].fo == f->fi[j].fo + f->fi[j].nrd*sizeof(RAYVAL)) {
              f->fi[j].nrd += f->fi[j-1].nrd;
              f->fi[j-1].nrd = 0;
       }
       for (k = j+1; k < f->nfrags; k++)  /* get non-empty predecessor */
              if (f->fi[k].nrd) {
                     if (f->fi[j].fo == f->fi[k].fo +
                                   f->fi[k].nrd*sizeof(RAYVAL)) {
                            f->fi[k].nrd += f->fi[j].nrd;
                            f->fi[j].nrd = 0;
                     }
                     break;
              }
       biglob(hp)->nrd -= bi->nrd;        /* tell fragment it's free */
       bi->nrd = 0;
       bi->fo = 0;
       hdmarkdirty(hp, i);                /* assume we'll reallocate */
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

BEAM* hdgetbeam ( HOLO hp,
int  i 
)

Here is the caller graph for this function:

void hdgrid ( FVECT  gp,
HOLO hp,
FVECT  wp 
)
HOLO* hdinit ( int  fd,
HDGRID hproto 
)

Definition at line 180 of file holofile.c.

{
       off_t  rtrunc;
       off_t  fpos;
       int    writable;
       register HOLO *hp;
       register int  n;
                                   /* prepare for system errors */
       errno = 0;
       if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0)
              error(SYSTEM, "cannot determine holodeck file position");
       if (hproto == NULL) {              /* assume we're loading it */
              HDGRID hpr;
                                          /* load header */
              if (read(fd, (char *)&hpr, sizeof(HDGRID)) != sizeof(HDGRID))
                     error(SYSTEM, "cannot load holodeck header");
                                          /* allocate grid */
              if ((hp = hdalloc(&hpr)) == NULL)
                     goto memerr;
                                          /* load beam directory */
              n = nbeams(hp)*sizeof(BEAMI);
              if (read(fd, (char *)(hp->bi+1), n) != n)
                     error(SYSTEM, "failure loading holodeck directory");
                                          /* check that it's clean */
              for (n = nbeams(hp); n > 0; n--)
                     if (hp->bi[n].fo < 0) {
                            hp->bi[n].fo = 0;
                            error(WARNING, "dirty holodeck section");
                            break;
                     }
                                          /* check writability */
              if (fd < nhdfragls && hdfragl[fd].nlinks)
                     writable = hdfragl[fd].writable;
              else
                     writable = lseek(fd, fpos, SEEK_SET) == fpos &&
                            write(fd, (char *)hp, sizeof(HDGRID)) ==
                                                 sizeof(HDGRID);
       } else {                    /* else assume we're creating it */
              if ((hp = hdalloc(hproto)) == NULL)
                     goto memerr;
                                          /* write header and skeleton */
              n = nbeams(hp)*sizeof(BEAMI);
              if (write(fd, (char *)hproto, sizeof(HDGRID)) !=
                                   sizeof(HDGRID) ||
                            write(fd, (char *)(hp->bi+1), n) != n)
                     error(SYSTEM, "cannot write header to holodeck file");
              writable = 1;
       }
       hp->fd = fd;  
       hp->dirty = 0;
       biglob(hp)->fo = fpos + sizeof(HDGRID);
                                   /* start tracking fragments */
       hdattach(fd, writable);
                                   /* check rays on disk */
       fpos = hdfilen(fd);
       biglob(hp)->nrd = rtrunc = 0;
       for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--)
              if (hp->bi[n].nrd) {
                     if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) {
                            rtrunc += hp->bi[n].nrd;
                            hp->bi[n].nrd = 0;
                     } else
                            biglob(hp)->nrd += hp->bi[n].nrd;
              }
       if (rtrunc) {
              sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)",
                            rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd));
              error(WARNING, errmsg);
       }
                                   /* add to holodeck list */
       for (n = 0; n < HDMAX; n++)
              if (hdlist[n] == NULL) {
                     hdlist[n] = hp;
                     break;
              }
                                   /* all done */
       return(hp);
memerr:
       error(SYSTEM, "cannot allocate holodeck grid");
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

double hdinter ( GCOORD  gc[2],
BYTE  r[2][2],
double *  ed,
HOLO hp,
FVECT  ro,
FVECT  rd 
)
int hdkillbeam ( HOLO hp,
int  i 
)

Here is the caller graph for this function:

void hdloadbeams ( HDBEAMI hb,
int  n,
void(*)(BEAM *bp, HDBEAMI *hb)  bf 
)

Here is the caller graph for this function:

int hdlseg ( int  lseg[2][3],
HOLO hp,
GCOORD  gc[2] 
)
RAYVAL* hdnewrays ( HOLO hp,
int  i,
int  nr 
)

Here is the caller graph for this function:

double hdray ( FVECT  ro,
FVECT  rd,
HOLO hp,
GCOORD  gc[2],
BYTE  r[2][2] 
)

Definition at line 246 of file holo.c.

{
       FVECT  cp[4], p[2];
       register int  i, j;
       double d0, d1;
                                   /* compute entry and exit points */
       for (i = 0; i < 2; i++) {
              hdcell(cp, hp, gc+i);
              d0 = (1./256.)*(r[i][0]+.5);
              d1 = (1./256.)*(r[i][1]+.5);
              for (j = 0; j < 3; j++)
                     p[i][j] = (1.-d0-d1)*cp[0][j] +
                                   d0*cp[1][j] + d1*cp[2][j];
       }
       VCOPY(ro, p[0]);            /* assign ray origin and direction */
       VSUB(rd, p[1], p[0]);
       return(normalize(rd));             /* return maximum inside distance */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int hdsync ( HOLO hp,
int  all 
)

Here is the caller graph for this function:

void hdworld ( FVECT  wp,
HOLO hp,
FVECT  gp 
)

Variable Documentation

float hd_depthmap[]

Definition at line 12 of file holo.c.

unsigned hdcachesize

Definition at line 52 of file holofile.c.

unsigned long hdclock

Definition at line 53 of file holofile.c.

Definition at line 51 of file holofile.c.

Definition at line 55 of file holofile.c.

int hdwg0[6]

Definition at line 14 of file holo.c.

int hdwg1[6]

Definition at line 15 of file holo.c.