ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm.h
Revision: 3.2
Committed: Fri Sep 11 11:52:25 1998 UTC (25 years, 7 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.1: +10 -5 lines
Log Message:
fixed triangle insertion using edge tracing

File Contents

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