1 |
greg |
2.11 |
/* RCSid $Id: octree.h,v 2.10 2003/06/27 06:53:21 greg Exp $ */ |
2 |
greg |
1.1 |
/* |
3 |
|
|
* octree.h - header file for routines using octrees. |
4 |
greg |
2.5 |
*/ |
5 |
schorsch |
2.9 |
#ifndef _RAD_OCTREE_H_ |
6 |
|
|
#define _RAD_OCTREE_H_ |
7 |
|
|
#ifdef __cplusplus |
8 |
|
|
extern "C" { |
9 |
|
|
#endif |
10 |
greg |
1.1 |
|
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 |
gwlarson |
2.4 |
#define OCTBLKSIZ 04000 /* octree block size */ |
35 |
|
|
#define octbi(ot) ((ot)>>11) /* octree block index */ |
36 |
|
|
#define octti(ot) (((ot)&03777)<<3)/* octree index in block */ |
37 |
greg |
1.1 |
|
38 |
greg |
1.5 |
#ifndef MAXOBLK |
39 |
greg |
2.8 |
#ifdef SMLMEM |
40 |
|
|
#define MAXOBLK 4095 /* maximum octree block */ |
41 |
|
|
#else |
42 |
gwlarson |
2.4 |
#define MAXOBLK 32767 /* maximum octree block */ |
43 |
greg |
1.5 |
#endif |
44 |
|
|
#endif |
45 |
greg |
1.1 |
|
46 |
|
|
extern OCTREE *octblock[MAXOBLK]; /* octree blocks */ |
47 |
|
|
|
48 |
|
|
#define octkid(ot,br) (octblock[octbi(ot)][octti(ot)+br]) |
49 |
|
|
|
50 |
|
|
/* |
51 |
|
|
* The cube structure is used to hold an octree and its cubic |
52 |
|
|
* boundaries. |
53 |
|
|
*/ |
54 |
|
|
|
55 |
|
|
typedef struct { |
56 |
|
|
FVECT cuorg; /* the cube origin */ |
57 |
|
|
double cusize; /* the cube size */ |
58 |
greg |
2.11 |
OCTREE cutree; /* the octree for this cube */ |
59 |
greg |
1.1 |
} CUBE; |
60 |
|
|
|
61 |
|
|
extern CUBE thescene; /* the main scene */ |
62 |
|
|
|
63 |
|
|
/* flags for reading and writing octrees */ |
64 |
|
|
#define IO_CHECK 0 /* verify file type */ |
65 |
|
|
#define IO_INFO 01 /* information header */ |
66 |
|
|
#define IO_SCENE 02 /* objects */ |
67 |
|
|
#define IO_TREE 04 /* octree */ |
68 |
|
|
#define IO_FILES 010 /* object file names */ |
69 |
|
|
#define IO_BOUNDS 020 /* octree boundary */ |
70 |
|
|
#define IO_ALL (~0) /* everything */ |
71 |
greg |
1.4 |
/* octree format identifier */ |
72 |
|
|
#define OCTFMT "Radiance_octree" |
73 |
greg |
1.1 |
/* magic number for octree files */ |
74 |
greg |
1.5 |
#define MAXOBJSIZ 8 /* maximum sizeof(OBJECT) */ |
75 |
|
|
#define OCTMAGIC ( 4 *MAXOBJSIZ+251) /* increment first value */ |
76 |
greg |
1.1 |
/* octree node types */ |
77 |
|
|
#define OT_EMPTY 0 |
78 |
|
|
#define OT_FULL 1 |
79 |
|
|
#define OT_TREE 2 |
80 |
greg |
1.2 |
/* return values for surface functions */ |
81 |
|
|
#define O_MISS 0 /* no intersection */ |
82 |
|
|
#define O_HIT 1 /* intersection */ |
83 |
|
|
#define O_IN 2 /* cube contained entirely */ |
84 |
greg |
2.5 |
|
85 |
|
|
|
86 |
|
|
extern OCTREE octalloc(void); |
87 |
|
|
extern void octfree(OCTREE ot); |
88 |
|
|
extern void octdone(void); |
89 |
|
|
extern OCTREE combine(OCTREE ot); |
90 |
|
|
extern void culocate(CUBE *cu, FVECT pt); |
91 |
|
|
extern void cucopy(CUBE *cu1, CUBE *cu2); |
92 |
|
|
extern int incube(CUBE *cu, FVECT pt); |
93 |
|
|
|
94 |
|
|
extern int readoct(char *fname, int load, CUBE *scene, char *ofn[]); |
95 |
greg |
2.7 |
|
96 |
|
|
extern void readscene(FILE *fp, int objsiz); |
97 |
|
|
extern void writescene(int firstobj, int nobjs, FILE *fp); |
98 |
greg |
2.5 |
|
99 |
schorsch |
2.9 |
|
100 |
|
|
#ifdef __cplusplus |
101 |
|
|
} |
102 |
greg |
2.5 |
#endif |
103 |
schorsch |
2.9 |
#endif /* _RAD_OCTREE_H_ */ |
104 |
|
|
|