| 1 | – | /* Copyright (c) 1996 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 "copyright.h" | 
| 17 | + |  | 
| 18 |  | #include "standard.h" | 
| 19 |  | #include <ctype.h> | 
| 13 | – | #include <sys/types.h> | 
| 20 |  | #include <sys/stat.h> | 
| 21 |  | #include "view.h" | 
| 22 |  | #include "vars.h" | 
| 23 |  | #include "netproc.h" | 
| 24 | + | /* default blur samples */ | 
| 25 | + | #ifndef DEF_NBLUR | 
| 26 | + | #define DEF_NBLUR       5 | 
| 27 | + | #endif | 
| 28 |  | /* default remote shell */ | 
| 29 |  | #ifdef _AUX_SOURCE | 
| 30 |  | #define REMSH           "remsh" | 
| 31 |  | #else | 
| 32 |  | #define REMSH           "rsh" | 
| 33 |  | #endif | 
| 34 | < | /* input variables */ | 
| 35 | < | #define HOST            0               /* rendering host machine */ | 
| 36 | < | #define RENDER          1               /* rendering options */ | 
| 37 | < | #define PFILT           2               /* pfilt options */ | 
| 38 | < | #define PINTERP         3               /* pinterp options */ | 
| 39 | < | #define OCTREE          4               /* octree file name */ | 
| 40 | < | #define DIRECTORY       5               /* working (sub)directory */ | 
| 41 | < | #define BASENAME        6               /* output image base name */ | 
| 42 | < | #define VIEWFILE        7               /* animation frame views */ | 
| 43 | < | #define START           8               /* starting frame number */ | 
| 44 | < | #define END             9               /* ending frame number */ | 
| 45 | < | #define RIF             10              /* rad input file */ | 
| 46 | < | #define NEXTANIM        11              /* next animation file */ | 
| 47 | < | #define ANIMATE         12              /* animation command */ | 
| 48 | < | #define TRANSFER        13              /* frame transfer command */ | 
| 49 | < | #define ARCHIVE         14              /* archiving command */ | 
| 50 | < | #define INTERP          15              /* # frames to interpolate */ | 
| 51 | < | #define OVERSAMP        16              /* # times to oversample image */ | 
| 52 | < | #define MBLUR           17              /* samples for motion blur */ | 
| 53 | < | #define RTRACE          18              /* use rtrace with pinterp? */ | 
| 54 | < | #define DISKSPACE       19              /* how much disk space to use */ | 
| 55 | < | #define RESOLUTION      20              /* desired final resolution */ | 
| 56 | < | #define EXPOSURE        21              /* how to compute exposure */ | 
| 57 | < | #define RSH             22              /* remote shell script or program */ | 
| 34 | > | /* input variables (alphabetical by name) */ | 
| 35 | > | #define ANIMATE         0               /* animation command */ | 
| 36 | > | #define ARCHIVE         1               /* archiving command */ | 
| 37 | > | #define BASENAME        2               /* output image base name */ | 
| 38 | > | #define DIRECTORY       3               /* working (sub)directory */ | 
| 39 | > | #define DISKSPACE       4               /* how much disk space to use */ | 
| 40 | > | #define END             5               /* ending frame number */ | 
| 41 | > | #define EXPOSURE        6               /* how to compute exposure */ | 
| 42 | > | #define HOST            7               /* rendering host machine */ | 
| 43 | > | #define INTERP          8               /* # frames to interpolate */ | 
| 44 | > | #define MBLUR           9               /* motion blur parameters */ | 
| 45 | > | #define NEXTANIM        10              /* next animation file */ | 
| 46 | > | #define OCTREE          11              /* octree file name */ | 
| 47 | > | #define OVERSAMP        12              /* # times to oversample image */ | 
| 48 | > | #define PFILT           13              /* pfilt options */ | 
| 49 | > | #define PINTERP         14              /* pinterp options */ | 
| 50 | > | #define RENDER          15              /* rendering options */ | 
| 51 | > | #define RESOLUTION      16              /* desired final resolution */ | 
| 52 | > | #define RIF             17              /* rad input file */ | 
| 53 | > | #define RSH             18              /* remote shell script or program */ | 
| 54 | > | #define RTRACE          19              /* use rtrace with pinterp? */ | 
| 55 | > | #define START           20              /* starting frame number */ | 
| 56 | > | #define TRANSFER        21              /* frame transfer command */ | 
| 57 | > | #define VIEWFILE        22              /* animation frame views */ | 
| 58 |  |  | 
| 59 |  | int     NVARS = 23;             /* total number of variables */ | 
| 60 |  |  | 
| 61 |  | 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}, | 
| 62 |  | {"ANIMATE",     2,      0,      NULL,   onevalue}, | 
| 65 | – | {"TRANSFER",    2,      0,      NULL,   onevalue}, | 
| 63 |  | {"ARCHIVE",     2,      0,      NULL,   onevalue}, | 
| 64 | + | {"BASENAME",    3,      0,      NULL,   onevalue}, | 
| 65 | + | {"DIRECTORY",   3,      0,      NULL,   onevalue}, | 
| 66 | + | {"DISKSPACE",   3,      0,      NULL,   fltvalue}, | 
| 67 | + | {"END",         2,      0,      NULL,   intvalue}, | 
| 68 | + | {"EXPOSURE",    3,      0,      NULL,   onevalue}, | 
| 69 | + | {"host",        4,      0,      NULL,   NULL}, | 
| 70 |  | {"INTERPOLATE", 3,      0,      NULL,   intvalue}, | 
| 68 | – | {"OVERSAMPLE",  2,      0,      NULL,   fltvalue}, | 
| 71 |  | {"MBLUR",       2,      0,      NULL,   onevalue}, | 
| 72 | < | {"RTRACE",      2,      0,      NULL,   boolvalue}, | 
| 73 | < | {"DISKSPACE",   3,      0,      NULL,   fltvalue}, | 
| 72 | > | {"NEXTANIM",    3,      0,      NULL,   onevalue}, | 
| 73 | > | {"OCTREE",      3,      0,      NULL,   onevalue}, | 
| 74 | > | {"OVERSAMPLE",  2,      0,      NULL,   fltvalue}, | 
| 75 | > | {"pfilt",       2,      0,      NULL,   catvalues}, | 
| 76 | > | {"pinterp",     2,      0,      NULL,   catvalues}, | 
| 77 | > | {"render",      3,      0,      NULL,   catvalues}, | 
| 78 |  | {"RESOLUTION",  3,      0,      NULL,   onevalue}, | 
| 79 | < | {"EXPOSURE",    3,      0,      NULL,   onevalue}, | 
| 79 | > | {"RIF",         3,      0,      NULL,   onevalue}, | 
| 80 |  | {"RSH",         3,      0,      NULL,   onevalue}, | 
| 81 | + | {"RTRACE",      2,      0,      NULL,   boolvalue}, | 
| 82 | + | {"START",       2,      0,      NULL,   intvalue}, | 
| 83 | + | {"TRANSFER",    2,      0,      NULL,   onevalue}, | 
| 84 | + | {"VIEWFILE",    2,      0,      NULL,   onevalue}, | 
| 85 |  | }; | 
| 86 |  |  | 
| 87 |  | #define SFNAME  "STATUS"                /* status file name */ | 
| 103 |  | int     noaction = 0;           /* take no action? */ | 
| 104 |  |  | 
| 105 |  | char    *remsh;                 /* remote shell program/script */ | 
| 106 | < | char    rendopt[2048] = "";     /* rendering options */ | 
| 106 | > | char    rendopt[2048];          /* rendering options */ | 
| 107 |  | char    rresopt[32];            /* rendering resolution options */ | 
| 108 |  | char    fresopt[32];            /* filter resolution options */ | 
| 109 |  | int     pfiltalways;            /* always use pfilt? */ | 
| 118 |  | }       *pslot;                 /* process slots */ | 
| 119 |  | int     npslots;                /* number of process slots */ | 
| 120 |  |  | 
| 111 | – | int     lastpid;                /* ID of last completed background process */ | 
| 112 | – | PSERVER *lastpserver;           /* last process server used */ | 
| 113 | – |  | 
| 121 |  | #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host) | 
| 122 |  |  | 
| 123 |  | struct pslot    *findpslot(); | 
| 124 |  |  | 
| 125 | + | PSERVER *lastpserver;           /* last process server with error */ | 
| 126 | + |  | 
| 127 |  | VIEW    *getview(); | 
| 128 | < | char    *getexp(); | 
| 128 | > | char    *getexp(), *dirfile(); | 
| 129 | > | int     getblur(); | 
| 130 |  |  | 
| 131 | < | extern time_t   fdate(), time(); | 
| 131 | > | extern time_t   time(); | 
| 132 |  |  | 
| 133 |  |  | 
| 134 |  | main(argc, argv) | 
| 161 |  | cfname = argv[i]; | 
| 162 |  | /* load variables */ | 
| 163 |  | loadvars(cfname); | 
| 164 | + | /* check variables */ | 
| 165 | + | checkvalues(); | 
| 166 |  | /* did we get DIRECTORY? */ | 
| 167 |  | checkdir(); | 
| 168 |  | /* check status */ | 
| 243 |  | } | 
| 244 |  | /* assume it is dead */ | 
| 245 |  | } | 
| 246 | < | if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */ | 
| 246 | > | if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */ | 
| 247 |  | fprintf(stderr, "%s: unfinished job \"%s\"\n", | 
| 248 |  | progname, astat.cfname); | 
| 249 |  | return(-1); | 
| 313 |  | setdefaults()                   /* set default values */ | 
| 314 |  | { | 
| 315 |  | extern char     *atos(); | 
| 316 | + | int     decades; | 
| 317 |  | char    buf[256]; | 
| 318 |  |  | 
| 319 |  | if (vdef(ANIMATE)) { | 
| 347 |  | quit(1); | 
| 348 |  | } | 
| 349 |  | if (!vdef(BASENAME)) { | 
| 350 | < | sprintf(buf, "%s/frame%%03d", vval(DIRECTORY)); | 
| 350 | > | decades = (int)log10((double)vint(END)) + 1; | 
| 351 | > | if (decades < 3) decades = 3; | 
| 352 | > | sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades); | 
| 353 |  | vval(BASENAME) = savqstr(buf); | 
| 354 |  | vdef(BASENAME)++; | 
| 355 |  | } | 
| 461 |  | char    combuf[256]; | 
| 462 |  | register int    i; | 
| 463 |  | register char   *cp; | 
| 464 | + | char    *pippt; | 
| 465 |  | /* create rad command */ | 
| 466 |  | sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); | 
| 467 |  | sprintf(combuf, | 
| 468 |  | "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", | 
| 469 |  | rfargs, rendopt+2); | 
| 470 |  | cp = combuf; | 
| 471 | < | while (*cp) cp++;               /* match unset variables */ | 
| 471 | > | while (*cp) { | 
| 472 | > | if (*cp == '|') pippt = cp; | 
| 473 | > | cp++; | 
| 474 | > | }                               /* match unset variables */ | 
| 475 |  | for (i = 0; mvar[i] >= 0; i++) | 
| 476 |  | if (!vdef(mvar[i])) { | 
| 477 |  | *cp++ = '|'; | 
| 478 |  | strcpy(cp, vnam(mvar[i])); | 
| 479 |  | while (*cp) cp++; | 
| 480 | + | pippt = NULL; | 
| 481 |  | } | 
| 482 | < | sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); | 
| 483 | < | cp += 11;                       /* point to file name */ | 
| 484 | < | if (system(combuf)) { | 
| 485 | < | fprintf(stderr, "%s: error executing rad command:\n\t%s\n", | 
| 486 | < | progname, combuf); | 
| 467 | < | quit(1); | 
| 482 | > | if (pippt != NULL) | 
| 483 | > | strcpy(pippt, "> /dev/null");   /* nothing to match */ | 
| 484 | > | else { | 
| 485 | > | sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); | 
| 486 | > | cp += 11;               /* point to file name */ | 
| 487 |  | } | 
| 488 | < | loadvars(cp);                   /* load variables and remove file */ | 
| 489 | < | unlink(cp); | 
| 488 | > | system(combuf);                 /* ignore exit code */ | 
| 489 | > | if (pippt == NULL) {            /* load variables and remove file */ | 
| 490 | > | loadvars(cp); | 
| 491 | > | unlink(cp); | 
| 492 | > | } | 
| 493 |  | } | 
| 494 |  |  | 
| 495 |  |  | 
| 523 |  | progname, vnam(INTERP)); | 
| 524 |  | vval(INTERP) = "0"; | 
| 525 |  | } | 
| 526 | < | if (atoi(vval(MBLUR))) {        /* can't handle this yet */ | 
| 526 | > | if (strcmp(vval(MBLUR),"0")) {  /* can't handle this */ | 
| 527 |  | if (!nowarn) | 
| 528 |  | fprintf(stderr, | 
| 529 |  | "%s: resetting %s=0 for animation\n", | 
| 533 |  | } | 
| 534 |  | /* figure # frames per batch */ | 
| 535 |  | d1 = mult*xres*mult*yres*4;             /* space for orig. picture */ | 
| 536 | < | if ((i=vint(INTERP)) || atoi(vval(MBLUR))) | 
| 536 | > | if ((i=vint(INTERP)) || getblur(NULL) > 1) | 
| 537 |  | d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */ | 
| 538 |  | d2 = xres*yres*4;                       /* space for final picture */ | 
| 539 |  | frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); | 
| 543 |  | quit(1); | 
| 544 |  | } | 
| 545 |  | /* initialize archive argument list */ | 
| 546 | < | i = 16; | 
| 525 | < | if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) | 
| 526 | < | i = strlen(vval(ARCHIVE)); | 
| 546 | > | i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; | 
| 547 |  | arcnext = arcfirst = arcargs + i; | 
| 548 |  | /* initialize status file */ | 
| 549 |  | if (astat.rnext == 0) | 
| 629 |  | if (astat.tnext < astat.fnext)  /* other work to do first */ | 
| 630 |  | return; | 
| 631 |  | /* filter each view */ | 
| 632 | < | for (i = astat.fnext; i < astat.rnext; i++) { | 
| 633 | < | if ((vp = getview(i)) == NULL) {        /* get view i */ | 
| 634 | < | fprintf(stderr, | 
| 615 | < | "%s: unexpected error reading view for frame %d\n", | 
| 616 | < | progname, i); | 
| 617 | < | quit(1); | 
| 618 | < | } | 
| 619 | < | dofilt(i, vp, getexp(i), 0);            /* filter frame */ | 
| 620 | < | } | 
| 632 | > | for (i = astat.fnext; i < astat.rnext; i++) | 
| 633 | > | dofilt(i, 0); | 
| 634 | > |  | 
| 635 |  | bwait(0);                       /* wait for filter processes */ | 
| 636 |  | archive();                      /* archive originals */ | 
| 637 |  | astat.fnext = i;                /* update status */ | 
| 641 |  |  | 
| 642 |  | transferframes()                        /* catch up with picture transfers */ | 
| 643 |  | { | 
| 644 | < | char    combuf[10240]; | 
| 644 | > | char    combuf[10240], *fbase; | 
| 645 |  | register char   *cp; | 
| 646 |  | register int    i; | 
| 647 |  |  | 
| 652 |  | putastat();             /* update status */ | 
| 653 |  | return; | 
| 654 |  | } | 
| 655 | < | strcpy(combuf, vval(TRANSFER)); /* start transfer command */ | 
| 656 | < | cp = combuf + strlen(combuf); | 
| 655 | > | strcpy(combuf, "cd ");          /* start transfer command */ | 
| 656 | > | fbase = dirfile(cp = combuf+3, vval(BASENAME)); | 
| 657 | > | if (*cp) { | 
| 658 | > | while (*++cp) ; | 
| 659 | > | *cp++ = ';'; *cp++ = ' '; | 
| 660 | > | } else | 
| 661 | > | cp = combuf; | 
| 662 | > | strcpy(cp, vval(TRANSFER)); | 
| 663 | > | while (*cp) cp++; | 
| 664 |  | /* make argument list */ | 
| 665 |  | for (i = astat.tnext; i < astat.fnext; i++) { | 
| 666 |  | *cp++ = ' '; | 
| 667 | < | sprintf(cp, vval(BASENAME), i); | 
| 667 | > | sprintf(cp, fbase, i); | 
| 668 |  | while (*cp) cp++; | 
| 669 |  | strcpy(cp, ".pic"); | 
| 670 |  | cp += 4; | 
| 701 |  | int     first, last; | 
| 702 |  | char    *vfn; | 
| 703 |  | { | 
| 704 | + | double  blurf; | 
| 705 | + | int     nblur = getblur(&blurf); | 
| 706 |  | char    combuf[2048]; | 
| 707 | < | char    *inspoint; | 
| 707 | > | register char   *inspoint; | 
| 708 |  | register int    i; | 
| 709 |  |  | 
| 710 |  | if (!noaction && vint(INTERP))          /* create dummy frames */ | 
| 715 |  | close(open(combuf, O_RDONLY|O_CREAT, 0666)); | 
| 716 |  | } | 
| 717 |  | /* create command */ | 
| 718 | < | sprintf(combuf, "rpict%s -w0", rendopt); | 
| 719 | < | if (vint(INTERP) || atoi(vval(MBLUR))) | 
| 720 | < | sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); | 
| 721 | < | sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", | 
| 718 | > | sprintf(combuf, "rpict%s%s -w0", rendopt, | 
| 719 | > | viewopt(getview(first>1 ? first-1 : 1))); | 
| 720 | > | inspoint = combuf; | 
| 721 | > | while (*inspoint) inspoint++; | 
| 722 | > | if (nblur) { | 
| 723 | > | sprintf(inspoint, " -pm %.3f", blurf/nblur); | 
| 724 | > | while (*inspoint) inspoint++; | 
| 725 | > | } | 
| 726 | > | if (nblur > 1 || vint(INTERP)) { | 
| 727 | > | sprintf(inspoint, " -z %s.zbf", vval(BASENAME)); | 
| 728 | > | while (*inspoint) inspoint++; | 
| 729 | > | } | 
| 730 | > | sprintf(inspoint, " -o %s.unf %s -S %d", | 
| 731 |  | vval(BASENAME), rresopt, first); | 
| 732 | < | inspoint = combuf + strlen(combuf); | 
| 732 | > | while (*inspoint) inspoint++; | 
| 733 |  | sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); | 
| 734 |  | /* run in parallel */ | 
| 735 |  | i = (last-first+1)/(vint(INTERP)+1); | 
| 755 |  | { | 
| 756 |  | static int      *rfrm;          /* list of recovered frames */ | 
| 757 |  | static int      nrfrms = 0; | 
| 758 | + | double  blurf; | 
| 759 | + | int     nblur = getblur(&blurf); | 
| 760 |  | char    combuf[2048]; | 
| 761 |  | char    fname[128]; | 
| 762 |  | register char   *cp; | 
| 772 |  | vval(ANIMATE), frame, rendopt); | 
| 773 |  | else | 
| 774 |  | sprintf(combuf, "rpict%s -w0", rendopt); | 
| 775 | < | cp = combuf + strlen(combuf); | 
| 776 | < | if (vint(INTERP) || atoi(vval(MBLUR))) { | 
| 775 | > | cp = combuf; | 
| 776 | > | while (*cp) cp++; | 
| 777 | > | if (nblur) { | 
| 778 | > | sprintf(cp, " -pm %.3f", blurf/nblur); | 
| 779 | > | while (*cp) cp++; | 
| 780 | > | } | 
| 781 | > | if (nblur > 1 || vint(INTERP)) { | 
| 782 |  | sprintf(cp, " -z %s.zbf", fname); | 
| 783 |  | while (*cp) cp++; | 
| 784 |  | } | 
| 792 |  | return(1); | 
| 793 |  | /* add frame to recovered list */ | 
| 794 |  | if (nrfrms) | 
| 795 | < | rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); | 
| 795 | > | rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int)); | 
| 796 |  | else | 
| 797 |  | rfrm = (int *)malloc(sizeof(int)); | 
| 798 |  | if (rfrm == NULL) { | 
| 808 |  | frecover(frame)                         /* recover filtered frame */ | 
| 809 |  | int     frame; | 
| 810 |  | { | 
| 811 | < | VIEW    *vp; | 
| 773 | < | char    *ex; | 
| 774 | < |  | 
| 775 | < | vp = getview(frame); | 
| 776 | < | ex = getexp(frame); | 
| 777 | < | if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) | 
| 811 | > | if (dofilt(frame, 2) && dofilt(frame, 1)) | 
| 812 |  | return(1); | 
| 813 |  | return(0); | 
| 814 |  | } | 
| 818 |  | { | 
| 819 |  | #define RMCOML  (sizeof(rmcom)-1) | 
| 820 |  | static char     rmcom[] = "rm -f"; | 
| 821 | < | register int    i; | 
| 821 | > | char    basedir[128]; | 
| 822 | > | int     dlen, alen; | 
| 823 | > | register int    j; | 
| 824 |  |  | 
| 825 |  | if (arcnext == arcfirst) | 
| 826 |  | return;                         /* nothing to do */ | 
| 827 | + | dirfile(basedir, vval(BASENAME)); | 
| 828 | + | dlen = strlen(basedir); | 
| 829 |  | if (vdef(ARCHIVE)) {                    /* run archive command */ | 
| 830 | < | i = strlen(vval(ARCHIVE)); | 
| 831 | < | strncpy(arcfirst-i, vval(ARCHIVE), i); | 
| 832 | < | if (runcom(arcfirst-i)) { | 
| 830 | > | alen = strlen(vval(ARCHIVE)); | 
| 831 | > | if (dlen) { | 
| 832 | > | j = alen + dlen + 5; | 
| 833 | > | strncpy(arcfirst-j, "cd ", 3); | 
| 834 | > | strncpy(arcfirst-j+3, basedir, dlen); | 
| 835 | > | (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; | 
| 836 | > | } else | 
| 837 | > | j = alen; | 
| 838 | > | strncpy(arcfirst-alen, vval(ARCHIVE), alen); | 
| 839 | > | if (runcom(arcfirst-j)) { | 
| 840 |  | fprintf(stderr, "%s: error running archive command\n", | 
| 841 |  | progname); | 
| 842 |  | quit(1); | 
| 843 |  | } | 
| 844 |  | } | 
| 845 | + | if (dlen) { | 
| 846 | + | j = RMCOML + dlen + 5; | 
| 847 | + | strncpy(arcfirst-j, "cd ", 3); | 
| 848 | + | strncpy(arcfirst-j+3, basedir, dlen); | 
| 849 | + | (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; | 
| 850 | + | } else | 
| 851 | + | j = RMCOML; | 
| 852 |  | /* run remove command */ | 
| 853 |  | strncpy(arcfirst-RMCOML, rmcom, RMCOML); | 
| 854 | < | runcom(arcfirst-RMCOML); | 
| 854 | > | runcom(arcfirst-j); | 
| 855 |  | arcnext = arcfirst;                     /* reset argument list */ | 
| 856 |  | #undef RMCOML | 
| 857 |  | } | 
| 858 |  |  | 
| 859 |  |  | 
| 860 |  | int | 
| 861 | < | dofilt(frame, vp, ep, rvr)                      /* filter frame */ | 
| 861 | > | dofilt(frame, rvr)                              /* filter frame */ | 
| 862 |  | int     frame; | 
| 811 | – | VIEW    *vp; | 
| 812 | – | char    *ep; | 
| 863 |  | int     rvr; | 
| 864 |  | { | 
| 865 |  | extern int      frecover(); | 
| 866 |  | static int      iter = 0; | 
| 867 | < | char    fnbefore[128], fnafter[128]; | 
| 867 | > | double  blurf; | 
| 868 | > | int     nblur = getblur(&blurf); | 
| 869 | > | VIEW    *vp = getview(frame); | 
| 870 | > | char    *ep = getexp(frame); | 
| 871 | > | char    fnbefore[128], fnafter[128], *fbase; | 
| 872 |  | char    combuf[1024], fname0[128], fname1[128]; | 
| 873 |  | int     usepinterp, usepfilt, nora_rgbe; | 
| 874 |  | int     frseq[2]; | 
| 875 |  | /* check what is needed */ | 
| 876 | < | usepinterp = atoi(vval(MBLUR)); | 
| 876 | > | if (vp == NULL) { | 
| 877 | > | fprintf(stderr, | 
| 878 | > | "%s: unexpected error reading view for frame %d\n", | 
| 879 | > | progname, frame); | 
| 880 | > | quit(1); | 
| 881 | > | } | 
| 882 | > | if (ep == NULL) { | 
| 883 | > | fprintf(stderr, | 
| 884 | > | "%s: unexpected error reading exposure for frame %d\n", | 
| 885 | > | progname, frame); | 
| 886 | > | quit(1); | 
| 887 | > | } | 
| 888 | > | usepinterp = (nblur > 1); | 
| 889 |  | usepfilt = pfiltalways | ep==NULL; | 
| 890 |  | if (ep != NULL && !strcmp(ep, "1")) | 
| 891 |  | ep = "+0"; | 
| 894 |  | /* compute rendered views */ | 
| 895 |  | frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); | 
| 896 |  | frseq[1] = frseq[0] + vint(INTERP) + 1; | 
| 897 | + | fbase = dirfile(NULL, vval(BASENAME)); | 
| 898 |  | if (frseq[1] > vint(END)) | 
| 899 |  | frseq[1] = vint(END); | 
| 900 |  | if (frseq[1] == frame) {                        /* pfilt only */ | 
| 904 |  | } else if (frseq[0] == frame) {         /* no interpolation needed */ | 
| 905 |  | if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */ | 
| 906 |  | *arcnext++ = ' '; | 
| 907 | < | sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); | 
| 907 | > | sprintf(arcnext, fbase, frame-vint(INTERP)-1); | 
| 908 |  | while (*arcnext) arcnext++; | 
| 909 |  | strcpy(arcnext, ".unf"); | 
| 910 |  | arcnext += 4; | 
| 911 |  | if (usepinterp || vint(INTERP)) {       /* and Z-buf */ | 
| 912 |  | *arcnext++ = ' '; | 
| 913 | < | sprintf(arcnext, vval(BASENAME), | 
| 847 | < | frame-vint(INTERP)-1); | 
| 913 | > | sprintf(arcnext, fbase, frame-vint(INTERP)-1); | 
| 914 |  | while (*arcnext) arcnext++; | 
| 915 |  | strcpy(arcnext, ".zbf"); | 
| 916 |  | arcnext += 4; | 
| 930 |  | if (usepinterp) {                       /* using pinterp */ | 
| 931 |  | if (rvr == 2 && recover(frseq[1]))      /* recover after? */ | 
| 932 |  | return(1); | 
| 933 | < | if (atoi(vval(MBLUR))) { | 
| 868 | < | FILE    *fp;            /* motion blurring */ | 
| 933 | > | if (nblur > 1) {                /* with pmblur */ | 
| 934 |  | sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), | 
| 935 |  | 'a'+(iter%26)); | 
| 871 | – | if ((fp = fopen(fname0, "w")) == NULL) { | 
| 872 | – | perror(fname0); quit(1); | 
| 873 | – | } | 
| 874 | – | fputs(VIEWSTR, fp); | 
| 875 | – | fprintview(vp, fp); | 
| 876 | – | putc('\n', fp); fclose(fp); | 
| 877 | – | if ((vp = getview(frame+1)) == NULL) { | 
| 878 | – | fprintf(stderr, | 
| 879 | – | "%s: unexpected error reading view for frame %d\n", | 
| 880 | – | progname, frame+1); | 
| 881 | – | quit(1); | 
| 882 | – | } | 
| 936 |  | sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), | 
| 937 |  | 'a'+(iter%26)); | 
| 938 | < | if ((fp = fopen(fname1, "w")) == NULL) { | 
| 939 | < | perror(fname1); quit(1); | 
| 938 | > | if (!noaction) { | 
| 939 | > | FILE    *fp;            /* motion blurring */ | 
| 940 | > | if ((fp = fopen(fname0, "w")) == NULL) { | 
| 941 | > | perror(fname0); quit(1); | 
| 942 | > | } | 
| 943 | > | fputs(VIEWSTR, fp); | 
| 944 | > | fprintview(vp, fp); | 
| 945 | > | putc('\n', fp); fclose(fp); | 
| 946 | > | if ((vp = getview(frame+1)) == NULL) { | 
| 947 | > | fprintf(stderr, | 
| 948 | > | "%s: unexpected error reading view for frame %d\n", | 
| 949 | > | progname, frame+1); | 
| 950 | > | quit(1); | 
| 951 | > | } | 
| 952 | > | if ((fp = fopen(fname1, "w")) == NULL) { | 
| 953 | > | perror(fname1); quit(1); | 
| 954 | > | } | 
| 955 | > | fputs(VIEWSTR, fp); | 
| 956 | > | fprintview(vp, fp); | 
| 957 | > | putc('\n', fp); fclose(fp); | 
| 958 |  | } | 
| 888 | – | fputs(VIEWSTR, fp); | 
| 889 | – | fprintview(vp, fp); | 
| 890 | – | putc('\n', fp); fclose(fp); | 
| 959 |  | sprintf(combuf, | 
| 960 | < | "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", | 
| 961 | < | *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", | 
| 894 | < | atoi(vval(MBLUR)), | 
| 960 | > | "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", | 
| 961 | > | blurf, nblur, | 
| 962 |  | fname0, fname1, fname0, fname1); | 
| 963 |  | iter++; | 
| 964 |  | } else                          /* no blurring */ | 
| 966 |  | strcat(combuf, viewopt(vp)); | 
| 967 |  | if (vbool(RTRACE)) | 
| 968 |  | sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'", | 
| 969 | < | rendopt, vval(OCTREE)); | 
| 969 | > | rendopt+1, vval(OCTREE)); | 
| 970 |  | if (vdef(PINTERP)) | 
| 971 |  | sprintf(combuf+strlen(combuf), " %s", vval(PINTERP)); | 
| 972 |  | if (usepfilt) | 
| 973 |  | sprintf(combuf+strlen(combuf), " %s", rresopt); | 
| 974 |  | else | 
| 975 | < | sprintf(combuf+strlen(combuf), " %s -e %s", | 
| 975 | > | sprintf(combuf+strlen(combuf), " -a %s -e %s", | 
| 976 |  | fresopt, ep); | 
| 977 |  | sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", | 
| 978 |  | fnbefore, fnbefore); | 
| 1037 |  | } | 
| 1038 |  | return(NULL); | 
| 1039 |  | } | 
| 1040 | < | if (viewfp == NULL) {           /* open file */ | 
| 1040 | > | if (viewfp == NULL) {                   /* open file */ | 
| 1041 |  | if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { | 
| 1042 |  | perror(vval(VIEWFILE)); | 
| 1043 |  | quit(1); | 
| 1044 |  | } | 
| 1045 | < | } else if (n < viewnum) {       /* rewind file */ | 
| 1045 | > | } else if (n > 0 && n < viewnum) {      /* rewind file */ | 
| 1046 |  | if (viewnum == 1 && feof(viewfp)) | 
| 1047 |  | return(&curview);               /* just one view */ | 
| 1048 |  | if (fseek(viewfp, 0L, 0) == EOF) { | 
| 1052 |  | copystruct(&curview, &stdview); | 
| 1053 |  | viewnum = 0; | 
| 1054 |  | } | 
| 1055 | + | if (n < 0) {                            /* get next view */ | 
| 1056 | + | register int    c = getc(viewfp); | 
| 1057 | + | if (c == EOF) | 
| 1058 | + | return((VIEW *)NULL);           /* that's it */ | 
| 1059 | + | ungetc(c, viewfp); | 
| 1060 | + | n = viewnum + 1; | 
| 1061 | + | } | 
| 1062 |  | while (n > viewnum) {           /* scan to desired view */ | 
| 1063 |  | if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) | 
| 1064 |  | return(viewnum==1 ? &curview : (VIEW *)NULL); | 
| 1072 |  | int | 
| 1073 |  | countviews()                    /* count views in view file */ | 
| 1074 |  | { | 
| 1075 | < | register int    n = 0; | 
| 1075 | > | int     n; | 
| 1076 |  |  | 
| 1077 | < | while (getview(n+1) != NULL) | 
| 1077 | > | if (getview(n=1) == NULL) | 
| 1078 | > | return(0); | 
| 1079 | > | while (getview(-1) != NULL) | 
| 1080 |  | n++; | 
| 1081 |  | return(n); | 
| 1082 |  | } | 
| 1096 |  | if (n == 0) {                           /* signal to close file */ | 
| 1097 |  | if (expfp != NULL) { | 
| 1098 |  | fclose(expfp); | 
| 1099 | < | free((char *)exppos); | 
| 1099 | > | free((void *)exppos); | 
| 1100 |  | expfp = NULL; | 
| 1101 |  | } | 
| 1102 |  | return(NULL); | 
| 1177 |  | int     status; | 
| 1178 |  | { | 
| 1179 |  | register PROC   *pp; | 
| 1180 | + | register struct pslot   *psl; | 
| 1181 |  |  | 
| 1182 |  | pp = ps->proc + pn; | 
| 1183 |  | if (pp->elen) {                 /* pass errors */ | 
| 1189 |  | if (ps->hostname[0]) | 
| 1190 |  | status = 1;     /* because rsh doesn't return status */ | 
| 1191 |  | } | 
| 1192 | + | lastpserver = NULL; | 
| 1193 | + | psl = findpslot(pp->pid);       /* check for bruncom() slot */ | 
| 1194 | + | if (psl->pid) { | 
| 1195 | + | if (status) { | 
| 1196 | + | if (psl->rcvf != NULL)  /* attempt recovery */ | 
| 1197 | + | status = (*psl->rcvf)(psl->fout); | 
| 1198 | + | if (status) { | 
| 1199 | + | fprintf(stderr, | 
| 1200 | + | "%s: error rendering frame %d\n", | 
| 1201 | + | progname, psl->fout); | 
| 1202 | + | quit(1); | 
| 1203 | + | } | 
| 1204 | + | lastpserver = ps; | 
| 1205 | + | } | 
| 1206 | + | psl->pid = 0;                   /* free process slot */ | 
| 1207 | + | } else if (status) | 
| 1208 | + | lastpserver = ps; | 
| 1209 |  | freestr(pp->com);               /* free command string */ | 
| 1116 | – | lastpid = pp->pid;              /* record PID for bwait() */ | 
| 1117 | – | lastpserver = ps;               /* record server for serverdown() */ | 
| 1210 |  | return(status); | 
| 1211 |  | } | 
| 1212 |  |  | 
| 1214 |  | int | 
| 1215 |  | serverdown()                    /* check status of last process server */ | 
| 1216 |  | { | 
| 1217 | + | if (lastpserver == NULL || !lastpserver->hostname[0]) | 
| 1218 | + | return(0); | 
| 1219 |  | if (pserverOK(lastpserver))     /* server still up? */ | 
| 1220 |  | return(0); | 
| 1221 |  | delpserver(lastpserver);        /* else delete it */ | 
| 1242 |  | printf("\t%s\n", com);  /* echo command */ | 
| 1243 |  | return(0); | 
| 1244 |  | } | 
| 1245 | < | /* else start it when we can */ | 
| 1246 | < | while ((pid = startjob(NULL, savestr(com), donecom)) == -1) | 
| 1245 | > | com = savestr(com);             /* else start it when we can */ | 
| 1246 | > | while ((pid = startjob(NULL, com, donecom)) == -1) | 
| 1247 |  | bwait(1); | 
| 1248 |  | if (!silent) {                          /* echo command */ | 
| 1249 |  | PSERVER *ps; | 
| 1265 |  | int     ncoms; | 
| 1266 |  | { | 
| 1267 |  | int     status; | 
| 1174 | – | register struct pslot   *psl; | 
| 1268 |  |  | 
| 1269 |  | if (noaction) | 
| 1270 |  | return; | 
| 1271 |  | while ((status = wait4job(NULL, -1)) != -1) { | 
| 1272 | < | psl = findpslot(lastpid); | 
| 1273 | < | if (status) {           /* attempt recovery */ | 
| 1274 | < | serverdown();   /* check server */ | 
| 1182 | < | if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) { | 
| 1183 | < | fprintf(stderr, | 
| 1184 | < | "%s: error rendering frame %d\n", | 
| 1185 | < | progname, psl->fout); | 
| 1186 | < | quit(1); | 
| 1187 | < | } | 
| 1188 | < | } | 
| 1189 | < | psl->pid = 0;           /* free process slot */ | 
| 1190 | < | if (!--ncoms) | 
| 1191 | < | return;         /* done enough */ | 
| 1272 | > | serverdown();           /* update server status */ | 
| 1273 | > | if (--ncoms == 0) | 
| 1274 | > | break;          /* done enough */ | 
| 1275 |  | } | 
| 1276 |  | } | 
| 1277 |  |  | 
| 1283 |  | { | 
| 1284 |  | int     retstatus = 0; | 
| 1285 |  | int     hostcopies; | 
| 1286 | < | char    buf[10240], *com1; | 
| 1204 | < | PSERVER *mps[64]; | 
| 1205 | < | int     nmps = 0; | 
| 1286 | > | char    buf[10240], *com1, *s; | 
| 1287 |  | int     status; | 
| 1288 |  | int     pfd; | 
| 1289 |  | register int    n; | 
| 1301 |  | strcpy(com1=buf, com);  /* build -PP command */ | 
| 1302 |  | sprintf(com1+(ppins-com), " -PP %s/%s.persist", | 
| 1303 |  | vval(DIRECTORY), phostname(ps)); | 
| 1304 | + | unlink(com1+(ppins-com)+5); | 
| 1305 |  | strcat(com1, ppins); | 
| 1224 | – | mps[nmps++] = ps; | 
| 1306 |  | } else | 
| 1307 |  | com1 = com; | 
| 1308 | < | while (maxcopies > 0 && | 
| 1309 | < | startjob(ps, savestr(com1), donecom) != -1) { | 
| 1310 | < | sleep(60); | 
| 1311 | < | hostcopies++; | 
| 1312 | < | maxcopies--; | 
| 1308 | > | while (maxcopies > 0) { | 
| 1309 | > | s = savestr(com1); | 
| 1310 | > | if (startjob(ps, s, donecom) != -1) { | 
| 1311 | > | sleep(20); | 
| 1312 | > | hostcopies++; | 
| 1313 | > | maxcopies--; | 
| 1314 | > | } else { | 
| 1315 | > | freestr(s); | 
| 1316 | > | break; | 
| 1317 | > | } | 
| 1318 |  | } | 
| 1319 |  | if (!silent && hostcopies) { | 
| 1320 |  | if (hostcopies > 1) | 
| 1327 |  | } | 
| 1328 |  | /* wait for jobs to finish */ | 
| 1329 |  | while ((status = wait4job(NULL, -1)) != -1) | 
| 1330 | < | if (status) | 
| 1245 | < | retstatus += !serverdown();     /* check server */ | 
| 1330 | > | retstatus += status && !serverdown(); | 
| 1331 |  | /* terminate parallel rpict's */ | 
| 1332 | < | while (nmps--) { | 
| 1333 | < | sprintf(buf, "%s/%s.persist", | 
| 1249 | < | vval(DIRECTORY), phostname(mps[nmps])); | 
| 1332 | > | for (ps = pslist; ps != NULL; ps = ps->next) { | 
| 1333 | > | sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps)); | 
| 1334 |  | if ((pfd = open(buf, O_RDONLY)) >= 0) { | 
| 1335 |  | n = read(pfd, buf, sizeof(buf)-1);      /* get PID */ | 
| 1336 |  | buf[n] = '\0'; | 
| 1339 |  | ; | 
| 1340 |  | /* terminate */ | 
| 1341 |  | sprintf(buf, "kill -ALRM %d", atoi(buf+n)); | 
| 1342 | < | wait4job(mps[nmps], startjob(mps[nmps], buf, NULL)); | 
| 1342 | > | wait4job(ps, startjob(ps, buf, NULL)); | 
| 1343 |  | } | 
| 1344 |  | } | 
| 1345 |  | return(retstatus); | 
| 1362 |  | char    *fn; | 
| 1363 |  | { | 
| 1364 |  | if (!silent) | 
| 1365 | < | #ifdef MSDOS | 
| 1365 | > | #ifdef _WIN32 | 
| 1366 |  | printf("\tdel %s\n", fn); | 
| 1367 |  | #else | 
| 1368 |  | printf("\trm -f %s\n", fn); | 
| 1379 |  | fprintf(stderr, "%s: bad value for variable '%s'\n", | 
| 1380 |  | progname, vnam(vc)); | 
| 1381 |  | quit(1); | 
| 1382 | + | } | 
| 1383 | + |  | 
| 1384 | + |  | 
| 1385 | + | char * | 
| 1386 | + | dirfile(df, path)               /* separate path into directory and file */ | 
| 1387 | + | char    *df; | 
| 1388 | + | register char   *path; | 
| 1389 | + | { | 
| 1390 | + | register int    i; | 
| 1391 | + | int     psep; | 
| 1392 | + |  | 
| 1393 | + | for (i = 0, psep = -1; path[i]; i++) | 
| 1394 | + | if (path[i] == '/') | 
| 1395 | + | psep = i; | 
| 1396 | + | if (df != NULL) | 
| 1397 | + | if (psep == 0) { | 
| 1398 | + | df[0] = '/'; | 
| 1399 | + | df[1] = '\0'; | 
| 1400 | + | } else if (psep > 0) { | 
| 1401 | + | strncpy(df, path, psep); | 
| 1402 | + | df[psep] = '\0'; | 
| 1403 | + | } else | 
| 1404 | + | df[0] = '\0'; | 
| 1405 | + | return(path+psep+1); | 
| 1406 | + | } | 
| 1407 | + |  | 
| 1408 | + |  | 
| 1409 | + | int | 
| 1410 | + | getblur(double *bf)             /* get # blur samples (and fraction) */ | 
| 1411 | + | { | 
| 1412 | + | double  blurf; | 
| 1413 | + | int     nblur; | 
| 1414 | + | char    *s; | 
| 1415 | + |  | 
| 1416 | + | if (!vdef(MBLUR)) { | 
| 1417 | + | if (bf != NULL) | 
| 1418 | + | *bf = 0.0; | 
| 1419 | + | return(0); | 
| 1420 | + | } | 
| 1421 | + | blurf = atof(vval(MBLUR)); | 
| 1422 | + | if (blurf < 0.0) | 
| 1423 | + | blurf = 0.0; | 
| 1424 | + | if (bf != NULL) | 
| 1425 | + | *bf = blurf; | 
| 1426 | + | if (blurf <= FTINY) | 
| 1427 | + | return(0); | 
| 1428 | + | s = sskip(vval(MBLUR)); | 
| 1429 | + | if (!*s) | 
| 1430 | + | return(DEF_NBLUR); | 
| 1431 | + | nblur = atoi(s); | 
| 1432 | + | if (nblur <= 0) | 
| 1433 | + | return(1); | 
| 1434 | + | return(nblur); | 
| 1435 |  | } |