--- ray/src/util/rad.c 2014/10/26 17:35:53 2.111 +++ ray/src/util/rad.c 2015/05/26 10:00:47 2.112 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rad.c,v 2.111 2014/10/26 17:35:53 greg Exp $"; +static const char RCSid[] = "$Id: rad.c,v 2.112 2015/05/26 10:00:47 greg Exp $"; #endif /* * Executive program for oconv, rpict and pfilt @@ -36,28 +36,31 @@ static const char RCSid[] = "$Id: rad.c,v 2.111 2014/1 #define INDIRECT 5 /* indirection in lighting */ #define MATERIAL 6 /* material files */ #define MKILLUM 7 /* mkillum options */ -#define OBJECT 8 /* object files */ -#define OCONV 9 /* oconv options */ -#define OCTREE 10 /* octree file name */ -#define OPTFILE 11 /* rendering options file */ -#define PENUMBRAS 12 /* shadow penumbras are desired */ -#define PFILT 13 /* pfilt options */ -#define PICTURE 14 /* picture file root name */ -#define QUALITY 15 /* desired rendering quality */ -#define RAWFILE 16 /* raw picture file root name */ -#define RENDER 17 /* rendering options */ -#define REPORT 18 /* report frequency and errfile */ -#define RESOLUTION 19 /* maximum picture resolution */ -#define RPICT 20 /* rpict parameters */ -#define RVU 21 /* rvu parameters */ -#define SCENE 22 /* scene files */ -#define UP 23 /* view up (X, Y or Z) */ -#define VARIABILITY 24 /* level of light variability */ -#define VIEWS 25 /* view(s) for picture(s) */ -#define ZFILE 26 /* distance file root name */ -#define ZONE 27 /* simulation zone */ +#define MKPMAP 8 /* mkpmap options */ +#define OBJECT 9 /* object files */ +#define OCONV 10 /* oconv options */ +#define OCTREE 11 /* octree file name */ +#define OPTFILE 12 /* rendering options file */ +#define PCMAP 13 /* caustic photon map */ +#define PENUMBRAS 14 /* shadow penumbras are desired */ +#define PFILT 15 /* pfilt options */ +#define PGMAP 16 /* global photon map */ +#define PICTURE 17 /* picture file root name */ +#define QUALITY 18 /* desired rendering quality */ +#define RAWFILE 19 /* raw picture file root name */ +#define RENDER 20 /* rendering options */ +#define REPORT 21 /* report frequency and errfile */ +#define RESOLUTION 22 /* maximum picture resolution */ +#define RPICT 23 /* rpict parameters */ +#define RVU 24 /* rvu parameters */ +#define SCENE 25 /* scene files */ +#define UP 26 /* view up (X, Y or Z) */ +#define VARIABILITY 27 /* level of light variability */ +#define VIEWS 28 /* view(s) for picture(s) */ +#define ZFILE 29 /* distance file root name */ +#define ZONE 30 /* simulation zone */ /* total number of variables */ -int NVARS = 28; +int NVARS = 31; VARIABLE vv[] = { /* variable-value pairs */ {"AMBFILE", 3, 0, NULL, onevalue}, @@ -68,12 +71,15 @@ VARIABLE vv[] = { /* variable-value pairs */ {"INDIRECT", 3, 0, NULL, intvalue}, {"materials", 3, 0, NULL, catvalues}, {"mkillum", 3, 0, NULL, catvalues}, + {"mkpmap", 3, 0, NULL, catvalues}, {"objects", 3, 0, NULL, catvalues}, {"oconv", 3, 0, NULL, catvalues}, {"OCTREE", 3, 0, NULL, onevalue}, {"OPTFILE", 3, 0, NULL, onevalue}, + {"PCMAP", 2, 0, NULL, onevalue}, {"PENUMBRAS", 3, 0, NULL, boolvalue}, {"pfilt", 2, 0, NULL, catvalues}, + {"PGMAP", 2, 0, NULL, onevalue}, {"PICTURE", 3, 0, NULL, onevalue}, {"QUALITY", 3, 0, NULL, qualvalue}, {"RAWFILE", 3, 0, NULL, onevalue}, @@ -108,6 +114,11 @@ time_t oct0date; /* date of pre-mkillum octree */ char *oct1name; /* name of post-mkillum octree */ time_t oct1date; /* date of post-mkillum octree (>= matdate) */ +char *pgmapname; /* name of global photon map */ +time_t pgmapdate; /* date of global photon map (>= oct1date) */ +char *pcmapname; /* name of caustic photon map */ +time_t pcmapdate; /* date of caustic photon map (>= oct1date) */ + int nowarn = 0; /* no warnings */ int explicate = 0; /* explicate variables */ int silent = 0; /* do work silently */ @@ -122,6 +133,7 @@ char *viewselect = NULL; /* specific view only */ /* command paths */ char c_oconv[256] = "oconv"; char c_mkillum[256] = "mkillum"; +char c_mkpmap[256] = "mkpmap"; char c_rvu[256] = "rvu"; char c_rpict[256] = DEF_RPICT_PATH; char c_rpiece[] = "rpiece"; @@ -145,9 +157,11 @@ static void checkfiles(void); static void getoctcube(double org[3], double *sizp); static void setdefaults(void); static void oconv(void); +static void mkpmap(void); static char * addarg(char *op, char *arg); static void oconvopts(char *oo); static void mkillumopts(char *mo); +static void mkpmapopts(char *mo); static void checkambfile(void); static double ambval(void); static void renderopts(char *op, char *po); @@ -244,6 +258,8 @@ main( printvars(stdout); /* build octree (and run mkillum) */ oconv(); + /* run mkpmap if indicated */ + mkpmap(); /* check date on ambient file */ checkambfile(); /* run simulation */ @@ -336,6 +352,7 @@ newfname( /* create modified file name */ static void checkfiles(void) /* check for existence and modified times */ { + char fntemp[256]; time_t objdate; if (!vdef(OCTREE)) { @@ -365,6 +382,29 @@ checkfiles(void) /* check for existence and modified vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); quit(1); } + if (vdef(PGMAP)) { + if (!*sskip2(vval(PGMAP),1)) { + fprintf(stderr, "%s: '%s' missing # photons argument\n", + progname, vnam(PGMAP)); + quit(1); + } + atos(fntemp, sizeof(fntemp), vval(PGMAP)); + pgmapname = savqstr(fntemp); + pgmapdate = fdate(pgmapname); + } + if (vdef(PCMAP)) { + if (!*sskip2(vval(PCMAP),1)) { + fprintf(stderr, "%s: '%s' missing # photons argument\n", + progname, vnam(PCMAP)); + quit(1); + } + atos(fntemp, sizeof(fntemp), vval(PCMAP)); + pcmapname = savqstr(fntemp); + pcmapdate = fdate(pcmapname); + if (pgmapname == NULL && !nowarn) + fprintf(stderr, "%s: '%s' assigned without '%s'\n", + progname, vnam(PCMAP), vnam(PGMAP)); + } matdate = checklast(vval(MATERIAL)); } @@ -586,6 +626,71 @@ oconv(void) /* run oconv and mkillum if necessary * } +static void +mkpmap(void) /* run mkpmap if indicated */ +{ + char combuf[2048], *cp; + time_t tnow; + /* nothing to do? */ + if ((pgmapname == NULL) | (pgmapdate >= oct1date) && + (pcmapname == NULL) | (pcmapdate >= oct1date)) + return; + /* just update existing file dates? */ + if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) && + (pcmapname == NULL) | (pcmapdate > 0)) { + if (pgmapname != NULL) + touch(pgmapname); + if (pcmapname != NULL) + touch(pcmapname); + } else { /* else need to (re)run pkpmap */ + strcpy(combuf, c_mkpmap); + for (cp = combuf; *cp; cp++) + ; + mkpmapopts(cp); + if (vdef(REPORT)) { + char errfile[256]; + int n; + double minutes; + n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile); + if (n == 2) + sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile); + else if (n == 1) + sprintf(cp, " -t %d", (int)(minutes*60)); + else + badvalue(REPORT); + } + if (vdef(PGMAP)) { + cp = addarg(cp, "-apg"); + addarg(cp, vval(PGMAP)); + cp = sskip(sskip(cp)); /* remove any bandwidth */ + *cp = '\0'; + } + if (vdef(PCMAP)) { + cp = addarg(cp, "-apc"); + addarg(cp, vval(PCMAP)); + cp = sskip(sskip(cp)); /* remove any bandwidth */ + *cp = '\0'; + } + cp = addarg(cp, oct1name); + if (runcom(combuf)) { + fprintf(stderr, "%s: error running %s\n", + progname, c_mkpmap); + if (pgmapname != NULL) + unlink(pgmapname); + if (pcmapname != NULL) + unlink(pcmapname); + quit(1); + } + } + tnow = time((time_t *)NULL); + if (pgmapname != NULL) + pgmapdate = tnow; + if (pcmapname != NULL) + pcmapdate = tnow; + oct1date = tnow; /* trigger ambient file removal if needed */ +} + + static char * addarg( /* append argument and advance pointer */ char *op, @@ -609,12 +714,13 @@ oconvopts( /* get oconv options */ /* BEWARE: This may be called via setdefaults(), so no assumptions */ *oo = '\0'; - if (vdef(OCONV)) - if (vval(OCONV)[0] != '-') { - atos(c_oconv, sizeof(c_oconv), vval(OCONV)); - oo = addarg(oo, sskip2(vval(OCONV), 1)); - } else - oo = addarg(oo, vval(OCONV)); + if (!vdef(OCONV)) + return; + if (vval(OCONV)[0] != '-') { + atos(c_oconv, sizeof(c_oconv), vval(OCONV)); + oo = addarg(oo, sskip2(vval(OCONV), 1)); + } else + oo = addarg(oo, vval(OCONV)); } @@ -629,16 +735,35 @@ mkillumopts( /* get mkillum options */ sprintf(mo, " -n %d", nprocs); else *mo = '\0'; - if (vdef(MKILLUM)) - if (vval(MKILLUM)[0] != '-') { - atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); - mo = addarg(mo, sskip2(vval(MKILLUM), 1)); - } else - mo = addarg(mo, vval(MKILLUM)); + if (!vdef(MKILLUM)) + return; + if (vval(MKILLUM)[0] != '-') { + atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); + mo = addarg(mo, sskip2(vval(MKILLUM), 1)); + } else + mo = addarg(mo, vval(MKILLUM)); } static void +mkpmapopts( /* get mkpmap options */ + char *mo +) +{ + /* BEWARE: This may be called via setdefaults(), so no assumptions */ + + *mo = '\0'; + if (!vdef(MKPMAP)) + return; + if (vval(MKPMAP)[0] != '-') { + atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP)); + mo = addarg(mo, sskip2(vval(MKPMAP), 1)); + } else + mo = addarg(mo, vval(MKPMAP)); +} + + +static void checkambfile(void) /* check date on ambient file */ { time_t afdate; @@ -679,6 +804,8 @@ renderopts( /* set rendering options */ char *po ) { + char pmapf[256], *bw; + switch(vscale(QUALITY)) { case LOW: lowqopts(op, po); @@ -689,6 +816,18 @@ renderopts( /* set rendering options */ case HIGH: hiqopts(op, po); break; + } + if (vdef(PGMAP)) { + bw = sskip2(vval(PGMAP), 2); + atos(pmapf, sizeof(pmapf), vval(PGMAP)); + op = addarg(addarg(op, "-ap"), pmapf); + if (atoi(bw) > 0) op = addarg(op, bw); + } + if (vdef(PCMAP)) { + bw = sskip2(vval(PCMAP), 2); + atos(pmapf, sizeof(pmapf), vval(PCMAP)); + op = addarg(addarg(op, "-ap"), pmapf); + if (atoi(bw) > 0) op = addarg(op, bw); } if (vdef(RENDER)) op = addarg(op, vval(RENDER));