1 |
< |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
< |
|
3 |
< |
/* SCCSid "$SunId$ SGI" */ |
4 |
< |
|
1 |
> |
/* RCSid: $Id$ */ |
2 |
|
/* |
3 |
|
* sm_stree.h - header file for spherical quadtree code: |
4 |
|
* |
5 |
|
*/ |
6 |
+ |
#ifndef _RAD_SM_STREE_H_ |
7 |
+ |
#define _RAD_SM_STREE_H_ |
8 |
|
|
9 |
+ |
#ifdef __cplusplus |
10 |
+ |
extern "C" { |
11 |
+ |
#endif |
12 |
|
|
13 |
+ |
|
14 |
+ |
#define STR_INDEX(s) (stRoot_indices[(s)]) |
15 |
+ |
#define STR_NTH_INDEX(s,n) (stRoot_indices[(s)][(n)]) |
16 |
+ |
|
17 |
|
#define ST_NUM_ROOT_NODES 8 |
18 |
|
|
19 |
+ |
|
20 |
+ |
|
21 |
|
/* The base is an octahedron: Each face contains a planar quadtree. At |
22 |
|
the root level, the "top" (positive y) four faces, and bottom four faces |
23 |
|
are stored together:forming two root quadtree nodes |
24 |
|
*/ |
25 |
|
|
26 |
|
typedef struct _STREE { |
27 |
< |
QUADTREE root[2]; /* root[0]= top four faces, root[1]=bottom 4 faces*/ |
28 |
< |
FVECT center; /* sphere center */ |
21 |
< |
FVECT base[6]; /* 6 vertices on sphere that define base octahedron: |
22 |
< |
in canonical form: origin(0,0,0) points (1,0,0), |
23 |
< |
(0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1) */ |
24 |
< |
FPEQ fplane[8]; /* Face plane equations */ |
25 |
< |
|
26 |
< |
FVECT enorms[8][3]; /* Edge normals: For plane through edge and origin*/ |
27 |
> |
QUADTREE qt[2]; /* root[0]= top four faces, root[1]=bottom 4 faces*/ |
28 |
> |
|
29 |
|
}STREE; |
30 |
|
|
31 |
|
|
32 |
|
#define ST_BASEI(n) ((n)>>2) /* root index: top or bottom */ |
33 |
|
#define ST_INDEX(n) ((n) & 0x3) /* which child in root */ |
34 |
< |
#define ST_ROOT(s,i) ((s)->root[ST_BASEI(i)]) /* top or bottom root*/ |
35 |
< |
#define ST_ROOT_PTR(s,i) (&ST_ROOT(s,i)) /* ptr to top(0)/bottom(1)root*/ |
36 |
< |
#define ST_TOP_ROOT(s) ((s)->root[0]) /* top root (y>0)*/ |
37 |
< |
#define ST_BOTTOM_ROOT(s) ((s)->root[1]) /* bottom root (y <= 0)*/ |
38 |
< |
#define ST_TOP_ROOT_PTR(s) (&ST_TOP_ROOT(s)) /* ptr to top root */ |
39 |
< |
#define ST_BOTTOM_ROOT_PTR(s) (&ST_BOTTOM_ROOT(s)) /* ptr to bottom root*/ |
38 |
< |
#define ST_NTH_ROOT(s,n) QT_NTH_CHILD(ST_ROOT(s,n),ST_INDEX(n)) |
39 |
< |
#define ST_NTH_ROOT_PTR(s,n) QT_NTH_CHILD_PTR(ST_ROOT(s,n),ST_INDEX(n)) |
40 |
< |
#define ST_CLEAR_ROOT(st) (ST_TOP_ROOT(st)=EMPTY,ST_BOTTOM_ROOT(st)=EMPTY) |
41 |
< |
#define ST_INIT_ROOT(st) (QT_CLEAR_CHILDREN(ST_TOP_ROOT(st)), \ |
42 |
< |
QT_CLEAR_CHILDREN(ST_BOTTOM_ROOT(st))) |
43 |
< |
#define ST_BASE(s) ((s)->base) |
44 |
< |
#define ST_NTH_BASE(s,n) ((s)->base[(n)]) |
45 |
< |
#define ST_NTH_V(s,n,i) ST_NTH_BASE(s,stBase_verts[(n)][(i)]) |
46 |
< |
#define ST_SET_NTH_BASE(s,n,b) VCOPY(ST_NTH_BASE(s,n),b) |
47 |
< |
#define ST_SET_BASE(s,b) (VCOPY(ST_NTH_BASE(s,0),(b)[0]), \ |
48 |
< |
VCOPY(ST_NTH_BASE(s,1),(b)[1]), \ |
49 |
< |
VCOPY(ST_NTH_BASE(s,2),(b)[2]), \ |
50 |
< |
VCOPY(ST_NTH_BASE(s,3),(b)[3]), \ |
51 |
< |
VCOPY(ST_NTH_BASE(s,4),(b)[4]), \ |
52 |
< |
VCOPY(ST_NTH_BASE(s,5),(b)[5])) |
34 |
> |
#define ST_QT(s,i) ((s)->qt[ST_BASEI(i)]) /* top or bottom root*/ |
35 |
> |
#define ST_QT_PTR(s,i) (&ST_QT(s,i)) /* ptr to top(0)/bottom(1)root*/ |
36 |
> |
#define ST_TOP_QT(s) ((s)->qt[0]) /* top root (y>0)*/ |
37 |
> |
#define ST_BOTTOM_QT(s) ((s)->qt[1]) /* bottom qt (y <= 0)*/ |
38 |
> |
#define ST_TOP_QT_PTR(s) (&ST_TOP_QT(s)) /* ptr to top qt */ |
39 |
> |
#define ST_BOTTOM_QT_PTR(s) (&ST_BOTTOM_QT(s)) /* ptr to bottom qt*/ |
40 |
|
|
41 |
< |
#define ST_CENTER(s) ((s)->center) |
42 |
< |
#define ST_SET_CENTER(s,b) VCOPY(ST_CENTER(s),b) |
41 |
> |
#define ST_NTH_V(s,n,w) (stDefault_base[stBase_verts[n][w]]) |
42 |
> |
#define ST_ROOT_QT(s,n) QT_NTH_CHILD(ST_QT(s,n),ST_INDEX(n)) |
43 |
|
|
44 |
< |
#define ST_NTH_PLANE(s,i) ((s)->fplane[(i)]) |
45 |
< |
#define ST_NTH_NORM(s,i) (ST_NTH_PLANE(s,i).n) |
46 |
< |
#define ST_NTH_D(s,i) (ST_NTH_PLANE(s,i).d) |
60 |
< |
#define ST_EDGE_NORM(s,i,n) ((s)->enorms[(i)][(n)]) |
44 |
> |
#define ST_CLEAR_QT(st) (ST_TOP_QT(st)=EMPTY,ST_BOTTOM_QT(st)=EMPTY) |
45 |
> |
#define ST_INIT_QT(st) (QT_CLEAR_CHILDREN(ST_TOP_QT(st)), \ |
46 |
> |
QT_CLEAR_CHILDREN(ST_BOTTOM_QT(st))) |
47 |
|
|
62 |
– |
#define ST_COORD(s,p,r) VSUB(r,p,ST_CENTER(s)) |
48 |
|
#define ST_CLEAR_FLAGS(s) qtClearAllFlags() |
49 |
|
|
50 |
|
/* Point location based on coordinate signs */ |
51 |
< |
#define TST(p) ((p)>0.0?1:0) |
52 |
< |
#define stPoint_in_root(p) stlocatetbl[TST((p)[0])<<2 | (TST((p)[1])<<1) \ |
68 |
< |
| TST((p)[2])] |
51 |
> |
#define stLocate_root(p) (((p)[2]>0.0?0:4)|((p)[1]>0.0?0:2)|((p)[0]>0.0?0:1)) |
52 |
> |
#define stClear(st) stInit(st) |
53 |
|
|
54 |
+ |
#define ST_CLIP_VERTS 16 |
55 |
|
/* STREE functions |
56 |
|
void stInit(STREE *st,FVECT center) |
57 |
|
Initializes an stree structure with origin 'center': |
60 |
|
STREE *stAlloc(STREE *st) |
61 |
|
Allocates a stree structure and creates octahedron base |
62 |
|
|
78 |
– |
void stClear(STREE *st) |
79 |
– |
Frees any existing root children and clears roots |
63 |
|
|
64 |
|
QUADTREE stPoint_locate(STREE *st,FVECT p) |
65 |
|
Returns quadtree leaf node containing point 'p'. |
84 |
|
*/ |
85 |
|
|
86 |
|
extern int stBase_verts[8][3]; |
87 |
+ |
extern FVECT stDefault_base[6]; |
88 |
|
extern STREE *stAlloc(); |
89 |
|
extern QUADTREE stPoint_locate(); |
90 |
|
|
91 |
< |
|
92 |
< |
|
91 |
> |
#ifdef __cplusplus |
92 |
> |
} |
93 |
> |
#endif |
94 |
> |
#endif /* _RAD_SM_STREE_H_ */ |
95 |
|
|
96 |
|
|