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