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.9 by greg, Wed Jan 3 12:52:30 1990 UTC vs.
Revision 1.10 by greg, Wed Jan 3 15:33:44 1990 UTC

# Line 32 | Line 32 | VIEW   theirview = STDVIEW(512);       /* input view */
32   int     gotview;                        /* got input view? */
33  
34   double  theirs2ours[4][4];              /* transformation matrix */
35 + int     regdist = 0;                    /* regular distance? */
36  
37  
38   main(argc, argv)                        /* interpolate pictures */
# Line 51 | Line 52 | char   *argv[];
52                          check(2,1);
53                          zeps = atof(argv[++i]);
54                          break;
55 +                case 'r':                               /* regular distance */
56 +                        check(2,0);
57 +                        regdist = !regdist;
58 +                        break;
59                  case 'x':                               /* x resolution */
60                          check(2,1);
61                          ourview.hresolu = atoi(argv[++i]);
# Line 109 | Line 114 | char   *argv[];
114                          break;
115                  default:
116                  badopt:
117 <                        fprintf(stderr, "%s: unknown option '%s'\n",
117 >                        fprintf(stderr, "%s: command line error at '%s'\n",
118                                          progname, argv[i]);
119 <                        exit(1);
119 >                        goto userr;
120                  }
121                                                  /* check arguments */
122 <        if (argc-i < 2 || (argc-i)%2) {
123 <                fprintf(stderr, "Usage: %s [view args] pfile zfile ..\n",
119 <                                progname);
120 <                exit(1);
121 <        }
122 >        if (argc-i < 2 || (argc-i)%2)
123 >                goto userr;
124                                                  /* set view */
125          if (err = setview(&ourview)) {
126                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 148 | Line 150 | char   *argv[];
150          writepicture();
151  
152          exit(0);
153 + userr:
154 +        fprintf(stderr,
155 +        "Usage: %s [view opts][-t zthresh][-r] pfile zspec ..\n",
156 +                        progname);
157 +        exit(1);
158   #undef check
159   }
160  
# Line 169 | Line 176 | char   *s;
176   }
177  
178  
179 < addpicture(pfile, zfile)                /* add picture to output */
180 < char    *pfile, *zfile;
179 > addpicture(pfile, zspec)                /* add picture to output */
180 > char    *pfile, *zspec;
181   {
182 +        extern double   atof();
183          FILE    *pfp, *zfp;
184          char    *err;
185          COLR    *scanin;
186          float   *zin, *zlast;
187          int     *plast;
188          int     y;
189 <                                        /* open input files */
189 >                                        /* open picture file */
190          if ((pfp = fopen(pfile, "r")) == NULL) {
191                  perror(pfile);
192                  exit(1);
193          }
186        if ((zfp = fopen(zfile, "r")) == NULL) {
187                perror(zfile);
188                exit(1);
189        }
194                                          /* get header and view */
195          printf("%s:\n", pfile);
196          gotview = 0;
# Line 205 | Line 209 | char   *pfile, *zfile;
209                                          /* allocate scanlines */
210          scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR));
211          zin = (float *)malloc(theirview.hresolu*sizeof(float));
208        zlast = (float *)calloc(theirview.hresolu, sizeof(float));
212          plast = (int *)calloc(theirview.hresolu, sizeof(int));
213 <        if (scanin == NULL || zin == NULL || zlast == NULL || plast == NULL) {
213 >        zlast = (float *)calloc(theirview.hresolu, sizeof(float));
214 >        if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) {
215                  perror(progname);
216                  exit(1);
217          }
218 +                                        /* get z specification or file */
219 +        if ((zfp = fopen(zspec, "r")) == NULL) {
220 +                double  zvalue;
221 +                register int    x;
222 +                if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) {
223 +                        perror(zspec);
224 +                        exit(1);
225 +                }
226 +                for (x = 0; x < theirview.hresolu; x++)
227 +                        zin[x] = zvalue;
228 +        }
229                                          /* load image */
230          for (y = theirview.vresolu-1; y >= 0; y--) {
231                  if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) {
232                          fprintf(stderr, "%s: read error\n", pfile);
233                          exit(1);
234                  }
235 <                if (fread(zin, sizeof(float), theirview.hresolu, zfp)
235 >                if (zfp != NULL
236 >                        && fread(zin,sizeof(float),theirview.hresolu,zfp)
237                                  < theirview.hresolu) {
238 <                        fprintf(stderr, "%s: read error\n", zfile);
238 >                        fprintf(stderr, "%s: read error\n", zspec);
239                          exit(1);
240                  }
241                  addscanline(y, scanin, zin, plast, zlast);
# Line 230 | Line 246 | char   *pfile, *zfile;
246          free((char *)plast);
247          free((char *)zlast);
248          fclose(pfp);
249 <        fclose(zfp);
249 >        if (zfp != NULL)
250 >                fclose(zfp);
251   }
252  
253  
# Line 290 | Line 307 | float  *lastyz;                /* input/output */
307                  pos[1] = y - .5*(theirview.vresolu-1);
308                  pos[2] = zline[x];
309                  if (theirview.type == VT_PER) {
310 <                        /*
311 <                         * The following (single) statement can go
295 <                         * if z is along the view direction rather
296 <                         * than an eye ray.
297 <                         */
298 <                        pos[2] /= sqrt( 1.
310 >                        if (!regdist)   /* adjust for eye-ray distance */
311 >                                pos[2] /= sqrt( 1.
312                                          + pos[0]*pos[0]*theirview.vhn2
313                                          + pos[1]*pos[1]*theirview.vvn2 );
314                          pos[0] *= pos[2];
# Line 438 | Line 451 | writepicture()                         /* write out picture */
451                          perror(progname);
452                          exit(1);
453                  }
454 + }
455 +
456 +
457 + isfloat(s)                              /* see if string is floating number */
458 + register char   *s;
459 + {
460 +        for ( ; *s; s++)
461 +                if ((*s < '0' || *s > '9') && *s != '.' && *s != '-'
462 +                                && *s != 'e' && *s != 'E' && *s != '+')
463 +                        return(0);
464 +        return(1);
465   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines