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.2 by gwlarson, Fri Mar 5 17:03:38 1999 UTC vs.
Revision 3.5 by gwlarson, Tue Mar 9 11:41:29 1999 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "view.h"
13  
14   #ifndef DEPS
15 < #define DEPS            0.01    /* depth epsilon */
15 > #define DEPS            0.02    /* depth epsilon */
16   #endif
17 + #ifndef PEPS
18 + #define PEPS            0.04    /* pixel value epsilon */
19 + #endif
20   #ifndef MAXRAD
21   #define MAXRAD          64      /* maximum kernel radius */
22   #endif
# Line 39 | Line 42 | static char SCCSid[] = "$SunId$ SGI";
42  
43   static int4     *pixFlags;      /* pixel occupancy flags */
44   static float    pixWeight[MAXRAD2];     /* pixel weighting function */
45 + static short    isqrttab[MAXRAD2];      /* integer square root table */
46  
47 + #define isqrt(i2)       ((int)isqrttab[(int)(i2)])
48 +
49   extern VIEW     myview;         /* current output view */
50   extern COLOR    *mypixel;       /* pixels being rendered */
51   extern float    *myweight;      /* weights (used to compute final pixels) */
# Line 107 | Line 113 | register HDBEAMI       *hb;
113   int
114   kill_occl(h, v, nl, n)          /* check for occlusion errors */
115   int     h, v;
116 < short   nl[NNEIGH][2];
116 > register short  nl[NNEIGH][2];
117   int     n;
118   {
119          short   forequad[2][2];
120          int     d;
121 <        register int4   i;
121 >        register int4   i, 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]);
133 <                if (mydepth[nl[i][1]*hres+nl[i][0]] <
134 <                                mydepth[v*hres+h]*(1.-DEPS*d))
133 >                d = isqrt(d);
134 >                if (mydepth[nl[i][1]*hres+nl[i][0]]*(1.+DEPS*d) < mydepth[p])
135                          forequad[nl[i][0]<h][nl[i][1]<v] = 1;
136          }
137 <        if (forequad[0][0]+forequad[0][1]+forequad[1][0]+forequad[1][1] > 1) {
138 <                i = v*hres + h;
139 <                setcolor(mypixel[i], 0., 0., 0.);
129 <                myweight[i] = 0.;       /* occupancy reset afterwards */
137 >        if (forequad[0][0]+forequad[0][1]+forequad[1][0]+forequad[1][1] > 2) {
138 >                setcolor(mypixel[p], 0., 0., 0.);
139 >                myweight[p] = 0.;       /* occupancy reset afterwards */
140          }
141          return(1);
142   }
# Line 138 | Line 148 | int    h, v;
148   register short  nl[NNEIGH][2];
149   int     n;
150   {
151 +        int     dis[NNEIGH], ndis;
152          COLOR   mykern[MAXRAD2];
142        float   mykw[MAXRAD2];
153          int4    maxr2;
154 <        double  w;
154 >        double  d;
155          register int4   p, r2;
156 <        int     maxr, h2, v2;
156 >        int     i, r, maxr, h2, v2;
157  
158          if (n <= 0)
159                  return(1);
160          p = v*hres + h;                         /* build kernel values */
161          maxr2 = (h-nl[n-1][0])*(h-nl[n-1][0]) + (v-nl[n-1][1])*(v-nl[n-1][1]);
162          DCHECK(maxr2>=MAXRAD2, CONSISTENCY, "out of range neighbor");
163 <        for (r2 = maxr2+1; --r2; ) {
164 <                copycolor(mykern[r2], mypixel[p]);
165 <                mykw[r2] = pixWeight[r2];
166 <                if (2*r2 >= maxr2)              /* soften skirt */
167 <                        mykw[r2] *= (2*(maxr2-r2)+1.0)/maxr2;
168 <                scalecolor(mykern[r2], mykw[r2]);
163 >        maxr = isqrt(maxr2);
164 >        for (v2 = 1; v2 <= maxr; v2++)
165 >                for (h2 = 0; h2 <= v2; h2++) {
166 >                        r2 = h2*h2 + v2*v2;
167 >                        if (r2 > maxr2) break;
168 >                        copycolor(mykern[r2], mypixel[p]);
169 >                        scalecolor(mykern[r2], pixWeight[r2]);
170 >                }
171 >        ndis = 0;                               /* find discontinuities */
172 >        for (i = n; i--; ) {
173 >                r2 = (h-nl[i][0])*(h-nl[i][0]) + (v-nl[i][1])*(v-nl[i][1]);
174 >                r = isqrt(r2);
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],
178 >                                mypixel[nl[i][1]*hres+nl[i][0]], r*PEPS))
179 >                        dis[ndis++] = i;
180          }
181 <        maxr = sqrt((double)maxr2) + .99;       /* stamp out that kernel */
181 >                                                /* stamp out that kernel */
182          for (v2 = v-maxr; v2 <= v+maxr; v2++) {
183 <                if (v2 < 0) continue;
184 <                if (v2 >= vres) break;
183 >                if (v2 < 0) v2 = 0;
184 >                else if (v2 >= vres) break;
185                  for (h2 = h-maxr; h2 <= h+maxr; h2++) {
186 <                        if (h2 < 0) continue;
187 <                        if (h2 >= hres) break;
188 <                        r2 = (v2-v)*(v2-v) + (h2-h)*(h2-h);
186 >                        if (h2 < 0) h2 = 0;
187 >                        else if (h2 >= hres) break;
188 >                        r2 = (h2-h)*(h2-h) + (v2-v)*(v2-v);
189                          if (r2 > maxr2) continue;
190                          if (CHK4(pixFlags, v2*hres+h2))
191                                  continue;       /* occupied */
192 +                        for (i = ndis; i--; ) {
193 +                                r = (h2-nl[dis[i]][0])*(h2-nl[dis[i]][0]) +
194 +                                        (v2-nl[dis[i]][1])*(v2-nl[dis[i]][1]);
195 +                                if (r < r2) break;
196 +                        }
197 +                        if (i >= 0) continue;   /* outside edge */
198                          addcolor(mypixel[v2*hres+h2], mykern[r2]);
199 <                        myweight[v2*hres+h2] += mykw[r2]*myweight[v*hres+h];
199 >                        myweight[v2*hres+h2] += pixWeight[r2] * myweight[p];
200                  }
201          }
202          return(1);
# Line 178 | Line 205 | int    n;
205  
206   pixFlush()                      /* done with beams -- flush pixel values */
207   {
208 +        if (pixWeight[0] <= FTINY)
209 +                init_wfunc();           /* initialize weighting function */
210          reset_flags();                  /* set occupancy flags */
211          meet_neighbors(kill_occl);      /* eliminate occlusion errors */
212          reset_flags();                  /* reset occupancy flags */
184        if (pixWeight[0] <= FTINY) {    /* initialize weighting function */
185                register int    r;
186                for (r = MAXRAD2; --r; )
187                        pixWeight[r] = G0NORM/sqrt((double)r);
188                pixWeight[0] = 1.;
189        }
213          meet_neighbors(grow_samp);      /* grow valid samples over image */
214          free((char *)pixFlags);         /* free pixel flags */
215          pixFlags = NULL;
# Line 195 | Line 218 | pixFlush()                     /* done with beams -- flush pixel values
218  
219   reset_flags()                   /* allocate/set/reset occupancy flags */
220   {
221 <        register int    p;
221 >        register int4   p;
222  
223          if (pixFlags == NULL) {
224                  pixFlags = (int4 *)calloc(FL4NELS(hres*vres), sizeof(int4));
# Line 208 | Line 231 | reset_flags()                  /* allocate/set/reset occupancy flags
231   }
232  
233  
234 + init_wfunc()                    /* initialize weighting function */
235 + {
236 +        register int    i, j;
237 +        register int4   r2;
238 +        register double d;
239 +
240 +        for (i = 1; i <= MAXRAD; i++)
241 +                for (j = 0; j <= i; j++) {
242 +                        r2 = i*i + j*j;
243 +                        if (r2 >= MAXRAD2) break;
244 +                        d = sqrt((double)r2);
245 +                        pixWeight[r2] = G0NORM/d;
246 +                        isqrttab[r2] = d + 0.99;
247 +                }
248 +        pixWeight[0] = 1.;
249 +        isqrttab[0] = 0;
250 + }
251 +
252 +
253   int
254   findneigh(nl, h, v, rnl)        /* find NNEIGH neighbors for pixel */
255   short   nl[NNEIGH][2];
# Line 215 | Line 257 | int    h, v;
257   register short  (*rnl)[NNEIGH];
258   {
259          int     nn = 0;
260 <        int4    d, ld, nd[NNEIGH+1];
260 >        int4    d, nd[NNEIGH];
261          int     n, hoff;
262          register int    h2, n2;
263  
264 <        ld = MAXRAD2;
264 >        nd[NNEIGH-1] = MAXRAD2;
265          for (hoff = 1; hoff < hres; hoff = (hoff<0) - hoff) {
266                  h2 = h + hoff;
267                  if (h2 < 0 | h2 >= hres)
268                          continue;
269 <                if ((h2-h)*(h2-h) >= ld)
269 >                if ((h2-h)*(h2-h) >= nd[NNEIGH-1])
270                          break;
271                  for (n = 0; n < NNEIGH && rnl[h2][n] < NINF; n++) {
272                          d = (h2-h)*(h2-h) + (v-rnl[h2][n])*(v-rnl[h2][n]);
273 <                        if (d >= ld)
273 >                        if (d >= nd[NNEIGH-1])
274                                  continue;
275 <                        for (n2 = nn; ; n2--)   {       /* insert neighbor */
275 >                        if (nn < NNEIGH)        /* insert neighbor */
276 >                                nn++;
277 >                        for (n2 = nn; n2--; )   {
278                                  if (!n2 || d >= nd[n2-1]) {
279                                          nd[n2] = d;
280                                          nl[n2][0] = h2;
# Line 241 | Line 285 | register short (*rnl)[NNEIGH];
285                                  nl[n2][0] = nl[n2-1][0];
286                                  nl[n2][1] = nl[n2-1][1];
287                          }
244                        if (nn < NNEIGH)
245                                nn++;
246                        else
247                                ld = nd[NNEIGH-1];
288                  }
289          }
290          return(nn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines