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

Comparing ray/src/hd/sm_samp.c (file contents):
Revision 3.3 by gwlarson, Tue Oct 6 18:16:54 1998 UTC vs.
Revision 3.8 by greg, Fri Jun 20 00:25:49 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * sm_samp.c
6   */
# Line 12 | Line 9 | static char SCCSid[] = "$SunId$ SGI";
9   #include "rhd_sample.h"
10  
11   SAMP rsL;
12 < int4 *samp_flag=NULL;
12 > int32 *samp_flag=NULL;
13  
17
14   /* Each sample has a world coord point, and direction, brightness,chrominance,
15     and RGB triples
16   */
17 < #ifndef HP_VERSION
17 >
18   #define TMSIZE sizeof(TMbright)
19 < #else
24 < #define TMSIZE 0
25 < #endif
26 < #define SAMPSIZ (3*sizeof(float)+sizeof(int4)+ 6*sizeof(BYTE) + TMSIZE)
19 > #define SAMPSIZ (3*sizeof(SFLOAT)+sizeof(int32)+ 6*sizeof(BYTE) + TMSIZE + 2*sizeof(int))
20  
21 < /* Extra points just need direction and world space point */
22 < #define POINTSIZ (3*sizeof(float))
21 > /* Extra points world space point, vert flag and qt flag */
22 > #define POINTSIZ (3*sizeof(SFLOAT) + 2*sizeof(int))
23  
24   /* Clear the flags for all samples */
25   sClear_all_flags(s)
26   SAMP *s;
27   {
28    if(samp_flag)
29 <    bzero((char *)samp_flag,FLAG_BYTES(S_MAX_SAMP(s)));
29 >    bzero((char *)samp_flag,FLAG_BYTES(S_MAX_BASE_PT(s)));
30   }
31  
32   sInit(s)
# Line 44 | Line 37 | sInit(s)
37    S_TONE_MAP(s) = 0;
38    S_FREE_SAMP(s) = -1;
39    sClear_base_points(s);
47  sClear_all_flags(s);
40  
41   }
42  
# Line 80 | Line 72 | int *nptr,extra_points;
72    /* get number of samples that fit in block */
73    n = (i - 8 - extra_points*POINTSIZ) / SAMPSIZ;        
74  
75 +  /* Must make sure n + extra_points can fit in a S_ID identifier */
76 +  if ( n > (S_ID_MAX - extra_points))
77 +    n = (S_ID_MAX - extra_points);
78 +
79    S_BASE(s) = (char *)malloc(n*SAMPSIZ + extra_points*POINTSIZ);
80    if (!S_BASE(s))
81 <    error(SYSTEM,"smInit_samples(): Unable to allocate memory");
81 >    error(SYSTEM,"sAlloc(): Unable to allocate memory");
82  
83    /* assign larger alignment types earlier */
84 <  S_W_PT(s) = (float (*)[3])S_BASE(s);
85 <  S_W_DIR(s) = (int4 *)(S_W_PT(s) + n + extra_points);
86 < #ifndef HP_VERSION
91 < S_BRT(s) = (TMbright *)(S_W_DIR(s) + n);
84 >  S_W_PT(s) = (SFLOAT(*)[3])S_BASE(s);
85 >  S_W_DIR(s) = (int32 *)(S_W_PT(s) + n + extra_points);
86 >  S_BRT(s) = (TMbright *)(S_W_DIR(s) + n);
87    S_CHR(s) = (BYTE (*)[3])(S_BRT(s) + n);
93 #else
94  S_CHR(s) = (BYTE (*)[3])(S_W_DIR(s) + n);
95 #endif
88    S_RGB(s) = (BYTE (*)[3])(S_CHR(s) + n);
89 +  S_INFO(s) = (int *)(S_RGB(s)+n);
90 +  S_INFO1(s) = (int *)(S_INFO(s)+n+extra_points);
91    S_MAX_SAMP(s) = n;
92    S_MAX_BASE_PT(s) = n + extra_points;
93  
94    /* Allocate memory for a per/sample bit flag */
95 <  if(!(samp_flag = (int4 *)malloc(FLAG_BYTES(n))))
96 <    error(SYSTEM,"smInit_samples(): Unable to allocate flag memory");
103 <
95 >  if(!(samp_flag = (int32 *)malloc(FLAG_BYTES(n+extra_points))))
96 >    error(SYSTEM,"sAlloc(): Unable to allocate flag memory");
97    sInit(s);
98 +  sClear_all_flags(s);
99 +
100    *nptr = n;
101    
102    return(s);
# Line 112 | Line 107 | int *nptr,extra_points;
107     is added: These points are not displayed-they are used to form the
108     initial mesh
109   */
110 < int
110 > S_ID
111   sAdd_base_point(s,v)
112       SAMP *s;
113       FVECT v;
114   {
115 <    int id;
115 >    S_ID id;
116  
117      /* Get pointer to next available point */
118      id = S_NEXT_BASE_PT(s);
# Line 132 | Line 127 | sAdd_base_point(s,v)
127      return(id);
128   }
129  
135 /* Initialize the sample 'id' to contain world point 'p', direction 'd' and
136   color 'c'. If 'p' is NULL, a direction only is represented in 'd'. In
137   this case, the world point is set to the projection of the direction on
138   the view sphere, and the direction value is set to -1
139 */
140 void
141 sInit_samp(s,id,c,d,p)
142   SAMP *s;
143   int id;
144   COLR c;
145   FVECT d,p;
146 {
147    /* Copy vector into point */
148    VCOPY(S_NTH_W_PT(s,id),p);
149    if(d)
150      S_NTH_W_DIR(s,id) = encodedir(d);
151  /* direction only */
152    else
153      S_NTH_W_DIR(s,id) = -1;
154
155   /* calculate the brightness and chrominance */
156 #ifndef TEST_DRIVER
157    tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1);
158 #else
159    if(c)
160    {
161      S_NTH_RGB(s,id)[0] = c[0];
162      S_NTH_RGB(s,id)[1] = c[1];
163      S_NTH_RGB(s,id)[2] = c[2];
164    }
165    else
166    {
167        S_NTH_RGB(s,id)[0] = 100;
168       S_NTH_RGB(s,id)[1] = 0;
169       S_NTH_RGB(s,id)[2] = 0;
170    }
171 #endif
172    /* Set ACTIVE bit upon creation */
173    S_SET_FLAG(id);
174
175 }
176
177
130   /* Copy the values of sample n_id into sample id: Note must not call with
131     Base point n_id
132   */
133   int
134 < sReset_samp(s,n_id,id)
134 > sCopy_samp(s,n_id,id)
135     SAMP *s;
136 <   int n_id,id;
136 >   S_ID n_id,id;
137   {
138  
139   #ifdef DEBUG
# Line 191 | Line 143 | sReset_samp(s,n_id,id)
143       return(0);
144     }
145   #endif
146 <
146 >   if(n_id == id)
147 >     return(1);
148   /* Copy vector into point */
149     VCOPY(S_NTH_W_PT(s,n_id),S_NTH_W_PT(s,id));
150     S_NTH_W_DIR(s,n_id) = S_NTH_W_DIR(s,id);
151  
199 #ifndef HP_VERSION
152     S_NTH_BRT(s,n_id) = S_NTH_BRT(s,id);
201 #endif
153     S_NTH_CHR(s,n_id)[0] = S_NTH_CHR(s,id)[0];
154     S_NTH_CHR(s,n_id)[1] = S_NTH_CHR(s,id)[1];
155     S_NTH_CHR(s,n_id)[2] = S_NTH_CHR(s,id)[2];
156 +
157     return(1);
158   }
159  
160 +
161 + /* Initialize the sample 'id' to contain world point 'p', direction 'd' and
162 +   color 'c'. If 'p' is NULL, a direction only is represented in 'd'. In
163 +   this case, the world point is set to the projection of the direction on
164 +   the view sphere, and the direction value is set to -1
165 + */
166 + void
167 + sInit_samp(s,id,c,d,p,o_id)
168 +   SAMP *s;
169 +   S_ID id;
170 +   COLR c;
171 +   FVECT d,p;
172 +   S_ID o_id;
173 + {
174 +
175 +  if(o_id != INVALID)
176 +    sCopy_samp(s,id,o_id);
177 +  else
178 +  {
179 +    /* Copy vector into point */
180 +    VCOPY(S_NTH_W_PT(s,id),p);
181 +    if(d)
182 +      S_NTH_W_DIR(s,id) = encodedir(d);
183 +    else
184 +      S_NTH_W_DIR(s,id) = -1;
185 +
186 +    /* calculate the brightness and chrominance,RGB will be set by
187 +       tonemapping
188 +       */
189 +    tmCvColrs(&S_NTH_BRT(s,id),S_NTH_CHR(s,id),c,1);
190 +  }
191 +    /* Set ACTIVE bit upon creation */
192 +  S_SET_FLAG(id);
193 +  if(id < S_TONE_MAP(s))
194 +    tmMapPixels(S_NTH_RGB(s,id),&S_NTH_BRT(s,id),S_NTH_CHR(s,id),1);
195 + }
196 +
197 +
198   /* Allocate a new sample. If an existing sample was replaced: set flag */
199 < int
199 > S_ID
200   sAlloc_samp(s,replaced)
201     SAMP *s;
202     int *replaced;
203    
204   {
205 <    int id;
205 >    S_ID id;
206  
207 <    if(replaced)
218 <       *replaced = 0;
219 <
207 >    /* First check if there are any freed sample available */
208      if((id = S_FREE_SAMP(s)) != INVALID)
209      {
210 <      S_FREE_SAMP(s) = INVALID;
210 >      *replaced = 0;
211 > #if 0
212 >      fprintf(stderr,"allocating previously freed sample %d\n",id);
213 > #endif
214 >      S_FREE_SAMP(s) = S_NTH_NEXT(s,id);
215        return(id);
216      }
217      /* If havn't reached end of sample array:return next sample */
218      if(S_NUM_SAMP(s) < S_MAX_SAMP(s))
227        id = S_NUM_SAMP(s)++;
228    else
219      {
220 <      /* CLOCKED LRU replacement policy: Search through samples starting
221 <         with S_REPLACE_SAMP for a sample that does not have its active
222 <         bit set. Clear bit along the way
223 <       */
224 <      id = S_REPLACE_SAMP(s);
225 <      while(S_IS_FLAG(id))
236 <      {
237 <        S_CLR_FLAG(id);
238 <        id = (id +1)% S_MAX_SAMP(s);
239 <      }
240 <      S_REPLACE_SAMP(s) = id = (id +1)% S_MAX_SAMP(s);
241 <      if(replaced)
242 <        *replaced = 1;
220 >      id = S_NUM_SAMP(s)++;
221 > #if 0
222 >      fprintf(stderr,"allocating sample %d\n",id);
223 > #endif
224 >      *replaced = 0;
225 >      return(id);
226      }
244    return(id);
245 }
227  
228 < /* Set the sample flag to be unused- so will get replaced on next LRU
248 <   iteration
249 <   */
250 <
251 < /* NOTE: Do we want a free list as well? */
252 < int
253 < sDelete_samp(s,id)
254 < SAMP *s;
255 < int id;
228 > #ifdef DEBUG
229   {
230 < #ifdef DEBUG
231 <    /* Fist check for a valid id */
232 <    if(id >= S_MAX_SAMP(s) || id < 0)
233 <       return(0);
230 >  static int replace = 0;
231 >  if(replace == 0)
232 >  {
233 >    eputs("Out of samples: using replacement strategy\n");
234 >    replace =1 ;
235 >  }
236 > }
237   #endif
238      
239 <    S_CLR_FLAG(id);
240 <    return(1);
239 >    /* CLOCKED LRU replacement policy: Search through samples starting
240 >       with S_REPLACE_SAMP for a sample that does not have its active
241 >       bit set. Clear bit along the way
242 >     */
243 >    id = S_REPLACE_SAMP(s);
244 >    while(S_IS_FLAG(id))
245 >    {
246 >      S_CLR_FLAG(id);
247 >      id = (id +1)% S_MAX_SAMP(s);
248 >    }
249 >    S_REPLACE_SAMP(s) = (id +1)% S_MAX_SAMP(s);
250 >    *replaced = 1;
251 >    return(id);
252   }
253 +
254 +
255 +
256 +
257 +
258 +
259 +
260 +
261 +
262 +
263 +
264 +
265  
266  
267  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines