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 |
|
|
#include "sm_stree.h" |
14 |
|
|
|
15 |
|
|
#ifndef TRUE |
16 |
|
|
#define TRUE 1 |
17 |
|
|
#define FALSE 0 |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
#define P_REPLACE_EPS 0.5 |
21 |
|
|
#define SQRT3_2 0.8660254 |
22 |
|
|
|
23 |
|
|
#define MAX_EDGES 200 |
24 |
|
|
|
25 |
|
|
#define SM_INVALID -1 |
26 |
|
|
#define SM_DEFAULT 0 |
27 |
|
|
#define SM_EXTRA_POINTS 5 |
28 |
|
|
#define SM_EXTRA_VERTS SM_EXTRA_POINTS |
29 |
|
|
#define SM_POINTSIZ (3*sizeof(float)+ sizeof(int4)) |
30 |
|
|
#define SM_POINT_SPACE SM_EXTRA_POINTS * SM_POINTSIZ |
31 |
|
|
|
32 |
|
|
#define SM_INC_PERCENT 0.60 |
33 |
|
|
#define SM_VIEW_FRAC 0.1 |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
typedef int VERT; /* One triangle that vertex belongs to- the rest |
37 |
|
|
are derived by traversing neighbors */ |
38 |
|
|
|
39 |
|
|
typedef struct _EDGE { |
40 |
|
|
int verts[2]; |
41 |
|
|
int tris[2]; |
42 |
|
|
} EDGE; |
43 |
|
|
#define E_NTH_VERT(e,i) ((e>0)?Edges[(e)].verts[(i)]:Edges[-(e)].verts[(1-i)]) |
44 |
|
|
#define SET_E_NTH_VERT(e,i,v) if(e>0) Edges[(e)].verts[(i)]=(v); \ |
45 |
|
|
else Edges[-(e)].verts[(1-i)]=(v) |
46 |
|
|
#define E_NTH_TRI(e,i) ((e>0)?Edges[(e)].tris[(i)]:Edges[-(e)].tris[(1-i)]) |
47 |
|
|
#define SET_E_NTH_TRI(e,i,v) if(e>0) Edges[(e)].tris[(i)]=(v); \ |
48 |
|
|
else Edges[-(e)].tris[(1-i)]=(v) |
49 |
|
|
#define eNew_edge() (((Ecnt) < MAX_EDGES)?(++Ecnt):SM_INVALID) |
50 |
|
|
#define eClear_edges() (Ecnt = 0) |
51 |
|
|
|
52 |
|
|
#define FOR_ALL_EDGES(i) for((i)=1; (i) <= Ecnt; i++) |
53 |
|
|
#define FOR_ALL_EDGES_FROM(e,i) for((i)=++e; (i) <= Ecnt; i++) |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
typedef struct _TRI { |
57 |
|
|
int verts[3]; /* Ids into sample and vertex array for each vertex*/ |
58 |
|
|
int nbrs[3]; /* Ids for neighboring triangles: -1 if invalid */ |
59 |
|
|
}TRI; |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
#define T_NTH_NBR(t,i) ((t)->nbrs[(i)]) |
63 |
|
|
#define T_CLEAR_NBRS(t) (T_NTH_NBR(t,0)=T_NTH_NBR(t,1)=T_NTH_NBR(t,2)=-1) |
64 |
|
|
#define T_NTH_NBR_PTR(t,n) \ |
65 |
|
|
(T_NTH_NBR(n,0)==(t)?0:T_NTH_NBR(n,1)==(t)?1:T_NTH_NBR(n,2)==(t)?2:-1) |
66 |
|
|
#define T_NTH_V(t,i) ((t)->verts[(i)]) |
67 |
|
|
#define T_WHICH_V(t,i) \ |
68 |
|
|
(T_NTH_V(t,0)==(i)?0:T_NTH_V(t,1)==(i)?1:T_NTH_V(t,2)==(i)?2:-1) |
69 |
|
|
#define T_NEXT_FREE(t) ((t)->verts[0]) |
70 |
|
|
#define T_VALID_FLAG(t) ((t)->verts[1]) |
71 |
|
|
#define T_IS_VALID(t) (T_VALID_FLAG(t)!=-1) |
72 |
|
|
#define T_FLAGS 4 |
73 |
|
|
#define T_FLAG_BYTES T_FLAGS/8.0 |
74 |
|
|
#define T_TOTAL_FLAG_BYTES(c) ((((c)+31)>>5)*sizeof(int4)) |
75 |
|
|
|
76 |
|
|
typedef struct _SM { |
77 |
|
|
FVECT view_center; /* Canonical view center defining unit sphere */ |
78 |
|
|
RSAMP *samples; /* Sample point information */ |
79 |
|
|
STREE locator; /* spherical quadtree for point/triangle location */ |
80 |
|
|
int max_tris; /* Maximum number of triangles */ |
81 |
|
|
int tri_cnt; /* Total number of tris ever alloc at one time*/ |
82 |
|
|
int num_tris; /* Current number of sample (nonbase)triangles */ |
83 |
|
|
int free_tris; /* pointer to free_list */ |
84 |
|
|
int max_verts; /* Maximum number of vertices in the mesh */ |
85 |
|
|
TRI *tris; /* Pointer to list of triangle structs */ |
86 |
|
|
VERT *verts; /* List of vertices */ |
87 |
|
|
int4 *flags[T_FLAGS]; /* Bit 0 set if active(in current frustum) */ |
88 |
|
|
/* Bit 1 set if not rendered since created */ |
89 |
|
|
/* Bit 2 set if base triangle */ |
90 |
|
|
/* Bit 3 set used for LRU replacement */ |
91 |
|
|
char *base; /* Allocated space */ |
92 |
|
|
}SM; |
93 |
|
|
|
94 |
|
|
#define T_ACTIVE_FLAG 0 |
95 |
|
|
#define T_NEW_FLAG 1 |
96 |
|
|
#define T_BASE_FLAG 2 |
97 |
|
|
#define T_LRU_FLAG 3 |
98 |
|
|
|
99 |
|
|
#define SM_VIEW_CENTER(m) ((m)->view_center) |
100 |
|
|
#define SM_SAMP(m) ((m)->samples) |
101 |
|
|
#define SM_LOCATOR(m) (&((m)->locator)) |
102 |
|
|
#define SM_MAX_TRIS(m) ((m)->max_tris) |
103 |
|
|
#define SM_TRI_CNT(m) ((m)->tri_cnt) |
104 |
|
|
#define SM_NUM_TRIS(m) ((m)->num_tris) |
105 |
|
|
#define SM_FREE_TRIS(m) ((m)->free_tris) |
106 |
|
|
#define SM_MAX_VERTS(m) ((m)->max_verts) |
107 |
|
|
#define SM_TRIS(m) ((m)->tris) |
108 |
|
|
#define SM_VERTS(m) ((m)->verts) |
109 |
|
|
#define SM_NTH_FLAGS(m,n) ((m)->flags[(n)]) |
110 |
|
|
#define SM_BASE(m) ((m)->base) |
111 |
|
|
|
112 |
|
|
#define TF_OFFSET(n) ((n) >> 5) |
113 |
|
|
#define TF_BIT(n) ((n) & 0x1f) |
114 |
|
|
#define SM_IS_NTH_T_FLAG(sm,n,f) (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] & (0x1 <<TF_BIT(n))) |
115 |
|
|
#define SM_SET_NTH_T_FLAG(sm,n,f) (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] |= (0x1<<TF_BIT(n))) |
116 |
|
|
#define SM_CLEAR_NTH_T_FLAG(sm,n,f) (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] &= ~(0x1<<TF_BIT(n))) |
117 |
|
|
|
118 |
|
|
#define SM_IS_NTH_T_ACTIVE(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG) |
119 |
|
|
#define SM_IS_NTH_T_BASE(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_BASE_FLAG) |
120 |
|
|
#define SM_IS_NTH_T_NEW(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_NEW_FLAG) |
121 |
|
|
#define SM_IS_NTH_T_LRU(sm,n) SM_IS_NTH_T_FLAG(sm,n,T_LRU_FLAG) |
122 |
|
|
|
123 |
|
|
#define SM_SET_NTH_T_ACTIVE(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG) |
124 |
|
|
#define SM_SET_NTH_T_BASE(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_BASE_FLAG) |
125 |
|
|
#define SM_SET_NTH_T_NEW(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_NEW_FLAG) |
126 |
|
|
#define SM_SET_NTH_T_LRU(sm,n) SM_SET_NTH_T_FLAG(sm,n,T_LRU_FLAG) |
127 |
|
|
|
128 |
|
|
#define SM_CLEAR_NTH_T_ACTIVE(sm,n) SM_CLEAR_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG) |
129 |
|
|
#define SM_CLEAR_NTH_T_BASE(sm,n) SM_CLEAR_NTH_T_FLAG(sm,n,T_BASE_FLAG) |
130 |
|
|
#define SM_CLEAR_NTH_T_NEW(sm,n) SM_CLEAR_NTH_T_FLAG(sm,n,T_NEW_FLAG) |
131 |
|
|
#define SM_CLEAR_NTH_T_LRU(sm,n) SM_CLEAR_NTH_T_FLAG(sm,n,T_LRU_FLAG) |
132 |
|
|
|
133 |
|
|
#define SM_NTH_TRI(m,n) (&(SM_TRIS(m)[(n)])) |
134 |
|
|
#define SM_NTH_VERT(m,n) (SM_VERTS(m)[(n)]) |
135 |
|
|
#define SM_FREE_TRI_ID(m,n) (n = SM_FREE_TRIS(m)==-1? \ |
136 |
|
|
(SM_TRI_CNT(m)<SM_MAX_TRIS(m)?SM_TRI_CNT(m)++:-1):(n=SM_FREE_TRIS(m), \ |
137 |
|
|
SM_FREE_TRIS(m)=T_NEXT_FREE(SM_NTH_TRI(m,SM_FREE_TRIS(m))),n)) |
138 |
|
|
|
139 |
|
|
#define SM_SAMP_BASE(m) RS_BASE(SM_SAMP(m)) |
140 |
|
|
#define SM_SAMP_FREE(m) RS_FREE(SM_SAMP(m)) |
141 |
|
|
#define SM_SAMP_EOL(m) RS_EOL(SM_SAMP(m)) |
142 |
|
|
#define SM_MAX_SAMP(m) RS_MAX_SAMP(SM_SAMP(m)) |
143 |
|
|
#define SM_MAX_AUX_PT(m) RS_MAX_AUX_PT(SM_SAMP(m)) |
144 |
|
|
#define SM_NTH_WV(m,i) RS_NTH_W_PT(SM_SAMP(m),i) |
145 |
|
|
#define SM_NTH_W_DIR(m,i) RS_NTH_W_DIR(SM_SAMP(m),i) |
146 |
|
|
#define SM_NTH_RGB(m,i) RS_NTH_RGB(SM_SAMP(m),i) |
147 |
|
|
#define SM_RGB(m) RS_RGB(SM_SAMP(m)) |
148 |
|
|
#define SM_BRT(m) RS_BRT(SM_SAMP(m)) |
149 |
|
|
#define SM_NTH_BRT(m,i) RS_NTH_BRT(SM_SAMP(m),i) |
150 |
|
|
#define SM_CHR(m) RS_CHR(SM_SAMP(m)) |
151 |
|
|
#define SM_NTH_CHR(m,i) RS_NTH_CHR(SM_SAMP(m),i) |
152 |
|
|
#define SM_NUM_SAMP(m) RS_NUM_SAMP(SM_SAMP(m)) |
153 |
|
|
#define SM_TONE_MAP(m) RS_TONE_MAP(SM_SAMP(m)) |
154 |
|
|
|
155 |
|
|
#define SM_ALLOWED_VIEW_CHANGE(m) (SM_NUM_SAMP(m)/smDist_sum*SM_VIEW_FRAC) |
156 |
|
|
|
157 |
|
|
#define SM_FOR_ALL_FLAGGED_TRIS(m,i,w,b) for(i=0,i=smNext_tri_flag_set(m,i,w,b);i < SM_TRI_CNT(m);i++,i=smNext_tri_flag_set(m,i,w,b)) |
158 |
|
|
|
159 |
|
|
#define SM_FOR_ALL_ACTIVE_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,0) |
160 |
|
|
#define SM_FOR_ALL_NEW_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_NEW_FLAG,0) |
161 |
|
|
#define SM_FOR_ALL_BASE_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_BASE_FLAG,0) |
162 |
|
|
#define SM_FOR_ALL_VALID_TRIS(m,i) for((i)=0,(i)=smNext_valid_tri(m,i);(i)< \ |
163 |
|
|
SM_TRI_CNT(m); (i)++,(i)= smNext_valid_tri(m,i)) |
164 |
|
|
|
165 |
|
|
#define SM_FOR_ALL_ACTIVE_FG_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,1) |
166 |
|
|
|
167 |
|
|
#define SM_FOR_ALL_ACTIVE_BG_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,2) |
168 |
|
|
|
169 |
|
|
|
170 |
|
|
#define SM_FOR_ALL_ADJACENT_TRIS(sm,id,t) for(t=smTri_next_ccw_nbr(sm,t,id); \ |
171 |
|
|
t!=SM_NTH_TRI(sm,SM_NTH_VERT(sm,id)); t=smTri_next_ccw_nbr(sm,t,id)) |
172 |
|
|
|
173 |
|
|
#define SM_INVALID_SAMP_ID(sm,id) (((id) < 0) || ((id) >= SM_MAX_SAMP(sm))) |
174 |
|
|
#define SM_INVALID_POINT_ID(sm,id) (((id) < 0) || ((id) >= SM_MAX_AUX_PT(sm))) |
175 |
|
|
#define SM_T_CENTROID(sm,t,c) tri_centroid(SM_NTH_WV(sm,T_NTH_V(t,0)),SM_NTH_WV(sm,T_NTH_V(t,1)),SM_NTH_WV(sm,T_NTH_V(t,2)),c) |
176 |
|
|
#define SM_T_NTH_WV(sm,t,i) (SM_NTH_WV(sm,T_NTH_V(t,i))) |
177 |
|
|
|
178 |
|
|
#define SM_BASE_ID(s,i) \ |
179 |
|
|
((i) >= RS_MAX_SAMP(SM_SAMP(s)) && (i) < RS_MAX_AUX_PT(SM_SAMP(s))) |
180 |
|
|
|
181 |
|
|
#define SM_BG_SAMPLE(sm,i) (SM_NTH_W_DIR(sm,i)==-1) |
182 |
|
|
|
183 |
|
|
#define SM_BG_TRI(sm,i) (SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),0)) || \ |
184 |
|
|
SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),1)) || \ |
185 |
|
|
SM_BG_SAMPLE(sm,T_NTH_V(SM_NTH_TRI(sm,i),2))) |
186 |
|
|
|
187 |
|
|
#define SM_FOR_ALL_SAMPLES(sm,i) for((i)=0;i < SM_NUM_SAMP(sm);(i)++) |
188 |
|
|
|
189 |
|
|
typedef struct _T_DEPTH { |
190 |
|
|
int tri; |
191 |
|
|
double depth; |
192 |
|
|
}T_DEPTH; |
193 |
|
|
|
194 |
|
|
|
195 |
|
|
extern SM *smMesh; |
196 |
|
|
extern int smNew_tri_cnt; |
197 |
|
|
extern double smDist_sum; |
198 |
|
|
|
199 |
|
|
#ifdef TEST_DRIVER |
200 |
|
|
extern VIEW View; |
201 |
|
|
extern VIEW Current_View; |
202 |
|
|
extern int Pick_tri,Picking; |
203 |
|
|
extern FVECT Pick_point[500],Pick_origin,Pick_dir; |
204 |
|
|
extern FVECT Pick_v0[500],Pick_v1[500],Pick_v2[500]; |
205 |
|
|
extern FVECT P0,P1,P2; |
206 |
|
|
extern int Pick_cnt; |
207 |
|
|
extern FVECT FrustumNear[4],FrustumFar[4]; |
208 |
|
|
#endif |
209 |
|
|
|
210 |
|
|
#ifdef DEBUG |
211 |
|
|
extern int Malloc_cnt; |
212 |
|
|
#endif |
213 |
|
|
#endif |
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|