--- ray/src/px/pinterp.c 1990/01/03 09:37:16 1.8 +++ ray/src/px/pinterp.c 1990/01/03 15:33:44 1.10 @@ -32,6 +32,7 @@ VIEW theirview = STDVIEW(512); /* input view */ int gotview; /* got input view? */ double theirs2ours[4][4]; /* transformation matrix */ +int regdist = 0; /* regular distance? */ main(argc, argv) /* interpolate pictures */ @@ -51,6 +52,10 @@ char *argv[]; check(2,1); zeps = atof(argv[++i]); break; + case 'r': /* regular distance */ + check(2,0); + regdist = !regdist; + break; case 'x': /* x resolution */ check(2,1); ourview.hresolu = atoi(argv[++i]); @@ -109,16 +114,13 @@ char *argv[]; break; default: badopt: - fprintf(stderr, "%s: unknown option '%s'\n", + fprintf(stderr, "%s: command line error at '%s'\n", progname, argv[i]); - exit(1); + goto userr; } /* check arguments */ - if (argc-i < 2 || (argc-i)%2) { - fprintf(stderr, "Usage: %s [view args] pfile zfile ..\n", - progname); - exit(1); - } + if (argc-i < 2 || (argc-i)%2) + goto userr; /* set view */ if (err = setview(&ourview)) { fprintf(stderr, "%s: %s\n", progname, err); @@ -148,6 +150,11 @@ char *argv[]; writepicture(); exit(0); +userr: + fprintf(stderr, + "Usage: %s [view opts][-t zthresh][-r] pfile zspec ..\n", + progname); + exit(1); #undef check } @@ -169,35 +176,30 @@ char *s; } -addpicture(pfile, zfile) /* add picture to output */ -char *pfile, *zfile; +addpicture(pfile, zspec) /* add picture to output */ +char *pfile, *zspec; { + extern double atof(); FILE *pfp, *zfp; char *err; COLR *scanin; - float *zin, *zout; - int *pout; - int xres, yres; + float *zin, *zlast; + int *plast; int y; - /* open input files */ + /* open picture file */ if ((pfp = fopen(pfile, "r")) == NULL) { perror(pfile); exit(1); } - if ((zfp = fopen(zfile, "r")) == NULL) { - perror(zfile); - exit(1); - } /* get header and view */ printf("%s:\n", pfile); gotview = 0; getheader(pfp, headline); - if (!gotview || fgetresolu(&xres, &yres, pfp) != (YMAJOR|YDECR)) { + if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp) + != (YMAJOR|YDECR)) { fprintf(stderr, "%s: picture view error\n", pfile); exit(1); } - theirview.hresolu = xres; - theirview.vresolu = yres; if (err = setview(&theirview)) { fprintf(stderr, "%s: %s\n", pfile, err); exit(1); @@ -205,33 +207,47 @@ char *pfile, *zfile; /* compute transformation */ pixform(theirs2ours, &theirview, &ourview); /* allocate scanlines */ - scanin = (COLR *)malloc(xres*sizeof(COLR)); - zin = (float *)malloc(xres*sizeof(float)); - zout = (float *)calloc(xres, sizeof(float)); - pout = (int *)calloc(xres, sizeof(int)); - if (scanin == NULL || zin == NULL || zout == NULL || pout == NULL) { + scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR)); + zin = (float *)malloc(theirview.hresolu*sizeof(float)); + plast = (int *)calloc(theirview.hresolu, sizeof(int)); + zlast = (float *)calloc(theirview.hresolu, sizeof(float)); + if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) { perror(progname); exit(1); } + /* get z specification or file */ + if ((zfp = fopen(zspec, "r")) == NULL) { + double zvalue; + register int x; + if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { + perror(zspec); + exit(1); + } + for (x = 0; x < theirview.hresolu; x++) + zin[x] = zvalue; + } /* load image */ - for (y = yres-1; y >= 0; y--) { - if (freadcolrs(scanin, xres, pfp) < 0) { + for (y = theirview.vresolu-1; y >= 0; y--) { + if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) { fprintf(stderr, "%s: read error\n", pfile); exit(1); } - if (fread(zin, sizeof(float), xres, zfp) < xres) { - fprintf(stderr, "%s: read error\n", zfile); + if (zfp != NULL + && fread(zin,sizeof(float),theirview.hresolu,zfp) + < theirview.hresolu) { + fprintf(stderr, "%s: read error\n", zspec); exit(1); } - addscanline(y, scanin, zin, pout, zout); + addscanline(y, scanin, zin, plast, zlast); } /* clean up */ free((char *)scanin); free((char *)zin); - free((char *)pout); - free((char *)zout); + free((char *)plast); + free((char *)zlast); fclose(pfp); - fclose(zfp); + if (zfp != NULL) + fclose(zfp); } @@ -275,8 +291,8 @@ addscanline(y, pline, zline, lasty, lastyz) /* add sca int y; COLR *pline; float *zline; -int *lasty; -float *lastyz; +int *lasty; /* input/output */ +float *lastyz; /* input/output */ { extern double sqrt(), fabs(); double pos[3]; @@ -291,12 +307,8 @@ float *lastyz; pos[1] = y - .5*(theirview.vresolu-1); pos[2] = zline[x]; if (theirview.type == VT_PER) { - /* - * The following (single) statement can go - * if z is along the view direction rather - * than an eye ray. - */ - pos[2] /= sqrt( 1. + if (!regdist) /* adjust for eye-ray distance */ + pos[2] /= sqrt( 1. + pos[0]*pos[0]*theirview.vhn2 + pos[1]*pos[1]*theirview.vvn2 ); pos[0] *= pos[2]; @@ -439,4 +451,15 @@ writepicture() /* write out picture */ perror(progname); exit(1); } +} + + +isfloat(s) /* see if string is floating number */ +register char *s; +{ + for ( ; *s; s++) + if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' + && *s != 'e' && *s != 'E' && *s != '+') + return(0); + return(1); }