ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm.h
Revision: 3.5
Committed: Wed Nov 11 12:05:37 1998 UTC (25 years, 5 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.4: +18 -3 lines
Log Message:
new triangulation code
changed triangle vertex order to CCW
changed numbering of triangle neighbors to match quadtree
fixed tone-mapping bug
removed errant printf() statements
redid logic for adding and testing samples with new epsilon

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