9 |
|
|
10 |
|
#include <ctype.h> |
11 |
|
#include <time.h> |
12 |
+ |
#include <signal.h> |
13 |
|
|
14 |
|
#include "platform.h" |
15 |
|
#include "rtprocess.h" |
17 |
|
#include "paths.h" |
18 |
|
#include "vars.h" |
19 |
|
|
20 |
< |
#ifdef _WIN32 |
20 |
> |
#if defined(_WIN32) || defined(_WIN64) |
21 |
|
#define DELCMD "del" |
22 |
|
#define RENAMECMD "rename" |
23 |
|
#else |
25 |
|
#define RENAMECMD "mv" |
26 |
|
#include <sys/types.h> |
27 |
|
#include <sys/wait.h> |
28 |
+ |
#include <signal.h> |
29 |
|
#endif |
30 |
|
|
31 |
|
/* variables (alphabetical by name) */ |
37 |
|
#define INDIRECT 5 /* indirection in lighting */ |
38 |
|
#define MATERIAL 6 /* material files */ |
39 |
|
#define MKILLUM 7 /* mkillum options */ |
40 |
< |
#define OBJECT 8 /* object files */ |
41 |
< |
#define OCONV 9 /* oconv options */ |
42 |
< |
#define OCTREE 10 /* octree file name */ |
43 |
< |
#define OPTFILE 11 /* rendering options file */ |
44 |
< |
#define PENUMBRAS 12 /* shadow penumbras are desired */ |
45 |
< |
#define PFILT 13 /* pfilt options */ |
46 |
< |
#define PICTURE 14 /* picture file root name */ |
47 |
< |
#define QUALITY 15 /* desired rendering quality */ |
48 |
< |
#define RAWFILE 16 /* raw picture file root name */ |
49 |
< |
#define RENDER 17 /* rendering options */ |
50 |
< |
#define REPORT 18 /* report frequency and errfile */ |
51 |
< |
#define RESOLUTION 19 /* maximum picture resolution */ |
52 |
< |
#define RPICT 20 /* rpict parameters */ |
53 |
< |
#define RVU 21 /* rvu parameters */ |
54 |
< |
#define SCENE 22 /* scene files */ |
55 |
< |
#define UP 23 /* view up (X, Y or Z) */ |
56 |
< |
#define VARIABILITY 24 /* level of light variability */ |
57 |
< |
#define VIEWS 25 /* view(s) for picture(s) */ |
58 |
< |
#define ZFILE 26 /* distance file root name */ |
59 |
< |
#define ZONE 27 /* simulation zone */ |
40 |
> |
#define MKPMAP 8 /* mkpmap options */ |
41 |
> |
#define OBJECT 9 /* object files */ |
42 |
> |
#define OCONV 10 /* oconv options */ |
43 |
> |
#define OCTREE 11 /* octree file name */ |
44 |
> |
#define OPTFILE 12 /* rendering options file */ |
45 |
> |
#define PCMAP 13 /* caustic photon map */ |
46 |
> |
#define PENUMBRAS 14 /* shadow penumbras are desired */ |
47 |
> |
#define PFILT 15 /* pfilt options */ |
48 |
> |
#define PGMAP 16 /* global photon map */ |
49 |
> |
#define PICTURE 17 /* picture file root name */ |
50 |
> |
#define QUALITY 18 /* desired rendering quality */ |
51 |
> |
#define RAWFILE 19 /* raw picture file root name */ |
52 |
> |
#define RENDER 20 /* rendering options */ |
53 |
> |
#define REPORT 21 /* report frequency and errfile */ |
54 |
> |
#define RESOLUTION 22 /* maximum picture resolution */ |
55 |
> |
#define RPICT 23 /* rpict parameters */ |
56 |
> |
#define RVU 24 /* rvu parameters */ |
57 |
> |
#define SCENE 25 /* scene files */ |
58 |
> |
#define UP 26 /* view up (X, Y or Z) */ |
59 |
> |
#define VARIABILITY 27 /* level of light variability */ |
60 |
> |
#define VIEWS 28 /* view(s) for picture(s) */ |
61 |
> |
#define ZFILE 29 /* distance file root name */ |
62 |
> |
#define ZONE 30 /* simulation zone */ |
63 |
|
/* total number of variables */ |
64 |
< |
int NVARS = 28; |
64 |
> |
int NVARS = 31; |
65 |
|
|
66 |
|
VARIABLE vv[] = { /* variable-value pairs */ |
67 |
< |
{"AMBFILE", 3, 0, NULL, onevalue}, |
67 |
> |
{"AMBFILE", 3, 0, NULL, strvalue}, |
68 |
|
{"DETAIL", 3, 0, NULL, qualvalue}, |
69 |
|
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
70 |
|
{"EYESEP", 3, 0, NULL, fltvalue}, |
72 |
|
{"INDIRECT", 3, 0, NULL, intvalue}, |
73 |
|
{"materials", 3, 0, NULL, catvalues}, |
74 |
|
{"mkillum", 3, 0, NULL, catvalues}, |
75 |
+ |
{"mkpmap", 3, 0, NULL, catvalues}, |
76 |
|
{"objects", 3, 0, NULL, catvalues}, |
77 |
|
{"oconv", 3, 0, NULL, catvalues}, |
78 |
< |
{"OCTREE", 3, 0, NULL, onevalue}, |
79 |
< |
{"OPTFILE", 3, 0, NULL, onevalue}, |
78 |
> |
{"OCTREE", 3, 0, NULL, strvalue}, |
79 |
> |
{"OPTFILE", 3, 0, NULL, strvalue}, |
80 |
> |
{"PCMAP", 2, 0, NULL, strvalue}, |
81 |
|
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
82 |
|
{"pfilt", 2, 0, NULL, catvalues}, |
83 |
< |
{"PICTURE", 3, 0, NULL, onevalue}, |
83 |
> |
{"PGMAP", 2, 0, NULL, strvalue}, |
84 |
> |
{"PICTURE", 3, 0, NULL, strvalue}, |
85 |
|
{"QUALITY", 3, 0, NULL, qualvalue}, |
86 |
< |
{"RAWFILE", 3, 0, NULL, onevalue}, |
86 |
> |
{"RAWFILE", 3, 0, NULL, strvalue}, |
87 |
|
{"render", 3, 0, NULL, catvalues}, |
88 |
|
{"REPORT", 3, 0, NULL, onevalue}, |
89 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
93 |
|
{"UP", 2, 0, NULL, onevalue}, |
94 |
|
{"VARIABILITY", 3, 0, NULL, qualvalue}, |
95 |
|
{"view", 2, 0, NULL, NULL}, |
96 |
< |
{"ZFILE", 2, 0, NULL, onevalue}, |
96 |
> |
{"ZFILE", 2, 0, NULL, strvalue}, |
97 |
|
{"ZONE", 2, 0, NULL, onevalue}, |
98 |
|
}; |
99 |
|
|
115 |
|
char *oct1name; /* name of post-mkillum octree */ |
116 |
|
time_t oct1date; /* date of post-mkillum octree (>= matdate) */ |
117 |
|
|
118 |
+ |
char *pgmapname; /* name of global photon map */ |
119 |
+ |
time_t pgmapdate; /* date of global photon map (>= oct1date) */ |
120 |
+ |
char *pcmapname; /* name of caustic photon map */ |
121 |
+ |
time_t pcmapdate; /* date of caustic photon map (>= oct1date) */ |
122 |
+ |
|
123 |
|
int nowarn = 0; /* no warnings */ |
124 |
|
int explicate = 0; /* explicate variables */ |
125 |
|
int silent = 0; /* do work silently */ |
131 |
|
|
132 |
|
#define DEF_RPICT_PATH "rpict" /* default rpict path */ |
133 |
|
|
134 |
+ |
#define R_CMDMAX (5*PATH_MAX+512) |
135 |
|
/* command paths */ |
136 |
|
char c_oconv[256] = "oconv"; |
137 |
|
char c_mkillum[256] = "mkillum"; |
138 |
+ |
char c_mkpmap[256] = "mkpmap"; |
139 |
|
char c_rvu[256] = "rvu"; |
140 |
|
char c_rpict[256] = DEF_RPICT_PATH; |
141 |
|
char c_rpiece[] = "rpiece"; |
159 |
|
static void getoctcube(double org[3], double *sizp); |
160 |
|
static void setdefaults(void); |
161 |
|
static void oconv(void); |
162 |
+ |
static void mkpmap(void); |
163 |
|
static char * addarg(char *op, char *arg); |
164 |
|
static void oconvopts(char *oo); |
165 |
|
static void mkillumopts(char *mo); |
166 |
+ |
static void mkpmapopts(char *mo); |
167 |
|
static void checkambfile(void); |
168 |
|
static double ambval(void); |
169 |
|
static void renderopts(char *op, char *po); |
243 |
|
/* load variable values */ |
244 |
|
loadvars(rifname); |
245 |
|
/* get any additional assignments */ |
246 |
< |
for (i++; i < argc; i++) |
247 |
< |
if (setvariable(argv[i], matchvar) < 0) { |
248 |
< |
fprintf(stderr, "%s: unknown variable: %s\n", |
246 |
> |
for (i++; i < argc; i++) { |
247 |
> |
int rv = setvariable(argv[i], matchvar); |
248 |
> |
if (rv < 0) { |
249 |
> |
fprintf(stderr, "%s: unknown setting: %s\n", |
250 |
|
progname, argv[i]); |
251 |
|
quit(1); |
252 |
|
} |
253 |
+ |
if (!rv) |
254 |
+ |
fprintf(stderr, |
255 |
+ |
"%s: bad variable assignment: %s (ignored)\n", |
256 |
+ |
progname, argv[i]); |
257 |
+ |
} |
258 |
|
/* check assignments */ |
259 |
|
checkvalues(); |
260 |
|
/* check files and dates */ |
266 |
|
printvars(stdout); |
267 |
|
/* build octree (and run mkillum) */ |
268 |
|
oconv(); |
269 |
+ |
/* run mkpmap if indicated */ |
270 |
+ |
mkpmap(); |
271 |
|
/* check date on ambient file */ |
272 |
|
checkambfile(); |
273 |
|
/* run simulation */ |
289 |
|
|
290 |
|
static void |
291 |
|
rootname( /* remove tail from end of fn */ |
292 |
< |
register char *rn, |
293 |
< |
register char *fn |
292 |
> |
char *rn, |
293 |
> |
char *fn |
294 |
|
) |
295 |
|
{ |
296 |
|
char *tp, *dp; |
307 |
|
|
308 |
|
static time_t |
309 |
|
checklast( /* check files and find most recent */ |
310 |
< |
register char *fnames |
310 |
> |
char *fnames |
311 |
|
) |
312 |
|
{ |
313 |
|
char thisfile[PATH_MAX]; |
337 |
|
int pred |
338 |
|
) |
339 |
|
{ |
340 |
< |
register char *cp; |
341 |
< |
register int n; |
340 |
> |
char *cp; |
341 |
> |
int n; |
342 |
|
int suffix; |
343 |
|
|
344 |
|
n = 0; cp = orig; suffix = -1; /* suffix position, length */ |
360 |
|
static void |
361 |
|
checkfiles(void) /* check for existence and modified times */ |
362 |
|
{ |
363 |
+ |
char fntemp[256]; |
364 |
|
time_t objdate; |
365 |
|
|
366 |
|
if (!vdef(OCTREE)) { |
390 |
|
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
391 |
|
quit(1); |
392 |
|
} |
393 |
+ |
if (vdef(PGMAP)) { |
394 |
+ |
if (!*sskip2(vval(PGMAP),1)) { |
395 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
396 |
+ |
progname, vnam(PGMAP)); |
397 |
+ |
quit(1); |
398 |
+ |
} |
399 |
+ |
atos(fntemp, sizeof(fntemp), vval(PGMAP)); |
400 |
+ |
pgmapname = savqstr(fntemp); |
401 |
+ |
pgmapdate = fdate(pgmapname); |
402 |
+ |
} |
403 |
+ |
if (vdef(PCMAP)) { |
404 |
+ |
if (!*sskip2(vval(PCMAP),1)) { |
405 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
406 |
+ |
progname, vnam(PCMAP)); |
407 |
+ |
quit(1); |
408 |
+ |
} |
409 |
+ |
atos(fntemp, sizeof(fntemp), vval(PCMAP)); |
410 |
+ |
pcmapname = savqstr(fntemp); |
411 |
+ |
pcmapdate = fdate(pcmapname); |
412 |
+ |
} |
413 |
|
matdate = checklast(vval(MATERIAL)); |
414 |
|
} |
415 |
|
|
424 |
|
double min[3], max[3]; |
425 |
|
char buf[1024]; |
426 |
|
FILE *fp; |
427 |
< |
register int i; |
427 |
> |
int i; |
428 |
|
|
429 |
|
if (osiz <= FTINY) { |
430 |
|
if (!nprocs && fdate(oct1name) < |
529 |
|
oconv(void) /* run oconv and mkillum if necessary */ |
530 |
|
{ |
531 |
|
static char illumtmp[] = "ilXXXXXX"; |
532 |
< |
char combuf[PATH_MAX], ocopts[64], mkopts[1024]; |
532 |
> |
char combuf[R_CMDMAX], ocopts[64], mkopts[1024]; |
533 |
|
|
534 |
|
oconvopts(ocopts); /* get options */ |
535 |
|
if (octreedate < scenedate) { /* check date on original octree */ |
563 |
|
return; |
564 |
|
/* make octree0 */ |
565 |
|
if ((oct0date < scenedate) | (oct0date < illumdate)) { |
566 |
< |
if (touchonly && oct0date) |
567 |
< |
touch(oct0name); |
568 |
< |
else { /* build command */ |
566 |
> |
if (touchonly && (oct0date || oct1date)) { |
567 |
> |
if (oct0date) |
568 |
> |
touch(oct0name); |
569 |
> |
} else { /* build command */ |
570 |
|
if (octreedate) |
571 |
|
sprintf(combuf, "%s%s -i %s %s > %s", c_oconv, |
572 |
|
ocopts, vval(OCTREE), |
591 |
|
oct0date = octreedate; |
592 |
|
if (oct0date < illumdate) /* ditto */ |
593 |
|
oct0date = illumdate; |
594 |
< |
} |
594 |
> |
} |
595 |
|
if (touchonly && oct1date) |
596 |
|
touch(oct1name); |
597 |
|
else { |
605 |
|
unlink(illumtmp); |
606 |
|
quit(1); |
607 |
|
} |
608 |
+ |
rmfile(oct0name); |
609 |
|
/* make octree1 (frozen) */ |
610 |
|
if (octreedate) |
611 |
|
sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv, |
632 |
|
} |
633 |
|
|
634 |
|
|
635 |
+ |
static void |
636 |
+ |
mkpmap(void) /* run mkpmap if indicated */ |
637 |
+ |
{ |
638 |
+ |
char combuf[2048], *cp; |
639 |
+ |
time_t tnow; |
640 |
+ |
/* nothing to do? */ |
641 |
+ |
if ((pgmapname == NULL) | (pgmapdate >= oct1date) && |
642 |
+ |
(pcmapname == NULL) | (pcmapdate >= oct1date)) |
643 |
+ |
return; |
644 |
+ |
/* just update existing file dates? */ |
645 |
+ |
if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) && |
646 |
+ |
(pcmapname == NULL) | (pcmapdate > 0)) { |
647 |
+ |
if (pgmapname != NULL) |
648 |
+ |
touch(pgmapname); |
649 |
+ |
if (pcmapname != NULL) |
650 |
+ |
touch(pcmapname); |
651 |
+ |
} else { /* else need to (re)run pkpmap */ |
652 |
+ |
strcpy(combuf, c_mkpmap); |
653 |
+ |
for (cp = combuf; *cp; cp++) |
654 |
+ |
; |
655 |
+ |
mkpmapopts(cp); |
656 |
+ |
/* force file overwrite */ |
657 |
+ |
cp = addarg(cp, "-fo+"); |
658 |
+ |
if (vdef(REPORT)) { |
659 |
+ |
char errfile[256]; |
660 |
+ |
int n; |
661 |
+ |
double minutes; |
662 |
+ |
n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile); |
663 |
+ |
if (n == 2) |
664 |
+ |
sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile); |
665 |
+ |
else if (n == 1) |
666 |
+ |
sprintf(cp, " -t %d", (int)(minutes*60)); |
667 |
+ |
else |
668 |
+ |
badvalue(REPORT); |
669 |
+ |
} |
670 |
+ |
if (pgmapname != NULL && pgmapdate < oct1date) { |
671 |
+ |
cp = addarg(cp, "-apg"); |
672 |
+ |
addarg(cp, vval(PGMAP)); |
673 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
674 |
+ |
*cp = '\0'; |
675 |
+ |
} |
676 |
+ |
if (pcmapname != NULL && pcmapdate < oct1date) { |
677 |
+ |
cp = addarg(cp, "-apc"); |
678 |
+ |
addarg(cp, vval(PCMAP)); |
679 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
680 |
+ |
*cp = '\0'; |
681 |
+ |
} |
682 |
+ |
cp = addarg(cp, oct1name); |
683 |
+ |
if (runcom(combuf)) { |
684 |
+ |
fprintf(stderr, "%s: error running %s\n", |
685 |
+ |
progname, c_mkpmap); |
686 |
+ |
if (pgmapname != NULL && pgmapdate < oct1date) |
687 |
+ |
unlink(pgmapname); |
688 |
+ |
if (pcmapname != NULL && pcmapdate < oct1date) |
689 |
+ |
unlink(pcmapname); |
690 |
+ |
quit(1); |
691 |
+ |
} |
692 |
+ |
} |
693 |
+ |
tnow = time((time_t *)NULL); |
694 |
+ |
if (pgmapname != NULL) |
695 |
+ |
pgmapdate = tnow; |
696 |
+ |
if (pcmapname != NULL) |
697 |
+ |
pcmapdate = tnow; |
698 |
+ |
oct1date = tnow; /* trigger ambient file removal if needed */ |
699 |
+ |
} |
700 |
+ |
|
701 |
+ |
|
702 |
|
static char * |
703 |
|
addarg( /* append argument and advance pointer */ |
704 |
< |
register char *op, |
705 |
< |
register char *arg |
704 |
> |
char *op, |
705 |
> |
char *arg |
706 |
|
) |
707 |
|
{ |
708 |
|
while (*op) |
716 |
|
|
717 |
|
static void |
718 |
|
oconvopts( /* get oconv options */ |
719 |
< |
register char *oo |
719 |
> |
char *oo |
720 |
|
) |
721 |
|
{ |
722 |
|
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
723 |
|
|
724 |
|
*oo = '\0'; |
725 |
< |
if (vdef(OCONV)) |
726 |
< |
if (vval(OCONV)[0] != '-') { |
727 |
< |
atos(c_oconv, sizeof(c_oconv), vval(OCONV)); |
728 |
< |
oo = addarg(oo, sskip2(vval(OCONV), 1)); |
729 |
< |
} else |
730 |
< |
oo = addarg(oo, vval(OCONV)); |
725 |
> |
if (!vdef(OCONV)) |
726 |
> |
return; |
727 |
> |
if (vval(OCONV)[0] != '-') { |
728 |
> |
atos(c_oconv, sizeof(c_oconv), vval(OCONV)); |
729 |
> |
oo = addarg(oo, sskip2(vval(OCONV), 1)); |
730 |
> |
} else |
731 |
> |
oo = addarg(oo, vval(OCONV)); |
732 |
|
} |
733 |
|
|
734 |
|
|
743 |
|
sprintf(mo, " -n %d", nprocs); |
744 |
|
else |
745 |
|
*mo = '\0'; |
746 |
< |
if (vdef(MKILLUM)) |
747 |
< |
if (vval(MKILLUM)[0] != '-') { |
748 |
< |
atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); |
749 |
< |
mo = addarg(mo, sskip2(vval(MKILLUM), 1)); |
750 |
< |
} else |
751 |
< |
mo = addarg(mo, vval(MKILLUM)); |
746 |
> |
if (!vdef(MKILLUM)) |
747 |
> |
return; |
748 |
> |
if (vval(MKILLUM)[0] != '-') { |
749 |
> |
atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); |
750 |
> |
mo = addarg(mo, sskip2(vval(MKILLUM), 1)); |
751 |
> |
} else |
752 |
> |
mo = addarg(mo, vval(MKILLUM)); |
753 |
|
} |
754 |
|
|
755 |
|
|
756 |
|
static void |
757 |
+ |
mkpmapopts( /* get mkpmap options */ |
758 |
+ |
char *mo |
759 |
+ |
) |
760 |
+ |
{ |
761 |
+ |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
762 |
+ |
|
763 |
+ |
if (nprocs > 1) |
764 |
+ |
sprintf(mo, " -n %d", nprocs); |
765 |
+ |
else |
766 |
+ |
*mo = '\0'; |
767 |
+ |
if (!vdef(MKPMAP)) |
768 |
+ |
return; |
769 |
+ |
if (vval(MKPMAP)[0] != '-') { |
770 |
+ |
atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP)); |
771 |
+ |
mo = addarg(mo, sskip2(vval(MKPMAP), 1)); |
772 |
+ |
} else |
773 |
+ |
mo = addarg(mo, vval(MKPMAP)); |
774 |
+ |
} |
775 |
+ |
|
776 |
+ |
|
777 |
+ |
static void |
778 |
|
checkambfile(void) /* check date on ambient file */ |
779 |
|
{ |
780 |
|
time_t afdate; |
797 |
|
{ |
798 |
|
if (vdef(EXPOSURE)) { |
799 |
|
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
800 |
< |
return(.5/pow(2.,vflt(EXPOSURE))); |
801 |
< |
return(.5/vflt(EXPOSURE)); |
800 |
> |
return(.18/pow(2.,vflt(EXPOSURE))); |
801 |
> |
return(.18/vflt(EXPOSURE)); |
802 |
|
} |
803 |
|
if (vlet(ZONE) == 'E') |
804 |
|
return(10.); |
815 |
|
char *po |
816 |
|
) |
817 |
|
{ |
818 |
+ |
char pmapf[256], *bw; |
819 |
+ |
|
820 |
+ |
if (vdef(PGMAP)) { |
821 |
+ |
*op = '\0'; |
822 |
+ |
bw = sskip2(vval(PGMAP), 2); |
823 |
+ |
atos(pmapf, sizeof(pmapf), vval(PGMAP)); |
824 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
825 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
826 |
+ |
} |
827 |
|
switch(vscale(QUALITY)) { |
828 |
|
case LOW: |
829 |
|
lowqopts(op, po); |
835 |
|
hiqopts(op, po); |
836 |
|
break; |
837 |
|
} |
838 |
< |
if (vdef(RENDER)) |
838 |
> |
if (vdef(PCMAP)) { |
839 |
> |
bw = sskip2(vval(PCMAP), 2); |
840 |
> |
atos(pmapf, sizeof(pmapf), vval(PCMAP)); |
841 |
> |
op = addarg(addarg(op, "-ap"), pmapf); |
842 |
> |
if (atoi(bw) > 0) op = addarg(op, bw); |
843 |
> |
} |
844 |
> |
if (vdef(RENDER)) { |
845 |
|
op = addarg(op, vval(RENDER)); |
846 |
+ |
bw = strstr(vval(RENDER), "-aa "); |
847 |
+ |
if (bw != NULL && atof(bw+4) <= FTINY) |
848 |
+ |
overture = 0; |
849 |
+ |
} |
850 |
|
if (rvdevice != NULL) { |
851 |
< |
if (vdef(RVU)) |
851 |
> |
if (vdef(RVU)) { |
852 |
|
if (vval(RVU)[0] != '-') { |
853 |
|
atos(c_rvu, sizeof(c_rvu), vval(RVU)); |
854 |
|
po = addarg(po, sskip2(vval(RVU), 1)); |
855 |
|
} else |
856 |
|
po = addarg(po, vval(RVU)); |
857 |
+ |
} |
858 |
|
} else { |
859 |
< |
if (vdef(RPICT)) |
859 |
> |
if (vdef(RPICT)) { |
860 |
|
if (vval(RPICT)[0] != '-') { |
861 |
|
atos(c_rpict, sizeof(c_rpict), vval(RPICT)); |
862 |
|
po = addarg(po, sskip2(vval(RPICT), 1)); |
863 |
|
} else |
864 |
|
po = addarg(po, vval(RPICT)); |
865 |
+ |
} |
866 |
|
} |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
|
static void |
871 |
|
lowqopts( /* low quality rendering options */ |
872 |
< |
register char *op, |
872 |
> |
char *op, |
873 |
|
char *po |
874 |
|
) |
875 |
|
{ |
931 |
|
d = ambval(); |
932 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
933 |
|
op += strlen(op); |
934 |
< |
op = addarg(op, "-lr 6 -lw .01"); |
934 |
> |
op = addarg(op, "-lr 6 -lw .001"); |
935 |
|
} |
936 |
|
|
937 |
|
|
938 |
|
static void |
939 |
|
medqopts( /* medium quality rendering options */ |
940 |
< |
register char *op, |
940 |
> |
char *op, |
941 |
|
char *po |
942 |
|
) |
943 |
|
{ |
1009 |
|
d = ambval(); |
1010 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
1011 |
|
op += strlen(op); |
1012 |
< |
op = addarg(op, "-lr 8 -lw .002"); |
1012 |
> |
op = addarg(op, "-lr 8 -lw 1e-4"); |
1013 |
|
} |
1014 |
|
|
1015 |
|
|
1016 |
|
static void |
1017 |
|
hiqopts( /* high quality rendering options */ |
1018 |
< |
register char *op, |
1018 |
> |
char *op, |
1019 |
|
char *po |
1020 |
|
) |
1021 |
|
{ |
1063 |
|
op = addarg(op, "-ds .1 -dj .9"); |
1064 |
|
else |
1065 |
|
op = addarg(op, "-ds .2"); |
1066 |
< |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 50 -st .01"); |
1066 |
> |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01"); |
1067 |
|
sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); |
1068 |
|
op += strlen(op); |
1069 |
|
if (vdef(AMBFILE)) { |
1085 |
|
d = ambval(); |
1086 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
1087 |
|
op += strlen(op); |
1088 |
< |
op = addarg(op, "-lr 12 -lw .0005"); |
1088 |
> |
op = addarg(op, "-lr 12 -lw 5e-6"); |
1089 |
|
} |
1090 |
|
|
1091 |
|
|
1092 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
1093 |
|
static void |
1094 |
+ |
setenv( /* set an environment variable */ |
1095 |
+ |
char *vname, |
1096 |
+ |
char *value |
1097 |
+ |
) |
1098 |
+ |
{ |
1099 |
+ |
char *evp; |
1100 |
+ |
|
1101 |
+ |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1102 |
+ |
if (evp == NULL) |
1103 |
+ |
syserr(progname); |
1104 |
+ |
sprintf(evp, "%s=%s", vname, value); |
1105 |
+ |
if (putenv(evp) != 0) { |
1106 |
+ |
fprintf(stderr, "%s: out of environment space\n", progname); |
1107 |
+ |
quit(1); |
1108 |
+ |
} |
1109 |
+ |
if (!silent) |
1110 |
+ |
printf("set %s\n", evp); |
1111 |
+ |
} |
1112 |
+ |
#endif |
1113 |
+ |
|
1114 |
+ |
|
1115 |
+ |
static void |
1116 |
|
xferopts( /* transfer options if indicated */ |
1117 |
|
char *ro |
1118 |
|
) |
1119 |
|
{ |
1120 |
|
int fd, n; |
1121 |
< |
register char *cp; |
1121 |
> |
char *cp; |
1122 |
|
|
1123 |
|
n = strlen(ro); |
1124 |
|
if (n < 2) |
1136 |
|
syserr(vval(OPTFILE)); |
1137 |
|
sprintf(ro, " @%s", vval(OPTFILE)); |
1138 |
|
} |
1139 |
< |
#ifdef _WIN32 |
1139 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1140 |
|
else if (n > 50) { |
1141 |
|
setenv("ROPT", ro+1); |
1142 |
|
strcpy(ro, " $ROPT"); |
1147 |
|
|
1148 |
|
static void |
1149 |
|
pfiltopts( /* get pfilt options */ |
1150 |
< |
register char *po |
1150 |
> |
char *po |
1151 |
|
) |
1152 |
|
{ |
1153 |
|
*po = '\0'; |
1163 |
|
po = addarg(po, "-m .25"); |
1164 |
|
break; |
1165 |
|
} |
1166 |
< |
if (vdef(PFILT)) |
1166 |
> |
if (vdef(PFILT)) { |
1167 |
|
if (vval(PFILT)[0] != '-') { |
1168 |
|
atos(c_pfilt, sizeof(c_pfilt), vval(PFILT)); |
1169 |
|
po = addarg(po, sskip2(vval(PFILT), 1)); |
1170 |
|
} else |
1171 |
|
po = addarg(po, vval(PFILT)); |
1172 |
+ |
} |
1173 |
|
} |
1174 |
|
|
1175 |
|
|
1176 |
|
static int |
1177 |
|
matchword( /* match white-delimited words */ |
1178 |
< |
register char *s1, |
1179 |
< |
register char *s2 |
1178 |
> |
char *s1, |
1179 |
> |
char *s2 |
1180 |
|
) |
1181 |
|
{ |
1182 |
|
while (isspace(*s1)) s1++; |
1190 |
|
|
1191 |
|
static char * |
1192 |
|
specview( /* get proper view spec from vs */ |
1193 |
< |
register char *vs |
1193 |
> |
char *vs |
1194 |
|
) |
1195 |
|
{ |
1196 |
|
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
1197 |
|
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
1198 |
|
static char viewopts[128]; |
1199 |
< |
register char *cp; |
1199 |
> |
char *cp; |
1200 |
|
int xpos, ypos, zpos, viewtype, upax; |
1201 |
< |
register int i; |
1201 |
> |
int i; |
1202 |
|
double cent[3], dim[3], mult, d; |
1203 |
|
|
1204 |
|
if (vs == NULL || *vs == '-') |
1258 |
|
cent[i] += .5*dim[i]; |
1259 |
|
} |
1260 |
|
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
1261 |
< |
sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g", |
1261 |
> |
sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g", |
1262 |
|
cent[0]+xpos*mult*dim[0], |
1263 |
|
cent[1]+ypos*mult*dim[1], |
1264 |
|
cent[2]+zpos*mult*dim[2], |
1290 |
|
break; |
1291 |
|
case VT_PAR: |
1292 |
|
d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); |
1293 |
< |
sprintf(cp, " -vh %.2g -vv %.2g", d, d); |
1293 |
> |
sprintf(cp, " -vh %.3g -vv %.3g", d, d); |
1294 |
|
cp += strlen(cp); |
1295 |
|
break; |
1296 |
|
case VT_ANG: |
1314 |
|
if (cp == viewopts) /* append any additional options */ |
1315 |
|
vs++; /* skip prefixed space if unneeded */ |
1316 |
|
strcpy(cp, vs); |
1317 |
< |
#ifdef _WIN32 |
1317 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1318 |
|
if (strlen(viewopts) > 40) { |
1319 |
|
setenv("VIEW", viewopts); |
1320 |
|
return("$VIEW"); |
1330 |
|
char *vn /* returned view name */ |
1331 |
|
) |
1332 |
|
{ |
1333 |
< |
register char *mv; |
1333 |
> |
char *mv; |
1334 |
|
|
1335 |
|
if (viewselect != NULL) { /* command-line selected */ |
1336 |
|
if (n) /* only do one */ |
1360 |
|
} |
1361 |
|
numview: |
1362 |
|
mv = nvalue(VIEWS, n); /* use view n */ |
1363 |
< |
if ((vn != NULL) & (mv != NULL)) |
1363 |
> |
if ((vn != NULL) & (mv != NULL)) { |
1364 |
|
if (*mv != '-') { |
1365 |
< |
register char *mv2 = mv; |
1365 |
> |
char *mv2 = mv; |
1366 |
|
while (*mv2 && !isspace(*mv2)) |
1367 |
|
*vn++ = *mv2++; |
1368 |
|
*vn = '\0'; |
1369 |
|
} else |
1370 |
|
sprintf(vn, "%d", n+1); |
1371 |
< |
|
1371 |
> |
} |
1372 |
|
return(specview(mv)); |
1373 |
|
} |
1374 |
|
|
1375 |
|
|
1376 |
|
static int |
1377 |
|
myprintview( /* print out selected view */ |
1378 |
< |
register char *vopts, |
1378 |
> |
char *vopts, |
1379 |
|
FILE *fp |
1380 |
|
) |
1381 |
|
{ |
1382 |
|
VIEW vwr; |
1383 |
|
char buf[128]; |
1384 |
< |
register char *cp; |
1385 |
< |
#ifdef _WIN32 |
1384 |
> |
char *cp; |
1385 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1386 |
|
/* XXX Should we allow something like this for all platforms? */ |
1387 |
|
/* XXX Or is it still required at all? */ |
1388 |
|
again: |
1389 |
|
#endif |
1390 |
|
if (vopts == NULL) |
1391 |
|
return(-1); |
1392 |
< |
#ifdef _WIN32 |
1392 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1393 |
|
if (vopts[0] == '$') { |
1394 |
|
vopts = getenv(vopts+1); |
1395 |
|
goto again; |
1416 |
|
) |
1417 |
|
{ |
1418 |
|
char *vw; |
1419 |
< |
char combuf[PATH_MAX]; |
1419 |
> |
char combuf[R_CMDMAX]; |
1420 |
|
/* build command */ |
1421 |
|
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1422 |
|
return; |
1437 |
|
} |
1438 |
|
|
1439 |
|
|
1440 |
+ |
static int |
1441 |
+ |
syncf_done( /* check if an rpiece sync file is complete */ |
1442 |
+ |
char *sfname |
1443 |
+ |
) |
1444 |
+ |
{ |
1445 |
+ |
FILE *fp = fopen(sfname, "r"); |
1446 |
+ |
int todo = 1; |
1447 |
+ |
int x, y; |
1448 |
+ |
|
1449 |
+ |
if (fp == NULL) |
1450 |
+ |
return(0); |
1451 |
+ |
if (fscanf(fp, "%d %d", &x, &y) != 2) |
1452 |
+ |
goto checked; |
1453 |
+ |
todo = x*y; /* total number of tiles */ |
1454 |
+ |
if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0)) |
1455 |
+ |
goto checked; |
1456 |
+ |
/* XXX assume no redundant tiles */ |
1457 |
+ |
while (fscanf(fp, "%d %d", &x, &y) == 2) |
1458 |
+ |
if (!--todo) |
1459 |
+ |
break; |
1460 |
+ |
checked: |
1461 |
+ |
fclose(fp); |
1462 |
+ |
return(!todo); |
1463 |
+ |
} |
1464 |
+ |
|
1465 |
+ |
|
1466 |
|
static void |
1467 |
|
rpict( /* run rpict and pfilt for each view */ |
1468 |
|
char *opts, |
1470 |
|
) |
1471 |
|
{ |
1472 |
|
#define do_rpiece (sfile[0]!='\0') |
1473 |
< |
char combuf[4*PATH_MAX+512]; |
1473 |
> |
char combuf[5*PATH_MAX+512]; |
1474 |
|
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
1475 |
|
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
1476 |
< |
char rppopt[128], sfile[64], *pfile = NULL; |
1476 |
> |
char rppopt[32], sfile[PATH_MAX], *pfile = NULL; |
1477 |
|
char pfopts[128]; |
1478 |
|
char vs[32], *vw; |
1479 |
|
int vn, mult; |
1480 |
|
FILE *fp; |
1481 |
|
time_t rfdt, pfdt; |
1482 |
+ |
int xres, yres; |
1483 |
+ |
double aspect; |
1484 |
+ |
int n; |
1485 |
|
/* get pfilt options */ |
1486 |
|
pfiltopts(pfopts); |
1487 |
|
/* get resolution, reporting */ |
1496 |
|
mult = 3; |
1497 |
|
break; |
1498 |
|
} |
1499 |
< |
{ |
1500 |
< |
int xres, yres; |
1501 |
< |
double aspect; |
1502 |
< |
int n; |
1503 |
< |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1504 |
< |
if (n == 3) |
1505 |
< |
sprintf(res, "-x %d -y %d -pa %.3f", |
1506 |
< |
mult*xres, mult*yres, aspect); |
1507 |
< |
else if (n) { |
1508 |
< |
if (n == 1) yres = xres; |
1297 |
< |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1298 |
< |
} else |
1299 |
< |
badvalue(RESOLUTION); |
1300 |
< |
} |
1499 |
> |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1500 |
> |
if (n == 3) |
1501 |
> |
sprintf(res, "-x %d -y %d -pa %.3f", |
1502 |
> |
mult*xres, mult*yres, aspect); |
1503 |
> |
else if (n) { |
1504 |
> |
aspect = 1.; |
1505 |
> |
if (n == 1) yres = xres; |
1506 |
> |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1507 |
> |
} else |
1508 |
> |
badvalue(RESOLUTION); |
1509 |
|
rep[0] = '\0'; |
1510 |
|
if (vdef(REPORT)) { |
1511 |
|
double minutes; |
1304 |
– |
int n; |
1512 |
|
n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); |
1513 |
|
if (n == 2) |
1514 |
|
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
1523 |
|
getview(0, vs) != NULL) { |
1524 |
|
if (!strcmp(c_rpict, DEF_RPICT_PATH) && |
1525 |
|
getview(1, NULL) == NULL) { |
1526 |
< |
sprintf(sfile, "rpsync_%s.txt", vs); |
1526 |
> |
sprintf(sfile, "%s_%s_rpsync.txt", |
1527 |
> |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), |
1528 |
> |
vs); |
1529 |
|
strcpy(rppopt, "-PP pfXXXXXX"); |
1530 |
|
} else { |
1531 |
|
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
1536 |
|
fprintf(stderr, "%s: cannot create\n", pfile); |
1537 |
|
quit(1); |
1538 |
|
} |
1539 |
+ |
pfile[-5] = '\0'; |
1540 |
|
pfile = NULL; |
1541 |
|
} |
1542 |
|
} |
1569 |
|
if (do_rpiece) { |
1570 |
|
if (rfdt < oct1date || !fdate(sfile)) { |
1571 |
|
int xdiv = 8+nprocs/3, ydiv = 8+nprocs/3; |
1572 |
< |
rfdt = 0; /* start fresh */ |
1572 |
> |
if (rfdt >= oct1date) { |
1573 |
> |
fprintf(stderr, |
1574 |
> |
"%s: partial output not created with %s\n", rawfile, c_rpiece); |
1575 |
> |
quit(1); |
1576 |
> |
} |
1577 |
> |
if (rfdt) { /* start fresh */ |
1578 |
> |
rmfile(rawfile); |
1579 |
> |
rfdt = 0; |
1580 |
> |
} |
1581 |
|
if (!silent) |
1582 |
|
printf("\techo %d %d > %s\n", |
1583 |
|
xdiv, ydiv, sfile); |
1614 |
|
} else { |
1615 |
|
if (overture) { /* run overture calculation */ |
1616 |
|
sprintf(combuf, |
1617 |
< |
"%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1618 |
< |
c_rpict, rep, vw, opts, |
1617 |
> |
"%s%s %s%s%s -x 64 -y 64 -ps 1 %s > %s", |
1618 |
> |
c_rpict, rep, vw, opts, po, |
1619 |
|
oct1name, overfile); |
1620 |
< |
if (do_rpiece) |
1621 |
< |
while (next_process(1)) |
1622 |
< |
sleep(5); |
1405 |
< |
if (runcom(combuf)) { |
1406 |
< |
fprintf(stderr, |
1620 |
> |
if (!do_rpiece || !next_process(0)) { |
1621 |
> |
if (runcom(combuf)) { |
1622 |
> |
fprintf(stderr, |
1623 |
|
"%s: error in overture for view %s\n", |
1624 |
< |
progname, vs); |
1625 |
< |
quit(1); |
1626 |
< |
} |
1411 |
< |
if (do_rpiece) { |
1412 |
< |
finish_process(); |
1413 |
< |
wait_process(1); |
1414 |
< |
} |
1624 |
> |
progname, vs); |
1625 |
> |
quit(1); |
1626 |
> |
} |
1627 |
|
#ifndef NULL_DEVICE |
1628 |
< |
rmfile(overfile); |
1628 |
> |
rmfile(overfile); |
1629 |
|
#endif |
1630 |
+ |
} else if (do_rpiece) |
1631 |
+ |
sleep(20); |
1632 |
|
} |
1633 |
|
if (do_rpiece) { |
1634 |
|
sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s", |
1660 |
|
if (do_rpiece) { /* need to finish raw, first */ |
1661 |
|
finish_process(); |
1662 |
|
wait_process(1); |
1663 |
< |
/* XXX should check sync file to see if really done? */ |
1663 |
> |
if (!syncf_done(sfile)) { |
1664 |
> |
fprintf(stderr, |
1665 |
> |
"%s: %s did not complete rendering of view %s\n", |
1666 |
> |
progname, c_rpiece, vs); |
1667 |
> |
quit(1); |
1668 |
> |
} |
1669 |
|
} |
1670 |
|
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1671 |
|
/* build pfilt command */ |
1672 |
< |
if (mult > 1) |
1672 |
> |
if (do_rpiece) |
1673 |
> |
sprintf(combuf, |
1674 |
> |
"%s%s -x %d -y %d -p %.3f %s > %s", |
1675 |
> |
c_pfilt, pfopts, xres, yres, aspect, |
1676 |
> |
rawfile, picfile); |
1677 |
> |
else if (mult > 1) |
1678 |
|
sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", |
1679 |
|
c_pfilt, pfopts, mult, mult, |
1680 |
|
rawfile, picfile); |
1794 |
|
child_pid = fork(); /* split process */ |
1795 |
|
if (child_pid == 0) { /* we're the child */ |
1796 |
|
children_running = -1; |
1797 |
+ |
nprocs = 1; |
1798 |
|
return(0); |
1799 |
|
} |
1800 |
|
if (child_pid > 0) { /* we're the parent */ |
1862 |
|
return; /* in parent -- noop */ |
1863 |
|
exit(0); |
1864 |
|
} |
1640 |
– |
|
1641 |
– |
#ifdef _WIN32 |
1642 |
– |
setenv(vname, value) /* set an environment variable */ |
1643 |
– |
char *vname, *value; |
1644 |
– |
{ |
1645 |
– |
register char *evp; |
1646 |
– |
|
1647 |
– |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1648 |
– |
if (evp == NULL) |
1649 |
– |
syserr(progname); |
1650 |
– |
sprintf(evp, "%s=%s", vname, value); |
1651 |
– |
if (putenv(evp) != 0) { |
1652 |
– |
fprintf(stderr, "%s: out of environment space\n", progname); |
1653 |
– |
quit(1); |
1654 |
– |
} |
1655 |
– |
if (!silent) |
1656 |
– |
printf("set %s\n", evp); |
1657 |
– |
} |
1658 |
– |
#endif |
1865 |
|
|
1866 |
|
|
1867 |
|
static void |