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.2 by gwlarson, Fri Sep 11 11:52:27 1998 UTC vs.
Revision 3.3 by gwlarson, Tue Oct 6 18:18:55 1998 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines