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.15 by greg, Mon Jun 24 09:19:36 1996 UTC vs.
Revision 2.47 by greg, Tue Jun 8 19:48:31 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Radiance animation control program
6 + *
7 + * The main difference between this program and ranimove is that
8 + * we have many optimizations here for camera motion in static
9 + * environments, calling rpict and pinterp on multiple processors,
10 + * where ranimove puts its emphasis on object motion, and does
11 + * not use any external programs for image generation.
12 + *
13 + * See the ranimate(1) man page for further details.
14   */
15  
16 < #include "standard.h"
16 > #include "copyright.h"
17 >
18 > #include <stdio.h>
19   #include <ctype.h>
13 #include <sys/types.h>
20   #include <sys/stat.h>
21 + #include <time.h>
22 + #include <signal.h>
23 +
24 + #include "platform.h"
25 + #include "paths.h"
26 + #include "standard.h"
27   #include "view.h"
28   #include "vars.h"
29   #include "netproc.h"
30 +                                /* default blur samples */
31 + #ifndef DEF_NBLUR
32 + #define DEF_NBLUR       5
33 + #endif
34                                  /* default remote shell */
19 #ifdef _AUX_SOURCE
20 #define REMSH           "remsh"
21 #else
35   #define REMSH           "rsh"
36 < #endif
37 <                                /* input variables */
38 < #define HOST            0               /* rendering host machine */
39 < #define RENDER          1               /* rendering options */
40 < #define PFILT           2               /* pfilt options */
41 < #define PINTERP         3               /* pinterp options */
42 < #define OCTREE          4               /* octree file name */
43 < #define DIRECTORY       5               /* working (sub)directory */
44 < #define BASENAME        6               /* output image base name */
45 < #define VIEWFILE        7               /* animation frame views */
46 < #define START           8               /* starting frame number */
47 < #define END             9               /* ending frame number */
48 < #define RIF             10              /* rad input file */
49 < #define NEXTANIM        11              /* next animation file */
50 < #define ANIMATE         12              /* animation command */
51 < #define TRANSFER        13              /* frame transfer command */
52 < #define ARCHIVE         14              /* archiving command */
53 < #define INTERP          15              /* # frames to interpolate */
54 < #define OVERSAMP        16              /* # times to oversample image */
55 < #define MBLUR           17              /* samples for motion blur */
56 < #define RTRACE          18              /* use rtrace with pinterp? */
57 < #define DISKSPACE       19              /* how much disk space to use */
58 < #define RESOLUTION      20              /* desired final resolution */
59 < #define EXPOSURE        21              /* how to compute exposure */
47 < #define RSH             22              /* remote shell script or program */
36 >                                /* input variables (alphabetical by name) */
37 > #define ANIMATE         0               /* animation command */
38 > #define ARCHIVE         1               /* archiving command */
39 > #define BASENAME        2               /* output image base name */
40 > #define DIRECTORY       3               /* working (sub)directory */
41 > #define DISKSPACE       4               /* how much disk space to use */
42 > #define END             5               /* ending frame number */
43 > #define EXPOSURE        6               /* how to compute exposure */
44 > #define HOST            7               /* rendering host machine */
45 > #define INTERP          8               /* # frames to interpolate */
46 > #define MBLUR           9               /* motion blur parameters */
47 > #define NEXTANIM        10              /* next animation file */
48 > #define OCTREE          11              /* octree file name */
49 > #define OVERSAMP        12              /* # times to oversample image */
50 > #define PFILT           13              /* pfilt options */
51 > #define PINTERP         14              /* pinterp options */
52 > #define RENDER          15              /* rendering options */
53 > #define RESOLUTION      16              /* desired final resolution */
54 > #define RIF             17              /* rad input file */
55 > #define RSH             18              /* remote shell script or program */
56 > #define RTRACE          19              /* use rtrace with pinterp? */
57 > #define START           20              /* starting frame number */
58 > #define TRANSFER        21              /* frame transfer command */
59 > #define VIEWFILE        22              /* animation frame views */
60  
61   int     NVARS = 23;             /* total number of variables */
62  
63   VARIABLE        vv[] = {                /* variable-value pairs */
52        {"host",        4,      0,      NULL,   NULL},
53        {"render",      3,      0,      NULL,   catvalues},
54        {"pfilt",       2,      0,      NULL,   catvalues},
55        {"pinterp",     2,      0,      NULL,   catvalues},
56        {"OCTREE",      3,      0,      NULL,   onevalue},
57        {"DIRECTORY",   3,      0,      NULL,   onevalue},
58        {"BASENAME",    3,      0,      NULL,   onevalue},
59        {"VIEWFILE",    2,      0,      NULL,   onevalue},
60        {"START",       2,      0,      NULL,   intvalue},
61        {"END",         2,      0,      NULL,   intvalue},
62        {"RIF",         3,      0,      NULL,   onevalue},
63        {"NEXTANIM",    3,      0,      NULL,   onevalue},
64          {"ANIMATE",     2,      0,      NULL,   onevalue},
65        {"TRANSFER",    2,      0,      NULL,   onevalue},
65          {"ARCHIVE",     2,      0,      NULL,   onevalue},
66 +        {"BASENAME",    3,      0,      NULL,   onevalue},
67 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
68 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
69 +        {"END",         2,      0,      NULL,   intvalue},
70 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
71 +        {"host",        4,      0,      NULL,   NULL},
72          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
68        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
73          {"MBLUR",       2,      0,      NULL,   onevalue},
74 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
75 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
74 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
75 >        {"OCTREE",      3,      0,      NULL,   onevalue},
76 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
77 >        {"pfilt",       2,      0,      NULL,   catvalues},
78 >        {"pinterp",     2,      0,      NULL,   catvalues},
79 >        {"render",      3,      0,      NULL,   catvalues},
80          {"RESOLUTION",  3,      0,      NULL,   onevalue},
81 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
81 >        {"RIF",         3,      0,      NULL,   onevalue},
82          {"RSH",         3,      0,      NULL,   onevalue},
83 +        {"RTRACE",      2,      0,      NULL,   boolvalue},
84 +        {"START",       2,      0,      NULL,   intvalue},
85 +        {"TRANSFER",    2,      0,      NULL,   onevalue},
86 +        {"VIEWFILE",    2,      0,      NULL,   onevalue},
87   };
88  
89   #define SFNAME  "STATUS"                /* status file name */
# Line 93 | Line 105 | int    silent = 0;             /* silent mode? */
105   int     noaction = 0;           /* take no action? */
106  
107   char    *remsh;                 /* remote shell program/script */
108 < char    rendopt[2048] = "";     /* rendering options */
108 > char    rendopt[2048];          /* rendering options */
109   char    rresopt[32];            /* rendering resolution options */
110   char    fresopt[32];            /* filter resolution options */
111   int     pfiltalways;            /* always use pfilt? */
# Line 108 | Line 120 | struct pslot {
120   }       *pslot;                 /* process slots */
121   int     npslots;                /* number of process slots */
122  
111 int     lastpid;                /* ID of last completed background process */
112 PSERVER *lastpserver;           /* last process server used */
113
123   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
124 + PSERVER *lastpserver;           /* last process server with error */
125  
126 < struct pslot    *findpslot();
126 > static struct pslot * findpslot(int pid);
127 > static void checkdir(void);
128 > static VIEW * getview(int n);
129  
130 < VIEW    *getview();
131 < char    *getexp();
130 > static char * dirfile(char *df, register char *path);
131 > static char * getexp(int n);
132 > static int getblur(double *bf);
133 > static int getastat(void);
134 > static void getradfile(char *rfargs);
135 > static void badvalue(int vc);
136 > static int rmfile(char *fn);
137 > static int runcom(char *cs);
138 > static int pruncom(char *com, char *ppins, int maxcopies);
139 > static void bwait(int ncoms);
140 > static int bruncom(char *com, int fout, int (*rf)());
141 > static int serverdown(void);
142 > static pscompfunc donecom;
143 > static int countviews(void);
144 > static int dofilt(int frame, int rvr);
145 > static void archive(void);
146 > static int frecover(int frame);
147 > static int recover(int frame);
148 > static void sethosts(void);
149 > static void walkwait(int first, int last, char *vfn);
150 > static void animrend(int frame, VIEW *vp);
151 > static void transferframes(void);
152 > static void filterframes(void);
153 > static void renderframes(int nframes);
154 > static void animate(void);
155 > static void setdefaults(void);
156 > static void putastat(void);
157  
121 extern time_t   fdate(), time();
158  
159 <
160 < main(argc, argv)
161 < int     argc;
162 < char    *argv[];
159 > int
160 > main(
161 >        int     argc,
162 >        char    *argv[]
163 > )
164   {
165          int     explicate = 0;
166          int     i;
# Line 151 | Line 188 | char   *argv[];
188          cfname = argv[i];
189                                                  /* load variables */
190          loadvars(cfname);
191 +                                                /* check variables */
192 +        checkvalues();
193                                                  /* did we get DIRECTORY? */
194          checkdir();
195                                                  /* check status */
# Line 184 | Line 223 | char   *argv[];
223                  quit(1);
224          }
225          quit(0);
226 +        return 0; /* pro forma return */
227   userr:
228          fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
229          quit(1);
230 +        return 1; /* pro forma return */
231   }
232  
233  
234 < getastat()                      /* check/set animation status */
234 > static int
235 > getastat(void)                  /* check/set animation status */
236   {
237          char    sfname[256];
238          FILE    *fp;
# Line 231 | Line 273 | getastat()                     /* check/set animation status */
273                  }
274                  /* assume it is dead */
275          }
276 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
276 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
277                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
278                                  progname, astat.cfname);
279                  return(-1);
# Line 254 | Line 296 | fmterr:
296   }
297  
298  
299 < putastat()                      /* put out current status */
299 > static void
300 > putastat(void)                  /* put out current status */
301   {
302          char    buf[256];
303          FILE    *fp;
# Line 276 | Line 319 | putastat()                     /* put out current status */
319   }
320  
321  
322 < checkdir()                      /* make sure we have our directory */
322 > static void
323 > checkdir(void)                  /* make sure we have our directory */
324   {
325          struct stat     stb;
326  
# Line 298 | Line 342 | checkdir()                     /* make sure we have our directory */
342   }
343  
344  
345 < setdefaults()                   /* set default values */
345 > static void
346 > setdefaults(void)                       /* set default values */
347   {
348          extern char     *atos();
349 +        int     decades;
350          char    buf[256];
351  
352          if (vdef(ANIMATE)) {
# Line 334 | Line 380 | setdefaults()                  /* set default values */
380                  quit(1);
381          }
382          if (!vdef(BASENAME)) {
383 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
383 >                decades = (int)log10((double)vint(END)) + 1;
384 >                if (decades < 3) decades = 3;
385 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
386                  vval(BASENAME) = savqstr(buf);
387                  vdef(BASENAME)++;
388          }
# Line 383 | Line 431 | setdefaults()                  /* set default values */
431   }
432  
433  
434 < sethosts()                      /* set up process servers */
434 > static void
435 > sethosts(void)                  /* set up process servers */
436   {
437          extern char     *iskip();
438          char    buf[256], *dir, *uname;
# Line 438 | Line 487 | sethosts()                     /* set up process servers */
487          }
488   }
489  
490 <
491 < getradfile(rfargs)              /* run rad and get needed variables */
443 < char    *rfargs;
490 > static void
491 > getradfile(char *rfargs)                /* run rad and get needed variables */
492   {
493          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
494          char    combuf[256];
495          register int    i;
496          register char   *cp;
497 +        char    *pippt = NULL;
498                                          /* create rad command */
499          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
500          sprintf(combuf,
501          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
502                          rfargs, rendopt+2);
503          cp = combuf;
504 <        while (*cp) cp++;               /* match unset variables */
504 >        while (*cp) {
505 >                if (*cp == '|') pippt = cp;
506 >                cp++;
507 >        }                               /* match unset variables */
508          for (i = 0; mvar[i] >= 0; i++)
509                  if (!vdef(mvar[i])) {
510                          *cp++ = '|';
511                          strcpy(cp, vnam(mvar[i]));
512                          while (*cp) cp++;
513 +                        pippt = NULL;
514                  }
515 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
516 <        cp += 11;                       /* point to file name */
517 <        if (system(combuf)) {
518 <                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
519 <                                progname, combuf);
467 <                quit(1);
515 >        if (pippt != NULL)
516 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
517 >        else {
518 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
519 >                cp += 11;               /* point to file name */
520          }
521 <        loadvars(cp);                   /* load variables and remove file */
522 <        unlink(cp);
521 >        system(combuf);                 /* ignore exit code */
522 >        if (pippt == NULL) {            /* load variables and remove file */
523 >                loadvars(cp);
524 >                unlink(cp);
525 >        }
526   }
527  
528  
529 < animate()                       /* run animation */
529 > static void
530 > animate(void)                   /* run animation */
531   {
532          int     xres, yres;
533          float   pa, mult;
# Line 482 | Line 538 | animate()                      /* run animation */
538          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
539          mult = vflt(OVERSAMP);
540          if (i == 3) {
541 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
541 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
542                                  (int)(mult*yres), pa);
543 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
543 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
544          } else if (i) {
545                  if (i == 1) yres = xres;
546                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 501 | Line 557 | animate()                      /* run animation */
557                                                  progname, vnam(INTERP));
558                          vval(INTERP) = "0";
559                  }
560 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
560 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
561                          if (!nowarn)
562                                  fprintf(stderr,
563                                          "%s: resetting %s=0 for animation\n",
# Line 511 | Line 567 | animate()                      /* run animation */
567          }
568                                          /* figure # frames per batch */
569          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
570 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
570 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
571                  d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
572          d2 = xres*yres*4;                       /* space for final picture */
573          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
# Line 521 | Line 577 | animate()                      /* run animation */
577                  quit(1);
578          }
579                                          /* initialize archive argument list */
580 <        i = 16;
525 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
526 <                i = strlen(vval(ARCHIVE));
580 >        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
581          arcnext = arcfirst = arcargs + i;
582                                          /* initialize status file */
583          if (astat.rnext == 0)
# Line 544 | Line 598 | animate()                      /* run animation */
598   }
599  
600  
601 < renderframes(nframes)           /* render next nframes frames */
602 < int     nframes;
601 > static void
602 > renderframes(int nframes)               /* render next nframes frames */
603   {
604          static char     vendbuf[16];
605          VIEW    *vp;
# Line 601 | Line 655 | int    nframes;
655   }
656  
657  
658 < filterframes()                          /* catch up with filtering */
658 > static void
659 > filterframes(void)                              /* catch up with filtering */
660   {
606        VIEW    *vp;
661          register int    i;
662  
663          if (astat.tnext < astat.fnext)  /* other work to do first */
664                  return;
665                                          /* filter each view */
666 <        for (i = astat.fnext; i < astat.rnext; i++) {
667 <                if ((vp = getview(i)) == NULL) {        /* get view i */
668 <                        fprintf(stderr,
615 <                        "%s: unexpected error reading view for frame %d\n",
616 <                                        progname, i);
617 <                        quit(1);
618 <                }
619 <                dofilt(i, vp, getexp(i), 0);            /* filter frame */
620 <        }
666 >        for (i = astat.fnext; i < astat.rnext; i++)
667 >                dofilt(i, 0);
668 >
669          bwait(0);                       /* wait for filter processes */
670          archive();                      /* archive originals */
671          astat.fnext = i;                /* update status */
# Line 625 | Line 673 | filterframes()                         /* catch up with filtering */
673   }
674  
675  
676 < transferframes()                        /* catch up with picture transfers */
676 > static void
677 > transferframes(void)                    /* catch up with picture transfers */
678   {
679 <        char    combuf[10240];
679 >        char    combuf[10240], *fbase;
680          register char   *cp;
681          register int    i;
682  
# Line 638 | Line 687 | transferframes()                       /* catch up with picture transfers
687                  putastat();             /* update status */
688                  return;
689          }
690 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
691 <        cp = combuf + strlen(combuf);
690 >        strcpy(combuf, "cd ");          /* start transfer command */
691 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
692 >        if (*cp) {
693 >                while (*++cp) ;
694 >                *cp++ = ';'; *cp++ = ' ';
695 >        } else
696 >                cp = combuf;
697 >        strcpy(cp, vval(TRANSFER));
698 >        while (*cp) cp++;
699                                          /* make argument list */
700          for (i = astat.tnext; i < astat.fnext; i++) {
701                  *cp++ = ' ';
702 <                sprintf(cp, vval(BASENAME), i);
702 >                sprintf(cp, fbase, i);
703                  while (*cp) cp++;
704                  strcpy(cp, ".pic");
705                  cp += 4;
# Line 658 | Line 714 | transferframes()                       /* catch up with picture transfers
714   }
715  
716  
717 < animrend(frame, vp)                     /* start animation frame */
718 < int     frame;
719 < VIEW    *vp;
717 > static void
718 > animrend(                       /* start animation frame */
719 > int     frame,
720 > VIEW    *vp
721 > )
722   {
665        extern int      recover();
723          char    combuf[2048];
724          char    fname[128];
725  
# Line 676 | Line 733 | VIEW   *vp;
733   }
734  
735  
736 < walkwait(first, last, vfn)              /* walk-through frames */
737 < int     first, last;
738 < char    *vfn;
736 > static void
737 > walkwait(               /* walk-through frames */
738 > int     first,
739 > int last,
740 > char    *vfn
741 > )
742   {
743 +        double  blurf;
744 +        int     nblur = getblur(&blurf);
745          char    combuf[2048];
746 <        char    *inspoint;
746 >        register char   *inspoint;
747          register int    i;
748  
749          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 692 | Line 754 | char   *vfn;
754                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
755                          }
756                                          /* create command */
757 <        sprintf(combuf, "rpict%s -w0", rendopt);
758 <        if (vint(INTERP) || atoi(vval(MBLUR)))
759 <                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
760 <        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
757 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
758 >                        viewopt(getview(first>1 ? first-1 : 1)));
759 >        inspoint = combuf;
760 >        while (*inspoint) inspoint++;
761 >        if (nblur) {
762 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
763 >                while (*inspoint) inspoint++;
764 >        }
765 >        if (nblur > 1 || vint(INTERP)) {
766 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
767 >                while (*inspoint) inspoint++;
768 >        }
769 >        sprintf(inspoint, " -o %s.unf %s -S %d",
770                          vval(BASENAME), rresopt, first);
771 <        inspoint = combuf + strlen(combuf);
771 >        while (*inspoint) inspoint++;
772          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
773                                          /* run in parallel */
774          i = (last-first+1)/(vint(INTERP)+1);
# Line 717 | Line 788 | char   *vfn;
788   }
789  
790  
791 < int
792 < recover(frame)                          /* recover the specified frame */
722 < int     frame;
791 > static int
792 > recover(int frame)                      /* recover the specified frame */
793   {
794          static int      *rfrm;          /* list of recovered frames */
795          static int      nrfrms = 0;
796 +        double  blurf;
797 +        int     nblur = getblur(&blurf);
798          char    combuf[2048];
799          char    fname[128];
800          register char   *cp;
# Line 738 | Line 810 | int    frame;
810                                  vval(ANIMATE), frame, rendopt);
811          else
812                  sprintf(combuf, "rpict%s -w0", rendopt);
813 <        cp = combuf + strlen(combuf);
814 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
813 >        cp = combuf;
814 >        while (*cp) cp++;
815 >        if (nblur) {
816 >                sprintf(cp, " -pm %.3f", blurf/nblur);
817 >                while (*cp) cp++;
818 >        }
819 >        if (nblur > 1 || vint(INTERP)) {
820                  sprintf(cp, " -z %s.zbf", fname);
821                  while (*cp) cp++;
822          }
# Line 753 | Line 830 | int    frame;
830                  return(1);
831                                          /* add frame to recovered list */
832          if (nrfrms)
833 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
833 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
834          else
835                  rfrm = (int *)malloc(sizeof(int));
836          if (rfrm == NULL) {
# Line 765 | Line 842 | int    frame;
842   }
843  
844  
845 < int
846 < frecover(frame)                         /* recover filtered frame */
770 < int     frame;
845 > static int
846 > frecover(int frame)                             /* recover filtered frame */
847   {
848 <        VIEW    *vp;
773 <        char    *ex;
774 <
775 <        vp = getview(frame);
776 <        ex = getexp(frame);
777 <        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
848 >        if (dofilt(frame, 2) && dofilt(frame, 1))
849                  return(1);
850          return(0);
851   }
852  
853  
854 < archive()                       /* archive and remove renderings */
854 > static void
855 > archive(void)                   /* archive and remove renderings */
856   {
857   #define RMCOML  (sizeof(rmcom)-1)
858          static char     rmcom[] = "rm -f";
859 <        register int    i;
859 >        char    basedir[128];
860 >        int     dlen, alen;
861 >        register int    j;
862  
863          if (arcnext == arcfirst)
864                  return;                         /* nothing to do */
865 +        dirfile(basedir, vval(BASENAME));
866 +        dlen = strlen(basedir);
867          if (vdef(ARCHIVE)) {                    /* run archive command */
868 <                i = strlen(vval(ARCHIVE));
869 <                strncpy(arcfirst-i, vval(ARCHIVE), i);
870 <                if (runcom(arcfirst-i)) {
868 >                alen = strlen(vval(ARCHIVE));
869 >                if (dlen) {
870 >                        j = alen + dlen + 5;
871 >                        strncpy(arcfirst-j, "cd ", 3);
872 >                        strncpy(arcfirst-j+3, basedir, dlen);
873 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
874 >                } else
875 >                        j = alen;
876 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
877 >                if (runcom(arcfirst-j)) {
878                          fprintf(stderr, "%s: error running archive command\n",
879                                          progname);
880                          quit(1);
881                  }
882          }
883 +        if (dlen) {
884 +                j = RMCOML + dlen + 5;
885 +                strncpy(arcfirst-j, "cd ", 3);
886 +                strncpy(arcfirst-j+3, basedir, dlen);
887 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
888 +        } else
889 +                j = RMCOML;
890                                                  /* run remove command */
891          strncpy(arcfirst-RMCOML, rmcom, RMCOML);
892 <        runcom(arcfirst-RMCOML);
892 >        runcom(arcfirst-j);
893          arcnext = arcfirst;                     /* reset argument list */
894   #undef RMCOML
895   }
896  
897  
898 < int
899 < dofilt(frame, vp, ep, rvr)                      /* filter frame */
900 < int     frame;
901 < VIEW    *vp;
902 < char    *ep;
813 < int     rvr;
898 > static int
899 > dofilt(                         /* filter frame */
900 > int     frame,
901 > int     rvr
902 > )
903   {
815        extern int      frecover();
904          static int      iter = 0;
905 <        char    fnbefore[128], fnafter[128];
905 >        double  blurf;
906 >        int     nblur = getblur(&blurf);
907 >        VIEW    *vp = getview(frame);
908 >        char    *ep = getexp(frame);
909 >        char    fnbefore[128], fnafter[128], *fbase;
910          char    combuf[1024], fname0[128], fname1[128];
911          int     usepinterp, usepfilt, nora_rgbe;
912          int     frseq[2];
913                                                  /* check what is needed */
914 <        usepinterp = atoi(vval(MBLUR));
915 <        usepfilt = pfiltalways | ep==NULL;
914 >        if (vp == NULL) {
915 >                 fprintf(stderr,
916 >                        "%s: unexpected error reading view for frame %d\n",
917 >                                          progname, frame);
918 >                quit(1);
919 >        }
920 >        usepinterp = (nblur > 1);
921 >        usepfilt = pfiltalways | (ep==NULL);
922          if (ep != NULL && !strcmp(ep, "1"))
923                  ep = "+0";
924          nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
# Line 828 | Line 926 | int    rvr;
926                                                  /* compute rendered views */
927          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
928          frseq[1] = frseq[0] + vint(INTERP) + 1;
929 +        fbase = dirfile(NULL, vval(BASENAME));
930          if (frseq[1] > vint(END))
931                  frseq[1] = vint(END);
932          if (frseq[1] == frame) {                        /* pfilt only */
# Line 837 | Line 936 | int    rvr;
936          } else if (frseq[0] == frame) {         /* no interpolation needed */
937                  if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
938                          *arcnext++ = ' ';
939 <                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
939 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
940                          while (*arcnext) arcnext++;
941                          strcpy(arcnext, ".unf");
942                          arcnext += 4;
943                          if (usepinterp || vint(INTERP)) {       /* and Z-buf */
944                                  *arcnext++ = ' ';
945 <                                sprintf(arcnext, vval(BASENAME),
847 <                                                frame-vint(INTERP)-1);
945 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
946                                  while (*arcnext) arcnext++;
947                                  strcpy(arcnext, ".zbf");
948                                  arcnext += 4;
# Line 864 | Line 962 | int    rvr;
962          if (usepinterp) {                       /* using pinterp */
963                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
964                          return(1);
965 <                if (atoi(vval(MBLUR))) {
868 <                        FILE    *fp;            /* motion blurring */
965 >                if (nblur > 1) {                /* with pmblur */
966                          sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
967                                          'a'+(iter%26));
871                        if ((fp = fopen(fname0, "w")) == NULL) {
872                                perror(fname0); quit(1);
873                        }
874                        fputs(VIEWSTR, fp);
875                        fprintview(vp, fp);
876                        putc('\n', fp); fclose(fp);
877                        if ((vp = getview(frame+1)) == NULL) {
878                                fprintf(stderr,
879                        "%s: unexpected error reading view for frame %d\n",
880                                                progname, frame+1);
881                                quit(1);
882                        }
968                          sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
969                                          'a'+(iter%26));
970 <                        if ((fp = fopen(fname1, "w")) == NULL) {
971 <                                perror(fname1); quit(1);
970 >                        if (!noaction) {
971 >                                FILE    *fp;            /* motion blurring */
972 >                                if ((fp = fopen(fname0, "w")) == NULL) {
973 >                                        perror(fname0); quit(1);
974 >                                }
975 >                                fputs(VIEWSTR, fp);
976 >                                fprintview(vp, fp);
977 >                                putc('\n', fp); fclose(fp);
978 >                                if ((vp = getview(frame+1)) == NULL) {
979 >                                        fprintf(stderr,
980 >                        "%s: unexpected error reading view for frame %d\n",
981 >                                                        progname, frame+1);
982 >                                        quit(1);
983 >                                }
984 >                                if ((fp = fopen(fname1, "w")) == NULL) {
985 >                                        perror(fname1); quit(1);
986 >                                }
987 >                                fputs(VIEWSTR, fp);
988 >                                fprintview(vp, fp);
989 >                                putc('\n', fp); fclose(fp);
990                          }
888                        fputs(VIEWSTR, fp);
889                        fprintview(vp, fp);
890                        putc('\n', fp); fclose(fp);
991                          sprintf(combuf,
992 <                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
993 <                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
894 <                                        atoi(vval(MBLUR)),
992 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
993 >                                        blurf, nblur,
994                                          fname0, fname1, fname0, fname1);
995                          iter++;
996                  } else                          /* no blurring */
# Line 899 | Line 998 | int    rvr;
998                  strcat(combuf, viewopt(vp));
999                  if (vbool(RTRACE))
1000                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1001 <                                        rendopt, vval(OCTREE));
1001 >                                        rendopt+1, vval(OCTREE));
1002                  if (vdef(PINTERP))
1003                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1004                  if (usepfilt)
1005                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1006                  else
1007 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1007 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1008                                          fresopt, ep);
1009                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1010                                  fnbefore, fnbefore);
# Line 952 | Line 1051 | int    rvr;
1051   }
1052  
1053  
1054 < VIEW *
1055 < getview(n)                      /* get view number n */
957 < int     n;
1054 > static VIEW *
1055 > getview(int n)                  /* get view number n */
1056   {
1057          static FILE     *viewfp = NULL;         /* view file pointer */
1058          static int      viewnum = 0;            /* current view number */
# Line 966 | Line 1064 | int    n;
1064                          fclose(viewfp);
1065                          viewfp = NULL;
1066                          viewnum = 0;
1067 <                        copystruct(&curview, &stdview);
1067 >                        curview = stdview;
1068                  }
1069                  return(NULL);
1070          }
1071 <        if (viewfp == NULL) {           /* open file */
1071 >        if (viewfp == NULL) {                   /* open file */
1072                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1073                          perror(vval(VIEWFILE));
1074                          quit(1);
1075                  }
1076 <        } else if (n < viewnum) {       /* rewind file */
1076 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1077                  if (viewnum == 1 && feof(viewfp))
1078                          return(&curview);               /* just one view */
1079                  if (fseek(viewfp, 0L, 0) == EOF) {
1080                          perror(vval(VIEWFILE));
1081                          quit(1);
1082                  }
1083 <                copystruct(&curview, &stdview);
1083 >                curview = stdview;
1084                  viewnum = 0;
1085          }
1086 +        if (n < 0) {                            /* get next view */
1087 +                register int    c = getc(viewfp);
1088 +                if (c == EOF)
1089 +                        return((VIEW *)NULL);           /* that's it */
1090 +                ungetc(c, viewfp);
1091 +                n = viewnum + 1;
1092 +        }
1093          while (n > viewnum) {           /* scan to desired view */
1094                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1095                          return(viewnum==1 ? &curview : (VIEW *)NULL);
# Line 995 | Line 1100 | int    n;
1100   }
1101  
1102  
1103 < int
1104 < countviews()                    /* count views in view file */
1103 > static int
1104 > countviews(void)                        /* count views in view file */
1105   {
1106 <        register int    n = 0;
1106 >        int     n;
1107  
1108 <        while (getview(n+1) != NULL)
1108 >        if (getview(n=1) == NULL)
1109 >                return(0);
1110 >        while (getview(-1) != NULL)
1111                  n++;
1112          return(n);
1113   }
1114  
1115  
1116 < char *
1117 < getexp(n)                       /* get exposure for nth frame */
1011 < int     n;
1116 > static char *
1117 > getexp(int n)                   /* get exposure for nth frame */
1118   {
1119          extern char     *fskip();
1120          static char     expval[32];
# Line 1020 | Line 1126 | int    n;
1126          if (n == 0) {                           /* signal to close file */
1127                  if (expfp != NULL) {
1128                          fclose(expfp);
1129 <                        free((char *)exppos);
1129 >                        free((void *)exppos);
1130                          expfp = NULL;
1131                  }
1132                  return(NULL);
# Line 1077 | Line 1183 | int    n;
1183   }
1184  
1185  
1186 < struct pslot *
1187 < findpslot(pid)                  /* find or allocate a process slot */
1082 < int     pid;
1186 > static struct pslot *
1187 > findpslot(int pid)                      /* find or allocate a process slot */
1188   {
1189          register struct pslot   *psempty = NULL;
1190          register int    i;
# Line 1094 | Line 1199 | int    pid;
1199   }
1200  
1201  
1202 < int
1203 < donecom(ps, pn, status)         /* clean up after finished process */
1204 < PSERVER *ps;
1205 < int     pn;
1206 < int     status;
1202 > static int
1203 > donecom(                /* clean up after finished process */
1204 >        PSERVER *ps,
1205 >        int     pn,
1206 >        int     status
1207 > )
1208   {
1209 <        register PROC   *pp;
1209 >        register NETPROC        *pp;
1210 >        register struct pslot   *psl;
1211  
1212          pp = ps->proc + pn;
1213          if (pp->elen) {                 /* pass errors */
# Line 1112 | Line 1219 | int    status;
1219                  if (ps->hostname[0])
1220                          status = 1;     /* because rsh doesn't return status */
1221          }
1222 +        lastpserver = NULL;
1223 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1224 +        if (psl->pid) {
1225 +                if (status) {
1226 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1227 +                                status = (*psl->rcvf)(psl->fout);
1228 +                        if (status) {
1229 +                                fprintf(stderr,
1230 +                                        "%s: error rendering frame %d\n",
1231 +                                                progname, psl->fout);
1232 +                                quit(1);
1233 +                        }
1234 +                        lastpserver = ps;
1235 +                }
1236 +                psl->pid = 0;                   /* free process slot */
1237 +        } else if (status)
1238 +                lastpserver = ps;
1239          freestr(pp->com);               /* free command string */
1116        lastpid = pp->pid;              /* record PID for bwait() */
1117        lastpserver = ps;               /* record server for serverdown() */
1240          return(status);
1241   }
1242  
1243  
1244 < int
1245 < serverdown()                    /* check status of last process server */
1244 > static int
1245 > serverdown(void)                        /* check status of last process server */
1246   {
1247 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1248 +                return(0);
1249          if (pserverOK(lastpserver))     /* server still up? */
1250                  return(0);
1251          delpserver(lastpserver);        /* else delete it */
# Line 1134 | Line 1258 | serverdown()                   /* check status of last process server
1258   }
1259  
1260  
1261 < int
1262 < bruncom(com, fout, rf)          /* run a command in the background */
1263 < char    *com;
1264 < int     fout;
1265 < int     (*rf)();
1261 > static int
1262 > bruncom(                /* run a command in the background */
1263 > char    *com,
1264 > int     fout,
1265 > int     (*rf)()
1266 > )
1267   {
1268          int     pid;
1269          register struct pslot   *psl;
# Line 1148 | Line 1273 | int    (*rf)();
1273                          printf("\t%s\n", com);  /* echo command */
1274                  return(0);
1275          }
1276 <                                        /* else start it when we can */
1277 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1276 >        com = savestr(com);             /* else start it when we can */
1277 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1278                  bwait(1);
1279          if (!silent) {                          /* echo command */
1280                  PSERVER *ps;
# Line 1167 | Line 1292 | int    (*rf)();
1292   }
1293  
1294  
1295 < bwait(ncoms)                            /* wait for batch job(s) to finish */
1296 < int     ncoms;
1295 > static void
1296 > bwait(int ncoms)                                /* wait for batch job(s) to finish */
1297   {
1298          int     status;
1174        register struct pslot   *psl;
1299  
1300          if (noaction)
1301                  return;
1302          while ((status = wait4job(NULL, -1)) != -1) {
1303 <                psl = findpslot(lastpid);
1304 <                if (status) {           /* attempt recovery */
1305 <                        serverdown();   /* check server */
1182 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1183 <                                fprintf(stderr,
1184 <                                        "%s: error rendering frame %d\n",
1185 <                                                progname, psl->fout);
1186 <                                quit(1);
1187 <                        }
1188 <                }
1189 <                psl->pid = 0;           /* free process slot */
1190 <                if (!--ncoms)
1191 <                        return;         /* done enough */
1303 >                serverdown();           /* update server status */
1304 >                if (--ncoms == 0)
1305 >                        break;          /* done enough */
1306          }
1307   }
1308  
1309  
1310 < int
1311 < pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1312 < char    *com, *ppins;
1313 < int     maxcopies;
1310 > static int
1311 > pruncom(        /* run a command in parallel over network */
1312 > char    *com,
1313 > char    *ppins,
1314 > int     maxcopies
1315 > )
1316   {
1317          int     retstatus = 0;
1318          int     hostcopies;
1319 <        char    com1buf[10240], *com1, *endcom1;
1319 >        char    buf[10240], *com1, *s;
1320          int     status;
1321 +        int     pfd;
1322 +        register int    n;
1323          register PSERVER        *ps;
1324  
1325          if (!silent)
# Line 1213 | Line 1331 | int    maxcopies;
1331          for (ps = pslist; ps != NULL; ps = ps->next) {
1332                  hostcopies = 0;
1333                  if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1334 <                        strcpy(com1=com1buf, com);      /* build -PP command */
1334 >                        strcpy(com1=buf, com);  /* build -PP command */
1335                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1336                                          vval(DIRECTORY), phostname(ps));
1337 +                        unlink(com1+(ppins-com)+5);
1338                          strcat(com1, ppins);
1339 <                        endcom1 = com1 + strlen(com1);
1221 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1222 <                                        vval(DIRECTORY), phostname(ps));
1223 <                } else {
1339 >                } else
1340                          com1 = com;
1341 <                        endcom1 = NULL;
1341 >                while (maxcopies > 0) {
1342 >                        s = savestr(com1);
1343 >                        if (startjob(ps, s, donecom) != -1) {
1344 >                                sleep(20);
1345 >                                hostcopies++;
1346 >                                maxcopies--;
1347 >                        } else {
1348 >                                freestr(s);
1349 >                                break;
1350 >                        }
1351                  }
1227                while (maxcopies > 0 &&
1228                                startjob(ps, savestr(com1), donecom) != -1) {
1229                        sleep(10);
1230                        hostcopies++;
1231                        maxcopies--;
1232                        if (endcom1 != NULL)
1233                                *endcom1 = '\0';
1234                }
1352                  if (!silent && hostcopies) {
1353                          if (hostcopies > 1)
1354                                  printf("\t%d duplicate processes", hostcopies);
# Line 1243 | Line 1360 | int    maxcopies;
1360          }
1361                                          /* wait for jobs to finish */
1362          while ((status = wait4job(NULL, -1)) != -1)
1363 <                if (status)
1364 <                        retstatus += !serverdown();     /* check server */
1363 >                retstatus += status && !serverdown();
1364 >                                        /* terminate parallel rpict's */
1365 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1366 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1367 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1368 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1369 >                        buf[n] = '\0';
1370 >                        close(pfd);
1371 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1372 >                                ;
1373 >                                                                /* terminate */
1374 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1375 >                        wait4job(ps, startjob(ps, buf, NULL));
1376 >                }
1377 >        }
1378          return(retstatus);
1379   }
1380  
1381  
1382 < runcom(cs)                      /* run a command locally and wait for it */
1383 < char    *cs;
1382 > static int
1383 > runcom(char *cs)                        /* run a command locally and wait for it */
1384   {
1385          if (!silent)            /* echo it */
1386                  printf("\t%s\n", cs);
# Line 1261 | Line 1391 | char   *cs;
1391   }
1392  
1393  
1394 < rmfile(fn)                      /* remove a file */
1395 < char    *fn;
1394 > static int
1395 > rmfile(char *fn)                        /* remove a file */
1396   {
1397          if (!silent)
1398 < #ifdef MSDOS
1398 > #ifdef _WIN32
1399                  printf("\tdel %s\n", fn);
1400   #else
1401                  printf("\trm -f %s\n", fn);
# Line 1276 | Line 1406 | char   *fn;
1406   }
1407  
1408  
1409 < badvalue(vc)                    /* report bad variable value and exit */
1410 < int     vc;
1409 > static void
1410 > badvalue(int vc)                        /* report bad variable value and exit */
1411   {
1412          fprintf(stderr, "%s: bad value for variable '%s'\n",
1413                          progname, vnam(vc));
1414          quit(1);
1415 + }
1416 +
1417 +
1418 + static char *
1419 + dirfile(                /* separate path into directory and file */
1420 + char    *df,
1421 + register char   *path
1422 + )
1423 + {
1424 +        register int    i;
1425 +        int     psep;
1426 +
1427 +        for (i = 0, psep = -1; path[i]; i++)
1428 +                if (path[i] == '/')
1429 +                        psep = i;
1430 +        if (df != NULL) {
1431 +                if (psep == 0) {
1432 +                        df[0] = '/';
1433 +                        df[1] = '\0';
1434 +                } else if (psep > 0) {
1435 +                        strncpy(df, path, psep);
1436 +                        df[psep] = '\0';
1437 +                } else
1438 +                        df[0] = '\0';
1439 +        }
1440 +        return(path+psep+1);
1441 + }
1442 +
1443 +
1444 + static int
1445 + getblur(double *bf)             /* get # blur samples (and fraction) */
1446 + {
1447 +        double  blurf;
1448 +        int     nblur;
1449 +        char    *s;
1450 +
1451 +        if (!vdef(MBLUR)) {
1452 +                if (bf != NULL)
1453 +                        *bf = 0.0;
1454 +                return(0);
1455 +        }
1456 +        blurf = atof(vval(MBLUR));
1457 +        if (blurf < 0.0)
1458 +                blurf = 0.0;
1459 +        if (bf != NULL)
1460 +                *bf = blurf;
1461 +        if (blurf <= FTINY)
1462 +                return(0);
1463 +        s = sskip(vval(MBLUR));
1464 +        if (!*s)
1465 +                return(DEF_NBLUR);
1466 +        nblur = atoi(s);
1467 +        if (nblur <= 0)
1468 +                return(1);
1469 +        return(nblur);
1470   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines