36 |
|
#define INDIRECT 5 /* indirection in lighting */ |
37 |
|
#define MATERIAL 6 /* material files */ |
38 |
|
#define MKILLUM 7 /* mkillum options */ |
39 |
< |
#define OBJECT 8 /* object files */ |
40 |
< |
#define OCONV 9 /* oconv options */ |
41 |
< |
#define OCTREE 10 /* octree file name */ |
42 |
< |
#define OPTFILE 11 /* rendering options file */ |
43 |
< |
#define PENUMBRAS 12 /* shadow penumbras are desired */ |
44 |
< |
#define PFILT 13 /* pfilt options */ |
45 |
< |
#define PICTURE 14 /* picture file root name */ |
46 |
< |
#define QUALITY 15 /* desired rendering quality */ |
47 |
< |
#define RAWFILE 16 /* raw picture file root name */ |
48 |
< |
#define RENDER 17 /* rendering options */ |
49 |
< |
#define REPORT 18 /* report frequency and errfile */ |
50 |
< |
#define RESOLUTION 19 /* maximum picture resolution */ |
51 |
< |
#define RPICT 20 /* rpict parameters */ |
52 |
< |
#define RVU 21 /* rvu parameters */ |
53 |
< |
#define SCENE 22 /* scene files */ |
54 |
< |
#define UP 23 /* view up (X, Y or Z) */ |
55 |
< |
#define VARIABILITY 24 /* level of light variability */ |
56 |
< |
#define VIEWS 25 /* view(s) for picture(s) */ |
57 |
< |
#define ZFILE 26 /* distance file root name */ |
58 |
< |
#define ZONE 27 /* simulation zone */ |
39 |
> |
#define MKPMAP 8 /* mkpmap options */ |
40 |
> |
#define OBJECT 9 /* object files */ |
41 |
> |
#define OCONV 10 /* oconv options */ |
42 |
> |
#define OCTREE 11 /* octree file name */ |
43 |
> |
#define OPTFILE 12 /* rendering options file */ |
44 |
> |
#define PCMAP 13 /* caustic photon map */ |
45 |
> |
#define PENUMBRAS 14 /* shadow penumbras are desired */ |
46 |
> |
#define PFILT 15 /* pfilt options */ |
47 |
> |
#define PGMAP 16 /* global photon map */ |
48 |
> |
#define PICTURE 17 /* picture file root name */ |
49 |
> |
#define QUALITY 18 /* desired rendering quality */ |
50 |
> |
#define RAWFILE 19 /* raw picture file root name */ |
51 |
> |
#define RENDER 20 /* rendering options */ |
52 |
> |
#define REPORT 21 /* report frequency and errfile */ |
53 |
> |
#define RESOLUTION 22 /* maximum picture resolution */ |
54 |
> |
#define RPICT 23 /* rpict parameters */ |
55 |
> |
#define RVU 24 /* rvu parameters */ |
56 |
> |
#define SCENE 25 /* scene files */ |
57 |
> |
#define UP 26 /* view up (X, Y or Z) */ |
58 |
> |
#define VARIABILITY 27 /* level of light variability */ |
59 |
> |
#define VIEWS 28 /* view(s) for picture(s) */ |
60 |
> |
#define ZFILE 29 /* distance file root name */ |
61 |
> |
#define ZONE 30 /* simulation zone */ |
62 |
|
/* total number of variables */ |
63 |
< |
int NVARS = 28; |
63 |
> |
int NVARS = 31; |
64 |
|
|
65 |
|
VARIABLE vv[] = { /* variable-value pairs */ |
66 |
|
{"AMBFILE", 3, 0, NULL, onevalue}, |
71 |
|
{"INDIRECT", 3, 0, NULL, intvalue}, |
72 |
|
{"materials", 3, 0, NULL, catvalues}, |
73 |
|
{"mkillum", 3, 0, NULL, catvalues}, |
74 |
+ |
{"mkpmap", 3, 0, NULL, catvalues}, |
75 |
|
{"objects", 3, 0, NULL, catvalues}, |
76 |
|
{"oconv", 3, 0, NULL, catvalues}, |
77 |
|
{"OCTREE", 3, 0, NULL, onevalue}, |
78 |
|
{"OPTFILE", 3, 0, NULL, onevalue}, |
79 |
+ |
{"PCMAP", 2, 0, NULL, onevalue}, |
80 |
|
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
81 |
|
{"pfilt", 2, 0, NULL, catvalues}, |
82 |
+ |
{"PGMAP", 2, 0, NULL, onevalue}, |
83 |
|
{"PICTURE", 3, 0, NULL, onevalue}, |
84 |
|
{"QUALITY", 3, 0, NULL, qualvalue}, |
85 |
|
{"RAWFILE", 3, 0, NULL, onevalue}, |
114 |
|
char *oct1name; /* name of post-mkillum octree */ |
115 |
|
time_t oct1date; /* date of post-mkillum octree (>= matdate) */ |
116 |
|
|
117 |
+ |
char *pgmapname; /* name of global photon map */ |
118 |
+ |
time_t pgmapdate; /* date of global photon map (>= oct1date) */ |
119 |
+ |
char *pcmapname; /* name of caustic photon map */ |
120 |
+ |
time_t pcmapdate; /* date of caustic photon map (>= oct1date) */ |
121 |
+ |
|
122 |
|
int nowarn = 0; /* no warnings */ |
123 |
|
int explicate = 0; /* explicate variables */ |
124 |
|
int silent = 0; /* do work silently */ |
133 |
|
/* command paths */ |
134 |
|
char c_oconv[256] = "oconv"; |
135 |
|
char c_mkillum[256] = "mkillum"; |
136 |
+ |
char c_mkpmap[256] = "mkpmap"; |
137 |
|
char c_rvu[256] = "rvu"; |
138 |
|
char c_rpict[256] = DEF_RPICT_PATH; |
139 |
|
char c_rpiece[] = "rpiece"; |
157 |
|
static void getoctcube(double org[3], double *sizp); |
158 |
|
static void setdefaults(void); |
159 |
|
static void oconv(void); |
160 |
+ |
static void mkpmap(void); |
161 |
|
static char * addarg(char *op, char *arg); |
162 |
|
static void oconvopts(char *oo); |
163 |
|
static void mkillumopts(char *mo); |
164 |
+ |
static void mkpmapopts(char *mo); |
165 |
|
static void checkambfile(void); |
166 |
|
static double ambval(void); |
167 |
|
static void renderopts(char *op, char *po); |
258 |
|
printvars(stdout); |
259 |
|
/* build octree (and run mkillum) */ |
260 |
|
oconv(); |
261 |
+ |
/* run mkpmap if indicated */ |
262 |
+ |
mkpmap(); |
263 |
|
/* check date on ambient file */ |
264 |
|
checkambfile(); |
265 |
|
/* run simulation */ |
352 |
|
static void |
353 |
|
checkfiles(void) /* check for existence and modified times */ |
354 |
|
{ |
355 |
+ |
char fntemp[256]; |
356 |
|
time_t objdate; |
357 |
|
|
358 |
|
if (!vdef(OCTREE)) { |
382 |
|
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
383 |
|
quit(1); |
384 |
|
} |
385 |
+ |
if (vdef(PGMAP)) { |
386 |
+ |
if (!*sskip2(vval(PGMAP),1)) { |
387 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
388 |
+ |
progname, vnam(PGMAP)); |
389 |
+ |
quit(1); |
390 |
+ |
} |
391 |
+ |
atos(fntemp, sizeof(fntemp), vval(PGMAP)); |
392 |
+ |
pgmapname = savqstr(fntemp); |
393 |
+ |
pgmapdate = fdate(pgmapname); |
394 |
+ |
} |
395 |
+ |
if (vdef(PCMAP)) { |
396 |
+ |
if (!*sskip2(vval(PCMAP),1)) { |
397 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
398 |
+ |
progname, vnam(PCMAP)); |
399 |
+ |
quit(1); |
400 |
+ |
} |
401 |
+ |
atos(fntemp, sizeof(fntemp), vval(PCMAP)); |
402 |
+ |
pcmapname = savqstr(fntemp); |
403 |
+ |
pcmapdate = fdate(pcmapname); |
404 |
+ |
if (pgmapname == NULL && !nowarn) |
405 |
+ |
fprintf(stderr, "%s: '%s' assigned without '%s'\n", |
406 |
+ |
progname, vnam(PCMAP), vnam(PGMAP)); |
407 |
+ |
} |
408 |
|
matdate = checklast(vval(MATERIAL)); |
409 |
|
} |
410 |
|
|
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
+ |
static void |
630 |
+ |
mkpmap(void) /* run mkpmap if indicated */ |
631 |
+ |
{ |
632 |
+ |
char combuf[2048], *cp; |
633 |
+ |
time_t tnow; |
634 |
+ |
/* nothing to do? */ |
635 |
+ |
if ((pgmapname == NULL) | (pgmapdate >= oct1date) && |
636 |
+ |
(pcmapname == NULL) | (pcmapdate >= oct1date)) |
637 |
+ |
return; |
638 |
+ |
/* just update existing file dates? */ |
639 |
+ |
if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) && |
640 |
+ |
(pcmapname == NULL) | (pcmapdate > 0)) { |
641 |
+ |
if (pgmapname != NULL) |
642 |
+ |
touch(pgmapname); |
643 |
+ |
if (pcmapname != NULL) |
644 |
+ |
touch(pcmapname); |
645 |
+ |
} else { /* else need to (re)run pkpmap */ |
646 |
+ |
strcpy(combuf, c_mkpmap); |
647 |
+ |
for (cp = combuf; *cp; cp++) |
648 |
+ |
; |
649 |
+ |
mkpmapopts(cp); |
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 (vdef(PGMAP)) { |
663 |
+ |
cp = addarg(cp, "-apg"); |
664 |
+ |
addarg(cp, vval(PGMAP)); |
665 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
666 |
+ |
*cp = '\0'; |
667 |
+ |
} |
668 |
+ |
if (vdef(PCMAP)) { |
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) |
679 |
+ |
unlink(pgmapname); |
680 |
+ |
if (pcmapname != NULL) |
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 |
|
switch(vscale(QUALITY)) { |
810 |
|
case LOW: |
811 |
|
lowqopts(op, po); |
816 |
|
case HIGH: |
817 |
|
hiqopts(op, po); |
818 |
|
break; |
819 |
+ |
} |
820 |
+ |
if (vdef(PGMAP)) { |
821 |
+ |
bw = sskip2(vval(PGMAP), 2); |
822 |
+ |
atos(pmapf, sizeof(pmapf), vval(PGMAP)); |
823 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
824 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
825 |
+ |
} |
826 |
+ |
if (vdef(PCMAP)) { |
827 |
+ |
bw = sskip2(vval(PCMAP), 2); |
828 |
+ |
atos(pmapf, sizeof(pmapf), vval(PCMAP)); |
829 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
830 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
831 |
|
} |
832 |
|
if (vdef(RENDER)) |
833 |
|
op = addarg(op, vval(RENDER)); |