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.14 by greg, Thu Jan 4 17:47:37 1990 UTC vs.
Revision 1.15 by greg, Fri Jan 5 11:34:27 1990 UTC

# Line 26 | Line 26 | static char SCCSid[] = "$SunId$ LBL";
26  
27   #define ABS(x)          ((x)>0?(x):-(x))
28  
29 + struct position {int x,y; float z;};
30 +
31   VIEW    ourview = STDVIEW(512);         /* desired view */
32  
33   double  zeps = .02;                     /* allowed z epsilon */
# Line 192 | Line 194 | char   *argv[];
194                                                  /* allocate frame */
195          ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR));
196          ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float));
197 <        if (ourpict == NULL || ourzbuf == NULL) {
198 <                perror(progname);
197 <                exit(1);
198 <        }
197 >        if (ourpict == NULL || ourzbuf == NULL)
198 >                syserror();
199                                                          /* get input */
200          for ( ; i < argc; i += 2)
201                  addpicture(argv[i], argv[i+1]);
# Line 254 | Line 254 | char   *pfile, *zspec;
254          FILE    *pfp, *zfp;
255          char    *err;
256          COLR    *scanin;
257 <        float   *zin, *zlast;
258 <        int     *plast;
257 >        float   *zin;
258 >        struct position *plast;
259          int     y;
260                                          /* open picture file */
261          if ((pfp = fopen(pfile, "r")) == NULL) {
# Line 280 | Line 280 | char   *pfile, *zspec;
280                                          /* allocate scanlines */
281          scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR));
282          zin = (float *)malloc(theirview.hresolu*sizeof(float));
283 <        plast = (int *)calloc(theirview.hresolu, sizeof(int));
284 <        zlast = (float *)calloc(theirview.hresolu, sizeof(float));
285 <        if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) {
286 <                perror(progname);
287 <                exit(1);
288 <        }
283 >        plast = (struct position *)calloc(theirview.hresolu,
284 >                                                sizeof(struct position));
285 >        if (scanin == NULL || zin == NULL || plast == NULL)
286 >                syserror();
287                                          /* get z specification or file */
288          if ((zfp = fopen(zspec, "r")) == NULL) {
289                  double  zvalue;
# Line 309 | Line 307 | char   *pfile, *zspec;
307                          fprintf(stderr, "%s: read error\n", zspec);
308                          exit(1);
309                  }
310 <                addscanline(y, scanin, zin, plast, zlast);
310 >                addscanline(y, scanin, zin, plast);
311          }
312                                          /* clean up */
313          free((char *)scanin);
314          free((char *)zin);
315          free((char *)plast);
318        free((char *)zlast);
316          fclose(pfp);
317          if (zfp != NULL)
318                  fclose(zfp);
# Line 358 | Line 355 | register VIEW  *vw1, *vw2;
355   }
356  
357  
358 < addscanline(y, pline, zline, lasty, lastyz)     /* add scanline to output */
358 > addscanline(y, pline, zline, lasty)     /* add scanline to output */
359   int     y;
360   COLR    *pline;
361   float   *zline;
362 < int     *lasty;                 /* input/output */
366 < float   *lastyz;                /* input/output */
362 > struct position *lasty;         /* input/output */
363   {
364          extern double   sqrt();
365          double  pos[3];
366 <        int     lastx = 0;
371 <        double  lastxz = 0;
372 <        double  zt;
373 <        int     xpos, ypos;
366 >        struct position lastx, newpos;
367          register int    x;
368  
369          for (x = theirview.hresolu-1; x >= 0; x--) {
# Line 386 | Line 379 | float  *lastyz;                /* input/output */
379                          pos[1] *= pos[2];
380                  }
381                  multp3(pos, pos, theirs2ours);
382 <                if (pos[2] <= 0)
382 >                if (pos[2] <= 0) {
383 >                        lasty[x].z = lastx.z = 0;       /* mark invalid */
384                          continue;
385 +                }
386                  if (ourview.type == VT_PER) {
387                          pos[0] /= pos[2];
388                          pos[1] /= pos[2];
389                  }
390                  pos[0] += .5*ourview.hresolu;
391                  pos[1] += .5*ourview.vresolu;
392 <                if (pos[0] < 0 || (xpos = pos[0]) >= ourview.hresolu
393 <                        || pos[1] < 0 || (ypos = pos[1]) >= ourview.vresolu)
394 <                        continue;
392 >                newpos.x = pos[0];
393 >                newpos.y = pos[1];
394 >                newpos.z = zline[x];
395                                          /* add pixel to our image */
396 <                zt = 2.*zeps*zline[x];
397 <                addpixel(xpos, ypos,
398 <                        (fill&F_FORE && ABS(zline[x]-lastxz) <= zt)
399 <                                ? lastx - xpos : 1,
400 <                        (fill&F_FORE && ABS(zline[x]-lastyz[x]) <= zt)
401 <                                ? lasty[x] - ypos : 1,
402 <                        pline[x], pos[2]);
403 <                lastx = xpos;
409 <                lasty[x] = ypos;
410 <                lastxz = lastyz[x] = zline[x];
396 >                if (pos[0] >= 0 && newpos.x < ourview.hresolu
397 >                                && pos[1] >= 0 && newpos.y < ourview.vresolu) {
398 >                        addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]);
399 >                        lasty[x].x = lastx.x = newpos.x;
400 >                        lasty[x].y = lastx.y = newpos.y;
401 >                        lasty[x].z = lastx.z = newpos.z;
402 >                } else
403 >                        lasty[x].z = lastx.z = 0;       /* mark invalid */
404          }
405   }
406  
407  
408 < addpixel(xstart, ystart, width, height, pix, z) /* fill in area for pixel */
409 < int     xstart, ystart;
417 < int     width, height;
408 > addpixel(p0, p1, p2, pix, z)            /* fill in pixel parallelogram */
409 > struct position *p0, *p1, *p2;
410   COLR    pix;
411   double  z;
412   {
413 <        register int    x, y;
414 <                                        /* make width and height positive */
415 <        if (width < 0) {
416 <                width = -width;
417 <                xstart = xstart-width+1;
418 <        } else if (width == 0)
419 <                width = 1;
420 <        if (height < 0) {
421 <                height = -height;
422 <                ystart = ystart-height+1;
423 <        } else if (height == 0)
424 <                height = 1;
425 <                                        /* fill pixel(s) within rectangle */
426 <        for (y = ystart; y < ystart+height; y++)
427 <                for (x = xstart; x < xstart+width; x++)
428 <                        if (zscan(y)[x] <= 0
429 <                                        || zscan(y)[x]-z > zeps*zscan(y)[x]) {
413 >        double  zt = 2.*zeps*p0->z;             /* threshold */
414 >        int     s1x, s1y, s2x, s2y;             /* step sizes */
415 >        int     l1, l2, c1, c2;                 /* side lengths and counters */
416 >        int     p1isy;                          /* p0p1 along y? */
417 >        int     x1, y1;                         /* p1 position */
418 >        register int    x, y;                   /* final position */
419 >
420 >                                        /* compute vector p0p1 */
421 >        if (fill&F_FORE && ABS(p1->z-p0->z) <= zt) {
422 >                s1x = p1->x - p0->x;
423 >                s1y = p1->y - p0->y;
424 >                l1 = ABS(s1x);
425 >                if (p1isy = (ABS(s1y) > l1))
426 >                        l1 = ABS(s1y);
427 >        } else {
428 >                l1 = s1x = s1y = 1;
429 >                p1isy = -1;
430 >        }
431 >                                        /* compute vector p0p2 */
432 >        if (fill&F_FORE && ABS(p2->z-p0->z) <= zt) {
433 >                s2x = p2->x - p0->x;
434 >                s2y = p2->y - p0->y;
435 >                if (p1isy == 1)
436 >                        l2 = ABS(s2x);
437 >                else {
438 >                        l2 = ABS(s2y);
439 >                        if (p1isy != 0 && ABS(s2x) > l2)
440 >                                l2 = ABS(s2x);
441 >                }
442 >        } else
443 >                l2 = s2x = s2y = 1;
444 >                                        /* fill the parallelogram */
445 >        for (c1 = l1; c1-- > 0; ) {
446 >                x1 = p0->x + c1*s1x/l1;
447 >                y1 = p0->y + c1*s1y/l1;
448 >                for (c2 = l2; c2-- > 0; ) {
449 >                        x = x1 + c2*s2x/l2;
450 >                        y = y1 + c2*s2y/l2;
451 >                        if (zscan(y)[x] <= 0 || zscan(y)[x]-z
452 >                                                > zeps*zscan(y)[x]) {
453                                  zscan(y)[x] = z;
454                                  copycolr(pscan(y)[x], pix);
455                          }
456 +                }
457 +        }
458   }
459  
460  
# Line 449 | Line 466 | backpicture()                          /* background fill algorithm */
466          register int    x, i;
467                                                          /* get back buffer */
468          yback = (int *)malloc(ourview.hresolu*sizeof(int));
469 <        if (yback == NULL) {
470 <                perror(progname);
454 <                return;
455 <        }
469 >        if (yback == NULL)
470 >                syserror();
471          for (x = 0; x < ourview.hresolu; x++)
472                  yback[x] = -2;
473          /*
# Line 542 | Line 557 | writepicture()                         /* write out picture */
557  
558          fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout);
559          for (y = ourview.vresolu-1; y >= 0; y--)
560 <                if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0) {
561 <                        perror(progname);
547 <                        exit(1);
548 <                }
560 >                if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0)
561 >                        syserror();
562   }
563  
564  
# Line 563 | Line 576 | char   *fname;
576                  exit(1);
577          }
578          if (donorm
579 <        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL) {
580 <                perror(progname);
568 <                exit(1);
569 <        }
579 >        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL)
580 >                syserror();
581          for (y = ourview.vresolu-1; y >= 0; y--) {
582                  if (donorm) {
583                          double  vx, yzn2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines