--- ray/src/px/pinterp.c 1992/09/24 21:33:52 2.8 +++ ray/src/px/pinterp.c 1994/12/22 19:11:01 2.15 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -20,10 +20,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "resolu.h" -#ifndef BSD -#define vfork fork -#endif - #define pscan(y) (ourpict+(y)*hresolu) #define zscan(y) (ourzbuf+(y)*hresolu) @@ -169,10 +165,9 @@ char *argv[]; goto badopt; check(3,"s"); gotvfile = viewfile(argv[++i], &ourview, 0, 0); - if (gotvfile < 0) { - perror(argv[i]); - exit(1); - } else if (gotvfile == 0) { + if (gotvfile < 0) + syserror(argv[i]); + else if (gotvfile == 0) { fprintf(stderr, "%s: bad view file\n", argv[i]); exit(1); @@ -191,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); } @@ -200,8 +195,10 @@ char *argv[]; ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); if (ourpict == NULL || ourzbuf == NULL) - syserror(); + 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]); @@ -212,6 +209,8 @@ char *argv[]; fillpicture(fillfunc); /* close calculation */ caldone(); + /* aft clipping */ + clipaft(); /* add to header */ printargs(argc, argv, stdout); if (gotvfile) { @@ -246,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; } @@ -274,10 +274,8 @@ char *pfile, *zspec; struct position *plast; int y; /* open picture file */ - if ((pfp = fopen(pfile, "r")) == NULL) { - perror(pfile); - exit(1); - } + if ((pfp = fopen(pfile, "r")) == NULL) + syserror(pfile); /* get header with exposure and view */ theirexp = 1.0; gotview = 0; @@ -303,15 +301,13 @@ char *pfile, *zspec; plast = (struct position *)calloc(scanlen(&tresolu), sizeof(struct position)); if (scanin == NULL || zin == NULL || plast == NULL) - syserror(); + syserror(progname); /* get z specification or file */ if ((zfd = open(zspec, O_RDONLY)) == -1) { double zvalue; register int x; - if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { - perror(zspec); - exit(1); - } + if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) + syserror(zspec); for (x = scanlen(&tresolu); x-- > 0; ) zin[x] = zvalue; } @@ -386,7 +382,6 @@ COLR *pline; float *zline; struct position *lasty; /* input/output */ { - extern double sqrt(); FVECT pos; struct position lastx, newpos; register int x; @@ -475,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]; } @@ -501,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]; @@ -523,7 +520,7 @@ int samp; /* get back buffer */ yback = (int *)malloc(hresolu*sizeof(int)); if (yback == NULL) - syserror(); + syserror(progname); for (x = 0; x < hresolu; x++) yback[x] = -2; /* @@ -620,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; @@ -627,26 +654,23 @@ writepicture() /* write out picture */ fprtresolu(hresolu, vresolu, stdout); for (y = vresolu-1; y >= 0; y--) if (fwritecolrs(pscan(y), hresolu, stdout) < 0) - syserror(); + syserror(progname); } writedistance(fname) /* write out z file */ char *fname; { - extern double sqrt(); int donorm = normdist && ourview.type == VT_PER; int fd; int y; float *zout; - if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { - perror(fname); - exit(1); - } + if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) + syserror(fname); if (donorm && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) - syserror(); + syserror(progname); for (y = vresolu-1; y >= 0; y--) { if (donorm) { double vx, yzn2; @@ -661,10 +685,8 @@ char *fname; } else zout = zscan(y); if (write(fd, (char *)zout, hresolu*sizeof(float)) - < hresolu*sizeof(float)) { - perror(fname); - exit(1); - } + < hresolu*sizeof(float)) + syserror(fname); } if (donorm) free((char *)zout); @@ -710,18 +732,18 @@ 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) - syserror(); + syserror(progname); if (rval == 0) { fprintf(stderr, "%s: command not found\n", argv[0]); exit(1); @@ -762,6 +784,8 @@ clearqueue() /* process queue */ register float *fbp; register int i; + if (queuesiz == 0) + return; fbp = fbuf; for (i = 0; i < queuesiz; i++) { viewray(orig, dir, &ourview, @@ -795,8 +819,9 @@ clearqueue() /* process queue */ } -syserror() /* report error and exit */ +syserror(s) /* report error and exit */ +char *s; { - perror(progname); + perror(s); exit(1); }