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}, |
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}, |
80 |
+ |
{"PCMAP", 2, 0, NULL, onevalue}, |
81 |
|
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
82 |
|
{"pfilt", 2, 0, NULL, catvalues}, |
83 |
+ |
{"PGMAP", 2, 0, NULL, onevalue}, |
84 |
|
{"PICTURE", 3, 0, NULL, onevalue}, |
85 |
|
{"QUALITY", 3, 0, NULL, qualvalue}, |
86 |
|
{"RAWFILE", 3, 0, NULL, onevalue}, |
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 */ |
134 |
|
/* command paths */ |
135 |
|
char c_oconv[256] = "oconv"; |
136 |
|
char c_mkillum[256] = "mkillum"; |
137 |
+ |
char c_mkpmap[256] = "mkpmap"; |
138 |
|
char c_rvu[256] = "rvu"; |
139 |
|
char c_rpict[256] = DEF_RPICT_PATH; |
140 |
|
char c_rpiece[] = "rpiece"; |
158 |
|
static void getoctcube(double org[3], double *sizp); |
159 |
|
static void setdefaults(void); |
160 |
|
static void oconv(void); |
161 |
+ |
static void mkpmap(void); |
162 |
|
static char * addarg(char *op, char *arg); |
163 |
|
static void oconvopts(char *oo); |
164 |
|
static void mkillumopts(char *mo); |
165 |
+ |
static void mkpmapopts(char *mo); |
166 |
|
static void checkambfile(void); |
167 |
|
static double ambval(void); |
168 |
|
static void renderopts(char *op, char *po); |
259 |
|
printvars(stdout); |
260 |
|
/* build octree (and run mkillum) */ |
261 |
|
oconv(); |
262 |
+ |
/* run mkpmap if indicated */ |
263 |
+ |
mkpmap(); |
264 |
|
/* check date on ambient file */ |
265 |
|
checkambfile(); |
266 |
|
/* run simulation */ |
353 |
|
static void |
354 |
|
checkfiles(void) /* check for existence and modified times */ |
355 |
|
{ |
356 |
+ |
char fntemp[256]; |
357 |
|
time_t objdate; |
358 |
|
|
359 |
|
if (!vdef(OCTREE)) { |
383 |
|
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
384 |
|
quit(1); |
385 |
|
} |
386 |
+ |
if (vdef(PGMAP)) { |
387 |
+ |
if (!*sskip2(vval(PGMAP),1)) { |
388 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
389 |
+ |
progname, vnam(PGMAP)); |
390 |
+ |
quit(1); |
391 |
+ |
} |
392 |
+ |
atos(fntemp, sizeof(fntemp), vval(PGMAP)); |
393 |
+ |
pgmapname = savqstr(fntemp); |
394 |
+ |
pgmapdate = fdate(pgmapname); |
395 |
+ |
} |
396 |
+ |
if (vdef(PCMAP)) { |
397 |
+ |
if (!*sskip2(vval(PCMAP),1)) { |
398 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
399 |
+ |
progname, vnam(PCMAP)); |
400 |
+ |
quit(1); |
401 |
+ |
} |
402 |
+ |
atos(fntemp, sizeof(fntemp), vval(PCMAP)); |
403 |
+ |
pcmapname = savqstr(fntemp); |
404 |
+ |
pcmapdate = fdate(pcmapname); |
405 |
+ |
} |
406 |
|
matdate = checklast(vval(MATERIAL)); |
407 |
|
} |
408 |
|
|
624 |
|
} |
625 |
|
|
626 |
|
|
627 |
+ |
static void |
628 |
+ |
mkpmap(void) /* run mkpmap if indicated */ |
629 |
+ |
{ |
630 |
+ |
char combuf[2048], *cp; |
631 |
+ |
time_t tnow; |
632 |
+ |
/* nothing to do? */ |
633 |
+ |
if ((pgmapname == NULL) | (pgmapdate >= oct1date) && |
634 |
+ |
(pcmapname == NULL) | (pcmapdate >= oct1date)) |
635 |
+ |
return; |
636 |
+ |
/* just update existing file dates? */ |
637 |
+ |
if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) && |
638 |
+ |
(pcmapname == NULL) | (pcmapdate > 0)) { |
639 |
+ |
if (pgmapname != NULL) |
640 |
+ |
touch(pgmapname); |
641 |
+ |
if (pcmapname != NULL) |
642 |
+ |
touch(pcmapname); |
643 |
+ |
} else { /* else need to (re)run pkpmap */ |
644 |
+ |
strcpy(combuf, c_mkpmap); |
645 |
+ |
for (cp = combuf; *cp; cp++) |
646 |
+ |
; |
647 |
+ |
mkpmapopts(cp); |
648 |
+ |
/* force file overwrite */ |
649 |
+ |
cp = addarg(cp, "-fo+"); |
650 |
+ |
if (vdef(REPORT)) { |
651 |
+ |
char errfile[256]; |
652 |
+ |
int n; |
653 |
+ |
double minutes; |
654 |
+ |
n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile); |
655 |
+ |
if (n == 2) |
656 |
+ |
sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile); |
657 |
+ |
else if (n == 1) |
658 |
+ |
sprintf(cp, " -t %d", (int)(minutes*60)); |
659 |
+ |
else |
660 |
+ |
badvalue(REPORT); |
661 |
+ |
} |
662 |
+ |
if (pgmapname != NULL && pgmapdate < oct1date) { |
663 |
+ |
cp = addarg(cp, "-apg"); |
664 |
+ |
addarg(cp, vval(PGMAP)); |
665 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
666 |
+ |
*cp = '\0'; |
667 |
+ |
} |
668 |
+ |
if (pcmapname != NULL && pcmapdate < oct1date) { |
669 |
+ |
cp = addarg(cp, "-apc"); |
670 |
+ |
addarg(cp, vval(PCMAP)); |
671 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
672 |
+ |
*cp = '\0'; |
673 |
+ |
} |
674 |
+ |
cp = addarg(cp, oct1name); |
675 |
+ |
if (runcom(combuf)) { |
676 |
+ |
fprintf(stderr, "%s: error running %s\n", |
677 |
+ |
progname, c_mkpmap); |
678 |
+ |
if (pgmapname != NULL && pgmapdate < oct1date) |
679 |
+ |
unlink(pgmapname); |
680 |
+ |
if (pcmapname != NULL && pcmapdate < oct1date) |
681 |
+ |
unlink(pcmapname); |
682 |
+ |
quit(1); |
683 |
+ |
} |
684 |
+ |
} |
685 |
+ |
tnow = time((time_t *)NULL); |
686 |
+ |
if (pgmapname != NULL) |
687 |
+ |
pgmapdate = tnow; |
688 |
+ |
if (pcmapname != NULL) |
689 |
+ |
pcmapdate = tnow; |
690 |
+ |
oct1date = tnow; /* trigger ambient file removal if needed */ |
691 |
+ |
} |
692 |
+ |
|
693 |
+ |
|
694 |
|
static char * |
695 |
|
addarg( /* append argument and advance pointer */ |
696 |
|
char *op, |
714 |
|
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
715 |
|
|
716 |
|
*oo = '\0'; |
717 |
< |
if (vdef(OCONV)) |
718 |
< |
if (vval(OCONV)[0] != '-') { |
719 |
< |
atos(c_oconv, sizeof(c_oconv), vval(OCONV)); |
720 |
< |
oo = addarg(oo, sskip2(vval(OCONV), 1)); |
721 |
< |
} else |
722 |
< |
oo = addarg(oo, vval(OCONV)); |
717 |
> |
if (!vdef(OCONV)) |
718 |
> |
return; |
719 |
> |
if (vval(OCONV)[0] != '-') { |
720 |
> |
atos(c_oconv, sizeof(c_oconv), vval(OCONV)); |
721 |
> |
oo = addarg(oo, sskip2(vval(OCONV), 1)); |
722 |
> |
} else |
723 |
> |
oo = addarg(oo, vval(OCONV)); |
724 |
|
} |
725 |
|
|
726 |
|
|
735 |
|
sprintf(mo, " -n %d", nprocs); |
736 |
|
else |
737 |
|
*mo = '\0'; |
738 |
< |
if (vdef(MKILLUM)) |
739 |
< |
if (vval(MKILLUM)[0] != '-') { |
740 |
< |
atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); |
741 |
< |
mo = addarg(mo, sskip2(vval(MKILLUM), 1)); |
742 |
< |
} else |
743 |
< |
mo = addarg(mo, vval(MKILLUM)); |
738 |
> |
if (!vdef(MKILLUM)) |
739 |
> |
return; |
740 |
> |
if (vval(MKILLUM)[0] != '-') { |
741 |
> |
atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); |
742 |
> |
mo = addarg(mo, sskip2(vval(MKILLUM), 1)); |
743 |
> |
} else |
744 |
> |
mo = addarg(mo, vval(MKILLUM)); |
745 |
|
} |
746 |
|
|
747 |
|
|
748 |
|
static void |
749 |
+ |
mkpmapopts( /* get mkpmap options */ |
750 |
+ |
char *mo |
751 |
+ |
) |
752 |
+ |
{ |
753 |
+ |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
754 |
+ |
|
755 |
+ |
*mo = '\0'; |
756 |
+ |
if (!vdef(MKPMAP)) |
757 |
+ |
return; |
758 |
+ |
if (vval(MKPMAP)[0] != '-') { |
759 |
+ |
atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP)); |
760 |
+ |
mo = addarg(mo, sskip2(vval(MKPMAP), 1)); |
761 |
+ |
} else |
762 |
+ |
mo = addarg(mo, vval(MKPMAP)); |
763 |
+ |
} |
764 |
+ |
|
765 |
+ |
|
766 |
+ |
static void |
767 |
|
checkambfile(void) /* check date on ambient file */ |
768 |
|
{ |
769 |
|
time_t afdate; |
804 |
|
char *po |
805 |
|
) |
806 |
|
{ |
807 |
+ |
char pmapf[256], *bw; |
808 |
+ |
|
809 |
+ |
if (vdef(PGMAP)) { |
810 |
+ |
*op = '\0'; |
811 |
+ |
bw = sskip2(vval(PGMAP), 2); |
812 |
+ |
atos(pmapf, sizeof(pmapf), vval(PGMAP)); |
813 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
814 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
815 |
+ |
} |
816 |
|
switch(vscale(QUALITY)) { |
817 |
|
case LOW: |
818 |
|
lowqopts(op, po); |
824 |
|
hiqopts(op, po); |
825 |
|
break; |
826 |
|
} |
827 |
+ |
if (vdef(PCMAP)) { |
828 |
+ |
bw = sskip2(vval(PCMAP), 2); |
829 |
+ |
atos(pmapf, sizeof(pmapf), vval(PCMAP)); |
830 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
831 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
832 |
+ |
} |
833 |
|
if (vdef(RENDER)) |
834 |
|
op = addarg(op, vval(RENDER)); |
835 |
|
if (rvdevice != NULL) { |
836 |
< |
if (vdef(RVU)) |
836 |
> |
if (vdef(RVU)) { |
837 |
|
if (vval(RVU)[0] != '-') { |
838 |
|
atos(c_rvu, sizeof(c_rvu), vval(RVU)); |
839 |
|
po = addarg(po, sskip2(vval(RVU), 1)); |
840 |
|
} else |
841 |
|
po = addarg(po, vval(RVU)); |
842 |
+ |
} |
843 |
|
} else { |
844 |
< |
if (vdef(RPICT)) |
844 |
> |
if (vdef(RPICT)) { |
845 |
|
if (vval(RPICT)[0] != '-') { |
846 |
|
atos(c_rpict, sizeof(c_rpict), vval(RPICT)); |
847 |
|
po = addarg(po, sskip2(vval(RPICT), 1)); |
848 |
|
} else |
849 |
|
po = addarg(po, vval(RPICT)); |
850 |
+ |
} |
851 |
|
} |
852 |
|
} |
853 |
|
|
1074 |
|
} |
1075 |
|
|
1076 |
|
|
1077 |
< |
#ifdef _WIN32 |
1077 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1078 |
|
static void |
1079 |
|
setenv( /* set an environment variable */ |
1080 |
|
char *vname, |
1121 |
|
syserr(vval(OPTFILE)); |
1122 |
|
sprintf(ro, " @%s", vval(OPTFILE)); |
1123 |
|
} |
1124 |
< |
#ifdef _WIN32 |
1124 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1125 |
|
else if (n > 50) { |
1126 |
|
setenv("ROPT", ro+1); |
1127 |
|
strcpy(ro, " $ROPT"); |
1148 |
|
po = addarg(po, "-m .25"); |
1149 |
|
break; |
1150 |
|
} |
1151 |
< |
if (vdef(PFILT)) |
1151 |
> |
if (vdef(PFILT)) { |
1152 |
|
if (vval(PFILT)[0] != '-') { |
1153 |
|
atos(c_pfilt, sizeof(c_pfilt), vval(PFILT)); |
1154 |
|
po = addarg(po, sskip2(vval(PFILT), 1)); |
1155 |
|
} else |
1156 |
|
po = addarg(po, vval(PFILT)); |
1157 |
+ |
} |
1158 |
|
} |
1159 |
|
|
1160 |
|
|
1299 |
|
if (cp == viewopts) /* append any additional options */ |
1300 |
|
vs++; /* skip prefixed space if unneeded */ |
1301 |
|
strcpy(cp, vs); |
1302 |
< |
#ifdef _WIN32 |
1302 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1303 |
|
if (strlen(viewopts) > 40) { |
1304 |
|
setenv("VIEW", viewopts); |
1305 |
|
return("$VIEW"); |
1345 |
|
} |
1346 |
|
numview: |
1347 |
|
mv = nvalue(VIEWS, n); /* use view n */ |
1348 |
< |
if ((vn != NULL) & (mv != NULL)) |
1348 |
> |
if ((vn != NULL) & (mv != NULL)) { |
1349 |
|
if (*mv != '-') { |
1350 |
|
char *mv2 = mv; |
1351 |
|
while (*mv2 && !isspace(*mv2)) |
1353 |
|
*vn = '\0'; |
1354 |
|
} else |
1355 |
|
sprintf(vn, "%d", n+1); |
1356 |
< |
|
1356 |
> |
} |
1357 |
|
return(specview(mv)); |
1358 |
|
} |
1359 |
|
|
1367 |
|
VIEW vwr; |
1368 |
|
char buf[128]; |
1369 |
|
char *cp; |
1370 |
< |
#ifdef _WIN32 |
1370 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1371 |
|
/* XXX Should we allow something like this for all platforms? */ |
1372 |
|
/* XXX Or is it still required at all? */ |
1373 |
|
again: |
1374 |
|
#endif |
1375 |
|
if (vopts == NULL) |
1376 |
|
return(-1); |
1377 |
< |
#ifdef _WIN32 |
1377 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1378 |
|
if (vopts[0] == '$') { |
1379 |
|
vopts = getenv(vopts+1); |
1380 |
|
goto again; |
1521 |
|
fprintf(stderr, "%s: cannot create\n", pfile); |
1522 |
|
quit(1); |
1523 |
|
} |
1524 |
+ |
pfile[-5] = '\0'; |
1525 |
|
pfile = NULL; |
1526 |
|
} |
1527 |
|
} |