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.19 by greg, Wed Jul 10 15:14:59 1996 UTC vs.
Revision 2.28 by gwlarson, Mon Jul 6 18:17:39 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1996 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   #else
22   #define REMSH           "rsh"
23   #endif
24 <                                /* input variables */
25 < #define HOST            0               /* rendering host machine */
26 < #define RENDER          1               /* rendering options */
27 < #define PFILT           2               /* pfilt options */
28 < #define PINTERP         3               /* pinterp options */
29 < #define OCTREE          4               /* octree file name */
30 < #define DIRECTORY       5               /* working (sub)directory */
31 < #define BASENAME        6               /* output image base name */
32 < #define VIEWFILE        7               /* animation frame views */
33 < #define START           8               /* starting frame number */
34 < #define END             9               /* ending frame number */
35 < #define RIF             10              /* rad input file */
36 < #define NEXTANIM        11              /* next animation file */
37 < #define ANIMATE         12              /* animation command */
38 < #define TRANSFER        13              /* frame transfer command */
39 < #define ARCHIVE         14              /* archiving command */
40 < #define INTERP          15              /* # frames to interpolate */
41 < #define OVERSAMP        16              /* # times to oversample image */
42 < #define MBLUR           17              /* samples for motion blur */
43 < #define RTRACE          18              /* use rtrace with pinterp? */
44 < #define DISKSPACE       19              /* how much disk space to use */
45 < #define RESOLUTION      20              /* desired final resolution */
46 < #define EXPOSURE        21              /* how to compute exposure */
47 < #define RSH             22              /* remote shell script or program */
24 >                                /* input variables (alphabetical by name) */
25 > #define ANIMATE         0               /* animation command */
26 > #define ARCHIVE         1               /* archiving command */
27 > #define BASENAME        2               /* output image base name */
28 > #define DIRECTORY       3               /* working (sub)directory */
29 > #define DISKSPACE       4               /* how much disk space to use */
30 > #define END             5               /* ending frame number */
31 > #define EXPOSURE        6               /* how to compute exposure */
32 > #define HOST            7               /* rendering host machine */
33 > #define INTERP          8               /* # frames to interpolate */
34 > #define MBLUR           9               /* samples for motion blur */
35 > #define NEXTANIM        10              /* next animation file */
36 > #define OCTREE          11              /* octree file name */
37 > #define OVERSAMP        12              /* # times to oversample image */
38 > #define PFILT           13              /* pfilt options */
39 > #define PINTERP         14              /* pinterp options */
40 > #define RENDER          15              /* rendering options */
41 > #define RESOLUTION      16              /* desired final resolution */
42 > #define RIF             17              /* rad input file */
43 > #define RSH             18              /* remote shell script or program */
44 > #define RTRACE          19              /* use rtrace with pinterp? */
45 > #define START           20              /* starting frame number */
46 > #define TRANSFER        21              /* frame transfer command */
47 > #define VIEWFILE        22              /* animation frame views */
48  
49   int     NVARS = 23;             /* total number of variables */
50  
51   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},
52          {"ANIMATE",     2,      0,      NULL,   onevalue},
65        {"TRANSFER",    2,      0,      NULL,   onevalue},
53          {"ARCHIVE",     2,      0,      NULL,   onevalue},
54 +        {"BASENAME",    3,      0,      NULL,   onevalue},
55 +        {"DIRECTORY",   3,      0,      NULL,   onevalue},
56 +        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
57 +        {"END",         2,      0,      NULL,   intvalue},
58 +        {"EXPOSURE",    3,      0,      NULL,   onevalue},
59 +        {"host",        4,      0,      NULL,   NULL},
60          {"INTERPOLATE", 3,      0,      NULL,   intvalue},
68        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
61          {"MBLUR",       2,      0,      NULL,   onevalue},
62 <        {"RTRACE",      2,      0,      NULL,   boolvalue},
63 <        {"DISKSPACE",   3,      0,      NULL,   fltvalue},
62 >        {"NEXTANIM",    3,      0,      NULL,   onevalue},
63 >        {"OCTREE",      3,      0,      NULL,   onevalue},
64 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
65 >        {"pfilt",       2,      0,      NULL,   catvalues},
66 >        {"pinterp",     2,      0,      NULL,   catvalues},
67 >        {"render",      3,      0,      NULL,   catvalues},
68          {"RESOLUTION",  3,      0,      NULL,   onevalue},
69 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
69 >        {"RIF",         3,      0,      NULL,   onevalue},
70          {"RSH",         3,      0,      NULL,   onevalue},
71 +        {"RTRACE",      2,      0,      NULL,   boolvalue},
72 +        {"START",       2,      0,      NULL,   intvalue},
73 +        {"TRANSFER",    2,      0,      NULL,   onevalue},
74 +        {"VIEWFILE",    2,      0,      NULL,   onevalue},
75   };
76  
77   #define SFNAME  "STATUS"                /* status file name */
# Line 93 | Line 93 | int    silent = 0;             /* silent mode? */
93   int     noaction = 0;           /* take no action? */
94  
95   char    *remsh;                 /* remote shell program/script */
96 < char    rendopt[2048] = "";     /* rendering options */
96 > char    rendopt[2048];          /* rendering options */
97   char    rresopt[32];            /* rendering resolution options */
98   char    fresopt[32];            /* filter resolution options */
99   int     pfiltalways;            /* always use pfilt? */
# Line 115 | Line 115 | struct pslot   *findpslot();
115   PSERVER *lastpserver;           /* last process server with error */
116  
117   VIEW    *getview();
118 < char    *getexp();
118 > char    *getexp(), *dirfile();
119  
120   extern time_t   fdate(), time();
121  
# Line 150 | Line 150 | char   *argv[];
150          cfname = argv[i];
151                                                  /* load variables */
152          loadvars(cfname);
153 +                                                /* check variables */
154 +        checkvalues();
155                                                  /* did we get DIRECTORY? */
156          checkdir();
157                                                  /* check status */
# Line 230 | Line 232 | getastat()                     /* check/set animation status */
232                  }
233                  /* assume it is dead */
234          }
235 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
235 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
236                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
237                                  progname, astat.cfname);
238                  return(-1);
# Line 448 | Line 450 | char   *rfargs;
450          char    combuf[256];
451          register int    i;
452          register char   *cp;
453 +        char    *pippt;
454                                          /* create rad command */
455          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
456          sprintf(combuf,
457          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
458                          rfargs, rendopt+2);
459          cp = combuf;
460 <        while (*cp) cp++;               /* match unset variables */
460 >        while (*cp) {
461 >                if (*cp == '|') pippt = cp;
462 >                cp++;
463 >        }                               /* match unset variables */
464          for (i = 0; mvar[i] >= 0; i++)
465                  if (!vdef(mvar[i])) {
466                          *cp++ = '|';
467                          strcpy(cp, vnam(mvar[i]));
468                          while (*cp) cp++;
469 +                        pippt = NULL;
470                  }
471 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
472 <        cp += 11;                       /* point to file name */
473 <        if (system(combuf)) {
474 <                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
475 <                                progname, combuf);
469 <                quit(1);
471 >        if (pippt != NULL)
472 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
473 >        else {
474 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
475 >                cp += 11;               /* point to file name */
476          }
477 <        loadvars(cp);                   /* load variables and remove file */
478 <        unlink(cp);
477 >        system(combuf);                 /* ignore exit code */
478 >        if (pippt == NULL) {            /* load variables and remove file */
479 >                loadvars(cp);
480 >                unlink(cp);
481 >        }
482   }
483  
484  
# Line 523 | Line 532 | animate()                      /* run animation */
532                  quit(1);
533          }
534                                          /* initialize archive argument list */
535 <        i = 16;
527 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
528 <                i = strlen(vval(ARCHIVE));
535 >        i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
536          arcnext = arcfirst = arcargs + i;
537                                          /* initialize status file */
538          if (astat.rnext == 0)
# Line 629 | Line 636 | filterframes()                         /* catch up with filtering */
636  
637   transferframes()                        /* catch up with picture transfers */
638   {
639 <        char    combuf[10240];
639 >        char    combuf[10240], *fbase;
640          register char   *cp;
641          register int    i;
642  
# Line 640 | Line 647 | transferframes()                       /* catch up with picture transfers
647                  putastat();             /* update status */
648                  return;
649          }
650 <        strcpy(combuf, vval(TRANSFER)); /* start transfer command */
651 <        cp = combuf + strlen(combuf);
650 >        strcpy(combuf, "cd ");          /* start transfer command */
651 >        fbase = dirfile(cp = combuf+3, vval(BASENAME));
652 >        if (*cp) {
653 >                while (*++cp) ;
654 >                *cp++ = ';'; *cp++ = ' ';
655 >        } else
656 >                cp = combuf;
657 >        strcpy(cp, vval(TRANSFER));
658 >        while (*cp) cp++;
659                                          /* make argument list */
660          for (i = astat.tnext; i < astat.fnext; i++) {
661                  *cp++ = ' ';
662 <                sprintf(cp, vval(BASENAME), i);
662 >                sprintf(cp, fbase, i);
663                  while (*cp) cp++;
664                  strcpy(cp, ".pic");
665                  cp += 4;
# Line 694 | Line 708 | char   *vfn;
708                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
709                          }
710                                          /* create command */
711 <        sprintf(combuf, "rpict%s -w0", rendopt);
711 >        sprintf(combuf, "rpict%s%s -w0", rendopt,
712 >                        viewopt(getview(first>1 ? first-1 : 1)));
713          if (vint(INTERP) || atoi(vval(MBLUR)))
714                  sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
715          sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
# Line 786 | Line 801 | archive()                      /* archive and remove renderings */
801   {
802   #define RMCOML  (sizeof(rmcom)-1)
803          static char     rmcom[] = "rm -f";
804 <        register int    i;
804 >        char    basedir[128];
805 >        int     dlen, alen;
806 >        register int    j;
807  
808          if (arcnext == arcfirst)
809                  return;                         /* nothing to do */
810 +        dirfile(basedir, vval(BASENAME));
811 +        dlen = strlen(basedir);
812          if (vdef(ARCHIVE)) {                    /* run archive command */
813 <                i = strlen(vval(ARCHIVE));
814 <                strncpy(arcfirst-i, vval(ARCHIVE), i);
815 <                if (runcom(arcfirst-i)) {
813 >                alen = strlen(vval(ARCHIVE));
814 >                if (dlen) {
815 >                        j = alen + dlen + 5;
816 >                        strncpy(arcfirst-j, "cd ", 3);
817 >                        strncpy(arcfirst-j+3, basedir, dlen);
818 >                        (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
819 >                } else
820 >                        j = alen;
821 >                strncpy(arcfirst-alen, vval(ARCHIVE), alen);
822 >                if (runcom(arcfirst-j)) {
823                          fprintf(stderr, "%s: error running archive command\n",
824                                          progname);
825                          quit(1);
826                  }
827          }
828 +        if (dlen) {
829 +                j = RMCOML + dlen + 5;
830 +                strncpy(arcfirst-j, "cd ", 3);
831 +                strncpy(arcfirst-j+3, basedir, dlen);
832 +                (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
833 +        } else
834 +                j = RMCOML;
835                                                  /* run remove command */
836          strncpy(arcfirst-RMCOML, rmcom, RMCOML);
837 <        runcom(arcfirst-RMCOML);
837 >        runcom(arcfirst-j);
838          arcnext = arcfirst;                     /* reset argument list */
839   #undef RMCOML
840   }
# Line 816 | Line 849 | int    rvr;
849   {
850          extern int      frecover();
851          static int      iter = 0;
852 <        char    fnbefore[128], fnafter[128];
852 >        char    fnbefore[128], fnafter[128], *fbase;
853          char    combuf[1024], fname0[128], fname1[128];
854          int     usepinterp, usepfilt, nora_rgbe;
855          int     frseq[2];
# Line 830 | Line 863 | int    rvr;
863                                                  /* compute rendered views */
864          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
865          frseq[1] = frseq[0] + vint(INTERP) + 1;
866 +        fbase = dirfile(NULL, vval(BASENAME));
867          if (frseq[1] > vint(END))
868                  frseq[1] = vint(END);
869          if (frseq[1] == frame) {                        /* pfilt only */
# Line 839 | Line 873 | int    rvr;
873          } else if (frseq[0] == frame) {         /* no interpolation needed */
874                  if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
875                          *arcnext++ = ' ';
876 <                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
876 >                        sprintf(arcnext, fbase, frame-vint(INTERP)-1);
877                          while (*arcnext) arcnext++;
878                          strcpy(arcnext, ".unf");
879                          arcnext += 4;
880                          if (usepinterp || vint(INTERP)) {       /* and Z-buf */
881                                  *arcnext++ = ' ';
882 <                                sprintf(arcnext, vval(BASENAME),
849 <                                                frame-vint(INTERP)-1);
882 >                                sprintf(arcnext, fbase, frame-vint(INTERP)-1);
883                                  while (*arcnext) arcnext++;
884                                  strcpy(arcnext, ".zbf");
885                                  arcnext += 4;
# Line 867 | Line 900 | int    rvr;
900                  if (rvr == 2 && recover(frseq[1]))      /* recover after? */
901                          return(1);
902                  if (atoi(vval(MBLUR))) {
870                        FILE    *fp;            /* motion blurring */
903                          sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
904                                          'a'+(iter%26));
873                        if ((fp = fopen(fname0, "w")) == NULL) {
874                                perror(fname0); quit(1);
875                        }
876                        fputs(VIEWSTR, fp);
877                        fprintview(vp, fp);
878                        putc('\n', fp); fclose(fp);
879                        if ((vp = getview(frame+1)) == NULL) {
880                                fprintf(stderr,
881                        "%s: unexpected error reading view for frame %d\n",
882                                                progname, frame+1);
883                                quit(1);
884                        }
905                          sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
906                                          'a'+(iter%26));
907 <                        if ((fp = fopen(fname1, "w")) == NULL) {
908 <                                perror(fname1); quit(1);
907 >                        if (!noaction) {
908 >                                FILE    *fp;            /* motion blurring */
909 >                                if ((fp = fopen(fname0, "w")) == NULL) {
910 >                                        perror(fname0); quit(1);
911 >                                }
912 >                                fputs(VIEWSTR, fp);
913 >                                fprintview(vp, fp);
914 >                                putc('\n', fp); fclose(fp);
915 >                                if ((vp = getview(frame+1)) == NULL) {
916 >                                        fprintf(stderr,
917 >                        "%s: unexpected error reading view for frame %d\n",
918 >                                                        progname, frame+1);
919 >                                        quit(1);
920 >                                }
921 >                                if ((fp = fopen(fname1, "w")) == NULL) {
922 >                                        perror(fname1); quit(1);
923 >                                }
924 >                                fputs(VIEWSTR, fp);
925 >                                fprintview(vp, fp);
926 >                                putc('\n', fp); fclose(fp);
927                          }
890                        fputs(VIEWSTR, fp);
891                        fprintview(vp, fp);
892                        putc('\n', fp); fclose(fp);
928                          sprintf(combuf,
929                          "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
930                          *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
# Line 901 | Line 936 | int    rvr;
936                  strcat(combuf, viewopt(vp));
937                  if (vbool(RTRACE))
938                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
939 <                                        rendopt, vval(OCTREE));
939 >                                        rendopt+1, vval(OCTREE));
940                  if (vdef(PINTERP))
941                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
942                  if (usepfilt)
# Line 972 | Line 1007 | int    n;
1007                  }
1008                  return(NULL);
1009          }
1010 <        if (viewfp == NULL) {           /* open file */
1010 >        if (viewfp == NULL) {                   /* open file */
1011                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1012                          perror(vval(VIEWFILE));
1013                          quit(1);
1014                  }
1015 <        } else if (n < viewnum) {       /* rewind file */
1015 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
1016                  if (viewnum == 1 && feof(viewfp))
1017                          return(&curview);               /* just one view */
1018                  if (fseek(viewfp, 0L, 0) == EOF) {
# Line 987 | Line 1022 | int    n;
1022                  copystruct(&curview, &stdview);
1023                  viewnum = 0;
1024          }
1025 +        if (n < 0) {                            /* get next view */
1026 +                register int    c = getc(viewfp);
1027 +                if (c == EOF)
1028 +                        return((VIEW *)NULL);           /* that's it */
1029 +                ungetc(c, viewfp);
1030 +                n = viewnum + 1;
1031 +        }
1032          while (n > viewnum) {           /* scan to desired view */
1033                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1034                          return(viewnum==1 ? &curview : (VIEW *)NULL);
# Line 1000 | Line 1042 | int    n;
1042   int
1043   countviews()                    /* count views in view file */
1044   {
1045 <        register int    n = 0;
1045 >        int     n;
1046  
1047 <        while (getview(n+1) != NULL)
1047 >        if (getview(n=1) == NULL)
1048 >                return(0);
1049 >        while (getview(-1) != NULL)
1050                  n++;
1051          return(n);
1052   }
# Line 1304 | Line 1348 | int    vc;
1348          fprintf(stderr, "%s: bad value for variable '%s'\n",
1349                          progname, vnam(vc));
1350          quit(1);
1351 + }
1352 +
1353 +
1354 + char *
1355 + dirfile(df, path)               /* separate path into directory and file */
1356 + char    *df;
1357 + register char   *path;
1358 + {
1359 +        register int    i;
1360 +        int     psep;
1361 +
1362 +        for (i = 0, psep = -1; path[i]; i++)
1363 +                if (path[i] == '/')
1364 +                        psep = i;
1365 +        if (df != NULL)
1366 +                if (psep == 0) {
1367 +                        df[0] = '/';
1368 +                        df[1] = '\0';
1369 +                } else if (psep > 0) {
1370 +                        strncpy(df, path, psep);
1371 +                        df[psep] = '\0';
1372 +                } else
1373 +                        df[0] = '\0';
1374 +        return(path+psep+1);
1375   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines