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