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