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.18 by greg, Mon Jul 8 14:53:17 1996 UTC vs.
Revision 2.44 by greg, Tue Dec 9 22:46:41 2003 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 +
23 + /*#include "standard.h"*/
24 + #include "platform.h"
25 + #include "paths.h"
26 + #include "rtio.h"
27 + #include "rterror.h"
28   #include "view.h"
29   #include "vars.h"
30   #include "netproc.h"
31 +                                /* default blur samples */
32 + #ifndef DEF_NBLUR
33 + #define DEF_NBLUR       5
34 + #endif
35                                  /* default remote shell */
19 #ifdef _AUX_SOURCE
20 #define REMSH           "remsh"
21 #else
36   #define REMSH           "rsh"
37 < #endif
38 <                                /* input variables */
39 < #define HOST            0               /* rendering host machine */
40 < #define RENDER          1               /* rendering options */
41 < #define PFILT           2               /* pfilt options */
42 < #define PINTERP         3               /* pinterp options */
43 < #define OCTREE          4               /* octree file name */
44 < #define DIRECTORY       5               /* working (sub)directory */
45 < #define BASENAME        6               /* output image base name */
46 < #define VIEWFILE        7               /* animation frame views */
47 < #define START           8               /* starting frame number */
48 < #define END             9               /* ending frame number */
49 < #define RIF             10              /* rad input file */
50 < #define NEXTANIM        11              /* next animation file */
51 < #define ANIMATE         12              /* animation command */
52 < #define TRANSFER        13              /* frame transfer command */
53 < #define ARCHIVE         14              /* archiving command */
54 < #define INTERP          15              /* # frames to interpolate */
55 < #define OVERSAMP        16              /* # times to oversample image */
56 < #define MBLUR           17              /* samples for motion blur */
57 < #define RTRACE          18              /* use rtrace with pinterp? */
58 < #define DISKSPACE       19              /* how much disk space to use */
59 < #define RESOLUTION      20              /* desired final resolution */
60 < #define EXPOSURE        21              /* how to compute exposure */
47 < #define RSH             22              /* remote shell script or program */
37 >                                /* input variables (alphabetical by name) */
38 > #define ANIMATE         0               /* animation command */
39 > #define ARCHIVE         1               /* archiving command */
40 > #define BASENAME        2               /* output image base name */
41 > #define DIRECTORY       3               /* working (sub)directory */
42 > #define DISKSPACE       4               /* how much disk space to use */
43 > #define END             5               /* ending frame number */
44 > #define EXPOSURE        6               /* how to compute exposure */
45 > #define HOST            7               /* rendering host machine */
46 > #define INTERP          8               /* # frames to interpolate */
47 > #define MBLUR           9               /* motion blur parameters */
48 > #define NEXTANIM        10              /* next animation file */
49 > #define OCTREE          11              /* octree file name */
50 > #define OVERSAMP        12              /* # times to oversample image */
51 > #define PFILT           13              /* pfilt options */
52 > #define PINTERP         14              /* pinterp options */
53 > #define RENDER          15              /* rendering options */
54 > #define RESOLUTION      16              /* desired final resolution */
55 > #define RIF             17              /* rad input file */
56 > #define RSH             18              /* remote shell script or program */
57 > #define RTRACE          19              /* use rtrace with pinterp? */
58 > #define START           20              /* starting frame number */
59 > #define TRANSFER        21              /* frame transfer command */
60 > #define VIEWFILE        22              /* animation frame views */
61  
62   int     NVARS = 23;             /* total number of variables */
63  
64   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},
65          {"ANIMATE",     2,      0,      NULL,   onevalue},
65        {"TRANSFER",    2,      0,      NULL,   onevalue},
66          {"ARCHIVE",     2,      0,      NULL,   onevalue},
67 +        {"BASENAME",    3,      0,      NULL,   onevalue},
68 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
69 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
70 +        {"END",         2,      0,      NULL,   intvalue},
71 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
72 +        {"host",        4,      0,      NULL,   NULL},
73          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
68        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
74          {"MBLUR",       2,      0,      NULL,   onevalue},
75 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
76 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
75 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
76 >        {"OCTREE",      3,      0,      NULL,   onevalue},
77 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
78 >        {"pfilt",       2,      0,      NULL,   catvalues},
79 >        {"pinterp",     2,      0,      NULL,   catvalues},
80 >        {"render",      3,      0,      NULL,   catvalues},
81          {"RESOLUTION",  3,      0,      NULL,   onevalue},
82 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
82 >        {"RIF",         3,      0,      NULL,   onevalue},
83          {"RSH",         3,      0,      NULL,   onevalue},
84 +        {"RTRACE",      2,      0,      NULL,   boolvalue},
85 +        {"START",       2,      0,      NULL,   intvalue},
86 +        {"TRANSFER",    2,      0,      NULL,   onevalue},
87 +        {"VIEWFILE",    2,      0,      NULL,   onevalue},
88   };
89  
90   #define SFNAME  "STATUS"                /* status file name */
# Line 93 | Line 106 | int    silent = 0;             /* silent mode? */
106   int     noaction = 0;           /* take no action? */
107  
108   char    *remsh;                 /* remote shell program/script */
109 < char    rendopt[2048] = "";     /* rendering options */
109 > char    rendopt[2048];          /* rendering options */
110   char    rresopt[32];            /* rendering resolution options */
111   char    fresopt[32];            /* filter resolution options */
112   int     pfiltalways;            /* always use pfilt? */
# Line 109 | Line 122 | struct pslot {
122   int     npslots;                /* number of process slots */
123  
124   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
112
113 struct pslot    *findpslot();
114
125   PSERVER *lastpserver;           /* last process server with error */
126  
127 < VIEW    *getview();
128 < char    *getexp();
127 > static struct pslot * findpslot(int pid);
128 > static void checkdir(void);
129 > static VIEW * getview(int n);
130  
131 < extern time_t   fdate(), time();
131 > static char * dirfile(char *df, register char *path);
132 > static char * getexp(int n);
133 > static int getblur(double *bf);
134 > static int getastat(void);
135 > static void getradfile(char *rfargs);
136 > static void badvalue(int vc);
137 > static int rmfile(char *fn);
138 > static int runcom(char *cs);
139 > static int pruncom(char *com, char *ppins, int maxcopies);
140 > static void bwait(int ncoms);
141 > static int bruncom(char *com, int fout, int (*rf)());
142 > static int serverdown(void);
143 > static int donecom(PSERVER *ps, int pn, int status);
144 > static int countviews(void);
145 > static int dofilt(int frame, int rvr);
146 > static void archive(void);
147 > static int frecover(int frame);
148 > static int recover(int frame);
149 > static void sethosts(void);
150 > static void walkwait(int first, int last, char *vfn);
151 > static void animrend(int frame, VIEW *vp);
152 > static void transferframes(void);
153 > static void filterframes(void);
154 > static void renderframes(int nframes);
155 > static void animate(void);
156 > static void setdefaults(void);
157 > static void putastat(void);
158  
159  
160   main(argc, argv)
# Line 150 | Line 187 | char   *argv[];
187          cfname = argv[i];
188                                                  /* load variables */
189          loadvars(cfname);
190 +                                                /* check variables */
191 +        checkvalues();
192                                                  /* did we get DIRECTORY? */
193          checkdir();
194                                                  /* check status */
# Line 189 | Line 228 | userr:
228   }
229  
230  
231 < getastat()                      /* check/set animation status */
231 > static int
232 > getastat(void)                  /* check/set animation status */
233   {
234          char    sfname[256];
235          FILE    *fp;
# Line 230 | Line 270 | getastat()                     /* check/set animation status */
270                  }
271                  /* assume it is dead */
272          }
273 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
273 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
274                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
275                                  progname, astat.cfname);
276                  return(-1);
# Line 253 | Line 293 | fmterr:
293   }
294  
295  
296 < putastat()                      /* put out current status */
296 > static void
297 > putastat(void)                  /* put out current status */
298   {
299          char    buf[256];
300          FILE    *fp;
# Line 275 | Line 316 | putastat()                     /* put out current status */
316   }
317  
318  
319 < checkdir()                      /* make sure we have our directory */
319 > static void
320 > checkdir(void)                  /* make sure we have our directory */
321   {
322          struct stat     stb;
323  
# Line 297 | Line 339 | checkdir()                     /* make sure we have our directory */
339   }
340  
341  
342 < setdefaults()                   /* set default values */
342 > static void
343 > setdefaults(void)                       /* set default values */
344   {
345          extern char     *atos();
346 +        int     decades;
347          char    buf[256];
348  
349          if (vdef(ANIMATE)) {
# Line 333 | Line 377 | setdefaults()                  /* set default values */
377                  quit(1);
378          }
379          if (!vdef(BASENAME)) {
380 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
380 >                decades = (int)log10((double)vint(END)) + 1;
381 >                if (decades < 3) decades = 3;
382 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
383                  vval(BASENAME) = savqstr(buf);
384                  vdef(BASENAME)++;
385          }
# Line 382 | Line 428 | setdefaults()                  /* set default values */
428   }
429  
430  
431 < sethosts()                      /* set up process servers */
431 > static void
432 > sethosts(void)                  /* set up process servers */
433   {
434          extern char     *iskip();
435          char    buf[256], *dir, *uname;
# Line 437 | Line 484 | sethosts()                     /* set up process servers */
484          }
485   }
486  
487 <
488 < getradfile(rfargs)              /* run rad and get needed variables */
442 < char    *rfargs;
487 > static void
488 > getradfile(char *rfargs)                /* run rad and get needed variables */
489   {
490          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
491          char    combuf[256];
492          register int    i;
493          register char   *cp;
494 +        char    *pippt;
495                                          /* create rad command */
496          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
497          sprintf(combuf,
498          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
499                          rfargs, rendopt+2);
500          cp = combuf;
501 <        while (*cp) cp++;               /* match unset variables */
501 >        while (*cp) {
502 >                if (*cp == '|') pippt = cp;
503 >                cp++;
504 >        }                               /* match unset variables */
505          for (i = 0; mvar[i] >= 0; i++)
506                  if (!vdef(mvar[i])) {
507                          *cp++ = '|';
508                          strcpy(cp, vnam(mvar[i]));
509                          while (*cp) cp++;
510 +                        pippt = NULL;
511                  }
512 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
513 <        cp += 11;                       /* point to file name */
514 <        if (system(combuf)) {
515 <                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
516 <                                progname, combuf);
466 <                quit(1);
512 >        if (pippt != NULL)
513 >                strcpy(pippt, "> " NULL_DEVICE);        /* nothing to match */
514 >        else {
515 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
516 >                cp += 11;               /* point to file name */
517          }
518 <        loadvars(cp);                   /* load variables and remove file */
519 <        unlink(cp);
518 >        system(combuf);                 /* ignore exit code */
519 >        if (pippt == NULL) {            /* load variables and remove file */
520 >                loadvars(cp);
521 >                unlink(cp);
522 >        }
523   }
524  
525  
526 < animate()                       /* run animation */
526 > static void
527 > animate(void)                   /* run animation */
528   {
529          int     xres, yres;
530          float   pa, mult;
# Line 500 | Line 554 | animate()                      /* run animation */
554                                                  progname, vnam(INTERP));
555                          vval(INTERP) = "0";
556                  }
557 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
557 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
558                          if (!nowarn)
559                                  fprintf(stderr,
560                                          "%s: resetting %s=0 for animation\n",
# Line 510 | Line 564 | animate()                      /* run animation */
564          }
565                                          /* figure # frames per batch */
566          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
567 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
567 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
568                  d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
569          d2 = xres*yres*4;                       /* space for final picture */
570          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
# Line 520 | Line 574 | animate()                      /* run animation */
574                  quit(1);
575          }
576                                          /* initialize archive argument list */
577 <        i = 16;
524 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
525 <                i = strlen(vval(ARCHIVE));
577 >        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
578          arcnext = arcfirst = arcargs + i;
579                                          /* initialize status file */
580          if (astat.rnext == 0)
# Line 543 | Line 595 | animate()                      /* run animation */
595   }
596  
597  
598 < renderframes(nframes)           /* render next nframes frames */
599 < int     nframes;
598 > static void
599 > renderframes(int nframes)               /* render next nframes frames */
600   {
601          static char     vendbuf[16];
602          VIEW    *vp;
# Line 600 | Line 652 | int    nframes;
652   }
653  
654  
655 < filterframes()                          /* catch up with filtering */
655 > static void
656 > filterframes(void)                              /* catch up with filtering */
657   {
658          VIEW    *vp;
659          register int    i;
# Line 608 | Line 661 | filterframes()                         /* catch up with filtering */
661          if (astat.tnext < astat.fnext)  /* other work to do first */
662                  return;
663                                          /* filter each view */
664 <        for (i = astat.fnext; i < astat.rnext; i++) {
665 <                if ((vp = getview(i)) == NULL) {        /* get view i */
666 <                        fprintf(stderr,
614 <                        "%s: unexpected error reading view for frame %d\n",
615 <                                        progname, i);
616 <                        quit(1);
617 <                }
618 <                dofilt(i, vp, getexp(i), 0);            /* filter frame */
619 <        }
664 >        for (i = astat.fnext; i < astat.rnext; i++)
665 >                dofilt(i, 0);
666 >
667          bwait(0);                       /* wait for filter processes */
668          archive();                      /* archive originals */
669          astat.fnext = i;                /* update status */
# Line 624 | Line 671 | filterframes()                         /* catch up with filtering */
671   }
672  
673  
674 < transferframes()                        /* catch up with picture transfers */
674 > static void
675 > transferframes(void)                    /* catch up with picture transfers */
676   {
677 <        char    combuf[10240];
677 >        char    combuf[10240], *fbase;
678          register char   *cp;
679          register int    i;
680  
# Line 637 | Line 685 | transferframes()                       /* catch up with picture transfers
685                  putastat();             /* update status */
686                  return;
687          }
688 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
689 <        cp = combuf + strlen(combuf);
688 >        strcpy(combuf, "cd ");          /* start transfer command */
689 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
690 >        if (*cp) {
691 >                while (*++cp) ;
692 >                *cp++ = ';'; *cp++ = ' ';
693 >        } else
694 >                cp = combuf;
695 >        strcpy(cp, vval(TRANSFER));
696 >        while (*cp) cp++;
697                                          /* make argument list */
698          for (i = astat.tnext; i < astat.fnext; i++) {
699                  *cp++ = ' ';
700 <                sprintf(cp, vval(BASENAME), i);
700 >                sprintf(cp, fbase, i);
701                  while (*cp) cp++;
702                  strcpy(cp, ".pic");
703                  cp += 4;
# Line 657 | Line 712 | transferframes()                       /* catch up with picture transfers
712   }
713  
714  
715 < animrend(frame, vp)                     /* start animation frame */
716 < int     frame;
717 < VIEW    *vp;
715 > static void
716 > animrend(                       /* start animation frame */
717 > int     frame,
718 > VIEW    *vp
719 > )
720   {
664        extern int      recover();
721          char    combuf[2048];
722          char    fname[128];
723  
# Line 675 | Line 731 | VIEW   *vp;
731   }
732  
733  
734 < walkwait(first, last, vfn)              /* walk-through frames */
735 < int     first, last;
736 < char    *vfn;
734 > static void
735 > walkwait(               /* walk-through frames */
736 > int     first,
737 > int last,
738 > char    *vfn
739 > )
740   {
741 +        double  blurf;
742 +        int     nblur = getblur(&blurf);
743          char    combuf[2048];
744 <        char    *inspoint;
744 >        register char   *inspoint;
745          register int    i;
746  
747          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 691 | Line 752 | char   *vfn;
752                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
753                          }
754                                          /* create command */
755 <        sprintf(combuf, "rpict%s -w0", rendopt);
756 <        if (vint(INTERP) || atoi(vval(MBLUR)))
757 <                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
758 <        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
755 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
756 >                        viewopt(getview(first>1 ? first-1 : 1)));
757 >        inspoint = combuf;
758 >        while (*inspoint) inspoint++;
759 >        if (nblur) {
760 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
761 >                while (*inspoint) inspoint++;
762 >        }
763 >        if (nblur > 1 || vint(INTERP)) {
764 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
765 >                while (*inspoint) inspoint++;
766 >        }
767 >        sprintf(inspoint, " -o %s.unf %s -S %d",
768                          vval(BASENAME), rresopt, first);
769 <        inspoint = combuf + strlen(combuf);
769 >        while (*inspoint) inspoint++;
770          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
771                                          /* run in parallel */
772          i = (last-first+1)/(vint(INTERP)+1);
# Line 716 | Line 786 | char   *vfn;
786   }
787  
788  
789 < int
790 < recover(frame)                          /* recover the specified frame */
721 < int     frame;
789 > static int
790 > recover(int frame)                      /* recover the specified frame */
791   {
792          static int      *rfrm;          /* list of recovered frames */
793          static int      nrfrms = 0;
794 +        double  blurf;
795 +        int     nblur = getblur(&blurf);
796          char    combuf[2048];
797          char    fname[128];
798          register char   *cp;
# Line 737 | Line 808 | int    frame;
808                                  vval(ANIMATE), frame, rendopt);
809          else
810                  sprintf(combuf, "rpict%s -w0", rendopt);
811 <        cp = combuf + strlen(combuf);
812 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
811 >        cp = combuf;
812 >        while (*cp) cp++;
813 >        if (nblur) {
814 >                sprintf(cp, " -pm %.3f", blurf/nblur);
815 >                while (*cp) cp++;
816 >        }
817 >        if (nblur > 1 || vint(INTERP)) {
818                  sprintf(cp, " -z %s.zbf", fname);
819                  while (*cp) cp++;
820          }
# Line 752 | Line 828 | int    frame;
828                  return(1);
829                                          /* add frame to recovered list */
830          if (nrfrms)
831 <                rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int));
831 >                rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
832          else
833                  rfrm = (int *)malloc(sizeof(int));
834          if (rfrm == NULL) {
# Line 764 | Line 840 | int    frame;
840   }
841  
842  
843 < int
844 < frecover(frame)                         /* recover filtered frame */
769 < int     frame;
843 > static int
844 > frecover(int frame)                             /* recover filtered frame */
845   {
846 <        VIEW    *vp;
772 <        char    *ex;
773 <
774 <        vp = getview(frame);
775 <        ex = getexp(frame);
776 <        if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1))
846 >        if (dofilt(frame, 2) && dofilt(frame, 1))
847                  return(1);
848          return(0);
849   }
850  
851  
852 < archive()                       /* archive and remove renderings */
852 > static void
853 > archive(void)                   /* archive and remove renderings */
854   {
855   #define RMCOML  (sizeof(rmcom)-1)
856          static char     rmcom[] = "rm -f";
857 <        register int    i;
857 >        char    basedir[128];
858 >        int     dlen, alen;
859 >        register int    j;
860  
861          if (arcnext == arcfirst)
862                  return;                         /* nothing to do */
863 +        dirfile(basedir, vval(BASENAME));
864 +        dlen = strlen(basedir);
865          if (vdef(ARCHIVE)) {                    /* run archive command */
866 <                i = strlen(vval(ARCHIVE));
867 <                strncpy(arcfirst-i, vval(ARCHIVE), i);
868 <                if (runcom(arcfirst-i)) {
866 >                alen = strlen(vval(ARCHIVE));
867 >                if (dlen) {
868 >                        j = alen + dlen + 5;
869 >                        strncpy(arcfirst-j, "cd ", 3);
870 >                        strncpy(arcfirst-j+3, basedir, dlen);
871 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
872 >                } else
873 >                        j = alen;
874 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
875 >                if (runcom(arcfirst-j)) {
876                          fprintf(stderr, "%s: error running archive command\n",
877                                          progname);
878                          quit(1);
879                  }
880          }
881 +        if (dlen) {
882 +                j = RMCOML + dlen + 5;
883 +                strncpy(arcfirst-j, "cd ", 3);
884 +                strncpy(arcfirst-j+3, basedir, dlen);
885 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
886 +        } else
887 +                j = RMCOML;
888                                                  /* run remove command */
889          strncpy(arcfirst-RMCOML, rmcom, RMCOML);
890 <        runcom(arcfirst-RMCOML);
890 >        runcom(arcfirst-j);
891          arcnext = arcfirst;                     /* reset argument list */
892   #undef RMCOML
893   }
894  
895  
896 < int
897 < dofilt(frame, vp, ep, rvr)                      /* filter frame */
898 < int     frame;
899 < VIEW    *vp;
900 < char    *ep;
812 < int     rvr;
896 > static int
897 > dofilt(                         /* filter frame */
898 > int     frame,
899 > int     rvr
900 > )
901   {
814        extern int      frecover();
902          static int      iter = 0;
903 <        char    fnbefore[128], fnafter[128];
903 >        double  blurf;
904 >        int     nblur = getblur(&blurf);
905 >        VIEW    *vp = getview(frame);
906 >        char    *ep = getexp(frame);
907 >        char    fnbefore[128], fnafter[128], *fbase;
908          char    combuf[1024], fname0[128], fname1[128];
909          int     usepinterp, usepfilt, nora_rgbe;
910          int     frseq[2];
911                                                  /* check what is needed */
912 <        usepinterp = atoi(vval(MBLUR));
913 <        usepfilt = pfiltalways | ep==NULL;
912 >        if (vp == NULL) {
913 >                 fprintf(stderr,
914 >                        "%s: unexpected error reading view for frame %d\n",
915 >                                          progname, frame);
916 >                quit(1);
917 >        }
918 >        if (ep == NULL) {
919 >                 fprintf(stderr,
920 >                        "%s: unexpected error reading exposure for frame %d\n",
921 >                                          progname, frame);
922 >                quit(1);
923 >        }
924 >        usepinterp = (nblur > 1);
925 >        usepfilt = pfiltalways | (ep==NULL);
926          if (ep != NULL && !strcmp(ep, "1"))
927                  ep = "+0";
928          nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
# Line 827 | Line 930 | int    rvr;
930                                                  /* compute rendered views */
931          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
932          frseq[1] = frseq[0] + vint(INTERP) + 1;
933 +        fbase = dirfile(NULL, vval(BASENAME));
934          if (frseq[1] > vint(END))
935                  frseq[1] = vint(END);
936          if (frseq[1] == frame) {                        /* pfilt only */
# Line 836 | Line 940 | int    rvr;
940          } else if (frseq[0] == frame) {         /* no interpolation needed */
941                  if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
942                          *arcnext++ = ' ';
943 <                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
943 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
944                          while (*arcnext) arcnext++;
945                          strcpy(arcnext, ".unf");
946                          arcnext += 4;
947                          if (usepinterp || vint(INTERP)) {       /* and Z-buf */
948                                  *arcnext++ = ' ';
949 <                                sprintf(arcnext, vval(BASENAME),
846 <                                                frame-vint(INTERP)-1);
949 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
950                                  while (*arcnext) arcnext++;
951                                  strcpy(arcnext, ".zbf");
952                                  arcnext += 4;
# Line 863 | Line 966 | int    rvr;
966          if (usepinterp) {                       /* using pinterp */
967                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
968                          return(1);
969 <                if (atoi(vval(MBLUR))) {
867 <                        FILE    *fp;            /* motion blurring */
969 >                if (nblur > 1) {                /* with pmblur */
970                          sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
971                                          'a'+(iter%26));
870                        if ((fp = fopen(fname0, "w")) == NULL) {
871                                perror(fname0); quit(1);
872                        }
873                        fputs(VIEWSTR, fp);
874                        fprintview(vp, fp);
875                        putc('\n', fp); fclose(fp);
876                        if ((vp = getview(frame+1)) == NULL) {
877                                fprintf(stderr,
878                        "%s: unexpected error reading view for frame %d\n",
879                                                progname, frame+1);
880                                quit(1);
881                        }
972                          sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
973                                          'a'+(iter%26));
974 <                        if ((fp = fopen(fname1, "w")) == NULL) {
975 <                                perror(fname1); quit(1);
974 >                        if (!noaction) {
975 >                                FILE    *fp;            /* motion blurring */
976 >                                if ((fp = fopen(fname0, "w")) == NULL) {
977 >                                        perror(fname0); quit(1);
978 >                                }
979 >                                fputs(VIEWSTR, fp);
980 >                                fprintview(vp, fp);
981 >                                putc('\n', fp); fclose(fp);
982 >                                if ((vp = getview(frame+1)) == NULL) {
983 >                                        fprintf(stderr,
984 >                        "%s: unexpected error reading view for frame %d\n",
985 >                                                        progname, frame+1);
986 >                                        quit(1);
987 >                                }
988 >                                if ((fp = fopen(fname1, "w")) == NULL) {
989 >                                        perror(fname1); quit(1);
990 >                                }
991 >                                fputs(VIEWSTR, fp);
992 >                                fprintview(vp, fp);
993 >                                putc('\n', fp); fclose(fp);
994                          }
887                        fputs(VIEWSTR, fp);
888                        fprintview(vp, fp);
889                        putc('\n', fp); fclose(fp);
995                          sprintf(combuf,
996 <                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
997 <                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
893 <                                        atoi(vval(MBLUR)),
996 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
997 >                                        blurf, nblur,
998                                          fname0, fname1, fname0, fname1);
999                          iter++;
1000                  } else                          /* no blurring */
# Line 898 | Line 1002 | int    rvr;
1002                  strcat(combuf, viewopt(vp));
1003                  if (vbool(RTRACE))
1004                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1005 <                                        rendopt, vval(OCTREE));
1005 >                                        rendopt+1, vval(OCTREE));
1006                  if (vdef(PINTERP))
1007                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1008                  if (usepfilt)
1009                          sprintf(combuf+strlen(combuf), " %s", rresopt);
1010                  else
1011 <                        sprintf(combuf+strlen(combuf), " %s -e %s",
1011 >                        sprintf(combuf+strlen(combuf), " -a %s -e %s",
1012                                          fresopt, ep);
1013                  sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
1014                                  fnbefore, fnbefore);
# Line 951 | Line 1055 | int    rvr;
1055   }
1056  
1057  
1058 < VIEW *
1059 < getview(n)                      /* get view number n */
956 < int     n;
1058 > static VIEW *
1059 > getview(int n)                  /* get view number n */
1060   {
1061          static FILE     *viewfp = NULL;         /* view file pointer */
1062          static int      viewnum = 0;            /* current view number */
# Line 965 | Line 1068 | int    n;
1068                          fclose(viewfp);
1069                          viewfp = NULL;
1070                          viewnum = 0;
1071 <                        copystruct(&curview, &stdview);
1071 >                        curview = stdview;
1072                  }
1073                  return(NULL);
1074          }
1075 <        if (viewfp == NULL) {           /* open file */
1075 >        if (viewfp == NULL) {                   /* open file */
1076                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1077                          perror(vval(VIEWFILE));
1078                          quit(1);
1079                  }
1080 <        } else if (n < viewnum) {       /* rewind file */
1080 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1081                  if (viewnum == 1 && feof(viewfp))
1082                          return(&curview);               /* just one view */
1083                  if (fseek(viewfp, 0L, 0) == EOF) {
1084                          perror(vval(VIEWFILE));
1085                          quit(1);
1086                  }
1087 <                copystruct(&curview, &stdview);
1087 >                curview = stdview;
1088                  viewnum = 0;
1089          }
1090 +        if (n < 0) {                            /* get next view */
1091 +                register int    c = getc(viewfp);
1092 +                if (c == EOF)
1093 +                        return((VIEW *)NULL);           /* that's it */
1094 +                ungetc(c, viewfp);
1095 +                n = viewnum + 1;
1096 +        }
1097          while (n > viewnum) {           /* scan to desired view */
1098                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1099                          return(viewnum==1 ? &curview : (VIEW *)NULL);
# Line 994 | Line 1104 | int    n;
1104   }
1105  
1106  
1107 < int
1108 < countviews()                    /* count views in view file */
1107 > static int
1108 > countviews(void)                        /* count views in view file */
1109   {
1110 <        register int    n = 0;
1110 >        int     n;
1111  
1112 <        while (getview(n+1) != NULL)
1112 >        if (getview(n=1) == NULL)
1113 >                return(0);
1114 >        while (getview(-1) != NULL)
1115                  n++;
1116          return(n);
1117   }
1118  
1119  
1120 < char *
1121 < getexp(n)                       /* get exposure for nth frame */
1010 < int     n;
1120 > static char *
1121 > getexp(int n)                   /* get exposure for nth frame */
1122   {
1123          extern char     *fskip();
1124          static char     expval[32];
# Line 1019 | Line 1130 | int    n;
1130          if (n == 0) {                           /* signal to close file */
1131                  if (expfp != NULL) {
1132                          fclose(expfp);
1133 <                        free((char *)exppos);
1133 >                        free((void *)exppos);
1134                          expfp = NULL;
1135                  }
1136                  return(NULL);
# Line 1076 | Line 1187 | int    n;
1187   }
1188  
1189  
1190 < struct pslot *
1191 < findpslot(pid)                  /* find or allocate a process slot */
1081 < int     pid;
1190 > static struct pslot *
1191 > findpslot(int pid)                      /* find or allocate a process slot */
1192   {
1193          register struct pslot   *psempty = NULL;
1194          register int    i;
# Line 1093 | Line 1203 | int    pid;
1203   }
1204  
1205  
1206 < int
1207 < donecom(ps, pn, status)         /* clean up after finished process */
1208 < PSERVER *ps;
1209 < int     pn;
1210 < int     status;
1206 > static int
1207 > donecom(                /* clean up after finished process */
1208 > PSERVER *ps,
1209 > int     pn,
1210 > int     status
1211 > )
1212   {
1213 <        register PROC   *pp;
1213 >        register NETPROC        *pp;
1214          register struct pslot   *psl;
1215  
1216          pp = ps->proc + pn;
# Line 1134 | Line 1245 | int    status;
1245   }
1246  
1247  
1248 < int
1249 < serverdown()                    /* check status of last process server */
1248 > static int
1249 > serverdown(void)                        /* check status of last process server */
1250   {
1251          if (lastpserver == NULL || !lastpserver->hostname[0])
1252                  return(0);
# Line 1151 | Line 1262 | serverdown()                   /* check status of last process server
1262   }
1263  
1264  
1265 < int
1266 < bruncom(com, fout, rf)          /* run a command in the background */
1267 < char    *com;
1268 < int     fout;
1269 < int     (*rf)();
1265 > static int
1266 > bruncom(                /* run a command in the background */
1267 > char    *com,
1268 > int     fout,
1269 > int     (*rf)()
1270 > )
1271   {
1272          int     pid;
1273          register struct pslot   *psl;
# Line 1184 | Line 1296 | int    (*rf)();
1296   }
1297  
1298  
1299 < bwait(ncoms)                            /* wait for batch job(s) to finish */
1300 < int     ncoms;
1299 > static void
1300 > bwait(int ncoms)                                /* wait for batch job(s) to finish */
1301   {
1302          int     status;
1303  
# Line 1199 | Line 1311 | int    ncoms;
1311   }
1312  
1313  
1314 < int
1315 < pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1316 < char    *com, *ppins;
1317 < int     maxcopies;
1314 > static int
1315 > pruncom(        /* run a command in parallel over network */
1316 > char    *com,
1317 > char    *ppins,
1318 > int     maxcopies
1319 > )
1320   {
1321          int     retstatus = 0;
1322          int     hostcopies;
# Line 1224 | Line 1338 | int    maxcopies;
1338                          strcpy(com1=buf, com);  /* build -PP command */
1339                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1340                                          vval(DIRECTORY), phostname(ps));
1341 +                        unlink(com1+(ppins-com)+5);
1342                          strcat(com1, ppins);
1343                  } else
1344                          com1 = com;
# Line 1268 | Line 1383 | int    maxcopies;
1383   }
1384  
1385  
1386 < runcom(cs)                      /* run a command locally and wait for it */
1387 < char    *cs;
1386 > static int
1387 > runcom(char *cs)                        /* run a command locally and wait for it */
1388   {
1389          if (!silent)            /* echo it */
1390                  printf("\t%s\n", cs);
# Line 1280 | Line 1395 | char   *cs;
1395   }
1396  
1397  
1398 < rmfile(fn)                      /* remove a file */
1399 < char    *fn;
1398 > static int
1399 > rmfile(char *fn)                        /* remove a file */
1400   {
1401          if (!silent)
1402 < #ifdef MSDOS
1402 > #ifdef _WIN32
1403                  printf("\tdel %s\n", fn);
1404   #else
1405                  printf("\trm -f %s\n", fn);
# Line 1295 | Line 1410 | char   *fn;
1410   }
1411  
1412  
1413 < badvalue(vc)                    /* report bad variable value and exit */
1414 < int     vc;
1413 > static void
1414 > badvalue(int vc)                        /* report bad variable value and exit */
1415   {
1416          fprintf(stderr, "%s: bad value for variable '%s'\n",
1417                          progname, vnam(vc));
1418          quit(1);
1419 + }
1420 +
1421 +
1422 + static char *
1423 + dirfile(                /* separate path into directory and file */
1424 + char    *df,
1425 + register char   *path
1426 + )
1427 + {
1428 +        register int    i;
1429 +        int     psep;
1430 +
1431 +        for (i = 0, psep = -1; path[i]; i++)
1432 +                if (path[i] == '/')
1433 +                        psep = i;
1434 +        if (df != NULL) {
1435 +                if (psep == 0) {
1436 +                        df[0] = '/';
1437 +                        df[1] = '\0';
1438 +                } else if (psep > 0) {
1439 +                        strncpy(df, path, psep);
1440 +                        df[psep] = '\0';
1441 +                } else
1442 +                        df[0] = '\0';
1443 +        }
1444 +        return(path+psep+1);
1445 + }
1446 +
1447 +
1448 + static int
1449 + getblur(double *bf)             /* get # blur samples (and fraction) */
1450 + {
1451 +        double  blurf;
1452 +        int     nblur;
1453 +        char    *s;
1454 +
1455 +        if (!vdef(MBLUR)) {
1456 +                if (bf != NULL)
1457 +                        *bf = 0.0;
1458 +                return(0);
1459 +        }
1460 +        blurf = atof(vval(MBLUR));
1461 +        if (blurf < 0.0)
1462 +                blurf = 0.0;
1463 +        if (bf != NULL)
1464 +                *bf = blurf;
1465 +        if (blurf <= FTINY)
1466 +                return(0);
1467 +        s = sskip(vval(MBLUR));
1468 +        if (!*s)
1469 +                return(DEF_NBLUR);
1470 +        nblur = atoi(s);
1471 +        if (nblur <= 0)
1472 +                return(1);
1473 +        return(nblur);
1474   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines