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

Comparing ray/src/px/pinterp.c (file contents):
Revision 1.2 by greg, Tue Dec 12 11:21:25 1989 UTC vs.
Revision 1.6 by greg, Thu Dec 28 15:09:28 1989 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17   #define pscan(y)        (ourpict+(y)*ourview.hresolu)
18   #define zscan(y)        (ourzbuf+(y)*ourview.hresolu)
19  
20 + #define ABS(x)          ((x)>0?(x):-(x))
21 +
22   VIEW    ourview = STDVIEW(512);         /* desired view */
23  
24   double  zeps = 0.001;                   /* allowed z epsilon */
# Line 29 | Line 31 | char   *progname;
31   VIEW    theirview = STDVIEW(512);       /* input view */
32   int     gotview;                        /* got input view? */
33  
34 + double  theirs2ours[4][4];              /* transformation matrix */
35  
36 +
37   main(argc, argv)                        /* interpolate pictures */
38   int     argc;
39   char    *argv[];
# Line 47 | Line 51 | char   *argv[];
51                          check(2,1);
52                          zeps = atof(argv[++i]);
53                          break;
54 +                case 'x':                               /* x resolution */
55 +                        check(2,1);
56 +                        ourview.hresolu = atoi(argv[++i]);
57 +                        break;
58 +                case 'y':                               /* y resolution */
59 +                        check(2,1);
60 +                        ourview.vresolu = atoi(argv[++i]);
61 +                        break;
62                  case 'v':                               /* view */
63                          switch (argv[i][2]) {
64                          case 't':                               /* type */
# Line 189 | Line 201 | char   *pfile, *zfile;
201                  fprintf(stderr, "%s: %s\n", pfile, err);
202                  exit(1);
203          }
204 +                                        /* compute transformation */
205 +        pixform(theirs2ours, &theirview, &ourview);
206                                          /* allocate scanlines */
207          scanin = (COLR *)malloc(xres*sizeof(COLR));
208          zin = (float *)malloc(xres*sizeof(float));
# Line 216 | Line 230 | char   *pfile, *zfile;
230   }
231  
232  
233 + pixform(xfmat, vw1, vw2)                /* compute view1 to view2 matrix */
234 + register double xfmat[4][4];
235 + register VIEW   *vw1, *vw2;
236 + {
237 +        double  m4t[4][4];
238 +
239 +        setident4(xfmat);
240 +        xfmat[0][0] = vw1->vhinc[0];
241 +        xfmat[0][1] = vw1->vhinc[1];
242 +        xfmat[0][2] = vw1->vhinc[2];
243 +        xfmat[1][0] = vw1->vvinc[0];
244 +        xfmat[1][1] = vw1->vvinc[1];
245 +        xfmat[1][2] = vw1->vvinc[2];
246 +        xfmat[2][0] = vw1->vdir[0];
247 +        xfmat[2][1] = vw1->vdir[1];
248 +        xfmat[2][2] = vw1->vdir[2];
249 +        xfmat[3][0] = vw1->vp[0];
250 +        xfmat[3][1] = vw1->vp[1];
251 +        xfmat[3][2] = vw1->vp[2];
252 +        setident4(m4t);
253 +        m4t[0][0] = vw2->vhinc[0]/vw2->vhn2;
254 +        m4t[1][0] = vw2->vhinc[1]/vw2->vhn2;
255 +        m4t[2][0] = vw2->vhinc[2]/vw2->vhn2;
256 +        m4t[3][0] = -DOT(vw2->vp,vw2->vhinc)/vw2->vhn2;
257 +        m4t[0][1] = vw2->vvinc[0]/vw2->vvn2;
258 +        m4t[1][1] = vw2->vvinc[1]/vw2->vvn2;
259 +        m4t[2][1] = vw2->vvinc[2]/vw2->vvn2;
260 +        m4t[3][1] = -DOT(vw2->vp,vw2->vvinc)/vw2->vvn2;
261 +        m4t[0][2] = vw2->vdir[0];
262 +        m4t[1][2] = vw2->vdir[1];
263 +        m4t[2][2] = vw2->vdir[2];
264 +        m4t[3][2] = -DOT(vw2->vp,vw2->vdir);
265 +        multmat4(xfmat, xfmat, m4t);
266 + }
267 +
268 +
269   addscanline(y, pline, zline)            /* add scanline to output */
270   int     y;
271   COLR    *pline;
272   float   *zline;
273   {
274 <        FVECT   p, dir;
275 <        double  xnew, ynew, znew;
274 >        extern double   sqrt();
275 >        double  pos[3];
276          register int    x;
277          register int    xpos, ypos;
278  
279          for (x = 0; x < theirview.hresolu; x++) {
280 <                rayview(p, dir, &theirview, x+.5, y+.5);
281 <                p[0] += zline[x]*dir[0];
282 <                p[1] += zline[x]*dir[1];
283 <                p[2] += zline[x]*dir[2];
284 <                pixelview(&xnew, &ynew, &znew, &ourview, p);
285 <                if (znew <= 0.0 || xnew < 0 || xnew > ourview.hresolu
286 <                                || ynew < 0 || ynew > ourview.vresolu)
280 >                pos[0] = x - .5*(theirview.hresolu-1);
281 >                pos[1] = y - .5*(theirview.vresolu-1);
282 >                pos[2] = zline[x];
283 >                if (theirview.type == VT_PER) {
284 >                        pos[2] /= sqrt( 1.
285 >                                        + pos[0]*pos[0]*theirview.vhn2
286 >                                        + pos[1]*pos[1]*theirview.vvn2 );
287 >                        pos[0] *= pos[2];
288 >                        pos[1] *= pos[2];
289 >                }
290 >                multp3(pos, pos, theirs2ours);
291 >                if (pos[2] <= 0.0)
292                          continue;
293 <                                        /* check current value at position */
294 <                xpos = xnew;
295 <                ypos = ynew;
293 >                if (ourview.type == VT_PER) {
294 >                        pos[0] /= pos[2];
295 >                        pos[1] /= pos[2];
296 >                }
297 >                pos[0] += .5*ourview.hresolu;
298 >                pos[1] += .5*ourview.vresolu;
299 >                if (pos[0] < 0 || pos[0] > ourview.hresolu
300 >                                || pos[1] < 0 || pos[1] > ourview.vresolu)
301 >                        continue;
302 >                                        /* check current value at pos */
303 >                xpos = pos[0];
304 >                ypos = pos[1];
305                  if (zscan(ypos)[xpos] <= 0.0
306 <                                || zscan(ypos)[xpos] - znew
306 >                                || zscan(ypos)[xpos] - pos[2]
307                                          > zeps*zscan(ypos)[xpos]) {
308 <                        zscan(ypos)[xpos] = znew;
308 >                        zscan(ypos)[xpos] = pos[2];
309                          copycolr(pscan(ypos)[xpos], pline[x]);
310                  }
311          }
# Line 261 | Line 325 | fillpicture()                          /* fill in empty spaces */
325                  return;
326          }
327          for (x = 0; x < ourview.hresolu; x++)
328 <                yback[x] = -1;
328 >                yback[x] = -2;
329                                                          /* fill image */
330 <        for (y = 0; y < ourview.vresolu; y++)
330 >        for (y = 0; y < ourview.vresolu; y++) {
331 >                xback = -2;
332                  for (x = 0; x < ourview.hresolu; x++)
333 <                        if (zscan(y)[x] <= 0.0) {       /* found hole */
334 <                                xback = x-1;
335 <                                do {                    /* find boundary */
336 <                                        if (yback[x] < 0) {
337 <                                                for (i = y+1;
338 <                                                        i < ourview.vresolu;
274 <                                                                i++)
275 <                                                        if (zscan(i)[x] > 0.0)
276 <                                                                break;
277 <                                                if (i < ourview.vresolu
333 >                        if (zscan(y)[x] <= 0.0) {       /* empty pixel */
334 >                                if (yback[x] == -2) {
335 >                                        for (i = y+1; i < ourview.vresolu; i++)
336 >                                                if (zscan(i)[x] > 0.0)
337 >                                                        break;
338 >                                        if (i < ourview.vresolu
339                                  && (y <= 0 || zscan(y-1)[x] < zscan(i)[x]))
340 <                                                        yback[x] = i;
341 <                                                else
342 <                                                        yback[x] = y-1;
282 <                                        }
283 <                                } while (++x < ourview.hresolu
284 <                                                && zscan(y)[x] <= 0.0);
285 <                                i = xback;              /* pick background */
286 <                                if (x < ourview.hresolu
287 <                        && (i < 0 || zscan(y)[i] < zscan(y)[x]))
288 <                                        xback = x;
289 <                                                        /* fill hole */
290 <                                if (xback < 0) {
291 <                                        while (++i < x)
292 <                                                if (yback[i] >= 0)
293 <                                copycolr(pscan(y)[i],pscan(yback[i])[i]);
294 <                                } else {
295 <                                        while (++i < x)
296 <                                                if (yback[i] < 0 ||
297 <                                zscan(yback[i])[i] < zscan(y)[xback])
298 <                                        copycolr(pscan(y)[i],pscan(y)[xback]);
299 <                                                else
300 <                                        copycolr(pscan(y)[i],pscan(yback[i])[i]);
340 >                                                yback[x] = i;
341 >                                        else
342 >                                                yback[x] = y-1;
343                                  }
344 <                } else
345 <                        yback[x] = -1;                  /* clear boundary */
344 >                                if (xback == -2) {
345 >                                        for (i = x+1; x < ourview.hresolu; i++)
346 >                                                if (zscan(y)[i] > 0.0)
347 >                                                        break;
348 >                                        if (i < ourview.hresolu
349 >                                && (x <= 0 || zscan(y)[x-1] < zscan(y)[i]))
350 >                                                xback = i;
351 >                                        else
352 >                                                xback = x-1;
353 >                                }
354 >                                if (xback < 0 && yback[x] < 0)
355 >                                        continue;
356 >                                if (yback[x] < 0 || ABS(x-xback) <= 1
357 >                                        || ( ABS(y-yback[x]) > 1
358 >                                && zscan(yback[x])[x] < zscan(y)[xback] ))
359 >                                        copycolr(pscan(y)[x],pscan(y)[xback]);
360 >                                else
361 >                                        copycolr(pscan(y)[x],pscan(yback[x])[x]);
362 >                        } else {                                /* full pixel */
363 >                                yback[x] = -2;
364 >                                xback = -2;
365 >                        }
366 >        }
367          free((char *)yback);
368   }
369  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines