--- ray/src/util/ranimate.c 1997/10/31 15:02:43 2.23 +++ ray/src/util/ranimate.c 1998/07/06 18:17:39 2.28 @@ -1,7 +1,7 @@ -/* Copyright (c) 1996 Regents of the University of California */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static char SCCSid[] = "$SunId$ SGI"; #endif /* @@ -21,57 +21,57 @@ static char SCCSid[] = "$SunId$ LBL"; #else #define REMSH "rsh" #endif - /* input variables */ -#define HOST 0 /* rendering host machine */ -#define RENDER 1 /* rendering options */ -#define PFILT 2 /* pfilt options */ -#define PINTERP 3 /* pinterp options */ -#define OCTREE 4 /* octree file name */ -#define DIRECTORY 5 /* working (sub)directory */ -#define BASENAME 6 /* output image base name */ -#define VIEWFILE 7 /* animation frame views */ -#define START 8 /* starting frame number */ -#define END 9 /* ending frame number */ -#define RIF 10 /* rad input file */ -#define NEXTANIM 11 /* next animation file */ -#define ANIMATE 12 /* animation command */ -#define TRANSFER 13 /* frame transfer command */ -#define ARCHIVE 14 /* archiving command */ -#define INTERP 15 /* # frames to interpolate */ -#define OVERSAMP 16 /* # times to oversample image */ -#define MBLUR 17 /* samples for motion blur */ -#define RTRACE 18 /* use rtrace with pinterp? */ -#define DISKSPACE 19 /* how much disk space to use */ -#define RESOLUTION 20 /* desired final resolution */ -#define EXPOSURE 21 /* how to compute exposure */ -#define RSH 22 /* remote shell script or program */ + /* input variables (alphabetical by name) */ +#define ANIMATE 0 /* animation command */ +#define ARCHIVE 1 /* archiving command */ +#define BASENAME 2 /* output image base name */ +#define DIRECTORY 3 /* working (sub)directory */ +#define DISKSPACE 4 /* how much disk space to use */ +#define END 5 /* ending frame number */ +#define EXPOSURE 6 /* how to compute exposure */ +#define HOST 7 /* rendering host machine */ +#define INTERP 8 /* # frames to interpolate */ +#define MBLUR 9 /* samples for motion blur */ +#define NEXTANIM 10 /* next animation file */ +#define OCTREE 11 /* octree file name */ +#define OVERSAMP 12 /* # times to oversample image */ +#define PFILT 13 /* pfilt options */ +#define PINTERP 14 /* pinterp options */ +#define RENDER 15 /* rendering options */ +#define RESOLUTION 16 /* desired final resolution */ +#define RIF 17 /* rad input file */ +#define RSH 18 /* remote shell script or program */ +#define RTRACE 19 /* use rtrace with pinterp? */ +#define START 20 /* starting frame number */ +#define TRANSFER 21 /* frame transfer command */ +#define VIEWFILE 22 /* animation frame views */ int NVARS = 23; /* total number of variables */ VARIABLE vv[] = { /* variable-value pairs */ - {"host", 4, 0, NULL, NULL}, - {"render", 3, 0, NULL, catvalues}, - {"pfilt", 2, 0, NULL, catvalues}, - {"pinterp", 2, 0, NULL, catvalues}, - {"OCTREE", 3, 0, NULL, onevalue}, - {"DIRECTORY", 3, 0, NULL, onevalue}, - {"BASENAME", 3, 0, NULL, onevalue}, - {"VIEWFILE", 2, 0, NULL, onevalue}, - {"START", 2, 0, NULL, intvalue}, - {"END", 2, 0, NULL, intvalue}, - {"RIF", 3, 0, NULL, onevalue}, - {"NEXTANIM", 3, 0, NULL, onevalue}, {"ANIMATE", 2, 0, NULL, onevalue}, - {"TRANSFER", 2, 0, NULL, onevalue}, {"ARCHIVE", 2, 0, NULL, onevalue}, + {"BASENAME", 3, 0, NULL, onevalue}, + {"DIRECTORY", 3, 0, NULL, onevalue}, + {"DISKSPACE", 3, 0, NULL, fltvalue}, + {"END", 2, 0, NULL, intvalue}, + {"EXPOSURE", 3, 0, NULL, onevalue}, + {"host", 4, 0, NULL, NULL}, {"INTERPOLATE", 3, 0, NULL, intvalue}, - {"OVERSAMPLE", 2, 0, NULL, fltvalue}, {"MBLUR", 2, 0, NULL, onevalue}, - {"RTRACE", 2, 0, NULL, boolvalue}, - {"DISKSPACE", 3, 0, NULL, fltvalue}, + {"NEXTANIM", 3, 0, NULL, onevalue}, + {"OCTREE", 3, 0, NULL, onevalue}, + {"OVERSAMPLE", 2, 0, NULL, fltvalue}, + {"pfilt", 2, 0, NULL, catvalues}, + {"pinterp", 2, 0, NULL, catvalues}, + {"render", 3, 0, NULL, catvalues}, {"RESOLUTION", 3, 0, NULL, onevalue}, - {"EXPOSURE", 3, 0, NULL, onevalue}, + {"RIF", 3, 0, NULL, onevalue}, {"RSH", 3, 0, NULL, onevalue}, + {"RTRACE", 2, 0, NULL, boolvalue}, + {"START", 2, 0, NULL, intvalue}, + {"TRANSFER", 2, 0, NULL, onevalue}, + {"VIEWFILE", 2, 0, NULL, onevalue}, }; #define SFNAME "STATUS" /* status file name */ @@ -115,7 +115,7 @@ struct pslot *findpslot(); PSERVER *lastpserver; /* last process server with error */ VIEW *getview(); -char *getexp(); +char *getexp(), *dirfile(); extern time_t fdate(), time(); @@ -474,11 +474,7 @@ char *rfargs; sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); cp += 11; /* point to file name */ } - if (system(combuf)) { - fprintf(stderr, "%s: error executing rad command:\n\t%s\n", - progname, combuf); - quit(1); - } + system(combuf); /* ignore exit code */ if (pippt == NULL) { /* load variables and remove file */ loadvars(cp); unlink(cp); @@ -536,9 +532,7 @@ animate() /* run animation */ quit(1); } /* initialize archive argument list */ - i = 16; - if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) - i = strlen(vval(ARCHIVE)); + i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; arcnext = arcfirst = arcargs + i; /* initialize status file */ if (astat.rnext == 0) @@ -642,7 +636,7 @@ filterframes() /* catch up with filtering */ transferframes() /* catch up with picture transfers */ { - char combuf[10240]; + char combuf[10240], *fbase; register char *cp; register int i; @@ -653,12 +647,19 @@ transferframes() /* catch up with picture transfers putastat(); /* update status */ return; } - strcpy(combuf, vval(TRANSFER)); /* start transfer command */ - cp = combuf + strlen(combuf); + strcpy(combuf, "cd "); /* start transfer command */ + fbase = dirfile(cp = combuf+3, vval(BASENAME)); + if (*cp) { + while (*++cp) ; + *cp++ = ';'; *cp++ = ' '; + } else + cp = combuf; + strcpy(cp, vval(TRANSFER)); + while (*cp) cp++; /* make argument list */ for (i = astat.tnext; i < astat.fnext; i++) { *cp++ = ' '; - sprintf(cp, vval(BASENAME), i); + sprintf(cp, fbase, i); while (*cp) cp++; strcpy(cp, ".pic"); cp += 4; @@ -707,7 +708,8 @@ char *vfn; close(open(combuf, O_RDONLY|O_CREAT, 0666)); } /* create command */ - sprintf(combuf, "rpict%s -w0", rendopt); + sprintf(combuf, "rpict%s%s -w0", rendopt, + viewopt(getview(first>1 ? first-1 : 1))); if (vint(INTERP) || atoi(vval(MBLUR))) sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", @@ -799,22 +801,40 @@ archive() /* archive and remove renderings */ { #define RMCOML (sizeof(rmcom)-1) static char rmcom[] = "rm -f"; - register int i; + char basedir[128]; + int dlen, alen; + register int j; if (arcnext == arcfirst) return; /* nothing to do */ + dirfile(basedir, vval(BASENAME)); + dlen = strlen(basedir); if (vdef(ARCHIVE)) { /* run archive command */ - i = strlen(vval(ARCHIVE)); - strncpy(arcfirst-i, vval(ARCHIVE), i); - if (runcom(arcfirst-i)) { + alen = strlen(vval(ARCHIVE)); + if (dlen) { + j = alen + dlen + 5; + strncpy(arcfirst-j, "cd ", 3); + strncpy(arcfirst-j+3, basedir, dlen); + (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; + } else + j = alen; + strncpy(arcfirst-alen, vval(ARCHIVE), alen); + if (runcom(arcfirst-j)) { fprintf(stderr, "%s: error running archive command\n", progname); quit(1); } } + if (dlen) { + j = RMCOML + dlen + 5; + strncpy(arcfirst-j, "cd ", 3); + strncpy(arcfirst-j+3, basedir, dlen); + (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; + } else + j = RMCOML; /* run remove command */ strncpy(arcfirst-RMCOML, rmcom, RMCOML); - runcom(arcfirst-RMCOML); + runcom(arcfirst-j); arcnext = arcfirst; /* reset argument list */ #undef RMCOML } @@ -829,7 +849,7 @@ int rvr; { extern int frecover(); static int iter = 0; - char fnbefore[128], fnafter[128]; + char fnbefore[128], fnafter[128], *fbase; char combuf[1024], fname0[128], fname1[128]; int usepinterp, usepfilt, nora_rgbe; int frseq[2]; @@ -843,6 +863,7 @@ int rvr; /* compute rendered views */ frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); frseq[1] = frseq[0] + vint(INTERP) + 1; + fbase = dirfile(NULL, vval(BASENAME)); if (frseq[1] > vint(END)) frseq[1] = vint(END); if (frseq[1] == frame) { /* pfilt only */ @@ -852,14 +873,13 @@ int rvr; } else if (frseq[0] == frame) { /* no interpolation needed */ if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ *arcnext++ = ' '; - sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); + sprintf(arcnext, fbase, frame-vint(INTERP)-1); while (*arcnext) arcnext++; strcpy(arcnext, ".unf"); arcnext += 4; if (usepinterp || vint(INTERP)) { /* and Z-buf */ *arcnext++ = ' '; - sprintf(arcnext, vval(BASENAME), - frame-vint(INTERP)-1); + sprintf(arcnext, fbase, frame-vint(INTERP)-1); while (*arcnext) arcnext++; strcpy(arcnext, ".zbf"); arcnext += 4; @@ -880,29 +900,31 @@ int rvr; if (rvr == 2 && recover(frseq[1])) /* recover after? */ return(1); if (atoi(vval(MBLUR))) { - FILE *fp; /* motion blurring */ sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), 'a'+(iter%26)); - if ((fp = fopen(fname0, "w")) == NULL) { - perror(fname0); quit(1); - } - fputs(VIEWSTR, fp); - fprintview(vp, fp); - putc('\n', fp); fclose(fp); - if ((vp = getview(frame+1)) == NULL) { - fprintf(stderr, - "%s: unexpected error reading view for frame %d\n", - progname, frame+1); - quit(1); - } sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), 'a'+(iter%26)); - if ((fp = fopen(fname1, "w")) == NULL) { - perror(fname1); quit(1); + if (!noaction) { + FILE *fp; /* motion blurring */ + if ((fp = fopen(fname0, "w")) == NULL) { + perror(fname0); quit(1); + } + fputs(VIEWSTR, fp); + fprintview(vp, fp); + putc('\n', fp); fclose(fp); + if ((vp = getview(frame+1)) == NULL) { + fprintf(stderr, + "%s: unexpected error reading view for frame %d\n", + progname, frame+1); + quit(1); + } + if ((fp = fopen(fname1, "w")) == NULL) { + perror(fname1); quit(1); + } + fputs(VIEWSTR, fp); + fprintview(vp, fp); + putc('\n', fp); fclose(fp); } - fputs(VIEWSTR, fp); - fprintview(vp, fp); - putc('\n', fp); fclose(fp); sprintf(combuf, "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", @@ -985,12 +1007,12 @@ int n; } return(NULL); } - if (viewfp == NULL) { /* open file */ + if (viewfp == NULL) { /* open file */ if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { perror(vval(VIEWFILE)); quit(1); } - } else if (n < viewnum) { /* rewind file */ + } else if (n > 0 && n < viewnum) { /* rewind file */ if (viewnum == 1 && feof(viewfp)) return(&curview); /* just one view */ if (fseek(viewfp, 0L, 0) == EOF) { @@ -1000,6 +1022,13 @@ int n; copystruct(&curview, &stdview); viewnum = 0; } + if (n < 0) { /* get next view */ + register int c = getc(viewfp); + if (c == EOF) + return((VIEW *)NULL); /* that's it */ + ungetc(c, viewfp); + n = viewnum + 1; + } while (n > viewnum) { /* scan to desired view */ if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) return(viewnum==1 ? &curview : (VIEW *)NULL); @@ -1013,9 +1042,11 @@ int n; int countviews() /* count views in view file */ { - register int n = 0; + int n; - while (getview(n+1) != NULL) + if (getview(n=1) == NULL) + return(0); + while (getview(-1) != NULL) n++; return(n); } @@ -1317,4 +1348,28 @@ int vc; fprintf(stderr, "%s: bad value for variable '%s'\n", progname, vnam(vc)); quit(1); +} + + +char * +dirfile(df, path) /* separate path into directory and file */ +char *df; +register char *path; +{ + register int i; + int psep; + + for (i = 0, psep = -1; path[i]; i++) + if (path[i] == '/') + psep = i; + if (df != NULL) + if (psep == 0) { + df[0] = '/'; + df[1] = '\0'; + } else if (psep > 0) { + strncpy(df, path, psep); + df[psep] = '\0'; + } else + df[0] = '\0'; + return(path+psep+1); }