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.10 by greg, Sat Feb 22 02:07:25 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines