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.1 by greg, Fri Jan 12 12:16:17 1996 UTC vs.
Revision 2.60 by greg, Sat Jun 7 05:09:46 2025 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"
17 < #include <sys/types.h>
16 > #include "copyright.h"
17 >
18 > #include <stdio.h>
19 > #include <ctype.h>
20   #include <sys/stat.h>
21 + #include <time.h>
22 + #include <signal.h>
23 +
24 + #include "platform.h"
25 + #include "rtprocess.h"
26 + #include "standard.h"
27   #include "view.h"
28   #include "vars.h"
29 <                                /* input variables */
30 < #define HOST            0               /* rendering host machine */
31 < #define RENDER          1               /* rendering options */
32 < #define PFILT           2               /* pfilt options */
33 < #define PINTERP         3               /* pinterp options */
34 < #define OCTREE          4               /* octree file name */
35 < #define DIRECTORY       5               /* working (sub)directory */
36 < #define BASENAME        6               /* output image base name */
37 < #define VIEWFILE        7               /* animation frame views */
38 < #define START           8               /* starting frame number */
39 < #define END             9               /* ending frame number */
40 < #define RIF             10              /* rad input file */
29 > #include "netproc.h"
30 >                                /* default blur samples */
31 > #ifndef DEF_NBLUR
32 > #define DEF_NBLUR       5
33 > #endif
34 >                                /* default remote shell */
35 > #ifndef REMSH
36 > #define REMSH           "ssh"
37 > #endif
38 >                                /* input variables (alphabetical by name) */
39 > #define ANIMATE         0               /* animation command */
40 > #define ARCHIVE         1               /* archiving command */
41 > #define BASENAME        2               /* output image base name */
42 > #define DBLUR           3               /* depth of field blur */
43 > #define DIRECTORY       4               /* working (sub)directory */
44 > #define DISKSPACE       5               /* how much disk space to use */
45 > #define END             6               /* ending frame number */
46 > #define EXPOSURE        7               /* how to compute exposure */
47 > #define HOST            8               /* rendering host machine */
48 > #define INTERP          9               /* # frames to interpolate */
49 > #define MBLUR           10              /* motion blur parameters */
50   #define NEXTANIM        11              /* next animation file */
51 < #define ANIMATE         12              /* animation command */
52 < #define TRANSFER        13              /* frame transfer command */
53 < #define ARCHIVE         14              /* archiving command */
54 < #define INTERP          15              /* # frames to interpolate */
55 < #define OVERSAMP        16              /* # times to oversample image */
56 < #define MBLUR           17              /* samples for motion blur */
57 < #define RTRACE          18              /* use rtrace with pinterp? */
58 < #define DISKSPACE       19              /* how much disk space to use */
59 < #define RESOLUTION      20              /* desired final resolution */
60 < #define EXPOSURE        21              /* how to compute exposure */
51 > #define OCTREE          12              /* octree file name */
52 > #define OVERSAMP        13              /* # times to oversample image */
53 > #define PFILT           14              /* pfilt options */
54 > #define PINTERP         15              /* pinterp options */
55 > #define RENDER          16              /* rendering options */
56 > #define RESOLUTION      17              /* desired final resolution */
57 > #define RIF             18              /* rad input file */
58 > #define RSH             19              /* remote shell script or program */
59 > #define RTRACE          20              /* use rtrace with pinterp? */
60 > #define START           21              /* starting frame number */
61 > #define TRANSFER        22              /* frame transfer command */
62 > #define VIEWFILE        23              /* animation frame views */
63  
64 < int     NVARS = 22;             /* total number of variables */
64 > int     NVARS = 24;             /* total number of variables */
65  
66   VARIABLE        vv[] = {                /* variable-value pairs */
67 +        {"ANIMATE",     2,      0,      NULL,   onevalue},
68 +        {"ARCHIVE",     2,      0,      NULL,   onevalue},
69 +        {"BASENAME",    3,      0,      NULL,   strvalue},
70 +        {"DBLUR",       2,      0,      NULL,   onevalue},
71 +        {"DIRECTORY",   3,      0,      NULL,   strvalue},
72 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
73 +        {"END",         2,      0,      NULL,   intvalue},
74 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
75          {"host",        4,      0,      NULL,   NULL},
76 <        {"render",      3,      0,      NULL,   catvalues},
76 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
77 >        {"MBLUR",       2,      0,      NULL,   onevalue},
78 >        {"NEXTANIM",    3,      0,      NULL,   strvalue},
79 >        {"OCTREE",      3,      0,      NULL,   strvalue},
80 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
81          {"pfilt",       2,      0,      NULL,   catvalues},
82          {"pinterp",     2,      0,      NULL,   catvalues},
83 <        {"OCTREE",      3,      0,      NULL,   onevalue},
84 <        {"DIRECTORY",   3,      0,      NULL,   onevalue},
85 <        {"BASENAME",    3,      0,      NULL,   onevalue},
86 <        {"VIEWFILE",    2,      0,      NULL,   onevalue},
83 >        {"render",      3,      0,      NULL,   catvalues},
84 >        {"RESOLUTION",  3,      0,      NULL,   onevalue},
85 >        {"RIF",         3,      0,      NULL,   strvalue},
86 >        {"RSH",         3,      0,      NULL,   onevalue},
87 >        {"RTRACE",      2,      0,      NULL,   boolvalue},
88          {"START",       2,      0,      NULL,   intvalue},
52        {"END",         2,      0,      NULL,   intvalue},
53        {"RIF",         3,      0,      NULL,   onevalue},
54        {"NEXTANIM",    3,      0,      NULL,   onevalue},
55        {"ANIMATE",     2,      0,      NULL,   onevalue},
89          {"TRANSFER",    2,      0,      NULL,   onevalue},
90 <        {"ARCHIVE",     2,      0,      NULL,   onevalue},
58 <        {"INTERP",      3,      0,      NULL,   intvalue},
59 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
60 <        {"MBLUR",       2,      0,      NULL,   onevalue},
61 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
62 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
63 <        {"RESOLUTION",  3,      0,      NULL,   onevalue},
64 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
90 >        {"VIEWFILE",    2,      0,      NULL,   strvalue},
91   };
92  
93   #define SFNAME  "STATUS"                /* status file name */
94  
95   struct {
96          char    host[64];               /* control host name */
97 <        int     pid;                    /* control process id */
97 >        RT_PID  pid;                    /* control process id */
98          char    cfname[128];            /* control file name */
99          int     rnext;                  /* next frame to render */
100          int     fnext;                  /* next frame to filter */
101          int     tnext;                  /* next frame to transfer */
102   }       astat;                  /* animation status */
103  
78 char    *progname;              /* our program name */
104   char    *cfname;                /* our control file name */
105  
106   int     nowarn = 0;             /* turn warnings off? */
107   int     silent = 0;             /* silent mode? */
108   int     noaction = 0;           /* take no action? */
109  
110 < char    rendopt[2048] = "";     /* rendering options */
110 > char    *remsh;                 /* remote shell program/script */
111 > char    rendopt[2048];          /* rendering options */
112   char    rresopt[32];            /* rendering resolution options */
113   char    fresopt[32];            /* filter resolution options */
114   int     pfiltalways;            /* always use pfilt? */
115  
116 < VIEW    *getview();
117 < char    *getexp();
116 > char    arcargs[10240];         /* files to archive */
117 > char    *arcfirst, *arcnext;    /* pointers to first and next argument */
118  
119 + struct pslot {
120 +        RT_PID  pid;                    /* process ID (0 if empty) */
121 +        int     fout;                   /* output frame number */
122 +        int     (*rcvf)();              /* recover function */
123 + }       *pslot;                 /* process slots */
124 + int     npslots;                /* number of process slots */
125  
126 < main(argc, argv)
127 < int     argc;
128 < char    *argv[];
126 > #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
127 > PSERVER *lastpserver;           /* last process server with error */
128 >
129 > static struct pslot * findpslot(RT_PID pid);
130 > static void checkdir(void);
131 > static VIEW * getview(int n);
132 >
133 > static char * dirfile(char *df, register char *path);
134 > static char * getexp(int n);
135 > static int getblur(double *mbf, double *dbf);
136 > static int getastat(void);
137 > static void getradfile(char *rfargs);
138 > static void badvalue(int vc);
139 > static int rmfile(char *fn);
140 > static int runcom(char *cs);
141 > static int pruncom(char *com, char *ppins, int maxcopies);
142 > static void bwait(int ncoms);
143 > static RT_PID bruncom(char *com, int fout, int (*rf)());
144 > static int serverdown(void);
145 > static pscompfunc donecom;
146 > static int countviews(void);
147 > static int dofilt(int frame, int rvr);
148 > static void archive(void);
149 > static int frecover(int frame);
150 > static int recover(int frame);
151 > static void sethosts(void);
152 > static void walkwait(int first, int last, char *vfn);
153 > static void animrend(int frame, VIEW *vp);
154 > static void transferframes(void);
155 > static void filterframes(void);
156 > static void renderframes(int nframes);
157 > static void animate(void);
158 > static void setdefaults(void);
159 > static void putastat(void);
160 >
161 >
162 > int
163 > main(
164 >        int     argc,
165 >        char    *argv[]
166 > )
167   {
168          int     explicate = 0;
169          int     i;
170 <
171 <        progname = argv[0];                     /* get arguments */
170 >                                                /* set global progname */
171 >        fixargv0(argv[0]);
172 >                                                /* get arguments */
173          for (i = 1; i < argc && argv[i][0] == '-'; i++)
174                  switch (argv[i][1]) {
175                  case 'e':                       /* print variables */
# Line 121 | Line 192 | char   *argv[];
192          cfname = argv[i];
193                                                  /* load variables */
194          loadvars(cfname);
195 +                                                /* check variables */
196 +        checkvalues();
197                                                  /* did we get DIRECTORY? */
198          checkdir();
199                                                  /* check status */
# Line 138 | Line 211 | char   *argv[];
211                                                  /* print variables */
212          if (explicate)
213                  printvars(stdout);
214 +                                                /* set up process servers */
215 +        sethosts();
216                                                  /* run animation */
217          animate();
218                                                  /* all done */
219          if (vdef(NEXTANIM)) {
220 +                char    *fullp;
221                  argv[i] = vval(NEXTANIM);       /* just change input file */
222                  if (!silent)
223                          printargs(argc, argv, stdout);
224 <                if (!noaction) {
225 <                        execvp(progname, argv);         /* pass to next */
226 <                        quit(1);                        /* shouldn't return */
227 <                }
224 >                fflush(stdout);
225 >                if ((fullp = getpath(argv[0],getenv("PATH"),X_OK)) == NULL)
226 >                        fprintf(stderr, "%s: command not found\n", argv[0]);
227 >                else
228 >                        execv(fullp, argv);
229 >                quit(1);
230          }
231          quit(0);
232 +        return(0); /* pro forma return */
233   userr:
234          fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
235          quit(1);
236 +        return 1; /* pro forma return */
237   }
238  
239  
240 < getastat()                      /* check/set animation status */
240 > static int
241 > getastat(void)                  /* check/set animation status */
242   {
243 <        char    buf[256];
243 >        char    sfname[256];
244          FILE    *fp;
245  
246 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
247 <        if ((fp = fopen(buf, "r")) == NULL) {
246 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
247 >        if ((fp = fopen(sfname, "r")) == NULL) {
248                  if (errno != ENOENT) {
249 <                        perror(buf);
249 >                        perror(sfname);
250                          return(-1);
251                  }
252                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 185 | Line 266 | getastat()                     /* check/set animation status */
266                  goto fmterr;
267          fclose(fp);
268          if (astat.pid != 0) {                   /* thinks it's still running */
269 <                gethostname(buf, sizeof(buf));
189 <                if (strcmp(buf, astat.host)) {
269 >                if (strcmp(myhostname(), astat.host)) {
270                          fprintf(stderr,
271                          "%s: process %d may still be running on host %s\n",
272                                          progname, astat.pid, astat.host);
# Line 199 | Line 279 | getastat()                     /* check/set animation status */
279                  }
280                  /* assume it is dead */
281          }
282 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
282 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
283                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
284                                  progname, astat.cfname);
285                  return(-1);
286          }
287 +                                                /* check control file mods. */
288 +        if (!nowarn && fdate(cfname) > fdate(sfname))
289 +                fprintf(stderr,
290 +                        "%s: warning - control file modified since last run\n",
291 +                                progname);
292   setours:                                        /* set our values */
293 <        gethostname(astat.host, sizeof(astat.host));
293 >        strcpy(astat.host, myhostname());
294          astat.pid = getpid();
295          strcpy(astat.cfname, cfname);
296          return(0);
297   fmterr:
298          fprintf(stderr, "%s: format error in status file \"%s\"\n",
299 <                        progname, buf);
299 >                        progname, sfname);
300          fclose(fp);
301          return(-1);
302   }
303  
304  
305 < putastat()                      /* put out current status */
305 > static void
306 > putastat(void)                  /* put out current status */
307   {
308          char    buf[256];
309          FILE    *fp;
310  
311 +        if (noaction)
312 +                return;
313          sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
314          if ((fp = fopen(buf, "w")) == NULL) {
315                  perror(buf);
# Line 237 | Line 325 | putastat()                     /* put out current status */
325   }
326  
327  
328 < checkdir()                      /* make sure we have our directory */
328 > static void
329 > checkdir(void)                  /* make sure we have our directory */
330   {
331          struct stat     stb;
332  
# Line 259 | Line 348 | checkdir()                     /* make sure we have our directory */
348   }
349  
350  
351 < setdefaults()                   /* set default values */
351 > static void
352 > setdefaults(void)                       /* set default values */
353   {
354 +        extern char     *atos();
355 +        int     decades;
356          char    buf[256];
357  
358 <        if (vdef(OCTREE) == vdef(ANIMATE)) {
358 >        if (vdef(ANIMATE)) {
359 >                vval(OCTREE) = NULL;
360 >                vdef(OCTREE) = 0;
361 >        } else if (!vdef(OCTREE)) {
362                  fprintf(stderr, "%s: either %s or %s must be defined\n",
363                                  progname, vnam(OCTREE), vnam(ANIMATE));
364                  quit(1);
# Line 272 | Line 367 | setdefaults()                  /* set default values */
367                  fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE));
368                  quit(1);
369          }
370 +        if (!vdef(HOST)) {
371 +                vval(HOST) = LHOSTNAME;
372 +                vdef(HOST)++;
373 +        }
374          if (!vdef(START)) {
375                  vval(START) = "1";
376                  vdef(START)++;
377          }
378          if (!vdef(END)) {
379 <                sprintf(buf, "%d", countviews());
379 >                sprintf(buf, "%d", countviews()+vint(START)-1);
380                  vval(END) = savqstr(buf);
381                  vdef(END)++;
382          }
383 +        if (vint(END) < vint(START)) {
384 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
385 +                                progname);
386 +                quit(1);
387 +        }
388          if (!vdef(BASENAME)) {
389 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
389 >                decades = (int)log10((double)vint(END)) + 1;
390 >                if (decades < 3) decades = 3;
391 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
392                  vval(BASENAME) = savqstr(buf);
393                  vdef(BASENAME)++;
394          }
# Line 309 | Line 415 | setdefaults()                  /* set default values */
415          if (!vdef(DISKSPACE)) {
416                  if (!nowarn)
417                          fprintf(stderr,
418 <                "%s: warning - no %s setting, assuming 100 Mbytes available\n",
418 >                "%s: warning - no %s setting, assuming 1000 Mbytes available\n",
419                                          progname, vnam(DISKSPACE));
420 <                vval(DISKSPACE) = "100";
420 >                vval(DISKSPACE) = "1000";
421                  vdef(DISKSPACE)++;
422          }
423 +        if (!vdef(RSH)) {
424 +                vval(RSH) = REMSH;
425 +                vdef(RSH)++;
426 +        }
427 +                                /* locate remote shell program */
428 +        atos(buf, sizeof(buf), vval(RSH));
429 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
430 +                remsh = savqstr(remsh);
431 +        else
432 +                remsh = vval(RSH);      /* will generate error if used */
433 +
434                                  /* append rendering options */
435          if (vdef(RENDER))
436                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
437   }
438  
439  
440 < getradfile(rfname)              /* run rad and get needed variables */
441 < char    *rfname;
440 > static void
441 > sethosts(void)                  /* set up process servers */
442   {
443 +        extern char     *iskip();
444 +        char    buf[256], *dir, *uname;
445 +        int     np;
446 +        register char   *cp;
447 +        int     i;
448 +
449 +        npslots = 0;
450 +        if (noaction)
451 +                return;
452 +        for (i = 0; i < vdef(HOST); i++) {      /* add each host */
453 +                dir = uname = NULL;
454 +                np = 1;
455 +                strcpy(cp=buf, nvalue(HOST, i));        /* copy to buffer */
456 +                cp = sskip(cp);                         /* skip host name */
457 +                while (isspace(*cp))
458 +                        *cp++ = '\0';
459 +                if (*cp) {                              /* has # processes? */
460 +                        np = atoi(cp);
461 +                        if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp)))
462 +                                badvalue(HOST);
463 +                        while (isspace(*cp))
464 +                                cp++;
465 +                        if (*cp) {                      /* has directory? */
466 +                                dir = cp;
467 +                                cp = sskip(cp);                 /* skip dir. */
468 +                                while (isspace(*cp))
469 +                                        *cp++ = '\0';
470 +                                if (*cp) {                      /* has user? */
471 +                                        uname = cp;
472 +                                        if (*sskip(cp))
473 +                                                badvalue(HOST);
474 +                                }
475 +                        }
476 +                }
477 +                if (addpserver(buf, dir, uname, np) == NULL) {
478 +                        if (!nowarn)
479 +                                fprintf(stderr,
480 +                                        "%s: cannot execute on host \"%s\"\n",
481 +                                                progname, buf);
482 +                } else
483 +                        npslots += np;
484 +        }
485 +        if (npslots == 0) {
486 +                fprintf(stderr, "%s: no working process servers\n", progname);
487 +                quit(1);
488 +        }
489 +        pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot));
490 +        if (pslot == NULL) {
491 +                perror("malloc");
492 +                quit(1);
493 +        }
494 + }
495 +
496 + static void
497 + getradfile(char *rfargs)                /* run rad and get needed variables */
498 + {
499          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
500          char    combuf[256];
501          register int    i;
502          register char   *cp;
503 +        char    *pippt = NULL;
504                                          /* create rad command */
505          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
506          sprintf(combuf,
507          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
508 <                        rfname, rendopt+2);
508 >                        rfargs, rendopt+2);
509          cp = combuf;
510 <        while (*cp) cp++;               /* match unset variables */
510 >        while (*cp) {
511 >                if (*cp == '|') pippt = cp;
512 >                cp++;
513 >        }                               /* match unset variables */
514          for (i = 0; mvar[i] >= 0; i++)
515                  if (!vdef(mvar[i])) {
516                          *cp++ = '|';
517                          strcpy(cp, vnam(mvar[i]));
518                          while (*cp) cp++;
519 +                        pippt = NULL;
520                  }
521 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
522 <        cp += 11;                       /* point to file name */
523 <        if (system(combuf)) {
524 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
525 <                                progname, rfname);
348 <                quit(1);
521 >        if (pippt != NULL)
522 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
523 >        else {
524 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
525 >                cp += 11;               /* point to file name */
526          }
527 <        loadvars(cp);                   /* load variables and remove file */
528 <        unlink(cp);
527 >        system(combuf);                 /* ignore exit code */
528 >        if (pippt == NULL) {            /* load variables and remove file */
529 >                loadvars(cp);
530 >                unlink(cp);
531 >        }
532   }
533  
534  
535 < animate()                       /* run animation */
535 > static void
536 > animate(void)                   /* run animation */
537   {
538          int     xres, yres;
539          float   pa, mult;
# Line 363 | Line 544 | animate()                      /* run animation */
544          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
545          mult = vflt(OVERSAMP);
546          if (i == 3) {
547 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
547 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
548                                  (int)(mult*yres), pa);
549 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
549 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
550          } else if (i) {
551                  if (i == 1) yres = xres;
552                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 382 | Line 563 | animate()                      /* run animation */
563                                                  progname, vnam(INTERP));
564                          vval(INTERP) = "0";
565                  }
566 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
566 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
567                          if (!nowarn)
568                                  fprintf(stderr,
569                                          "%s: resetting %s=0 for animation\n",
# Line 392 | Line 573 | animate()                      /* run animation */
573          }
574                                          /* figure # frames per batch */
575          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
576 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
577 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
576 >        if ((i=vint(INTERP)) || getblur(NULL, NULL) > 1)
577 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
578          d2 = xres*yres*4;                       /* space for final picture */
579          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
580          if (frames_batch < i+2) {
# Line 401 | Line 582 | animate()                      /* run animation */
582                                  progname);
583                  quit(1);
584          }
585 +                                        /* initialize archive argument list */
586 +        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
587 +        arcnext = arcfirst = arcargs + i;
588                                          /* initialize status file */
589          if (astat.rnext == 0)
590                  astat.rnext = astat.fnext = astat.tnext = vint(START);
591          putastat();
592                                          /* render in batches */
593 <        while (astat.rnext <= vint(END)) {
593 >        while (astat.tnext <= vint(END)) {
594                  renderframes(frames_batch);
595                  filterframes();
596                  transferframes();
# Line 420 | Line 604 | animate()                      /* run animation */
604   }
605  
606  
607 < renderframes(nframes)           /* render next nframes frames */
608 < int     nframes;
607 > static void
608 > renderframes(int nframes)               /* render next nframes frames */
609   {
610          static char     vendbuf[16];
611          VIEW    *vp;
# Line 466 | Line 650 | int    nframes;
650                  }
651          }
652          if (vdef(ANIMATE))              /* wait for renderings to finish */
653 <                animwait(0);
653 >                bwait(0);
654          else {                          /* else if walk-through */
655                  fclose(fp);             /* close view file */
656                  walkwait(astat.rnext, lastframe, vfname);       /* walk it */
657                  unlink(vfname);         /* remove view file */
658          }
475        if (vdef(ARCHIVE))              /* archive results */
476                archive(astat.rnext, lastframe);
659          astat.rnext = i;                /* update status */
660          putastat();
661   }
662  
663  
664 < filterframes()                          /* catch up with filtering */
664 > static void
665 > filterframes(void)                              /* catch up with filtering */
666   {
484        VIEW    *vp;
667          register int    i;
668  
669          if (astat.tnext < astat.fnext)  /* other work to do first */
670                  return;
671                                          /* filter each view */
672 <        for (i = astat.fnext; i < astat.rnext; i++) {
673 <                if ((vp = getview(i)) == NULL) {        /* get view i */
674 <                        fprintf(stderr,
675 <                        "%s: unexpected error reading view for frame %d\n",
676 <                                        progname, i);
495 <                        quit(1);
496 <                }
497 <                dofilt(i, vp, getexp(i));               /* filter frame */
498 <        }
499 <        filtwait(0);                    /* wait for filter processes */
672 >        for (i = astat.fnext; i < astat.rnext; i++)
673 >                dofilt(i, 0);
674 >
675 >        bwait(0);                       /* wait for filter processes */
676 >        archive();                      /* archive originals */
677          astat.fnext = i;                /* update status */
678          putastat();
679   }
680  
681  
682 < transferframes()                        /* catch up with picture transfers */
682 > static void
683 > transferframes(void)                    /* catch up with picture transfers */
684   {
685 <        char    combuf[10240];
685 >        char    combuf[10240], *fbase;
686          register char   *cp;
687          register int    i;
688  
# Line 515 | Line 693 | transferframes()                       /* catch up with picture transfers
693                  putastat();             /* update status */
694                  return;
695          }
696 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
697 <        cp = combuf + strlen(combuf);
696 >        strcpy(combuf, "cd ");          /* start transfer command */
697 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
698 >        if (*cp) {
699 >                while (*++cp) ;
700 >                *cp++ = ';'; *cp++ = ' ';
701 >        } else
702 >                cp = combuf;
703 >        strcpy(cp, vval(TRANSFER));
704 >        while (*cp) cp++;
705                                          /* make argument list */
706          for (i = astat.tnext; i < astat.fnext; i++) {
707                  *cp++ = ' ';
708 <                sprintf(cp, vval(BASENAME), i);
708 >                sprintf(cp, fbase, i);
709                  while (*cp) cp++;
710 <                strcpy(cp, ".pic");
710 >                strcpy(cp, ".hdr");
711                  cp += 4;
712          }
713          if (runcom(combuf)) {           /* transfer frames */
# Line 535 | Line 720 | transferframes()                       /* catch up with picture transfers
720   }
721  
722  
723 < animrend(frame, vp)                     /* start animation frame */
724 < int     frame;
725 < VIEW    *vp;
723 > static void
724 > animrend(                       /* start animation frame */
725 > int     frame,
726 > VIEW    *vp
727 > )
728   {
729          char    combuf[2048];
730          char    fname[128];
# Line 546 | Line 733 | VIEW   *vp;
733          strcat(fname, ".unf");
734          if (access(fname, F_OK) == 0)
735                  return;
736 <        sprintf(combuf, "%s %d | rpict%s%s %s > %s", vval(ANIMATE), frame,
736 >        sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame,
737                          rendopt, viewopt(vp), rresopt, fname);
738 <        if (runcom(combuf)) {
552 <                fprintf(stderr, "%s: error rendering frame %d\n",
553 <                                progname, frame);
554 <                quit(1);
555 <        }
738 >        bruncom(combuf, frame, recover);        /* run in background */
739   }
740  
741  
742 < animwait(nwait)                         /* wait for renderings to finish */
743 < int     nwait;
742 > static void
743 > walkwait(               /* walk-through frames */
744 > int     first,
745 > int last,
746 > char    *vfn
747 > )
748   {
749 <        /* currently does nothing since parallel rendering not working */
750 < }
564 <
565 <
566 < walkwait(first, last, vfn)              /* walk-through frames */
567 < int     first, last;
568 < char    *vfn;
569 < {
749 >        double  mblurf, dblurf;
750 >        int     nblur = getblur(&mblurf, &dblurf);
751          char    combuf[2048];
752 +        register char   *inspoint;
753          register int    i;
754  
755          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 578 | Line 760 | char   *vfn;
760                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
761                          }
762                                          /* create command */
763 <        sprintf(combuf, "rpict%s ", rendopt);
764 <        if (vint(INTERP) || atoi(vval(MBLUR)))
765 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
766 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
767 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
768 <        if (runcom(combuf)) {
769 <                fprintf(stderr,
770 <                "%s: error rendering walk-through frames %d through %d\n",
763 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
764 >                        viewopt(getview(first>1 ? first-1 : 1)));
765 >        inspoint = combuf;
766 >        while (*inspoint) inspoint++;
767 >        if (nblur) {
768 >                sprintf(inspoint, " -pm %.3f", mblurf/nblur);
769 >                while (*inspoint) inspoint++;
770 >                sprintf(inspoint, " -pd %.3f", dblurf/nblur);
771 >                while (*inspoint) inspoint++;
772 >        }
773 >        if (nblur > 1 || vint(INTERP)) {
774 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
775 >                while (*inspoint) inspoint++;
776 >        }
777 >        sprintf(inspoint, " -o %s.unf %s -S %d",
778 >                        vval(BASENAME), rresopt, first);
779 >        while (*inspoint) inspoint++;
780 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
781 >                                        /* run in parallel */
782 >        i = (last-first+1)/(vint(INTERP)+1);
783 >        if (i < 1) i = 1;
784 >        if (pruncom(combuf, inspoint, i)) {
785 >                fprintf(stderr, "%s: error rendering frames %d through %d\n",
786                                  progname, first, last);
787                  quit(1);
788          }
# Line 599 | Line 796 | char   *vfn;
796   }
797  
798  
799 < recover(frame)                          /* recover the specified frame */
800 < int     frame;
799 > static int
800 > recover(int frame)                      /* recover the specified frame */
801   {
802 +        static int      *rfrm;          /* list of recovered frames */
803 +        static int      nrfrms = 0;
804 +        double  mblurf, dblurf;
805 +        int     nblur = getblur(&mblurf, &dblurf);
806          char    combuf[2048];
807          char    fname[128];
808          register char   *cp;
809 <
809 >        register int    i;
810 >                                        /* check to see if recovered already */
811 >        for (i = nrfrms; i--; )
812 >                if (rfrm[i] == frame)
813 >                        return(0);
814 >                                        /* build command */
815          sprintf(fname, vval(BASENAME), frame);
816          if (vdef(ANIMATE))
817 <                sprintf(combuf, "%s %d | rpict%s",
817 >                sprintf(combuf, "%s %d | rpict%s -w0",
818                                  vval(ANIMATE), frame, rendopt);
819          else
820 <                sprintf(combuf, "rpict%s", rendopt);
821 <        cp = combuf + strlen(combuf);
822 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
820 >                sprintf(combuf, "rpict%s -w0", rendopt);
821 >        cp = combuf;
822 >        while (*cp) cp++;
823 >        if (nblur) {
824 >                sprintf(cp, " -pm %.3f", mblurf/nblur);
825 >                while (*cp) cp++;
826 >                sprintf(cp, " -pd %.3f", dblurf/nblur);
827 >                while (*cp) cp++;
828 >        }
829 >        if (nblur > 1 || vint(INTERP)) {
830                  sprintf(cp, " -z %s.zbf", fname);
831                  while (*cp) cp++;
832          }
# Line 623 | Line 836 | int    frame;
836                  *cp++ = ' ';
837                  strcpy(cp, vval(OCTREE));
838          }
839 <        if (runcom(combuf)) {
840 <                fprintf(stderr, "%s: error recovering frame %d\n",
841 <                                progname, frame);
839 >        if (runcom(combuf))             /* run command */
840 >                return(1);
841 >                                        /* add frame to recovered list */
842 >        if (nrfrms)
843 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
844 >        else
845 >                rfrm = (int *)malloc(sizeof(int));
846 >        if (rfrm == NULL) {
847 >                perror("malloc");
848                  quit(1);
849          }
850 +        rfrm[nrfrms++] = frame;
851 +        return(0);
852   }
853  
854  
855 < archive(first, last)                    /* archive finished renderings */
856 < int     first, last;
855 > static int
856 > frecover(int frame)                             /* recover filtered frame */
857   {
858 <        char    combuf[10240];
859 <        int     offset;
860 <        struct stat     stb;
861 <        register char   *cp;
641 <        register int    i;
858 >        if (dofilt(frame, 2) && dofilt(frame, 1))
859 >                return(1);
860 >        return(0);
861 > }
862  
863 <        strcpy(cp=combuf, vval(ARCHIVE));
864 <        while (*cp) cp++;
865 <        offset = cp - combuf;
866 <        *cp++ = ' ';                            /* make argument list */
867 <        for (i = first; i <= last; i++) {
868 <                sprintf(cp, vval(BASENAME), i);
869 <                strcat(cp, ".unf");
870 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
871 <                        while (*cp) cp++;
872 <                        *cp++ = ' ';
873 <                        sprintf(cp, vval(BASENAME), i);
874 <                        strcat(cp, ".zbf");
875 <                        if (access(cp, F_OK) == 0) {            /* exists? */
876 <                                while (*cp) cp++;
877 <                                *cp++ = ' ';
878 <                        }
863 >
864 > static void
865 > archive(void)                   /* archive and remove renderings */
866 > {
867 > #define RMCOML  (sizeof(rmcom)-1)
868 >        static char     rmcom[] = "rm -f";
869 >        char    basedir[128];
870 >        int     dlen, alen;
871 >        register int    j;
872 >
873 >        if (arcnext == arcfirst)
874 >                return;                         /* nothing to do */
875 >        dirfile(basedir, vval(BASENAME));
876 >        dlen = strlen(basedir);
877 >        if (vdef(ARCHIVE)) {                    /* run archive command */
878 >                alen = strlen(vval(ARCHIVE));
879 >                if (dlen) {
880 >                        j = alen + dlen + 5;
881 >                        strncpy(arcfirst-j, "cd ", 3);
882 >                        strncpy(arcfirst-j+3, basedir, dlen);
883 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
884 >                } else
885 >                        j = alen;
886 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
887 >                if (runcom(arcfirst-j)) {
888 >                        fprintf(stderr, "%s: error running archive command\n",
889 >                                        progname);
890 >                        quit(1);
891                  }
892          }
893 <        *--cp = '\0';
894 <        if (cp <= combuf + offset)              /* no files? */
895 <                return;
896 <        if (runcom(combuf)) {                   /* run archive command */
897 <                fprintf(stderr,
898 <                "%s: error running archive command on frames %d through %d\n",
899 <                                progname, first, last);
900 <                quit(1);
901 <        }
893 >        if (dlen) {
894 >                j = RMCOML + dlen + 5;
895 >                strncpy(arcfirst-j, "cd ", 3);
896 >                strncpy(arcfirst-j+3, basedir, dlen);
897 >                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
898 >        } else
899 >                j = RMCOML;
900 >                                                /* run remove command */
901 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
902 >        runcom(arcfirst-j);
903 >        arcnext = arcfirst;                     /* reset argument list */
904 > #undef RMCOML
905   }
906  
907  
908 < dofilt(frame, vp, ep)                           /* filter frame */
909 < int     frame;
910 < VIEW    *vp;
911 < char    *ep;
908 > static int
909 > dofilt(                         /* filter frame */
910 > int     frame,
911 > int     rvr
912 > )
913   {
914 <        char    fnbefore[128], fnafter[128];
915 <        char    combuf[1024], fname[128];
916 <        int     usepinterp, usepfilt;
917 <        int     frbefore, frafter, triesleft;
914 >        static int      iter = 0;
915 >        double  mblurf, dblurf;
916 >        int     nblur = getblur(&mblurf, &dblurf);
917 >        VIEW    *vp = getview(frame);
918 >        char    *ep = getexp(frame);
919 >        char    fnbefore[128], fnafter[128], *fbase;
920 >        char    combuf[1024], fname0[128], fname1[128];
921 >        int     usepinterp, usepfilt, nora_rgbe;
922 >        int     frseq[2];
923                                                  /* check what is needed */
924 <        usepinterp = atoi(vval(MBLUR));
925 <        usepfilt = pfiltalways | ep==NULL;
924 >        if (vp == NULL) {
925 >                 fprintf(stderr,
926 >                        "%s: unexpected error reading view for frame %d\n",
927 >                                          progname, frame);
928 >                quit(1);
929 >        }
930 >        usepinterp = (nblur > 1);
931 >        usepfilt = pfiltalways | (ep==NULL);
932 >        if (ep != NULL && !strcmp(ep, "1"))
933 >                ep = "+0";
934 >        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
935 >                        *ep != '+' || *ep != '-' || !isint(ep);
936                                                  /* compute rendered views */
937 <        frbefore = frame - ((frame-1) % (vint(INTERP)+1));
938 <        frafter = frbefore + vint(INTERP) + 1;
939 <        if (frafter > vint(END))
940 <                frafter = vint(END);
941 <        if (frafter == frame) {                 /* pfilt only */
942 <                frbefore = frafter;
937 >        frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
938 >        frseq[1] = frseq[0] + vint(INTERP) + 1;
939 >        fbase = dirfile(NULL, vval(BASENAME));
940 >        if (frseq[1] > vint(END))
941 >                frseq[1] = vint(END);
942 >        if (frseq[1] == frame) {                        /* pfilt only */
943 >                frseq[0] = frseq[1];
944                  usepinterp = 0;                 /* update what's needed */
945 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
946 <                triesleft = 2;
947 <        } else if (frbefore == frame) {         /* no interpolation */
948 <                                                /* remove unneeded files */
949 <                if (frbefore-vint(INTERP)-1 >= 1) {
950 <                        sprintf(fname, vval(BASENAME), frbefore-vint(INTERP)-1);
951 <                        sprintf(combuf, "rm -f %s.unf %s.zbf", fname, fname);
952 <                        runcom(combuf);
945 >                usepfilt |= nora_rgbe;
946 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
947 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
948 >                        if (arcnext - arcargs +
949 >                                        strlen(fbase) >= sizeof(arcargs)-8) {
950 >                                fprintf(stderr,
951 > "%s: too many filenames in archive command -- reduce %s variable\n",
952 >                                                progname, vnam(DISKSPACE));
953 >                                quit(1);
954 >                        }
955 >                        *arcnext++ = ' ';
956 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
957 >                        while (*arcnext) arcnext++;
958 >                        strcpy(arcnext, ".unf");
959 >                        arcnext += 4;
960 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
961 >                                *arcnext++ = ' ';
962 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
963 >                                while (*arcnext) arcnext++;
964 >                                strcpy(arcnext, ".zbf");
965 >                                arcnext += 4;
966 >                        }
967                  }
968 <                                                /* update what's needed */
969 <                if (usepinterp)
970 <                        triesleft = 3;
705 <                else {
706 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
707 <                        triesleft = 2;
708 <                }
709 <        } else {                                /* interpolation needed */
968 >                if (!usepinterp)                /* update what's needed */
969 >                        usepfilt |= nora_rgbe;
970 >        } else                                  /* interpolation needed */
971                  usepinterp++;
972 <                triesleft = 3;
973 <        }
974 <        if (frafter >= astat.rnext) {           /* next batch unavailable */
975 <                frafter = frbefore;
976 <                if (triesleft > 2)
977 <                        triesleft = 2;
978 <        }
718 <        sprintf(fnbefore, vval(BASENAME), frbefore);
719 <        sprintf(fnafter, vval(BASENAME), frafter);
720 < tryit:                                          /* generate command */
972 >        if (frseq[1] >= astat.rnext)            /* next batch unavailable */
973 >                frseq[1] = frseq[0];
974 >        sprintf(fnbefore, vval(BASENAME), frseq[0]);
975 >        sprintf(fnafter, vval(BASENAME), frseq[1]);
976 >        if (rvr == 1 && recover(frseq[0]))      /* recover before frame? */
977 >                return(1);
978 >                                                /* generate command */
979          if (usepinterp) {                       /* using pinterp */
980 <                if (atoi(vval(MBLUR))) {
981 <                        FILE    *fp;            /* motion blurring */
982 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
983 <                        if ((fp = fopen(fname, "w")) == NULL) {
984 <                                perror(fname); quit(1);
985 <                        }
986 <                        fputs(VIEWSTR, fp);
987 <                        fprintview(vp, fp);
988 <                        putc('\n', fp); fclose(fp);
989 <                        if ((vp = getview(frame+1)) == NULL) {
990 <                                fprintf(stderr,
980 >                if (rvr == 2 && recover(frseq[1]))      /* recover after? */
981 >                        return(1);
982 >                if (nblur > 1) {                /* with pdmblur */
983 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
984 >                                        'a'+(iter%26));
985 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
986 >                                        'a'+(iter%26));
987 >                        if (!noaction) {
988 >                                FILE    *fp;            /* motion blurring */
989 >                                if ((fp = fopen(fname0, "w")) == NULL) {
990 >                                        perror(fname0); quit(1);
991 >                                }
992 >                                fputs(VIEWSTR, fp);
993 >                                fprintview(vp, fp);
994 >                                putc('\n', fp); fclose(fp);
995 >                                if ((vp = getview(frame+1)) == NULL) {
996 >                                        fprintf(stderr,
997                          "%s: unexpected error reading view for frame %d\n",
998 <                                                progname, frame+1);
999 <                                quit(1);
998 >                                                        progname, frame+1);
999 >                                        quit(1);
1000 >                                }
1001 >                                if ((fp = fopen(fname1, "w")) == NULL) {
1002 >                                        perror(fname1); quit(1);
1003 >                                }
1004 >                                fputs(VIEWSTR, fp);
1005 >                                fprintview(vp, fp);
1006 >                                putc('\n', fp); fclose(fp);
1007                          }
737                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
738                        if ((fp = fopen(fname, "w")) == NULL) {
739                                perror(fname); quit(1);
740                        }
741                        fputs(VIEWSTR, fp);
742                        fprintview(vp, fp);
743                        putc('\n', fp); fclose(fp);
1008                          sprintf(combuf,
1009 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
1010 <                                *sskip(vval(MBLUR)) ? sskip(vval(MBLUR)) : "1",
1011 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
1012 <                                        vval(DIRECTORY), vval(DIRECTORY),
749 <                                        vval(DIRECTORY), vval(DIRECTORY));
1009 >                        "(pmdblur %.3f %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
1010 >                                        mblurf, dblurf, nblur,
1011 >                                        fname0, fname1, fname0, fname1);
1012 >                        iter++;
1013                  } else                          /* no blurring */
1014                          strcpy(combuf, "pinterp");
1015                  strcat(combuf, viewopt(vp));
1016                  if (vbool(RTRACE))
1017 <                        sprintf(combuf+strlen(combuf), " -ff -fr '%s %s'",
1018 <                                        rendopt, vval(OCTREE));
1017 >                        sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1018 >                                        rendopt+1, vval(OCTREE));
1019                  if (vdef(PINTERP))
1020                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1021                  if (usepfilt)
1022                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1023                  else
1024 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1024 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1025                                          fresopt, ep);
1026                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1027                                  fnbefore, fnbefore);
1028 <                if (frafter != frbefore)
1028 >                if (frseq[1] != frseq[0])
1029                           sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1030                                          fnafter, fnafter);
1031                  if (usepfilt) {                 /* also pfilt */
# Line 778 | Line 1041 | tryit:                                         /* generate command */
1041                                  sprintf(combuf+strlen(combuf), " %s", fresopt);
1042                  }
1043          } else if (usepfilt) {                  /* pfilt only */
1044 +                if (rvr == 2)
1045 +                        return(1);
1046                  if (vdef(PFILT))
1047                          sprintf(combuf, "pfilt %s", vval(PFILT));
1048                  else
# Line 789 | Line 1054 | tryit:                                         /* generate command */
1054                          sprintf(combuf+strlen(combuf), " %s %s.unf",
1055                                          fresopt, fnbefore);
1056          } else {                                /* else just check it */
1057 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
1057 >                if (rvr == 2)
1058 >                        return(1);
1059 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1060          }
1061                                                  /* output file name */
1062 <        sprintf(fname, vval(BASENAME), frame);
1063 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
1064 <        if (runcom(combuf))                     /* run filter command */
1065 <                switch (--triesleft) {
1066 <                case 2:                         /* try to recover frafter */
1067 <                        recover(frafter);
801 <                        goto tryit;
802 <                case 1:                         /* try to recover frbefore */
803 <                        recover(frbefore);
804 <                        goto tryit;
805 <                default:                        /* we've really failed */
806 <                        fprintf(stderr,
807 <                        "%s: unrecoverable filtering error on frame %d\n",
808 <                                        progname, frame);
809 <                        quit(1);
810 <                }
1062 >        sprintf(fname0, vval(BASENAME), frame);
1063 >        sprintf(combuf+strlen(combuf), " > %s.hdr", fname0);
1064 >        if (rvr)                                /* in recovery */
1065 >                return(runcom(combuf));
1066 >        bruncom(combuf, frame, frecover);       /* else run in background */
1067 >        return(0);
1068   }
1069  
1070  
1071 < filtwait(nwait)                 /* wait for filtering processes to finish */
1072 < int     nwait;
1071 > static VIEW *
1072 > getview(int n)                  /* get view number n */
1073   {
817        /* currently does nothing since parallel filtering not working */
818 }
819
820
821 VIEW *
822 getview(n)                      /* get view number n */
823 int     n;
824 {
1074          static FILE     *viewfp = NULL;         /* view file pointer */
1075          static int      viewnum = 0;            /* current view number */
1076          static VIEW     curview = STDVIEW;      /* current view */
# Line 832 | Line 1081 | int    n;
1081                          fclose(viewfp);
1082                          viewfp = NULL;
1083                          viewnum = 0;
1084 <                        copystruct(&curview, &stdview);
1084 >                        curview = stdview;
1085                  }
1086                  return(NULL);
1087          }
1088 <        if (viewfp == NULL) {           /* open file */
1088 >        if (viewfp == NULL) {                   /* open file */
1089                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1090                          perror(vval(VIEWFILE));
1091                          quit(1);
1092                  }
1093 <        } else if (n < viewnum) {       /* rewind file */
1093 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1094 >                if (viewnum == 1 && feof(viewfp))
1095 >                        return(&curview);               /* just one view */
1096                  if (fseek(viewfp, 0L, 0) == EOF) {
1097                          perror(vval(VIEWFILE));
1098                          quit(1);
1099                  }
1100 <                copystruct(&curview, &stdview);
1100 >                curview = stdview;
1101                  viewnum = 0;
1102          }
1103 +        if (n < 0) {                            /* get next view */
1104 +                register int    c = getc(viewfp);
1105 +                if (c == EOF)
1106 +                        return((VIEW *)NULL);           /* that's it */
1107 +                ungetc(c, viewfp);
1108 +                n = viewnum + 1;
1109 +        }
1110          while (n > viewnum) {           /* scan to desired view */
1111                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1112 <                        return(NULL);
1112 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1113                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1114                          viewnum++;
1115          }
# Line 859 | Line 1117 | int    n;
1117   }
1118  
1119  
1120 < int
1121 < countviews()                    /* count views in view file */
1120 > static int
1121 > countviews(void)                        /* count views in view file */
1122   {
1123 <        register int    n = 0;
1123 >        int     n;
1124  
1125 <        while (getview(n+1) != NULL)
1125 >        if (getview(n=1) == NULL)
1126 >                return(0);
1127 >        while (getview(-1) != NULL)
1128                  n++;
1129          return(n);
1130   }
1131  
1132  
1133 < char *
1134 < getexp(n)                       /* get exposure for nth frame */
875 < int     n;
1133 > static char *
1134 > getexp(int n)                   /* get exposure for nth frame */
1135   {
877        extern char     *fskip();
1136          static char     expval[32];
1137          static FILE     *expfp = NULL;
1138          static long     *exppos;
# Line 884 | Line 1142 | int    n;
1142          if (n == 0) {                           /* signal to close file */
1143                  if (expfp != NULL) {
1144                          fclose(expfp);
1145 +                        free((void *)exppos);
1146                          expfp = NULL;
1147                  }
1148                  return(NULL);
1149 <        }
1149 >        } else if (n > vint(END))               /* request past end (error?) */
1150 >                return(NULL);
1151          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1152                  return(NULL);
1153          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 925 | Line 1185 | int    n;
1185                  }
1186                  curfrm++;
1187                  cp = fskip(expval);                     /* check format */
1188 <                if (cp == NULL || *cp != '\n') {
1188 >                if (cp != NULL)
1189 >                        while (isspace(*cp))
1190 >                                *cp++ = '\0';
1191 >                if (cp == NULL || *cp) {
1192                          fprintf(stderr,
1193                                  "%s: exposure format error on line %d\n",
1194                                          vval(EXPOSURE), curfrm);
1195                          quit(1);
1196                  }
934                *cp = '\0';
1197          }
1198          return(expval);                         /* return value */
1199   }
1200  
1201  
1202 < runcom(cs)                      /* run command */
1203 < char    *cs;
1202 > static struct pslot *
1203 > findpslot(RT_PID pid)                   /* find or allocate a process slot */
1204   {
1205 +        register struct pslot   *psempty = NULL;
1206 +        register int    i;
1207 +
1208 +        for (i = 0; i < npslots; i++) {         /* look for match */
1209 +                if (pslot[i].pid == pid)
1210 +                        return(pslot+i);
1211 +                if (psempty == NULL && pslot[i].pid == 0)
1212 +                        psempty = pslot+i;
1213 +        }
1214 +        return(psempty);                /* return emtpy slot (error if NULL) */
1215 + }
1216 +
1217 +
1218 + static int
1219 + donecom(                /* clean up after finished process */
1220 +        PSERVER *ps,
1221 +        int     pn,
1222 +        int     status
1223 + )
1224 + {
1225 +        register NETPROC        *pp;
1226 +        register struct pslot   *psl;
1227 +
1228 +        pp = ps->proc + pn;
1229 +        if (pp->elen) {                 /* pass errors */
1230 +                if (ps->hostname[0])
1231 +                        fprintf(stderr, "%s: ", ps->hostname);
1232 +                fprintf(stderr, "Error output from: %s\n", pp->com);
1233 +                fputs(pp->errs, stderr);
1234 +                fflush(stderr);
1235 +                if (ps->hostname[0])
1236 +                        status = 1;     /* because rsh doesn't return status */
1237 +        }
1238 +        lastpserver = NULL;
1239 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1240 +        if (psl->pid) {
1241 +                if (status) {
1242 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1243 +                                status = (*psl->rcvf)(psl->fout);
1244 +                        if (status) {
1245 +                                fprintf(stderr,
1246 +                                        "%s: error rendering frame %d\n",
1247 +                                                progname, psl->fout);
1248 +                                quit(1);
1249 +                        }
1250 +                        lastpserver = ps;
1251 +                }
1252 +                psl->pid = 0;                   /* free process slot */
1253 +        } else if (status)
1254 +                lastpserver = ps;
1255 +        freestr(pp->com);               /* free command string */
1256 +        return(status);
1257 + }
1258 +
1259 +
1260 + static int
1261 + serverdown(void)                        /* check status of last process server */
1262 + {
1263 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1264 +                return(0);
1265 +        if (pserverOK(lastpserver))     /* server still up? */
1266 +                return(0);
1267 +        delpserver(lastpserver);        /* else delete it */
1268 +        if (pslist == NULL) {
1269 +                fprintf(stderr, "%s: all process servers are down\n",
1270 +                                progname);
1271 +                quit(1);
1272 +        }
1273 +        return(1);
1274 + }
1275 +
1276 +
1277 + static RT_PID
1278 + bruncom(                /* run a command in the background */
1279 + char    *com,
1280 + int     fout,
1281 + int     (*rf)()
1282 + )
1283 + {
1284 +        RT_PID  pid;
1285 +        register struct pslot   *psl;
1286 +
1287 +        if (noaction) {
1288 +                if (!silent)
1289 +                        printf("\t%s\n", com);  /* echo command */
1290 +                return(0);
1291 +        }
1292 +        com = savestr(com);             /* else start it when we can */
1293 +        while ((pid = startjob(NULL, com, donecom)) == -1)
1294 +                bwait(1);
1295 +        if (!silent) {                          /* echo command */
1296 +                PSERVER *ps;
1297 +                RT_PID  psn = pid;
1298 +                ps = findjob(&psn);
1299 +                printf("\t%s\n", com);
1300 +                printf("\tProcess started on %s\n", phostname(ps));
1301 +                fflush(stdout);
1302 +        }
1303 +        psl = findpslot(pid);           /* record info. in appropriate slot */
1304 +        psl->pid = pid;
1305 +        psl->fout = fout;
1306 +        psl->rcvf = rf;
1307 +        return(pid);
1308 + }
1309 +
1310 +
1311 + static void
1312 + bwait(int ncoms)                                /* wait for batch job(s) to finish */
1313 + {
1314 +        int     status;
1315 +
1316 +        if (noaction)
1317 +                return;
1318 +        while ((status = wait4job(NULL, -1)) != -1) {
1319 +                serverdown();           /* update server status */
1320 +                if (--ncoms == 0)
1321 +                        break;          /* done enough */
1322 +        }
1323 + }
1324 +
1325 +
1326 + static int
1327 + pruncom(        /* run a command in parallel over network */
1328 + char    *com,
1329 + char    *ppins,
1330 + int     maxcopies
1331 + )
1332 + {
1333 +        int     retstatus = 0;
1334 +        int     hostcopies;
1335 +        char    buf[10240], *com1, *s;
1336 +        int     status;
1337 +        int     pfd;
1338 +        register int    n;
1339 +        register PSERVER        *ps;
1340 +
1341 +        if (!silent)
1342 +                printf("\t%s\n", com);  /* echo command */
1343 +        if (noaction)
1344 +                return(0);
1345 +        fflush(stdout);
1346 +                                        /* start jobs on each server */
1347 +        for (ps = pslist; ps != NULL; ps = ps->next) {
1348 +                hostcopies = 0;
1349 +                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1350 +                        strcpy(com1=buf, com);  /* build -PP command */
1351 +                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1352 +                                        vval(DIRECTORY), phostname(ps));
1353 +                        unlink(com1+(ppins-com)+5);
1354 +                        strcat(com1, ppins);
1355 +                } else
1356 +                        com1 = com;
1357 +                while (maxcopies > 0) {
1358 +                        s = savestr(com1);
1359 +                        if (startjob(ps, s, donecom) != -1) {
1360 +                                sleep(20);
1361 +                                hostcopies++;
1362 +                                maxcopies--;
1363 +                        } else {
1364 +                                freestr(s);
1365 +                                break;
1366 +                        }
1367 +                }
1368 +                if (!silent && hostcopies) {
1369 +                        if (hostcopies > 1)
1370 +                                printf("\t%d duplicate processes", hostcopies);
1371 +                        else
1372 +                                printf("\tProcess");
1373 +                        printf(" started on %s\n", phostname(ps));
1374 +                        fflush(stdout);
1375 +                }
1376 +        }
1377 +                                        /* wait for jobs to finish */
1378 +        while ((status = wait4job(NULL, -1)) != -1)
1379 +                retstatus += status && !serverdown();
1380 +                                        /* terminate parallel rpict's */
1381 +        for (ps = pslist; ps != NULL; ps = ps->next) {
1382 +                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1383 +                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1384 +                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1385 +                        buf[n] = '\0';
1386 +                        close(pfd);
1387 +                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1388 +                                ;
1389 +                                                                /* terminate */
1390 +                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1391 +                        wait4job(ps, startjob(ps, buf, NULL));
1392 +                }
1393 +        }
1394 +        return(retstatus);
1395 + }
1396 +
1397 +
1398 + static int
1399 + runcom(char *cs)                        /* run a command locally and wait for it */
1400 + {
1401          if (!silent)            /* echo it */
1402                  printf("\t%s\n", cs);
1403          if (noaction)
# Line 949 | Line 1407 | char   *cs;
1407   }
1408  
1409  
1410 < rmfile(fn)                      /* remove a file */
1411 < char    *fn;
1410 > static int
1411 > rmfile(char *fn)                        /* remove a file */
1412   {
1413          if (!silent)
1414 < #ifdef MSDOS
1414 > #if defined(_WIN32) || defined(_WIN64)
1415                  printf("\tdel %s\n", fn);
1416   #else
1417                  printf("\trm -f %s\n", fn);
# Line 964 | Line 1422 | char   *fn;
1422   }
1423  
1424  
1425 < badvalue(vc)                    /* report bad variable value and exit */
1426 < int     vc;
1425 > static void
1426 > badvalue(int vc)                        /* report bad variable value and exit */
1427   {
1428          fprintf(stderr, "%s: bad value for variable '%s'\n",
1429                          progname, vnam(vc));
1430          quit(1);
1431 + }
1432 +
1433 +
1434 + static char *
1435 + dirfile(                /* separate path into directory and file */
1436 + char    *df,
1437 + register char   *path
1438 + )
1439 + {
1440 +        register int    i;
1441 +        int     psep;
1442 +
1443 +        for (i = 0, psep = -1; path[i]; i++)
1444 +                if (path[i] == '/')
1445 +                        psep = i;
1446 +        if (df != NULL) {
1447 +                if (psep == 0) {
1448 +                        df[0] = '/';
1449 +                        df[1] = '\0';
1450 +                } else if (psep > 0) {
1451 +                        strncpy(df, path, psep);
1452 +                        df[psep] = '\0';
1453 +                } else
1454 +                        df[0] = '\0';
1455 +        }
1456 +        return(path+psep+1);
1457 + }
1458 +
1459 +
1460 + static int
1461 + getblur(double *mbf, double *dbf)       /* get # blur samples (and fraction) */
1462 + {
1463 +        double  mblurf, dblurf;
1464 +        int     nmblur, ndblur;
1465 +        char    *s;
1466 +                                        /* get motion blur */
1467 +        if (vdef(ANIMATE) || !vdef(MBLUR) || (mblurf = atof(vval(MBLUR))) < 0.0)
1468 +                mblurf = 0.0;
1469 +        if (mbf != NULL)
1470 +                *mbf = mblurf;
1471 +        if (mblurf <= FTINY)
1472 +                nmblur = 0;
1473 +        else if (!*(s = sskip(vval(MBLUR))))
1474 +                nmblur = DEF_NBLUR;
1475 +        else if ((nmblur = atoi(s)) <= 0)
1476 +                nmblur = 1;
1477 +                                        /* get depth-of-field blur */
1478 +        if (!vdef(DBLUR) || (dblurf = atof(vval(DBLUR))) < 0.0)
1479 +                dblurf = 0.0;
1480 +        if (dbf != NULL)
1481 +                *dbf = dblurf;
1482 +        if (dblurf <= FTINY)
1483 +                ndblur = 0;
1484 +        else if (!*(s = sskip(vval(DBLUR))))
1485 +                ndblur = DEF_NBLUR;
1486 +        else if ((ndblur = atoi(s)) <= 0)
1487 +                ndblur = 1;
1488 +        if ((nmblur == 1) & (ndblur == 1))
1489 +                return(1);
1490 +                                        /* return combined samples */
1491 +        return(nmblur + ndblur);
1492   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines