Back to index

radiance  4R0+20100331
octree.h
Go to the documentation of this file.
00001 /* RCSid $Id: octree.h,v 2.12 2009/11/01 04:41:55 greg Exp $ */
00002 /*
00003  *  octree.h - header file for routines using octrees.
00004  */
00005 #ifndef _RAD_OCTREE_H_
00006 #define _RAD_OCTREE_H_
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010 
00011 /*
00012  *     An octree is expressed as an integer which is either
00013  *     an index to eight other nodes, the empty tree, or an index
00014  *     to a set of objects.  If the octree has a value:
00015  *
00016  *            > -1:  it is an index to eight other nodes.
00017  *
00018  *            -1:    it is empty
00019  *
00020  *            < -1:  it is an index to a set of objects
00021  */
00022 
00023 #ifndef  OCTREE
00024 #define  OCTREE             int
00025 #endif
00026 
00027 #define  EMPTY              (-1)
00028 
00029 #define  isempty(ot) ((ot) == EMPTY)
00030 #define  isfull(ot)  ((ot) < EMPTY)
00031 #define  istree(ot)  ((ot) > EMPTY)
00032 
00033 #define  oseti(ot)   (-(ot)-2)     /* object set index */
00034 #define  OCTBLKSIZ   04000         /* octree block size */
00035 #define  octbi(ot)   ((ot)>>11)    /* octree block index */
00036 #define  octti(ot)   (((ot)&03777)<<3)/* octree index in block */
00037 
00038 #ifndef  MAXOBLK
00039 #ifdef  SMLMEM
00040 #define  MAXOBLK     4095          /* maximum octree block */
00041 #else
00042 #define  MAXOBLK     32767         /* maximum octree block */
00043 #endif
00044 #endif
00045 
00046 extern OCTREE  *octblock[MAXOBLK]; /* octree blocks */
00047 
00048 #define  octkid(ot,br)      (octblock[octbi(ot)][octti(ot)+br])
00049 
00050 /*
00051  *     The cube structure is used to hold an octree and its cubic
00052  *     boundaries.
00053  */
00054 
00055 typedef struct {
00056        FVECT  cuorg;               /* the cube origin */
00057        double  cusize;                    /* the cube size */
00058        OCTREE  cutree;                    /* the octree for this cube */
00059 }  CUBE;
00060 
00061 extern CUBE  thescene;                    /* the main scene */
00062 
00063                             /* flags for reading and writing octrees */
00064 #define  IO_CHECK    0             /* verify file type */
00065 #define  IO_INFO     01            /* information header */
00066 #define  IO_SCENE    02            /* objects */
00067 #define  IO_TREE     04            /* octree */
00068 #define  IO_FILES    010           /* object file names */
00069 #define  IO_BOUNDS   020           /* octree boundary */
00070 #define  IO_ALL             (~0)          /* everything */
00071                             /* octree format identifier */
00072 #define  OCTFMT             "Radiance_octree"
00073                             /* magic number for octree files */
00074 #define  MAXOBJSIZ   8             /* maximum sizeof(OBJECT) */
00075 #define  OCTMAGIC    ( 4 *MAXOBJSIZ+251)  /* increment first value */
00076                             /* octree node types */
00077 #define  OT_EMPTY    0
00078 #define  OT_FULL     1
00079 #define  OT_TREE     2
00080                             /* return values for surface functions */
00081 #define  O_MISS             0             /* no intersection */
00082 #define  O_HIT              1             /* intersection */
00083 #define  O_IN        2             /* cube contained entirely */
00084 
00085 
00086 extern OCTREE octalloc(void);
00087 extern void   octfree(OCTREE ot);
00088 extern void   octdone(void);
00089 extern OCTREE combine(OCTREE ot);
00090 extern void   culocate(CUBE *cu, FVECT pt);
00091 extern int    incube(CUBE *cu, FVECT pt);
00092 
00093 extern int    readoct(char *fname, int load, CUBE *scene, char *ofn[]);
00094 
00095 extern void   readscene(FILE *fp, int objsiz);
00096 extern void   writescene(int firstobj, int nobjs, FILE *fp);
00097 
00098 
00099 #ifdef __cplusplus
00100 }
00101 #endif
00102 #endif /* _RAD_OCTREE_H_ */
00103