| 1 |
greg |
1.1 |
/* Copyright (c) 1986 Regents of the University of California */ |
| 2 |
|
|
|
| 3 |
|
|
/* SCCSid "$SunId$ LBL" */ |
| 4 |
|
|
|
| 5 |
|
|
/* |
| 6 |
|
|
* octree.h - header file for routines using octrees. |
| 7 |
|
|
* |
| 8 |
|
|
* 7/28/85 |
| 9 |
|
|
*/ |
| 10 |
|
|
|
| 11 |
|
|
/* |
| 12 |
|
|
* An octree is expressed as an integer which is either |
| 13 |
|
|
* an index to eight other nodes, the empty tree, or an index |
| 14 |
|
|
* to a set of objects. If the octree has a value: |
| 15 |
|
|
* |
| 16 |
|
|
* > -1: it is an index to eight other nodes. |
| 17 |
|
|
* |
| 18 |
|
|
* -1: it is empty |
| 19 |
|
|
* |
| 20 |
|
|
* < -1: it is an index to a set of objects |
| 21 |
|
|
*/ |
| 22 |
|
|
|
| 23 |
greg |
1.5 |
#ifndef OCTREE |
| 24 |
|
|
#define OCTREE int |
| 25 |
|
|
#endif |
| 26 |
greg |
1.1 |
|
| 27 |
|
|
#define EMPTY (-1) |
| 28 |
|
|
|
| 29 |
|
|
#define isempty(ot) ((ot) == EMPTY) |
| 30 |
|
|
#define isfull(ot) ((ot) < EMPTY) |
| 31 |
|
|
#define istree(ot) ((ot) > EMPTY) |
| 32 |
|
|
|
| 33 |
|
|
#define oseti(ot) (-(ot)-2) /* object set index */ |
| 34 |
|
|
#define octbi(ot) ((ot)>>8) /* octree block index */ |
| 35 |
|
|
#define octti(ot) (((ot)&0377)<<3)/* octree index in block */ |
| 36 |
|
|
|
| 37 |
greg |
1.5 |
#ifndef MAXOBLK |
| 38 |
|
|
#ifdef BIGMEM |
| 39 |
|
|
#define MAXOBLK 8191 /* maximum octree block */ |
| 40 |
|
|
#else |
| 41 |
greg |
1.1 |
#define MAXOBLK 4095 /* maximum octree block */ |
| 42 |
greg |
1.5 |
#endif |
| 43 |
|
|
#endif |
| 44 |
greg |
1.1 |
|
| 45 |
|
|
extern OCTREE *octblock[MAXOBLK]; /* octree blocks */ |
| 46 |
|
|
|
| 47 |
|
|
#define octkid(ot,br) (octblock[octbi(ot)][octti(ot)+br]) |
| 48 |
|
|
|
| 49 |
|
|
extern OCTREE octalloc(), combine(), fullnode(); |
| 50 |
|
|
|
| 51 |
|
|
/* |
| 52 |
|
|
* The cube structure is used to hold an octree and its cubic |
| 53 |
|
|
* boundaries. |
| 54 |
|
|
*/ |
| 55 |
|
|
|
| 56 |
|
|
typedef struct { |
| 57 |
|
|
OCTREE cutree; /* the octree for this cube */ |
| 58 |
|
|
FVECT cuorg; /* the cube origin */ |
| 59 |
|
|
double cusize; /* the cube size */ |
| 60 |
|
|
} CUBE; |
| 61 |
|
|
|
| 62 |
|
|
extern CUBE thescene; /* the main scene */ |
| 63 |
|
|
|
| 64 |
|
|
/* flags for reading and writing octrees */ |
| 65 |
|
|
#define IO_CHECK 0 /* verify file type */ |
| 66 |
|
|
#define IO_INFO 01 /* information header */ |
| 67 |
|
|
#define IO_SCENE 02 /* objects */ |
| 68 |
|
|
#define IO_TREE 04 /* octree */ |
| 69 |
|
|
#define IO_FILES 010 /* object file names */ |
| 70 |
|
|
#define IO_BOUNDS 020 /* octree boundary */ |
| 71 |
|
|
#define IO_ALL (~0) /* everything */ |
| 72 |
greg |
1.4 |
/* octree format identifier */ |
| 73 |
|
|
#define OCTFMT "Radiance_octree" |
| 74 |
greg |
1.1 |
/* magic number for octree files */ |
| 75 |
greg |
1.5 |
#define MAXOBJSIZ 8 /* maximum sizeof(OBJECT) */ |
| 76 |
|
|
#define OCTMAGIC ( 4 *MAXOBJSIZ+251) /* increment first value */ |
| 77 |
greg |
1.1 |
/* octree node types */ |
| 78 |
|
|
#define OT_EMPTY 0 |
| 79 |
|
|
#define OT_FULL 1 |
| 80 |
|
|
#define OT_TREE 2 |
| 81 |
greg |
1.2 |
/* return values for surface functions */ |
| 82 |
|
|
#define O_MISS 0 /* no intersection */ |
| 83 |
|
|
#define O_HIT 1 /* intersection */ |
| 84 |
|
|
#define O_IN 2 /* cube contained entirely */ |