--- ray/src/util/ranimate.c 1998/06/03 16:37:51 2.27 +++ ray/src/util/ranimate.c 2003/10/21 19:19:29 2.42 @@ -1,26 +1,34 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ranimate.c,v 2.42 2003/10/21 19:19:29 schorsch Exp $"; #endif - /* * Radiance animation control program + * + * The main difference between this program and ranimove is that + * we have many optimizations here for camera motion in static + * environments, calling rpict and pinterp on multiple processors, + * where ranimove puts its emphasis on object motion, and does + * not use any external programs for image generation. + * + * See the ranimate(1) man page for further details. */ -#include "standard.h" +#include "copyright.h" + #include -#include #include + +#include "standard.h" +#include "paths.h" #include "view.h" #include "vars.h" #include "netproc.h" + /* default blur samples */ +#ifndef DEF_NBLUR +#define DEF_NBLUR 5 +#endif /* default remote shell */ -#ifdef _AUX_SOURCE -#define REMSH "remsh" -#else #define REMSH "rsh" -#endif /* input variables (alphabetical by name) */ #define ANIMATE 0 /* animation command */ #define ARCHIVE 1 /* archiving command */ @@ -31,7 +39,7 @@ static char SCCSid[] = "$SunId$ LBL"; #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 MBLUR 9 /* motion blur parameters */ #define NEXTANIM 10 /* next animation file */ #define OCTREE 11 /* octree file name */ #define OVERSAMP 12 /* # times to oversample image */ @@ -116,8 +124,9 @@ PSERVER *lastpserver; /* last process server with err VIEW *getview(); char *getexp(), *dirfile(); +int getblur(); -extern time_t fdate(), time(); +extern time_t time(); main(argc, argv) @@ -469,16 +478,12 @@ char *rfargs; pippt = NULL; } if (pippt != NULL) - strcpy(pippt, "> /dev/null"); /* nothing to match */ + strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ else { 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); @@ -516,7 +521,7 @@ animate() /* run animation */ progname, vnam(INTERP)); vval(INTERP) = "0"; } - if (atoi(vval(MBLUR))) { /* can't handle this yet */ + if (strcmp(vval(MBLUR),"0")) { /* can't handle this */ if (!nowarn) fprintf(stderr, "%s: resetting %s=0 for animation\n", @@ -526,7 +531,7 @@ animate() /* run animation */ } /* figure # frames per batch */ d1 = mult*xres*mult*yres*4; /* space for orig. picture */ - if ((i=vint(INTERP)) || atoi(vval(MBLUR))) + if ((i=vint(INTERP)) || getblur(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); @@ -622,15 +627,9 @@ filterframes() /* catch up with filtering */ if (astat.tnext < astat.fnext) /* other work to do first */ return; /* filter each view */ - for (i = astat.fnext; i < astat.rnext; i++) { - if ((vp = getview(i)) == NULL) { /* get view i */ - fprintf(stderr, - "%s: unexpected error reading view for frame %d\n", - progname, i); - quit(1); - } - dofilt(i, vp, getexp(i), 0); /* filter frame */ - } + for (i = astat.fnext; i < astat.rnext; i++) + dofilt(i, 0); + bwait(0); /* wait for filter processes */ archive(); /* archive originals */ astat.fnext = i; /* update status */ @@ -700,8 +699,10 @@ walkwait(first, last, vfn) /* walk-through frames */ int first, last; char *vfn; { + double blurf; + int nblur = getblur(&blurf); char combuf[2048]; - char *inspoint; + register char *inspoint; register int i; if (!noaction && vint(INTERP)) /* create dummy frames */ @@ -714,11 +715,19 @@ char *vfn; /* create command */ 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", + inspoint = combuf; + while (*inspoint) inspoint++; + if (nblur) { + sprintf(inspoint, " -pm %.3f", blurf/nblur); + while (*inspoint) inspoint++; + } + if (nblur > 1 || vint(INTERP)) { + sprintf(inspoint, " -z %s.zbf", vval(BASENAME)); + while (*inspoint) inspoint++; + } + sprintf(inspoint, " -o %s.unf %s -S %d", vval(BASENAME), rresopt, first); - inspoint = combuf + strlen(combuf); + while (*inspoint) inspoint++; sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); /* run in parallel */ i = (last-first+1)/(vint(INTERP)+1); @@ -744,6 +753,8 @@ int frame; { static int *rfrm; /* list of recovered frames */ static int nrfrms = 0; + double blurf; + int nblur = getblur(&blurf); char combuf[2048]; char fname[128]; register char *cp; @@ -759,8 +770,13 @@ int frame; vval(ANIMATE), frame, rendopt); else sprintf(combuf, "rpict%s -w0", rendopt); - cp = combuf + strlen(combuf); - if (vint(INTERP) || atoi(vval(MBLUR))) { + cp = combuf; + while (*cp) cp++; + if (nblur) { + sprintf(cp, " -pm %.3f", blurf/nblur); + while (*cp) cp++; + } + if (nblur > 1 || vint(INTERP)) { sprintf(cp, " -z %s.zbf", fname); while (*cp) cp++; } @@ -774,7 +790,7 @@ int frame; return(1); /* add frame to recovered list */ if (nrfrms) - rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); + rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int)); else rfrm = (int *)malloc(sizeof(int)); if (rfrm == NULL) { @@ -790,12 +806,7 @@ int frecover(frame) /* recover filtered frame */ int frame; { - VIEW *vp; - char *ex; - - vp = getview(frame); - ex = getexp(frame); - if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) + if (dofilt(frame, 2) && dofilt(frame, 1)) return(1); return(0); } @@ -845,21 +856,35 @@ archive() /* archive and remove renderings */ int -dofilt(frame, vp, ep, rvr) /* filter frame */ +dofilt(frame, rvr) /* filter frame */ int frame; -VIEW *vp; -char *ep; int rvr; { extern int frecover(); static int iter = 0; + double blurf; + int nblur = getblur(&blurf); + VIEW *vp = getview(frame); + char *ep = getexp(frame); char fnbefore[128], fnafter[128], *fbase; char combuf[1024], fname0[128], fname1[128]; int usepinterp, usepfilt, nora_rgbe; int frseq[2]; /* check what is needed */ - usepinterp = atoi(vval(MBLUR)); - usepfilt = pfiltalways | ep==NULL; + if (vp == NULL) { + fprintf(stderr, + "%s: unexpected error reading view for frame %d\n", + progname, frame); + quit(1); + } + if (ep == NULL) { + fprintf(stderr, + "%s: unexpected error reading exposure for frame %d\n", + progname, frame); + quit(1); + } + usepinterp = (nblur > 1); + usepfilt = pfiltalways | (ep==NULL); if (ep != NULL && !strcmp(ep, "1")) ep = "+0"; nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || @@ -903,7 +928,7 @@ int rvr; if (usepinterp) { /* using pinterp */ if (rvr == 2 && recover(frseq[1])) /* recover after? */ return(1); - if (atoi(vval(MBLUR))) { + if (nblur > 1) { /* with pmblur */ sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), 'a'+(iter%26)); sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), @@ -930,9 +955,8 @@ int rvr; 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", - atoi(vval(MBLUR)), + "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", + blurf, nblur, fname0, fname1, fname0, fname1); iter++; } else /* no blurring */ @@ -946,7 +970,7 @@ int rvr; if (usepfilt) sprintf(combuf+strlen(combuf), " %s", rresopt); else - sprintf(combuf+strlen(combuf), " %s -e %s", + sprintf(combuf+strlen(combuf), " -a %s -e %s", fresopt, ep); sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", fnbefore, fnbefore); @@ -1007,7 +1031,7 @@ int n; fclose(viewfp); viewfp = NULL; viewnum = 0; - copystruct(&curview, &stdview); + curview = stdview; } return(NULL); } @@ -1023,7 +1047,7 @@ int n; perror(vval(VIEWFILE)); quit(1); } - copystruct(&curview, &stdview); + curview = stdview; viewnum = 0; } if (n < 0) { /* get next view */ @@ -1070,7 +1094,7 @@ int n; if (n == 0) { /* signal to close file */ if (expfp != NULL) { fclose(expfp); - free((char *)exppos); + free((void *)exppos); expfp = NULL; } return(NULL); @@ -1275,6 +1299,7 @@ int maxcopies; strcpy(com1=buf, com); /* build -PP command */ sprintf(com1+(ppins-com), " -PP %s/%s.persist", vval(DIRECTORY), phostname(ps)); + unlink(com1+(ppins-com)+5); strcat(com1, ppins); } else com1 = com; @@ -1335,7 +1360,7 @@ rmfile(fn) /* remove a file */ char *fn; { if (!silent) -#ifdef MSDOS +#ifdef _WIN32 printf("\tdel %s\n", fn); #else printf("\trm -f %s\n", fn); @@ -1366,7 +1391,7 @@ register char *path; for (i = 0, psep = -1; path[i]; i++) if (path[i] == '/') psep = i; - if (df != NULL) + if (df != NULL) { if (psep == 0) { df[0] = '/'; df[1] = '\0'; @@ -1375,5 +1400,35 @@ register char *path; df[psep] = '\0'; } else df[0] = '\0'; + } return(path+psep+1); +} + + +int +getblur(double *bf) /* get # blur samples (and fraction) */ +{ + double blurf; + int nblur; + 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) + return(1); + return(nblur); }