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.16 by greg, Sat Jan 6 22:27:10 1990 UTC vs.
Revision 1.17 by greg, Mon Jan 8 14:47:15 1990 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include "color.h"
16  
17 < #define pscan(y)        (ourpict+(y)*ourview.hresolu)
18 < #define zscan(y)        (ourzbuf+(y)*ourview.hresolu)
17 > #define pscan(y)        (ourpict+(y)*hresolu)
18 > #define zscan(y)        (ourzbuf+(y)*hresolu)
19  
20   #define F_FORE          1               /* fill foreground */
21   #define F_BACK          2               /* fill background */
# Line 28 | Line 28 | static char SCCSid[] = "$SunId$ LBL";
28  
29   struct position {int x,y; float z;};
30  
31 < VIEW    ourview = STDVIEW(512);         /* desired view */
31 > VIEW    ourview = STDVIEW;              /* desired view */
32 > int     hresolu = 512;                  /* horizontal resolution */
33 > int     vresolu = 512;                  /* vertical resolution */
34  
35   double  zeps = .02;                     /* allowed z epsilon */
36  
# Line 45 | Line 47 | double backz = 0.0;                    /* background z value */
47   int     normdist = 1;                   /* normalized distance? */
48   double  ourexp = -1;                    /* output picture exposure */
49  
50 < VIEW    theirview = STDVIEW(512);       /* input view */
50 > VIEW    theirview = STDVIEW;            /* input view */
51   int     gotview;                        /* got input view? */
52 < double  theirs2ours[4][4];              /* transformation matrix */
52 > int     thresolu, tvresolu;             /* input resolution */
53   double  theirexp;                       /* input picture exposure */
54 + double  theirs2ours[4][4];              /* transformation matrix */
55  
56   int     childpid = -1;                  /* id of fill process */
57   FILE    *psend, *precv;                 /* pipes to/from fill calculation */
# Line 65 | Line 68 | char   *argv[];
68          int     gotvfile = 0;
69          char    *zfile = NULL;
70          char    *err;
71 <        int     i;
71 >        int     i, rval;
72  
73          progname = argv[0];
74  
75 <        for (i = 1; i < argc && argv[i][0] == '-'; i++)
75 >        for (i = 1; i < argc && argv[i][0] == '-'; i++) {
76 >                rval = getviewopt(&ourview, argc-i, argv+i);
77 >                if (rval >= 0) {
78 >                        i += rval;
79 >                        continue;
80 >                }
81                  switch (argv[i][1]) {
82                  case 't':                               /* threshold */
83                          check(2,1);
# Line 124 | Line 132 | char   *argv[];
132                          break;
133                  case 'x':                               /* x resolution */
134                          check(2,1);
135 <                        ourview.hresolu = atoi(argv[++i]);
135 >                        hresolu = atoi(argv[++i]);
136                          break;
137                  case 'y':                               /* y resolution */
138                          check(2,1);
139 <                        ourview.vresolu = atoi(argv[++i]);
139 >                        vresolu = atoi(argv[++i]);
140                          break;
141 <                case 'v':                               /* view */
142 <                        switch (argv[i][2]) {
135 <                        case 't':                               /* type */
136 <                                check(4,0);
137 <                                ourview.type = argv[i][3];
138 <                                break;
139 <                        case 'p':                               /* point */
140 <                                check(3,3);
141 <                                ourview.vp[0] = atof(argv[++i]);
142 <                                ourview.vp[1] = atof(argv[++i]);
143 <                                ourview.vp[2] = atof(argv[++i]);
144 <                                break;
145 <                        case 'd':                               /* direction */
146 <                                check(3,3);
147 <                                ourview.vdir[0] = atof(argv[++i]);
148 <                                ourview.vdir[1] = atof(argv[++i]);
149 <                                ourview.vdir[2] = atof(argv[++i]);
150 <                                break;
151 <                        case 'u':                               /* up */
152 <                                check(3,3);
153 <                                ourview.vup[0] = atof(argv[++i]);
154 <                                ourview.vup[1] = atof(argv[++i]);
155 <                                ourview.vup[2] = atof(argv[++i]);
156 <                                break;
157 <                        case 'h':                               /* horizontal */
158 <                                check(3,1);
159 <                                ourview.horiz = atof(argv[++i]);
160 <                                break;
161 <                        case 'v':                               /* vertical */
162 <                                check(3,1);
163 <                                ourview.vert = atof(argv[++i]);
164 <                                break;
165 <                        case 'f':                               /* file */
166 <                                check(3,1);
167 <                                gotvfile = viewfile(argv[++i], &ourview);
168 <                                if (gotvfile < 0) {
169 <                                        perror(argv[i]);
170 <                                        exit(1);
171 <                                } else if (gotvfile == 0) {
172 <                                        fprintf(stderr, "%s: bad view file\n",
173 <                                                        argv[i]);
174 <                                        exit(1);
175 <                                }
176 <                                break;
177 <                        default:
141 >                case 'v':                               /* view file */
142 >                        if (argv[i][2] != 'f')
143                                  goto badopt;
144 +                        check(3,1);
145 +                        gotvfile = viewfile(argv[++i], &ourview);
146 +                        if (gotvfile < 0) {
147 +                                perror(argv[i]);
148 +                                exit(1);
149 +                        } else if (gotvfile == 0) {
150 +                                fprintf(stderr, "%s: bad view file\n",
151 +                                                argv[i]);
152 +                                exit(1);
153                          }
154                          break;
155                  default:
# Line 184 | Line 158 | char   *argv[];
158                                          progname, argv[i]);
159                          goto userr;
160                  }
161 +        }
162                                                  /* check arguments */
163          if ((argc-i)%2)
164                  goto userr;
# Line 193 | Line 168 | char   *argv[];
168                  exit(1);
169          }
170                                                  /* allocate frame */
171 <        ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR));
172 <        ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float));
171 >        ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR));
172 >        ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float));
173          if (ourpict == NULL || ourzbuf == NULL)
174                  syserror();
175                                                          /* get input */
# Line 226 | Line 201 | char   *argv[];
201          exit(0);
202   userr:
203          fprintf(stderr,
204 <        "Usage: %s [view opts][-t zthresh][-z zout][-fT][-n] pfile zspec ..\n",
204 >        "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n",
205                          progname);
206          exit(1);
207   #undef check
# Line 247 | Line 222 | char   *s;
222          }
223          for (an = altname; *an != NULL; an++)
224                  if (!strncmp(*an, s, strlen(*an))) {
225 <                        if (sscanview(&theirview, s+strlen(*an)) == 0)
225 >                        if (sscanview(&theirview, s+strlen(*an)) > 0)
226                                  gotview++;
227                          break;
228                  }
# Line 274 | Line 249 | char   *pfile, *zspec;
249          gotview = 0;
250          printf("%s:\n", pfile);
251          getheader(pfp, headline);
252 <        if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp)
252 >        if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp)
253                          != (YMAJOR|YDECR)) {
254                  fprintf(stderr, "%s: picture view error\n", pfile);
255                  exit(1);
# Line 290 | Line 265 | char   *pfile, *zspec;
265                                          /* compute transformation */
266          pixform(theirs2ours, &theirview, &ourview);
267                                          /* allocate scanlines */
268 <        scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR));
269 <        zin = (float *)malloc(theirview.hresolu*sizeof(float));
270 <        plast = (struct position *)calloc(theirview.hresolu,
296 <                                                sizeof(struct position));
268 >        scanin = (COLR *)malloc(thresolu*sizeof(COLR));
269 >        zin = (float *)malloc(thresolu*sizeof(float));
270 >        plast = (struct position *)calloc(thresolu, sizeof(struct position));
271          if (scanin == NULL || zin == NULL || plast == NULL)
272                  syserror();
273                                          /* get z specification or file */
# Line 304 | Line 278 | char   *pfile, *zspec;
278                          perror(zspec);
279                          exit(1);
280                  }
281 <                for (x = 0; x < theirview.hresolu; x++)
281 >                for (x = 0; x < thresolu; x++)
282                          zin[x] = zvalue;
283          }
284                                          /* load image */
285 <        for (y = theirview.vresolu-1; y >= 0; y--) {
286 <                if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) {
285 >        for (y = tvresolu-1; y >= 0; y--) {
286 >                if (freadcolrs(scanin, thresolu, pfp) < 0) {
287                          fprintf(stderr, "%s: read error\n", pfile);
288                          exit(1);
289                  }
290                  if (zfp != NULL
291 <                        && fread(zin,sizeof(float),theirview.hresolu,zfp)
318 <                                < theirview.hresolu) {
291 >                        && fread(zin,sizeof(float),thresolu,zfp) < thresolu) {
292                          fprintf(stderr, "%s: read error\n", zspec);
293                          exit(1);
294                  }
# Line 338 | Line 311 | register VIEW  *vw1, *vw2;
311          double  m4t[4][4];
312  
313          setident4(xfmat);
314 <        xfmat[0][0] = vw1->vhinc[0];
315 <        xfmat[0][1] = vw1->vhinc[1];
316 <        xfmat[0][2] = vw1->vhinc[2];
317 <        xfmat[1][0] = vw1->vvinc[0];
318 <        xfmat[1][1] = vw1->vvinc[1];
319 <        xfmat[1][2] = vw1->vvinc[2];
314 >        xfmat[0][0] = vw1->hvec[0];
315 >        xfmat[0][1] = vw1->hvec[1];
316 >        xfmat[0][2] = vw1->hvec[2];
317 >        xfmat[1][0] = vw1->vvec[0];
318 >        xfmat[1][1] = vw1->vvec[1];
319 >        xfmat[1][2] = vw1->vvec[2];
320          xfmat[2][0] = vw1->vdir[0];
321          xfmat[2][1] = vw1->vdir[1];
322          xfmat[2][2] = vw1->vdir[2];
# Line 351 | Line 324 | register VIEW  *vw1, *vw2;
324          xfmat[3][1] = vw1->vp[1];
325          xfmat[3][2] = vw1->vp[2];
326          setident4(m4t);
327 <        m4t[0][0] = vw2->vhinc[0]/vw2->vhn2;
328 <        m4t[1][0] = vw2->vhinc[1]/vw2->vhn2;
329 <        m4t[2][0] = vw2->vhinc[2]/vw2->vhn2;
330 <        m4t[3][0] = -DOT(vw2->vp,vw2->vhinc)/vw2->vhn2;
331 <        m4t[0][1] = vw2->vvinc[0]/vw2->vvn2;
332 <        m4t[1][1] = vw2->vvinc[1]/vw2->vvn2;
333 <        m4t[2][1] = vw2->vvinc[2]/vw2->vvn2;
334 <        m4t[3][1] = -DOT(vw2->vp,vw2->vvinc)/vw2->vvn2;
327 >        m4t[0][0] = vw2->hvec[0]/vw2->hn2;
328 >        m4t[1][0] = vw2->hvec[1]/vw2->hn2;
329 >        m4t[2][0] = vw2->hvec[2]/vw2->hn2;
330 >        m4t[3][0] = -DOT(vw2->vp,vw2->hvec)/vw2->hn2;
331 >        m4t[0][1] = vw2->vvec[0]/vw2->vn2;
332 >        m4t[1][1] = vw2->vvec[1]/vw2->vn2;
333 >        m4t[2][1] = vw2->vvec[2]/vw2->vn2;
334 >        m4t[3][1] = -DOT(vw2->vp,vw2->vvec)/vw2->vn2;
335          m4t[0][2] = vw2->vdir[0];
336          m4t[1][2] = vw2->vdir[1];
337          m4t[2][2] = vw2->vdir[2];
# Line 378 | Line 351 | struct position        *lasty;         /* input/output */
351          struct position lastx, newpos;
352          register int    x;
353  
354 <        for (x = theirview.hresolu-1; x >= 0; x--) {
355 <                pos[0] = x - .5*(theirview.hresolu-1);
356 <                pos[1] = y - .5*(theirview.vresolu-1);
354 >        for (x = thresolu-1; x >= 0; x--) {
355 >                pos[0] = (x+.5)/thresolu + theirview.hoff - .5;
356 >                pos[1] = (y+.5)/tvresolu + theirview.voff - .5;
357                  pos[2] = zline[x];
358                  if (theirview.type == VT_PER) {
359                          if (normdist)   /* adjust for eye-ray distance */
360                                  pos[2] /= sqrt( 1.
361 <                                        + pos[0]*pos[0]*theirview.vhn2
362 <                                        + pos[1]*pos[1]*theirview.vvn2 );
361 >                                        + pos[0]*pos[0]*theirview.hn2
362 >                                        + pos[1]*pos[1]*theirview.vn2 );
363                          pos[0] *= pos[2];
364                          pos[1] *= pos[2];
365                  }
# Line 399 | Line 372 | struct position        *lasty;         /* input/output */
372                          pos[0] /= pos[2];
373                          pos[1] /= pos[2];
374                  }
375 <                pos[0] += .5*ourview.hresolu;
376 <                pos[1] += .5*ourview.vresolu;
377 <                newpos.x = pos[0];
378 <                newpos.y = pos[1];
375 >                pos[0] += .5 - ourview.hoff;
376 >                pos[1] += .5 - ourview.voff;
377 >                newpos.x = pos[0] * hresolu;
378 >                newpos.y = pos[1] * vresolu;
379                  newpos.z = zline[x];
380                                          /* add pixel to our image */
381 <                if (pos[0] >= 0 && newpos.x < ourview.hresolu
382 <                                && pos[1] >= 0 && newpos.y < ourview.vresolu) {
381 >                if (pos[0] >= 0 && newpos.x < hresolu
382 >                                && pos[1] >= 0 && newpos.y < vresolu) {
383                          addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]);
384                          lasty[x].x = lastx.x = newpos.x;
385                          lasty[x].y = lastx.y = newpos.y;
# Line 477 | Line 450 | backpicture()                          /* background fill algorithm */
450          COLR    pfill;
451          register int    x, i;
452                                                          /* get back buffer */
453 <        yback = (int *)malloc(ourview.hresolu*sizeof(int));
453 >        yback = (int *)malloc(hresolu*sizeof(int));
454          if (yback == NULL)
455                  syserror();
456 <        for (x = 0; x < ourview.hresolu; x++)
456 >        for (x = 0; x < hresolu; x++)
457                  yback[x] = -2;
458          /*
459           * Xback and yback are the pixel locations of suitable
# Line 489 | Line 462 | backpicture()                          /* background fill algorithm */
462           * that there is no suitable background in this direction.
463           */
464                                                          /* fill image */
465 <        for (y = 0; y < ourview.vresolu; y++) {
465 >        for (y = 0; y < vresolu; y++) {
466                  xback = -2;
467 <                for (x = 0; x < ourview.hresolu; x++)
467 >                for (x = 0; x < hresolu; x++)
468                          if (zscan(y)[x] <= 0) {         /* empty pixel */
469                                  /*
470                                   * First, find background from above or below.
471                                   * (farthest assigned pixel)
472                                   */
473                                  if (yback[x] == -2) {
474 <                                        for (i = y+1; i < ourview.vresolu; i++)
474 >                                        for (i = y+1; i < vresolu; i++)
475                                                  if (zscan(i)[x] > 0)
476                                                          break;
477 <                                        if (i < ourview.vresolu
477 >                                        if (i < vresolu
478                                  && (y <= 0 || zscan(y-1)[x] < zscan(i)[x]))
479                                                  yback[x] = i;
480                                          else
# Line 511 | Line 484 | backpicture()                          /* background fill algorithm */
484                                   * Next, find background from left or right.
485                                   */
486                                  if (xback == -2) {
487 <                                        for (i = x+1; i < ourview.hresolu; i++)
487 >                                        for (i = x+1; i < hresolu; i++)
488                                                  if (zscan(y)[i] > 0)
489                                                          break;
490 <                                        if (i < ourview.hresolu
490 >                                        if (i < hresolu
491                                  && (x <= 0 || zscan(y)[x-1] < zscan(y)[i]))
492                                                  xback = i;
493                                          else
# Line 556 | Line 529 | fillpicture()                          /* paint in empty pixels with default
529   {
530          register int    x, y;
531  
532 <        for (y = 0; y < ourview.vresolu; y++)
533 <                for (x = 0; x < ourview.hresolu; x++)
532 >        for (y = 0; y < vresolu; y++)
533 >                for (x = 0; x < hresolu; x++)
534                          if (zscan(y)[x] <= 0)
535                                  (*deffill)(x,y);
536   }
# Line 567 | Line 540 | writepicture()                         /* write out picture */
540   {
541          int     y;
542  
543 <        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout);
544 <        for (y = ourview.vresolu-1; y >= 0; y--)
545 <                if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0)
543 >        fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
544 >        for (y = vresolu-1; y >= 0; y--)
545 >                if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
546                          syserror();
547   }
548  
# Line 588 | Line 561 | char   *fname;
561                  exit(1);
562          }
563          if (donorm
564 <        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL)
564 >        && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL)
565                  syserror();
566 <        for (y = ourview.vresolu-1; y >= 0; y--) {
566 >        for (y = vresolu-1; y >= 0; y--) {
567                  if (donorm) {
568                          double  vx, yzn2;
569                          register int    x;
570 <                        yzn2 = y - .5*(ourview.vresolu-1);
571 <                        yzn2 = 1. + yzn2*yzn2*ourview.vvn2;
572 <                        for (x = 0; x < ourview.hresolu; x++) {
573 <                                vx = x - .5*(ourview.hresolu-1);
570 >                        yzn2 = y - .5*(vresolu-1);
571 >                        yzn2 = 1. + yzn2*yzn2*ourview.vn2;
572 >                        for (x = 0; x < hresolu; x++) {
573 >                                vx = x - .5*(hresolu-1);
574                                  zout[x] = zscan(y)[x]
575 <                                        * sqrt(vx*vx*ourview.vhn2 + yzn2);
575 >                                        * sqrt(vx*vx*ourview.hn2 + yzn2);
576                          }
577                  } else
578                          zout = zscan(y);
579 <                if (fwrite(zout, sizeof(float), ourview.hresolu, fp)
607 <                                < ourview.hresolu) {
579 >                if (fwrite(zout, sizeof(float), hresolu, fp) < hresolu) {
580                          perror(fname);
581                          exit(1);
582                  }
# Line 704 | Line 676 | int    x, y;
676                  clearqueue();
677          }
678                                          /* send new ray */
679 <        rayview(orig, dir, &ourview, x+.5, y+.5);
679 >        viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu);
680          outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2];
681          outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2];
682          if (fwrite(outbuf, sizeof(float), 6, psend) < 6)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines