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.10 by greg, Wed Jan 3 15:33:44 1990 UTC vs.
Revision 1.11 by greg, Thu Jan 4 10:12:49 1990 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 F_FORE  1                       /* fill foreground */
21 + #define F_BACK  2                       /* fill background */
22 +
23   #define ABS(x)          ((x)>0?(x):-(x))
24  
25   VIEW    ourview = STDVIEW(512);         /* desired view */
# Line 31 | Line 34 | char   *progname;
34   VIEW    theirview = STDVIEW(512);       /* input view */
35   int     gotview;                        /* got input view? */
36  
37 + int     fill = F_FORE|F_BACK;           /* fill level */
38 + COLR    backcolr = BLKCOLR;             /* background color */
39 +
40   double  theirs2ours[4][4];              /* transformation matrix */
41 < int     regdist = 0;                    /* regular distance? */
41 > int     normdist = 1;                   /* normalized distance? */
42  
43  
44   main(argc, argv)                        /* interpolate pictures */
# Line 40 | Line 46 | int    argc;
46   char    *argv[];
47   {
48   #define check(olen,narg)        if (argv[i][olen] || narg >= argc-i) goto badopt
49 +        extern double   atof();
50          int     gotvfile = 0;
51 +        char    *zfile = NULL;
52          char    *err;
53          int     i;
54  
# Line 52 | Line 60 | char   *argv[];
60                          check(2,1);
61                          zeps = atof(argv[++i]);
62                          break;
63 <                case 'r':                               /* regular distance */
63 >                case 'n':                               /* dist. normalized? */
64                          check(2,0);
65 <                        regdist = !regdist;
65 >                        normdist = !normdist;
66                          break;
67 +                case 'f':                               /* fill type */
68 +                        switch (argv[i][2]) {
69 +                        case '0':                               /* none */
70 +                                check(3,0);
71 +                                fill = 0;
72 +                                break;
73 +                        case 'f':                               /* foreground */
74 +                                check(3,0);
75 +                                fill = F_FORE;
76 +                                break;
77 +                        case 'b':                               /* background */
78 +                                check(3,0);
79 +                                fill = F_BACK;
80 +                                break;
81 +                        case 'a':                               /* all */
82 +                                check(3,0);
83 +                                fill = F_FORE|F_BACK;
84 +                                break;
85 +                        case 'c':                               /* color */
86 +                                check(3,3);
87 +                                setcolr(backcolr, atof(argv[i+1]),
88 +                                        atof(argv[i+2]), atof(argv[i+3]));
89 +                                i += 3;
90 +                                break;
91 +                        default:
92 +                                goto badopt;
93 +                        }
94 +                        break;
95 +                case 'z':                               /* z file */
96 +                        check(2,1);
97 +                        zfile = argv[++i];
98 +                        break;
99                  case 'x':                               /* x resolution */
100                          check(2,1);
101                          ourview.hresolu = atoi(argv[++i]);
# Line 137 | Line 177 | char   *argv[];
177          for ( ; i < argc; i += 2)
178                  addpicture(argv[i], argv[i+1]);
179                                                          /* fill in spaces */
180 <        fillpicture();
180 >        if (fill&F_BACK)
181 >                fillpicture();
182 >        else
183 >                backpicture();
184                                                          /* add to header */
185          printargs(argc, argv, stdout);
186          if (gotvfile) {
# Line 146 | Line 189 | char   *argv[];
189                  printf("\n");
190          }
191          printf("\n");
192 <                                                        /* write output */
192 >                                                        /* write picture */
193          writepicture();
194 +                                                        /* write z file */
195 +        if (zfile != NULL)
196 +                writedistance(zfile);
197  
198          exit(0);
199   userr:
200          fprintf(stderr,
201 <        "Usage: %s [view opts][-t zthresh][-r] pfile zspec ..\n",
201 >        "Usage: %s [view opts][-t zthresh][-z zout][-fT][-n] pfile zspec ..\n",
202                          progname);
203          exit(1);
204   #undef check
# Line 294 | Line 340 | float  *zline;
340   int     *lasty;                 /* input/output */
341   float   *lastyz;                /* input/output */
342   {
343 <        extern double   sqrt(), fabs();
343 >        extern double   sqrt();
344          double  pos[3];
345          int     lastx = 0;
346          double  lastxz = 0;
# Line 307 | Line 353 | float  *lastyz;                /* input/output */
353                  pos[1] = y - .5*(theirview.vresolu-1);
354                  pos[2] = zline[x];
355                  if (theirview.type == VT_PER) {
356 <                        if (!regdist)   /* adjust for eye-ray distance */
356 >                        if (normdist)   /* adjust for eye-ray distance */
357                                  pos[2] /= sqrt( 1.
358                                          + pos[0]*pos[0]*theirview.vhn2
359                                          + pos[1]*pos[1]*theirview.vvn2 );
# Line 329 | Line 375 | float  *lastyz;                /* input/output */
375                                          /* add pixel to our image */
376                  zt = 2.*zeps*zline[x];
377                  addpixel(xpos, ypos,
378 <                        (fabs(zline[x]-lastxz) <= zt) ? lastx - xpos : 1,
379 <                        (fabs(zline[x]-lastyz[x]) <= zt) ? lasty[x] - ypos : 1,
378 >                        (fill&F_FORE && ABS(zline[x]-lastxz) <= zt)
379 >                                ? lastx - xpos : 1,
380 >                        (fill&F_FORE && ABS(zline[x]-lastyz[x]) <= zt)
381 >                                ? lasty[x] - ypos : 1,
382                          pline[x], pos[2]);
383                  lastx = xpos;
384                  lasty[x] = ypos;
# Line 411 | Line 459 | fillpicture()                          /* fill in empty spaces */
459                                   * Next, find background from left or right.
460                                   */
461                                  if (xback == -2) {
462 <                                        for (i = x+1; x < ourview.hresolu; i++)
462 >                                        for (i = x+1; i < ourview.hresolu; i++)
463                                                  if (zscan(y)[i] > 0)
464                                                          break;
465                                          if (i < ourview.hresolu
# Line 420 | Line 468 | fillpicture()                          /* fill in empty spaces */
468                                          else
469                                                  xback = x-1;
470                                  }
423                                if (xback < 0 && yback[x] < 0)
424                                        continue;       /* no background */
471                                  /*
472 +                                 * Check to see if we have no background for
473 +                                 * this pixel.  If not, use background color.
474 +                                 */
475 +                                if (xback < 0 && yback[x] < 0) {
476 +                                        copycolr(pscan(y)[x], backcolr);
477 +                                        continue;
478 +                                }
479 +                                /*
480                                   * Compare, and use the background that is
481                                   * farther, unless one of them is next to us.
482                                   */
483 <                                if (yback[x] < 0 || ABS(x-xback) <= 1
483 >                                if ( yback[x] < 0
484 >                                        || (xback >= 0 && ABS(x-xback) <= 1)
485                                          || ( ABS(y-yback[x]) > 1
486 <                                && zscan(yback[x])[x] < zscan(y)[xback] ))
486 >                                                && zscan(yback[x])[x]
487 >                                                < zscan(y)[xback] ) )
488                                          copycolr(pscan(y)[x],pscan(y)[xback]);
489                                  else
490                                          copycolr(pscan(y)[x],pscan(yback[x])[x]);
# Line 441 | Line 497 | fillpicture()                          /* fill in empty spaces */
497   }
498  
499  
500 + backpicture()                           /* paint in empty pixels */
501 + {
502 +        register int    x, y;
503 +
504 +        for (y = 0; y < ourview.vresolu; y++)
505 +                for (x = 0; x < ourview.hresolu; x++)
506 +                        if (zscan(y)[x] <= 0)
507 +                                copycolr(pscan(y)[x], backcolr);
508 + }
509 +
510 +
511   writepicture()                          /* write out picture */
512   {
513          int     y;
# Line 451 | Line 518 | writepicture()                         /* write out picture */
518                          perror(progname);
519                          exit(1);
520                  }
521 + }
522 +
523 +
524 + writedistance(fname)                    /* write out z file */
525 + char    *fname;
526 + {
527 +        extern double   sqrt();
528 +        int     donorm = normdist && ourview.type == VT_PER;
529 +        FILE    *fp;
530 +        int     y;
531 +        float   *zout;
532 +
533 +        if ((fp = fopen(fname, "w")) == NULL) {
534 +                perror(fname);
535 +                exit(1);
536 +        }
537 +        if (donorm
538 +        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL) {
539 +                perror(progname);
540 +                exit(1);
541 +        }
542 +        for (y = ourview.vresolu-1; y >= 0; y--) {
543 +                if (donorm) {
544 +                        double  vx, yzn2;
545 +                        register int    x;
546 +                        yzn2 = y - .5*(ourview.vresolu-1);
547 +                        yzn2 = 1. + yzn2*yzn2*ourview.vvn2;
548 +                        for (x = 0; x < ourview.hresolu; x++) {
549 +                                vx = x - .5*(ourview.hresolu-1);
550 +                                zout[x] = zscan(y)[x]
551 +                                        * sqrt(vx*vx*ourview.vhn2 + yzn2);
552 +                        }
553 +                } else
554 +                        zout = zscan(y);
555 +                if (fwrite(zout, sizeof(float), ourview.hresolu, fp)
556 +                                < ourview.hresolu) {
557 +                        perror(fname);
558 +                        exit(1);
559 +                }
560 +        }
561 +        if (donorm)
562 +                free((char *)zout);
563 +        fclose(fp);
564   }
565  
566  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines