ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm.h
(Generate patch)

Comparing ray/src/hd/sm.h (file contents):
Revision 3.3 by gwlarson, Mon Sep 14 10:33:46 1998 UTC vs.
Revision 3.7 by gwlarson, Tue Jan 5 16:52:38 1999 UTC

# Line 10 | Line 10
10   #define _SM_H_
11  
12   #include "rhd_sample.h"
13 < #include "sm_stree.h"
13 > #define NEWSETS
14  
15  
16   #ifndef TRUE
# Line 18 | Line 18
18   #define FALSE 0
19   #endif
20  
21 #define P_REPLACE_EPS 0.5
22 #define SQRT3_2 0.8660254
21  
22 < #define MAX_EDGES 200
22 > #define ON_V 1
23 > #define ON_P 2
24 > #define ON_E 3
25 > #define IN_T 4
26  
27 < #define SM_INVALID  -1
28 < #define SM_DEFAULT   0
29 < #define SM_EXTRA_POINTS 5
27 > #define S_REPLACE_EPS 0.04      /* if (distance on sphere between sample
28 >                                     and a base point) < S_REPLACE_EPS,
29 >                                     replace base:
30 >                                     */
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 >
39 > #define SQRT3_2 0.8660254
40 >
41 > #define SM_DEFAULT 0
42 > #define SM_EXTRA_POINTS 162
43 > #define SM_BASE_TRIS 320
44   #define SM_EXTRA_VERTS  SM_EXTRA_POINTS
30 #define SM_POINTSIZ     (3*sizeof(float)+ sizeof(int4))
31 #define SM_POINT_SPACE SM_EXTRA_POINTS * SM_POINTSIZ
45  
46 < #define SM_INC_PERCENT 0.60
46 > #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   #define SM_VIEW_FRAC   0.1
53  
54  
# Line 41 | Line 59 | typedef struct _EDGE {
59      int verts[2];
60      int tris[2];
61   } EDGE;
62 +
63   #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)
50 #define eNew_edge() (((Ecnt) < MAX_EDGES)?(++Ecnt):SM_INVALID)
69   #define eClear_edges() (Ecnt = 0)
70  
71   #define FOR_ALL_EDGES(i) for((i)=1; (i) <= Ecnt; i++)
# Line 68 | Line 86 | typedef struct _TRI {
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   #define T_NEXT_FREE(t) ((t)->nbrs[0])
89 + #define T_NEXT_AVAILABLE(t) ((t)->nbrs[0])
90   #define T_VALID_FLAG(t) ((t)->nbrs[1])
91   #define T_IS_VALID(t)  (T_VALID_FLAG(t)!=-1)
92 < #define T_FLAGS 4
74 < #define T_FLAG_BYTES T_FLAGS/8.0
75 < #define T_TOTAL_FLAG_BYTES(c)  ((((c)+31)>>5)*sizeof(int4))
92 > #define T_FLAGS 3
93  
94   typedef struct _SM {
95      FVECT view_center;    /* Canonical view center defining unit sphere */
96 <    RSAMP *samples;       /* Sample point information */
97 <    STREE locator;      /* spherical quadtree for point/triangle location */
96 >    SAMP *samples;        /* Sample point information */
97 >    STREE locator;        /* spherical quadtree for point/triangle location */
98      int max_tris;         /* Maximum number of triangles */
99 <    int tri_cnt;          /* Total number of tris ever alloc at one time*/
100 <    int num_tris;         /* Current number of sample (nonbase)triangles */
99 >    int num_tri;          /* Current number of triangles */
100 >    int sample_tris;      /* Current number of non-base triangles*/
101      int free_tris;        /* pointer to free_list */
102 +    int available_tris;   /* pointer to available_list */
103      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 <                             /* Bit 1 set if not rendered since created */
108 <                             /* Bit 2 set if base triangle */
91 <                             /* Bit 3 set used for LRU replacement */
92 <    char *base;           /* Allocated space */
107 >                          /* Bit 1 set if not rendered since created */
108 >                          /* Bit 2 set if base triangle */
109   }SM;
110  
111   #define T_ACTIVE_FLAG   0
112   #define T_NEW_FLAG      1
113   #define T_BASE_FLAG     2
98 #define T_LRU_FLAG      3
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 < #define SM_TRI_CNT(m)                 ((m)->tri_cnt)
120 < #define SM_NUM_TRIS(m)                 ((m)->num_tris)
119 > #define SM_NUM_TRI(m)                 ((m)->num_tri)
120 > #define SM_SAMPLE_TRIS(m)                 ((m)->sample_tris)
121   #define SM_FREE_TRIS(m)               ((m)->free_tris)
122 + #define SM_AVAILABLE_TRIS(m)          ((m)->available_tris)
123   #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 < #define SM_BASE(m)                    ((m)->base)
127 > #define SM_FLAGS(m)                   ((m)->flags)
128  
113 #define TF_OFFSET(n)  ((n) >> 5)
114 #define TF_BIT(n)     ((n) & 0x1f)
115 #define SM_IS_NTH_T_FLAG(sm,n,f)  (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] & (0x1 <<TF_BIT(n)))
116 #define SM_SET_NTH_T_FLAG(sm,n,f) (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] |= (0x1<<TF_BIT(n)))
117 #define SM_CLEAR_NTH_T_FLAG(sm,n,f) (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] &= ~(0x1<<TF_BIT(n)))
129  
130 + #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   #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)
122 #define SM_IS_NTH_T_LRU(sm,n)        SM_IS_NTH_T_FLAG(sm,n,T_LRU_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 < #define SM_SET_NTH_T_NEW(sm,n)    SM_SET_NTH_T_FLAG(sm,n,T_NEW_FLAG)
127 < #define SM_SET_NTH_T_LRU(sm,n)       SM_SET_NTH_T_FLAG(sm,n,T_LRU_FLAG)
140 > #define SM_SET_NTH_T_NEW(sm,n)       SM_SET_NTH_T_FLAG(sm,n,T_NEW_FLAG)
141  
142 < #define SM_CLEAR_NTH_T_ACTIVE(sm,n)  SM_CLEAR_NTH_T_FLAG(sm,n,T_ACTIVE_FLAG)
143 < #define SM_CLEAR_NTH_T_BASE(sm,n)    SM_CLEAR_NTH_T_FLAG(sm,n,T_BASE_FLAG)
144 < #define SM_CLEAR_NTH_T_NEW(sm,n)  SM_CLEAR_NTH_T_FLAG(sm,n,T_NEW_FLAG)
132 < #define SM_CLEAR_NTH_T_LRU(sm,n)     SM_CLEAR_NTH_T_FLAG(sm,n,T_LRU_FLAG)
142 > #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  
146   #define SM_NTH_TRI(m,n)               (&(SM_TRIS(m)[(n)]))
147   #define SM_NTH_VERT(m,n)              (SM_VERTS(m)[(n)])
148 < #define SM_FREE_TRI_ID(m,n) (n = SM_FREE_TRIS(m)==-1? \
149 <    (SM_TRI_CNT(m)<SM_MAX_TRIS(m)?SM_TRI_CNT(m)++:-1):(n=SM_FREE_TRIS(m), \
138 <     SM_FREE_TRIS(m)=T_NEXT_FREE(SM_NTH_TRI(m,SM_FREE_TRIS(m))),n))
148 >
149 > #define SM_T_ID_VALID(s,t_id) T_IS_VALID(SM_NTH_TRI(s,t_id))
150  
140 #define SM_SAMP_BASE(m)               RS_BASE(SM_SAMP(m))
141 #define SM_SAMP_FREE(m)               RS_FREE(SM_SAMP(m))
142 #define SM_SAMP_EOL(m)                RS_EOL(SM_SAMP(m))
143 #define SM_MAX_SAMP(m)                RS_MAX_SAMP(SM_SAMP(m))
144 #define SM_MAX_AUX_PT(m)              RS_MAX_AUX_PT(SM_SAMP(m))
145 #define SM_NTH_WV(m,i)                RS_NTH_W_PT(SM_SAMP(m),i)
146 #define SM_NTH_W_DIR(m,i)             RS_NTH_W_DIR(SM_SAMP(m),i)
147 #define SM_NTH_RGB(m,i)               RS_NTH_RGB(SM_SAMP(m),i)
148 #define SM_RGB(m)                    RS_RGB(SM_SAMP(m))
149 #define SM_BRT(m)                     RS_BRT(SM_SAMP(m))
150 #define SM_NTH_BRT(m,i)               RS_NTH_BRT(SM_SAMP(m),i)
151 #define SM_CHR(m)                     RS_CHR(SM_SAMP(m))
152 #define SM_NTH_CHR(m,i)               RS_NTH_CHR(SM_SAMP(m),i)
153 #define SM_NUM_SAMP(m)               RS_NUM_SAMP(SM_SAMP(m))
154 #define SM_TONE_MAP(m)               RS_TONE_MAP(SM_SAMP(m))
151  
152 + #define SM_MAX_SAMP(m)                S_MAX_SAMP(SM_SAMP(m))
153 + #define SM_MAX_POINTS(m)              S_MAX_POINTS(SM_SAMP(m))
154 + #define SM_SAMP_BASE(m)               S_BASE(SM_SAMP(m))
155 + #define SM_NTH_WV(m,i)                S_NTH_W_PT(SM_SAMP(m),i)
156 + #define SM_NTH_W_DIR(m,i)             S_NTH_W_DIR(SM_SAMP(m),i)
157 + #define SM_DIR_ID(m,i)            (!SM_BASE_ID(m,i) && SM_NTH_W_DIR(m,i)==-1)
158 + #define SM_NTH_RGB(m,i)               S_NTH_RGB(SM_SAMP(m),i)
159 + #define SM_RGB(m)                    S_RGB(SM_SAMP(m))
160 + #define SM_WP(m)                    S_W_PT(SM_SAMP(m))
161 + #define SM_BRT(m)                     S_BRT(SM_SAMP(m))
162 + #define SM_NTH_BRT(m,i)               S_NTH_BRT(SM_SAMP(m),i)
163 + #define SM_CHR(m)                     S_CHR(SM_SAMP(m))
164 + #define SM_NTH_CHR(m,i)               S_NTH_CHR(SM_SAMP(m),i)
165 + #define SM_NUM_SAMP(m)               S_NUM_SAMP(SM_SAMP(m))
166 + #define SM_TONE_MAP(m)               S_TONE_MAP(SM_SAMP(m))
167 +
168   #define SM_ALLOWED_VIEW_CHANGE(m) (SM_NUM_SAMP(m)/smDist_sum*SM_VIEW_FRAC)
169  
170   #define SM_FOR_ALL_FLAGGED_TRIS(m,i,w,b) for(i=smNext_tri_flag_set(m,0,w,b); \
171 < i < SM_TRI_CNT(m); i=smNext_tri_flag_set(m,i+1,w,b))
171 > i < SM_NUM_TRI(m); i=smNext_tri_flag_set(m,i+1,w,b))
172  
173   #define SM_FOR_ALL_ACTIVE_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,0)
174 + #if 0
175   #define SM_FOR_ALL_NEW_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_NEW_FLAG,0)
176 + #else
177 + #define SM_FOR_ALL_NEW_TRIS(m,i) for(i=0; i < smNew_tri_cnt; i++)
178 + #endif
179   #define SM_FOR_ALL_BASE_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_BASE_FLAG,0)
180   #define SM_FOR_ALL_VALID_TRIS(m,i) for(i=smNext_valid_tri(m,0); \
181 < i < SM_TRI_CNT(m); i=smNext_valid_tri(m,i+1))
181 > i < SM_NUM_TRI(m); i=smNext_valid_tri(m,i+1))
182  
183   #define SM_FOR_ALL_ACTIVE_FG_TRIS(m,i) SM_FOR_ALL_FLAGGED_TRIS(m,i,T_ACTIVE_FLAG,1)
184  
# Line 173 | Line 189 | i < SM_TRI_CNT(m); i=smNext_valid_tri(m,i+1))
189   t!=SM_NTH_TRI(sm,SM_NTH_VERT(sm,id)); t=smTri_next_ccw_nbr(sm,t,id))
190  
191   #define SM_INVALID_SAMP_ID(sm,id)  (((id) < 0) || ((id) >= SM_MAX_SAMP(sm)))
192 < #define SM_INVALID_POINT_ID(sm,id)  (((id) < 0) || ((id) >= SM_MAX_AUX_PT(sm)))
177 < #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)
192 > #define SM_INVALID_POINT_ID(sm,id)  (((id) < 0) || ((id) >= SM_MAX_POINTS(sm)))
193   #define SM_T_NTH_WV(sm,t,i)  (SM_NTH_WV(sm,T_NTH_V(t,i)))
194  
195   #define SM_BASE_ID(s,i)  \
196 < ((i) >= RS_MAX_SAMP(SM_SAMP(s)) && (i) < RS_MAX_AUX_PT(SM_SAMP(s)))
196 > ((i) >= S_MAX_SAMP(SM_SAMP(s)) && (i) < S_MAX_BASE_PT(SM_SAMP(s)))
197  
198   #define SM_BG_SAMPLE(sm,i)   (SM_NTH_W_DIR(sm,i)==-1)
199  
# Line 191 | Line 206 | t!=SM_NTH_TRI(sm,SM_NTH_VERT(sm,id)); t=smTri_next_ccw
206  
207   #define SM_FOR_ALL_SAMPLES(sm,i) for((i)=0;i < SM_NUM_SAMP(sm);(i)++)
208  
209 + #define smInit_locator(sm,c)    (stInit(SM_LOCATOR(sm)), \
210 +                                 ST_SET_CENTER(SM_LOCATOR(sm),c))
211 + #define smClear_locator(sm)    stClear(SM_LOCATOR(sm))
212 + #define smAlloc_locator(sm)   stAlloc(SM_LOCATOR(sm))
213 + #define smFree_locator(sm)   stClear(SM_LOCATOR(sm))
214 + #define smPointLocateCell(sm,pt)  stPoint_locate(SM_LOCATOR(sm),pt)
215 + #define smUnalloc_samp(sm,id)  sUnalloc_samp(SM_SAMP(sm),id)
216 + #define smFree_samples(sm)     sFree(SM_SAMP(sm))
217 + #define smClear_samples(sm)    sClear(SM_SAMP(sm))
218 + #define smInit_samples(sm)     sInit(SM_SAMP(sm))
219 +
220 +
221 + #define smClear_vert(sm,id)    (SM_NTH_VERT(sm,id) = INVALID)
222 +
223 + #define SQRT3_INV 0.5773502692
224 +
225   typedef struct _T_DEPTH {
226    int tri;
227    double depth;
228   }T_DEPTH;
229  
230 + typedef struct _RT_ARGS_{
231 +  FVECT orig,dir;
232 +  int t_id;
233 +  OBJECT *os;
234 + }RT_ARGS;
235  
236 +
237 + typedef struct _ADD_ARGS {
238 +  int t_id;
239 +  OBJECT *del_set;
240 + }ADD_ARGS;
241 +
242   extern SM *smMesh;
243   extern int smNew_tri_cnt;
244 + extern int smNew_tri_size;
245 + extern T_DEPTH *smNew_tris;
246 +
247   extern double smDist_sum;
248  
249 +
250   #ifdef TEST_DRIVER
251   extern VIEW View;
252   extern VIEW Current_View;
253   extern int Pick_tri,Picking,Pick_samp;
254   extern FVECT Pick_point[500],Pick_origin,Pick_dir;
255   extern FVECT Pick_v0[500],Pick_v1[500],Pick_v2[500];
256 + extern int Pick_q[500];
257   extern FVECT P0,P1,P2;
258   extern int Pick_cnt;
259   extern FVECT FrustumNear[4],FrustumFar[4];
260   #endif
261  
262 < #ifdef DEBUG
263 < extern int Malloc_cnt;
264 < #endif
262 >
263 > /*
264 > * int
265 > * smInit(n)            : Initialize/clear data structures for n entries
266 > * int  n;
267 > *
268 > * Initialize sampL and other data structures for at least n samples.
269 > * If n is 0, then free data structures.  Return number actually allocated.
270 > *
271 > *
272 > * int
273 > * smNewSamp(c, p, v)   : register new sample point and return index
274 > * COLR c;              : pixel color (RGBE)
275 > * FVECT        p;      : world intersection point
276 > * FVECT        v;      : ray direction vector
277 > *
278 > * Add new sample point to data structures, removing old values as necessary.
279 > * New sample representation will be output in next call to smUpdate().
280 > *
281 > *
282 > * int
283 > * smFindSamp(orig, dir): intersect ray with 3D rep. and find closest sample
284 > * FVECT        orig, dir;
285 > *
286 > * Find the closest sample to the given ray.  Return -1 on failure.
287 > *
288 > *
289 > * smClean()            : display has been wiped clean
290 > *
291 > * Called after display has been effectively cleared, meaning that all
292 > * geometry must be resent down the pipeline in the next call to smUpdate().
293 > *
294 > *
295 > * smUpdate(vp, qua)    : update OpenGL output geometry for view vp
296 > * VIEW *vp;            : desired view
297 > * int  qua;            : quality level (percentage on linear time scale)
298 > *
299 > * Draw new geometric representation using OpenGL calls.  Assume that the
300 > * view has already been set up and the correct frame buffer has been
301 > * selected for drawing.  The quality level is on a linear scale, where 100%
302 > * is full (final) quality.  It is not necessary to redraw geometry that has
303 > * been output since the last call to smClean().  (The last view drawn will
304 > * be vp==&odev.v each time.)
305 > */
306   #endif
307  
308  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines