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.21 by greg, Wed Jan 17 15:12:37 1990 UTC vs.
Revision 1.27 by greg, Tue Mar 6 15:45:31 1990 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "standard.h"
12  
13 < #include <sys/fcntl.h>
13 > #include <fcntl.h>
14  
15   #include "view.h"
16  
# Line 28 | Line 28 | static char SCCSid[] = "$SunId$ LBL";
28  
29   #define PACKSIZ         42              /* calculation packet size */
30  
31 < #define RTCOM           "rtrace -h -ovl -fff -x %d %s"
31 > #define RTCOM           "rtrace -h -ovl -fff %s"
32  
33   #define ABS(x)          ((x)>0?(x):-(x))
34  
# Line 46 | Line 46 | float  *ourzbuf;                       /* corresponding z-buffer */
46  
47   char    *progname;
48  
49 < int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
49 > int     fillo = F_FORE|F_BACK;          /* selected fill options */
50 > int     fillsamp = 0;                   /* sample separation (0 == inf) */
51   extern int      backfill(), rcalfill(); /* fill functions */
52 < int     (*deffill)() = backfill;        /* selected fill function */
52 > int     (*fillfunc)() = backfill;       /* selected fill function */
53   COLR    backcolr = BLKCOLR;             /* background color */
54   double  backz = 0.0;                    /* background z value */
55   int     normdist = 1;                   /* normalized distance? */
# Line 98 | Line 99 | char   *argv[];
99                          switch (argv[i][2]) {
100                          case '0':                               /* none */
101                                  check(3,0);
102 <                                fill = 0;
102 >                                fillo = 0;
103                                  break;
104                          case 'f':                               /* foreground */
105                                  check(3,0);
106 <                                fill = F_FORE;
106 >                                fillo = F_FORE;
107                                  break;
108                          case 'b':                               /* background */
109                                  check(3,0);
110 <                                fill = F_BACK;
110 >                                fillo = F_BACK;
111                                  break;
112                          case 'a':                               /* all */
113                                  check(3,0);
114 <                                fill = F_FORE|F_BACK;
114 >                                fillo = F_FORE|F_BACK;
115                                  break;
116 +                        case 's':                               /* sample */
117 +                                check(3,1);
118 +                                fillsamp = atoi(argv[++i]);
119 +                                break;
120                          case 'c':                               /* color */
121                                  check(3,3);
122 <                                deffill = backfill;
122 >                                fillfunc = backfill;
123                                  setcolr(backcolr, atof(argv[i+1]),
124                                          atof(argv[i+2]), atof(argv[i+3]));
125                                  i += 3;
126                                  break;
127                          case 'z':                               /* z value */
128                                  check(3,1);
129 <                                deffill = backfill;
129 >                                fillfunc = backfill;
130                                  backz = atof(argv[++i]);
131                                  break;
132                          case 'r':                               /* rtrace */
133                                  check(3,1);
134 <                                deffill = rcalfill;
134 >                                fillfunc = rcalfill;
135                                  calstart(RTCOM, argv[++i]);
136                                  break;
137                          default:
# Line 188 | Line 193 | char   *argv[];
193          for ( ; i < argc; i += 2)
194                  addpicture(argv[i], argv[i+1]);
195                                                          /* fill in spaces */
196 <        if (fill&F_BACK)
197 <                backpicture();
196 >        if (fillo&F_BACK)
197 >                backpicture(fillfunc, fillsamp);
198          else
199 <                fillpicture();
199 >                fillpicture(fillfunc);
200                                                          /* close calculation */
201          caldone();
202                                                          /* add to header */
203          printargs(argc, argv, stdout);
204          if (gotvfile) {
205 <                printf(VIEWSTR);
205 >                fputs(VIEWSTR, stdout);
206                  fprintview(&ourview, stdout);
207 <                printf("\n");
207 >                putc('\n', stdout);
208          }
209          if (pixaspect < .99 || pixaspect > 1.01)
210                  fputaspect(pixaspect, stdout);
211          if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
212                  fputexpos(ourexp, stdout);
213 <        printf("\n");
213 >        putc('\n', stdout);
214                                                          /* write picture */
215          writepicture();
216                                                          /* write z file */
# Line 225 | Line 230 | userr:
230   headline(s)                             /* process header string */
231   char    *s;
232   {
233 <        static char     *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL};
233 >        static char     *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL};
234          register char   **an;
235  
236 <        printf("\t%s", s);
236 >        putc('\t', stdout);
237 >        fputs(s, stdout);
238  
239          if (isexpos(s)) {
240                  theirexp *= exposval(s);
# Line 302 | Line 308 | char   *pfile, *zspec;
308                          fprintf(stderr, "%s: read error\n", pfile);
309                          exit(1);
310                  }
311 <                if (zfd != -1 && read(zfd,zin,thresolu*sizeof(float))
311 >                if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float))
312                                  < thresolu*sizeof(float)) {
313                          fprintf(stderr, "%s: read error\n", zspec);
314                          exit(1);
# Line 419 | Line 425 | double z;
425          register int    x, y;                   /* final position */
426  
427                                          /* compute vector p0p1 */
428 <        if (fill&F_FORE && ABS(p1->z-p0->z) <= zt) {
428 >        if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) {
429                  s1x = p1->x - p0->x;
430                  s1y = p1->y - p0->y;
431                  l1 = ABS(s1x);
# Line 430 | Line 436 | double z;
436                  p1isy = -1;
437          }
438                                          /* compute vector p0p2 */
439 <        if (fill&F_FORE && ABS(p2->z-p0->z) <= zt) {
439 >        if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) {
440                  s2x = p2->x - p0->x;
441                  s2y = p2->y - p0->y;
442                  if (p1isy == 1)
# Line 459 | Line 465 | double z;
465   }
466  
467  
468 < backpicture()                           /* background fill algorithm */
468 > backpicture(fill, samp)                 /* background fill algorithm */
469 > int     (*fill)();
470 > int     samp;
471   {
472          int     *yback, xback;
473          int     y;
# Line 510 | Line 518 | backpicture()                          /* background fill algorithm */
518                                                  xback = x-1;
519                                  }
520                                  /*
521 <                                 * Check to see if we have no background for
522 <                                 * this pixel.  If not, use background color.
521 >                                 * If we have no background for this pixel,
522 >                                 * use the given fill function.
523                                   */
524 <                                if (xback < 0 && yback[x] < 0) {
525 <                                        (*deffill)(x,y);
518 <                                        continue;
519 <                                }
524 >                                if (xback < 0 && yback[x] < 0)
525 >                                        goto fillit;
526                                  /*
527                                   * Compare, and use the background that is
528                                   * farther, unless one of them is next to us.
529 +                                 * If the background is too distant, call
530 +                                 * the fill function.
531                                   */
532                                  if ( yback[x] < 0
533                                          || (xback >= 0 && ABS(x-xback) <= 1)
534                                          || ( ABS(y-yback[x]) > 1
535                                                  && zscan(yback[x])[x]
536                                                  < zscan(y)[xback] ) ) {
537 +                                        if (samp > 0 && ABS(x-xback) >= samp)
538 +                                                goto fillit;
539                                          copycolr(pscan(y)[x],pscan(y)[xback]);
540                                          zscan(y)[x] = zscan(y)[xback];
541                                  } else {
542 +                                        if (samp > 0 && ABS(y-yback[x]) > samp)
543 +                                                goto fillit;
544                                          copycolr(pscan(y)[x],pscan(yback[x])[x]);
545                                          zscan(y)[x] = zscan(yback[x])[x];
546                                  }
547 +                                continue;
548 +                        fillit:
549 +                                (*fill)(x,y);
550 +                                if (fill == rcalfill) {         /* use it */
551 +                                        clearqueue();
552 +                                        xback = x;
553 +                                        yback[x] = y;
554 +                                }
555                          } else {                                /* full pixel */
556                                  yback[x] = -2;
557                                  xback = -2;
# Line 541 | Line 561 | backpicture()                          /* background fill algorithm */
561   }
562  
563  
564 < fillpicture()                           /* paint in empty pixels with default */
564 > fillpicture(fill)               /* paint in empty pixels using fill */
565 > int     (*fill)();
566   {
567          register int    x, y;
568  
569          for (y = 0; y < vresolu; y++)
570                  for (x = 0; x < hresolu; x++)
571                          if (zscan(y)[x] <= 0)
572 <                                (*deffill)(x,y);
572 >                                (*fill)(x,y);
573   }
574  
575  
# Line 592 | Line 613 | char   *fname;
613                          }
614                  } else
615                          zout = zscan(y);
616 <                if (write(fd, zout, hresolu*sizeof(float))
616 >                if (write(fd, (char *)zout, hresolu*sizeof(float))
617                                  < hresolu*sizeof(float)) {
618                          perror(fname);
619                          exit(1);
# Line 635 | Line 656 | char   *prog, *args;
656                  fprintf(stderr, "%s: too many calculations\n", progname);
657                  exit(1);
658          }
659 <        sprintf(combuf, prog, PACKSIZ, args);
659 >        sprintf(combuf, prog, args);
660          if (pipe(p0) < 0 || pipe(p1) < 0)
661                  syserror();
662          if ((childpid = vfork()) == 0) {        /* fork calculation */
# Line 671 | Line 692 | caldone()                              /* done with calculation */
692  
693          if (childpid == -1)
694                  return;
674        if (fclose(psend) == EOF)
675                syserror();
695          clearqueue();
696 +        fclose(psend);
697          fclose(precv);
698          while ((pid = wait(0)) != -1 && pid != childpid)
699                  ;
# Line 684 | Line 704 | caldone()                              /* done with calculation */
704   rcalfill(x, y)                          /* fill with ray-calculated pixel */
705   int     x, y;
706   {
707 <        FVECT   orig, dir;
688 <        float   outbuf[6];
689 <
690 <        if (queuesiz >= PACKSIZ) {      /* flush queue */
691 <                if (fflush(psend) == EOF)
692 <                        syserror();
707 >        if (queuesiz >= PACKSIZ)        /* flush queue if needed */
708                  clearqueue();
709 <        }
695 <                                        /* send new ray */
696 <        viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu);
697 <        outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2];
698 <        outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2];
699 <        if (fwrite(outbuf, sizeof(float), 6, psend) < 6)
700 <                syserror();
701 <                                        /* remember it */
709 >                                        /* add position to queue */
710          queue[queuesiz][0] = x;
711          queue[queuesiz][1] = y;
712          queuesiz++;
713   }
714  
715  
716 < clearqueue()                            /* get results from queue */
716 > clearqueue()                            /* process queue */
717   {
718 <        float   inbuf[4];
718 >        FVECT   orig, dir;
719 >        float   fbuf[6];
720          register int    i;
721  
722          for (i = 0; i < queuesiz; i++) {
723 <                if (fread(inbuf, sizeof(float), 4, precv) < 4) {
723 >                viewray(orig, dir, &ourview,
724 >                                (queue[i][0]+.5)/hresolu,
725 >                                (queue[i][1]+.5)/vresolu);
726 >                fbuf[0] = orig[0]; fbuf[1] = orig[1]; fbuf[2] = orig[2];
727 >                fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2];
728 >                fwrite((char *)fbuf, sizeof(float), 6, psend);
729 >        }
730 >                                        /* flush output and get results */
731 >        fbuf[3] = fbuf[4] = fbuf[5] = 0.0;              /* mark */
732 >        fwrite((char *)fbuf, sizeof(float), 6, psend);
733 >        if (fflush(psend) == EOF)
734 >                syserror();
735 >        for (i = 0; i < queuesiz; i++) {
736 >                if (fread((char *)fbuf, sizeof(float), 4, precv) < 4) {
737                          fprintf(stderr, "%s: read error in clearqueue\n",
738                                          progname);
739                          exit(1);
740                  }
741                  if (ourexp > 0 && ourexp != 1.0) {
742 <                        inbuf[0] *= ourexp;
743 <                        inbuf[1] *= ourexp;
744 <                        inbuf[2] *= ourexp;
742 >                        fbuf[0] *= ourexp;
743 >                        fbuf[1] *= ourexp;
744 >                        fbuf[2] *= ourexp;
745                  }
746                  setcolr(pscan(queue[i][1])[queue[i][0]],
747 <                                inbuf[0], inbuf[1], inbuf[2]);
748 <                zscan(queue[i][1])[queue[i][0]] = inbuf[3];
747 >                                fbuf[0], fbuf[1], fbuf[2]);
748 >                zscan(queue[i][1])[queue[i][0]] = fbuf[3];
749          }
750          queuesiz = 0;
751   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines