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 2.24 by greg, Thu Sep 14 13:40:17 1995 UTC vs.
Revision 2.34 by schorsch, Thu Jun 26 00:58:10 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Interpolate and extrapolate pictures with different view parameters.
6   *
7   *      Greg Ward       09Dec89
8   */
9  
10 < #include "standard.h"
10 > #include "copyright.h"
11  
12   #include <ctype.h>
13  
14 + #include "standard.h"
15 + #include "rtprocess.h" /* Windows: must come before color.h */
16   #include "view.h"
18
17   #include "color.h"
18  
21 #include "resolu.h"
22
19   #define LOG2            0.69314718055994530942
20  
21   #define pscan(y)        (ourpict+(y)*hresolu)
# Line 39 | Line 35 | static char SCCSid[] = "$SunId$ LBL";
35  
36   #define PACKSIZ         256             /* max. calculation packet size */
37  
38 < #define RTCOM           "rtrace -h- -ovl -fff "
38 > #define RTCOM           "rtrace -h- -ovl -fff -ld- -i- -I- "
39  
40   #define ABS(x)          ((x)>0?(x):-(x))
41  
# Line 61 | Line 57 | COLR   *ourpict;                       /* output picture (COLR's) */
57   COLOR   *ourspict;                      /* output pixel sums (averaging) */
58   float   *ourweigh = NULL;               /* output pixel weights (averaging) */
59   float   *ourzbuf;                       /* corresponding z-buffer */
60 < COLOR   *ourbpict = NULL;               /* blurred picture */
60 > COLOR   *ourbpict = NULL;               /* blurred picture (view averaging) */
61  
62   VIEW    avgview;                        /* average view for -B option */
63   int     nvavg;                          /* number of views averaged */
# Line 76 | Line 72 | COLR   backcolr = BLKCOLR;             /* background color */
72   COLOR   backcolor = BLKCOLOR;           /* background color (float) */
73   double  backz = 0.0;                    /* background z value */
74   int     normdist = 1;                   /* i/o normalized distance? */
75 + char    ourfmt[LPICFMT+1] = PICFMT;     /* original picture format */
76   double  ourexp = -1;                    /* original picture exposure */
77   int     expadj = 0;                     /* exposure adjustment (f-stops) */
78   double  rexpadj = 1;                    /* real exposure adjustment */
# Line 88 | Line 85 | double theirexp;                       /* input picture exposure */
85   MAT4    theirs2ours;                    /* transformation matrix */
86   int     hasmatrix = 0;                  /* has transformation matrix */
87  
88 < int     PDesc[3] = {-1,-1,-1};          /* rtrace process descriptor */
92 < #define childpid        (PDesc[2])
88 > static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */
89   unsigned short  queue[PACKSIZ][2];      /* pending pixels */
90   int     packsiz;                        /* actual packet size */
91 < int     queuesiz;                       /* number of pixels pending */
91 > int     queuesiz = 0;                   /* number of pixels pending */
92  
93   extern double   movepixel();
94  
# Line 212 | Line 208 | char   *argv[];
208                          if (argv[an][2] != 'f')
209                                  goto badopt;
210                          check(3,"s");
211 <                        gotvfile = viewfile(argv[++an], &ourview, 0, 0);
211 >                        gotvfile = viewfile(argv[++an], &ourview, NULL);
212                          if (gotvfile < 0)
213                                  syserror(argv[an]);
214                          else if (gotvfile == 0) {
# Line 251 | Line 247 | char   *argv[];
247                                  rexpadj = pow(2.0, (double)expadj);
248                  }
249                                                  /* set view */
250 <        if (nextview(doblur ? stdin : NULL) == EOF) {
250 >        if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) {
251                  fprintf(stderr, "%s: no view on standard input!\n",
252                                  progname);
253                  exit(1);
# Line 278 | Line 274 | char   *argv[];
274                  syserror(progname);
275                                                          /* new header */
276          newheader("RADIANCE", stdout);
277 +        fputnow(stdout);
278                                                          /* run pictures */
279          do {
280                  bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float));
# Line 308 | Line 305 | char   *argv[];
305                  ourexp = rexpadj;
306          if (ourexp < .995 | ourexp > 1.005)
307                  fputexpos(ourexp, stdout);
308 <        fputformat(COLRFMT, stdout);
308 >        if (strcmp(ourfmt, PICFMT))             /* print format if known */
309 >                fputformat(ourfmt, stdout);
310          putc('\n', stdout);
311                                                          /* write picture */
312          writepicture();
# Line 326 | Line 324 | userr:
324   }
325  
326  
327 + int
328   headline(s)                             /* process header string */
329   char    *s;
330   {
331          char    fmt[32];
332  
333          if (isheadid(s))
334 <                return;
334 >                return(0);
335          if (formatval(fmt, s)) {
336 <                wrongformat = strcmp(fmt, COLRFMT);
337 <                return;
336 >                if (globmatch(ourfmt, fmt)) {
337 >                        wrongformat = 0;
338 >                        strcpy(ourfmt, fmt);
339 >                } else
340 >                        wrongformat = 1;
341 >                return(0);
342          }
343          if (nvavg < 2) {
344                  putc('\t', stdout);
# Line 343 | Line 346 | char   *s;
346          }
347          if (isexpos(s)) {
348                  theirexp *= exposval(s);
349 <                return;
349 >                return(0);
350          }
351          if (isview(s) && sscanview(&theirview, s) > 0)
352                  gotview++;
353 +        return(0);
354   }
355  
356  
# Line 465 | Line 469 | char   *pfile, *zspec;
469          if (xlim == NULL)
470                  syserror(progname);
471          if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */
472 <                free((char *)zin);
473 <                free((char *)xlim);
472 >                free((void *)zin);
473 >                free((void *)xlim);
474                  if (zfd != -1)
475                          close(zfd);
476                  fclose(pfp);
# Line 485 | Line 489 | char   *pfile, *zspec;
489                          exit(1);
490                  }
491          if (zfd != -1 && lseek(zfd,
492 <                        (long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0)
492 >                        (off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0)
493                  syserror(zspec);
494                                          /* load image */
495          for (y = ylim.min; y <= ylim.max; y++) {
# Line 500 | Line 504 | char   *pfile, *zspec;
504                  addscanline(xlim+y, y, scanin, zin, plast);
505          }
506                                          /* clean up */
507 <        free((char *)xlim);
508 <        free((char *)scanin);
509 <        free((char *)zin);
510 <        free((char *)plast);
507 >        free((void *)xlim);
508 >        free((void *)scanin);
509 >        free((void *)zin);
510 >        free((void *)plast);
511          fclose(pfp);
512          if (zfd != -1)
513                  close(zfd);
# Line 516 | Line 520 | register VIEW  *vw1, *vw2;
520   {
521          double  m4t[4][4];
522  
523 <        if (vw1->type != VT_PER && vw1->type != VT_PAR)
523 >        if (vw1->type != VT_PER & vw1->type != VT_PAR)
524                  return(0);
525 <        if (vw2->type != VT_PER && vw2->type != VT_PAR)
525 >        if (vw2->type != VT_PER & vw2->type != VT_PAR)
526                  return(0);
527          setident4(xfmat);
528          xfmat[0][0] = vw1->hvec[0];
# Line 635 | Line 639 | double z;
639                  y1 = p0->y + c1*s1y/l1;
640                  for (c2 = l2; c2-- > 0; ) {
641                          x = x1 + c2*s2x/l2;
642 <                        if (x < 0 || x >= hresolu)
642 >                        if (x < 0 | x >= hresolu)
643                                  continue;
644                          y = y1 + c2*s2y/l2;
645 <                        if (y < 0 || y >= vresolu)
645 >                        if (y < 0 | y >= vresolu)
646                                  continue;
647                          if (averaging) {
648                                  if (zscan(y)[x] <= 0 || zscan(y)[x]-z
# Line 666 | Line 670 | register FVECT pos;
670   {
671          FVECT   pt, tdir, odir;
672          double  d;
669        register int    i;
673          
674          if (pos[2] <= 0)                /* empty pixel */
675                  return(0);
676          if (usematrix) {
677                  pos[0] += theirview.hoff - .5;
678                  pos[1] += theirview.voff - .5;
679 <                if (normdist && theirview.type == VT_PER)
679 >                if (normdist & theirview.type == VT_PER)
680                          d = sqrt(1. + pos[0]*pos[0]*theirview.hn2
681                                          + pos[1]*pos[1]*theirview.vn2);
682                  else
# Line 707 | Line 710 | register FVECT pos;
710                  if (pos[2] <= 0)
711                          return(0);
712          }
713 <        if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY)
713 >        if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY)
714                  return(0);
715          if (!averaging)
716                  return(1);
717 <        if (ourview.type == VT_PAR)             /* compute our direction */
718 <                VCOPY(odir, ourview.vdir);
719 <        else
720 <                for (i = 0; i < 3; i++)
721 <                        odir[i] = (pt[i] - ourview.vp[i])/pos[2];
722 <        d = DOT(odir,tdir);                     /* compute pixel weight */
723 <        if (d >= 1.-1./MAXWT/MAXWT)
717 >                                                /* compute pixel weight */
718 >        if (ourview.type == VT_PAR) {
719 >                d = DOT(ourview.vdir,tdir);
720 >                d = 1. - d*d;
721 >        } else {
722 >                VSUB(odir, pt, ourview.vp);
723 >                d = DOT(odir,tdir);
724 >                d = 1. - d*d/DOT(odir,odir);
725 >        }
726 >        if (d <= 1./MAXWT/MAXWT)
727                  return(MAXWT);          /* clip to maximum weight */
728 <        return(1./sqrt(1.-d));
728 >        return(1./sqrt(d));
729   }
730  
731  
# Line 750 | Line 756 | int    zfd;
756          yl->min = 32000; yl->max = 0;           /* search for points on image */
757          for (y = step - 1; y < numscans(&tresolu); y += step) {
758                  if (zfd != -1) {
759 <                        if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float),
759 >                        if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float),
760                                          0) < 0)
761                                  syserror("lseek");
762                          if (read(zfd, (char *)zline,
# Line 911 | Line 917 | int    samp;
917                                  xback = -2;
918                          }
919          }
920 <        free((char *)yback);
920 >        free((void *)yback);
921   }
922  
923  
# Line 924 | Line 930 | int    (*fill)();
930                  for (x = 0; x < hresolu; x++)
931                          if (zscan(y)[x] <= 0)
932                                  (*fill)(x,y);
933 +        if (fill == rcalfill)
934 +                clearqueue();
935   }
936  
937  
# Line 1087 | Line 1095 | char   *prog, *args;
1095          int     rval;
1096          register char   **wp, *cp;
1097  
1098 <        if (childpid != -1) {
1098 >        if (PDesc.running) {
1099                  fprintf(stderr, "%s: too many calculations\n", progname);
1100                  exit(1);
1101          }
# Line 1106 | Line 1114 | char   *prog, *args;
1114          }
1115          *wp = NULL;
1116                                                  /* start process */
1117 <        if ((rval = open_process(PDesc, argv)) < 0)
1117 >        if ((rval = open_process(&PDesc, argv)) < 0)
1118                  syserror(progname);
1119          if (rval == 0) {
1120                  fprintf(stderr, "%s: command not found\n", argv[0]);
# Line 1121 | Line 1129 | char   *prog, *args;
1129  
1130   caldone()                               /* done with calculation */
1131   {
1132 <        if (childpid == -1)
1132 >        if (!PDesc.running)
1133                  return;
1134          clearqueue();
1135 <        close_process(PDesc);
1128 <        childpid = -1;
1135 >        close_process(&PDesc);
1136   }
1137  
1138  
# Line 1161 | Line 1168 | clearqueue()                           /* process queue */
1168          }
1169                                          /* mark end and get results */
1170          bzero((char *)fbp, 6*sizeof(float));
1171 <        if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz,
1171 >        if (process(&PDesc, (char *)fbuf, (char *)fbuf,
1172 >                        4*sizeof(float)*(queuesiz+1),
1173                          6*sizeof(float)*(queuesiz+1)) !=
1174 <                        4*sizeof(float)*queuesiz) {
1174 >                        4*sizeof(float)*(queuesiz+1)) {
1175                  fprintf(stderr, "%s: error reading from rtrace process\n",
1176                                  progname);
1177                  exit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines