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.12 by greg, Thu Jan 4 14:25:56 1990 UTC vs.
Revision 1.14 by greg, Thu Jan 4 17:47:37 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 */
20 > #define F_FORE          1               /* fill foreground */
21 > #define F_BACK          2               /* fill background */
22  
23 + #define PACKSIZ         42              /* calculation packet size */
24 +
25 + #define RTCOM           "rtrace -h -ovl -fff -x %d %s"
26 +
27   #define ABS(x)          ((x)>0?(x):-(x))
28  
29   VIEW    ourview = STDVIEW(512);         /* desired view */
# Line 35 | Line 39 | VIEW   theirview = STDVIEW(512);       /* input view */
39   int     gotview;                        /* got input view? */
40  
41   int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
42 < extern int      backfill();             /* fill functions */
42 > extern int      backfill(), rcalfill(); /* fill functions */
43   int     (*deffill)() = backfill;        /* selected fill function */
44   COLR    backcolr = BLKCOLR;             /* background color */
45 + double  backz = 0.0;                    /* background z value */
46  
47   double  theirs2ours[4][4];              /* transformation matrix */
48   int     normdist = 1;                   /* normalized distance? */
49  
50 + int     childpid = -1;                  /* id of fill process */
51 + FILE    *psend, *precv;                 /* pipes to/from fill calculation */
52 + int     queue[PACKSIZ][2];              /* pending pixels */
53 + int     queuesiz;                       /* number of pixels pending */
54  
55 +
56   main(argc, argv)                        /* interpolate pictures */
57   int     argc;
58   char    *argv[];
# Line 91 | Line 101 | char   *argv[];
101                                          atof(argv[i+2]), atof(argv[i+3]));
102                                  i += 3;
103                                  break;
104 +                        case 'z':                               /* z value */
105 +                                check(3,1);
106 +                                deffill = backfill;
107 +                                backz = atof(argv[++i]);
108 +                                break;
109 +                        case 'r':                               /* rtrace */
110 +                                check(3,1);
111 +                                deffill = rcalfill;
112 +                                calstart(RTCOM, argv[++i]);
113 +                                break;
114                          default:
115                                  goto badopt;
116                          }
# Line 162 | Line 182 | char   *argv[];
182                          goto userr;
183                  }
184                                                  /* check arguments */
185 <        if (argc-i < 2 || (argc-i)%2)
185 >        if ((argc-i)%2)
186                  goto userr;
187                                                  /* set view */
188          if (err = setview(&ourview)) {
# Line 184 | Line 204 | char   *argv[];
204                  backpicture();
205          else
206                  fillpicture();
207 +                                                        /* close calculation */
208 +        caldone();
209                                                          /* add to header */
210          printargs(argc, argv, stdout);
211          if (gotvfile) {
# Line 487 | Line 509 | backpicture()                          /* background fill algorithm */
509                                          || (xback >= 0 && ABS(x-xback) <= 1)
510                                          || ( ABS(y-yback[x]) > 1
511                                                  && zscan(yback[x])[x]
512 <                                                < zscan(y)[xback] ) )
512 >                                                < zscan(y)[xback] ) ) {
513                                          copycolr(pscan(y)[x],pscan(y)[xback]);
514 <                                else
514 >                                        zscan(y)[x] = zscan(y)[xback];
515 >                                } else {
516                                          copycolr(pscan(y)[x],pscan(yback[x])[x]);
517 +                                        zscan(y)[x] = zscan(yback[x])[x];
518 +                                }
519                          } else {                                /* full pixel */
520                                  yback[x] = -2;
521                                  xback = -2;
# Line 584 | Line 609 | int    x, y;
609          register BYTE   *dest = pscan(y)[x];
610  
611          copycolr(dest, backcolr);
612 +        zscan(y)[x] = backz;
613 + }
614 +
615 +
616 + calstart(prog, args)                    /* start fill calculation */
617 + char    *prog, *args;
618 + {
619 +        char    combuf[512];
620 +        int     p0[2], p1[2];
621 +
622 +        if (childpid != -1) {
623 +                fprintf(stderr, "%s: too many calculations\n", progname);
624 +                exit(1);
625 +        }
626 +        sprintf(combuf, prog, PACKSIZ, args);
627 +        if (pipe(p0) < 0 || pipe(p1) < 0)
628 +                syserror();
629 +        if ((childpid = vfork()) == 0) {        /* fork calculation */
630 +                close(p0[1]);
631 +                close(p1[0]);
632 +                if (p0[0] != 0) {
633 +                        dup2(p0[0], 0);
634 +                        close(p0[0]);
635 +                }
636 +                if (p1[1] != 1) {
637 +                        dup2(p1[1], 1);
638 +                        close(p1[1]);
639 +                }
640 +                execl("/bin/sh", "sh", "-c", combuf, 0);
641 +                perror("/bin/sh");
642 +                _exit(127);
643 +        }
644 +        if (childpid == -1)
645 +                syserror();
646 +        close(p0[0]);
647 +        close(p1[1]);
648 +        if ((psend = fdopen(p0[1], "w")) == NULL)
649 +                syserror();
650 +        if ((precv = fdopen(p1[0], "r")) == NULL)
651 +                syserror();
652 +        queuesiz = 0;
653 + }
654 +
655 +
656 + caldone()                               /* done with calculation */
657 + {
658 +        int     pid;
659 +
660 +        if (childpid == -1)
661 +                return;
662 +        if (fclose(psend) == EOF)
663 +                syserror();
664 +        clearqueue();
665 +        fclose(precv);
666 +        while ((pid = wait(0)) != -1 && pid != childpid)
667 +                ;
668 +        childpid = -1;
669 + }
670 +
671 +
672 + rcalfill(x, y)                          /* fill with ray-calculated pixel */
673 + int     x, y;
674 + {
675 +        FVECT   orig, dir;
676 +        float   outbuf[6];
677 +
678 +        if (queuesiz >= PACKSIZ) {      /* flush queue */
679 +                if (fflush(psend) == EOF)
680 +                        syserror();
681 +                clearqueue();
682 +        }
683 +                                        /* send new ray */
684 +        rayview(orig, dir, &ourview, x+.5, y+.5);
685 +        outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2];
686 +        outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2];
687 +        if (fwrite(outbuf, sizeof(float), 6, psend) < 6)
688 +                syserror();
689 +                                        /* remember it */
690 +        queue[queuesiz][0] = x;
691 +        queue[queuesiz][1] = y;
692 +        queuesiz++;
693 + }
694 +
695 +
696 + clearqueue()                            /* get results from queue */
697 + {
698 +        float   inbuf[4];
699 +        register int    i;
700 +
701 +        for (i = 0; i < queuesiz; i++) {
702 +                if (fread(inbuf, sizeof(float), 4, precv) < 4) {
703 +                        fprintf(stderr, "%s: read error in clearqueue\n",
704 +                                        progname);
705 +                        exit(1);
706 +                }
707 +                setcolr(pscan(queue[i][1])[queue[i][0]],
708 +                                inbuf[0], inbuf[1], inbuf[2]);
709 +                zscan(queue[i][1])[queue[i][0]] = inbuf[3];
710 +        }
711 +        queuesiz = 0;
712 + }
713 +
714 +
715 + syserror()                      /* report error and exit */
716 + {
717 +        perror(progname);
718 +        exit(1);
719   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines