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 "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 |
+ |
#include <signal.h> |
23 |
+ |
|
24 |
+ |
#include "platform.h" |
25 |
+ |
#include "paths.h" |
26 |
+ |
#include "standard.h" |
27 |
|
#include "view.h" |
28 |
|
#include "vars.h" |
29 |
|
#include "netproc.h" |
30 |
+ |
/* default blur samples */ |
31 |
+ |
#ifndef DEF_NBLUR |
32 |
+ |
#define DEF_NBLUR 5 |
33 |
+ |
#endif |
34 |
|
/* default remote shell */ |
19 |
– |
#ifdef _AUX_SOURCE |
20 |
– |
#define REMSH "remsh" |
21 |
– |
#else |
35 |
|
#define REMSH "rsh" |
36 |
< |
#endif |
37 |
< |
/* input variables */ |
38 |
< |
#define HOST 0 /* rendering host machine */ |
39 |
< |
#define RENDER 1 /* rendering options */ |
40 |
< |
#define PFILT 2 /* pfilt options */ |
41 |
< |
#define PINTERP 3 /* pinterp options */ |
42 |
< |
#define OCTREE 4 /* octree file name */ |
43 |
< |
#define DIRECTORY 5 /* working (sub)directory */ |
44 |
< |
#define BASENAME 6 /* output image base name */ |
45 |
< |
#define VIEWFILE 7 /* animation frame views */ |
46 |
< |
#define START 8 /* starting frame number */ |
47 |
< |
#define END 9 /* ending frame number */ |
48 |
< |
#define RIF 10 /* rad input file */ |
49 |
< |
#define NEXTANIM 11 /* next animation file */ |
50 |
< |
#define ANIMATE 12 /* animation command */ |
51 |
< |
#define TRANSFER 13 /* frame transfer command */ |
52 |
< |
#define ARCHIVE 14 /* archiving command */ |
53 |
< |
#define INTERP 15 /* # frames to interpolate */ |
54 |
< |
#define OVERSAMP 16 /* # times to oversample image */ |
55 |
< |
#define MBLUR 17 /* samples for motion blur */ |
56 |
< |
#define RTRACE 18 /* use rtrace with pinterp? */ |
57 |
< |
#define DISKSPACE 19 /* how much disk space to use */ |
58 |
< |
#define RESOLUTION 20 /* desired final resolution */ |
59 |
< |
#define EXPOSURE 21 /* how to compute exposure */ |
47 |
< |
#define RSH 22 /* remote shell script or program */ |
36 |
> |
/* input variables (alphabetical by name) */ |
37 |
> |
#define ANIMATE 0 /* animation command */ |
38 |
> |
#define ARCHIVE 1 /* archiving command */ |
39 |
> |
#define BASENAME 2 /* output image base name */ |
40 |
> |
#define DIRECTORY 3 /* working (sub)directory */ |
41 |
> |
#define DISKSPACE 4 /* how much disk space to use */ |
42 |
> |
#define END 5 /* ending frame number */ |
43 |
> |
#define EXPOSURE 6 /* how to compute exposure */ |
44 |
> |
#define HOST 7 /* rendering host machine */ |
45 |
> |
#define INTERP 8 /* # frames to interpolate */ |
46 |
> |
#define MBLUR 9 /* motion blur parameters */ |
47 |
> |
#define NEXTANIM 10 /* next animation file */ |
48 |
> |
#define OCTREE 11 /* octree file name */ |
49 |
> |
#define OVERSAMP 12 /* # times to oversample image */ |
50 |
> |
#define PFILT 13 /* pfilt options */ |
51 |
> |
#define PINTERP 14 /* pinterp options */ |
52 |
> |
#define RENDER 15 /* rendering options */ |
53 |
> |
#define RESOLUTION 16 /* desired final resolution */ |
54 |
> |
#define RIF 17 /* rad input file */ |
55 |
> |
#define RSH 18 /* remote shell script or program */ |
56 |
> |
#define RTRACE 19 /* use rtrace with pinterp? */ |
57 |
> |
#define START 20 /* starting frame number */ |
58 |
> |
#define TRANSFER 21 /* frame transfer command */ |
59 |
> |
#define VIEWFILE 22 /* animation frame views */ |
60 |
|
|
61 |
|
int NVARS = 23; /* total number of variables */ |
62 |
|
|
63 |
|
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}, |
64 |
|
{"ANIMATE", 2, 0, NULL, onevalue}, |
65 |
– |
{"TRANSFER", 2, 0, NULL, onevalue}, |
65 |
|
{"ARCHIVE", 2, 0, NULL, onevalue}, |
66 |
+ |
{"BASENAME", 3, 0, NULL, onevalue}, |
67 |
+ |
{"DIRECTORY", 3, 0, NULL, onevalue}, |
68 |
+ |
{"DISKSPACE", 3, 0, NULL, fltvalue}, |
69 |
+ |
{"END", 2, 0, NULL, intvalue}, |
70 |
+ |
{"EXPOSURE", 3, 0, NULL, onevalue}, |
71 |
+ |
{"host", 4, 0, NULL, NULL}, |
72 |
|
{"INTERPOLATE", 3, 0, NULL, intvalue}, |
68 |
– |
{"OVERSAMPLE", 2, 0, NULL, fltvalue}, |
73 |
|
{"MBLUR", 2, 0, NULL, onevalue}, |
74 |
< |
{"RTRACE", 2, 0, NULL, boolvalue}, |
75 |
< |
{"DISKSPACE", 3, 0, NULL, fltvalue}, |
74 |
> |
{"NEXTANIM", 3, 0, NULL, onevalue}, |
75 |
> |
{"OCTREE", 3, 0, NULL, onevalue}, |
76 |
> |
{"OVERSAMPLE", 2, 0, NULL, fltvalue}, |
77 |
> |
{"pfilt", 2, 0, NULL, catvalues}, |
78 |
> |
{"pinterp", 2, 0, NULL, catvalues}, |
79 |
> |
{"render", 3, 0, NULL, catvalues}, |
80 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
81 |
< |
{"EXPOSURE", 3, 0, NULL, onevalue}, |
81 |
> |
{"RIF", 3, 0, NULL, onevalue}, |
82 |
|
{"RSH", 3, 0, NULL, onevalue}, |
83 |
+ |
{"RTRACE", 2, 0, NULL, boolvalue}, |
84 |
+ |
{"START", 2, 0, NULL, intvalue}, |
85 |
+ |
{"TRANSFER", 2, 0, NULL, onevalue}, |
86 |
+ |
{"VIEWFILE", 2, 0, NULL, onevalue}, |
87 |
|
}; |
88 |
|
|
89 |
|
#define SFNAME "STATUS" /* status file name */ |
121 |
|
int npslots; /* number of process slots */ |
122 |
|
|
123 |
|
#define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host) |
112 |
– |
|
113 |
– |
struct pslot *findpslot(); |
114 |
– |
|
124 |
|
PSERVER *lastpserver; /* last process server with error */ |
125 |
|
|
126 |
< |
VIEW *getview(); |
127 |
< |
char *getexp(); |
126 |
> |
static struct pslot * findpslot(int pid); |
127 |
> |
static void checkdir(void); |
128 |
> |
static VIEW * getview(int n); |
129 |
|
|
130 |
< |
extern time_t fdate(), time(); |
130 |
> |
static char * dirfile(char *df, register char *path); |
131 |
> |
static char * getexp(int n); |
132 |
> |
static int getblur(double *bf); |
133 |
> |
static int getastat(void); |
134 |
> |
static void getradfile(char *rfargs); |
135 |
> |
static void badvalue(int vc); |
136 |
> |
static int rmfile(char *fn); |
137 |
> |
static int runcom(char *cs); |
138 |
> |
static int pruncom(char *com, char *ppins, int maxcopies); |
139 |
> |
static void bwait(int ncoms); |
140 |
> |
static int bruncom(char *com, int fout, int (*rf)()); |
141 |
> |
static int serverdown(void); |
142 |
> |
static pscompfunc donecom; |
143 |
> |
static int countviews(void); |
144 |
> |
static int dofilt(int frame, int rvr); |
145 |
> |
static void archive(void); |
146 |
> |
static int frecover(int frame); |
147 |
> |
static int recover(int frame); |
148 |
> |
static void sethosts(void); |
149 |
> |
static void walkwait(int first, int last, char *vfn); |
150 |
> |
static void animrend(int frame, VIEW *vp); |
151 |
> |
static void transferframes(void); |
152 |
> |
static void filterframes(void); |
153 |
> |
static void renderframes(int nframes); |
154 |
> |
static void animate(void); |
155 |
> |
static void setdefaults(void); |
156 |
> |
static void putastat(void); |
157 |
|
|
158 |
|
|
159 |
< |
main(argc, argv) |
160 |
< |
int argc; |
161 |
< |
char *argv[]; |
159 |
> |
int |
160 |
> |
main( |
161 |
> |
int argc, |
162 |
> |
char *argv[] |
163 |
> |
) |
164 |
|
{ |
165 |
|
int explicate = 0; |
166 |
|
int i; |
223 |
|
quit(1); |
224 |
|
} |
225 |
|
quit(0); |
226 |
+ |
return 0; /* pro forma return */ |
227 |
|
userr: |
228 |
|
fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname); |
229 |
|
quit(1); |
230 |
+ |
return 1; /* pro forma return */ |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
< |
getastat() /* check/set animation status */ |
234 |
> |
static int |
235 |
> |
getastat(void) /* check/set animation status */ |
236 |
|
{ |
237 |
|
char sfname[256]; |
238 |
|
FILE *fp; |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
< |
putastat() /* put out current status */ |
299 |
> |
static void |
300 |
> |
putastat(void) /* put out current status */ |
301 |
|
{ |
302 |
|
char buf[256]; |
303 |
|
FILE *fp; |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
< |
checkdir() /* make sure we have our directory */ |
322 |
> |
static void |
323 |
> |
checkdir(void) /* make sure we have our directory */ |
324 |
|
{ |
325 |
|
struct stat stb; |
326 |
|
|
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
< |
setdefaults() /* set default values */ |
345 |
> |
static void |
346 |
> |
setdefaults(void) /* set default values */ |
347 |
|
{ |
348 |
|
extern char *atos(); |
349 |
|
int decades; |
431 |
|
} |
432 |
|
|
433 |
|
|
434 |
< |
sethosts() /* set up process servers */ |
434 |
> |
static void |
435 |
> |
sethosts(void) /* set up process servers */ |
436 |
|
{ |
437 |
|
extern char *iskip(); |
438 |
|
char buf[256], *dir, *uname; |
487 |
|
} |
488 |
|
} |
489 |
|
|
490 |
< |
|
491 |
< |
getradfile(rfargs) /* run rad and get needed variables */ |
447 |
< |
char *rfargs; |
490 |
> |
static void |
491 |
> |
getradfile(char *rfargs) /* run rad and get needed variables */ |
492 |
|
{ |
493 |
|
static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1}; |
494 |
|
char combuf[256]; |
495 |
|
register int i; |
496 |
|
register char *cp; |
497 |
+ |
char *pippt = NULL; |
498 |
|
/* create rad command */ |
499 |
|
sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY)); |
500 |
|
sprintf(combuf, |
501 |
|
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
502 |
|
rfargs, rendopt+2); |
503 |
|
cp = combuf; |
504 |
< |
while (*cp) cp++; /* match unset variables */ |
504 |
> |
while (*cp) { |
505 |
> |
if (*cp == '|') pippt = cp; |
506 |
> |
cp++; |
507 |
> |
} /* match unset variables */ |
508 |
|
for (i = 0; mvar[i] >= 0; i++) |
509 |
|
if (!vdef(mvar[i])) { |
510 |
|
*cp++ = '|'; |
511 |
|
strcpy(cp, vnam(mvar[i])); |
512 |
|
while (*cp) cp++; |
513 |
+ |
pippt = NULL; |
514 |
|
} |
515 |
< |
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
516 |
< |
cp += 11; /* point to file name */ |
517 |
< |
if (system(combuf)) { |
518 |
< |
fprintf(stderr, "%s: error executing rad command:\n\t%s\n", |
519 |
< |
progname, combuf); |
471 |
< |
quit(1); |
515 |
> |
if (pippt != NULL) |
516 |
> |
strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ |
517 |
> |
else { |
518 |
> |
sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY)); |
519 |
> |
cp += 11; /* point to file name */ |
520 |
|
} |
521 |
< |
loadvars(cp); /* load variables and remove file */ |
522 |
< |
unlink(cp); |
521 |
> |
system(combuf); /* ignore exit code */ |
522 |
> |
if (pippt == NULL) { /* load variables and remove file */ |
523 |
> |
loadvars(cp); |
524 |
> |
unlink(cp); |
525 |
> |
} |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
< |
animate() /* run animation */ |
529 |
> |
static void |
530 |
> |
animate(void) /* run animation */ |
531 |
|
{ |
532 |
|
int xres, yres; |
533 |
|
float pa, mult; |
557 |
|
progname, vnam(INTERP)); |
558 |
|
vval(INTERP) = "0"; |
559 |
|
} |
560 |
< |
if (atoi(vval(MBLUR))) { /* can't handle this yet */ |
560 |
> |
if (strcmp(vval(MBLUR),"0")) { /* can't handle this */ |
561 |
|
if (!nowarn) |
562 |
|
fprintf(stderr, |
563 |
|
"%s: resetting %s=0 for animation\n", |
567 |
|
} |
568 |
|
/* figure # frames per batch */ |
569 |
|
d1 = mult*xres*mult*yres*4; /* space for orig. picture */ |
570 |
< |
if ((i=vint(INTERP)) || atoi(vval(MBLUR))) |
570 |
> |
if ((i=vint(INTERP)) || getblur(NULL) > 1) |
571 |
|
d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */ |
572 |
|
d2 = xres*yres*4; /* space for final picture */ |
573 |
|
frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2); |
577 |
|
quit(1); |
578 |
|
} |
579 |
|
/* initialize archive argument list */ |
580 |
< |
i = 16; |
529 |
< |
if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i) |
530 |
< |
i = strlen(vval(ARCHIVE)); |
580 |
> |
i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132; |
581 |
|
arcnext = arcfirst = arcargs + i; |
582 |
|
/* initialize status file */ |
583 |
|
if (astat.rnext == 0) |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
< |
renderframes(nframes) /* render next nframes frames */ |
602 |
< |
int nframes; |
601 |
> |
static void |
602 |
> |
renderframes(int nframes) /* render next nframes frames */ |
603 |
|
{ |
604 |
|
static char vendbuf[16]; |
605 |
|
VIEW *vp; |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
< |
filterframes() /* catch up with filtering */ |
658 |
> |
static void |
659 |
> |
filterframes(void) /* catch up with filtering */ |
660 |
|
{ |
610 |
– |
VIEW *vp; |
661 |
|
register int i; |
662 |
|
|
663 |
|
if (astat.tnext < astat.fnext) /* other work to do first */ |
664 |
|
return; |
665 |
|
/* filter each view */ |
666 |
< |
for (i = astat.fnext; i < astat.rnext; i++) { |
667 |
< |
if ((vp = getview(i)) == NULL) { /* get view i */ |
668 |
< |
fprintf(stderr, |
619 |
< |
"%s: unexpected error reading view for frame %d\n", |
620 |
< |
progname, i); |
621 |
< |
quit(1); |
622 |
< |
} |
623 |
< |
dofilt(i, vp, getexp(i), 0); /* filter frame */ |
624 |
< |
} |
666 |
> |
for (i = astat.fnext; i < astat.rnext; i++) |
667 |
> |
dofilt(i, 0); |
668 |
> |
|
669 |
|
bwait(0); /* wait for filter processes */ |
670 |
|
archive(); /* archive originals */ |
671 |
|
astat.fnext = i; /* update status */ |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
< |
transferframes() /* catch up with picture transfers */ |
676 |
> |
static void |
677 |
> |
transferframes(void) /* catch up with picture transfers */ |
678 |
|
{ |
679 |
< |
char combuf[10240]; |
679 |
> |
char combuf[10240], *fbase; |
680 |
|
register char *cp; |
681 |
|
register int i; |
682 |
|
|
687 |
|
putastat(); /* update status */ |
688 |
|
return; |
689 |
|
} |
690 |
< |
strcpy(combuf, vval(TRANSFER)); /* start transfer command */ |
691 |
< |
cp = combuf + strlen(combuf); |
690 |
> |
strcpy(combuf, "cd "); /* start transfer command */ |
691 |
> |
fbase = dirfile(cp = combuf+3, vval(BASENAME)); |
692 |
> |
if (*cp) { |
693 |
> |
while (*++cp) ; |
694 |
> |
*cp++ = ';'; *cp++ = ' '; |
695 |
> |
} else |
696 |
> |
cp = combuf; |
697 |
> |
strcpy(cp, vval(TRANSFER)); |
698 |
> |
while (*cp) cp++; |
699 |
|
/* make argument list */ |
700 |
|
for (i = astat.tnext; i < astat.fnext; i++) { |
701 |
|
*cp++ = ' '; |
702 |
< |
sprintf(cp, vval(BASENAME), i); |
702 |
> |
sprintf(cp, fbase, i); |
703 |
|
while (*cp) cp++; |
704 |
|
strcpy(cp, ".pic"); |
705 |
|
cp += 4; |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
< |
animrend(frame, vp) /* start animation frame */ |
718 |
< |
int frame; |
719 |
< |
VIEW *vp; |
717 |
> |
static void |
718 |
> |
animrend( /* start animation frame */ |
719 |
> |
int frame, |
720 |
> |
VIEW *vp |
721 |
> |
) |
722 |
|
{ |
669 |
– |
extern int recover(); |
723 |
|
char combuf[2048]; |
724 |
|
char fname[128]; |
725 |
|
|
733 |
|
} |
734 |
|
|
735 |
|
|
736 |
< |
walkwait(first, last, vfn) /* walk-through frames */ |
737 |
< |
int first, last; |
738 |
< |
char *vfn; |
736 |
> |
static void |
737 |
> |
walkwait( /* walk-through frames */ |
738 |
> |
int first, |
739 |
> |
int last, |
740 |
> |
char *vfn |
741 |
> |
) |
742 |
|
{ |
743 |
+ |
double blurf; |
744 |
+ |
int nblur = getblur(&blurf); |
745 |
|
char combuf[2048]; |
746 |
< |
char *inspoint; |
746 |
> |
register char *inspoint; |
747 |
|
register int i; |
748 |
|
|
749 |
|
if (!noaction && vint(INTERP)) /* create dummy frames */ |
754 |
|
close(open(combuf, O_RDONLY|O_CREAT, 0666)); |
755 |
|
} |
756 |
|
/* create command */ |
757 |
< |
sprintf(combuf, "rpict%s -w0", rendopt); |
758 |
< |
if (vint(INTERP) || atoi(vval(MBLUR))) |
759 |
< |
sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME)); |
760 |
< |
sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d", |
757 |
> |
sprintf(combuf, "rpict%s%s -w0", rendopt, |
758 |
> |
viewopt(getview(first>1 ? first-1 : 1))); |
759 |
> |
inspoint = combuf; |
760 |
> |
while (*inspoint) inspoint++; |
761 |
> |
if (nblur) { |
762 |
> |
sprintf(inspoint, " -pm %.3f", blurf/nblur); |
763 |
> |
while (*inspoint) inspoint++; |
764 |
> |
} |
765 |
> |
if (nblur > 1 || vint(INTERP)) { |
766 |
> |
sprintf(inspoint, " -z %s.zbf", vval(BASENAME)); |
767 |
> |
while (*inspoint) inspoint++; |
768 |
> |
} |
769 |
> |
sprintf(inspoint, " -o %s.unf %s -S %d", |
770 |
|
vval(BASENAME), rresopt, first); |
771 |
< |
inspoint = combuf + strlen(combuf); |
771 |
> |
while (*inspoint) inspoint++; |
772 |
|
sprintf(inspoint, " %s < %s", vval(OCTREE), vfn); |
773 |
|
/* run in parallel */ |
774 |
|
i = (last-first+1)/(vint(INTERP)+1); |
788 |
|
} |
789 |
|
|
790 |
|
|
791 |
< |
int |
792 |
< |
recover(frame) /* recover the specified frame */ |
726 |
< |
int frame; |
791 |
> |
static int |
792 |
> |
recover(int frame) /* recover the specified frame */ |
793 |
|
{ |
794 |
|
static int *rfrm; /* list of recovered frames */ |
795 |
|
static int nrfrms = 0; |
796 |
+ |
double blurf; |
797 |
+ |
int nblur = getblur(&blurf); |
798 |
|
char combuf[2048]; |
799 |
|
char fname[128]; |
800 |
|
register char *cp; |
810 |
|
vval(ANIMATE), frame, rendopt); |
811 |
|
else |
812 |
|
sprintf(combuf, "rpict%s -w0", rendopt); |
813 |
< |
cp = combuf + strlen(combuf); |
814 |
< |
if (vint(INTERP) || atoi(vval(MBLUR))) { |
813 |
> |
cp = combuf; |
814 |
> |
while (*cp) cp++; |
815 |
> |
if (nblur) { |
816 |
> |
sprintf(cp, " -pm %.3f", blurf/nblur); |
817 |
> |
while (*cp) cp++; |
818 |
> |
} |
819 |
> |
if (nblur > 1 || vint(INTERP)) { |
820 |
|
sprintf(cp, " -z %s.zbf", fname); |
821 |
|
while (*cp) cp++; |
822 |
|
} |
830 |
|
return(1); |
831 |
|
/* add frame to recovered list */ |
832 |
|
if (nrfrms) |
833 |
< |
rfrm = (int *)realloc((char *)rfrm, (nrfrms+1)*sizeof(int)); |
833 |
> |
rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int)); |
834 |
|
else |
835 |
|
rfrm = (int *)malloc(sizeof(int)); |
836 |
|
if (rfrm == NULL) { |
842 |
|
} |
843 |
|
|
844 |
|
|
845 |
< |
int |
846 |
< |
frecover(frame) /* recover filtered frame */ |
774 |
< |
int frame; |
845 |
> |
static int |
846 |
> |
frecover(int frame) /* recover filtered frame */ |
847 |
|
{ |
848 |
< |
VIEW *vp; |
777 |
< |
char *ex; |
778 |
< |
|
779 |
< |
vp = getview(frame); |
780 |
< |
ex = getexp(frame); |
781 |
< |
if (dofilt(frame, vp, ex, 2) && dofilt(frame, vp, ex, 1)) |
848 |
> |
if (dofilt(frame, 2) && dofilt(frame, 1)) |
849 |
|
return(1); |
850 |
|
return(0); |
851 |
|
} |
852 |
|
|
853 |
|
|
854 |
< |
archive() /* archive and remove renderings */ |
854 |
> |
static void |
855 |
> |
archive(void) /* archive and remove renderings */ |
856 |
|
{ |
857 |
|
#define RMCOML (sizeof(rmcom)-1) |
858 |
|
static char rmcom[] = "rm -f"; |
859 |
< |
register int i; |
859 |
> |
char basedir[128]; |
860 |
> |
int dlen, alen; |
861 |
> |
register int j; |
862 |
|
|
863 |
|
if (arcnext == arcfirst) |
864 |
|
return; /* nothing to do */ |
865 |
+ |
dirfile(basedir, vval(BASENAME)); |
866 |
+ |
dlen = strlen(basedir); |
867 |
|
if (vdef(ARCHIVE)) { /* run archive command */ |
868 |
< |
i = strlen(vval(ARCHIVE)); |
869 |
< |
strncpy(arcfirst-i, vval(ARCHIVE), i); |
870 |
< |
if (runcom(arcfirst-i)) { |
868 |
> |
alen = strlen(vval(ARCHIVE)); |
869 |
> |
if (dlen) { |
870 |
> |
j = alen + dlen + 5; |
871 |
> |
strncpy(arcfirst-j, "cd ", 3); |
872 |
> |
strncpy(arcfirst-j+3, basedir, dlen); |
873 |
> |
(arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; |
874 |
> |
} else |
875 |
> |
j = alen; |
876 |
> |
strncpy(arcfirst-alen, vval(ARCHIVE), alen); |
877 |
> |
if (runcom(arcfirst-j)) { |
878 |
|
fprintf(stderr, "%s: error running archive command\n", |
879 |
|
progname); |
880 |
|
quit(1); |
881 |
|
} |
882 |
|
} |
883 |
+ |
if (dlen) { |
884 |
+ |
j = RMCOML + dlen + 5; |
885 |
+ |
strncpy(arcfirst-j, "cd ", 3); |
886 |
+ |
strncpy(arcfirst-j+3, basedir, dlen); |
887 |
+ |
(arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' '; |
888 |
+ |
} else |
889 |
+ |
j = RMCOML; |
890 |
|
/* run remove command */ |
891 |
|
strncpy(arcfirst-RMCOML, rmcom, RMCOML); |
892 |
< |
runcom(arcfirst-RMCOML); |
892 |
> |
runcom(arcfirst-j); |
893 |
|
arcnext = arcfirst; /* reset argument list */ |
894 |
|
#undef RMCOML |
895 |
|
} |
896 |
|
|
897 |
|
|
898 |
< |
int |
899 |
< |
dofilt(frame, vp, ep, rvr) /* filter frame */ |
900 |
< |
int frame; |
901 |
< |
VIEW *vp; |
902 |
< |
char *ep; |
817 |
< |
int rvr; |
898 |
> |
static int |
899 |
> |
dofilt( /* filter frame */ |
900 |
> |
int frame, |
901 |
> |
int rvr |
902 |
> |
) |
903 |
|
{ |
819 |
– |
extern int frecover(); |
904 |
|
static int iter = 0; |
905 |
< |
char fnbefore[128], fnafter[128]; |
905 |
> |
double blurf; |
906 |
> |
int nblur = getblur(&blurf); |
907 |
> |
VIEW *vp = getview(frame); |
908 |
> |
char *ep = getexp(frame); |
909 |
> |
char fnbefore[128], fnafter[128], *fbase; |
910 |
|
char combuf[1024], fname0[128], fname1[128]; |
911 |
|
int usepinterp, usepfilt, nora_rgbe; |
912 |
|
int frseq[2]; |
913 |
|
/* check what is needed */ |
914 |
< |
usepinterp = atoi(vval(MBLUR)); |
915 |
< |
usepfilt = pfiltalways | ep==NULL; |
914 |
> |
if (vp == NULL) { |
915 |
> |
fprintf(stderr, |
916 |
> |
"%s: unexpected error reading view for frame %d\n", |
917 |
> |
progname, frame); |
918 |
> |
quit(1); |
919 |
> |
} |
920 |
> |
usepinterp = (nblur > 1); |
921 |
> |
usepfilt = pfiltalways | (ep==NULL); |
922 |
|
if (ep != NULL && !strcmp(ep, "1")) |
923 |
|
ep = "+0"; |
924 |
|
nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL || |
926 |
|
/* compute rendered views */ |
927 |
|
frseq[0] = frame - ((frame-1) % (vint(INTERP)+1)); |
928 |
|
frseq[1] = frseq[0] + vint(INTERP) + 1; |
929 |
+ |
fbase = dirfile(NULL, vval(BASENAME)); |
930 |
|
if (frseq[1] > vint(END)) |
931 |
|
frseq[1] = vint(END); |
932 |
|
if (frseq[1] == frame) { /* pfilt only */ |
936 |
|
} else if (frseq[0] == frame) { /* no interpolation needed */ |
937 |
|
if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */ |
938 |
|
*arcnext++ = ' '; |
939 |
< |
sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1); |
939 |
> |
sprintf(arcnext, fbase, frame-vint(INTERP)-1); |
940 |
|
while (*arcnext) arcnext++; |
941 |
|
strcpy(arcnext, ".unf"); |
942 |
|
arcnext += 4; |
943 |
|
if (usepinterp || vint(INTERP)) { /* and Z-buf */ |
944 |
|
*arcnext++ = ' '; |
945 |
< |
sprintf(arcnext, vval(BASENAME), |
851 |
< |
frame-vint(INTERP)-1); |
945 |
> |
sprintf(arcnext, fbase, frame-vint(INTERP)-1); |
946 |
|
while (*arcnext) arcnext++; |
947 |
|
strcpy(arcnext, ".zbf"); |
948 |
|
arcnext += 4; |
962 |
|
if (usepinterp) { /* using pinterp */ |
963 |
|
if (rvr == 2 && recover(frseq[1])) /* recover after? */ |
964 |
|
return(1); |
965 |
< |
if (atoi(vval(MBLUR))) { |
872 |
< |
FILE *fp; /* motion blurring */ |
965 |
> |
if (nblur > 1) { /* with pmblur */ |
966 |
|
sprintf(fname0, "%s/vw0%c", vval(DIRECTORY), |
967 |
|
'a'+(iter%26)); |
875 |
– |
if ((fp = fopen(fname0, "w")) == NULL) { |
876 |
– |
perror(fname0); quit(1); |
877 |
– |
} |
878 |
– |
fputs(VIEWSTR, fp); |
879 |
– |
fprintview(vp, fp); |
880 |
– |
putc('\n', fp); fclose(fp); |
881 |
– |
if ((vp = getview(frame+1)) == NULL) { |
882 |
– |
fprintf(stderr, |
883 |
– |
"%s: unexpected error reading view for frame %d\n", |
884 |
– |
progname, frame+1); |
885 |
– |
quit(1); |
886 |
– |
} |
968 |
|
sprintf(fname1, "%s/vw1%c", vval(DIRECTORY), |
969 |
|
'a'+(iter%26)); |
970 |
< |
if ((fp = fopen(fname1, "w")) == NULL) { |
971 |
< |
perror(fname1); quit(1); |
970 |
> |
if (!noaction) { |
971 |
> |
FILE *fp; /* motion blurring */ |
972 |
> |
if ((fp = fopen(fname0, "w")) == NULL) { |
973 |
> |
perror(fname0); quit(1); |
974 |
> |
} |
975 |
> |
fputs(VIEWSTR, fp); |
976 |
> |
fprintview(vp, fp); |
977 |
> |
putc('\n', fp); fclose(fp); |
978 |
> |
if ((vp = getview(frame+1)) == NULL) { |
979 |
> |
fprintf(stderr, |
980 |
> |
"%s: unexpected error reading view for frame %d\n", |
981 |
> |
progname, frame+1); |
982 |
> |
quit(1); |
983 |
> |
} |
984 |
> |
if ((fp = fopen(fname1, "w")) == NULL) { |
985 |
> |
perror(fname1); quit(1); |
986 |
> |
} |
987 |
> |
fputs(VIEWSTR, fp); |
988 |
> |
fprintview(vp, fp); |
989 |
> |
putc('\n', fp); fclose(fp); |
990 |
|
} |
892 |
– |
fputs(VIEWSTR, fp); |
893 |
– |
fprintview(vp, fp); |
894 |
– |
putc('\n', fp); fclose(fp); |
991 |
|
sprintf(combuf, |
992 |
< |
"(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B", |
993 |
< |
*sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1", |
898 |
< |
atoi(vval(MBLUR)), |
992 |
> |
"(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a", |
993 |
> |
blurf, nblur, |
994 |
|
fname0, fname1, fname0, fname1); |
995 |
|
iter++; |
996 |
|
} else /* no blurring */ |
1004 |
|
if (usepfilt) |
1005 |
|
sprintf(combuf+strlen(combuf), " %s", rresopt); |
1006 |
|
else |
1007 |
< |
sprintf(combuf+strlen(combuf), " %s -e %s", |
1007 |
> |
sprintf(combuf+strlen(combuf), " -a %s -e %s", |
1008 |
|
fresopt, ep); |
1009 |
|
sprintf(combuf+strlen(combuf), " %s.unf %s.zbf", |
1010 |
|
fnbefore, fnbefore); |
1051 |
|
} |
1052 |
|
|
1053 |
|
|
1054 |
< |
VIEW * |
1055 |
< |
getview(n) /* get view number n */ |
961 |
< |
int n; |
1054 |
> |
static VIEW * |
1055 |
> |
getview(int n) /* get view number n */ |
1056 |
|
{ |
1057 |
|
static FILE *viewfp = NULL; /* view file pointer */ |
1058 |
|
static int viewnum = 0; /* current view number */ |
1064 |
|
fclose(viewfp); |
1065 |
|
viewfp = NULL; |
1066 |
|
viewnum = 0; |
1067 |
< |
copystruct(&curview, &stdview); |
1067 |
> |
curview = stdview; |
1068 |
|
} |
1069 |
|
return(NULL); |
1070 |
|
} |
1071 |
< |
if (viewfp == NULL) { /* open file */ |
1071 |
> |
if (viewfp == NULL) { /* open file */ |
1072 |
|
if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) { |
1073 |
|
perror(vval(VIEWFILE)); |
1074 |
|
quit(1); |
1075 |
|
} |
1076 |
< |
} else if (n < viewnum) { /* rewind file */ |
1076 |
> |
} else if (n > 0 && n < viewnum) { /* rewind file */ |
1077 |
|
if (viewnum == 1 && feof(viewfp)) |
1078 |
|
return(&curview); /* just one view */ |
1079 |
|
if (fseek(viewfp, 0L, 0) == EOF) { |
1080 |
|
perror(vval(VIEWFILE)); |
1081 |
|
quit(1); |
1082 |
|
} |
1083 |
< |
copystruct(&curview, &stdview); |
1083 |
> |
curview = stdview; |
1084 |
|
viewnum = 0; |
1085 |
|
} |
1086 |
+ |
if (n < 0) { /* get next view */ |
1087 |
+ |
register int c = getc(viewfp); |
1088 |
+ |
if (c == EOF) |
1089 |
+ |
return((VIEW *)NULL); /* that's it */ |
1090 |
+ |
ungetc(c, viewfp); |
1091 |
+ |
n = viewnum + 1; |
1092 |
+ |
} |
1093 |
|
while (n > viewnum) { /* scan to desired view */ |
1094 |
|
if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL) |
1095 |
|
return(viewnum==1 ? &curview : (VIEW *)NULL); |
1100 |
|
} |
1101 |
|
|
1102 |
|
|
1103 |
< |
int |
1104 |
< |
countviews() /* count views in view file */ |
1103 |
> |
static int |
1104 |
> |
countviews(void) /* count views in view file */ |
1105 |
|
{ |
1106 |
< |
register int n = 0; |
1106 |
> |
int n; |
1107 |
|
|
1108 |
< |
while (getview(n+1) != NULL) |
1108 |
> |
if (getview(n=1) == NULL) |
1109 |
> |
return(0); |
1110 |
> |
while (getview(-1) != NULL) |
1111 |
|
n++; |
1112 |
|
return(n); |
1113 |
|
} |
1114 |
|
|
1115 |
|
|
1116 |
< |
char * |
1117 |
< |
getexp(n) /* get exposure for nth frame */ |
1015 |
< |
int n; |
1116 |
> |
static char * |
1117 |
> |
getexp(int n) /* get exposure for nth frame */ |
1118 |
|
{ |
1119 |
|
extern char *fskip(); |
1120 |
|
static char expval[32]; |
1126 |
|
if (n == 0) { /* signal to close file */ |
1127 |
|
if (expfp != NULL) { |
1128 |
|
fclose(expfp); |
1129 |
< |
free((char *)exppos); |
1129 |
> |
free((void *)exppos); |
1130 |
|
expfp = NULL; |
1131 |
|
} |
1132 |
|
return(NULL); |
1183 |
|
} |
1184 |
|
|
1185 |
|
|
1186 |
< |
struct pslot * |
1187 |
< |
findpslot(pid) /* find or allocate a process slot */ |
1086 |
< |
int pid; |
1186 |
> |
static struct pslot * |
1187 |
> |
findpslot(int pid) /* find or allocate a process slot */ |
1188 |
|
{ |
1189 |
|
register struct pslot *psempty = NULL; |
1190 |
|
register int i; |
1199 |
|
} |
1200 |
|
|
1201 |
|
|
1202 |
< |
int |
1203 |
< |
donecom(ps, pn, status) /* clean up after finished process */ |
1204 |
< |
PSERVER *ps; |
1205 |
< |
int pn; |
1206 |
< |
int status; |
1202 |
> |
static int |
1203 |
> |
donecom( /* clean up after finished process */ |
1204 |
> |
PSERVER *ps, |
1205 |
> |
int pn, |
1206 |
> |
int status |
1207 |
> |
) |
1208 |
|
{ |
1209 |
< |
register PROC *pp; |
1209 |
> |
register NETPROC *pp; |
1210 |
|
register struct pslot *psl; |
1211 |
|
|
1212 |
|
pp = ps->proc + pn; |
1241 |
|
} |
1242 |
|
|
1243 |
|
|
1244 |
< |
int |
1245 |
< |
serverdown() /* check status of last process server */ |
1244 |
> |
static int |
1245 |
> |
serverdown(void) /* check status of last process server */ |
1246 |
|
{ |
1247 |
|
if (lastpserver == NULL || !lastpserver->hostname[0]) |
1248 |
|
return(0); |
1258 |
|
} |
1259 |
|
|
1260 |
|
|
1261 |
< |
int |
1262 |
< |
bruncom(com, fout, rf) /* run a command in the background */ |
1263 |
< |
char *com; |
1264 |
< |
int fout; |
1265 |
< |
int (*rf)(); |
1261 |
> |
static int |
1262 |
> |
bruncom( /* run a command in the background */ |
1263 |
> |
char *com, |
1264 |
> |
int fout, |
1265 |
> |
int (*rf)() |
1266 |
> |
) |
1267 |
|
{ |
1268 |
|
int pid; |
1269 |
|
register struct pslot *psl; |
1292 |
|
} |
1293 |
|
|
1294 |
|
|
1295 |
< |
bwait(ncoms) /* wait for batch job(s) to finish */ |
1296 |
< |
int ncoms; |
1295 |
> |
static void |
1296 |
> |
bwait(int ncoms) /* wait for batch job(s) to finish */ |
1297 |
|
{ |
1298 |
|
int status; |
1299 |
|
|
1307 |
|
} |
1308 |
|
|
1309 |
|
|
1310 |
< |
int |
1311 |
< |
pruncom(com, ppins, maxcopies) /* run a command in parallel over network */ |
1312 |
< |
char *com, *ppins; |
1313 |
< |
int maxcopies; |
1310 |
> |
static int |
1311 |
> |
pruncom( /* run a command in parallel over network */ |
1312 |
> |
char *com, |
1313 |
> |
char *ppins, |
1314 |
> |
int maxcopies |
1315 |
> |
) |
1316 |
|
{ |
1317 |
|
int retstatus = 0; |
1318 |
|
int hostcopies; |
1334 |
|
strcpy(com1=buf, com); /* build -PP command */ |
1335 |
|
sprintf(com1+(ppins-com), " -PP %s/%s.persist", |
1336 |
|
vval(DIRECTORY), phostname(ps)); |
1337 |
+ |
unlink(com1+(ppins-com)+5); |
1338 |
|
strcat(com1, ppins); |
1339 |
|
} else |
1340 |
|
com1 = com; |
1379 |
|
} |
1380 |
|
|
1381 |
|
|
1382 |
< |
runcom(cs) /* run a command locally and wait for it */ |
1383 |
< |
char *cs; |
1382 |
> |
static int |
1383 |
> |
runcom(char *cs) /* run a command locally and wait for it */ |
1384 |
|
{ |
1385 |
|
if (!silent) /* echo it */ |
1386 |
|
printf("\t%s\n", cs); |
1391 |
|
} |
1392 |
|
|
1393 |
|
|
1394 |
< |
rmfile(fn) /* remove a file */ |
1395 |
< |
char *fn; |
1394 |
> |
static int |
1395 |
> |
rmfile(char *fn) /* remove a file */ |
1396 |
|
{ |
1397 |
|
if (!silent) |
1398 |
< |
#ifdef MSDOS |
1398 |
> |
#ifdef _WIN32 |
1399 |
|
printf("\tdel %s\n", fn); |
1400 |
|
#else |
1401 |
|
printf("\trm -f %s\n", fn); |
1406 |
|
} |
1407 |
|
|
1408 |
|
|
1409 |
< |
badvalue(vc) /* report bad variable value and exit */ |
1410 |
< |
int vc; |
1409 |
> |
static void |
1410 |
> |
badvalue(int vc) /* report bad variable value and exit */ |
1411 |
|
{ |
1412 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1413 |
|
progname, vnam(vc)); |
1414 |
|
quit(1); |
1415 |
+ |
} |
1416 |
+ |
|
1417 |
+ |
|
1418 |
+ |
static char * |
1419 |
+ |
dirfile( /* separate path into directory and file */ |
1420 |
+ |
char *df, |
1421 |
+ |
register char *path |
1422 |
+ |
) |
1423 |
+ |
{ |
1424 |
+ |
register int i; |
1425 |
+ |
int psep; |
1426 |
+ |
|
1427 |
+ |
for (i = 0, psep = -1; path[i]; i++) |
1428 |
+ |
if (path[i] == '/') |
1429 |
+ |
psep = i; |
1430 |
+ |
if (df != NULL) { |
1431 |
+ |
if (psep == 0) { |
1432 |
+ |
df[0] = '/'; |
1433 |
+ |
df[1] = '\0'; |
1434 |
+ |
} else if (psep > 0) { |
1435 |
+ |
strncpy(df, path, psep); |
1436 |
+ |
df[psep] = '\0'; |
1437 |
+ |
} else |
1438 |
+ |
df[0] = '\0'; |
1439 |
+ |
} |
1440 |
+ |
return(path+psep+1); |
1441 |
+ |
} |
1442 |
+ |
|
1443 |
+ |
|
1444 |
+ |
static int |
1445 |
+ |
getblur(double *bf) /* get # blur samples (and fraction) */ |
1446 |
+ |
{ |
1447 |
+ |
double blurf; |
1448 |
+ |
int nblur; |
1449 |
+ |
char *s; |
1450 |
+ |
|
1451 |
+ |
if (!vdef(MBLUR)) { |
1452 |
+ |
if (bf != NULL) |
1453 |
+ |
*bf = 0.0; |
1454 |
+ |
return(0); |
1455 |
+ |
} |
1456 |
+ |
blurf = atof(vval(MBLUR)); |
1457 |
+ |
if (blurf < 0.0) |
1458 |
+ |
blurf = 0.0; |
1459 |
+ |
if (bf != NULL) |
1460 |
+ |
*bf = blurf; |
1461 |
+ |
if (blurf <= FTINY) |
1462 |
+ |
return(0); |
1463 |
+ |
s = sskip(vval(MBLUR)); |
1464 |
+ |
if (!*s) |
1465 |
+ |
return(DEF_NBLUR); |
1466 |
+ |
nblur = atoi(s); |
1467 |
+ |
if (nblur <= 0) |
1468 |
+ |
return(1); |
1469 |
+ |
return(nblur); |
1470 |
|
} |