ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm.h
Revision: 3.10
Committed: Thu Jun 10 15:22:22 1999 UTC (24 years, 11 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.9: +47 -38 lines
Log Message:
Implemented sample quadtree in place of triangle quadtree
Made geometric predicates more robust
Added #define LORES which utilizes a single precision floating point
  sample array, the default is a double sample array
Added topology DEBUG commands (for DEBUG > 1)
Made code optimizations

File Contents

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