ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm.h
Revision: 3.4
Committed: Tue Oct 6 18:16:54 1998 UTC (25 years, 6 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.3: +115 -63 lines
Log Message:
new triangulate routine
added smTestSample to check for occlusion
added frustum culling before rebuild
changed base quadtree to use octahedron and created new point locate
added "sample active" flags and implemented LRU replacement
started handling case of too many triangles
set sizes are now unbounded
changed all quadtree pointers to quadtrees

File Contents

# User Rev Content
1 gwlarson 3.1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2    
3     /* SCCSid "$SunId$ SGI" */
4    
5     /*
6     * sm.h
7     */
8    
9     #ifndef _SM_H_
10     #define _SM_H_
11    
12     #include "rhd_sample.h"
13    
14 gwlarson 3.2
15 gwlarson 3.1 #ifndef TRUE
16     #define TRUE 1
17     #define FALSE 0
18     #endif
19    
20 gwlarson 3.4 #define S_REPLACE_EPS 0.06
21     #define S_REPLACE_SCALE 10.0
22    
23 gwlarson 3.1 #define SQRT3_2 0.8660254
24    
25 gwlarson 3.4 #define SM_DEFAULT 0
26     #define SM_EXTRA_POINTS 8
27 gwlarson 3.1 #define SM_EXTRA_VERTS SM_EXTRA_POINTS
28    
29     #define SM_INC_PERCENT 0.60
30     #define SM_VIEW_FRAC 0.1
31    
32    
33     typedef int VERT; /* One triangle that vertex belongs to- the rest
34     are derived by traversing neighbors */
35    
36     typedef struct _EDGE {
37     int verts[2];
38     int tris[2];
39     } EDGE;
40 gwlarson 3.4
41 gwlarson 3.1 #define E_NTH_VERT(e,i) ((e>0)?Edges[(e)].verts[(i)]:Edges[-(e)].verts[(1-i)])
42     #define SET_E_NTH_VERT(e,i,v) if(e>0) Edges[(e)].verts[(i)]=(v); \
43     else Edges[-(e)].verts[(1-i)]=(v)
44     #define E_NTH_TRI(e,i) ((e>0)?Edges[(e)].tris[(i)]:Edges[-(e)].tris[(1-i)])
45     #define SET_E_NTH_TRI(e,i,v) if(e>0) Edges[(e)].tris[(i)]=(v); \
46     else Edges[-(e)].tris[(1-i)]=(v)
47     #define eClear_edges() (Ecnt = 0)
48    
49     #define FOR_ALL_EDGES(i) for((i)=1; (i) <= Ecnt; i++)
50     #define FOR_ALL_EDGES_FROM(e,i) for((i)=++e; (i) <= Ecnt; i++)
51    
52    
53     typedef struct _TRI {
54     int verts[3]; /* Ids into sample and vertex array for each vertex*/
55     int nbrs[3]; /* Ids for neighboring triangles: -1 if invalid */
56     }TRI;
57    
58    
59     #define T_NTH_NBR(t,i) ((t)->nbrs[(i)])
60     #define T_CLEAR_NBRS(t) (T_NTH_NBR(t,0)=T_NTH_NBR(t,1)=T_NTH_NBR(t,2)=-1)
61     #define T_NTH_NBR_PTR(t,n) \
62     (T_NTH_NBR(n,0)==(t)?0:T_NTH_NBR(n,1)==(t)?1:T_NTH_NBR(n,2)==(t)?2:-1)
63     #define T_NTH_V(t,i) ((t)->verts[(i)])
64     #define T_WHICH_V(t,i) \
65     (T_NTH_V(t,0)==(i)?0:T_NTH_V(t,1)==(i)?1:T_NTH_V(t,2)==(i)?2:-1)
66 gwlarson 3.3 #define T_NEXT_FREE(t) ((t)->nbrs[0])
67     #define T_VALID_FLAG(t) ((t)->nbrs[1])
68 gwlarson 3.1 #define T_IS_VALID(t) (T_VALID_FLAG(t)!=-1)
69 gwlarson 3.4 #define T_FLAGS 3
70 gwlarson 3.1
71     typedef struct _SM {
72     FVECT view_center; /* Canonical view center defining unit sphere */
73 gwlarson 3.4 SAMP *samples; /* Sample point information */
74     STREE locator; /* spherical quadtree for point/triangle location */
75 gwlarson 3.1 int max_tris; /* Maximum number of triangles */
76 gwlarson 3.4 int num_tri; /* Current number of triangles */
77     int sample_tris; /* Current number of non-base triangles*/
78 gwlarson 3.1 int free_tris; /* pointer to free_list */
79     int max_verts; /* Maximum number of vertices in the mesh */
80     TRI *tris; /* Pointer to list of triangle structs */
81     VERT *verts; /* List of vertices */
82     int4 *flags[T_FLAGS]; /* Bit 0 set if active(in current frustum) */
83 gwlarson 3.4 /* Bit 1 set if not rendered since created */
84     /* Bit 2 set if base triangle */
85 gwlarson 3.1 }SM;
86    
87     #define T_ACTIVE_FLAG 0
88     #define T_NEW_FLAG 1
89     #define T_BASE_FLAG 2
90    
91     #define SM_VIEW_CENTER(m) ((m)->view_center)
92     #define SM_SAMP(m) ((m)->samples)
93     #define SM_LOCATOR(m) (&((m)->locator))
94     #define SM_MAX_TRIS(m) ((m)->max_tris)
95 gwlarson 3.4 #define SM_NUM_TRI(m) ((m)->num_tri)
96     #define SM_SAMPLE_TRIS(m) ((m)->sample_tris)
97 gwlarson 3.1 #define SM_FREE_TRIS(m) ((m)->free_tris)
98     #define SM_MAX_VERTS(m) ((m)->max_verts)
99     #define SM_TRIS(m) ((m)->tris)
100     #define SM_VERTS(m) ((m)->verts)
101     #define SM_NTH_FLAGS(m,n) ((m)->flags[(n)])
102 gwlarson 3.4 #define SM_FLAGS(m) ((m)->flags)
103 gwlarson 3.1
104    
105 gwlarson 3.4 #define SM_IS_NTH_T_FLAG(sm,n,f) IS_FLAG(SM_NTH_FLAGS(sm,f),n)
106     #define SM_SET_NTH_T_FLAG(sm,n,f) SET_FLAG(SM_NTH_FLAGS(sm,f),n)
107     #define SM_CLR_NTH_T_FLAG(sm,n,f) CLR_FLAG(SM_NTH_FLAGS(sm,f),n)
108    
109 gwlarson 3.1 #define SM_IS_NTH_T_ACTIVE(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG)
110     #define SM_IS_NTH_T_BASE(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_BASE_FLAG)
111     #define SM_IS_NTH_T_NEW(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_NEW_FLAG)
112    
113     #define SM_SET_NTH_T_ACTIVE(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG)
114     #define SM_SET_NTH_T_BASE(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_BASE_FLAG)
115 gwlarson 3.4 #define SM_SET_NTH_T_NEW(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_NEW_FLAG)
116 gwlarson 3.1
117 gwlarson 3.4 #define SM_CLR_NTH_T_ACTIVE(sm,n) SM_CLR_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG)
118     #define SM_CLR_NTH_T_BASE(sm,n) SM_CLR_NTH_T_FLAG(sm,n,T_BASE_FLAG)
119     #define SM_CLR_NTH_T_NEW(sm,n) SM_CLR_NTH_T_FLAG(sm,n,T_NEW_FLAG)
120 gwlarson 3.1
121     #define SM_NTH_TRI(m,n) (&(SM_TRIS(m)[(n)]))
122     #define SM_NTH_VERT(m,n) (SM_VERTS(m)[(n)])
123    
124 gwlarson 3.4 #define SM_MAX_SAMP(m) S_MAX_SAMP(SM_SAMP(m))
125     #define SM_MAX_POINTS(m) S_MAX_POINTS(SM_SAMP(m))
126     #define SM_SAMP_BASE(m) S_BASE(SM_SAMP(m))
127     #define SM_NTH_WV(m,i) S_NTH_W_PT(SM_SAMP(m),i)
128     #define SM_NTH_W_DIR(m,i) S_NTH_W_DIR(SM_SAMP(m),i)
129     #define SM_DIR_ID(m,i) (SM_NTH_W_DIR(m,i)==-1)
130     #define SM_NTH_RGB(m,i) S_NTH_RGB(SM_SAMP(m),i)
131     #define SM_RGB(m) S_RGB(SM_SAMP(m))
132     #define SM_BRT(m) S_BRT(SM_SAMP(m))
133     #define SM_NTH_BRT(m,i) S_NTH_BRT(SM_SAMP(m),i)
134     #define SM_CHR(m) S_CHR(SM_SAMP(m))
135     #define SM_NTH_CHR(m,i) S_NTH_CHR(SM_SAMP(m),i)
136     #define SM_NUM_SAMP(m) S_NUM_SAMP(SM_SAMP(m))
137     #define SM_TONE_MAP(m) S_TONE_MAP(SM_SAMP(m))
138 gwlarson 3.1
139     #define SM_ALLOWED_VIEW_CHANGE(m) (SM_NUM_SAMP(m)/smDist_sum*SM_VIEW_FRAC)
140    
141 gwlarson 3.2 #define SM_FOR_ALL_FLAGGED_TRIS(m,i,w,b) for(i=smNext_tri_flag_set(m,0,w,b); \
142 gwlarson 3.4 i < SM_NUM_TRI(m); i=smNext_tri_flag_set(m,i+1,w,b))
143 gwlarson 3.1
144     #define SM_FOR_ALL_ACTIVE_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,0)
145     #define SM_FOR_ALL_NEW_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_NEW_FLAG,0)
146     #define SM_FOR_ALL_BASE_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_BASE_FLAG,0)
147 gwlarson 3.2 #define SM_FOR_ALL_VALID_TRIS(m,i) for(i=smNext_valid_tri(m,0); \
148 gwlarson 3.4 i < SM_NUM_TRI(m); i=smNext_valid_tri(m,i+1))
149 gwlarson 3.1
150     #define SM_FOR_ALL_ACTIVE_FG_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,1)
151    
152     #define SM_FOR_ALL_ACTIVE_BG_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,2)
153    
154    
155     #define SM_FOR_ALL_ADJACENT_TRIS(sm,id,t) for(t=smTri_next_ccw_nbr(sm,t,id); \
156     t!=SM_NTH_TRI(sm,SM_NTH_VERT(sm,id)); t=smTri_next_ccw_nbr(sm,t,id))
157    
158     #define SM_INVALID_SAMP_ID(sm,id) (((id) < 0) || ((id) >= SM_MAX_SAMP(sm)))
159 gwlarson 3.4 #define SM_INVALID_POINT_ID(sm,id) (((id) < 0) || ((id) >= SM_MAX_POINTS(sm)))
160 gwlarson 3.1 #define SM_T_NTH_WV(sm,t,i) (SM_NTH_WV(sm,T_NTH_V(t,i)))
161    
162     #define SM_BASE_ID(s,i) \
163 gwlarson 3.4 ((i) >= S_MAX_SAMP(SM_SAMP(s)) && (i) < S_MAX_BASE_PT(SM_SAMP(s)))
164 gwlarson 3.1
165     #define SM_BG_SAMPLE(sm,i) (SM_NTH_W_DIR(sm,i)==-1)
166    
167 gwlarson 3.2 #define SM_BG_TRI(sm,i) (SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),0)) && \
168     SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),1)) && \
169     SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),2)))
170     #define SM_MIXED_TRI(sm,i) (SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),0)) || \
171 gwlarson 3.1 SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),1)) || \
172     SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),2)))
173    
174     #define SM_FOR_ALL_SAMPLES(sm,i) for((i)=0;i < SM_NUM_SAMP(sm);(i)++)
175    
176 gwlarson 3.4 #define smInit_locator(sm,c) (stInit(SM_LOCATOR(sm)), \
177     ST_SET_CENTER(SM_LOCATOR(sm),c))
178     #define smClear_locator(sm) stClear(SM_LOCATOR(sm))
179     #define smAlloc_locator(sm) stAlloc(SM_LOCATOR(sm))
180     #define smFree_locator(sm) stClear(SM_LOCATOR(sm))
181     #define smPointLocateCell(sm,pt) stPoint_locate(SM_LOCATOR(sm),pt)
182     #define smUnalloc_samp(sm,id) sUnalloc_samp(SM_SAMP(sm),id)
183     #define smFree_samples(sm) sFree(SM_SAMP(sm))
184     #define smClear_samples(sm) sClear(SM_SAMP(sm))
185     #define smInit_samples(sm) sInit(SM_SAMP(sm))
186    
187    
188     #define smClear_vert(sm,id) (SM_NTH_VERT(sm,id) = INVALID)
189    
190     #define SQRT3_INV 0.5773502692
191    
192 gwlarson 3.1 typedef struct _T_DEPTH {
193     int tri;
194     double depth;
195     }T_DEPTH;
196    
197 gwlarson 3.4 typedef struct _RT_ARGS_{
198     FVECT orig,dir;
199     int t_id;
200     OBJECT *os;
201     }RT_ARGS;
202 gwlarson 3.1
203 gwlarson 3.4
204     typedef struct _ADD_ARGS {
205     int t_id;
206     OBJECT *del_set;
207     }ADD_ARGS;
208    
209 gwlarson 3.1 extern SM *smMesh;
210     extern int smNew_tri_cnt;
211     extern double smDist_sum;
212    
213 gwlarson 3.4
214 gwlarson 3.1 #ifdef TEST_DRIVER
215     extern VIEW View;
216     extern VIEW Current_View;
217 gwlarson 3.2 extern int Pick_tri,Picking,Pick_samp;
218 gwlarson 3.1 extern FVECT Pick_point[500],Pick_origin,Pick_dir;
219     extern FVECT Pick_v0[500],Pick_v1[500],Pick_v2[500];
220     extern FVECT P0,P1,P2;
221     extern int Pick_cnt;
222     extern FVECT FrustumNear[4],FrustumFar[4];
223     #endif
224    
225 gwlarson 3.4
226     /*
227     * int
228     * smInit(n) : Initialize/clear data structures for n entries
229     * int n;
230     *
231     * Initialize sampL and other data structures for at least n samples.
232     * If n is 0, then free data structures. Return number actually allocated.
233     *
234     *
235     * int
236     * smNewSamp(c, p, v) : register new sample point and return index
237     * COLR c; : pixel color (RGBE)
238     * FVECT p; : world intersection point
239     * FVECT v; : ray direction vector
240     *
241     * Add new sample point to data structures, removing old values as necessary.
242     * New sample representation will be output in next call to smUpdate().
243     *
244     *
245     * int
246     * smFindSamp(orig, dir): intersect ray with 3D rep. and find closest sample
247     * FVECT orig, dir;
248     *
249     * Find the closest sample to the given ray. Return -1 on failure.
250     *
251     *
252     * smClean() : display has been wiped clean
253     *
254     * Called after display has been effectively cleared, meaning that all
255     * geometry must be resent down the pipeline in the next call to smUpdate().
256     *
257     *
258     * smUpdate(vp, qua) : update OpenGL output geometry for view vp
259     * VIEW *vp; : desired view
260     * int qua; : quality level (percentage on linear time scale)
261     *
262     * Draw new geometric representation using OpenGL calls. Assume that the
263     * view has already been set up and the correct frame buffer has been
264     * selected for drawing. The quality level is on a linear scale, where 100%
265     * is full (final) quality. It is not necessary to redraw geometry that has
266     * been output since the last call to smClean(). (The last view drawn will
267     * be vp==&odev.v each time.)
268     */
269    
270 gwlarson 3.1 #endif
271    
272    
273    
274    
275    
276    
277    
278