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.4 by greg, Mon Jan 22 17:19:37 1996 UTC vs.
Revision 2.34 by greg, Tue May 27 15:30:04 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 "copyright.h"
17 +
18   #include "standard.h"
19   #include <ctype.h>
13 #include <sys/types.h>
20   #include <sys/stat.h>
21   #include "view.h"
22   #include "vars.h"
23   #include "netproc.h"
24 <                                /* input variables */
25 < #define HOST            0               /* rendering host machine */
26 < #define RENDER          1               /* rendering options */
27 < #define PFILT           2               /* pfilt options */
28 < #define PINTERP         3               /* pinterp options */
29 < #define OCTREE          4               /* octree file name */
30 < #define DIRECTORY       5               /* working (sub)directory */
31 < #define BASENAME        6               /* output image base name */
32 < #define VIEWFILE        7               /* animation frame views */
33 < #define START           8               /* starting frame number */
34 < #define END             9               /* ending frame number */
35 < #define RIF             10              /* rad input file */
36 < #define NEXTANIM        11              /* next animation file */
37 < #define ANIMATE         12              /* animation command */
38 < #define TRANSFER        13              /* frame transfer command */
39 < #define ARCHIVE         14              /* archiving command */
40 < #define INTERP          15              /* # frames to interpolate */
41 < #define OVERSAMP        16              /* # times to oversample image */
42 < #define MBLUR           17              /* samples for motion blur */
43 < #define RTRACE          18              /* use rtrace with pinterp? */
44 < #define DISKSPACE       19              /* how much disk space to use */
45 < #define RESOLUTION      20              /* desired final resolution */
46 < #define EXPOSURE        21              /* how to compute exposure */
24 >                                /* default blur samples */
25 > #ifndef DEF_NBLUR
26 > #define DEF_NBLUR       5
27 > #endif
28 >                                /* default remote shell */
29 > #ifdef _AUX_SOURCE
30 > #define REMSH           "remsh"
31 > #else
32 > #define REMSH           "rsh"
33 > #endif
34 >                                /* input variables (alphabetical by name) */
35 > #define ANIMATE         0               /* animation command */
36 > #define ARCHIVE         1               /* archiving command */
37 > #define BASENAME        2               /* output image base name */
38 > #define DIRECTORY       3               /* working (sub)directory */
39 > #define DISKSPACE       4               /* how much disk space to use */
40 > #define END             5               /* ending frame number */
41 > #define EXPOSURE        6               /* how to compute exposure */
42 > #define HOST            7               /* rendering host machine */
43 > #define INTERP          8               /* # frames to interpolate */
44 > #define MBLUR           9               /* motion blur parameters */
45 > #define NEXTANIM        10              /* next animation file */
46 > #define OCTREE          11              /* octree file name */
47 > #define OVERSAMP        12              /* # times to oversample image */
48 > #define PFILT           13              /* pfilt options */
49 > #define PINTERP         14              /* pinterp options */
50 > #define RENDER          15              /* rendering options */
51 > #define RESOLUTION      16              /* desired final resolution */
52 > #define RIF             17              /* rad input file */
53 > #define RSH             18              /* remote shell script or program */
54 > #define RTRACE          19              /* use rtrace with pinterp? */
55 > #define START           20              /* starting frame number */
56 > #define TRANSFER        21              /* frame transfer command */
57 > #define VIEWFILE        22              /* animation frame views */
58  
59 < int     NVARS = 22;             /* total number of variables */
59 > int     NVARS = 23;             /* total number of variables */
60  
61   VARIABLE        vv[] = {                /* variable-value pairs */
62 +        {"ANIMATE",     2,      0,      NULL,   onevalue},
63 +        {"ARCHIVE",     2,      0,      NULL,   onevalue},
64 +        {"BASENAME",    3,      0,      NULL,   onevalue},
65 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
66 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
67 +        {"END",         2,      0,      NULL,   intvalue},
68 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
69          {"host",        4,      0,      NULL,   NULL},
70 <        {"render",      3,      0,      NULL,   catvalues},
70 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
71 >        {"MBLUR",       2,      0,      NULL,   onevalue},
72 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
73 >        {"OCTREE",      3,      0,      NULL,   onevalue},
74 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
75          {"pfilt",       2,      0,      NULL,   catvalues},
76          {"pinterp",     2,      0,      NULL,   catvalues},
77 <        {"OCTREE",      3,      0,      NULL,   onevalue},
78 <        {"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},
77 >        {"render",      3,      0,      NULL,   catvalues},
78 >        {"RESOLUTION",  3,      0,      NULL,   onevalue},
79          {"RIF",         3,      0,      NULL,   onevalue},
80 <        {"NEXTANIM",    3,      0,      NULL,   onevalue},
57 <        {"ANIMATE",     2,      0,      NULL,   onevalue},
58 <        {"TRANSFER",    2,      0,      NULL,   onevalue},
59 <        {"ARCHIVE",     2,      0,      NULL,   onevalue},
60 <        {"INTERP",      3,      0,      NULL,   intvalue},
61 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
62 <        {"MBLUR",       2,      0,      NULL,   onevalue},
80 >        {"RSH",         3,      0,      NULL,   onevalue},
81          {"RTRACE",      2,      0,      NULL,   boolvalue},
82 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
83 <        {"RESOLUTION",  3,      0,      NULL,   onevalue},
84 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
82 >        {"START",       2,      0,      NULL,   intvalue},
83 >        {"TRANSFER",    2,      0,      NULL,   onevalue},
84 >        {"VIEWFILE",    2,      0,      NULL,   onevalue},
85   };
86  
87   #define SFNAME  "STATUS"                /* status file name */
# Line 84 | Line 102 | int    nowarn = 0;             /* turn warnings off? */
102   int     silent = 0;             /* silent mode? */
103   int     noaction = 0;           /* take no action? */
104  
105 < char    rendopt[2048] = "";     /* rendering options */
105 > char    *remsh;                 /* remote shell program/script */
106 > char    rendopt[2048];          /* rendering options */
107   char    rresopt[32];            /* rendering resolution options */
108   char    fresopt[32];            /* filter resolution options */
109   int     pfiltalways;            /* always use pfilt? */
110  
111 + char    arcargs[10240];         /* files to archive */
112 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
113 +
114   struct pslot {
115          int     pid;                    /* process ID (0 if empty) */
116          int     fout;                   /* output frame number */
# Line 96 | Line 118 | struct pslot {
118   }       *pslot;                 /* process slots */
119   int     npslots;                /* number of process slots */
120  
99 int     lastpid;                /* ID of last completed background process */
100 PSERVER *lastpserver;           /* last process server used */
101
121   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
122  
123   struct pslot    *findpslot();
124  
125 + PSERVER *lastpserver;           /* last process server with error */
126 +
127   VIEW    *getview();
128 < char    *getexp();
128 > char    *getexp(), *dirfile();
129 > int     getblur();
130  
131 + extern time_t   time();
132  
133 +
134   main(argc, argv)
135   int     argc;
136   char    *argv[];
# Line 137 | Line 161 | char   *argv[];
161          cfname = argv[i];
162                                                  /* load variables */
163          loadvars(cfname);
164 +                                                /* check variables */
165 +        checkvalues();
166                                                  /* did we get DIRECTORY? */
167          checkdir();
168                                                  /* check status */
# Line 163 | Line 189 | char   *argv[];
189                  argv[i] = vval(NEXTANIM);       /* just change input file */
190                  if (!silent)
191                          printargs(argc, argv, stdout);
192 <                execvp(progname, argv);         /* pass to next */
193 <                quit(1);                        /* shouldn't return */
192 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
193 >                        fprintf(stderr, "%s: command not found\n", progname);
194 >                else
195 >                        execv(progname, argv);
196 >                quit(1);
197          }
198          quit(0);
199   userr:
# Line 175 | Line 204 | userr:
204  
205   getastat()                      /* check/set animation status */
206   {
207 <        char    buf[256];
207 >        char    sfname[256];
208          FILE    *fp;
209  
210 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
211 <        if ((fp = fopen(buf, "r")) == NULL) {
210 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
211 >        if ((fp = fopen(sfname, "r")) == NULL) {
212                  if (errno != ENOENT) {
213 <                        perror(buf);
213 >                        perror(sfname);
214                          return(-1);
215                  }
216                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 201 | Line 230 | getastat()                     /* check/set animation status */
230                  goto fmterr;
231          fclose(fp);
232          if (astat.pid != 0) {                   /* thinks it's still running */
233 <                gethostname(buf, sizeof(buf));
205 <                if (strcmp(buf, astat.host)) {
233 >                if (strcmp(myhostname(), astat.host)) {
234                          fprintf(stderr,
235                          "%s: process %d may still be running on host %s\n",
236                                          progname, astat.pid, astat.host);
# Line 215 | Line 243 | getastat()                     /* check/set animation status */
243                  }
244                  /* assume it is dead */
245          }
246 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
246 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
247                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
248                                  progname, astat.cfname);
249                  return(-1);
250          }
251 +                                                /* check control file mods. */
252 +        if (!nowarn && fdate(cfname) > fdate(sfname))
253 +                fprintf(stderr,
254 +                        "%s: warning - control file modified since last run\n",
255 +                                progname);
256   setours:                                        /* set our values */
257 <        gethostname(astat.host, sizeof(astat.host));
257 >        strcpy(astat.host, myhostname());
258          astat.pid = getpid();
259          strcpy(astat.cfname, cfname);
260          return(0);
261   fmterr:
262          fprintf(stderr, "%s: format error in status file \"%s\"\n",
263 <                        progname, buf);
263 >                        progname, sfname);
264          fclose(fp);
265          return(-1);
266   }
# Line 279 | Line 312 | checkdir()                     /* make sure we have our directory */
312  
313   setdefaults()                   /* set default values */
314   {
315 +        extern char     *atos();
316 +        int     decades;
317          char    buf[256];
318  
319          if (vdef(ANIMATE)) {
# Line 302 | Line 337 | setdefaults()                  /* set default values */
337                  vdef(START)++;
338          }
339          if (!vdef(END)) {
340 <                sprintf(buf, "%d", countviews());
340 >                sprintf(buf, "%d", countviews()+vint(START)-1);
341                  vval(END) = savqstr(buf);
342                  vdef(END)++;
343          }
344 +        if (vint(END) < vint(START)) {
345 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
346 +                                progname);
347 +                quit(1);
348 +        }
349          if (!vdef(BASENAME)) {
350 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
350 >                decades = (int)log10((double)vint(END)) + 1;
351 >                if (decades < 3) decades = 3;
352 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
353                  vval(BASENAME) = savqstr(buf);
354                  vdef(BASENAME)++;
355          }
# Line 339 | Line 381 | setdefaults()                  /* set default values */
381                  vval(DISKSPACE) = "100";
382                  vdef(DISKSPACE)++;
383          }
384 +        if (!vdef(RSH)) {
385 +                vval(RSH) = REMSH;
386 +                vdef(RSH)++;
387 +        }
388 +                                /* locate remote shell program */
389 +        atos(buf, sizeof(buf), vval(RSH));
390 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
391 +                remsh = savqstr(remsh);
392 +        else
393 +                remsh = vval(RSH);      /* will generate error if used */
394 +
395                                  /* append rendering options */
396          if (vdef(RENDER))
397                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
# Line 401 | Line 454 | sethosts()                     /* set up process servers */
454   }
455  
456  
457 < getradfile(rfname)              /* run rad and get needed variables */
458 < char    *rfname;
457 > getradfile(rfargs)              /* run rad and get needed variables */
458 > char    *rfargs;
459   {
460          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
461          char    combuf[256];
462          register int    i;
463          register char   *cp;
464 +        char    *pippt;
465                                          /* create rad command */
466          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
467          sprintf(combuf,
468          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
469 <                        rfname, rendopt+2);
469 >                        rfargs, rendopt+2);
470          cp = combuf;
471 <        while (*cp) cp++;               /* match unset variables */
471 >        while (*cp) {
472 >                if (*cp == '|') pippt = cp;
473 >                cp++;
474 >        }                               /* match unset variables */
475          for (i = 0; mvar[i] >= 0; i++)
476                  if (!vdef(mvar[i])) {
477                          *cp++ = '|';
478                          strcpy(cp, vnam(mvar[i]));
479                          while (*cp) cp++;
480 +                        pippt = NULL;
481                  }
482 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
483 <        cp += 11;                       /* point to file name */
484 <        if (system(combuf)) {
485 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
486 <                                progname, rfname);
429 <                quit(1);
482 >        if (pippt != NULL)
483 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
484 >        else {
485 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
486 >                cp += 11;               /* point to file name */
487          }
488 <        loadvars(cp);                   /* load variables and remove file */
489 <        unlink(cp);
488 >        system(combuf);                 /* ignore exit code */
489 >        if (pippt == NULL) {            /* load variables and remove file */
490 >                loadvars(cp);
491 >                unlink(cp);
492 >        }
493   }
494  
495  
# Line 444 | Line 504 | animate()                      /* run animation */
504          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
505          mult = vflt(OVERSAMP);
506          if (i == 3) {
507 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
507 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
508                                  (int)(mult*yres), pa);
509 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
509 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
510          } else if (i) {
511                  if (i == 1) yres = xres;
512                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 463 | Line 523 | animate()                      /* run animation */
523                                                  progname, vnam(INTERP));
524                          vval(INTERP) = "0";
525                  }
526 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
526 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
527                          if (!nowarn)
528                                  fprintf(stderr,
529                                          "%s: resetting %s=0 for animation\n",
# Line 473 | Line 533 | animate()                      /* run animation */
533          }
534                                          /* figure # frames per batch */
535          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
536 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
537 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
536 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
537 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
538          d2 = xres*yres*4;                       /* space for final picture */
539          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
540          if (frames_batch < i+2) {
# Line 482 | Line 542 | animate()                      /* run animation */
542                                  progname);
543                  quit(1);
544          }
545 +                                        /* initialize archive argument list */
546 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
547 +        arcnext = arcfirst = arcargs + i;
548                                          /* initialize status file */
549          if (astat.rnext == 0)
550                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 576 | Line 639 | filterframes()                         /* catch up with filtering */
639                  dofilt(i, vp, getexp(i), 0);            /* filter frame */
640          }
641          bwait(0);                       /* wait for filter processes */
642 <        archive(astat.fnext, i-1);      /* archive originals */
642 >        archive();                      /* archive originals */
643          astat.fnext = i;                /* update status */
644          putastat();
645   }
# Line 584 | Line 647 | filterframes()                         /* catch up with filtering */
647  
648   transferframes()                        /* catch up with picture transfers */
649   {
650 <        char    combuf[10240];
650 >        char    combuf[10240], *fbase;
651          register char   *cp;
652          register int    i;
653  
# Line 595 | Line 658 | transferframes()                       /* catch up with picture transfers
658                  putastat();             /* update status */
659                  return;
660          }
661 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
662 <        cp = combuf + strlen(combuf);
661 >        strcpy(combuf, "cd ");          /* start transfer command */
662 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
663 >        if (*cp) {
664 >                while (*++cp) ;
665 >                *cp++ = ';'; *cp++ = ' ';
666 >        } else
667 >                cp = combuf;
668 >        strcpy(cp, vval(TRANSFER));
669 >        while (*cp) cp++;
670                                          /* make argument list */
671          for (i = astat.tnext; i < astat.fnext; i++) {
672                  *cp++ = ' ';
673 <                sprintf(cp, vval(BASENAME), i);
673 >                sprintf(cp, fbase, i);
674                  while (*cp) cp++;
675                  strcpy(cp, ".pic");
676                  cp += 4;
# Line 637 | Line 707 | walkwait(first, last, vfn)             /* walk-through frames */
707   int     first, last;
708   char    *vfn;
709   {
710 +        double  blurf;
711 +        int     nblur = getblur(&blurf);
712          char    combuf[2048];
713 <        char    *inspoint;
713 >        register char   *inspoint;
714          register int    i;
715  
716          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 650 | Line 722 | char   *vfn;
722                          }
723                                          /* create command */
724          sprintf(combuf, "rpict%s -w0", rendopt);
725 <        if (vint(INTERP) || atoi(vval(MBLUR)))
726 <                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
727 <        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
725 >        inspoint = combuf;
726 >        while (*inspoint) inspoint++;
727 >        if (nblur) {
728 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
729 >                while (*inspoint) inspoint++;
730 >        }
731 >        if (nblur > 1 || vint(INTERP)) {
732 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
733 >                while (*inspoint) inspoint++;
734 >        }
735 >        sprintf(inspoint, " -o %s.unf %s -S %d",
736                          vval(BASENAME), rresopt, first);
737 <        inspoint = combuf + strlen(combuf);
737 >        while (*inspoint) inspoint++;
738          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
739                                          /* run in parallel */
740 <        if (pruncom(combuf, inspoint, (last-first+1)/(vint(INTERP)+1))) {
740 >        i = (last-first+1)/(vint(INTERP)+1);
741 >        if (i < 1) i = 1;
742 >        if (pruncom(combuf, inspoint, i)) {
743                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
744                                  progname, first, last);
745                  quit(1);
# Line 678 | Line 760 | int    frame;
760   {
761          static int      *rfrm;          /* list of recovered frames */
762          static int      nrfrms = 0;
763 +        double  blurf;
764 +        int     nblur = getblur(&blurf);
765          char    combuf[2048];
766          char    fname[128];
767          register char   *cp;
# Line 693 | Line 777 | int    frame;
777                                  vval(ANIMATE), frame, rendopt);
778          else
779                  sprintf(combuf, "rpict%s -w0", rendopt);
780 <        cp = combuf + strlen(combuf);
781 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
780 >        cp = combuf;
781 >        while (*cp) cp++;
782 >        if (nblur) {
783 >                sprintf(cp, " -pm %.3f", blurf/nblur);
784 >                while (*cp) cp++;
785 >        }
786 >        if (nblur > 1 || vint(INTERP)) {
787                  sprintf(cp, " -z %s.zbf", fname);
788                  while (*cp) cp++;
789          }
# Line 708 | Line 797 | int    frame;
797                  return(1);
798                                          /* add frame to recovered list */
799          if (nrfrms)
800 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
800 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
801          else
802                  rfrm = (int *)malloc(sizeof(int));
803          if (rfrm == NULL) {
# Line 735 | Line 824 | int    frame;
824   }
825  
826  
827 < archive(first, last)                    /* archive and remove renderings */
739 < int     first, last;
827 > archive()                       /* archive and remove renderings */
828   {
829   #define RMCOML  (sizeof(rmcom)-1)
830          static char     rmcom[] = "rm -f";
831 <        int     offset = RMCOML;
832 <        char    combuf[10240];
833 <        struct stat     stb;
746 <        register char   *cp;
747 <        register int    i;
831 >        char    basedir[128];
832 >        int     dlen, alen;
833 >        register int    j;
834  
835 <        if (noaction)
836 <                return;
837 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
838 <                offset = strlen(vval(ARCHIVE));
753 <        cp = combuf + offset;
754 <        *cp++ = ' ';                            /* make argument list */
755 <        for (i = first; i <= last; i++) {
756 <                sprintf(cp, vval(BASENAME), i);
757 <                strcat(cp, ".unf");
758 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
759 <                        while (*cp) cp++;
760 <                        *cp++ = ' ';
761 <                        sprintf(cp, vval(BASENAME), i);
762 <                        strcat(cp, ".zbf");
763 <                        if (access(cp, F_OK) == 0) {            /* exists? */
764 <                                while (*cp) cp++;
765 <                                *cp++ = ' ';
766 <                        }
767 <                }
768 <        }
769 <        *--cp = '\0';
770 <        if (cp <= combuf + offset)              /* no files? */
771 <                return;
835 >        if (arcnext == arcfirst)
836 >                return;                         /* nothing to do */
837 >        dirfile(basedir, vval(BASENAME));
838 >        dlen = strlen(basedir);
839          if (vdef(ARCHIVE)) {                    /* run archive command */
840 <                i = strlen(vval(ARCHIVE));
841 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
842 <                if (runcom(combuf+offset-i)) {
843 <                        fprintf(stderr,
844 <                "%s: error running archive command on frames %d through %d\n",
845 <                                        progname, first, last);
840 >                alen = strlen(vval(ARCHIVE));
841 >                if (dlen) {
842 >                        j = alen + dlen + 5;
843 >                        strncpy(arcfirst-j, "cd ", 3);
844 >                        strncpy(arcfirst-j+3, basedir, dlen);
845 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
846 >                } else
847 >                        j = alen;
848 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
849 >                if (runcom(arcfirst-j)) {
850 >                        fprintf(stderr, "%s: error running archive command\n",
851 >                                        progname);
852                          quit(1);
853                  }
854          }
855 +        if (dlen) {
856 +                j = RMCOML + dlen + 5;
857 +                strncpy(arcfirst-j, "cd ", 3);
858 +                strncpy(arcfirst-j+3, basedir, dlen);
859 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
860 +        } else
861 +                j = RMCOML;
862                                                  /* run remove command */
863 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
864 <        runcom(combuf+offset-RMCOML);
863 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
864 >        runcom(arcfirst-j);
865 >        arcnext = arcfirst;                     /* reset argument list */
866   #undef RMCOML
867   }
868  
# Line 794 | Line 875 | char   *ep;
875   int     rvr;
876   {
877          extern int      frecover();
878 <        char    fnbefore[128], fnafter[128];
879 <        char    combuf[1024], fname[128];
880 <        int     usepinterp, usepfilt;
878 >        static int      iter = 0;
879 >        double  blurf;
880 >        int     nblur = getblur(&blurf);
881 >        char    fnbefore[128], fnafter[128], *fbase;
882 >        char    combuf[1024], fname0[128], fname1[128];
883 >        int     usepinterp, usepfilt, nora_rgbe;
884          int     frseq[2];
885                                                  /* check what is needed */
886 <        usepinterp = atoi(vval(MBLUR));
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 826 | 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 ((fp = fopen(fname, "w")) == NULL) {
935 <                                perror(fname); quit(1);
936 <                        }
937 <                        fputs(VIEWSTR, fp);
938 <                        fprintview(vp, fp);
939 <                        putc('\n', fp); fclose(fp);
940 <                        if ((vp = getview(frame+1)) == NULL) {
941 <                                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                          }
844                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
845                        if ((fp = fopen(fname, "w")) == NULL) {
846                                perror(fname); quit(1);
847                        }
848                        fputs(VIEWSTR, fp);
849                        fprintview(vp, fp);
850                        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),
856 <                                        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 900 | 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 930 | Line 1035 | int    n;
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);
# Line 943 | Line 1050 | int    n;
1050                  copystruct(&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 956 | 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 978 | 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 1019 | 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                  }
1028                *cp = '\0';
1149          }
1150          return(expval);                         /* return value */
1151   }
# Line 1055 | 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 1066 | 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 */
1070        lastpid = pp->pid;              /* record PID for bwait() */
1071        lastpserver = ps;               /* record server for serverdown() */
1208          return(status);
1209   }
1210  
# Line 1076 | 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 1097 | Line 1235 | int    (*rf)();
1235          int     pid;
1236          register struct pslot   *psl;
1237  
1238 <        if (!silent)
1239 <                printf("\t%s &\n", com);        /* echo command */
1240 <        if (noaction)
1238 >        if (noaction) {
1239 >                if (!silent)
1240 >                        printf("\t%s\n", com);  /* echo command */
1241                  return(0);
1242 <        fflush(stdout);
1243 <                                        /* else start it when we can */
1244 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1242 >        }
1243 >        com = savestr(com);             /* else start it when we can */
1244 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1245                  bwait(1);
1246 <        if (!silent) {
1246 >        if (!silent) {                          /* echo command */
1247                  PSERVER *ps;
1248                  int     psn = pid;
1249                  ps = findjob(&psn);
1250 +                printf("\t%s\n", com);
1251                  printf("\tProcess started on %s\n", phostname(ps));
1252                  fflush(stdout);
1253          }
# Line 1124 | Line 1263 | bwait(ncoms)                           /* wait for batch job(s) to finish */
1263   int     ncoms;
1264   {
1265          int     status;
1127        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 */
1135 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1136 <                                fprintf(stderr,
1137 <                                        "%s: error rendering frame %d\n",
1138 <                                                progname, psl->fout);
1139 <                                quit(1);
1140 <                        }
1141 <                }
1142 <                psl->pid = 0;           /* free process slot */
1143 <                if (!--ncoms)
1144 <                        return;         /* done enough */
1270 >                serverdown();           /* update server status */
1271 >                if (--ncoms == 0)
1272 >                        break;          /* done enough */
1273          }
1274   }
1275  
# Line 1153 | 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 1166 | 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                          strcat(com1, ppins);
1303 <                        endcom1 = com1 + strlen(com1);
1174 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1175 <                                        vval(DIRECTORY), phostname(ps));
1176 <                } else {
1303 >                } else
1304                          com1 = com;
1305 <                        endcom1 = NULL;
1305 >                while (maxcopies > 0) {
1306 >                        s = savestr(com1);
1307 >                        if (startjob(ps, s, donecom) != -1) {
1308 >                                sleep(20);
1309 >                                hostcopies++;
1310 >                                maxcopies--;
1311 >                        } else {
1312 >                                freestr(s);
1313 >                                break;
1314 >                        }
1315                  }
1180                while (maxcopies > 0 &&
1181                                startjob(ps, savestr(com1), donecom) != -1) {
1182                        sleep(10);
1183                        hostcopies++;
1184                        maxcopies--;
1185                        if (endcom1 != NULL)
1186                                *endcom1 = '\0';
1187                }
1316                  if (!silent && hostcopies) {
1317                          if (hostcopies > 1)
1318                                  printf("\t%d duplicate processes", hostcopies);
# Line 1196 | Line 1324 | int    maxcopies;
1324          }
1325                                          /* wait for jobs to finish */
1326          while ((status = wait4job(NULL, -1)) != -1)
1327 <                if (status)
1328 <                        retstatus += !serverdown();     /* check server */
1327 >                retstatus += status && !serverdown();
1328 >                                        /* terminate parallel rpict's */
1329 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1330 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1331 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1332 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1333 >                        buf[n] = '\0';
1334 >                        close(pfd);
1335 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1336 >                                ;
1337 >                                                                /* terminate */
1338 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1339 >                        wait4job(ps, startjob(ps, buf, NULL));
1340 >                }
1341 >        }
1342          return(retstatus);
1343   }
1344  
# Line 1235 | Line 1376 | int    vc;
1376          fprintf(stderr, "%s: bad value for variable '%s'\n",
1377                          progname, vnam(vc));
1378          quit(1);
1379 + }
1380 +
1381 +
1382 + char *
1383 + dirfile(df, path)               /* separate path into directory and file */
1384 + char    *df;
1385 + register char   *path;
1386 + {
1387 +        register int    i;
1388 +        int     psep;
1389 +
1390 +        for (i = 0, psep = -1; path[i]; i++)
1391 +                if (path[i] == '/')
1392 +                        psep = i;
1393 +        if (df != NULL)
1394 +                if (psep == 0) {
1395 +                        df[0] = '/';
1396 +                        df[1] = '\0';
1397 +                } else if (psep > 0) {
1398 +                        strncpy(df, path, psep);
1399 +                        df[psep] = '\0';
1400 +                } else
1401 +                        df[0] = '\0';
1402 +        return(path+psep+1);
1403 + }
1404 +
1405 +
1406 + int
1407 + getblur(double *bf)             /* get # blur samples (and fraction) */
1408 + {
1409 +        double  blurf;
1410 +        int     nblur;
1411 +        char    *s;
1412 +
1413 +        if (!vdef(MBLUR)) {
1414 +                if (bf != NULL)
1415 +                        *bf = 0.0;
1416 +                return(0);
1417 +        }
1418 +        blurf = atof(vval(MBLUR));
1419 +        if (blurf < 0.0)
1420 +                blurf = 0.0;
1421 +        if (bf != NULL)
1422 +                *bf = blurf;
1423 +        if (blurf <= FTINY)
1424 +                return(0);
1425 +        s = sskip(vval(MBLUR));
1426 +        if (!*s)
1427 +                return(DEF_NBLUR);
1428 +        nblur = atoi(s);
1429 +        if (nblur <= 0)
1430 +                return(1);
1431 +        return(nblur);
1432   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines