| 1 |
– |
/* Copyright (c) 1995 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 |
< |
#include "standard.h" |
| 16 |
> |
#include "copyright.h" |
| 17 |
> |
|
| 18 |
> |
#include <stdio.h> |
| 19 |
|
#include <ctype.h> |
| 13 |
– |
#include <sys/types.h> |
| 20 |
|
#include <sys/stat.h> |
| 21 |
+ |
#include <time.h> |
| 22 |
+ |
|
| 23 |
+ |
/*#include "standard.h"*/ |
| 24 |
+ |
#include "platform.h" |
| 25 |
+ |
#include "paths.h" |
| 26 |
+ |
#include "rtio.h" |
| 27 |
+ |
#include "rterror.h" |
| 28 |
|
#include "view.h" |
| 29 |
|
#include "vars.h" |
| 30 |
|
#include "netproc.h" |
| 31 |
< |
/* input variables */ |
| 32 |
< |
#define HOST 0 /* rendering host machine */ |
| 33 |
< |
#define RENDER 1 /* rendering options */ |
| 34 |
< |
#define PFILT 2 /* pfilt options */ |
| 35 |
< |
#define PINTERP 3 /* pinterp options */ |
| 36 |
< |
#define OCTREE 4 /* octree file name */ |
| 37 |
< |
#define DIRECTORY 5 /* working (sub)directory */ |
| 38 |
< |
#define BASENAME 6 /* output image base name */ |
| 39 |
< |
#define VIEWFILE 7 /* animation frame views */ |
| 40 |
< |
#define START 8 /* starting frame number */ |
| 41 |
< |
#define END 9 /* ending frame number */ |
| 42 |
< |
#define RIF 10 /* rad input file */ |
| 43 |
< |
#define NEXTANIM 11 /* next animation file */ |
| 44 |
< |
#define ANIMATE 12 /* animation command */ |
| 45 |
< |
#define TRANSFER 13 /* frame transfer command */ |
| 46 |
< |
#define ARCHIVE 14 /* archiving command */ |
| 47 |
< |
#define INTERP 15 /* # frames to interpolate */ |
| 48 |
< |
#define OVERSAMP 16 /* # times to oversample image */ |
| 49 |
< |
#define MBLUR 17 /* samples for motion blur */ |
| 50 |
< |
#define RTRACE 18 /* use rtrace with pinterp? */ |
| 51 |
< |
#define DISKSPACE 19 /* how much disk space to use */ |
| 52 |
< |
#define RESOLUTION 20 /* desired final resolution */ |
| 53 |
< |
#define EXPOSURE 21 /* how to compute exposure */ |
| 31 |
> |
/* default blur samples */ |
| 32 |
> |
#ifndef DEF_NBLUR |
| 33 |
> |
#define DEF_NBLUR 5 |
| 34 |
> |
#endif |
| 35 |
> |
/* default remote shell */ |
| 36 |
> |
#define REMSH "rsh" |
| 37 |
> |
/* input variables (alphabetical by name) */ |
| 38 |
> |
#define ANIMATE 0 /* animation command */ |
| 39 |
> |
#define ARCHIVE 1 /* archiving command */ |
| 40 |
> |
#define BASENAME 2 /* output image base name */ |
| 41 |
> |
#define DIRECTORY 3 /* working (sub)directory */ |
| 42 |
> |
#define DISKSPACE 4 /* how much disk space to use */ |
| 43 |
> |
#define END 5 /* ending frame number */ |
| 44 |
> |
#define EXPOSURE 6 /* how to compute exposure */ |
| 45 |
> |
#define HOST 7 /* rendering host machine */ |
| 46 |
> |
#define INTERP 8 /* # frames to interpolate */ |
| 47 |
> |
#define MBLUR 9 /* motion blur parameters */ |
| 48 |
> |
#define NEXTANIM 10 /* next animation file */ |
| 49 |
> |
#define OCTREE 11 /* octree file name */ |
| 50 |
> |
#define OVERSAMP 12 /* # times to oversample image */ |
| 51 |
> |
#define PFILT 13 /* pfilt options */ |
| 52 |
> |
#define PINTERP 14 /* pinterp options */ |
| 53 |
> |
#define RENDER 15 /* rendering options */ |
| 54 |
> |
#define RESOLUTION 16 /* desired final resolution */ |
| 55 |
> |
#define RIF 17 /* rad input file */ |
| 56 |
> |
#define RSH 18 /* remote shell script or program */ |
| 57 |
> |
#define RTRACE 19 /* use rtrace with pinterp? */ |
| 58 |
> |
#define START 20 /* starting frame number */ |
| 59 |
> |
#define TRANSFER 21 /* frame transfer command */ |
| 60 |
> |
#define VIEWFILE 22 /* animation frame views */ |
| 61 |
|
|
| 62 |
< |
int NVARS = 22; /* total number of variables */ |
| 62 |
> |
int NVARS = 23; /* total number of variables */ |
| 63 |
|
|
| 64 |
|
VARIABLE vv[] = { /* variable-value pairs */ |
| 45 |
– |
{"host", 4, 0, NULL, NULL}, |
| 46 |
– |
{"render", 3, 0, NULL, catvalues}, |
| 47 |
– |
{"pfilt", 2, 0, NULL, catvalues}, |
| 48 |
– |
{"pinterp", 2, 0, NULL, catvalues}, |
| 49 |
– |
{"OCTREE", 3, 0, NULL, onevalue}, |
| 50 |
– |
{"DIRECTORY", 3, 0, NULL, onevalue}, |
| 51 |
– |
{"BASENAME", 3, 0, NULL, onevalue}, |
| 52 |
– |
{"VIEWFILE", 2, 0, NULL, onevalue}, |
| 53 |
– |
{"START", 2, 0, NULL, intvalue}, |
| 54 |
– |
{"END", 2, 0, NULL, intvalue}, |
| 55 |
– |
{"RIF", 3, 0, NULL, onevalue}, |
| 56 |
– |
{"NEXTANIM", 3, 0, NULL, onevalue}, |
| 65 |
|
{"ANIMATE", 2, 0, NULL, onevalue}, |
| 58 |
– |
{"TRANSFER", 2, 0, NULL, onevalue}, |
| 66 |
|
{"ARCHIVE", 2, 0, NULL, onevalue}, |
| 67 |
+ |
{"BASENAME", 3, 0, NULL, onevalue}, |
| 68 |
+ |
{"DIRECTORY", 3, 0, NULL, onevalue}, |
| 69 |
+ |
{"DISKSPACE", 3, 0, NULL, fltvalue}, |
| 70 |
+ |
{"END", 2, 0, NULL, intvalue}, |
| 71 |
+ |
{"EXPOSURE", 3, 0, NULL, onevalue}, |
| 72 |
+ |
{"host", 4, 0, NULL, NULL}, |
| 73 |
|
{"INTERPOLATE", 3, 0, NULL, intvalue}, |
| 61 |
– |
{"OVERSAMPLE", 2, 0, NULL, fltvalue}, |
| 74 |
|
{"MBLUR", 2, 0, NULL, onevalue}, |
| 75 |
< |
{"RTRACE", 2, 0, NULL, boolvalue}, |
| 76 |
< |
{"DISKSPACE", 3, 0, NULL, fltvalue}, |
| 75 |
> |
{"NEXTANIM", 3, 0, NULL, onevalue}, |
| 76 |
> |
{"OCTREE", 3, 0, NULL, onevalue}, |
| 77 |
> |
{"OVERSAMPLE", 2, 0, NULL, fltvalue}, |
| 78 |
> |
{"pfilt", 2, 0, NULL, catvalues}, |
| 79 |
> |
{"pinterp", 2, 0, NULL, catvalues}, |
| 80 |
> |
{"render", 3, 0, NULL, catvalues}, |
| 81 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
| 82 |
< |
{"EXPOSURE", 3, 0, NULL, onevalue}, |
| 82 |
> |
{"RIF", 3, 0, NULL, onevalue}, |
| 83 |
> |
{"RSH", 3, 0, NULL, onevalue}, |
| 84 |
> |
{"RTRACE", 2, 0, NULL, boolvalue}, |
| 85 |
> |
{"START", 2, 0, NULL, intvalue}, |
| 86 |
> |
{"TRANSFER", 2, 0, NULL, onevalue}, |
| 87 |
> |
{"VIEWFILE", 2, 0, NULL, onevalue}, |
| 88 |
|
}; |
| 89 |
|
|
| 90 |
|
#define SFNAME "STATUS" /* status file name */ |
| 105 |
|
int silent = 0; /* silent mode? */ |
| 106 |
|
int noaction = 0; /* take no action? */ |
| 107 |
|
|
| 108 |
< |
char rendopt[2048] = ""; /* rendering options */ |
| 108 |
> |
char *remsh; /* remote shell program/script */ |
| 109 |
> |
char rendopt[2048]; /* rendering options */ |
| 110 |
|
char rresopt[32]; /* rendering resolution options */ |
| 111 |
|
char fresopt[32]; /* filter resolution options */ |
| 112 |
|
int pfiltalways; /* always use pfilt? */ |
| 121 |
|
} *pslot; /* process slots */ |
| 122 |
|
int npslots; /* number of process slots */ |
| 123 |
|
|
| 102 |
– |
int lastpid; /* ID of last completed background process */ |
| 103 |
– |
PSERVER *lastpserver; /* last process server used */ |
| 104 |
– |
|
| 124 |
|
#define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) |
| 125 |
+ |
PSERVER *lastpserver; /* last process server with error */ |
| 126 |
|
|
| 127 |
< |
struct pslot *findpslot(); |
| 127 |
> |
static struct pslot * findpslot(int pid); |
| 128 |
> |
static void checkdir(void); |
| 129 |
> |
static VIEW * getview(int n); |
| 130 |
|
|
| 131 |
< |
VIEW *getview(); |
| 132 |
< |
char *getexp(); |
| 131 |
> |
static char * dirfile(char *df, register char *path); |
| 132 |
> |
static char * getexp(int n); |
| 133 |
> |
static int getblur(double *bf); |
| 134 |
> |
static int getastat(void); |
| 135 |
> |
static void getradfile(char *rfargs); |
| 136 |
> |
static void badvalue(int vc); |
| 137 |
> |
static int rmfile(char *fn); |
| 138 |
> |
static int runcom(char *cs); |
| 139 |
> |
static int pruncom(char *com, char *ppins, int maxcopies); |
| 140 |
> |
static void bwait(int ncoms); |
| 141 |
> |
static int bruncom(char *com, int fout, int (*rf)()); |
| 142 |
> |
static int serverdown(void); |
| 143 |
> |
static int donecom(PSERVER *ps, int pn, int status); |
| 144 |
> |
static int countviews(void); |
| 145 |
> |
static int dofilt(int frame, int rvr); |
| 146 |
> |
static void archive(void); |
| 147 |
> |
static int frecover(int frame); |
| 148 |
> |
static int recover(int frame); |
| 149 |
> |
static void sethosts(void); |
| 150 |
> |
static void walkwait(int first, int last, char *vfn); |
| 151 |
> |
static void animrend(int frame, VIEW *vp); |
| 152 |
> |
static void transferframes(void); |
| 153 |
> |
static void filterframes(void); |
| 154 |
> |
static void renderframes(int nframes); |
| 155 |
> |
static void animate(void); |
| 156 |
> |
static void setdefaults(void); |
| 157 |
> |
static void putastat(void); |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
main(argc, argv) |
| 187 |
|
cfname = argv[i]; |
| 188 |
|
/* load variables */ |
| 189 |
|
loadvars(cfname); |
| 190 |
+ |
/* check variables */ |
| 191 |
+ |
checkvalues(); |
| 192 |
|
/* did we get DIRECTORY? */ |
| 193 |
|
checkdir(); |
| 194 |
|
/* check status */ |
| 215 |
|
argv[i] = vval(NEXTANIM); /* just change input file */ |
| 216 |
|
if (!silent) |
| 217 |
|
printargs(argc, argv, stdout); |
| 218 |
< |
execvp(progname, argv); /* pass to next */ |
| 219 |
< |
quit(1); /* shouldn't return */ |
| 218 |
> |
if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL) |
| 219 |
> |
fprintf(stderr, "%s: command not found\n", progname); |
| 220 |
> |
else |
| 221 |
> |
execv(progname, argv); |
| 222 |
> |
quit(1); |
| 223 |
|
} |
| 224 |
|
quit(0); |
| 225 |
|
userr: |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
|
| 231 |
< |
getastat() /* check/set animation status */ |
| 231 |
> |
static int |
| 232 |
> |
getastat(void) /* check/set animation status */ |
| 233 |
|
{ |
| 234 |
< |
char buf[256]; |
| 234 |
> |
char sfname[256]; |
| 235 |
|
FILE *fp; |
| 236 |
|
|
| 237 |
< |
sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME); |
| 238 |
< |
if ((fp = fopen(buf, "r")) == NULL) { |
| 237 |
> |
sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME); |
| 238 |
> |
if ((fp = fopen(sfname, "r")) == NULL) { |
| 239 |
|
if (errno != ENOENT) { |
| 240 |
< |
perror(buf); |
| 240 |
> |
perror(sfname); |
| 241 |
|
return(-1); |
| 242 |
|
} |
| 243 |
|
astat.rnext = astat.fnext = astat.tnext = 0; |
| 257 |
|
goto fmterr; |
| 258 |
|
fclose(fp); |
| 259 |
|
if (astat.pid != 0) { /* thinks it's still running */ |
| 260 |
< |
gethostname(buf, sizeof(buf)); |
| 208 |
< |
if (strcmp(buf, astat.host)) { |
| 260 |
> |
if (strcmp(myhostname(), astat.host)) { |
| 261 |
|
fprintf(stderr, |
| 262 |
|
"%s: process %d may still be running on host %s\n", |
| 263 |
|
progname, astat.pid, astat.host); |
| 270 |
|
} |
| 271 |
|
/* assume it is dead */ |
| 272 |
|
} |
| 273 |
< |
if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ |
| 273 |
> |
if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */ |
| 274 |
|
fprintf(stderr, "%s: unfinished job \"%s\"\n", |
| 275 |
|
progname, astat.cfname); |
| 276 |
|
return(-1); |
| 277 |
|
} |
| 278 |
+ |
/* check control file mods. */ |
| 279 |
+ |
if (!nowarn && fdate(cfname) > fdate(sfname)) |
| 280 |
+ |
fprintf(stderr, |
| 281 |
+ |
"%s: warning - control file modified since last run\n", |
| 282 |
+ |
progname); |
| 283 |
|
setours: /* set our values */ |
| 284 |
< |
gethostname(astat.host, sizeof(astat.host)); |
| 284 |
> |
strcpy(astat.host, myhostname()); |
| 285 |
|
astat.pid = getpid(); |
| 286 |
|
strcpy(astat.cfname, cfname); |
| 287 |
|
return(0); |
| 288 |
|
fmterr: |
| 289 |
|
fprintf(stderr, "%s: format error in status file \"%s\"\n", |
| 290 |
< |
progname, buf); |
| 290 |
> |
progname, sfname); |
| 291 |
|
fclose(fp); |
| 292 |
|
return(-1); |
| 293 |
|
} |
| 294 |
|
|
| 295 |
|
|
| 296 |
< |
putastat() /* put out current status */ |
| 296 |
> |
static void |
| 297 |
> |
putastat(void) /* put out current status */ |
| 298 |
|
{ |
| 299 |
|
char buf[256]; |
| 300 |
|
FILE *fp; |
| 316 |
|
} |
| 317 |
|
|
| 318 |
|
|
| 319 |
< |
checkdir() /* make sure we have our directory */ |
| 319 |
> |
static void |
| 320 |
> |
checkdir(void) /* make sure we have our directory */ |
| 321 |
|
{ |
| 322 |
|
struct stat stb; |
| 323 |
|
|
| 339 |
|
} |
| 340 |
|
|
| 341 |
|
|
| 342 |
< |
setdefaults() /* set default values */ |
| 342 |
> |
static void |
| 343 |
> |
setdefaults(void) /* set default values */ |
| 344 |
|
{ |
| 345 |
+ |
extern char *atos(); |
| 346 |
+ |
int decades; |
| 347 |
|
char buf[256]; |
| 348 |
|
|
| 349 |
|
if (vdef(ANIMATE)) { |
| 377 |
|
quit(1); |
| 378 |
|
} |
| 379 |
|
if (!vdef(BASENAME)) { |
| 380 |
< |
sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); |
| 380 |
> |
decades = (int)log10((double)vint(END)) + 1; |
| 381 |
> |
if (decades < 3) decades = 3; |
| 382 |
> |
sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); |
| 383 |
|
vval(BASENAME) = savqstr(buf); |
| 384 |
|
vdef(BASENAME)++; |
| 385 |
|
} |
| 411 |
|
vval(DISKSPACE) = "100"; |
| 412 |
|
vdef(DISKSPACE)++; |
| 413 |
|
} |
| 414 |
+ |
if (!vdef(RSH)) { |
| 415 |
+ |
vval(RSH) = REMSH; |
| 416 |
+ |
vdef(RSH)++; |
| 417 |
+ |
} |
| 418 |
+ |
/* locate remote shell program */ |
| 419 |
+ |
atos(buf, sizeof(buf), vval(RSH)); |
| 420 |
+ |
if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL) |
| 421 |
+ |
remsh = savqstr(remsh); |
| 422 |
+ |
else |
| 423 |
+ |
remsh = vval(RSH); /* will generate error if used */ |
| 424 |
+ |
|
| 425 |
|
/* append rendering options */ |
| 426 |
|
if (vdef(RENDER)) |
| 427 |
|
sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER)); |
| 428 |
|
} |
| 429 |
|
|
| 430 |
|
|
| 431 |
< |
sethosts() /* set up process servers */ |
| 431 |
> |
static void |
| 432 |
> |
sethosts(void) /* set up process servers */ |
| 433 |
|
{ |
| 434 |
|
extern char *iskip(); |
| 435 |
|
char buf[256], *dir, *uname; |
| 484 |
|
} |
| 485 |
|
} |
| 486 |
|
|
| 487 |
< |
|
| 488 |
< |
getradfile(rfargs) /* run rad and get needed variables */ |
| 413 |
< |
char *rfargs; |
| 487 |
> |
static void |
| 488 |
> |
getradfile(char *rfargs) /* run rad and get needed variables */ |
| 489 |
|
{ |
| 490 |
|
static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; |
| 491 |
|
char combuf[256]; |
| 492 |
|
register int i; |
| 493 |
|
register char *cp; |
| 494 |
+ |
char *pippt; |
| 495 |
|
/* create rad command */ |
| 496 |
|
sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); |
| 497 |
|
sprintf(combuf, |
| 498 |
|
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
| 499 |
|
rfargs, rendopt+2); |
| 500 |
|
cp = combuf; |
| 501 |
< |
while (*cp) cp++; /* match unset variables */ |
| 501 |
> |
while (*cp) { |
| 502 |
> |
if (*cp == '|') pippt = cp; |
| 503 |
> |
cp++; |
| 504 |
> |
} /* match unset variables */ |
| 505 |
|
for (i = 0; mvar[i] >= 0; i++) |
| 506 |
|
if (!vdef(mvar[i])) { |
| 507 |
|
*cp++ = '|'; |
| 508 |
|
strcpy(cp, vnam(mvar[i])); |
| 509 |
|
while (*cp) cp++; |
| 510 |
+ |
pippt = NULL; |
| 511 |
|
} |
| 512 |
< |
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
| 513 |
< |
cp += 11; /* point to file name */ |
| 514 |
< |
if (system(combuf)) { |
| 515 |
< |
fprintf(stderr, "%s: error executing rad command:\n\t%s\n", |
| 516 |
< |
progname, combuf); |
| 437 |
< |
quit(1); |
| 512 |
> |
if (pippt != NULL) |
| 513 |
> |
strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ |
| 514 |
> |
else { |
| 515 |
> |
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
| 516 |
> |
cp += 11; /* point to file name */ |
| 517 |
|
} |
| 518 |
< |
loadvars(cp); /* load variables and remove file */ |
| 519 |
< |
unlink(cp); |
| 518 |
> |
system(combuf); /* ignore exit code */ |
| 519 |
> |
if (pippt == NULL) { /* load variables and remove file */ |
| 520 |
> |
loadvars(cp); |
| 521 |
> |
unlink(cp); |
| 522 |
> |
} |
| 523 |
|
} |
| 524 |
|
|
| 525 |
|
|
| 526 |
< |
animate() /* run animation */ |
| 526 |
> |
static void |
| 527 |
> |
animate(void) /* run animation */ |
| 528 |
|
{ |
| 529 |
|
int xres, yres; |
| 530 |
|
float pa, mult; |
| 535 |
|
i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa); |
| 536 |
|
mult = vflt(OVERSAMP); |
| 537 |
|
if (i == 3) { |
| 538 |
< |
sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres), |
| 538 |
> |
sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres), |
| 539 |
|
(int)(mult*yres), pa); |
| 540 |
< |
sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa); |
| 540 |
> |
sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa); |
| 541 |
|
} else if (i) { |
| 542 |
|
if (i == 1) yres = xres; |
| 543 |
|
sprintf(rresopt, "-x %d -y %d", (int)(mult*xres), |
| 554 |
|
progname, vnam(INTERP)); |
| 555 |
|
vval(INTERP) = "0"; |
| 556 |
|
} |
| 557 |
< |
if (atoi(vval(MBLUR))) { /* can't handle this yet */ |
| 557 |
> |
if (strcmp(vval(MBLUR),"0")) { /* can't handle this */ |
| 558 |
|
if (!nowarn) |
| 559 |
|
fprintf(stderr, |
| 560 |
|
"%s: resetting %s=0 for animation\n", |
| 564 |
|
} |
| 565 |
|
/* figure # frames per batch */ |
| 566 |
|
d1 = mult*xres*mult*yres*4; /* space for orig. picture */ |
| 567 |
< |
if ((i=vint(INTERP)) || atoi(vval(MBLUR))) |
| 568 |
< |
d1 += mult*xres*mult*yres*4; /* space for z-buffer */ |
| 567 |
> |
if ((i=vint(INTERP)) || getblur(NULL) > 1) |
| 568 |
> |
d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ |
| 569 |
|
d2 = xres*yres*4; /* space for final picture */ |
| 570 |
|
frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); |
| 571 |
|
if (frames_batch < i+2) { |
| 574 |
|
quit(1); |
| 575 |
|
} |
| 576 |
|
/* initialize archive argument list */ |
| 577 |
< |
i = 16; |
| 495 |
< |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) |
| 496 |
< |
i = strlen(vval(ARCHIVE)); |
| 577 |
> |
i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; |
| 578 |
|
arcnext = arcfirst = arcargs + i; |
| 579 |
|
/* initialize status file */ |
| 580 |
|
if (astat.rnext == 0) |
| 595 |
|
} |
| 596 |
|
|
| 597 |
|
|
| 598 |
< |
renderframes(nframes) /* render next nframes frames */ |
| 599 |
< |
int nframes; |
| 598 |
> |
static void |
| 599 |
> |
renderframes(int nframes) /* render next nframes frames */ |
| 600 |
|
{ |
| 601 |
|
static char vendbuf[16]; |
| 602 |
|
VIEW *vp; |
| 652 |
|
} |
| 653 |
|
|
| 654 |
|
|
| 655 |
< |
filterframes() /* catch up with filtering */ |
| 655 |
> |
static void |
| 656 |
> |
filterframes(void) /* catch up with filtering */ |
| 657 |
|
{ |
| 658 |
|
VIEW *vp; |
| 659 |
|
register int i; |
| 661 |
|
if (astat.tnext < astat.fnext) /* other work to do first */ |
| 662 |
|
return; |
| 663 |
|
/* filter each view */ |
| 664 |
< |
for (i = astat.fnext; i < astat.rnext; i++) { |
| 665 |
< |
if ((vp = getview(i)) == NULL) { /* get view i */ |
| 666 |
< |
fprintf(stderr, |
| 585 |
< |
"%s: unexpected error reading view for frame %d\n", |
| 586 |
< |
progname, i); |
| 587 |
< |
quit(1); |
| 588 |
< |
} |
| 589 |
< |
dofilt(i, vp, getexp(i), 0); /* filter frame */ |
| 590 |
< |
} |
| 664 |
> |
for (i = astat.fnext; i < astat.rnext; i++) |
| 665 |
> |
dofilt(i, 0); |
| 666 |
> |
|
| 667 |
|
bwait(0); /* wait for filter processes */ |
| 668 |
|
archive(); /* archive originals */ |
| 669 |
|
astat.fnext = i; /* update status */ |
| 671 |
|
} |
| 672 |
|
|
| 673 |
|
|
| 674 |
< |
transferframes() /* catch up with picture transfers */ |
| 674 |
> |
static void |
| 675 |
> |
transferframes(void) /* catch up with picture transfers */ |
| 676 |
|
{ |
| 677 |
< |
char combuf[10240]; |
| 677 |
> |
char combuf[10240], *fbase; |
| 678 |
|
register char *cp; |
| 679 |
|
register int i; |
| 680 |
|
|
| 685 |
|
putastat(); /* update status */ |
| 686 |
|
return; |
| 687 |
|
} |
| 688 |
< |
strcpy(combuf, vval(TRANSFER)); /* start transfer command */ |
| 689 |
< |
cp = combuf + strlen(combuf); |
| 688 |
> |
strcpy(combuf, "cd "); /* start transfer command */ |
| 689 |
> |
fbase = dirfile(cp = combuf+3, vval(BASENAME)); |
| 690 |
> |
if (*cp) { |
| 691 |
> |
while (*++cp) ; |
| 692 |
> |
*cp++ = ';'; *cp++ = ' '; |
| 693 |
> |
} else |
| 694 |
> |
cp = combuf; |
| 695 |
> |
strcpy(cp, vval(TRANSFER)); |
| 696 |
> |
while (*cp) cp++; |
| 697 |
|
/* make argument list */ |
| 698 |
|
for (i = astat.tnext; i < astat.fnext; i++) { |
| 699 |
|
*cp++ = ' '; |
| 700 |
< |
sprintf(cp, vval(BASENAME), i); |
| 700 |
> |
sprintf(cp, fbase, i); |
| 701 |
|
while (*cp) cp++; |
| 702 |
|
strcpy(cp, ".pic"); |
| 703 |
|
cp += 4; |
| 712 |
|
} |
| 713 |
|
|
| 714 |
|
|
| 715 |
< |
animrend(frame, vp) /* start animation frame */ |
| 716 |
< |
int frame; |
| 717 |
< |
VIEW *vp; |
| 715 |
> |
static void |
| 716 |
> |
animrend( /* start animation frame */ |
| 717 |
> |
int frame, |
| 718 |
> |
VIEW *vp |
| 719 |
> |
) |
| 720 |
|
{ |
| 635 |
– |
extern int recover(); |
| 721 |
|
char combuf[2048]; |
| 722 |
|
char fname[128]; |
| 723 |
|
|
| 731 |
|
} |
| 732 |
|
|
| 733 |
|
|
| 734 |
< |
walkwait(first, last, vfn) /* walk-through frames */ |
| 735 |
< |
int first, last; |
| 736 |
< |
char *vfn; |
| 734 |
> |
static void |
| 735 |
> |
walkwait( /* walk-through frames */ |
| 736 |
> |
int first, |
| 737 |
> |
int last, |
| 738 |
> |
char *vfn |
| 739 |
> |
) |
| 740 |
|
{ |
| 741 |
+ |
double blurf; |
| 742 |
+ |
int nblur = getblur(&blurf); |
| 743 |
|
char combuf[2048]; |
| 744 |
< |
char *inspoint; |
| 744 |
> |
register char *inspoint; |
| 745 |
|
register int i; |
| 746 |
|
|
| 747 |
|
if (!noaction && vint(INTERP)) /* create dummy frames */ |
| 752 |
|
close(open(combuf, O_RDONLY|O_CREAT, 0666)); |
| 753 |
|
} |
| 754 |
|
/* create command */ |
| 755 |
< |
sprintf(combuf, "rpict%s -w0", rendopt); |
| 756 |
< |
if (vint(INTERP) || atoi(vval(MBLUR))) |
| 757 |
< |
sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); |
| 758 |
< |
sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", |
| 755 |
> |
sprintf(combuf, "rpict%s%s -w0", rendopt, |
| 756 |
> |
viewopt(getview(first>1 ? first-1 : 1))); |
| 757 |
> |
inspoint = combuf; |
| 758 |
> |
while (*inspoint) inspoint++; |
| 759 |
> |
if (nblur) { |
| 760 |
> |
sprintf(inspoint, " -pm %.3f", blurf/nblur); |
| 761 |
> |
while (*inspoint) inspoint++; |
| 762 |
> |
} |
| 763 |
> |
if (nblur > 1 || vint(INTERP)) { |
| 764 |
> |
sprintf(inspoint, " -z %s.zbf", vval(BASENAME)); |
| 765 |
> |
while (*inspoint) inspoint++; |
| 766 |
> |
} |
| 767 |
> |
sprintf(inspoint, " -o %s.unf %s -S %d", |
| 768 |
|
vval(BASENAME), rresopt, first); |
| 769 |
< |
inspoint = combuf + strlen(combuf); |
| 769 |
> |
while (*inspoint) inspoint++; |
| 770 |
|
sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); |
| 771 |
|
/* run in parallel */ |
| 772 |
|
i = (last-first+1)/(vint(INTERP)+1); |
| 786 |
|
} |
| 787 |
|
|
| 788 |
|
|
| 789 |
< |
int |
| 790 |
< |
recover(frame) /* recover the specified frame */ |
| 692 |
< |
int frame; |
| 789 |
> |
static int |
| 790 |
> |
recover(int frame) /* recover the specified frame */ |
| 791 |
|
{ |
| 792 |
|
static int *rfrm; /* list of recovered frames */ |
| 793 |
|
static int nrfrms = 0; |
| 794 |
+ |
double blurf; |
| 795 |
+ |
int nblur = getblur(&blurf); |
| 796 |
|
char combuf[2048]; |
| 797 |
|
char fname[128]; |
| 798 |
|
register char *cp; |
| 808 |
|
vval(ANIMATE), frame, rendopt); |
| 809 |
|
else |
| 810 |
|
sprintf(combuf, "rpict%s -w0", rendopt); |
| 811 |
< |
cp = combuf + strlen(combuf); |
| 812 |
< |
if (vint(INTERP) || atoi(vval(MBLUR))) { |
| 811 |
> |
cp = combuf; |
| 812 |
> |
while (*cp) cp++; |
| 813 |
> |
if (nblur) { |
| 814 |
> |
sprintf(cp, " -pm %.3f", blurf/nblur); |
| 815 |
> |
while (*cp) cp++; |
| 816 |
> |
} |
| 817 |
> |
if (nblur > 1 || vint(INTERP)) { |
| 818 |
|
sprintf(cp, " -z %s.zbf", fname); |
| 819 |
|
while (*cp) cp++; |
| 820 |
|
} |
| 828 |
|
return(1); |
| 829 |
|
/* add frame to recovered list */ |
| 830 |
|
if (nrfrms) |
| 831 |
< |
rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); |
| 831 |
> |
rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int)); |
| 832 |
|
else |
| 833 |
|
rfrm = (int *)malloc(sizeof(int)); |
| 834 |
|
if (rfrm == NULL) { |
| 840 |
|
} |
| 841 |
|
|
| 842 |
|
|
| 843 |
< |
int |
| 844 |
< |
frecover(frame) /* recover filtered frame */ |
| 740 |
< |
int frame; |
| 843 |
> |
static int |
| 844 |
> |
frecover(int frame) /* recover filtered frame */ |
| 845 |
|
{ |
| 846 |
< |
VIEW *vp; |
| 743 |
< |
char *ex; |
| 744 |
< |
|
| 745 |
< |
vp = getview(frame); |
| 746 |
< |
ex = getexp(frame); |
| 747 |
< |
if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) |
| 846 |
> |
if (dofilt(frame, 2) && dofilt(frame, 1)) |
| 847 |
|
return(1); |
| 848 |
|
return(0); |
| 849 |
|
} |
| 850 |
|
|
| 851 |
|
|
| 852 |
< |
archive() /* archive and remove renderings */ |
| 852 |
> |
static void |
| 853 |
> |
archive(void) /* archive and remove renderings */ |
| 854 |
|
{ |
| 855 |
|
#define RMCOML (sizeof(rmcom)-1) |
| 856 |
|
static char rmcom[] = "rm -f"; |
| 857 |
< |
register int i; |
| 857 |
> |
char basedir[128]; |
| 858 |
> |
int dlen, alen; |
| 859 |
> |
register int j; |
| 860 |
|
|
| 861 |
|
if (arcnext == arcfirst) |
| 862 |
|
return; /* nothing to do */ |
| 863 |
+ |
dirfile(basedir, vval(BASENAME)); |
| 864 |
+ |
dlen = strlen(basedir); |
| 865 |
|
if (vdef(ARCHIVE)) { /* run archive command */ |
| 866 |
< |
i = strlen(vval(ARCHIVE)); |
| 867 |
< |
strncpy(arcfirst-i, vval(ARCHIVE), i); |
| 868 |
< |
if (runcom(arcfirst-i)) { |
| 866 |
> |
alen = strlen(vval(ARCHIVE)); |
| 867 |
> |
if (dlen) { |
| 868 |
> |
j = alen + dlen + 5; |
| 869 |
> |
strncpy(arcfirst-j, "cd ", 3); |
| 870 |
> |
strncpy(arcfirst-j+3, basedir, dlen); |
| 871 |
> |
(arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; |
| 872 |
> |
} else |
| 873 |
> |
j = alen; |
| 874 |
> |
strncpy(arcfirst-alen, vval(ARCHIVE), alen); |
| 875 |
> |
if (runcom(arcfirst-j)) { |
| 876 |
|
fprintf(stderr, "%s: error running archive command\n", |
| 877 |
|
progname); |
| 878 |
|
quit(1); |
| 879 |
|
} |
| 880 |
|
} |
| 881 |
+ |
if (dlen) { |
| 882 |
+ |
j = RMCOML + dlen + 5; |
| 883 |
+ |
strncpy(arcfirst-j, "cd ", 3); |
| 884 |
+ |
strncpy(arcfirst-j+3, basedir, dlen); |
| 885 |
+ |
(arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; |
| 886 |
+ |
} else |
| 887 |
+ |
j = RMCOML; |
| 888 |
|
/* run remove command */ |
| 889 |
|
strncpy(arcfirst-RMCOML, rmcom, RMCOML); |
| 890 |
< |
runcom(arcfirst-RMCOML); |
| 890 |
> |
runcom(arcfirst-j); |
| 891 |
|
arcnext = arcfirst; /* reset argument list */ |
| 892 |
|
#undef RMCOML |
| 893 |
|
} |
| 894 |
|
|
| 895 |
|
|
| 896 |
< |
int |
| 897 |
< |
dofilt(frame, vp, ep, rvr) /* filter frame */ |
| 898 |
< |
int frame; |
| 899 |
< |
VIEW *vp; |
| 900 |
< |
char *ep; |
| 783 |
< |
int rvr; |
| 896 |
> |
static int |
| 897 |
> |
dofilt( /* filter frame */ |
| 898 |
> |
int frame, |
| 899 |
> |
int rvr |
| 900 |
> |
) |
| 901 |
|
{ |
| 785 |
– |
extern int frecover(); |
| 902 |
|
static int iter = 0; |
| 903 |
< |
char fnbefore[128], fnafter[128]; |
| 903 |
> |
double blurf; |
| 904 |
> |
int nblur = getblur(&blurf); |
| 905 |
> |
VIEW *vp = getview(frame); |
| 906 |
> |
char *ep = getexp(frame); |
| 907 |
> |
char fnbefore[128], fnafter[128], *fbase; |
| 908 |
|
char combuf[1024], fname0[128], fname1[128]; |
| 909 |
|
int usepinterp, usepfilt, nora_rgbe; |
| 910 |
|
int frseq[2]; |
| 911 |
|
/* check what is needed */ |
| 912 |
< |
usepinterp = atoi(vval(MBLUR)); |
| 913 |
< |
usepfilt = pfiltalways | ep==NULL; |
| 912 |
> |
if (vp == NULL) { |
| 913 |
> |
fprintf(stderr, |
| 914 |
> |
"%s: unexpected error reading view for frame %d\n", |
| 915 |
> |
progname, frame); |
| 916 |
> |
quit(1); |
| 917 |
> |
} |
| 918 |
> |
usepinterp = (nblur > 1); |
| 919 |
> |
usepfilt = pfiltalways | (ep==NULL); |
| 920 |
|
if (ep != NULL && !strcmp(ep, "1")) |
| 921 |
|
ep = "+0"; |
| 922 |
|
nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || |
| 924 |
|
/* compute rendered views */ |
| 925 |
|
frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); |
| 926 |
|
frseq[1] = frseq[0] + vint(INTERP) + 1; |
| 927 |
+ |
fbase = dirfile(NULL, vval(BASENAME)); |
| 928 |
|
if (frseq[1] > vint(END)) |
| 929 |
|
frseq[1] = vint(END); |
| 930 |
|
if (frseq[1] == frame) { /* pfilt only */ |
| 934 |
|
} else if (frseq[0] == frame) { /* no interpolation needed */ |
| 935 |
|
if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ |
| 936 |
|
*arcnext++ = ' '; |
| 937 |
< |
sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); |
| 937 |
> |
sprintf(arcnext, fbase, frame-vint(INTERP)-1); |
| 938 |
|
while (*arcnext) arcnext++; |
| 939 |
|
strcpy(arcnext, ".unf"); |
| 940 |
|
arcnext += 4; |
| 941 |
< |
if (usepinterp || vint(INTERP)) { /* and z-buf */ |
| 941 |
> |
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
| 942 |
|
*arcnext++ = ' '; |
| 943 |
< |
sprintf(arcnext, vval(BASENAME), |
| 817 |
< |
frame-vint(INTERP)-1); |
| 943 |
> |
sprintf(arcnext, fbase, frame-vint(INTERP)-1); |
| 944 |
|
while (*arcnext) arcnext++; |
| 945 |
|
strcpy(arcnext, ".zbf"); |
| 946 |
|
arcnext += 4; |
| 960 |
|
if (usepinterp) { /* using pinterp */ |
| 961 |
|
if (rvr == 2 && recover(frseq[1])) /* recover after? */ |
| 962 |
|
return(1); |
| 963 |
< |
if (atoi(vval(MBLUR))) { |
| 838 |
< |
FILE *fp; /* motion blurring */ |
| 963 |
> |
if (nblur > 1) { /* with pmblur */ |
| 964 |
|
sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), |
| 965 |
|
'a'+(iter%26)); |
| 841 |
– |
if ((fp = fopen(fname0, "w")) == NULL) { |
| 842 |
– |
perror(fname0); quit(1); |
| 843 |
– |
} |
| 844 |
– |
fputs(VIEWSTR, fp); |
| 845 |
– |
fprintview(vp, fp); |
| 846 |
– |
putc('\n', fp); fclose(fp); |
| 847 |
– |
if ((vp = getview(frame+1)) == NULL) { |
| 848 |
– |
fprintf(stderr, |
| 849 |
– |
"%s: unexpected error reading view for frame %d\n", |
| 850 |
– |
progname, frame+1); |
| 851 |
– |
quit(1); |
| 852 |
– |
} |
| 966 |
|
sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), |
| 967 |
|
'a'+(iter%26)); |
| 968 |
< |
if ((fp = fopen(fname1, "w")) == NULL) { |
| 969 |
< |
perror(fname1); quit(1); |
| 968 |
> |
if (!noaction) { |
| 969 |
> |
FILE *fp; /* motion blurring */ |
| 970 |
> |
if ((fp = fopen(fname0, "w")) == NULL) { |
| 971 |
> |
perror(fname0); quit(1); |
| 972 |
> |
} |
| 973 |
> |
fputs(VIEWSTR, fp); |
| 974 |
> |
fprintview(vp, fp); |
| 975 |
> |
putc('\n', fp); fclose(fp); |
| 976 |
> |
if ((vp = getview(frame+1)) == NULL) { |
| 977 |
> |
fprintf(stderr, |
| 978 |
> |
"%s: unexpected error reading view for frame %d\n", |
| 979 |
> |
progname, frame+1); |
| 980 |
> |
quit(1); |
| 981 |
> |
} |
| 982 |
> |
if ((fp = fopen(fname1, "w")) == NULL) { |
| 983 |
> |
perror(fname1); quit(1); |
| 984 |
> |
} |
| 985 |
> |
fputs(VIEWSTR, fp); |
| 986 |
> |
fprintview(vp, fp); |
| 987 |
> |
putc('\n', fp); fclose(fp); |
| 988 |
|
} |
| 858 |
– |
fputs(VIEWSTR, fp); |
| 859 |
– |
fprintview(vp, fp); |
| 860 |
– |
putc('\n', fp); fclose(fp); |
| 989 |
|
sprintf(combuf, |
| 990 |
< |
"(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", |
| 991 |
< |
*sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", |
| 864 |
< |
atoi(vval(MBLUR)), |
| 990 |
> |
"(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", |
| 991 |
> |
blurf, nblur, |
| 992 |
|
fname0, fname1, fname0, fname1); |
| 993 |
|
iter++; |
| 994 |
|
} else /* no blurring */ |
| 996 |
|
strcat(combuf, viewopt(vp)); |
| 997 |
|
if (vbool(RTRACE)) |
| 998 |
|
sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", |
| 999 |
< |
rendopt, vval(OCTREE)); |
| 999 |
> |
rendopt+1, vval(OCTREE)); |
| 1000 |
|
if (vdef(PINTERP)) |
| 1001 |
|
sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); |
| 1002 |
|
if (usepfilt) |
| 1003 |
|
sprintf(combuf+strlen(combuf), " %s", rresopt); |
| 1004 |
|
else |
| 1005 |
< |
sprintf(combuf+strlen(combuf), " %s -e %s", |
| 1005 |
> |
sprintf(combuf+strlen(combuf), " -a %s -e %s", |
| 1006 |
|
fresopt, ep); |
| 1007 |
|
sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", |
| 1008 |
|
fnbefore, fnbefore); |
| 1049 |
|
} |
| 1050 |
|
|
| 1051 |
|
|
| 1052 |
< |
VIEW * |
| 1053 |
< |
getview(n) /* get view number n */ |
| 927 |
< |
int n; |
| 1052 |
> |
static VIEW * |
| 1053 |
> |
getview(int n) /* get view number n */ |
| 1054 |
|
{ |
| 1055 |
|
static FILE *viewfp = NULL; /* view file pointer */ |
| 1056 |
|
static int viewnum = 0; /* current view number */ |
| 1062 |
|
fclose(viewfp); |
| 1063 |
|
viewfp = NULL; |
| 1064 |
|
viewnum = 0; |
| 1065 |
< |
copystruct(&curview, &stdview); |
| 1065 |
> |
curview = stdview; |
| 1066 |
|
} |
| 1067 |
|
return(NULL); |
| 1068 |
|
} |
| 1069 |
< |
if (viewfp == NULL) { /* open file */ |
| 1069 |
> |
if (viewfp == NULL) { /* open file */ |
| 1070 |
|
if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { |
| 1071 |
|
perror(vval(VIEWFILE)); |
| 1072 |
|
quit(1); |
| 1073 |
|
} |
| 1074 |
< |
} else if (n < viewnum) { /* rewind file */ |
| 1074 |
> |
} else if (n > 0 && n < viewnum) { /* rewind file */ |
| 1075 |
|
if (viewnum == 1 && feof(viewfp)) |
| 1076 |
|
return(&curview); /* just one view */ |
| 1077 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
| 1078 |
|
perror(vval(VIEWFILE)); |
| 1079 |
|
quit(1); |
| 1080 |
|
} |
| 1081 |
< |
copystruct(&curview, &stdview); |
| 1081 |
> |
curview = stdview; |
| 1082 |
|
viewnum = 0; |
| 1083 |
|
} |
| 1084 |
+ |
if (n < 0) { /* get next view */ |
| 1085 |
+ |
register int c = getc(viewfp); |
| 1086 |
+ |
if (c == EOF) |
| 1087 |
+ |
return((VIEW *)NULL); /* that's it */ |
| 1088 |
+ |
ungetc(c, viewfp); |
| 1089 |
+ |
n = viewnum + 1; |
| 1090 |
+ |
} |
| 1091 |
|
while (n > viewnum) { /* scan to desired view */ |
| 1092 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
| 1093 |
< |
return(viewnum==1 ? &curview : NULL); |
| 1093 |
> |
return(viewnum==1 ? &curview : (VIEW *)NULL); |
| 1094 |
|
if (isview(linebuf) && sscanview(&curview, linebuf) > 0) |
| 1095 |
|
viewnum++; |
| 1096 |
|
} |
| 1098 |
|
} |
| 1099 |
|
|
| 1100 |
|
|
| 1101 |
< |
int |
| 1102 |
< |
countviews() /* count views in view file */ |
| 1101 |
> |
static int |
| 1102 |
> |
countviews(void) /* count views in view file */ |
| 1103 |
|
{ |
| 1104 |
< |
register int n = 0; |
| 1104 |
> |
int n; |
| 1105 |
|
|
| 1106 |
< |
while (getview(n+1) != NULL) |
| 1106 |
> |
if (getview(n=1) == NULL) |
| 1107 |
> |
return(0); |
| 1108 |
> |
while (getview(-1) != NULL) |
| 1109 |
|
n++; |
| 1110 |
|
return(n); |
| 1111 |
|
} |
| 1112 |
|
|
| 1113 |
|
|
| 1114 |
< |
char * |
| 1115 |
< |
getexp(n) /* get exposure for nth frame */ |
| 981 |
< |
int n; |
| 1114 |
> |
static char * |
| 1115 |
> |
getexp(int n) /* get exposure for nth frame */ |
| 1116 |
|
{ |
| 1117 |
|
extern char *fskip(); |
| 1118 |
|
static char expval[32]; |
| 1124 |
|
if (n == 0) { /* signal to close file */ |
| 1125 |
|
if (expfp != NULL) { |
| 1126 |
|
fclose(expfp); |
| 1127 |
+ |
free((void *)exppos); |
| 1128 |
|
expfp = NULL; |
| 1129 |
|
} |
| 1130 |
|
return(NULL); |
| 1131 |
< |
} |
| 1131 |
> |
} else if (n > vint(END)) /* request past end (error?) */ |
| 1132 |
> |
return(NULL); |
| 1133 |
|
if (!vdef(EXPOSURE)) /* no setting (auto) */ |
| 1134 |
|
return(NULL); |
| 1135 |
|
if (isflt(vval(EXPOSURE))) /* always the same */ |
| 1167 |
|
} |
| 1168 |
|
curfrm++; |
| 1169 |
|
cp = fskip(expval); /* check format */ |
| 1170 |
< |
if (cp == NULL || *cp != '\n') { |
| 1170 |
> |
if (cp != NULL) |
| 1171 |
> |
while (isspace(*cp)) |
| 1172 |
> |
*cp++ = '\0'; |
| 1173 |
> |
if (cp == NULL || *cp) { |
| 1174 |
|
fprintf(stderr, |
| 1175 |
|
"%s: exposure format error on line %d\n", |
| 1176 |
|
vval(EXPOSURE), curfrm); |
| 1177 |
|
quit(1); |
| 1178 |
|
} |
| 1040 |
– |
*cp = '\0'; |
| 1179 |
|
} |
| 1180 |
|
return(expval); /* return value */ |
| 1181 |
|
} |
| 1182 |
|
|
| 1183 |
|
|
| 1184 |
< |
struct pslot * |
| 1185 |
< |
findpslot(pid) /* find or allocate a process slot */ |
| 1048 |
< |
int pid; |
| 1184 |
> |
static struct pslot * |
| 1185 |
> |
findpslot(int pid) /* find or allocate a process slot */ |
| 1186 |
|
{ |
| 1187 |
|
register struct pslot *psempty = NULL; |
| 1188 |
|
register int i; |
| 1197 |
|
} |
| 1198 |
|
|
| 1199 |
|
|
| 1200 |
< |
int |
| 1201 |
< |
donecom(ps, pn, status) /* clean up after finished process */ |
| 1202 |
< |
PSERVER *ps; |
| 1203 |
< |
int pn; |
| 1204 |
< |
int status; |
| 1200 |
> |
static int |
| 1201 |
> |
donecom( /* clean up after finished process */ |
| 1202 |
> |
PSERVER *ps, |
| 1203 |
> |
int pn, |
| 1204 |
> |
int status |
| 1205 |
> |
) |
| 1206 |
|
{ |
| 1207 |
< |
register PROC *pp; |
| 1207 |
> |
register NETPROC *pp; |
| 1208 |
> |
register struct pslot *psl; |
| 1209 |
|
|
| 1210 |
|
pp = ps->proc + pn; |
| 1211 |
|
if (pp->elen) { /* pass errors */ |
| 1217 |
|
if (ps->hostname[0]) |
| 1218 |
|
status = 1; /* because rsh doesn't return status */ |
| 1219 |
|
} |
| 1220 |
+ |
lastpserver = NULL; |
| 1221 |
+ |
psl = findpslot(pp->pid); /* check for bruncom() slot */ |
| 1222 |
+ |
if (psl->pid) { |
| 1223 |
+ |
if (status) { |
| 1224 |
+ |
if (psl->rcvf != NULL) /* attempt recovery */ |
| 1225 |
+ |
status = (*psl->rcvf)(psl->fout); |
| 1226 |
+ |
if (status) { |
| 1227 |
+ |
fprintf(stderr, |
| 1228 |
+ |
"%s: error rendering frame %d\n", |
| 1229 |
+ |
progname, psl->fout); |
| 1230 |
+ |
quit(1); |
| 1231 |
+ |
} |
| 1232 |
+ |
lastpserver = ps; |
| 1233 |
+ |
} |
| 1234 |
+ |
psl->pid = 0; /* free process slot */ |
| 1235 |
+ |
} else if (status) |
| 1236 |
+ |
lastpserver = ps; |
| 1237 |
|
freestr(pp->com); /* free command string */ |
| 1082 |
– |
lastpid = pp->pid; /* record PID for bwait() */ |
| 1083 |
– |
lastpserver = ps; /* record server for serverdown() */ |
| 1238 |
|
return(status); |
| 1239 |
|
} |
| 1240 |
|
|
| 1241 |
|
|
| 1242 |
< |
int |
| 1243 |
< |
serverdown() /* check status of last process server */ |
| 1242 |
> |
static int |
| 1243 |
> |
serverdown(void) /* check status of last process server */ |
| 1244 |
|
{ |
| 1245 |
+ |
if (lastpserver == NULL || !lastpserver->hostname[0]) |
| 1246 |
+ |
return(0); |
| 1247 |
|
if (pserverOK(lastpserver)) /* server still up? */ |
| 1248 |
|
return(0); |
| 1249 |
|
delpserver(lastpserver); /* else delete it */ |
| 1256 |
|
} |
| 1257 |
|
|
| 1258 |
|
|
| 1259 |
< |
int |
| 1260 |
< |
bruncom(com, fout, rf) /* run a command in the background */ |
| 1261 |
< |
char *com; |
| 1262 |
< |
int fout; |
| 1263 |
< |
int (*rf)(); |
| 1259 |
> |
static int |
| 1260 |
> |
bruncom( /* run a command in the background */ |
| 1261 |
> |
char *com, |
| 1262 |
> |
int fout, |
| 1263 |
> |
int (*rf)() |
| 1264 |
> |
) |
| 1265 |
|
{ |
| 1266 |
|
int pid; |
| 1267 |
|
register struct pslot *psl; |
| 1271 |
|
printf("\t%s\n", com); /* echo command */ |
| 1272 |
|
return(0); |
| 1273 |
|
} |
| 1274 |
< |
/* else start it when we can */ |
| 1275 |
< |
while ((pid = startjob(NULL, savestr(com), donecom)) == -1) |
| 1274 |
> |
com = savestr(com); /* else start it when we can */ |
| 1275 |
> |
while ((pid = startjob(NULL, com, donecom)) == -1) |
| 1276 |
|
bwait(1); |
| 1277 |
|
if (!silent) { /* echo command */ |
| 1278 |
|
PSERVER *ps; |
| 1290 |
|
} |
| 1291 |
|
|
| 1292 |
|
|
| 1293 |
< |
bwait(ncoms) /* wait for batch job(s) to finish */ |
| 1294 |
< |
int ncoms; |
| 1293 |
> |
static void |
| 1294 |
> |
bwait(int ncoms) /* wait for batch job(s) to finish */ |
| 1295 |
|
{ |
| 1296 |
|
int status; |
| 1140 |
– |
register struct pslot *psl; |
| 1297 |
|
|
| 1298 |
|
if (noaction) |
| 1299 |
|
return; |
| 1300 |
|
while ((status = wait4job(NULL, -1)) != -1) { |
| 1301 |
< |
psl = findpslot(lastpid); |
| 1302 |
< |
if (status) { /* attempt recovery */ |
| 1303 |
< |
serverdown(); /* check server */ |
| 1148 |
< |
if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { |
| 1149 |
< |
fprintf(stderr, |
| 1150 |
< |
"%s: error rendering frame %d\n", |
| 1151 |
< |
progname, psl->fout); |
| 1152 |
< |
quit(1); |
| 1153 |
< |
} |
| 1154 |
< |
} |
| 1155 |
< |
psl->pid = 0; /* free process slot */ |
| 1156 |
< |
if (!--ncoms) |
| 1157 |
< |
return; /* done enough */ |
| 1301 |
> |
serverdown(); /* update server status */ |
| 1302 |
> |
if (--ncoms == 0) |
| 1303 |
> |
break; /* done enough */ |
| 1304 |
|
} |
| 1305 |
|
} |
| 1306 |
|
|
| 1307 |
|
|
| 1308 |
< |
int |
| 1309 |
< |
pruncom(com, ppins, maxcopies) /* run a command in parallel over network */ |
| 1310 |
< |
char *com, *ppins; |
| 1311 |
< |
int maxcopies; |
| 1308 |
> |
static int |
| 1309 |
> |
pruncom( /* run a command in parallel over network */ |
| 1310 |
> |
char *com, |
| 1311 |
> |
char *ppins, |
| 1312 |
> |
int maxcopies |
| 1313 |
> |
) |
| 1314 |
|
{ |
| 1315 |
|
int retstatus = 0; |
| 1316 |
|
int hostcopies; |
| 1317 |
< |
char com1buf[10240], *com1, *endcom1; |
| 1317 |
> |
char buf[10240], *com1, *s; |
| 1318 |
|
int status; |
| 1319 |
+ |
int pfd; |
| 1320 |
+ |
register int n; |
| 1321 |
|
register PSERVER *ps; |
| 1322 |
|
|
| 1323 |
|
if (!silent) |
| 1329 |
|
for (ps = pslist; ps != NULL; ps = ps->next) { |
| 1330 |
|
hostcopies = 0; |
| 1331 |
|
if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) { |
| 1332 |
< |
strcpy(com1=com1buf, com); /* build -PP command */ |
| 1332 |
> |
strcpy(com1=buf, com); /* build -PP command */ |
| 1333 |
|
sprintf(com1+(ppins-com), " -PP %s/%s.persist", |
| 1334 |
|
vval(DIRECTORY), phostname(ps)); |
| 1335 |
+ |
unlink(com1+(ppins-com)+5); |
| 1336 |
|
strcat(com1, ppins); |
| 1337 |
< |
endcom1 = com1 + strlen(com1); |
| 1187 |
< |
sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`", |
| 1188 |
< |
vval(DIRECTORY), phostname(ps)); |
| 1189 |
< |
} else { |
| 1337 |
> |
} else |
| 1338 |
|
com1 = com; |
| 1339 |
< |
endcom1 = NULL; |
| 1339 |
> |
while (maxcopies > 0) { |
| 1340 |
> |
s = savestr(com1); |
| 1341 |
> |
if (startjob(ps, s, donecom) != -1) { |
| 1342 |
> |
sleep(20); |
| 1343 |
> |
hostcopies++; |
| 1344 |
> |
maxcopies--; |
| 1345 |
> |
} else { |
| 1346 |
> |
freestr(s); |
| 1347 |
> |
break; |
| 1348 |
> |
} |
| 1349 |
|
} |
| 1193 |
– |
while (maxcopies > 0 && |
| 1194 |
– |
startjob(ps, savestr(com1), donecom) != -1) { |
| 1195 |
– |
sleep(10); |
| 1196 |
– |
hostcopies++; |
| 1197 |
– |
maxcopies--; |
| 1198 |
– |
if (endcom1 != NULL) |
| 1199 |
– |
*endcom1 = '\0'; |
| 1200 |
– |
} |
| 1350 |
|
if (!silent && hostcopies) { |
| 1351 |
|
if (hostcopies > 1) |
| 1352 |
|
printf("\t%d duplicate processes", hostcopies); |
| 1358 |
|
} |
| 1359 |
|
/* wait for jobs to finish */ |
| 1360 |
|
while ((status = wait4job(NULL, -1)) != -1) |
| 1361 |
< |
if (status) |
| 1362 |
< |
retstatus += !serverdown(); /* check server */ |
| 1361 |
> |
retstatus += status && !serverdown(); |
| 1362 |
> |
/* terminate parallel rpict's */ |
| 1363 |
> |
for (ps = pslist; ps != NULL; ps = ps->next) { |
| 1364 |
> |
sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); |
| 1365 |
> |
if ((pfd = open(buf, O_RDONLY)) >= 0) { |
| 1366 |
> |
n = read(pfd, buf, sizeof(buf)-1); /* get PID */ |
| 1367 |
> |
buf[n] = '\0'; |
| 1368 |
> |
close(pfd); |
| 1369 |
> |
for (n = 0; buf[n] && !isspace(buf[n]); n++) |
| 1370 |
> |
; |
| 1371 |
> |
/* terminate */ |
| 1372 |
> |
sprintf(buf, "kill -ALRM %d", atoi(buf+n)); |
| 1373 |
> |
wait4job(ps, startjob(ps, buf, NULL)); |
| 1374 |
> |
} |
| 1375 |
> |
} |
| 1376 |
|
return(retstatus); |
| 1377 |
|
} |
| 1378 |
|
|
| 1379 |
|
|
| 1380 |
< |
runcom(cs) /* run a command locally and wait for it */ |
| 1381 |
< |
char *cs; |
| 1380 |
> |
static int |
| 1381 |
> |
runcom(char *cs) /* run a command locally and wait for it */ |
| 1382 |
|
{ |
| 1383 |
|
if (!silent) /* echo it */ |
| 1384 |
|
printf("\t%s\n", cs); |
| 1389 |
|
} |
| 1390 |
|
|
| 1391 |
|
|
| 1392 |
< |
rmfile(fn) /* remove a file */ |
| 1393 |
< |
char *fn; |
| 1392 |
> |
static int |
| 1393 |
> |
rmfile(char *fn) /* remove a file */ |
| 1394 |
|
{ |
| 1395 |
|
if (!silent) |
| 1396 |
< |
#ifdef MSDOS |
| 1396 |
> |
#ifdef _WIN32 |
| 1397 |
|
printf("\tdel %s\n", fn); |
| 1398 |
|
#else |
| 1399 |
|
printf("\trm -f %s\n", fn); |
| 1404 |
|
} |
| 1405 |
|
|
| 1406 |
|
|
| 1407 |
< |
badvalue(vc) /* report bad variable value and exit */ |
| 1408 |
< |
int vc; |
| 1407 |
> |
static void |
| 1408 |
> |
badvalue(int vc) /* report bad variable value and exit */ |
| 1409 |
|
{ |
| 1410 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
| 1411 |
|
progname, vnam(vc)); |
| 1412 |
|
quit(1); |
| 1413 |
+ |
} |
| 1414 |
+ |
|
| 1415 |
+ |
|
| 1416 |
+ |
static char * |
| 1417 |
+ |
dirfile( /* separate path into directory and file */ |
| 1418 |
+ |
char *df, |
| 1419 |
+ |
register char *path |
| 1420 |
+ |
) |
| 1421 |
+ |
{ |
| 1422 |
+ |
register int i; |
| 1423 |
+ |
int psep; |
| 1424 |
+ |
|
| 1425 |
+ |
for (i = 0, psep = -1; path[i]; i++) |
| 1426 |
+ |
if (path[i] == '/') |
| 1427 |
+ |
psep = i; |
| 1428 |
+ |
if (df != NULL) { |
| 1429 |
+ |
if (psep == 0) { |
| 1430 |
+ |
df[0] = '/'; |
| 1431 |
+ |
df[1] = '\0'; |
| 1432 |
+ |
} else if (psep > 0) { |
| 1433 |
+ |
strncpy(df, path, psep); |
| 1434 |
+ |
df[psep] = '\0'; |
| 1435 |
+ |
} else |
| 1436 |
+ |
df[0] = '\0'; |
| 1437 |
+ |
} |
| 1438 |
+ |
return(path+psep+1); |
| 1439 |
+ |
} |
| 1440 |
+ |
|
| 1441 |
+ |
|
| 1442 |
+ |
static int |
| 1443 |
+ |
getblur(double *bf) /* get # blur samples (and fraction) */ |
| 1444 |
+ |
{ |
| 1445 |
+ |
double blurf; |
| 1446 |
+ |
int nblur; |
| 1447 |
+ |
char *s; |
| 1448 |
+ |
|
| 1449 |
+ |
if (!vdef(MBLUR)) { |
| 1450 |
+ |
if (bf != NULL) |
| 1451 |
+ |
*bf = 0.0; |
| 1452 |
+ |
return(0); |
| 1453 |
+ |
} |
| 1454 |
+ |
blurf = atof(vval(MBLUR)); |
| 1455 |
+ |
if (blurf < 0.0) |
| 1456 |
+ |
blurf = 0.0; |
| 1457 |
+ |
if (bf != NULL) |
| 1458 |
+ |
*bf = blurf; |
| 1459 |
+ |
if (blurf <= FTINY) |
| 1460 |
+ |
return(0); |
| 1461 |
+ |
s = sskip(vval(MBLUR)); |
| 1462 |
+ |
if (!*s) |
| 1463 |
+ |
return(DEF_NBLUR); |
| 1464 |
+ |
nblur = atoi(s); |
| 1465 |
+ |
if (nblur <= 0) |
| 1466 |
+ |
return(1); |
| 1467 |
+ |
return(nblur); |
| 1468 |
|
} |