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.13 by greg, Tue May 21 14:27:19 1996 UTC vs.
Revision 2.29 by greg, Sat Feb 22 02:07:30 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 + /* ====================================================================
17 + * The Radiance Software License, Version 1.0
18 + *
19 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
20 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
21 + *
22 + * Redistribution and use in source and binary forms, with or without
23 + * modification, are permitted provided that the following conditions
24 + * are met:
25 + *
26 + * 1. Redistributions of source code must retain the above copyright
27 + *         notice, this list of conditions and the following disclaimer.
28 + *
29 + * 2. Redistributions in binary form must reproduce the above copyright
30 + *       notice, this list of conditions and the following disclaimer in
31 + *       the documentation and/or other materials provided with the
32 + *       distribution.
33 + *
34 + * 3. The end-user documentation included with the redistribution,
35 + *           if any, must include the following acknowledgment:
36 + *             "This product includes Radiance software
37 + *                 (http://radsite.lbl.gov/)
38 + *                 developed by the Lawrence Berkeley National Laboratory
39 + *               (http://www.lbl.gov/)."
40 + *       Alternately, this acknowledgment may appear in the software itself,
41 + *       if and wherever such third-party acknowledgments normally appear.
42 + *
43 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
44 + *       and "The Regents of the University of California" must
45 + *       not be used to endorse or promote products derived from this
46 + *       software without prior written permission. For written
47 + *       permission, please contact [email protected].
48 + *
49 + * 5. Products derived from this software may not be called "Radiance",
50 + *       nor may "Radiance" appear in their name, without prior written
51 + *       permission of Lawrence Berkeley National Laboratory.
52 + *
53 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
54 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
56 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
57 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
60 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
63 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 + * SUCH DAMAGE.
65 + * ====================================================================
66 + *
67 + * This software consists of voluntary contributions made by many
68 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
69 + * information on Lawrence Berkeley National Laboratory, please see
70 + * <http://www.lbl.gov/>.
71 + */
72 +
73   #include "standard.h"
74   #include <ctype.h>
13 #include <sys/types.h>
75   #include <sys/stat.h>
76   #include "view.h"
77   #include "vars.h"
78   #include "netproc.h"
79 +                                /* default blur samples */
80 + #ifndef DEF_NBLUR
81 + #define DEF_NBLUR       5
82 + #endif
83                                  /* default remote shell */
84   #ifdef _AUX_SOURCE
85   #define REMSH           "remsh"
86   #else
87   #define REMSH           "rsh"
88   #endif
89 <                                /* input variables */
90 < #define HOST            0               /* rendering host machine */
91 < #define RENDER          1               /* rendering options */
92 < #define PFILT           2               /* pfilt options */
93 < #define PINTERP         3               /* pinterp options */
94 < #define OCTREE          4               /* octree file name */
95 < #define DIRECTORY       5               /* working (sub)directory */
96 < #define BASENAME        6               /* output image base name */
97 < #define VIEWFILE        7               /* animation frame views */
98 < #define START           8               /* starting frame number */
99 < #define END             9               /* ending frame number */
100 < #define RIF             10              /* rad input file */
101 < #define NEXTANIM        11              /* next animation file */
102 < #define ANIMATE         12              /* animation command */
103 < #define TRANSFER        13              /* frame transfer command */
104 < #define ARCHIVE         14              /* archiving command */
105 < #define INTERP          15              /* # frames to interpolate */
106 < #define OVERSAMP        16              /* # times to oversample image */
107 < #define MBLUR           17              /* samples for motion blur */
108 < #define RTRACE          18              /* use rtrace with pinterp? */
109 < #define DISKSPACE       19              /* how much disk space to use */
110 < #define RESOLUTION      20              /* desired final resolution */
111 < #define EXPOSURE        21              /* how to compute exposure */
112 < #define RSH             22              /* remote shell script or program */
89 >                                /* input variables (alphabetical by name) */
90 > #define ANIMATE         0               /* animation command */
91 > #define ARCHIVE         1               /* archiving command */
92 > #define BASENAME        2               /* output image base name */
93 > #define DIRECTORY       3               /* working (sub)directory */
94 > #define DISKSPACE       4               /* how much disk space to use */
95 > #define END             5               /* ending frame number */
96 > #define EXPOSURE        6               /* how to compute exposure */
97 > #define HOST            7               /* rendering host machine */
98 > #define INTERP          8               /* # frames to interpolate */
99 > #define MBLUR           9               /* motion blur parameters */
100 > #define NEXTANIM        10              /* next animation file */
101 > #define OCTREE          11              /* octree file name */
102 > #define OVERSAMP        12              /* # times to oversample image */
103 > #define PFILT           13              /* pfilt options */
104 > #define PINTERP         14              /* pinterp options */
105 > #define RENDER          15              /* rendering options */
106 > #define RESOLUTION      16              /* desired final resolution */
107 > #define RIF             17              /* rad input file */
108 > #define RSH             18              /* remote shell script or program */
109 > #define RTRACE          19              /* use rtrace with pinterp? */
110 > #define START           20              /* starting frame number */
111 > #define TRANSFER        21              /* frame transfer command */
112 > #define VIEWFILE        22              /* animation frame views */
113  
114   int     NVARS = 23;             /* total number of variables */
115  
116   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},
117          {"ANIMATE",     2,      0,      NULL,   onevalue},
65        {"TRANSFER",    2,      0,      NULL,   onevalue},
118          {"ARCHIVE",     2,      0,      NULL,   onevalue},
119 +        {"BASENAME",    3,      0,      NULL,   onevalue},
120 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
121 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
122 +        {"END",         2,      0,      NULL,   intvalue},
123 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
124 +        {"host",        4,      0,      NULL,   NULL},
125          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
68        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
126          {"MBLUR",       2,      0,      NULL,   onevalue},
127 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
128 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
127 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
128 >        {"OCTREE",      3,      0,      NULL,   onevalue},
129 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
130 >        {"pfilt",       2,      0,      NULL,   catvalues},
131 >        {"pinterp",     2,      0,      NULL,   catvalues},
132 >        {"render",      3,      0,      NULL,   catvalues},
133          {"RESOLUTION",  3,      0,      NULL,   onevalue},
134 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
134 >        {"RIF",         3,      0,      NULL,   onevalue},
135          {"RSH",         3,      0,      NULL,   onevalue},
136 +        {"RTRACE",      2,      0,      NULL,   boolvalue},
137 +        {"START",       2,      0,      NULL,   intvalue},
138 +        {"TRANSFER",    2,      0,      NULL,   onevalue},
139 +        {"VIEWFILE",    2,      0,      NULL,   onevalue},
140   };
141  
142   #define SFNAME  "STATUS"                /* status file name */
# Line 93 | Line 158 | int    silent = 0;             /* silent mode? */
158   int     noaction = 0;           /* take no action? */
159  
160   char    *remsh;                 /* remote shell program/script */
161 < char    rendopt[2048] = "";     /* rendering options */
161 > char    rendopt[2048];          /* rendering options */
162   char    rresopt[32];            /* rendering resolution options */
163   char    fresopt[32];            /* filter resolution options */
164   int     pfiltalways;            /* always use pfilt? */
# Line 108 | Line 173 | struct pslot {
173   }       *pslot;                 /* process slots */
174   int     npslots;                /* number of process slots */
175  
111 int     lastpid;                /* ID of last completed background process */
112 PSERVER *lastpserver;           /* last process server used */
113
176   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
177  
178   struct pslot    *findpslot();
179  
180 + PSERVER *lastpserver;           /* last process server with error */
181 +
182   VIEW    *getview();
183 < char    *getexp();
183 > char    *getexp(), *dirfile();
184 > int     getblur();
185  
186 < extern time_t   fdate(), time();
186 > extern time_t   time();
187  
188  
189   main(argc, argv)
# Line 151 | Line 216 | char   *argv[];
216          cfname = argv[i];
217                                                  /* load variables */
218          loadvars(cfname);
219 +                                                /* check variables */
220 +        checkvalues();
221                                                  /* did we get DIRECTORY? */
222          checkdir();
223                                                  /* check status */
# Line 231 | Line 298 | getastat()                     /* check/set animation status */
298                  }
299                  /* assume it is dead */
300          }
301 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
301 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
302                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
303                                  progname, astat.cfname);
304                  return(-1);
# Line 301 | Line 368 | checkdir()                     /* make sure we have our directory */
368   setdefaults()                   /* set default values */
369   {
370          extern char     *atos();
371 +        int     decades;
372          char    buf[256];
373  
374          if (vdef(ANIMATE)) {
# Line 334 | Line 402 | setdefaults()                  /* set default values */
402                  quit(1);
403          }
404          if (!vdef(BASENAME)) {
405 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
405 >                decades = (int)log10((double)vint(END)) + 1;
406 >                if (decades < 3) decades = 3;
407 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
408                  vval(BASENAME) = savqstr(buf);
409                  vdef(BASENAME)++;
410          }
# Line 446 | Line 516 | char   *rfargs;
516          char    combuf[256];
517          register int    i;
518          register char   *cp;
519 +        char    *pippt;
520                                          /* create rad command */
521          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
522          sprintf(combuf,
523          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
524                          rfargs, rendopt+2);
525          cp = combuf;
526 <        while (*cp) cp++;               /* match unset variables */
526 >        while (*cp) {
527 >                if (*cp == '|') pippt = cp;
528 >                cp++;
529 >        }                               /* match unset variables */
530          for (i = 0; mvar[i] >= 0; i++)
531                  if (!vdef(mvar[i])) {
532                          *cp++ = '|';
533                          strcpy(cp, vnam(mvar[i]));
534                          while (*cp) cp++;
535 +                        pippt = NULL;
536                  }
537 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
538 <        cp += 11;                       /* point to file name */
539 <        if (system(combuf)) {
540 <                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
541 <                                progname, combuf);
467 <                quit(1);
537 >        if (pippt != NULL)
538 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
539 >        else {
540 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
541 >                cp += 11;               /* point to file name */
542          }
543 <        loadvars(cp);                   /* load variables and remove file */
544 <        unlink(cp);
543 >        system(combuf);                 /* ignore exit code */
544 >        if (pippt == NULL) {            /* load variables and remove file */
545 >                loadvars(cp);
546 >                unlink(cp);
547 >        }
548   }
549  
550  
# Line 482 | Line 559 | animate()                      /* run animation */
559          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
560          mult = vflt(OVERSAMP);
561          if (i == 3) {
562 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
562 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
563                                  (int)(mult*yres), pa);
564 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
564 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
565          } else if (i) {
566                  if (i == 1) yres = xres;
567                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 501 | Line 578 | animate()                      /* run animation */
578                                                  progname, vnam(INTERP));
579                          vval(INTERP) = "0";
580                  }
581 <                if (atoi(vval(MBLUR))) {        /* can't handle this yet */
581 >                if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */
582                          if (!nowarn)
583                                  fprintf(stderr,
584                                          "%s: resetting %s=0 for animation\n",
# Line 511 | Line 588 | animate()                      /* run animation */
588          }
589                                          /* figure # frames per batch */
590          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
591 <        if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
591 >        if ((i=vint(INTERP)) || getblur(NULL) > 1)
592                  d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
593          d2 = xres*yres*4;                       /* space for final picture */
594          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
# Line 521 | Line 598 | animate()                      /* run animation */
598                  quit(1);
599          }
600                                          /* initialize archive argument list */
601 <        i = 16;
525 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
526 <                i = strlen(vval(ARCHIVE));
601 >        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
602          arcnext = arcfirst = arcargs + i;
603                                          /* initialize status file */
604          if (astat.rnext == 0)
# Line 627 | Line 702 | filterframes()                         /* catch up with filtering */
702  
703   transferframes()                        /* catch up with picture transfers */
704   {
705 <        char    combuf[10240];
705 >        char    combuf[10240], *fbase;
706          register char   *cp;
707          register int    i;
708  
# Line 638 | Line 713 | transferframes()                       /* catch up with picture transfers
713                  putastat();             /* update status */
714                  return;
715          }
716 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
717 <        cp = combuf + strlen(combuf);
716 >        strcpy(combuf, "cd ");          /* start transfer command */
717 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
718 >        if (*cp) {
719 >                while (*++cp) ;
720 >                *cp++ = ';'; *cp++ = ' ';
721 >        } else
722 >                cp = combuf;
723 >        strcpy(cp, vval(TRANSFER));
724 >        while (*cp) cp++;
725                                          /* make argument list */
726          for (i = astat.tnext; i < astat.fnext; i++) {
727                  *cp++ = ' ';
728 <                sprintf(cp, vval(BASENAME), i);
728 >                sprintf(cp, fbase, i);
729                  while (*cp) cp++;
730                  strcpy(cp, ".pic");
731                  cp += 4;
# Line 680 | Line 762 | walkwait(first, last, vfn)             /* walk-through frames */
762   int     first, last;
763   char    *vfn;
764   {
765 +        double  blurf;
766 +        int     nblur = getblur(&blurf);
767          char    combuf[2048];
768 <        char    *inspoint;
768 >        register char   *inspoint;
769          register int    i;
770  
771          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 692 | Line 776 | char   *vfn;
776                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
777                          }
778                                          /* create command */
779 <        sprintf(combuf, "rpict%s -w0", rendopt);
780 <        if (vint(INTERP) || atoi(vval(MBLUR)))
781 <                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
782 <        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
779 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
780 >                        viewopt(getview(first>1 ? first-1 : 1)));
781 >        inspoint = combuf;
782 >        while (*inspoint) inspoint++;
783 >        if (nblur) {
784 >                sprintf(inspoint, " -pm %.3f", blurf/nblur);
785 >                while (*inspoint) inspoint++;
786 >        }
787 >        if (nblur > 1 || vint(INTERP)) {
788 >                sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
789 >                while (*inspoint) inspoint++;
790 >        }
791 >        sprintf(inspoint, " -o %s.unf %s -S %d",
792                          vval(BASENAME), rresopt, first);
793 <        inspoint = combuf + strlen(combuf);
793 >        while (*inspoint) inspoint++;
794          sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
795                                          /* run in parallel */
796          i = (last-first+1)/(vint(INTERP)+1);
# Line 723 | Line 816 | int    frame;
816   {
817          static int      *rfrm;          /* list of recovered frames */
818          static int      nrfrms = 0;
819 +        double  blurf;
820 +        int     nblur = getblur(&blurf);
821          char    combuf[2048];
822          char    fname[128];
823          register char   *cp;
# Line 738 | Line 833 | int    frame;
833                                  vval(ANIMATE), frame, rendopt);
834          else
835                  sprintf(combuf, "rpict%s -w0", rendopt);
836 <        cp = combuf + strlen(combuf);
837 <        if (vint(INTERP) || atoi(vval(MBLUR))) {
836 >        cp = combuf;
837 >        while (*cp) cp++;
838 >        if (nblur) {
839 >                sprintf(cp, " -pm %.3f", blurf/nblur);
840 >                while (*cp) cp++;
841 >        }
842 >        if (nblur > 1 || vint(INTERP)) {
843                  sprintf(cp, " -z %s.zbf", fname);
844                  while (*cp) cp++;
845          }
# Line 784 | Line 884 | archive()                      /* archive and remove renderings */
884   {
885   #define RMCOML  (sizeof(rmcom)-1)
886          static char     rmcom[] = "rm -f";
887 <        register int    i;
887 >        char    basedir[128];
888 >        int     dlen, alen;
889 >        register int    j;
890  
891          if (arcnext == arcfirst)
892                  return;                         /* nothing to do */
893 +        dirfile(basedir, vval(BASENAME));
894 +        dlen = strlen(basedir);
895          if (vdef(ARCHIVE)) {                    /* run archive command */
896 <                i = strlen(vval(ARCHIVE));
897 <                strncpy(arcfirst-i, vval(ARCHIVE), i);
898 <                if (runcom(arcfirst-i)) {
896 >                alen = strlen(vval(ARCHIVE));
897 >                if (dlen) {
898 >                        j = alen + dlen + 5;
899 >                        strncpy(arcfirst-j, "cd ", 3);
900 >                        strncpy(arcfirst-j+3, basedir, dlen);
901 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
902 >                } else
903 >                        j = alen;
904 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
905 >                if (runcom(arcfirst-j)) {
906                          fprintf(stderr, "%s: error running archive command\n",
907                                          progname);
908                          quit(1);
909                  }
910          }
911 +        if (dlen) {
912 +                j = RMCOML + dlen + 5;
913 +                strncpy(arcfirst-j, "cd ", 3);
914 +                strncpy(arcfirst-j+3, basedir, dlen);
915 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
916 +        } else
917 +                j = RMCOML;
918                                                  /* run remove command */
919          strncpy(arcfirst-RMCOML, rmcom, RMCOML);
920 <        runcom(arcfirst-RMCOML);
920 >        runcom(arcfirst-j);
921          arcnext = arcfirst;                     /* reset argument list */
922   #undef RMCOML
923   }
# Line 814 | Line 932 | int    rvr;
932   {
933          extern int      frecover();
934          static int      iter = 0;
935 <        char    fnbefore[128], fnafter[128];
935 >        double  blurf;
936 >        int     nblur = getblur(&blurf);
937 >        char    fnbefore[128], fnafter[128], *fbase;
938          char    combuf[1024], fname0[128], fname1[128];
939          int     usepinterp, usepfilt, nora_rgbe;
940          int     frseq[2];
941                                                  /* check what is needed */
942 <        usepinterp = atoi(vval(MBLUR));
942 >        usepinterp = (nblur > 1);
943          usepfilt = pfiltalways | ep==NULL;
944          if (ep != NULL && !strcmp(ep, "1"))
945                  ep = "+0";
# Line 828 | Line 948 | int    rvr;
948                                                  /* compute rendered views */
949          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
950          frseq[1] = frseq[0] + vint(INTERP) + 1;
951 +        fbase = dirfile(NULL, vval(BASENAME));
952          if (frseq[1] > vint(END))
953                  frseq[1] = vint(END);
954          if (frseq[1] == frame) {                        /* pfilt only */
# Line 837 | Line 958 | int    rvr;
958          } else if (frseq[0] == frame) {         /* no interpolation needed */
959                  if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
960                          *arcnext++ = ' ';
961 <                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
961 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
962                          while (*arcnext) arcnext++;
963                          strcpy(arcnext, ".unf");
964                          arcnext += 4;
965                          if (usepinterp || vint(INTERP)) {       /* and Z-buf */
966                                  *arcnext++ = ' ';
967 <                                sprintf(arcnext, vval(BASENAME),
847 <                                                frame-vint(INTERP)-1);
967 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
968                                  while (*arcnext) arcnext++;
969                                  strcpy(arcnext, ".zbf");
970                                  arcnext += 4;
# Line 864 | Line 984 | int    rvr;
984          if (usepinterp) {                       /* using pinterp */
985                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
986                          return(1);
987 <                if (atoi(vval(MBLUR))) {
868 <                        FILE    *fp;            /* motion blurring */
987 >                if (nblur > 1) {                /* with pmblur */
988                          sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
989                                          '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                        }
990                          sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
991                                          'a'+(iter%26));
992 <                        if ((fp = fopen(fname1, "w")) == NULL) {
993 <                                perror(fname1); quit(1);
992 >                        if (!noaction) {
993 >                                FILE    *fp;            /* motion blurring */
994 >                                if ((fp = fopen(fname0, "w")) == NULL) {
995 >                                        perror(fname0); quit(1);
996 >                                }
997 >                                fputs(VIEWSTR, fp);
998 >                                fprintview(vp, fp);
999 >                                putc('\n', fp); fclose(fp);
1000 >                                if ((vp = getview(frame+1)) == NULL) {
1001 >                                        fprintf(stderr,
1002 >                        "%s: unexpected error reading view for frame %d\n",
1003 >                                                        progname, frame+1);
1004 >                                        quit(1);
1005 >                                }
1006 >                                if ((fp = fopen(fname1, "w")) == NULL) {
1007 >                                        perror(fname1); quit(1);
1008 >                                }
1009 >                                fputs(VIEWSTR, fp);
1010 >                                fprintview(vp, fp);
1011 >                                putc('\n', fp); fclose(fp);
1012                          }
888                        fputs(VIEWSTR, fp);
889                        fprintview(vp, fp);
890                        putc('\n', fp); fclose(fp);
1013                          sprintf(combuf,
1014 <                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
1015 <                        *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
894 <                                        atoi(vval(MBLUR)),
1014 >                        "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B",
1015 >                                        blurf, nblur,
1016                                          fname0, fname1, fname0, fname1);
1017                          iter++;
1018                  } else                          /* no blurring */
# Line 899 | Line 1020 | int    rvr;
1020                  strcat(combuf, viewopt(vp));
1021                  if (vbool(RTRACE))
1022                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
1023 <                                        rendopt, vval(OCTREE));
1023 >                                        rendopt+1, vval(OCTREE));
1024                  if (vdef(PINTERP))
1025                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
1026                  if (usepfilt)
# Line 970 | Line 1091 | int    n;
1091                  }
1092                  return(NULL);
1093          }
1094 <        if (viewfp == NULL) {           /* open file */
1094 >        if (viewfp == NULL) {                   /* open file */
1095                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1096                          perror(vval(VIEWFILE));
1097                          quit(1);
1098                  }
1099 <        } else if (n < viewnum) {       /* rewind file */
1099 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1100                  if (viewnum == 1 && feof(viewfp))
1101                          return(&curview);               /* just one view */
1102                  if (fseek(viewfp, 0L, 0) == EOF) {
# Line 985 | Line 1106 | int    n;
1106                  copystruct(&curview, &stdview);
1107                  viewnum = 0;
1108          }
1109 +        if (n < 0) {                            /* get next view */
1110 +                register int    c = getc(viewfp);
1111 +                if (c == EOF)
1112 +                        return((VIEW *)NULL);           /* that's it */
1113 +                ungetc(c, viewfp);
1114 +                n = viewnum + 1;
1115 +        }
1116          while (n > viewnum) {           /* scan to desired view */
1117                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1118 <                        return(viewnum==1 ? &curview : NULL);
1118 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1119                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1120                          viewnum++;
1121          }
# Line 998 | Line 1126 | int    n;
1126   int
1127   countviews()                    /* count views in view file */
1128   {
1129 <        register int    n = 0;
1129 >        int     n;
1130  
1131 <        while (getview(n+1) != NULL)
1131 >        if (getview(n=1) == NULL)
1132 >                return(0);
1133 >        while (getview(-1) != NULL)
1134                  n++;
1135          return(n);
1136   }
# Line 1020 | Line 1150 | int    n;
1150          if (n == 0) {                           /* signal to close file */
1151                  if (expfp != NULL) {
1152                          fclose(expfp);
1153 +                        free((void *)exppos);
1154                          expfp = NULL;
1155                  }
1156                  return(NULL);
1157 <        }
1157 >        } else if (n > vint(END))               /* request past end (error?) */
1158 >                return(NULL);
1159          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1160                  return(NULL);
1161          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1061 | Line 1193 | int    n;
1193                  }
1194                  curfrm++;
1195                  cp = fskip(expval);                     /* check format */
1196 <                if (cp == NULL || *cp != '\n') {
1196 >                if (cp != NULL)
1197 >                        while (isspace(*cp))
1198 >                                *cp++ = '\0';
1199 >                if (cp == NULL || *cp) {
1200                          fprintf(stderr,
1201                                  "%s: exposure format error on line %d\n",
1202                                          vval(EXPOSURE), curfrm);
1203                          quit(1);
1204                  }
1070                *cp = '\0';
1205          }
1206          return(expval);                         /* return value */
1207   }
# Line 1097 | Line 1231 | int    pn;
1231   int     status;
1232   {
1233          register PROC   *pp;
1234 +        register struct pslot   *psl;
1235  
1236          pp = ps->proc + pn;
1237          if (pp->elen) {                 /* pass errors */
# Line 1108 | Line 1243 | int    status;
1243                  if (ps->hostname[0])
1244                          status = 1;     /* because rsh doesn't return status */
1245          }
1246 +        lastpserver = NULL;
1247 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1248 +        if (psl->pid) {
1249 +                if (status) {
1250 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1251 +                                status = (*psl->rcvf)(psl->fout);
1252 +                        if (status) {
1253 +                                fprintf(stderr,
1254 +                                        "%s: error rendering frame %d\n",
1255 +                                                progname, psl->fout);
1256 +                                quit(1);
1257 +                        }
1258 +                        lastpserver = ps;
1259 +                }
1260 +                psl->pid = 0;                   /* free process slot */
1261 +        } else if (status)
1262 +                lastpserver = ps;
1263          freestr(pp->com);               /* free command string */
1112        lastpid = pp->pid;              /* record PID for bwait() */
1113        lastpserver = ps;               /* record server for serverdown() */
1264          return(status);
1265   }
1266  
# Line 1118 | Line 1268 | int    status;
1268   int
1269   serverdown()                    /* check status of last process server */
1270   {
1271 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1272 +                return(0);
1273          if (pserverOK(lastpserver))     /* server still up? */
1274                  return(0);
1275          delpserver(lastpserver);        /* else delete it */
# Line 1144 | Line 1296 | int    (*rf)();
1296                          printf("\t%s\n", com);  /* echo command */
1297                  return(0);
1298          }
1299 <                                        /* else start it when we can */
1300 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1299 >        com = savestr(com);             /* else start it when we can */
1300 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1301                  bwait(1);
1302          if (!silent) {                          /* echo command */
1303                  PSERVER *ps;
# Line 1167 | Line 1319 | bwait(ncoms)                           /* wait for batch job(s) to finish */
1319   int     ncoms;
1320   {
1321          int     status;
1170        register struct pslot   *psl;
1322  
1323          if (noaction)
1324                  return;
1325          while ((status = wait4job(NULL, -1)) != -1) {
1326 <                psl = findpslot(lastpid);
1327 <                if (status) {           /* attempt recovery */
1328 <                        serverdown();   /* check server */
1178 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1179 <                                fprintf(stderr,
1180 <                                        "%s: error rendering frame %d\n",
1181 <                                                progname, psl->fout);
1182 <                                quit(1);
1183 <                        }
1184 <                }
1185 <                psl->pid = 0;           /* free process slot */
1186 <                if (!--ncoms)
1187 <                        return;         /* done enough */
1326 >                serverdown();           /* update server status */
1327 >                if (--ncoms == 0)
1328 >                        break;          /* done enough */
1329          }
1330   }
1331  
# Line 1196 | Line 1337 | int    maxcopies;
1337   {
1338          int     retstatus = 0;
1339          int     hostcopies;
1340 <        char    com1buf[10240], *com1, *endcom1;
1340 >        char    buf[10240], *com1, *s;
1341          int     status;
1342 +        int     pfd;
1343 +        register int    n;
1344          register PSERVER        *ps;
1345  
1346          if (!silent)
# Line 1209 | Line 1352 | int    maxcopies;
1352          for (ps = pslist; ps != NULL; ps = ps->next) {
1353                  hostcopies = 0;
1354                  if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1355 <                        strcpy(com1=com1buf, com);      /* build -PP command */
1355 >                        strcpy(com1=buf, com);  /* build -PP command */
1356                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1357                                          vval(DIRECTORY), phostname(ps));
1358                          strcat(com1, ppins);
1359 <                        endcom1 = com1 + strlen(com1);
1217 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1218 <                                        vval(DIRECTORY), phostname(ps));
1219 <                } else {
1359 >                } else
1360                          com1 = com;
1361 <                        endcom1 = NULL;
1361 >                while (maxcopies > 0) {
1362 >                        s = savestr(com1);
1363 >                        if (startjob(ps, s, donecom) != -1) {
1364 >                                sleep(20);
1365 >                                hostcopies++;
1366 >                                maxcopies--;
1367 >                        } else {
1368 >                                freestr(s);
1369 >                                break;
1370 >                        }
1371                  }
1223                while (maxcopies > 0 &&
1224                                startjob(ps, savestr(com1), donecom) != -1) {
1225                        sleep(10);
1226                        hostcopies++;
1227                        maxcopies--;
1228                        if (endcom1 != NULL)
1229                                *endcom1 = '\0';
1230                }
1372                  if (!silent && hostcopies) {
1373                          if (hostcopies > 1)
1374                                  printf("\t%d duplicate processes", hostcopies);
# Line 1239 | Line 1380 | int    maxcopies;
1380          }
1381                                          /* wait for jobs to finish */
1382          while ((status = wait4job(NULL, -1)) != -1)
1383 <                if (status)
1384 <                        retstatus += !serverdown();     /* check server */
1383 >                retstatus += status && !serverdown();
1384 >                                        /* terminate parallel rpict's */
1385 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1386 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1387 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1388 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1389 >                        buf[n] = '\0';
1390 >                        close(pfd);
1391 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1392 >                                ;
1393 >                                                                /* terminate */
1394 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1395 >                        wait4job(ps, startjob(ps, buf, NULL));
1396 >                }
1397 >        }
1398          return(retstatus);
1399   }
1400  
# Line 1278 | Line 1432 | int    vc;
1432          fprintf(stderr, "%s: bad value for variable '%s'\n",
1433                          progname, vnam(vc));
1434          quit(1);
1435 + }
1436 +
1437 +
1438 + char *
1439 + dirfile(df, path)               /* separate path into directory and file */
1440 + char    *df;
1441 + register char   *path;
1442 + {
1443 +        register int    i;
1444 +        int     psep;
1445 +
1446 +        for (i = 0, psep = -1; path[i]; i++)
1447 +                if (path[i] == '/')
1448 +                        psep = i;
1449 +        if (df != NULL)
1450 +                if (psep == 0) {
1451 +                        df[0] = '/';
1452 +                        df[1] = '\0';
1453 +                } else if (psep > 0) {
1454 +                        strncpy(df, path, psep);
1455 +                        df[psep] = '\0';
1456 +                } else
1457 +                        df[0] = '\0';
1458 +        return(path+psep+1);
1459 + }
1460 +
1461 +
1462 + int
1463 + getblur(double *bf)             /* get # blur samples (and fraction) */
1464 + {
1465 +        double  blurf;
1466 +        int     nblur;
1467 +        char    *s;
1468 +
1469 +        if (!vdef(MBLUR)) {
1470 +                if (bf != NULL)
1471 +                        *bf = 0.0;
1472 +                return(0);
1473 +        }
1474 +        blurf = atof(vval(MBLUR));
1475 +        if (blurf < 0.0)
1476 +                blurf = 0.0;
1477 +        if (bf != NULL)
1478 +                *bf = blurf;
1479 +        if (blurf <= FTINY)
1480 +                return(0);
1481 +        s = sskip(vval(MBLUR));
1482 +        if (!*s)
1483 +                return(DEF_NBLUR);
1484 +        nblur = atoi(s);
1485 +        if (nblur <= 0)
1486 +                return(1);
1487 +        return(nblur);
1488   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines