--- ray/src/util/ranimate.c 2004/02/15 06:21:01 2.45 +++ ray/src/util/ranimate.c 2006/04/18 04:30:35 2.52 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ranimate.c,v 2.45 2004/02/15 06:21:01 greg Exp $"; +static const char RCSid[] = "$Id: ranimate.c,v 2.52 2006/04/18 04:30:35 greg Exp $"; #endif /* * Radiance animation control program @@ -19,12 +19,12 @@ static const char RCSid[] = "$Id: ranimate.c,v 2.45 20 #include #include #include +#include -/*#include "standard.h"*/ #include "platform.h" +#include "rtprocess.h" #include "paths.h" -#include "rtio.h" -#include "rterror.h" +#include "standard.h" #include "view.h" #include "vars.h" #include "netproc.h" @@ -33,38 +33,42 @@ static const char RCSid[] = "$Id: ranimate.c,v 2.45 20 #define DEF_NBLUR 5 #endif /* default remote shell */ -#define REMSH "rsh" +#ifndef REMSH +#define REMSH "ssh" +#endif /* 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 /* motion blur parameters */ -#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 */ +#define DBLUR 3 /* depth of field blur */ +#define DIRECTORY 4 /* working (sub)directory */ +#define DISKSPACE 5 /* how much disk space to use */ +#define END 6 /* ending frame number */ +#define EXPOSURE 7 /* how to compute exposure */ +#define HOST 8 /* rendering host machine */ +#define INTERP 9 /* # frames to interpolate */ +#define MBLUR 10 /* motion blur parameters */ +#define NEXTANIM 11 /* next animation file */ +#define OCTREE 12 /* octree file name */ +#define OVERSAMP 13 /* # times to oversample image */ +#define PFILT 14 /* pfilt options */ +#define PINTERP 15 /* pinterp options */ +#define RENDER 16 /* rendering options */ +#define RESOLUTION 17 /* desired final resolution */ +#define RIF 18 /* rad input file */ +#define RSH 19 /* remote shell script or program */ +#define RTRACE 20 /* use rtrace with pinterp? */ +#define START 21 /* starting frame number */ +#define TRANSFER 22 /* frame transfer command */ +#define VIEWFILE 23 /* animation frame views */ -int NVARS = 23; /* total number of variables */ +int NVARS = 24; /* total number of variables */ VARIABLE vv[] = { /* variable-value pairs */ {"ANIMATE", 2, 0, NULL, onevalue}, {"ARCHIVE", 2, 0, NULL, onevalue}, {"BASENAME", 3, 0, NULL, onevalue}, + {"DBLUR", 2, 0, NULL, onevalue}, {"DIRECTORY", 3, 0, NULL, onevalue}, {"DISKSPACE", 3, 0, NULL, fltvalue}, {"END", 2, 0, NULL, intvalue}, @@ -91,7 +95,7 @@ VARIABLE vv[] = { /* variable-value pairs */ struct { char host[64]; /* control host name */ - int pid; /* control process id */ + RT_PID pid; /* control process id */ char cfname[128]; /* control file name */ int rnext; /* next frame to render */ int fnext; /* next frame to filter */ @@ -115,7 +119,7 @@ char arcargs[10240]; /* files to archive */ char *arcfirst, *arcnext; /* pointers to first and next argument */ struct pslot { - int pid; /* process ID (0 if empty) */ + RT_PID pid; /* process ID (0 if empty) */ int fout; /* output frame number */ int (*rcvf)(); /* recover function */ } *pslot; /* process slots */ @@ -124,13 +128,13 @@ int npslots; /* number of process slots */ #define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) PSERVER *lastpserver; /* last process server with error */ -static struct pslot * findpslot(int pid); +static struct pslot * findpslot(RT_PID pid); static void checkdir(void); static VIEW * getview(int n); static char * dirfile(char *df, register char *path); static char * getexp(int n); -static int getblur(double *bf); +static int getblur(double *mbf, double *dbf); static int getastat(void); static void getradfile(char *rfargs); static void badvalue(int vc); @@ -138,9 +142,9 @@ static int rmfile(char *fn); static int runcom(char *cs); static int pruncom(char *com, char *ppins, int maxcopies); static void bwait(int ncoms); -static int bruncom(char *com, int fout, int (*rf)()); +static RT_PID bruncom(char *com, int fout, int (*rf)()); static int serverdown(void); -static int donecom(PSERVER *ps, int pn, int status); +static pscompfunc donecom; static int countviews(void); static int dofilt(int frame, int rvr); static void archive(void); @@ -157,9 +161,11 @@ static void setdefaults(void); static void putastat(void); -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { int explicate = 0; int i; @@ -212,19 +218,23 @@ char *argv[]; animate(); /* all done */ if (vdef(NEXTANIM)) { + char *fullp; argv[i] = vval(NEXTANIM); /* just change input file */ if (!silent) printargs(argc, argv, stdout); - if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) - fprintf(stderr, "%s: command not found\n", progname); + fflush(stdout); + if ((fullp = getpath(argv[0],getenv("PATH"),X_OK)) == NULL) + fprintf(stderr, "%s: command not found\n", argv[0]); else - execv(progname, argv); + execv(fullp, argv); quit(1); } quit(0); + return(0); /* pro forma return */ userr: fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname); quit(1); + return 1; /* pro forma return */ } @@ -491,7 +501,7 @@ getradfile(char *rfargs) /* run rad and get needed va char combuf[256]; register int i; register char *cp; - char *pippt; + char *pippt = NULL; /* create rad command */ sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); sprintf(combuf, @@ -564,7 +574,7 @@ animate(void) /* run animation */ } /* figure # frames per batch */ d1 = mult*xres*mult*yres*4; /* space for orig. picture */ - if ((i=vint(INTERP)) || getblur(NULL) > 1) + if ((i=vint(INTERP)) || getblur(NULL, NULL) > 1) d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ d2 = xres*yres*4; /* space for final picture */ frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); @@ -655,7 +665,6 @@ renderframes(int nframes) /* render next nframes fram static void filterframes(void) /* catch up with filtering */ { - VIEW *vp; register int i; if (astat.tnext < astat.fnext) /* other work to do first */ @@ -738,8 +747,8 @@ int last, char *vfn ) { - double blurf; - int nblur = getblur(&blurf); + double mblurf, dblurf; + int nblur = getblur(&mblurf, &dblurf); char combuf[2048]; register char *inspoint; register int i; @@ -757,8 +766,10 @@ char *vfn inspoint = combuf; while (*inspoint) inspoint++; if (nblur) { - sprintf(inspoint, " -pm %.3f", blurf/nblur); + sprintf(inspoint, " -pm %.3f", mblurf/nblur); while (*inspoint) inspoint++; + sprintf(inspoint, " -pd %.3f", dblurf/nblur); + while (*inspoint) inspoint++; } if (nblur > 1 || vint(INTERP)) { sprintf(inspoint, " -z %s.zbf", vval(BASENAME)); @@ -791,8 +802,8 @@ recover(int frame) /* recover the specified frame */ { static int *rfrm; /* list of recovered frames */ static int nrfrms = 0; - double blurf; - int nblur = getblur(&blurf); + double mblurf, dblurf; + int nblur = getblur(&mblurf, &dblurf); char combuf[2048]; char fname[128]; register char *cp; @@ -811,8 +822,10 @@ recover(int frame) /* recover the specified frame */ cp = combuf; while (*cp) cp++; if (nblur) { - sprintf(cp, " -pm %.3f", blurf/nblur); + sprintf(cp, " -pm %.3f", mblurf/nblur); while (*cp) cp++; + sprintf(cp, " -pd %.3f", dblurf/nblur); + while (*cp) cp++; } if (nblur > 1 || vint(INTERP)) { sprintf(cp, " -z %s.zbf", fname); @@ -900,8 +913,8 @@ int rvr ) { static int iter = 0; - double blurf; - int nblur = getblur(&blurf); + double mblurf, dblurf; + int nblur = getblur(&mblurf, &dblurf); VIEW *vp = getview(frame); char *ep = getexp(frame); char fnbefore[128], fnafter[128], *fbase; @@ -933,6 +946,13 @@ int rvr usepfilt |= nora_rgbe; } else if (frseq[0] == frame) { /* no interpolation needed */ if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ + if (arcnext - arcargs + + strlen(fbase) >= sizeof(arcargs)-8) { + fprintf(stderr, +"%s: too many filenames in archive command -- reduce %s variable\n", + progname, vnam(DISKSPACE)); + quit(1); + } *arcnext++ = ' '; sprintf(arcnext, fbase, frame-vint(INTERP)-1); while (*arcnext) arcnext++; @@ -960,7 +980,7 @@ int rvr if (usepinterp) { /* using pinterp */ if (rvr == 2 && recover(frseq[1])) /* recover after? */ return(1); - if (nblur > 1) { /* with pmblur */ + if (nblur > 1) { /* with pdmblur */ sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), 'a'+(iter%26)); sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), @@ -987,8 +1007,8 @@ int rvr putc('\n', fp); fclose(fp); } sprintf(combuf, - "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", - blurf, nblur, + "(pmdblur %.3f %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", + mblurf, dblurf, nblur, fname0, fname1, fname0, fname1); iter++; } else /* no blurring */ @@ -1182,7 +1202,7 @@ getexp(int n) /* get exposure for nth frame */ static struct pslot * -findpslot(int pid) /* find or allocate a process slot */ +findpslot(RT_PID pid) /* find or allocate a process slot */ { register struct pslot *psempty = NULL; register int i; @@ -1199,9 +1219,9 @@ findpslot(int pid) /* find or allocate a process slo static int donecom( /* clean up after finished process */ -PSERVER *ps, -int pn, -int status + PSERVER *ps, + int pn, + int status ) { register NETPROC *pp; @@ -1256,14 +1276,14 @@ serverdown(void) /* check status of last process ser } -static int +static RT_PID bruncom( /* run a command in the background */ char *com, int fout, int (*rf)() ) { - int pid; + RT_PID pid; register struct pslot *psl; if (noaction) { @@ -1276,7 +1296,7 @@ int (*rf)() bwait(1); if (!silent) { /* echo command */ PSERVER *ps; - int psn = pid; + RT_PID psn = pid; ps = findjob(&psn); printf("\t%s\n", com); printf("\tProcess started on %s\n", phostname(ps)); @@ -1440,29 +1460,35 @@ register char *path static int -getblur(double *bf) /* get # blur samples (and fraction) */ +getblur(double *mbf, double *dbf) /* get # blur samples (and fraction) */ { - double blurf; - int nblur; + double mblurf, dblurf; + int nmblur, ndblur; char *s; - - if (!vdef(MBLUR)) { - if (bf != NULL) - *bf = 0.0; - return(0); - } - blurf = atof(vval(MBLUR)); - if (blurf < 0.0) - blurf = 0.0; - if (bf != NULL) - *bf = blurf; - if (blurf <= FTINY) - return(0); - s = sskip(vval(MBLUR)); - if (!*s) - return(DEF_NBLUR); - nblur = atoi(s); - if (nblur <= 0) + /* get motion blur */ + if (!vdef(MBLUR) || (mblurf = atof(vval(MBLUR))) < 0.0) + mblurf = 0.0; + if (mbf != NULL) + *mbf = mblurf; + if (mblurf <= FTINY) + nmblur = 0; + else if (!*(s = sskip(vval(MBLUR)))) + nmblur = DEF_NBLUR; + else if ((nmblur = atoi(s)) <= 0) + nmblur = 1; + /* get depth-of-field blur */ + if (!vdef(DBLUR) || (dblurf = atof(vval(DBLUR))) < 0.0) + dblurf = 0.0; + if (dbf != NULL) + *dbf = dblurf; + if (dblurf <= FTINY) + ndblur = 0; + else if (!*(s = sskip(vval(DBLUR)))) + ndblur = DEF_NBLUR; + else if ((ndblur = atoi(s)) <= 0) + ndblur = 1; + if ((nmblur == 1) & (ndblur == 1)) return(1); - return(nblur); + /* return combined samples */ + return(nmblur + ndblur); }