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

File Contents

# Content
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ SGI";
5 #endif
6
7 /*
8 * sm_samp.c
9 */
10 #include "standard.h"
11
12 #include "sm.h"
13
14 RSAMP rsL;
15
16
17 #define SAMPSIZ (3*sizeof(float)+sizeof(int4)+\
18 sizeof(TMbright)+6*sizeof(BYTE))
19 /* Initialize/clear global smL sample list for at least n samples */
20 int
21 smAlloc_samples(sm,n,extra_points)
22 SM *sm;
23 register int n,extra_points;
24 {
25 unsigned nbytes;
26 register unsigned i;
27 RSAMP *rs;
28
29 rs = &rsL;
30
31 SM_SAMP(sm) = rs;
32
33 /* round space up to nearest power of 2 */
34 nbytes = n*SAMPSIZ + extra_points*SM_POINTSIZ + 8;
35 for (i = 1024; nbytes > i; i <<= 1)
36 ;
37 n = (i - 8 - extra_points*SM_POINTSIZ) / SAMPSIZ;
38
39 RS_BASE(rs) = (char *)malloc(n*SAMPSIZ + extra_points*SM_POINTSIZ);
40 if (!RS_BASE(rs))
41 error(SYSTEM,"smInit_samples(): Unable to allocate memory");
42
43 /* assign larger alignment types earlier */
44 RS_W_PT(rs) = (float (*)[3])RS_BASE(rs);
45 RS_W_DIR(rs) = (int4 *)(RS_W_PT(rs) + n + extra_points);
46 RS_BRT(rs) = (TMbright *)(RS_W_DIR(rs) + n + extra_points);
47 RS_CHR(rs) = (BYTE (*)[3])(RS_BRT(rs) + n);
48 RS_RGB(rs) = (BYTE (*)[3])(RS_CHR(rs) + n);
49 RS_MAX_SAMP(rs) = n;
50 RS_MAX_AUX_PT(rs) = n + extra_points;
51
52 smClear_samples(sm);
53
54 return(n);
55 }
56
57 smClear_aux_samples(sm)
58 SM *sm;
59 {
60 RS_NEXT_AUX_PT(SM_SAMP(sm)) = RS_MAX_SAMP(SM_SAMP(sm));
61 }
62
63 int
64 smClear_samples(sm)
65 SM *sm;
66 {
67 RSAMP *samp;
68
69 samp = SM_SAMP(sm);
70 RS_FREE_SAMP(samp) = -1;
71 RS_REPLACE_SAMP(samp) = 0;
72 RS_NUM_SAMP(samp) = 0;
73 RS_TONE_MAP(samp) = 0;
74 smClear_aux_samples(sm);
75 return(1);
76 }
77
78 int
79 smAdd_aux_point(sm,v,d)
80 SM *sm;
81 FVECT v,d;
82 {
83 RSAMP *samp;
84 int id;
85
86 /* Get the SM sample array */
87 samp = SM_SAMP(sm);
88 /* Get pointer to next available point */
89 id = RS_NEXT_AUX_PT(samp);
90 if(id >= RS_MAX_AUX_PT(samp))
91 return(-1);
92
93 /* Update free aux pointer */
94 RS_NEXT_AUX_PT(samp)++;
95
96 /* Copy vector into point */
97 VCOPY(RS_NTH_W_PT(samp,id),v);
98 RS_NTH_W_DIR(samp,id) = encodedir(d);
99 return(id);
100 }
101
102 void
103 smInit_sample(sm,id,c,d,p)
104 SM *sm;
105 int id;
106 COLR c;
107 FVECT d,p;
108 {
109 RSAMP *samp;
110
111 samp = SM_SAMP(sm);
112 if(p)
113 {
114 /* Copy vector into point */
115 VCOPY(RS_NTH_W_PT(samp,id),p);
116 RS_NTH_W_DIR(samp,id) = encodedir(d);
117 }
118 else
119 {
120 VADD(RS_NTH_W_PT(samp,id),d,SM_VIEW_CENTER(sm));
121 RS_NTH_W_DIR(samp,id) = -1;
122 }
123
124 #ifndef TEST_DRIVER
125 tmCvColrs(&RS_NTH_BRT(samp,id),RS_NTH_CHR(samp,id),c,1);
126 #else
127 if(c)
128 {
129 RS_NTH_RGB(samp,id)[0] = c[0];
130 RS_NTH_RGB(samp,id)[1] = c[1];
131 RS_NTH_RGB(samp,id)[2] = c[2];
132 }
133 else
134 {
135 RS_NTH_RGB(samp,id)[0] = 100;
136 RS_NTH_RGB(samp,id)[1] = 0;
137 RS_NTH_RGB(samp,id)[2] = 0;
138 }
139 #endif
140 }
141
142
143 void
144 smReset_sample(sm,id,n_id)
145 SM *sm;
146 int id,n_id;
147 {
148 RSAMP *samp;
149
150 samp = SM_SAMP(sm);
151
152 /* Copy vector into point */
153 VCOPY(RS_NTH_W_PT(samp,id),RS_NTH_W_PT(samp,n_id));
154 RS_NTH_W_DIR(samp,id) = RS_NTH_W_DIR(samp,n_id);
155
156 RS_NTH_BRT(samp,id) = RS_NTH_BRT(samp,n_id);
157 RS_NTH_CHR(samp,id)[0] = RS_NTH_CHR(samp,n_id)[0];
158 RS_NTH_CHR(samp,id)[1] = RS_NTH_CHR(samp,n_id)[1];
159 RS_NTH_CHR(samp,id)[2] = RS_NTH_CHR(samp,n_id)[2];
160 RS_NTH_RGB(samp,id)[0] = RS_NTH_RGB(samp,n_id)[0];
161 RS_NTH_RGB(samp,id)[1] = RS_NTH_RGB(samp,n_id)[1];
162 RS_NTH_RGB(samp,id)[2] = RS_NTH_RGB(samp,n_id)[2];
163
164 }
165
166 int
167 rsAlloc_samp(samp,replaced)
168 RSAMP *samp;
169 int *replaced;
170
171 {
172 int id;
173
174 if(replaced)
175 *replaced = FALSE;
176 if(RS_NUM_SAMP(samp) < RS_MAX_SAMP(samp))
177 {
178 id = RS_NUM_SAMP(samp);
179 RS_NUM_SAMP(samp)++;
180
181 }
182 else
183 if(RS_REPLACE_SAMP(samp) != -1)
184 {
185 id = RS_REPLACE_SAMP(samp);
186 /* NOTE: NEED to do LRU later*/
187 RS_REPLACE_SAMP(samp) = (id + 1)% RS_MAX_SAMP(samp);
188 if(replaced)
189 *replaced = TRUE;
190 }
191 else
192 if(RS_FREE_SAMP(samp) != -1)
193 {
194 id = RS_FREE_SAMP(samp);
195 RS_FREE_SAMP(samp) = RS_NTH_W_DIR(samp,id);
196 }
197 else
198 {
199 #ifdef DEBUG
200 eputs("rsAlloc_samp(): no samples available");
201 #endif
202 id = -1;
203 }
204
205 return(id);
206 }
207
208 int
209 rsDelete_sample(samp,id)
210 RSAMP *samp;
211 int id;
212 {
213 /* First check for a valid id */
214 if(id >= RS_MAX_SAMP(samp) || id < 0)
215 return(FALSE);
216
217 RS_NTH_W_DIR(samp,id) = RS_FREE_SAMP(samp);
218 RS_FREE_SAMP(samp) = id;
219
220 return(TRUE);
221 }
222
223 int
224 smDelete_sample(sm,id)
225 SM *sm;
226 int id;
227 {
228 RSAMP *samp;
229
230 samp = SM_SAMP(sm);
231 return(rsDelete_sample(samp,id));
232 }
233
234 /* NEEDS: to add free list- and bit for clocked LRU */
235 int
236 smAdd_sample_point(sm,c,dir,p)
237 SM *sm;
238 COLR c;
239 FVECT dir;
240 FVECT p;
241
242 {
243 RSAMP *samp;
244 int id;
245 int replaced;
246
247 /* Get the SM sample array */
248 samp = SM_SAMP(sm);
249 /* Get pointer to next available point */
250 id = rsAlloc_samp(samp,&replaced);
251 if(id < 0)
252 return(-1);
253
254 if(replaced)
255 smMesh_remove_vertex(sm,id);
256
257 smInit_sample(sm,id,c,dir,p);
258
259 return(id);
260 }
261
262
263
264
265
266
267
268
269