--- ray/src/util/rad.c 1993/09/24 16:49:02 2.26 +++ ray/src/util/rad.c 1997/03/20 12:50:07 2.53 @@ -1,4 +1,4 @@ -/* Copyright (c) 1993 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,19 +10,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" #include "paths.h" +#include "vars.h" #include +#include - -typedef struct { - char *name; /* variable name */ - short nick; /* # characters required for nickname */ - short nass; /* # assignments made */ - char *value; /* assigned value(s) */ - int (*fixval)(); /* assignment checking function */ -} VARIABLE; - -int onevalue(), catvalues(); - /* variables */ #define OBJECT 0 /* object files */ #define SCENE 1 /* scene files */ @@ -36,7 +27,7 @@ int onevalue(), catvalues(); #define ZONE 9 /* simulation zone */ #define QUALITY 10 /* desired rendering quality */ #define OCTREE 11 /* octree file name */ -#define PICTURE 12 /* picture file name */ +#define PICTURE 12 /* picture file root name */ #define AMBFILE 13 /* ambient file name */ #define OPTFILE 14 /* rendering options file */ #define EXPOSURE 15 /* picture exposure setting */ @@ -47,10 +38,12 @@ int onevalue(), catvalues(); #define PENUMBRAS 20 /* shadow penumbras are desired */ #define VARIABILITY 21 /* level of light variability */ #define REPORT 22 /* report frequency and errfile */ +#define RAWFILE 23 /* raw picture file root name */ +#define ZFILE 24 /* distance file root name */ /* total number of variables */ -#define NVARS 23 +int NVARS = 25; -VARIABLE vv[NVARS] = { /* variable-value pairs */ +VARIABLE vv[] = { /* variable-value pairs */ {"objects", 3, 0, NULL, catvalues}, {"scene", 3, 0, NULL, catvalues}, {"materials", 3, 0, NULL, catvalues}, @@ -61,64 +54,46 @@ VARIABLE vv[NVARS] = { /* variable-value pairs */ {"pfilt", 2, 0, NULL, catvalues}, {"view", 2, 0, NULL, NULL}, {"ZONE", 2, 0, NULL, onevalue}, - {"QUALITY", 3, 0, NULL, onevalue}, + {"QUALITY", 3, 0, NULL, qualvalue}, {"OCTREE", 3, 0, NULL, onevalue}, {"PICTURE", 3, 0, NULL, onevalue}, {"AMBFILE", 3, 0, NULL, onevalue}, {"OPTFILE", 3, 0, NULL, onevalue}, - {"EXPOSURE", 3, 0, NULL, onevalue}, + {"EXPOSURE", 3, 0, NULL, fltvalue}, {"RESOLUTION", 3, 0, NULL, onevalue}, {"UP", 2, 0, NULL, onevalue}, - {"INDIRECT", 3, 0, NULL, onevalue}, - {"DETAIL", 3, 0, NULL, onevalue}, - {"PENUMBRAS", 3, 0, NULL, onevalue}, - {"VARIABILITY", 3, 0, NULL, onevalue}, + {"INDIRECT", 3, 0, NULL, intvalue}, + {"DETAIL", 3, 0, NULL, qualvalue}, + {"PENUMBRAS", 3, 0, NULL, boolvalue}, + {"VARIABILITY", 3, 0, NULL, qualvalue}, {"REPORT", 3, 0, NULL, onevalue}, + {"RAWFILE", 3, 0, NULL, onevalue}, + {"ZFILE", 2, 0, NULL, onevalue}, }; -VARIABLE *matchvar(); -char *nvalue(); -int vscale(); - -#define UPPER(c) ((c)&~0x20) /* ASCII trick */ - -#define vnam(vc) (vv[vc].name) -#define vdef(vc) (vv[vc].nass) -#define vval(vc) (vv[vc].value) -#define vint(vc) atoi(vval(vc)) -#define vlet(vc) UPPER(vval(vc)[0]) -#define vbool(vc) (vlet(vc)=='T') - -#define HIGH 2 -#define MEDIUM 1 -#define LOW 0 - -int lowqopts(), medqopts(), hiqopts(); -int (*setqopts[3])() = {lowqopts, medqopts, hiqopts}; - -#define renderopts (*setqopts[vscale(QUALITY)]) - /* overture calculation file */ #ifdef NIX -char overfile[] = "overture.raw"; +char overfile[] = "overture.unf"; #else char overfile[] = "/dev/null"; #endif -extern unsigned long fdate(), time(); +extern time_t fdate(), time(); -unsigned long scenedate; /* date of latest scene or object file */ -unsigned long octreedate; /* date of octree */ -unsigned long matdate; /* date of latest material file */ -unsigned long illumdate; /* date of last illum file */ +time_t scenedate; /* date of latest scene or object file */ +time_t octreedate; /* date of octree */ +time_t matdate; /* date of latest material file */ +time_t illumdate; /* date of last illum file */ char *oct0name; /* name of pre-mkillum octree */ -unsigned long oct0date; /* date of pre-mkillum octree */ +time_t oct0date; /* date of pre-mkillum octree */ char *oct1name; /* name of post-mkillum octree */ -unsigned long oct1date; /* date of post-mkillum octree (>= matdate) */ +time_t oct1date; /* date of post-mkillum octree (>= matdate) */ +int nowarn = 0; /* no warnings */ int explicate = 0; /* explicate variables */ int silent = 0; /* do work silently */ +int touchonly = 0; /* touch files only */ int noaction = 0; /* don't do anything */ int sayview = 0; /* print view out */ char *rvdevice = NULL; /* rview output device */ @@ -137,6 +112,7 @@ int argc; char *argv[]; { char ropts[512]; + char popts[64]; int i; progname = argv[0]; @@ -149,6 +125,9 @@ char *argv[]; case 'n': noaction++; break; + case 't': + touchonly++; + break; case 'e': explicate++; break; @@ -161,6 +140,9 @@ char *argv[]; case 'v': viewselect = argv[++i]; break; + case 'w': + nowarn++; + break; default: goto userr; } @@ -170,10 +152,14 @@ char *argv[]; /* assign Radiance root file name */ rootname(radname, rifname); /* load variable values */ - load(rifname); + loadvars(rifname); /* get any additional assignments */ for (i++; i < argc; i++) - setvariable(argv[i]); + if (setvariable(argv[i], matchvar) < 0) { + fprintf(stderr, "%s: unknown variable: %s\n", + progname, argv[i]); + quit(1); + } /* check assignments */ checkvalues(); /* check files and dates */ @@ -182,24 +168,24 @@ char *argv[]; setdefaults(); /* print all values if requested */ if (explicate) - printvals(); + printvars(stdout); /* build octree (and run mkillum) */ oconv(); /* check date on ambient file */ checkambfile(); /* run simulation */ - renderopts(ropts); + renderopts(ropts, popts); xferopts(ropts); if (rvdevice != NULL) - rview(ropts); + rview(ropts, popts); else - rpict(ropts); - exit(0); + rpict(ropts, popts); + quit(0); userr: fprintf(stderr, - "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", +"Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", progname); - exit(1); + quit(1); } @@ -218,196 +204,12 @@ register char *rn, *fn; } -#define NOCHAR 127 /* constant for character to delete */ - - -load(rfname) /* load Radiance simulation file */ -char *rfname; -{ - FILE *fp; - char buf[512]; - register char *cp; - - if (rfname == NULL) - fp = stdin; - else if ((fp = fopen(rfname, "r")) == NULL) - syserr(rfname); - while (fgetline(buf, sizeof(buf), fp) != NULL) { - for (cp = buf; *cp; cp++) { - switch (*cp) { - case '\\': - *cp++ = NOCHAR; - continue; - case '#': - *cp = '\0'; - break; - default: - continue; - } - break; - } - setvariable(buf); - } - fclose(fp); -} - - -setvariable(ass) /* assign variable according to string */ -register char *ass; -{ - char varname[32]; - char varval[512]; - int n; - register char *cp; - register VARIABLE *vp; - register int i; - - while (isspace(*ass)) /* skip leading space */ - ass++; - cp = varname; /* extract name */ - while (cp < varname+sizeof(varname)-1 - && *ass && !isspace(*ass) && *ass != '=') - *cp++ = *ass++; - *cp = '\0'; - if (!varname[0]) - return; /* no variable name! */ - /* trim value */ - while (isspace(*ass) || *ass == '=') - ass++; - for (n = strlen(ass); n > 0; n--) - if (!isspace(ass[n-1])) - break; - if (!n) { - fprintf(stderr, "%s: warning - missing value for variable '%s'\n", - progname, varname); - return; - } - /* match variable from list */ - vp = matchvar(varname); - if (vp == NULL) { - fprintf(stderr, "%s: unknown variable '%s'\n", - progname, varname); - exit(1); - } - /* assign new value */ - if (i = vp->nass) { - cp = vp->value; - while (i--) - while (*cp++) - ; - i = cp - vp->value; - vp->value = realloc(vp->value, i+n+1); - } else - vp->value = malloc(n+1); - if (vp->value == NULL) - syserr(progname); - cp = vp->value+i; /* copy value, squeezing spaces */ - *cp = *ass; - for (i = 1; i <= n; i++) { - if (ass[i] == NOCHAR) - continue; - if (isspace(*cp)) - while (isspace(ass[i])) - i++; - *++cp = ass[i]; - } - if (isspace(*cp)) /* remove trailing space */ - *cp = '\0'; - vp->nass++; -} - - -VARIABLE * -matchvar(nam) /* match a variable by its name */ -char *nam; -{ - int n = strlen(nam); - register int i; - - for (i = 0; i < NVARS; i++) - if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) - return(vv+i); - return(NULL); -} - - -char * -nvalue(vp, n) /* return nth variable value */ -VARIABLE *vp; -register int n; -{ - register char *cp; - - if (vp == NULL | n < 0 | n >= vp->nass) - return(NULL); - cp = vp->value; - while (n--) - while (*cp++) - ; - return(cp); -} - - -int -vscale(vc) /* return scale for variable vc */ -int vc; -{ - switch(vlet(vc)) { - case 'H': - return(HIGH); - case 'M': - return(MEDIUM); - case 'L': - return(LOW); - } - badvalue(vc); -} - - -checkvalues() /* check assignments */ -{ - register int i; - - for (i = 0; i < NVARS; i++) - if (vv[i].fixval != NULL) - (*vv[i].fixval)(vv+i); -} - - -onevalue(vp) /* only one assignment for this variable */ -register VARIABLE *vp; -{ - if (vp->nass < 2) - return; - fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n", - progname, vp->name); - do - vp->value += strlen(vp->value)+1; - while (--vp->nass > 1); -} - - -catvalues(vp) /* concatenate variable values */ -register VARIABLE *vp; -{ - register char *cp; - - if (vp->nass < 2) - return; - for (cp = vp->value; vp->nass > 1; vp->nass--) { - while (*cp) - cp++; - *cp++ = ' '; - } -} - - -unsigned long +time_t checklast(fnames) /* check files and find most recent */ register char *fnames; { char thisfile[MAXPATH]; - unsigned long thisdate, lastdate = 0; + time_t thisdate, lastdate = 0; register char *cp; if (fnames == NULL) @@ -437,9 +239,13 @@ int pred; register int n; int suffix; - suffix = n = strlen(orig); /* find start of suffix */ - if ((cp = rindex(orig, '.')) != NULL) - suffix = cp - orig; + n = 0; cp = orig; suffix = -1; /* suffix position, length */ + while (*cp) { + if (*cp == '.') suffix = n; + else if (ISDIRSEP(*cp)) suffix = -1; + cp++; n++; + } + if (suffix == -1) suffix = n; if ((cp = bmalloc(n+2)) == NULL) syserr(progname); strncpy(cp, orig, suffix); @@ -451,7 +257,7 @@ int pred; checkfiles() /* check for existence and modified times */ { - unsigned long objdate; + time_t objdate; if (!vdef(OCTREE)) { if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL) @@ -474,7 +280,7 @@ checkfiles() /* check for existence and modified tim if (!octreedate & !scenedate & !illumdate) { fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); - exit(1); + quit(1); } matdate = checklast(vval(MATERIAL)); } @@ -486,7 +292,7 @@ double org[3], *sizp; extern FILE *popen(); static double oorg[3], osiz = 0.; double min[3], max[3]; - char buf[512]; + char buf[1024]; FILE *fp; register int i; @@ -504,7 +310,7 @@ double org[3], *sizp; fprintf(stderr, "%s: error reading bounding box from getbbox\n", progname); - exit(1); + quit(1); } for (i = 0; i < 3; i++) if (max[i] - min[i] > osiz) @@ -522,7 +328,7 @@ double org[3], *sizp; fprintf(stderr, "%s: error reading bounding cube from getinfo\n", progname); - exit(1); + quit(1); } pclose(fp); } @@ -577,40 +383,35 @@ setdefaults() /* set default values for unassigned v } -printvals() /* print variable values */ -{ - register int i, j; - - for (i = 0; i < NVARS; i++) - for (j = 0; j < vdef(i); j++) - printf("%s= %s\n", vnam(i), nvalue(vv+i, j)); - fflush(stdout); -} - - oconv() /* run oconv and mkillum if necessary */ { static char illumtmp[] = "ilXXXXXX"; - char combuf[512], ocopts[64], mkopts[64]; + char combuf[1024], ocopts[64], mkopts[64]; oconvopts(ocopts); /* get options */ if (octreedate < scenedate) { /* check date on original octree */ - /* build command */ - if (vdef(MATERIAL)) - sprintf(combuf, "oconv%s %s %s > %s", ocopts, - vval(MATERIAL), vval(SCENE), vval(OCTREE)); - else - sprintf(combuf, "oconv%s %s > %s", ocopts, - vval(SCENE), vval(OCTREE)); - - if (runcom(combuf)) { /* run it */ - fprintf(stderr, + if (touchonly && octreedate) + touch(vval(OCTREE)); + else { /* build command */ + if (vdef(MATERIAL)) + sprintf(combuf, "oconv%s %s %s > %s", ocopts, + vval(MATERIAL), vval(SCENE), + vval(OCTREE)); + else + sprintf(combuf, "oconv%s %s > %s", ocopts, + vval(SCENE), vval(OCTREE)); + + if (runcom(combuf)) { /* run it */ + fprintf(stderr, "%s: error generating octree\n\t%s removed\n", - progname, vval(OCTREE)); - unlink(vval(OCTREE)); - exit(1); + progname, vval(OCTREE)); + unlink(vval(OCTREE)); + quit(1); + } } - octreedate = time(0); + octreedate = time((time_t *)NULL); + if (octreedate < scenedate) /* in case clock is off */ + octreedate = scenedate; } if (oct1name == vval(OCTREE)) /* no mkillum? */ oct1date = octreedate > matdate ? octreedate : matdate; @@ -619,53 +420,68 @@ oconv() /* run oconv and mkillum if necessary */ return; /* make octree0 */ if (oct0date < scenedate | oct0date < illumdate) { - /* build command */ + if (touchonly && oct0date) + touch(oct0name); + else { /* build command */ + if (octreedate) + sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, + vval(OCTREE), vval(ILLUM), oct0name); + else if (vdef(MATERIAL)) + sprintf(combuf, "oconv%s %s %s > %s", ocopts, + vval(MATERIAL), vval(ILLUM), oct0name); + else + sprintf(combuf, "oconv%s %s > %s", ocopts, + vval(ILLUM), oct0name); + if (runcom(combuf)) { /* run it */ + fprintf(stderr, + "%s: error generating octree\n\t%s removed\n", + progname, oct0name); + unlink(oct0name); + quit(1); + } + } + oct0date = time((time_t *)NULL); + if (oct0date < octreedate) /* in case clock is off */ + oct0date = octreedate; + if (oct0date < illumdate) /* ditto */ + oct0date = illumdate; + } + if (touchonly && oct1date) + touch(oct1name); + else { + mkillumopts(mkopts); /* build mkillum command */ + mktemp(illumtmp); + sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, + oct0name, vval(ILLUM), illumtmp); + if (runcom(combuf)) { /* run it */ + fprintf(stderr, "%s: error running mkillum\n", + progname); + unlink(illumtmp); + quit(1); + } + /* make octree1 (frozen) */ if (octreedate) - sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, - vval(OCTREE), vval(ILLUM), oct0name); + sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, + vval(OCTREE), illumtmp, oct1name); else if (vdef(MATERIAL)) - sprintf(combuf, "oconv%s %s %s > %s", ocopts, - vval(MATERIAL), vval(ILLUM), oct0name); + sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, + vval(MATERIAL), illumtmp, oct1name); else - sprintf(combuf, "oconv%s %s > %s", ocopts, - vval(ILLUM), oct0name); + sprintf(combuf, "oconv%s -f %s > %s", ocopts, + illumtmp, oct1name); if (runcom(combuf)) { /* run it */ fprintf(stderr, "%s: error generating octree\n\t%s removed\n", - progname, oct0name); - unlink(oct0name); - exit(1); + progname, oct1name); + unlink(oct1name); + unlink(illumtmp); + quit(1); } - oct0date = time(0); + rmfile(illumtmp); } - mkillumopts(mkopts); /* build mkillum command */ - mktemp(illumtmp); - sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, - oct0name, vval(ILLUM), illumtmp); - if (runcom(combuf)) { /* run it */ - fprintf(stderr, "%s: error running mkillum\n", progname); - unlink(illumtmp); - exit(1); - } - /* make octree1 (frozen) */ - if (octreedate) - sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, - vval(OCTREE), illumtmp, oct1name); - else if (vdef(MATERIAL)) - sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, - vval(MATERIAL), illumtmp, oct1name); - else - sprintf(combuf, "oconv%s -f %s > %s", ocopts, - illumtmp, oct1name); - if (runcom(combuf)) { /* run it */ - fprintf(stderr, - "%s: error generating octree\n\t%s removed\n", - progname, oct1name); - unlink(oct1name); - exit(1); - } - oct1date = time(0); - rmfile(illumtmp); + oct1date = time((time_t *)NULL); + if (oct1date < oct0date) /* in case clock is off */ + oct1date = oct0date; } @@ -704,14 +520,17 @@ register char *mo; checkambfile() /* check date on ambient file */ { - unsigned long afdate; + time_t afdate; if (!vdef(AMBFILE)) return; if (!(afdate = fdate(vval(AMBFILE)))) return; if (oct1date > afdate) - rmfile(vval(AMBFILE)); + if (touchonly) + touch(vval(AMBFILE)); + else + rmfile(vval(AMBFILE)); } @@ -719,11 +538,9 @@ double ambval() /* compute ambient value */ { if (vdef(EXPOSURE)) { - if (!isflt(vval(EXPOSURE))) - badvalue(EXPOSURE); if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') - return(.5/pow(2.,atof(vval(EXPOSURE)))); - return(.5/atof(vval(EXPOSURE))); + return(.5/pow(2.,vflt(EXPOSURE))); + return(.5/vflt(EXPOSURE)); } if (vlet(ZONE) == 'E') return(10.); @@ -733,36 +550,60 @@ ambval() /* compute ambient value */ } -lowqopts(op) /* low quality rendering options */ +renderopts(op, po) /* set rendering options */ +char *op, *po; +{ + switch(vscale(QUALITY)) { + case LOW: + lowqopts(op, po); + break; + case MEDIUM: + medqopts(op, po); + break; + case HIGH: + hiqopts(op, po); + break; + } +} + + +lowqopts(op, po) /* low quality rendering options */ register char *op; +char *po; { double d, org[3], siz[3]; *op = '\0'; + *po = '\0'; if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) badvalue(ZONE); siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; + if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) + badvalue(ZONE); getoctcube(org, &d); d *= 3./(siz[0]+siz[1]+siz[2]); switch (vscale(DETAIL)) { case LOW: - op = addarg(op, "-ps 16 -dp 64"); + po = addarg(po, "-ps 16"); + op = addarg(op, "-dp 64"); sprintf(op, " -ar %d", (int)(4*d)); op += strlen(op); break; case MEDIUM: - op = addarg(op, "-ps 8 -dp 128"); + po = addarg(po, "-ps 8"); + op = addarg(op, "-dp 128"); sprintf(op, " -ar %d", (int)(8*d)); op += strlen(op); break; case HIGH: - op = addarg(op, "-ps 4 -dp 256"); + po = addarg(po, "-ps 4"); + op = addarg(op, "-dp 256"); sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); break; } - op = addarg(op, "-pt .16"); + po = addarg(po, "-pt .16"); if (vbool(PENUMBRAS)) op = addarg(op, "-ds .4"); else @@ -775,10 +616,10 @@ register char *op; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aa .4 -ad 64"); + op = addarg(op, "-aw 128 -aa .4 -ad 64"); break; case MEDIUM: - op = addarg(op, "-aa .3 -ad 128"); + op = addarg(op, "-aw 1024 -aa .3 -ad 128"); break; case HIGH: op = addarg(op, "-aa .25 -ad 256"); @@ -794,41 +635,52 @@ register char *op; } -medqopts(op) /* medium quality rendering options */ +medqopts(op, po) /* medium quality rendering options */ register char *op; +char *po; { - double d, org[3], siz[3]; + double d, org[3], siz[3], asz; *op = '\0'; + *po = '\0'; if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) badvalue(ZONE); siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; + if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) + badvalue(ZONE); getoctcube(org, &d); - d *= 3./(siz[0]+siz[1]+siz[2]); + asz = (siz[0]+siz[1]+siz[2])/3.; + d /= asz; switch (vscale(DETAIL)) { case LOW: - op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); + po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); op = addarg(op, "-dp 256"); sprintf(op, " -ar %d", (int)(8*d)); op += strlen(op); + sprintf(op, " -ms %.2g", asz/20.); + op += strlen(op); break; case MEDIUM: - op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); + po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); op = addarg(op, "-dp 512"); sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); + sprintf(op, " -ms %.2g", asz/40.); + op += strlen(op); break; case HIGH: - op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); + po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); op = addarg(op, "-dp 1024"); sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); + sprintf(op, " -ms %.2g", asz/80.); + op += strlen(op); break; } - op = addarg(op, "-pt .08"); + po = addarg(po, "-pt .08"); if (vbool(PENUMBRAS)) - op = addarg(op, "-ds .2 -dj .35"); + op = addarg(op, "-ds .2 -dj .5"); else op = addarg(op, "-ds .3"); op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); @@ -843,10 +695,10 @@ register char *op; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aa .25 -ad 196 -as 0"); + op = addarg(op, "-aw 128 -aa .25 -ad 196 -as 0"); break; case MEDIUM: - op = addarg(op, "-aa .2 -ad 400 -as 64"); + op = addarg(op, "-aw 1024 -aa .2 -ad 400 -as 64"); break; case HIGH: op = addarg(op, "-aa .15 -ad 768 -as 196"); @@ -861,41 +713,52 @@ register char *op; } -hiqopts(op) /* high quality rendering options */ +hiqopts(op, po) /* high quality rendering options */ register char *op; +char *po; { - double d, org[3], siz[3]; + double d, org[3], siz[3], asz; *op = '\0'; + *po = '\0'; if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) badvalue(ZONE); siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; + if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) + badvalue(ZONE); getoctcube(org, &d); - d *= 3./(siz[0]+siz[1]+siz[2]); + asz = (siz[0]+siz[1]+siz[2])/3.; + d /= asz; switch (vscale(DETAIL)) { case LOW: - op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); + po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); op = addarg(op, "-dp 1024"); sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); + sprintf(op, " -ms %.2g", asz/40.); + op += strlen(op); break; case MEDIUM: - op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); + po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); op = addarg(op, "-dp 2048"); sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); + sprintf(op, " -ms %.2g", asz/80.); + op += strlen(op); break; case HIGH: - op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); + po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); op = addarg(op, "-dp 4096"); sprintf(op, " -ar %d", (int)(64*d)); op += strlen(op); + sprintf(op, " -ms %.2g", asz/160.); + op += strlen(op); break; } - op = addarg(op, "-pt .04"); + po = addarg(po, "-pt .04"); if (vbool(PENUMBRAS)) - op = addarg(op, "-ds .1 -dj .7"); + op = addarg(op, "-ds .1 -dj .65"); else op = addarg(op, "-ds .2"); op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); @@ -908,10 +771,10 @@ register char *op; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aa .15 -ad 256 -as 0"); + op = addarg(op, "-aw 128 -aa .15 -ad 256 -as 0"); break; case MEDIUM: - op = addarg(op, "-aa .125 -ad 512 -as 256"); + op = addarg(op, "-aw 1024 -aa .125 -ad 512 -as 256"); break; case HIGH: op = addarg(op, "-aa .08 -ad 1024 -as 512"); @@ -937,7 +800,8 @@ char *ro; return; if (vdef(OPTFILE)) { for (cp = ro; cp[1]; cp++) - if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) + if (isspace(cp[1]) && (cp[2] == '@' || + (cp[2] == '-' && isalpha(cp[3])))) *cp = '\n'; else *cp = cp[1]; @@ -1032,7 +896,7 @@ register char *vs; zpos = -1; vs++; } viewtype = 'v'; - if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h') + if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c') viewtype = *vs++; cp = viewopts; if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ @@ -1043,6 +907,8 @@ register char *vs; badvalue(ZONE); for (i = 0; i < 3; i++) { dim[i] -= cent[i]; + if (dim[i] <= FTINY) + badvalue(ZONE); cent[i] += .5*dim[i]; } mult = vlet(ZONE)=='E' ? 2. : .45 ; @@ -1085,6 +951,9 @@ register char *vs; case 'h': cp = addarg(cp, "-vh 180 -vv 180"); break; + case 'c': + cp = addarg(cp, "-vh 180 -vv 90"); + break; } } else { while (!isspace(*vs)) /* else skip id */ @@ -1130,14 +999,14 @@ char *vn; /* returned view name */ } /* view number? */ if (isint(viewselect)) - return(specview(nvalue(vv+VIEW, atoi(viewselect)-1))); + return(specview(nvalue(VIEW, atoi(viewselect)-1))); /* check list */ - while ((mv = nvalue(vv+VIEW, n++)) != NULL) + while ((mv = nvalue(VIEW, n++)) != NULL) if (matchword(viewselect, mv)) return(specview(mv)); return(specview(viewselect)); /* standard view? */ } - mv = nvalue(vv+VIEW, n); /* use view n */ + mv = nvalue(VIEW, n); /* use view n */ if (vn != NULL & mv != NULL) { register char *mv2 = mv; if (*mv2 != '-') @@ -1206,39 +1075,53 @@ register char *vopts; } -rview(opts) /* run rview with first view */ -char *opts; +rview(opts, po) /* run rview with first view */ +char *opts, *po; { char *vw; char combuf[512]; /* build command */ - if ((vw = getview(0, NULL)) == NULL) + if (touchonly || (vw = getview(0, NULL)) == NULL) return; if (sayview) printview(vw); - sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname); + sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname); if (rvdevice != NULL) sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); + if (vdef(EXPOSURE)) + sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); strcat(combuf, oct1name); if (runcom(combuf)) { /* run it */ fprintf(stderr, "%s: error running rview\n", progname); - exit(1); + quit(1); } } -rpict(opts) /* run rpict and pfilt for each view */ -char *opts; +rpict(opts, po) /* run rpict and pfilt for each view */ +char *opts, *po; { char combuf[1024]; - char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32]; + char rawfile[MAXPATH], picfile[MAXPATH]; + char zopt[MAXPATH+4], rep[MAXPATH+16], res[32]; char pfopts[128]; char vs[32], *vw; int vn, mult; + time_t rfdt, pfdt; /* get pfilt options */ pfiltopts(pfopts); /* get resolution, reporting */ - mult = vscale(QUALITY)+1; + switch (vscale(QUALITY)) { + case LOW: + mult = 1; + break; + case MEDIUM: + mult = 2; + break; + case HIGH: + mult = 3; + break; + } { int xres, yres; double aspect; @@ -1273,14 +1156,30 @@ char *opts; if (!vs[0]) sprintf(vs, "%d", vn); sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); + if (vdef(ZFILE)) + sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); + else + zopt[0] = '\0'; /* check date on picture */ - if (fdate(picfile) >= oct1date) + pfdt = fdate(picfile); + if (pfdt >= oct1date) continue; + /* get raw file name */ + sprintf(rawfile, "%s_%s.unf", + vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs); + rfdt = fdate(rawfile); + if (touchonly) { /* update times only */ + if (rfdt) { + if (rfdt < oct1date) + touch(rawfile); + } else if (pfdt && pfdt < oct1date) + touch(picfile); + continue; + } /* build rpict command */ - sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); - if (fdate(rawfile) >= oct1date) /* recover */ - sprintf(combuf, "rpict%s%s -ro %s %s", - rep, opts, rawfile, oct1name); + if (rfdt >= oct1date) /* recover */ + sprintf(combuf, "rpict%s%s%s%s -ro %s %s", + rep, po, opts, zopt, rawfile, oct1name); else { if (overture) { /* run overture calculation */ sprintf(combuf, @@ -1291,41 +1190,63 @@ char *opts; fprintf(stderr, "%s: error in overture for view %s\n", progname, vs); - exit(1); + quit(1); } #ifdef NIX rmfile(overfile); #endif } - sprintf(combuf, "rpict%s %s %s%s %s > %s", - rep, vw, res, opts, + sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", + rep, vw, res, po, opts, zopt, oct1name, rawfile); } if (runcom(combuf)) { /* run rpict */ fprintf(stderr, "%s: error rendering view %s\n", progname, vs); - exit(1); + quit(1); } + if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { /* build pfilt command */ - if (mult > 1) - sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", + if (mult > 1) + sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", pfopts, mult, mult, rawfile, picfile); - else - sprintf(combuf, "pfilt%s %s > %s", pfopts, - rawfile, picfile); - if (runcom(combuf)) { /* run pfilt */ - fprintf(stderr, - "%s: error filtering view %s\n\t%s removed\n", - progname, vs, picfile); - unlink(picfile); - exit(1); + else + sprintf(combuf, "pfilt%s %s > %s", pfopts, + rawfile, picfile); + if (runcom(combuf)) { /* run pfilt */ + fprintf(stderr, + "%s: error filtering view %s\n\t%s removed\n", + progname, vs, picfile); + unlink(picfile); + quit(1); + } } - /* remove raw file */ - rmfile(rawfile); + /* remove/rename raw file */ + if (vdef(RAWFILE)) { + sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs); + mvfile(rawfile, combuf); + } else + rmfile(rawfile); } } +touch(fn) /* update a file */ +char *fn; +{ + if (!silent) + printf("\ttouch %s\n", fn); + if (noaction) + return(0); +#ifdef notused + if (access(fn, F_OK) == -1) /* create it */ + if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1) + return(-1); +#endif + return(setfdate(fn, time((time_t *)NULL))); +} + + runcom(cs) /* run command */ char *cs; { @@ -1353,7 +1274,22 @@ char *fn; } +mvfile(fold, fnew) /* move a file */ +char *fold, *fnew; +{ + if (!silent) #ifdef MSDOS + printf("\trename %s %s\n", fold, fnew); +#else + printf("\tmv %s %s\n", fold, fnew); +#endif + if (noaction) + return(0); + return(rename(fold, fnew)); +} + + +#ifdef MSDOS setenv(vname, value) /* set an environment variable */ char *vname, *value; { @@ -1365,7 +1301,7 @@ char *vname, *value; sprintf(evp, "%s=%s", vname, value); if (putenv(evp) != 0) { fprintf(stderr, "%s: out of environment space\n", progname); - exit(1); + quit(1); } if (!silent) printf("set %s\n", evp); @@ -1378,7 +1314,7 @@ int vc; { fprintf(stderr, "%s: bad value for variable '%s'\n", progname, vnam(vc)); - exit(1); + quit(1); } @@ -1386,5 +1322,12 @@ syserr(s) /* report a system error and exit */ char *s; { perror(s); - exit(1); + quit(1); +} + + +quit(ec) /* exit program */ +int ec; +{ + exit(ec); }