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.24 by greg, Mon Feb 26 14:01:44 1990 UTC vs.
Revision 1.25 by greg, Tue Mar 6 11:14:36 1990 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include "color.h"
18  
19 + #include "random.h"
20 +
21   #ifndef BSD
22   #define vfork           fork
23   #endif
# Line 23 | Line 25 | static char SCCSid[] = "$SunId$ LBL";
25   #define pscan(y)        (ourpict+(y)*hresolu)
26   #define zscan(y)        (ourzbuf+(y)*hresolu)
27  
28 + #define PMASK           0xfffffff       /* probability mask */
29 + #define sampval(x)      (long)((x)*(PMASK+1)+.5)
30 + #define samp(p)         ((p) > (random()&PMASK))
31 +
32   #define F_FORE          1               /* fill foreground */
33   #define F_BACK          2               /* fill background */
34  
35   #define PACKSIZ         42              /* calculation packet size */
36  
37 < #define RTCOM           "rtrace -h -ovl -fff -x %d %s"
37 > #define RTCOM           "rtrace -h -ovl -fff %s"
38  
39   #define ABS(x)          ((x)>0?(x):-(x))
40  
# Line 46 | Line 52 | float  *ourzbuf;                       /* corresponding z-buffer */
52  
53   char    *progname;
54  
55 < int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
55 > int     fillo = F_FORE|F_BACK;          /* selected fill options */
56 > long    sampprob = 0;                   /* sample probability */
57   extern int      backfill(), rcalfill(); /* fill functions */
58 < int     (*deffill)() = backfill;        /* selected fill function */
58 > int     (*fillfunc)() = backfill;       /* selected fill function */
59   COLR    backcolr = BLKCOLR;             /* background color */
60   double  backz = 0.0;                    /* background z value */
61   int     normdist = 1;                   /* normalized distance? */
# Line 98 | Line 105 | char   *argv[];
105                          switch (argv[i][2]) {
106                          case '0':                               /* none */
107                                  check(3,0);
108 <                                fill = 0;
108 >                                fillo = 0;
109                                  break;
110                          case 'f':                               /* foreground */
111                                  check(3,0);
112 <                                fill = F_FORE;
112 >                                fillo = F_FORE;
113                                  break;
114                          case 'b':                               /* background */
115                                  check(3,0);
116 <                                fill = F_BACK;
116 >                                fillo = F_BACK;
117                                  break;
118                          case 'a':                               /* all */
119                                  check(3,0);
120 <                                fill = F_FORE|F_BACK;
120 >                                fillo = F_FORE|F_BACK;
121                                  break;
122 +                        case 's':                               /* sample */
123 +                                check(3,1);
124 +                                sampprob = sampval(atof(argv[++i]));
125 +                                break;
126                          case 'c':                               /* color */
127                                  check(3,3);
128 <                                deffill = backfill;
128 >                                fillfunc = backfill;
129                                  setcolr(backcolr, atof(argv[i+1]),
130                                          atof(argv[i+2]), atof(argv[i+3]));
131                                  i += 3;
132                                  break;
133                          case 'z':                               /* z value */
134                                  check(3,1);
135 <                                deffill = backfill;
135 >                                fillfunc = backfill;
136                                  backz = atof(argv[++i]);
137                                  break;
138                          case 'r':                               /* rtrace */
139                                  check(3,1);
140 <                                deffill = rcalfill;
140 >                                fillfunc = rcalfill;
141                                  calstart(RTCOM, argv[++i]);
142                                  break;
143                          default:
# Line 188 | Line 199 | char   *argv[];
199          for ( ; i < argc; i += 2)
200                  addpicture(argv[i], argv[i+1]);
201                                                          /* fill in spaces */
202 <        if (fill&F_BACK)
203 <                backpicture();
202 >        if (fillo&F_BACK)
203 >                backpicture(fillfunc, sampprob);
204          else
205 <                fillpicture();
205 >                fillpicture(fillfunc);
206                                                          /* close calculation */
207          caldone();
208                                                          /* add to header */
209          printargs(argc, argv, stdout);
210          if (gotvfile) {
211 <                printf(VIEWSTR);
211 >                fputs(VIEWSTR, stdout);
212                  fprintview(&ourview, stdout);
213 <                printf("\n");
213 >                putc('\n', stdout);
214          }
215          if (pixaspect < .99 || pixaspect > 1.01)
216                  fputaspect(pixaspect, stdout);
217          if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
218                  fputexpos(ourexp, stdout);
219 <        printf("\n");
219 >        putc('\n', stdout);
220                                                          /* write picture */
221          writepicture();
222                                                          /* write z file */
# Line 225 | Line 236 | userr:
236   headline(s)                             /* process header string */
237   char    *s;
238   {
239 <        static char     *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL};
239 >        static char     *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL};
240          register char   **an;
241  
242 <        printf("\t%s", s);
242 >        putc('\t', stdout);
243 >        fputs(s, stdout);
244  
245          if (isexpos(s)) {
246                  theirexp *= exposval(s);
# Line 419 | Line 431 | double z;
431          register int    x, y;                   /* final position */
432  
433                                          /* compute vector p0p1 */
434 <        if (fill&F_FORE && ABS(p1->z-p0->z) <= zt) {
434 >        if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) {
435                  s1x = p1->x - p0->x;
436                  s1y = p1->y - p0->y;
437                  l1 = ABS(s1x);
# Line 430 | Line 442 | double z;
442                  p1isy = -1;
443          }
444                                          /* compute vector p0p2 */
445 <        if (fill&F_FORE && ABS(p2->z-p0->z) <= zt) {
445 >        if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) {
446                  s2x = p2->x - p0->x;
447                  s2y = p2->y - p0->y;
448                  if (p1isy == 1)
# Line 459 | Line 471 | double z;
471   }
472  
473  
474 < backpicture()                           /* background fill algorithm */
474 > backpicture(fill, prob)                 /* background fill algorithm */
475 > int     (*fill)();
476 > long    prob;
477   {
478          int     *yback, xback;
479          int     y;
# Line 511 | Line 525 | backpicture()                          /* background fill algorithm */
525                                  }
526                                  /*
527                                   * Check to see if we have no background for
528 <                                 * this pixel.  If not, use background color.
528 >                                 * this pixel.  If not, or sampling was
529 >                                 * requested, use the given fill function.
530                                   */
531 <                                if (xback < 0 && yback[x] < 0) {
532 <                                        (*deffill)(x,y);
531 >                                if ((xback < 0 && yback[x] < 0) || samp(prob)) {
532 >                                        (*fill)(x,y);
533                                          continue;
534                                  }
535                                  /*
# Line 541 | Line 556 | backpicture()                          /* background fill algorithm */
556   }
557  
558  
559 < fillpicture()                           /* paint in empty pixels with default */
559 > fillpicture(fill)               /* paint in empty pixels using fill */
560 > int     (*fill)();
561   {
562          register int    x, y;
563  
564          for (y = 0; y < vresolu; y++)
565                  for (x = 0; x < hresolu; x++)
566                          if (zscan(y)[x] <= 0)
567 <                                (*deffill)(x,y);
567 >                                (*fill)(x,y);
568   }
569  
570  
# Line 635 | Line 651 | char   *prog, *args;
651                  fprintf(stderr, "%s: too many calculations\n", progname);
652                  exit(1);
653          }
654 <        sprintf(combuf, prog, PACKSIZ, args);
654 >        sprintf(combuf, prog, args);
655          if (pipe(p0) < 0 || pipe(p1) < 0)
656                  syserror();
657          if ((childpid = vfork()) == 0) {        /* fork calculation */
# Line 671 | Line 687 | caldone()                              /* done with calculation */
687  
688          if (childpid == -1)
689                  return;
690 <        clearqueue(1);
690 >        clearqueue();
691 >        fclose(psend);
692 >        fclose(precv);
693          while ((pid = wait(0)) != -1 && pid != childpid)
694                  ;
695          childpid = -1;
# Line 682 | Line 700 | rcalfill(x, y)                         /* fill with ray-calculated pixel */
700   int     x, y;
701   {
702          if (queuesiz >= PACKSIZ)        /* flush queue if needed */
703 <                clearqueue(0);
703 >                clearqueue();
704                                          /* add position to queue */
705          queue[queuesiz][0] = x;
706          queue[queuesiz][1] = y;
# Line 690 | Line 708 | int    x, y;
708   }
709  
710  
711 < clearqueue(done)                        /* process queue */
694 < int     done;
711 > clearqueue()                            /* process queue */
712   {
713          FVECT   orig, dir;
714          float   fbuf[6];
# Line 705 | Line 722 | int    done;
722                  fbuf[3] = dir[0]; fbuf[4] = dir[1]; fbuf[5] = dir[2];
723                  fwrite((char *)fbuf, sizeof(float), 6, psend);
724          }
725 <        if ((done ? fclose(psend) : fflush(psend)) == EOF)
725 >                                        /* flush output and get results */
726 >        fbuf[3] = fbuf[4] = fbuf[5] = 0.0;              /* mark */
727 >        fwrite((char *)fbuf, sizeof(float), 6, psend);
728 >        if (fflush(psend) == EOF)
729                  syserror();
730          for (i = 0; i < queuesiz; i++) {
731                  if (fread((char *)fbuf, sizeof(float), 4, precv) < 4) {
# Line 722 | Line 742 | int    done;
742                                  fbuf[0], fbuf[1], fbuf[2]);
743                  zscan(queue[i][1])[queue[i][0]] = fbuf[3];
744          }
725        if (done)
726                fclose(precv);
745          queuesiz = 0;
746   }
747  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines