--- ray/src/px/pinterp.c 1993/04/01 11:21:18 2.10 +++ ray/src/px/pinterp.c 1994/12/22 19:11:01 2.15 @@ -1,4 +1,4 @@ -/* Copyright (c) 1993 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -186,7 +186,7 @@ char *argv[]; if (fillsamp == 1) fillo &= ~F_BACK; /* set view */ - if (err = setview(&ourview)) { + if ((err = setview(&ourview)) != NULL) { fprintf(stderr, "%s: %s\n", progname, err); exit(1); } @@ -197,6 +197,8 @@ char *argv[]; if (ourpict == NULL || ourzbuf == NULL) syserror(progname); bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); + /* new header */ + newheader("RADIANCE", stdout); /* get input */ for ( ; i < argc; i += 2) addpicture(argv[i], argv[i+1]); @@ -207,6 +209,8 @@ char *argv[]; fillpicture(fillfunc); /* close calculation */ caldone(); + /* aft clipping */ + clipaft(); /* add to header */ printargs(argc, argv, stdout); if (gotvfile) { @@ -241,8 +245,9 @@ char *s; { char fmt[32]; - if (isformat(s)) { - formatval(fmt, s); + if (isheadid(s)) + return; + if (formatval(fmt, s)) { wrongformat = strcmp(fmt, COLRFMT); return; } @@ -303,7 +308,6 @@ char *pfile, *zspec; register int x; if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) syserror(zspec); - exit(1); for (x = scanlen(&tresolu); x-- > 0; ) zin[x] = zvalue; } @@ -466,18 +470,20 @@ double z; movepixel(pos) /* reposition image point */ FVECT pos; { + double d0, d1; FVECT pt, direc; if (pos[2] <= 0) /* empty pixel */ return(-1); + if (normdist && theirview.type == VT_PER) { /* adjust distance */ + d0 = pos[0] + theirview.hoff - .5; + d1 = pos[1] + theirview.voff - .5; + pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2); + } if (hasmatrix) { pos[0] += theirview.hoff - .5; pos[1] += theirview.voff - .5; if (theirview.type == VT_PER) { - if (normdist) /* adjust for eye-ray distance */ - pos[2] /= sqrt( 1. - + pos[0]*pos[0]*theirview.hn2 - + pos[1]*pos[1]*theirview.vn2 ); pos[0] *= pos[2]; pos[1] *= pos[2]; } @@ -492,7 +498,7 @@ FVECT pos; pos[1] += .5 - ourview.voff; return(0); } - if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) + if (viewray(pt, direc, &theirview, pos[0], pos[1]) < -FTINY) return(-1); pt[0] += direc[0]*pos[2]; pt[1] += direc[1]*pos[2]; @@ -611,6 +617,36 @@ int (*fill)(); } +clipaft() /* perform aft clipping as indicated */ +{ + register int x, y; + double tstdist; + double yzn2, vx; + + if (ourview.vaft <= FTINY) + return; + tstdist = ourview.vaft; + for (y = 0; y < vresolu; y++) { + if (ourview.type == VT_PER) { /* adjust distance */ + yzn2 = (y+.5)/vresolu + ourview.voff - .5; + yzn2 = 1. + yzn2*yzn2*ourview.vn2; + tstdist = ourview.vaft * sqrt(yzn2); + } + for (x = 0; x < hresolu; x++) + if (zscan(y)[x] > tstdist) { + if (ourview.type == VT_PER) { + vx = (x+.5)/hresolu + ourview.hoff - .5; + if (zscan(y)[x] <= ourview.vaft * + sqrt(vx*vx*ourview.hn2 + yzn2)) + continue; + } + bzero(pscan(y)[x], sizeof(COLR)); + zscan(y)[x] = 0.0; + } + } +} + + writepicture() /* write out picture */ { int y; @@ -696,14 +732,14 @@ char *prog, *args; cp = combuf; wp = argv; for ( ; ; ) { - while (isspace(*cp)) cp++; - if (!*cp) break; - *wp++ = cp; - while (!isspace(*cp)) - if (!*cp++) goto done; - *cp++ = '\0'; + while (isspace(*cp)) /* nullify spaces */ + *cp++ = '\0'; + if (!*cp) /* all done? */ + break; + *wp++ = cp; /* add argument to list */ + while (*++cp && !isspace(*cp)) + ; } -done: *wp = NULL; /* start process */ if ((rval = open_process(PDesc, argv)) < 0)