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

Comparing ray/src/hd/rhpict2.c (file contents):
Revision 3.5 by gwlarson, Tue Mar 9 11:41:29 1999 UTC vs.
Revision 3.6 by gwlarson, Tue Mar 9 14:23:51 1999 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10  
11   #include "holo.h"
12   #include "view.h"
13 + #include "random.h"
14  
15   #ifndef DEPS
16   #define DEPS            0.02    /* depth epsilon */
# Line 143 | Line 144 | int    n;
144  
145  
146   int
147 < grow_samp(h, v, nl, n)          /* grow sample point appropriately */
147 > smooth_samp(h, v, nl, n)        /* grow sample point smoothly */
148   int     h, v;
149   register short  nl[NNEIGH][2];
150   int     n;
# Line 203 | Line 204 | int    n;
204   }
205  
206  
207 < pixFlush()                      /* done with beams -- flush pixel values */
207 > int
208 > random_samp(h, v, nl, n)        /* grow sample point noisily */
209 > int     h, v;
210 > register short  nl[NNEIGH][2];
211 > int     n;
212   {
213 +        float   nwt[NNEIGH];
214 +        int4    maxr2;
215 +        register int4   p, r2;
216 +        register int    i;
217 +        int     maxr, h2, v2;
218 +        COLOR   ctmp;
219 +
220 +        if (n <= 0)
221 +                return(1);
222 +        p = v*hres + h;                         /* compute kernel radius */
223 +        maxr2 = (h-nl[n-1][0])*(h-nl[n-1][0]) + (v-nl[n-1][1])*(v-nl[n-1][1]);
224 +        DCHECK(maxr2>=MAXRAD2, CONSISTENCY, "out of range neighbor");
225 +        maxr = isqrt(maxr2);
226 +                                                /* compute neighbor weights */
227 +        for (i = n; i--; ) {
228 +                r2 = (nl[i][0]-h)*(nl[i][0]-h) + (nl[i][1]-v)*(nl[i][1]-v);
229 +                nwt[i] = pixWeight[r2];
230 +        }
231 +                                                /* sample kernel */
232 +        for (v2 = v-maxr; v2 <= v+maxr; v2++) {
233 +                if (v2 < 0) v2 = 0;
234 +                else if (v2 >= vres) break;
235 +                for (h2 = h-maxr; h2 <= h+maxr; h2++) {
236 +                        if (h2 < 0) h2 = 0;
237 +                        else if (h2 >= hres) break;
238 +                        r2 = (h2-h)*(h2-h) + (v2-v)*(v2-v);
239 +                        if (r2 > maxr2) continue;
240 +                        if (CHK4(pixFlags, v2*hres+h2))
241 +                                continue;       /* occupied */
242 +                        if (frandom() > pixWeight[r2]) {
243 +                                                /* pick neighbor instead */
244 +                                i = random() % n;
245 +                                r2 = nl[i][1]*hres + nl[i][0];
246 +                                copycolor(ctmp, mypixel[r2]);
247 +                                scalecolor(ctmp, nwt[i]);
248 +                                addcolor(mypixel[v2*hres+h2], ctmp);
249 +                                myweight[v2*hres+h2] += nwt[i] * myweight[r2];
250 +                                continue;
251 +                        }
252 +                        addcolor(mypixel[v2*hres+h2], mypixel[p]);
253 +                        myweight[v2*hres+h2] += myweight[p];
254 +                }
255 +        }
256 +        return(1);
257 + }
258 +
259 +
260 + pixFinish(ransamp)              /* done with beams -- compute pixel values */
261 + int     ransamp;
262 + {
263          if (pixWeight[0] <= FTINY)
264                  init_wfunc();           /* initialize weighting function */
265          reset_flags();                  /* set occupancy flags */
266          meet_neighbors(kill_occl);      /* eliminate occlusion errors */
267          reset_flags();                  /* reset occupancy flags */
268 <        meet_neighbors(grow_samp);      /* grow valid samples over image */
268 >        if (ransamp)                    /* spread samples over image */
269 >                meet_neighbors(random_samp);
270 >        else
271 >                meet_neighbors(smooth_samp);
272          free((char *)pixFlags);         /* free pixel flags */
273          pixFlags = NULL;
274   }
# Line 233 | Line 291 | reset_flags()                  /* allocate/set/reset occupancy flags
291  
292   init_wfunc()                    /* initialize weighting function */
293   {
236        register int    i, j;
294          register int4   r2;
295          register double d;
296  
297 <        for (i = 1; i <= MAXRAD; i++)
298 <                for (j = 0; j <= i; j++) {
299 <                        r2 = i*i + j*j;
300 <                        if (r2 >= MAXRAD2) break;
301 <                        d = sqrt((double)r2);
245 <                        pixWeight[r2] = G0NORM/d;
246 <                        isqrttab[r2] = d + 0.99;
247 <                }
297 >        for (r2 = MAXRAD2; --r2; ) {
298 >                d = sqrt((double)r2);
299 >                pixWeight[r2] = G0NORM/d;
300 >                isqrttab[r2] = d + 0.99;
301 >        }
302          pixWeight[0] = 1.;
303          isqrttab[0] = 0;
304   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines