ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ranimate.c
(Generate patch)

Comparing ray/src/util/ranimate.c (file contents):
Revision 2.5 by greg, Tue Jan 23 16:14:28 1996 UTC vs.
Revision 2.42 by schorsch, Tue Oct 21 19:19:29 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   * Radiance animation control program
6 + *
7 + * The main difference between this program and ranimove is that
8 + * we have many optimizations here for camera motion in static
9 + * environments, calling rpict and pinterp on multiple processors,
10 + * where ranimove puts its emphasis on object motion, and does
11 + * not use any external programs for image generation.
12 + *
13 + * See the ranimate(1) man page for further details.
14   */
15  
16 < #include "standard.h"
16 > #include "copyright.h"
17 >
18   #include <ctype.h>
13 #include <sys/types.h>
19   #include <sys/stat.h>
20 +
21 + #include "standard.h"
22 + #include "paths.h"
23   #include "view.h"
24   #include "vars.h"
25   #include "netproc.h"
26 <                                /* input variables */
27 < #define HOST            0               /* rendering host machine */
28 < #define RENDER          1               /* rendering options */
29 < #define PFILT           2               /* pfilt options */
30 < #define PINTERP         3               /* pinterp options */
31 < #define OCTREE          4               /* octree file name */
32 < #define DIRECTORY       5               /* working (sub)directory */
33 < #define BASENAME        6               /* output image base name */
34 < #define VIEWFILE        7               /* animation frame views */
35 < #define START           8               /* starting frame number */
36 < #define END             9               /* ending frame number */
37 < #define RIF             10              /* rad input file */
38 < #define NEXTANIM        11              /* next animation file */
39 < #define ANIMATE         12              /* animation command */
40 < #define TRANSFER        13              /* frame transfer command */
41 < #define ARCHIVE         14              /* archiving command */
42 < #define INTERP          15              /* # frames to interpolate */
43 < #define OVERSAMP        16              /* # times to oversample image */
44 < #define MBLUR           17              /* samples for motion blur */
45 < #define RTRACE          18              /* use rtrace with pinterp? */
46 < #define DISKSPACE       19              /* how much disk space to use */
47 < #define RESOLUTION      20              /* desired final resolution */
48 < #define EXPOSURE        21              /* how to compute exposure */
26 >                                /* default blur samples */
27 > #ifndef DEF_NBLUR
28 > #define DEF_NBLUR       5
29 > #endif
30 >                                /* default remote shell */
31 > #define REMSH           "rsh"
32 >                                /* input variables (alphabetical by name) */
33 > #define ANIMATE         0               /* animation command */
34 > #define ARCHIVE         1               /* archiving command */
35 > #define BASENAME        2               /* output image base name */
36 > #define DIRECTORY       3               /* working (sub)directory */
37 > #define DISKSPACE       4               /* how much disk space to use */
38 > #define END             5               /* ending frame number */
39 > #define EXPOSURE        6               /* how to compute exposure */
40 > #define HOST            7               /* rendering host machine */
41 > #define INTERP          8               /* # frames to interpolate */
42 > #define MBLUR           9               /* motion blur parameters */
43 > #define NEXTANIM        10              /* next animation file */
44 > #define OCTREE          11              /* octree file name */
45 > #define OVERSAMP        12              /* # times to oversample image */
46 > #define PFILT           13              /* pfilt options */
47 > #define PINTERP         14              /* pinterp options */
48 > #define RENDER          15              /* rendering options */
49 > #define RESOLUTION      16              /* desired final resolution */
50 > #define RIF             17              /* rad input file */
51 > #define RSH             18              /* remote shell script or program */
52 > #define RTRACE          19              /* use rtrace with pinterp? */
53 > #define START           20              /* starting frame number */
54 > #define TRANSFER        21              /* frame transfer command */
55 > #define VIEWFILE        22              /* animation frame views */
56  
57 < int     NVARS = 22;             /* total number of variables */
57 > int     NVARS = 23;             /* total number of variables */
58  
59   VARIABLE        vv[] = {                /* variable-value pairs */
45        {"host",        4,      0,      NULL,   NULL},
46        {"render",      3,      0,      NULL,   catvalues},
47        {"pfilt",       2,      0,      NULL,   catvalues},
48        {"pinterp",     2,      0,      NULL,   catvalues},
49        {"OCTREE",      3,      0,      NULL,   onevalue},
50        {"DIRECTORY",   3,      0,      NULL,   onevalue},
51        {"BASENAME",    3,      0,      NULL,   onevalue},
52        {"VIEWFILE",    2,      0,      NULL,   onevalue},
53        {"START",       2,      0,      NULL,   intvalue},
54        {"END",         2,      0,      NULL,   intvalue},
55        {"RIF",         3,      0,      NULL,   onevalue},
56        {"NEXTANIM",    3,      0,      NULL,   onevalue},
60          {"ANIMATE",     2,      0,      NULL,   onevalue},
58        {"TRANSFER",    2,      0,      NULL,   onevalue},
61          {"ARCHIVE",     2,      0,      NULL,   onevalue},
62 +        {"BASENAME",    3,      0,      NULL,   onevalue},
63 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
64 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
65 +        {"END",         2,      0,      NULL,   intvalue},
66 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
67 +        {"host",        4,      0,      NULL,   NULL},
68          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
61        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
69          {"MBLUR",       2,      0,      NULL,   onevalue},
70 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
71 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
70 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
71 >        {"OCTREE",      3,      0,      NULL,   onevalue},
72 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
73 >        {"pfilt",       2,      0,      NULL,   catvalues},
74 >        {"pinterp",     2,      0,      NULL,   catvalues},
75 >        {"render",      3,      0,      NULL,   catvalues},
76          {"RESOLUTION",  3,      0,      NULL,   onevalue},
77 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
77 >        {"RIF",         3,      0,      NULL,   onevalue},
78 >        {"RSH",         3,      0,      NULL,   onevalue},
79 >        {"RTRACE",      2,      0,      NULL,   boolvalue},
80 >        {"START",       2,      0,      NULL,   intvalue},
81 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
82 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
83   };
84  
85   #define SFNAME  "STATUS"                /* status file name */
# Line 84 | Line 100 | int    nowarn = 0;             /* turn warnings off? */
100   int     silent = 0;             /* silent mode? */
101   int     noaction = 0;           /* take no action? */
102  
103 < char    rendopt[2048] = "";     /* rendering options */
103 > char    *remsh;                 /* remote shell program/script */
104 > char    rendopt[2048];          /* rendering options */
105   char    rresopt[32];            /* rendering resolution options */
106   char    fresopt[32];            /* filter resolution options */
107   int     pfiltalways;            /* always use pfilt? */
108  
109 + char    arcargs[10240];         /* files to archive */
110 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
111 +
112   struct pslot {
113          int     pid;                    /* process ID (0 if empty) */
114          int     fout;                   /* output frame number */
# Line 96 | Line 116 | struct pslot {
116   }       *pslot;                 /* process slots */
117   int     npslots;                /* number of process slots */
118  
99 int     lastpid;                /* ID of last completed background process */
100 PSERVER *lastpserver;           /* last process server used */
101
119   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
120  
121   struct pslot    *findpslot();
122  
123 + PSERVER *lastpserver;           /* last process server with error */
124 +
125   VIEW    *getview();
126 < char    *getexp();
126 > char    *getexp(), *dirfile();
127 > int     getblur();
128  
129 + extern time_t   time();
130  
131 +
132   main(argc, argv)
133   int     argc;
134   char    *argv[];
# Line 137 | Line 159 | char   *argv[];
159          cfname = argv[i];
160                                                  /* load variables */
161          loadvars(cfname);
162 +                                                /* check variables */
163 +        checkvalues();
164                                                  /* did we get DIRECTORY? */
165          checkdir();
166                                                  /* check status */
# Line 163 | Line 187 | char   *argv[];
187                  argv[i] = vval(NEXTANIM);       /* just change input file */
188                  if (!silent)
189                          printargs(argc, argv, stdout);
190 <                execvp(progname, argv);         /* pass to next */
191 <                quit(1);                        /* shouldn't return */
190 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
191 >                        fprintf(stderr, "%s: command not found\n", progname);
192 >                else
193 >                        execv(progname, argv);
194 >                quit(1);
195          }
196          quit(0);
197   userr:
# Line 175 | Line 202 | userr:
202  
203   getastat()                      /* check/set animation status */
204   {
205 <        char    buf[256];
205 >        char    sfname[256];
206          FILE    *fp;
207  
208 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
209 <        if ((fp = fopen(buf, "r")) == NULL) {
208 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
209 >        if ((fp = fopen(sfname, "r")) == NULL) {
210                  if (errno != ENOENT) {
211 <                        perror(buf);
211 >                        perror(sfname);
212                          return(-1);
213                  }
214                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 201 | Line 228 | getastat()                     /* check/set animation status */
228                  goto fmterr;
229          fclose(fp);
230          if (astat.pid != 0) {                   /* thinks it's still running */
231 <                gethostname(buf, sizeof(buf));
205 <                if (strcmp(buf, astat.host)) {
231 >                if (strcmp(myhostname(), astat.host)) {
232                          fprintf(stderr,
233                          "%s: process %d may still be running on host %s\n",
234                                          progname, astat.pid, astat.host);
# Line 215 | Line 241 | getastat()                     /* check/set animation status */
241                  }
242                  /* assume it is dead */
243          }
244 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
244 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
245                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
246                                  progname, astat.cfname);
247                  return(-1);
248          }
249 +                                                /* check control file mods. */
250 +        if (!nowarn && fdate(cfname) > fdate(sfname))
251 +                fprintf(stderr,
252 +                        "%s: warning - control file modified since last run\n",
253 +                                progname);
254   setours:                                        /* set our values */
255 <        gethostname(astat.host, sizeof(astat.host));
255 >        strcpy(astat.host, myhostname());
256          astat.pid = getpid();
257          strcpy(astat.cfname, cfname);
258          return(0);
259   fmterr:
260          fprintf(stderr, "%s: format error in status file \"%s\"\n",
261 <                        progname, buf);
261 >                        progname, sfname);
262          fclose(fp);
263          return(-1);
264   }
# Line 279 | Line 310 | checkdir()                     /* make sure we have our directory */
310  
311   setdefaults()                   /* set default values */
312   {
313 +        extern char     *atos();
314 +        int     decades;
315          char    buf[256];
316  
317          if (vdef(ANIMATE)) {
# Line 312 | Line 345 | setdefaults()                  /* set default values */
345                  quit(1);
346          }
347          if (!vdef(BASENAME)) {
348 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
348 >                decades = (int)log10((double)vint(END)) + 1;
349 >                if (decades < 3) decades = 3;
350 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
351                  vval(BASENAME) = savqstr(buf);
352                  vdef(BASENAME)++;
353          }
# Line 344 | Line 379 | setdefaults()                  /* set default values */
379                  vval(DISKSPACE) = "100";
380                  vdef(DISKSPACE)++;
381          }
382 +        if (!vdef(RSH)) {
383 +                vval(RSH) = REMSH;
384 +                vdef(RSH)++;
385 +        }
386 +                                /* locate remote shell program */
387 +        atos(buf, sizeof(buf), vval(RSH));
388 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
389 +                remsh = savqstr(remsh);
390 +        else
391 +                remsh = vval(RSH);      /* will generate error if used */
392 +
393                                  /* append rendering options */
394          if (vdef(RENDER))
395                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
# Line 406 | Line 452 | sethosts()                     /* set up process servers */
452   }
453  
454  
455 < getradfile(rfname)              /* run rad and get needed variables */
456 < char    *rfname;
455 > getradfile(rfargs)              /* run rad and get needed variables */
456 > char    *rfargs;
457   {
458          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
459          char    combuf[256];
460          register int    i;
461          register char   *cp;
462 +        char    *pippt;
463                                          /* create rad command */
464          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
465          sprintf(combuf,
466          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
467 <                        rfname, rendopt+2);
467 >                        rfargs, rendopt+2);
468          cp = combuf;
469 <        while (*cp) cp++;               /* match unset variables */
469 >        while (*cp) {
470 >                if (*cp == '|') pippt = cp;
471 >                cp++;
472 >        }                               /* match unset variables */
473          for (i = 0; mvar[i] >= 0; i++)
474                  if (!vdef(mvar[i])) {
475                          *cp++ = '|';
476                          strcpy(cp, vnam(mvar[i]));
477                          while (*cp) cp++;
478 +                        pippt = NULL;
479                  }
480 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
481 <        cp += 11;                       /* point to file name */
482 <        if (system(combuf)) {
483 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
484 <                                progname, rfname);
434 <                quit(1);
480 >        if (pippt != NULL)
481 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
482 >        else {
483 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
484 >                cp += 11;               /* point to file name */
485          }
486 <        loadvars(cp);                   /* load variables and remove file */
487 <        unlink(cp);
486 >        system(combuf);                 /* ignore exit code */
487 >        if (pippt == NULL) {            /* load variables and remove file */
488 >                loadvars(cp);
489 >                unlink(cp);
490 >        }
491   }
492  
493  
# Line 449 | Line 502 | animate()                      /* run animation */
502          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
503          mult = vflt(OVERSAMP);
504          if (i == 3) {
505 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
505 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
506                                  (int)(mult*yres), pa);
507 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
507 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
508          } else if (i) {
509                  if (i == 1) yres = xres;
510                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 468 | Line 521 | animate()                      /* run animation */
521                                                  progname, vnam(INTERP));
522                          vval(INTERP) = "0";
523                  }
524 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
524 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
525                          if (!nowarn)
526                                  fprintf(stderr,
527                                          "%s: resetting %s=0 for animation\n",
# Line 478 | Line 531 | animate()                      /* run animation */
531          }
532                                          /* figure # frames per batch */
533          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
534 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
535 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
534 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
535 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
536          d2 = xres*yres*4;                       /* space for final picture */
537          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
538          if (frames_batch < i+2) {
# Line 487 | Line 540 | animate()                      /* run animation */
540                                  progname);
541                  quit(1);
542          }
543 +                                        /* initialize archive argument list */
544 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
545 +        arcnext = arcfirst = arcargs + i;
546                                          /* initialize status file */
547          if (astat.rnext == 0)
548                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 571 | Line 627 | filterframes()                         /* catch up with filtering */
627          if (astat.tnext < astat.fnext)  /* other work to do first */
628                  return;
629                                          /* filter each view */
630 <        for (i = astat.fnext; i < astat.rnext; i++) {
631 <                if ((vp = getview(i)) == NULL) {        /* get view i */
632 <                        fprintf(stderr,
577 <                        "%s: unexpected error reading view for frame %d\n",
578 <                                        progname, i);
579 <                        quit(1);
580 <                }
581 <                dofilt(i, vp, getexp(i), 0);            /* filter frame */
582 <        }
630 >        for (i = astat.fnext; i < astat.rnext; i++)
631 >                dofilt(i, 0);
632 >
633          bwait(0);                       /* wait for filter processes */
634 <        archive(astat.fnext, i-1);      /* archive originals */
634 >        archive();                      /* archive originals */
635          astat.fnext = i;                /* update status */
636          putastat();
637   }
# Line 589 | Line 639 | filterframes()                         /* catch up with filtering */
639  
640   transferframes()                        /* catch up with picture transfers */
641   {
642 <        char    combuf[10240];
642 >        char    combuf[10240], *fbase;
643          register char   *cp;
644          register int    i;
645  
# Line 600 | Line 650 | transferframes()                       /* catch up with picture transfers
650                  putastat();             /* update status */
651                  return;
652          }
653 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
654 <        cp = combuf + strlen(combuf);
653 >        strcpy(combuf, "cd ");          /* start transfer command */
654 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
655 >        if (*cp) {
656 >                while (*++cp) ;
657 >                *cp++ = ';'; *cp++ = ' ';
658 >        } else
659 >                cp = combuf;
660 >        strcpy(cp, vval(TRANSFER));
661 >        while (*cp) cp++;
662                                          /* make argument list */
663          for (i = astat.tnext; i < astat.fnext; i++) {
664                  *cp++ = ' ';
665 <                sprintf(cp, vval(BASENAME), i);
665 >                sprintf(cp, fbase, i);
666                  while (*cp) cp++;
667                  strcpy(cp, ".pic");
668                  cp += 4;
# Line 642 | Line 699 | walkwait(first, last, vfn)             /* walk-through frames */
699   int     first, last;
700   char    *vfn;
701   {
702 +        double  blurf;
703 +        int     nblur = getblur(&blurf);
704          char    combuf[2048];
705 <        char    *inspoint;
705 >        register char   *inspoint;
706          register int    i;
707  
708          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 654 | Line 713 | char   *vfn;
713                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
714                          }
715                                          /* create command */
716 <        sprintf(combuf, "rpict%s -w0", rendopt);
717 <        if (vint(INTERP) || atoi(vval(MBLUR)))
718 <                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
719 <        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
716 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
717 >                        viewopt(getview(first>1 ? first-1 : 1)));
718 >        inspoint = combuf;
719 >        while (*inspoint) inspoint++;
720 >        if (nblur) {
721 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
722 >                while (*inspoint) inspoint++;
723 >        }
724 >        if (nblur > 1 || vint(INTERP)) {
725 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
726 >                while (*inspoint) inspoint++;
727 >        }
728 >        sprintf(inspoint, " -o %s.unf %s -S %d",
729                          vval(BASENAME), rresopt, first);
730 <        inspoint = combuf + strlen(combuf);
730 >        while (*inspoint) inspoint++;
731          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
732                                          /* run in parallel */
733 <        if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) {
733 >        i = (last-first+1)/(vint(INTERP)+1);
734 >        if (i < 1) i = 1;
735 >        if (pruncom(combuf, inspoint, i)) {
736                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
737                                  progname, first, last);
738                  quit(1);
# Line 683 | Line 753 | int    frame;
753   {
754          static int      *rfrm;          /* list of recovered frames */
755          static int      nrfrms = 0;
756 +        double  blurf;
757 +        int     nblur = getblur(&blurf);
758          char    combuf[2048];
759          char    fname[128];
760          register char   *cp;
# Line 698 | Line 770 | int    frame;
770                                  vval(ANIMATE), frame, rendopt);
771          else
772                  sprintf(combuf, "rpict%s -w0", rendopt);
773 <        cp = combuf + strlen(combuf);
774 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
773 >        cp = combuf;
774 >        while (*cp) cp++;
775 >        if (nblur) {
776 >                sprintf(cp, " -pm %.3f", blurf/nblur);
777 >                while (*cp) cp++;
778 >        }
779 >        if (nblur > 1 || vint(INTERP)) {
780                  sprintf(cp, " -z %s.zbf", fname);
781                  while (*cp) cp++;
782          }
# Line 713 | Line 790 | int    frame;
790                  return(1);
791                                          /* add frame to recovered list */
792          if (nrfrms)
793 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
793 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
794          else
795                  rfrm = (int *)malloc(sizeof(int));
796          if (rfrm == NULL) {
# Line 729 | Line 806 | int
806   frecover(frame)                         /* recover filtered frame */
807   int     frame;
808   {
809 <        VIEW    *vp;
733 <        char    *ex;
734 <
735 <        vp = getview(frame);
736 <        ex = getexp(frame);
737 <        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
809 >        if (dofilt(frame, 2) && dofilt(frame, 1))
810                  return(1);
811          return(0);
812   }
813  
814  
815 < archive(first, last)                    /* archive and remove renderings */
744 < int     first, last;
815 > archive()                       /* archive and remove renderings */
816   {
817   #define RMCOML  (sizeof(rmcom)-1)
818          static char     rmcom[] = "rm -f";
819 <        int     offset = RMCOML;
820 <        char    combuf[10240];
821 <        struct stat     stb;
751 <        register char   *cp;
752 <        register int    i;
819 >        char    basedir[128];
820 >        int     dlen, alen;
821 >        register int    j;
822  
823 <        if (noaction)
824 <                return;
825 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
826 <                offset = strlen(vval(ARCHIVE));
758 <        cp = combuf + offset;
759 <        *cp++ = ' ';                            /* make argument list */
760 <        for (i = first; i <= last; i++) {
761 <                sprintf(cp, vval(BASENAME), i);
762 <                strcat(cp, ".unf");
763 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
764 <                        while (*cp) cp++;
765 <                        *cp++ = ' ';
766 <                        sprintf(cp, vval(BASENAME), i);
767 <                        strcat(cp, ".zbf");
768 <                        if (access(cp, F_OK) == 0) {            /* exists? */
769 <                                while (*cp) cp++;
770 <                                *cp++ = ' ';
771 <                        }
772 <                }
773 <        }
774 <        *--cp = '\0';
775 <        if (cp <= combuf + offset)              /* no files? */
776 <                return;
823 >        if (arcnext == arcfirst)
824 >                return;                         /* nothing to do */
825 >        dirfile(basedir, vval(BASENAME));
826 >        dlen = strlen(basedir);
827          if (vdef(ARCHIVE)) {                    /* run archive command */
828 <                i = strlen(vval(ARCHIVE));
829 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
830 <                if (runcom(combuf+offset-i)) {
831 <                        fprintf(stderr,
832 <                "%s: error running archive command on frames %d through %d\n",
833 <                                        progname, first, last);
828 >                alen = strlen(vval(ARCHIVE));
829 >                if (dlen) {
830 >                        j = alen + dlen + 5;
831 >                        strncpy(arcfirst-j, "cd ", 3);
832 >                        strncpy(arcfirst-j+3, basedir, dlen);
833 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
834 >                } else
835 >                        j = alen;
836 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
837 >                if (runcom(arcfirst-j)) {
838 >                        fprintf(stderr, "%s: error running archive command\n",
839 >                                        progname);
840                          quit(1);
841                  }
842          }
843 +        if (dlen) {
844 +                j = RMCOML + dlen + 5;
845 +                strncpy(arcfirst-j, "cd ", 3);
846 +                strncpy(arcfirst-j+3, basedir, dlen);
847 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
848 +        } else
849 +                j = RMCOML;
850                                                  /* run remove command */
851 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
852 <        runcom(combuf+offset-RMCOML);
851 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
852 >        runcom(arcfirst-j);
853 >        arcnext = arcfirst;                     /* reset argument list */
854   #undef RMCOML
855   }
856  
857  
858   int
859 < dofilt(frame, vp, ep, rvr)                      /* filter frame */
859 > dofilt(frame, rvr)                              /* filter frame */
860   int     frame;
797 VIEW    *vp;
798 char    *ep;
861   int     rvr;
862   {
863          extern int      frecover();
864 <        char    fnbefore[128], fnafter[128];
865 <        char    combuf[1024], fname[128];
866 <        int     usepinterp, usepfilt;
864 >        static int      iter = 0;
865 >        double  blurf;
866 >        int     nblur = getblur(&blurf);
867 >        VIEW    *vp = getview(frame);
868 >        char    *ep = getexp(frame);
869 >        char    fnbefore[128], fnafter[128], *fbase;
870 >        char    combuf[1024], fname0[128], fname1[128];
871 >        int     usepinterp, usepfilt, nora_rgbe;
872          int     frseq[2];
873                                                  /* check what is needed */
874 <        usepinterp = atoi(vval(MBLUR));
875 <        usepfilt = pfiltalways | ep==NULL;
874 >        if (vp == NULL) {
875 >                 fprintf(stderr,
876 >                        "%s: unexpected error reading view for frame %d\n",
877 >                                          progname, frame);
878 >                quit(1);
879 >        }
880 >        if (ep == NULL) {
881 >                 fprintf(stderr,
882 >                        "%s: unexpected error reading exposure for frame %d\n",
883 >                                          progname, frame);
884 >                quit(1);
885 >        }
886 >        usepinterp = (nblur > 1);
887 >        usepfilt = pfiltalways | (ep==NULL);
888 >        if (ep != NULL && !strcmp(ep, "1"))
889 >                ep = "+0";
890 >        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
891 >                        *ep != '+' || *ep != '-' || !isint(ep);
892                                                  /* compute rendered views */
893          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
894          frseq[1] = frseq[0] + vint(INTERP) + 1;
895 +        fbase = dirfile(NULL, vval(BASENAME));
896          if (frseq[1] > vint(END))
897                  frseq[1] = vint(END);
898          if (frseq[1] == frame) {                        /* pfilt only */
899                  frseq[0] = frseq[1];
900                  usepinterp = 0;                 /* update what's needed */
901 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
902 <        } else if (frseq[0] == frame) {         /* no interpolation */
903 <                                                /* update what's needed */
904 <                if (!usepinterp)
905 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
901 >                usepfilt |= nora_rgbe;
902 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
903 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
904 >                        *arcnext++ = ' ';
905 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
906 >                        while (*arcnext) arcnext++;
907 >                        strcpy(arcnext, ".unf");
908 >                        arcnext += 4;
909 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
910 >                                *arcnext++ = ' ';
911 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
912 >                                while (*arcnext) arcnext++;
913 >                                strcpy(arcnext, ".zbf");
914 >                                arcnext += 4;
915 >                        }
916 >                }
917 >                if (!usepinterp)                /* update what's needed */
918 >                        usepfilt |= nora_rgbe;
919          } else                                  /* interpolation needed */
920                  usepinterp++;
921          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 831 | Line 928 | int    rvr;
928          if (usepinterp) {                       /* using pinterp */
929                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
930                          return(1);
931 <                if (atoi(vval(MBLUR))) {
932 <                        FILE    *fp;            /* motion blurring */
933 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
934 <                        if (access(fname, F_OK) == 0)
935 <                                sleep(10);
936 <                        if ((fp = fopen(fname, "w")) == NULL) {
937 <                                perror(fname); quit(1);
938 <                        }
939 <                        fputs(VIEWSTR, fp);
940 <                        fprintview(vp, fp);
941 <                        putc('\n', fp); fclose(fp);
942 <                        if ((vp = getview(frame+1)) == NULL) {
943 <                                fprintf(stderr,
931 >                if (nblur > 1) {                /* with pmblur */
932 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
933 >                                        'a'+(iter%26));
934 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
935 >                                        'a'+(iter%26));
936 >                        if (!noaction) {
937 >                                FILE    *fp;            /* motion blurring */
938 >                                if ((fp = fopen(fname0, "w")) == NULL) {
939 >                                        perror(fname0); quit(1);
940 >                                }
941 >                                fputs(VIEWSTR, fp);
942 >                                fprintview(vp, fp);
943 >                                putc('\n', fp); fclose(fp);
944 >                                if ((vp = getview(frame+1)) == NULL) {
945 >                                        fprintf(stderr,
946                          "%s: unexpected error reading view for frame %d\n",
947 <                                                progname, frame+1);
948 <                                quit(1);
947 >                                                        progname, frame+1);
948 >                                        quit(1);
949 >                                }
950 >                                if ((fp = fopen(fname1, "w")) == NULL) {
951 >                                        perror(fname1); quit(1);
952 >                                }
953 >                                fputs(VIEWSTR, fp);
954 >                                fprintview(vp, fp);
955 >                                putc('\n', fp); fclose(fp);
956                          }
851                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
852                        if ((fp = fopen(fname, "w")) == NULL) {
853                                perror(fname); quit(1);
854                        }
855                        fputs(VIEWSTR, fp);
856                        fprintview(vp, fp);
857                        putc('\n', fp); fclose(fp);
957                          sprintf(combuf,
958 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
959 <                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
960 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
961 <                                        vval(DIRECTORY), vval(DIRECTORY),
863 <                                        vval(DIRECTORY), vval(DIRECTORY));
958 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
959 >                                        blurf, nblur,
960 >                                        fname0, fname1, fname0, fname1);
961 >                        iter++;
962                  } else                          /* no blurring */
963                          strcpy(combuf, "pinterp");
964                  strcat(combuf, viewopt(vp));
965                  if (vbool(RTRACE))
966                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
967 <                                        rendopt, vval(OCTREE));
967 >                                        rendopt+1, vval(OCTREE));
968                  if (vdef(PINTERP))
969                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
970                  if (usepfilt)
971                          sprintf(combuf+strlen(combuf), " %s", rresopt);
972                  else
973 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
973 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
974                                          fresopt, ep);
975                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
976                                  fnbefore, fnbefore);
# Line 907 | Line 1005 | int    rvr;
1005          } else {                                /* else just check it */
1006                  if (rvr == 2)
1007                          return(1);
1008 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
1008 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1009          }
1010                                                  /* output file name */
1011 <        sprintf(fname, vval(BASENAME), frame);
1012 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
1011 >        sprintf(fname0, vval(BASENAME), frame);
1012 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1013          if (rvr)                                /* in recovery */
1014                  return(runcom(combuf));
1015          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 933 | Line 1031 | int    n;
1031                          fclose(viewfp);
1032                          viewfp = NULL;
1033                          viewnum = 0;
1034 <                        copystruct(&curview, &stdview);
1034 >                        curview = stdview;
1035                  }
1036                  return(NULL);
1037          }
1038 <        if (viewfp == NULL) {           /* open file */
1038 >        if (viewfp == NULL) {                   /* open file */
1039                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1040                          perror(vval(VIEWFILE));
1041                          quit(1);
1042                  }
1043 <        } else if (n < viewnum) {       /* rewind file */
1043 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1044 >                if (viewnum == 1 && feof(viewfp))
1045 >                        return(&curview);               /* just one view */
1046                  if (fseek(viewfp, 0L, 0) == EOF) {
1047                          perror(vval(VIEWFILE));
1048                          quit(1);
1049                  }
1050 <                copystruct(&curview, &stdview);
1050 >                curview = stdview;
1051                  viewnum = 0;
1052          }
1053 +        if (n < 0) {                            /* get next view */
1054 +                register int    c = getc(viewfp);
1055 +                if (c == EOF)
1056 +                        return((VIEW *)NULL);           /* that's it */
1057 +                ungetc(c, viewfp);
1058 +                n = viewnum + 1;
1059 +        }
1060          while (n > viewnum) {           /* scan to desired view */
1061                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1062 <                        return(NULL);
1062 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1063                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1064                          viewnum++;
1065          }
# Line 963 | Line 1070 | int    n;
1070   int
1071   countviews()                    /* count views in view file */
1072   {
1073 <        register int    n = 0;
1073 >        int     n;
1074  
1075 <        while (getview(n+1) != NULL)
1075 >        if (getview(n=1) == NULL)
1076 >                return(0);
1077 >        while (getview(-1) != NULL)
1078                  n++;
1079          return(n);
1080   }
# Line 985 | Line 1094 | int    n;
1094          if (n == 0) {                           /* signal to close file */
1095                  if (expfp != NULL) {
1096                          fclose(expfp);
1097 +                        free((void *)exppos);
1098                          expfp = NULL;
1099                  }
1100                  return(NULL);
1101 <        }
1101 >        } else if (n > vint(END))               /* request past end (error?) */
1102 >                return(NULL);
1103          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1104                  return(NULL);
1105          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1026 | Line 1137 | int    n;
1137                  }
1138                  curfrm++;
1139                  cp = fskip(expval);                     /* check format */
1140 <                if (cp == NULL || *cp != '\n') {
1140 >                if (cp != NULL)
1141 >                        while (isspace(*cp))
1142 >                                *cp++ = '\0';
1143 >                if (cp == NULL || *cp) {
1144                          fprintf(stderr,
1145                                  "%s: exposure format error on line %d\n",
1146                                          vval(EXPOSURE), curfrm);
1147                          quit(1);
1148                  }
1035                *cp = '\0';
1149          }
1150          return(expval);                         /* return value */
1151   }
# Line 1062 | Line 1175 | int    pn;
1175   int     status;
1176   {
1177          register PROC   *pp;
1178 +        register struct pslot   *psl;
1179  
1180          pp = ps->proc + pn;
1181          if (pp->elen) {                 /* pass errors */
# Line 1073 | Line 1187 | int    status;
1187                  if (ps->hostname[0])
1188                          status = 1;     /* because rsh doesn't return status */
1189          }
1190 +        lastpserver = NULL;
1191 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1192 +        if (psl->pid) {
1193 +                if (status) {
1194 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1195 +                                status = (*psl->rcvf)(psl->fout);
1196 +                        if (status) {
1197 +                                fprintf(stderr,
1198 +                                        "%s: error rendering frame %d\n",
1199 +                                                progname, psl->fout);
1200 +                                quit(1);
1201 +                        }
1202 +                        lastpserver = ps;
1203 +                }
1204 +                psl->pid = 0;                   /* free process slot */
1205 +        } else if (status)
1206 +                lastpserver = ps;
1207          freestr(pp->com);               /* free command string */
1077        lastpid = pp->pid;              /* record PID for bwait() */
1078        lastpserver = ps;               /* record server for serverdown() */
1208          return(status);
1209   }
1210  
# Line 1083 | Line 1212 | int    status;
1212   int
1213   serverdown()                    /* check status of last process server */
1214   {
1215 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1216 +                return(0);
1217          if (pserverOK(lastpserver))     /* server still up? */
1218                  return(0);
1219          delpserver(lastpserver);        /* else delete it */
# Line 1109 | Line 1240 | int    (*rf)();
1240                          printf("\t%s\n", com);  /* echo command */
1241                  return(0);
1242          }
1243 <                                        /* else start it when we can */
1244 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1243 >        com = savestr(com);             /* else start it when we can */
1244 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1245                  bwait(1);
1246          if (!silent) {                          /* echo command */
1247                  PSERVER *ps;
# Line 1132 | Line 1263 | bwait(ncoms)                           /* wait for batch job(s) to finish */
1263   int     ncoms;
1264   {
1265          int     status;
1135        register struct pslot   *psl;
1266  
1267          if (noaction)
1268                  return;
1269          while ((status = wait4job(NULL, -1)) != -1) {
1270 <                psl = findpslot(lastpid);
1271 <                if (status) {           /* attempt recovery */
1272 <                        serverdown();   /* check server */
1143 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1144 <                                fprintf(stderr,
1145 <                                        "%s: error rendering frame %d\n",
1146 <                                                progname, psl->fout);
1147 <                                quit(1);
1148 <                        }
1149 <                }
1150 <                psl->pid = 0;           /* free process slot */
1151 <                if (!--ncoms)
1152 <                        return;         /* done enough */
1270 >                serverdown();           /* update server status */
1271 >                if (--ncoms == 0)
1272 >                        break;          /* done enough */
1273          }
1274   }
1275  
# Line 1161 | Line 1281 | int    maxcopies;
1281   {
1282          int     retstatus = 0;
1283          int     hostcopies;
1284 <        char    com1buf[10240], *com1, *endcom1;
1284 >        char    buf[10240], *com1, *s;
1285          int     status;
1286 +        int     pfd;
1287 +        register int    n;
1288          register PSERVER        *ps;
1289  
1290          if (!silent)
1291 <                printf("\t%s &\n", com);        /* echo command */
1291 >                printf("\t%s\n", com);  /* echo command */
1292          if (noaction)
1293                  return(0);
1294          fflush(stdout);
# Line 1174 | Line 1296 | int    maxcopies;
1296          for (ps = pslist; ps != NULL; ps = ps->next) {
1297                  hostcopies = 0;
1298                  if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1299 <                        strcpy(com1=com1buf, com);      /* build -PP command */
1299 >                        strcpy(com1=buf, com);  /* build -PP command */
1300                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1301                                          vval(DIRECTORY), phostname(ps));
1302 +                        unlink(com1+(ppins-com)+5);
1303                          strcat(com1, ppins);
1304 <                        endcom1 = com1 + strlen(com1);
1182 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1183 <                                        vval(DIRECTORY), phostname(ps));
1184 <                } else {
1304 >                } else
1305                          com1 = com;
1306 <                        endcom1 = NULL;
1306 >                while (maxcopies > 0) {
1307 >                        s = savestr(com1);
1308 >                        if (startjob(ps, s, donecom) != -1) {
1309 >                                sleep(20);
1310 >                                hostcopies++;
1311 >                                maxcopies--;
1312 >                        } else {
1313 >                                freestr(s);
1314 >                                break;
1315 >                        }
1316                  }
1188                while (maxcopies > 0 &&
1189                                startjob(ps, savestr(com1), donecom) != -1) {
1190                        sleep(10);
1191                        hostcopies++;
1192                        maxcopies--;
1193                        if (endcom1 != NULL)
1194                                *endcom1 = '\0';
1195                }
1317                  if (!silent && hostcopies) {
1318                          if (hostcopies > 1)
1319                                  printf("\t%d duplicate processes", hostcopies);
# Line 1204 | Line 1325 | int    maxcopies;
1325          }
1326                                          /* wait for jobs to finish */
1327          while ((status = wait4job(NULL, -1)) != -1)
1328 <                if (status)
1329 <                        retstatus += !serverdown();     /* check server */
1328 >                retstatus += status && !serverdown();
1329 >                                        /* terminate parallel rpict's */
1330 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1331 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1332 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1333 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1334 >                        buf[n] = '\0';
1335 >                        close(pfd);
1336 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1337 >                                ;
1338 >                                                                /* terminate */
1339 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1340 >                        wait4job(ps, startjob(ps, buf, NULL));
1341 >                }
1342 >        }
1343          return(retstatus);
1344   }
1345  
# Line 1226 | Line 1360 | rmfile(fn)                     /* remove a file */
1360   char    *fn;
1361   {
1362          if (!silent)
1363 < #ifdef MSDOS
1363 > #ifdef _WIN32
1364                  printf("\tdel %s\n", fn);
1365   #else
1366                  printf("\trm -f %s\n", fn);
# Line 1243 | Line 1377 | int    vc;
1377          fprintf(stderr, "%s: bad value for variable '%s'\n",
1378                          progname, vnam(vc));
1379          quit(1);
1380 + }
1381 +
1382 +
1383 + char *
1384 + dirfile(df, path)               /* separate path into directory and file */
1385 + char    *df;
1386 + register char   *path;
1387 + {
1388 +        register int    i;
1389 +        int     psep;
1390 +
1391 +        for (i = 0, psep = -1; path[i]; i++)
1392 +                if (path[i] == '/')
1393 +                        psep = i;
1394 +        if (df != NULL) {
1395 +                if (psep == 0) {
1396 +                        df[0] = '/';
1397 +                        df[1] = '\0';
1398 +                } else if (psep > 0) {
1399 +                        strncpy(df, path, psep);
1400 +                        df[psep] = '\0';
1401 +                } else
1402 +                        df[0] = '\0';
1403 +        }
1404 +        return(path+psep+1);
1405 + }
1406 +
1407 +
1408 + int
1409 + getblur(double *bf)             /* get # blur samples (and fraction) */
1410 + {
1411 +        double  blurf;
1412 +        int     nblur;
1413 +        char    *s;
1414 +
1415 +        if (!vdef(MBLUR)) {
1416 +                if (bf != NULL)
1417 +                        *bf = 0.0;
1418 +                return(0);
1419 +        }
1420 +        blurf = atof(vval(MBLUR));
1421 +        if (blurf < 0.0)
1422 +                blurf = 0.0;
1423 +        if (bf != NULL)
1424 +                *bf = blurf;
1425 +        if (blurf <= FTINY)
1426 +                return(0);
1427 +        s = sskip(vval(MBLUR));
1428 +        if (!*s)
1429 +                return(DEF_NBLUR);
1430 +        nblur = atoi(s);
1431 +        if (nblur <= 0)
1432 +                return(1);
1433 +        return(nblur);
1434   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines