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.4 by gwlarson, Mon Mar 8 17:34:24 1999 UTC vs.
Revision 3.9 by gwlarson, Wed Mar 10 16:15:19 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 21 | Line 22 | static char SCCSid[] = "$SunId$ SGI";
22   #define MAXRAD          64      /* maximum kernel radius */
23   #endif
24   #ifndef NNEIGH
25 < #define NNEIGH          7       /* find this many neighbors */
25 > #define NNEIGH          5       /* find this many neighbors */
26   #endif
27  
28   #define NINF            16382
# Line 44 | Line 45 | static int4    *pixFlags;      /* pixel occupancy flags */
45   static float    pixWeight[MAXRAD2];     /* pixel weighting function */
46   static short    isqrttab[MAXRAD2];      /* integer square root table */
47  
48 < #define isqrt(i2)       ((int)isqrttab[(int)(i2)])
48 > #define isqrt(i2)       (isqrttab[i2])
49  
50   extern VIEW     myview;         /* current output view */
51   extern COLOR    *mypixel;       /* pixels being rendered */
# Line 111 | Line 112 | register HDBEAMI       *hb;
112  
113  
114   int
115 < kill_occl(h, v, nl, n)          /* check for occlusion errors */
115 > kill_occl(h, v, nl, nd, n)              /* check for occlusion errors */
116   int     h, v;
117   register short  nl[NNEIGH][2];
118 + int     nd[NNEIGH];
119   int     n;
120   {
121          short   forequad[2][2];
122          int     d;
123 <        register int4   i, p;
123 >        register int    i;
124 >        register int4   p;
125  
126 <        if (n <= 0)
126 >        if (n <= 0) {
127 > #ifdef DEBUG
128 >                error(WARNING, "neighborless sample in kill_occl");
129 > #endif
130                  return(1);
131 +        }
132          p = v*hres + h;
133          forequad[0][0] = forequad[0][1] = forequad[1][0] = forequad[1][1] = 0;
134          for (i = n; i--; ) {
135 <                d = (h-nl[i][0])*(h-nl[i][0]) + (v-nl[i][1])*(v-nl[i][1]);
129 <                d = isqrt(d);
135 >                d = isqrt(nd[i]);
136                  if (mydepth[nl[i][1]*hres+nl[i][0]]*(1.+DEPS*d) < mydepth[p])
137                          forequad[nl[i][0]<h][nl[i][1]<v] = 1;
138          }
# Line 139 | Line 145 | int    n;
145  
146  
147   int
148 < grow_samp(h, v, nl, n)          /* grow sample point appropriately */
148 > smooth_samp(h, v, nl, nd, n)    /* grow sample point smoothly */
149   int     h, v;
150   register short  nl[NNEIGH][2];
151 + int     nd[NNEIGH];
152   int     n;
153   {
154          int     dis[NNEIGH], ndis;
155          COLOR   mykern[MAXRAD2];
156 <        int4    maxr2;
157 <        double  w, d;
158 <        register int4   p, r2;
156 >        int     maxr2;
157 >        double  d;
158 >        register int4   p;
159 >        register int    r2;
160          int     i, r, maxr, h2, v2;
161  
162          if (n <= 0)
163                  return(1);
164          p = v*hres + h;                         /* build kernel values */
165 <        maxr2 = (h-nl[n-1][0])*(h-nl[n-1][0]) + (v-nl[n-1][1])*(v-nl[n-1][1]);
165 >        maxr2 = nd[n-1];
166          DCHECK(maxr2>=MAXRAD2, CONSISTENCY, "out of range neighbor");
167          maxr = isqrt(maxr2);
168          for (v2 = 1; v2 <= maxr; v2++)
# Line 166 | Line 174 | int    n;
174                  }
175          ndis = 0;                               /* find discontinuities */
176          for (i = n; i--; ) {
177 <                r2 = (h-nl[i][0])*(h-nl[i][0]) + (v-nl[i][1])*(v-nl[i][1]);
170 <                r = isqrt(r2);
177 >                r = isqrt(nd[i]);
178                  d = mydepth[nl[i][1]*hres+nl[i][0]] / mydepth[p];
179                  d = d>=1. ? d-1. : 1.-d;
180                  if (d > r*DEPS || bigdiff(mypixel[p],
# Line 192 | Line 199 | int    n;
199                          }
200                          if (i >= 0) continue;   /* outside edge */
201                          addcolor(mypixel[v2*hres+h2], mykern[r2]);
202 <                        myweight[v2*hres+h2] += pixWeight[r2] *
196 <                                                        myweight[v*hres+h];
202 >                        myweight[v2*hres+h2] += pixWeight[r2] * myweight[p];
203                  }
204          }
205          return(1);
206   }
207  
208  
209 < pixFlush()                      /* done with beams -- flush pixel values */
209 > int
210 > random_samp(h, v, nl, nd, n, rf)        /* gather samples randomly */
211 > int     h, v;
212 > register short  nl[NNEIGH][2];
213 > int     nd[NNEIGH];
214 > int     n;
215 > double  *rf;
216   {
217 <        reset_flags();                  /* set occupancy flags */
218 <        meet_neighbors(kill_occl);      /* eliminate occlusion errors */
219 <        reset_flags();                  /* reset occupancy flags */
217 >        float   rnt[NNEIGH];
218 >        double  rvar;
219 >        register int4   p, pn;
220 >        register int    ni;
221 >
222 >        if (n <= 0)
223 >                return(1);
224 >        p = v*hres + h;
225 >        if (*rf <= FTINY)               /* straight Voronoi regions */
226 >                ni = 0;
227 >        else {                          /* weighted choice */
228 >                DCHECK(nd[n-1]>=MAXRAD2, CONSISTENCY, "out of range neighbor");
229 >                rnt[0] = pixWeight[nd[0]];
230 >                for (ni = 1; ni < n; ni++)
231 >                        rnt[ni] = rnt[ni-1] + pixWeight[nd[ni]];
232 >                rvar = rnt[n-1]*pow(frandom(), 1. / *rf);
233 >                for (ni = 0; rvar > rnt[ni]+FTINY; ni++)
234 >                        ;
235 >        }
236 >        pn = nl[ni][1]*hres + nl[ni][0];
237 >        addcolor(mypixel[p], mypixel[pn]);
238 >        myweight[p] += myweight[pn];
239 >        return(1);
240 > }
241 >
242 >
243 > pixFinish(ransamp)              /* done with beams -- compute pixel values */
244 > double  ransamp;
245 > {
246          if (pixWeight[0] <= FTINY)
247                  init_wfunc();           /* initialize weighting function */
248 <        meet_neighbors(grow_samp);      /* grow valid samples over image */
248 >        reset_flags();                  /* set occupancy flags */
249 >        meet_neighbors(1,kill_occl,NULL); /* identify occlusion errors */
250 >        reset_flags();                  /* reset occupancy flags */
251 >        if (ransamp >= 0.)              /* spread samples over image */
252 >                meet_neighbors(0,random_samp,&ransamp);
253 >        else
254 >                meet_neighbors(1,smooth_samp,NULL);
255          free((char *)pixFlags);         /* free pixel flags */
256          pixFlags = NULL;
257   }
# Line 230 | Line 274 | reset_flags()                  /* allocate/set/reset occupancy flags
274  
275   init_wfunc()                    /* initialize weighting function */
276   {
277 <        register int    i, j;
234 <        register int4   r2;
277 >        register int    r2;
278          register double d;
279  
280 <        for (i = 1; i <= MAXRAD; i++)
281 <                for (j = 0; j <= i; j++) {
282 <                        r2 = i*i + j*j;
283 <                        if (r2 >= MAXRAD2) break;
284 <                        d = sqrt((double)r2);
242 <                        pixWeight[r2] = G0NORM/d;
243 <                        isqrttab[r2] = d + 0.99;
244 <                }
280 >        for (r2 = MAXRAD2; --r2; ) {
281 >                d = sqrt((double)r2);
282 >                pixWeight[r2] = G0NORM/d;
283 >                isqrttab[r2] = d + 0.99;
284 >        }
285          pixWeight[0] = 1.;
286          isqrttab[0] = 0;
287   }
288  
289  
290   int
291 < findneigh(nl, h, v, rnl)        /* find NNEIGH neighbors for pixel */
291 > findneigh(nl, nd, h, v, rnl)    /* find NNEIGH neighbors for pixel */
292   short   nl[NNEIGH][2];
293 + int     nd[NNEIGH];
294   int     h, v;
295   register short  (*rnl)[NNEIGH];
296   {
297          int     nn = 0;
298 <        int4    d, nd[NNEIGH];
258 <        int     n, hoff;
298 >        int     d, n, hoff;
299          register int    h2, n2;
300  
301          nd[NNEIGH-1] = MAXRAD2;
302 <        for (hoff = 1; hoff < hres; hoff = (hoff<0) - hoff) {
302 >        for (hoff = 0; hoff < hres; hoff = (hoff<=0) - hoff) {
303                  h2 = h + hoff;
304                  if (h2 < 0 | h2 >= hres)
305                          continue;
# Line 267 | Line 307 | register short (*rnl)[NNEIGH];
307                          break;
308                  for (n = 0; n < NNEIGH && rnl[h2][n] < NINF; n++) {
309                          d = (h2-h)*(h2-h) + (v-rnl[h2][n])*(v-rnl[h2][n]);
310 <                        if (d >= nd[NNEIGH-1])
310 >                        if (d == 0 | d >= nd[NNEIGH-1])
311                                  continue;
312                          if (nn < NNEIGH)        /* insert neighbor */
313                                  nn++;
# Line 288 | Line 328 | register short (*rnl)[NNEIGH];
328   }
329  
330  
331 < meet_neighbors(nf)              /* run through samples and their neighbors */
331 > meet_neighbors(occ, nf, dp)     /* run through samples and their neighbors */
332 > int     occ;
333   int     (*nf)();
334 + char    *dp;
335   {
336          short   ln[NNEIGH][2];
337 +        int     nd[NNEIGH];
338          int     h, v, n, v2;
339          register short  (*rnl)[NNEIGH];
340                                          /* initialize bottom row list */
# Line 310 | Line 353 | int    (*nf)();
353          v = 0;                          /* do each row */
354          for ( ; ; ) {
355                  for (h = 0; h < hres; h++) {
356 <                        if (!CHK4(pixFlags, v*hres+h))
357 <                                continue;       /* no one home */
358 <                        n = findneigh(ln, h, v, rnl);
359 <                        (*nf)(h, v, ln, n);     /* call on neighbors */
356 >                        if (!CHK4(pixFlags, v*hres+h) != !occ)
357 >                                continue;       /* occupancy mismatch */
358 >                                                /* find neighbors */
359 >                        n = findneigh(ln, nd, h, v, rnl);
360 >                                                /* call on neighbors */
361 >                        (*nf)(h, v, ln, nd, n, dp);
362                  }
363                  if (++v >= vres)                /* reinitialize row list */
364                          break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines