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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines