ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm_stree.h
(Generate patch)

Comparing ray/src/hd/sm_stree.h (file contents):
Revision 3.1 by gwlarson, Wed Aug 19 17:45:24 1998 UTC vs.
Revision 3.4 by gwlarson, Mon Dec 28 18:07:36 1998 UTC

# Line 7 | Line 7
7   *            
8   */
9  
10 < #include "sm_qtree.h"
10 > #define STR_INDEX(s)  (stRoot_indices[(s)])
11 > #define STR_NTH_INDEX(s,n)  (stRoot_indices[(s)][(n)])
12  
13 < #define SQRT3_INV 0.5773502692
13 > #define ST_NUM_ROOT_NODES 8
14  
15  
16 +
17 + /* The base is an octahedron: Each face contains a planar quadtree. At
18 + the root level, the "top" (positive y) four faces, and bottom four faces
19 + are stored together:forming two root quadtree nodes
20 + */
21 +
22   typedef struct _STREE {
23 <    QUADTREE   root;       /* quadtree triangulation of sphere */
24 <    FVECT    center;   /* sphere center */
25 <    FVECT    base[4];  /* 4 vertices on sphere that define base triangulation
26 <                        of 4 triangles: assume cover sphere and triangles
27 <                        are base verts (0,1,2),(0,2,3),(0,3,1), and (1,3,2)
28 <                        */
23 >  QUADTREE   qt[2];  /* root[0]= top four faces, root[1]=bottom 4 faces*/
24 >  FVECT      center;   /* sphere center */
25 >
26 >  /* will go **************************************************/
27 >  FVECT      base[6];  /* 6 vertices on sphere that define base octahedron:
28 >                          in canonical form: origin(0,0,0) points (1,0,0),
29 >                          (0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1) */
30 >  FPEQ      fplane[8];     /* Face plane equations */
31 >        
32 >  FVECT enorms[8][3];  /* Edge normals: For plane through edge and origin*/
33 >  /* gone ****************************************************************/
34 >
35   }STREE;
36  
24 #define ST_ROOT(s)             ((s)->root)
25 #define ST_NTH_ROOT(s,n)       QT_NTH_CHILD(ST_ROOT(s),n)
26 #define ST_NTH_ROOT_PTR(s,n)   QT_NTH_CHILD_PTR(ST_ROOT(s),n)
27 #define ST_CLEAR_ROOT(s)       QT_CLEAR_CHILDREN(ST_ROOT(s))
37  
38 < #define ST_CENTER(s)           ((s)->center)
39 < #define ST_SET_CENTER(s,b)     VCOPY(ST_CENTER(s),b)
38 > #define ST_BASEI(n)            ((n)>>2)     /* root index: top or bottom */
39 > #define ST_INDEX(n)            ((n) & 0x3) /* which child in root */
40 > #define ST_QT(s,i)           ((s)->qt[ST_BASEI(i)]) /* top or bottom root*/
41 > #define ST_QT_PTR(s,i)       (&ST_QT(s,i)) /* ptr to top(0)/bottom(1)root*/
42 > #define ST_TOP_QT(s)         ((s)->qt[0])  /* top root (y>0)*/
43 > #define ST_BOTTOM_QT(s)      ((s)->qt[1])  /* bottom qt (y <= 0)*/
44 > #define ST_TOP_QT_PTR(s)     (&ST_TOP_QT(s)) /* ptr to top qt */
45 > #define ST_BOTTOM_QT_PTR(s)  (&ST_BOTTOM_QT(s)) /* ptr to bottom qt*/
46 >
47 >
48 > #define ST_ROOT_QT(s,n)        QT_NTH_CHILD(ST_QT(s,n),ST_INDEX(n))
49 >
50 > #define ST_CLEAR_QT(st)      (ST_TOP_QT(st)=EMPTY,ST_BOTTOM_QT(st)=EMPTY)
51 > #define ST_INIT_QT(st)      (QT_CLEAR_CHILDREN(ST_TOP_QT(st)), \
52 >                                QT_CLEAR_CHILDREN(ST_BOTTOM_QT(st)))
53 >
54 >
55 >
56 >     /* Will go *****************************************************/
57   #define ST_BASE(s)             ((s)->base)
58   #define ST_NTH_BASE(s,n)       ((s)->base[(n)])
59 + #define ST_NTH_V(s,n,i)        ST_NTH_BASE(s,stBase_verts[(n)][(i)])
60   #define ST_SET_NTH_BASE(s,n,b) VCOPY(ST_NTH_BASE(s,n),b)
61   #define ST_SET_BASE(s,b)       (VCOPY(ST_NTH_BASE(s,0),(b)[0]), \
62                                  VCOPY(ST_NTH_BASE(s,1),(b)[1]), \
63                                  VCOPY(ST_NTH_BASE(s,2),(b)[2]), \
64 <                                VCOPY(ST_NTH_BASE(s,3),(b)[3]))
64 >                                VCOPY(ST_NTH_BASE(s,3),(b)[3]), \
65 >                                VCOPY(ST_NTH_BASE(s,4),(b)[4]), \
66 >                                VCOPY(ST_NTH_BASE(s,5),(b)[5]))
67 > #define ST_NTH_PLANE(s,i)        ((s)->fplane[(i)])
68 > #define ST_NTH_NORM(s,i)         (ST_NTH_PLANE(s,i).n)
69 > #define ST_NTH_D(s,i)            (ST_NTH_PLANE(s,i).d)
70 > #define ST_EDGE_NORM(s,i,n)      ((s)->enorms[(i)][(n)])
71 > /* gone *****************************************************/
72 >
73 > #define ST_CENTER(s)           ((s)->center)
74 > #define ST_SET_CENTER(s,b)     VCOPY(ST_CENTER(s),b)
75 >
76   #define ST_COORD(s,p,r)         VSUB(r,p,ST_CENTER(s))
77 + #define ST_CLEAR_FLAGS(s)       qtClearAllFlags()
78  
79 + /* Point location based on coordinate signs */
80 + #define stLocate_root(p) (((p)[2]>0.0?0:4)|((p)[1]>0.0?0:2)|((p)[0]>0.0?0:1))
81 +
82 + #define ST_CLIP_VERTS 16
83   /* STREE functions
84 + void stInit(STREE *st,FVECT  center)
85 +          Initializes an stree structure with origin 'center':
86 +          Frees existing quadtrees hanging off of the roots
87  
88 + STREE *stAlloc(STREE *st)
89 +         Allocates a stree structure  and creates octahedron base
90  
91 <   STREE *stInit(STREE *st)
92 <           Initialize STREE: if st = NULL, allocate a new one, else clear
93 <           return pointer to initialized structure
91 > void stClear(STREE *st)
92 >         Frees any existing root children and clears roots
93 >        
94 > QUADTREE stPoint_locate(STREE *st,FVECT p)
95 >         Returns quadtree leaf node containing point 'p'.
96  
97 <   QUADTREE *stPoint_locate(STREE *st,FVECT pt)
98 <           Find stree node that projection of pt on sphere falls in
97 > int stAdd_tri(STREE *st,int id,FVECT t0,t1,t2)
98 >         Add triangle 'id' with coordinates 't0,t1,t2' to the stree: returns
99 >         FALSE on error, TRUE otherwise
100 >        
101 > int stRemove_tri(STREE *st,int id,FVECT t0,t1,t2)
102 >         Removes triangle 'id' with coordinates 't0,t1,t2' from stree: returns
103 >         FALSE on error, TRUE otherwise
104 >        
105 > int stTrace_ray(STREE *st,FVECT orig,dir,int (*func)(),int *arg1,*arg2)
106 >        Trace ray 'orig-dir' through stree and apply 'func(arg1,arg2)' at each
107 >        node that it intersects
108  
109 <   stInsert_tri()
110 <          for every quadtree tri in the base- find node all leaf nodes that
111 <          tri overlaps and add tri to set. If this causes any of the nodes
112 <          to be over threshhold- split
113 <   stDelete_tri()
55 <          for every quadtree tri in the base- find node all leaf nodes that
56 <          tri overlaps. If this causes any of the nodes to be under
57 <          threshold- merge
109 > int stApply_to_tri(STREE *st,FVECT t0,t1,t2,int (*edge_func)(),
110 >        (*tri_func)(),int arg1,*arg2)  
111 >   Visit nodes intersected by tri 't0,t1,t2'.Apply 'edge_func(arg1,arg2,arg3)',
112 >   to those nodes intersected by edges, and interior_func to ALL nodes:
113 >   ie some Nodes  will be visited more than once
114   */
59 extern int   stTri_verts[4][3];
60 extern FVECT stDefault_base[4];
115  
116 <
117 <
118 <
116 > extern int stBase_verts[8][3];
117 > extern STREE *stAlloc();
118 > extern QUADTREE stPoint_locate();
119  
120  
121  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines