Back to index

radiance  4R0+20100331
holo.h
Go to the documentation of this file.
00001 /* RCSid: $Id: holo.h,v 3.25 2004/09/09 01:06:19 greg Exp $ */
00002 /*
00003  * Header file for holodeck programs
00004  *
00005  *     9/29/97       GWLarson
00006  */
00007 #ifndef _RAD_HOLO_H_
00008 #define _RAD_HOLO_H_
00009 
00010 #include "standard.h"
00011 #include "color.h"
00012 
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016 
00017 #ifndef HDMAX
00018 #define HDMAX        128    /* maximum active holodeck sections */
00019 #endif
00020 
00021 #ifndef MAXDIRSE
00022 #define MAXDIRSE     32     /* maximum seeks per directory write */
00023 #endif
00024 
00025 #define DCINF (unsigned)((1L<<16)-1)      /* special value for infinity */
00026 #define DCLIN (unsigned)(1L<<11)   /* linear depth limit */
00027 
00028 typedef struct {
00029        BYTE   r[2][2];      /* ray direction index */
00030        COLR   v;            /* color value */
00031        uint16 d;            /* depth code (from entry wall) */
00032 } RAYVAL;            /* ray value */
00033 
00034 /*
00035  * Walls are ordered:              X0     X1     X2     WN
00036  *                          0      ?      ?      0
00037  *                          1      ?      ?      1
00038  *                          ?      0      ?      2
00039  *                          ?      1      ?      3
00040  *                          ?      ?      0      4
00041  *                          ?      ?      1      5
00042  *
00043  * Grid on wall WN corresponds to X(WN/2+1)%3 and X(WN/2+2)%3, resp.
00044  */
00045 
00046 typedef struct {
00047        short  w;            /* wall number */
00048        short  i[2];         /* index on wall grid */
00049 } GCOORD;            /* grid coordinates (two for beam) */
00050 
00051 typedef struct {
00052        uint32 nrd;          /* number of beam rays bundled on disk */
00053        off_t  fo;           /* position in file */
00054 } BEAMI;             /* beam index */
00055 
00056 typedef struct {
00057        uint32 nrm;          /* number of beam rays bundled in memory */
00058        unsigned long tick;  /* clock tick for LRU replacement */
00059 } BEAM;                     /* followed by nrm RAYVAL's */
00060 
00061 #define hdbray(bp)   ((RAYVAL *)((bp)+1))
00062 #define hdbsiz(nr)   (sizeof(BEAM)+(nr)*sizeof(RAYVAL))
00063 
00064 typedef struct {
00065        FVECT  orig;         /* prism origin (first) */
00066        FVECT  xv[3];        /* side vectors (second) */
00067        int16  grid[3];      /* grid resolution (third) */
00068 } HDGRID;            /* holodeck section grid (must match HOLO struct) */
00069 
00070 typedef struct holo {
00071        FVECT  orig;         /* prism origin (first) */
00072        FVECT  xv[3];        /* side vectors (second) */
00073        int16  grid[3];      /* grid resolution (third) */
00074        int    fd;           /* file descriptor */
00075        struct {
00076               int    s, n;         /* dirty section start, length */
00077        } dirseg[MAXDIRSE+1];       /* dirty beam index segments */
00078        short  dirty;        /* number of dirty segments */
00079        double tlin;         /* linear range for depth encoding */
00080        FVECT  wg[3];        /* wall grid vectors (derived) */
00081        int    wi[6];        /* wall super-indices (derived) */
00082        char   *priv;        /* pointer to private client data */
00083        BEAM   **bl;         /* beam pointers (memory cache) */
00084        BEAMI  bi[1];        /* beam index (extends struct) */
00085 } HOLO;                     /* holodeck section */
00086 
00087 typedef struct {
00088        HOLO   *h;           /* pointer to holodeck */
00089        int    b;            /* beam index */
00090 } HDBEAMI;           /* holodeck beam index */
00091 
00092 #define nbeams(hp)   (((hp)->wi[5]-1)<<1)
00093 #define biglob(hp)   ((hp)->bi)
00094 #define blglob(hp)   (*(hp)->bl)
00095 
00096 #define bnrays(hp,i) ((hp)->bl[i]!=NULL ? (hp)->bl[i]->nrm : (hp)->bi[i].nrd)
00097 
00098 #define hdflush(hp)  (hdfreebeam(hp,0), hdsync(hp,0))
00099 #define hdclobber(hp)       (hdkillbeam(hp,0), hdsync(hp,0))
00100 
00101 /*
00102 extern HOLO   *hdinit(), *hdalloc();
00103 extern BEAM   *hdgetbeam();
00104 extern RAYVAL *hdnewrays();
00105 extern unsigned      hdmemuse();
00106 extern off_t  hdfiluse(), hdfilen(), hdallocfrag();
00107 extern double hdray(), hdinter();
00108 extern unsigned      hdcode();
00109 extern int    hdfilord();
00110 */
00111 
00112 #define FF_NEVER     0             /* never free fragments */
00113 #define FF_WRITE     01            /* free fragment on write */
00114 #define FF_ALLOC     02            /* free fragment on ray alloc */
00115 #define FF_READ             04            /* free fragment on read */
00116 #define FF_KILL             010           /* free fragment on beam kill */
00117 
00118 extern int    hdfragflags;         /* tells when to free fragments */
00119 extern unsigned      hdcachesize;         /* target cache size (bytes) */
00120 extern unsigned long hdclock;      /* holodeck system clock */
00121 extern HOLO   *hdlist[HDMAX+1];    /* holodeck pointers (NULL term.) */
00122 
00123 extern float  hd_depthmap[];              /* depth conversion map */
00124 
00125 extern int    hdwg0[6];            /* wall grid 0 index */
00126 extern int    hdwg1[6];            /* wall grid 1 index */
00127 
00128 #define hddepth(hp,dc)      ( (dc) >= DCINF ? FHUGE : \
00129                             (hp)->tlin * ( (dc) >= DCLIN ? \
00130                                    hd_depthmap[(dc)-DCLIN] : \
00131                                    ((dc)+.5)/DCLIN ) )
00132 
00133 #define HOLOFMT             "Holodeck"    /* file format identifier */
00134 #define HOLOVERS     0             /* file format version number */
00135 #define HOLOMAGIC    (323+sizeof(off_t)+8*HOLOVERS)     /* file magic number */
00136 
00137 /*
00138  * A holodeck file consists of an information header terminated by a
00139  * blank line, with "FORMAT=Holodeck" somewhere in it.
00140  * The first integer after the information header is the
00141  * above magic number, which includes the file format version number.
00142  * The first longword after the magic number is a pointer to the pointer
00143  * just before the SECOND holodeck section, or 0 if there is only one.
00144  * This longword is immediately followed by the first holodeck
00145  * section header and directory.
00146  * Similarly, every holodeck section in the file is preceeded by
00147  * a pointer to the following section, or 0 for the final section.
00148  * Since holodeck files consist of directly written C data structures, 
00149  * they are not generally portable between different machine architectures.
00150  * In particular, different floating point formats or bit/byte ordering
00151  * will make the data unusable.  This is unfortunate, and may be changed
00152  * in future versions, but we thought this would be best for paging speed
00153  * in our initial implementation.
00154  */
00155 
00156        /* clumpbeams.c */
00157 extern void clumpbeams(HOLO *hp, int maxcnt, int maxsiz,
00158 int (*cf)(HOLO *hp, int *bqueue, int bqlen));
00159        /* holo.c */
00160 extern void hdcompgrid(HOLO *hp);
00161 extern int hdbcoord(GCOORD gc[2], HOLO *hp, int i);
00162 extern int hdbindex(HOLO *hp, GCOORD gc[2]);
00163 extern void hdcell(FVECT cp[4], HOLO *hp, GCOORD *gc);
00164 extern int hdlseg(int       lseg[2][3], HOLO     *hp, GCOORD   gc[2]);
00165 extern unsigned int hdcode(HOLO *hp, double d);
00166 extern void hdgrid( FVECT gp, HOLO *hp, FVECT wp);
00167 extern void hdworld(FVECT wp, HOLO *hp, FVECT gp);
00168 extern double hdray(FVECT ro, FVECT rd, HOLO *hp, GCOORD gc[2], BYTE r[2][2]);
00169 extern double hdinter(GCOORD gc[2], BYTE r[2][2], double *ed, HOLO *hp,
00170               FVECT ro, FVECT rd);
00171        /* holofile.c */
00172 extern HOLO * hdinit(int fd, HDGRID *hproto);
00173 extern void hddone(HOLO *hp);
00174 extern int hdsync(HOLO *hp, int all);
00175 extern off_t hdfilen(int fd);
00176 extern off_t hdfiluse(int fd);
00177 extern RAYVAL * hdnewrays(HOLO *hp, int i, int nr);
00178 extern BEAM * hdgetbeam(HOLO *hp, int i);
00179 extern void hdloadbeams(HDBEAMI *hb, int n, void (*bf)(BEAM *bp, HDBEAMI *hb));
00180 extern int hdfreebeam(HOLO *hp, int i);
00181 extern int hdfreefrag(HOLO *hp, int i);
00182 extern int hdfragOK(int fd, int *listlen, int32 *listsiz);
00183 extern int hdkillbeam(HOLO *hp, int i);
00184 
00185 
00186 #ifdef __cplusplus
00187 }
00188 #endif
00189 #endif /* _RAD_HOLO_H_ */
00190