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.25 by greg, Tue Mar 6 11:14:36 1990 UTC vs.
Revision 1.32 by greg, Mon Feb 11 18:10:56 1991 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include "color.h"
18  
19 #include "random.h"
20
19   #ifndef BSD
20   #define vfork           fork
21   #endif
# Line 25 | Line 23 | static char SCCSid[] = "$SunId$ LBL";
23   #define pscan(y)        (ourpict+(y)*hresolu)
24   #define zscan(y)        (ourzbuf+(y)*hresolu)
25  
28 #define PMASK           0xfffffff       /* probability mask */
29 #define sampval(x)      (long)((x)*(PMASK+1)+.5)
30 #define samp(p)         ((p) > (random()&PMASK))
31
26   #define F_FORE          1               /* fill foreground */
27   #define F_BACK          2               /* fill background */
28  
# Line 53 | Line 47 | float  *ourzbuf;                       /* corresponding z-buffer */
47   char    *progname;
48  
49   int     fillo = F_FORE|F_BACK;          /* selected fill options */
50 < long    sampprob = 0;                   /* sample probability */
50 > int     fillsamp = 0;                   /* sample separation (0 == inf) */
51   extern int      backfill(), rcalfill(); /* fill functions */
52   int     (*fillfunc)() = backfill;       /* selected fill function */
53   COLR    backcolr = BLKCOLR;             /* background color */
# Line 66 | Line 60 | int    gotview;                        /* got input view? */
60   int     thresolu, tvresolu;             /* input resolution */
61   double  theirexp;                       /* input picture exposure */
62   double  theirs2ours[4][4];              /* transformation matrix */
63 + int     hasmatrix = 0;                  /* has transformation matrix */
64  
65   int     childpid = -1;                  /* id of fill process */
66   FILE    *psend, *precv;                 /* pipes to/from fill calculation */
# Line 121 | Line 116 | char   *argv[];
116                                  break;
117                          case 's':                               /* sample */
118                                  check(3,1);
119 <                                sampprob = sampval(atof(argv[++i]));
119 >                                fillsamp = atoi(argv[++i]);
120                                  break;
121                          case 'c':                               /* color */
122                                  check(3,3);
# Line 200 | Line 195 | char   *argv[];
195                  addpicture(argv[i], argv[i+1]);
196                                                          /* fill in spaces */
197          if (fillo&F_BACK)
198 <                backpicture(fillfunc, sampprob);
198 >                backpicture(fillfunc, fillsamp);
199          else
200                  fillpicture(fillfunc);
201                                                          /* close calculation */
# Line 290 | Line 285 | char   *pfile, *zspec;
285                  exit(1);
286          }
287                                          /* compute transformation */
288 <        pixform(theirs2ours, &theirview, &ourview);
288 >        hasmatrix = pixform(theirs2ours, &theirview, &ourview);
289                                          /* allocate scanlines */
290          scanin = (COLR *)malloc(thresolu*sizeof(COLR));
291          zin = (float *)malloc(thresolu*sizeof(float));
# Line 337 | Line 332 | register VIEW  *vw1, *vw2;
332   {
333          double  m4t[4][4];
334  
335 +        if (vw1->type != VT_PER && vw1->type != VT_PAR)
336 +                return(0);
337 +        if (vw2->type != VT_PER && vw2->type != VT_PAR)
338 +                return(0);
339          setident4(xfmat);
340          xfmat[0][0] = vw1->hvec[0];
341          xfmat[0][1] = vw1->hvec[1];
# Line 364 | Line 363 | register VIEW  *vw1, *vw2;
363          m4t[2][2] = vw2->vdir[2];
364          m4t[3][2] = -DOT(vw2->vp,vw2->vdir);
365          multmat4(xfmat, xfmat, m4t);
366 +        return(1);
367   }
368  
369  
# Line 374 | Line 374 | float  *zline;
374   struct position *lasty;         /* input/output */
375   {
376          extern double   sqrt();
377 <        double  pos[3];
377 >        FVECT   pos;
378          struct position lastx, newpos;
379          register int    x;
380  
381          lastx.z = 0;
382          for (x = thresolu-1; x >= 0; x--) {
383 <                pos[0] = (x+.5)/thresolu + theirview.hoff - .5;
384 <                pos[1] = (y+.5)/tvresolu + theirview.voff - .5;
383 >                pos[0] = (x+.5)/thresolu;
384 >                pos[1] = (y+.5)/tvresolu;
385                  pos[2] = zline[x];
386 <                if (theirview.type == VT_PER) {
387 <                        if (normdist)   /* adjust for eye-ray distance */
388 <                                pos[2] /= sqrt( 1.
389 <                                        + pos[0]*pos[0]*theirview.hn2
390 <                                        + pos[1]*pos[1]*theirview.vn2 );
391 <                        pos[0] *= pos[2];
392 <                        pos[1] *= pos[2];
393 <                }
394 <                multp3(pos, pos, theirs2ours);
395 <                if (pos[2] <= 0) {
386 >                if (movepixel(pos) < 0) {
387                          lasty[x].z = lastx.z = 0;       /* mark invalid */
388                          continue;
389                  }
399                if (ourview.type == VT_PER) {
400                        pos[0] /= pos[2];
401                        pos[1] /= pos[2];
402                }
403                pos[0] += .5 - ourview.hoff;
404                pos[1] += .5 - ourview.voff;
390                  newpos.x = pos[0] * hresolu;
391                  newpos.y = pos[1] * vresolu;
392                  newpos.z = zline[x];
# Line 460 | Line 445 | double z;
445                  y1 = p0->y + c1*s1y/l1;
446                  for (c2 = l2; c2-- > 0; ) {
447                          x = x1 + c2*s2x/l2;
448 +                        if (x < 0 || x >= hresolu)
449 +                                continue;
450                          y = y1 + c2*s2y/l2;
451 +                        if (y < 0 || y >= vresolu)
452 +                                continue;
453                          if (zscan(y)[x] <= 0 || zscan(y)[x]-z
454                                                  > zeps*zscan(y)[x]) {
455                                  zscan(y)[x] = z;
# Line 471 | Line 460 | double z;
460   }
461  
462  
463 < backpicture(fill, prob)                 /* background fill algorithm */
463 > movepixel(pos)                          /* reposition image point */
464 > FVECT   pos;
465 > {
466 >        FVECT   pt, direc;
467 >        
468 >        if (pos[2] <= 0)                /* empty pixel */
469 >                return(-1);
470 >        if (hasmatrix) {
471 >                pos[0] += theirview.hoff - .5;
472 >                pos[1] += theirview.voff - .5;
473 >                if (theirview.type == VT_PER) {
474 >                        if (normdist)   /* adjust for eye-ray distance */
475 >                                pos[2] /= sqrt( 1.
476 >                                        + pos[0]*pos[0]*theirview.hn2
477 >                                        + pos[1]*pos[1]*theirview.vn2 );
478 >                        pos[0] *= pos[2];
479 >                        pos[1] *= pos[2];
480 >                }
481 >                multp3(pos, pos, theirs2ours);
482 >                if (pos[2] <= 0)
483 >                        return(-1);
484 >                if (ourview.type == VT_PER) {
485 >                        pos[0] /= pos[2];
486 >                        pos[1] /= pos[2];
487 >                }
488 >                pos[0] += .5 - ourview.hoff;
489 >                pos[1] += .5 - ourview.voff;
490 >                return(0);
491 >        }
492 >        if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0)
493 >                return(-1);
494 >        pt[0] += direc[0]*pos[2];
495 >        pt[1] += direc[1]*pos[2];
496 >        pt[2] += direc[2]*pos[2];
497 >        viewpixel(&pos[0], &pos[1], &pos[2], &ourview, pt);
498 >        if (pos[2] <= 0)
499 >                return(-1);
500 >        return(0);
501 > }
502 >
503 >
504 > backpicture(fill, samp)                 /* background fill algorithm */
505   int     (*fill)();
506 < long    prob;
506 > int     samp;
507   {
508          int     *yback, xback;
509          int     y;
480        COLR    pfill;
510          register int    x, i;
511                                                          /* get back buffer */
512          yback = (int *)malloc(hresolu*sizeof(int));
# Line 524 | Line 553 | long   prob;
553                                                  xback = x-1;
554                                  }
555                                  /*
556 <                                 * Check to see if we have no background for
557 <                                 * this pixel.  If not, or sampling was
529 <                                 * requested, use the given fill function.
556 >                                 * If we have no background for this pixel,
557 >                                 * use the given fill function.
558                                   */
559 <                                if ((xback < 0 && yback[x] < 0) || samp(prob)) {
560 <                                        (*fill)(x,y);
533 <                                        continue;
534 <                                }
559 >                                if (xback < 0 && yback[x] < 0)
560 >                                        goto fillit;
561                                  /*
562                                   * Compare, and use the background that is
563                                   * farther, unless one of them is next to us.
564 +                                 * If the background is too distant, call
565 +                                 * the fill function.
566                                   */
567                                  if ( yback[x] < 0
568                                          || (xback >= 0 && ABS(x-xback) <= 1)
569                                          || ( ABS(y-yback[x]) > 1
570                                                  && zscan(yback[x])[x]
571                                                  < zscan(y)[xback] ) ) {
572 +                                        if (samp > 0 && ABS(x-xback) >= samp)
573 +                                                goto fillit;
574                                          copycolr(pscan(y)[x],pscan(y)[xback]);
575                                          zscan(y)[x] = zscan(y)[xback];
576                                  } else {
577 +                                        if (samp > 0 && ABS(y-yback[x]) > samp)
578 +                                                goto fillit;
579                                          copycolr(pscan(y)[x],pscan(yback[x])[x]);
580                                          zscan(y)[x] = zscan(yback[x])[x];
581                                  }
582 +                                continue;
583 +                        fillit:
584 +                                (*fill)(x,y);
585 +                                if (fill == rcalfill) {         /* use it */
586 +                                        clearqueue();
587 +                                        xback = x;
588 +                                        yback[x] = y;
589 +                                }
590                          } else {                                /* full pixel */
591                                  yback[x] = -2;
592                                  xback = -2;
# Line 599 | Line 639 | char   *fname;
639                  if (donorm) {
640                          double  vx, yzn2;
641                          register int    x;
642 <                        yzn2 = y - .5*(vresolu-1);
642 >                        yzn2 = (y+.5)/vresolu + ourview.voff - .5;
643                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
644                          for (x = 0; x < hresolu; x++) {
645 <                                vx = x - .5*(hresolu-1);
645 >                                vx = (x+.5)/hresolu + ourview.hoff - .5;
646                                  zout[x] = zscan(y)[x]
647                                          * sqrt(vx*vx*ourview.hn2 + yzn2);
648                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines