--- ray/src/util/rad.c 1995/07/06 12:15:40 2.43 +++ ray/src/util/rad.c 1996/01/05 14:43:03 2.50 @@ -1,4 +1,4 @@ -/* Copyright (c) 1994 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,21 +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(), boolvalue(), - qualvalue(), fltvalue(), intvalue(); - /* variables */ #define OBJECT 0 /* object files */ #define SCENE 1 /* scene files */ @@ -38,7 +27,7 @@ int onevalue(), catvalues(), boolvalue(), #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 */ @@ -49,11 +38,12 @@ int onevalue(), catvalues(), boolvalue(), #define PENUMBRAS 20 /* shadow penumbras are desired */ #define VARIABILITY 21 /* level of light variability */ #define REPORT 22 /* report frequency and errfile */ -#define RAWSAVE 23 /* save raw picture file */ +#define RAWFILE 23 /* raw picture file root name */ +#define ZFILE 24 /* distance file root name */ /* total number of variables */ -#define NVARS 24 +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}, @@ -77,29 +67,13 @@ VARIABLE vv[NVARS] = { /* variable-value pairs */ {"PENUMBRAS", 3, 0, NULL, boolvalue}, {"VARIABILITY", 3, 0, NULL, qualvalue}, {"REPORT", 3, 0, NULL, onevalue}, - {"RAWSAVE", 3, 0, NULL, boolvalue}, + {"RAWFILE", 3, 0, NULL, onevalue}, + {"ZFILE", 2, 0, NULL, onevalue}, }; -VARIABLE *matchvar(); -char *nvalue(); - -#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 vscale vlet -#define vbool(vc) (vlet(vc)=='T') - -#define HIGH 'H' -#define MEDIUM 'M' -#define LOW 'L' - /* overture calculation file */ #ifdef NIX -char overfile[] = "overture.raw"; +char overfile[] = "overture.unf"; #else char overfile[] = "/dev/null"; #endif @@ -178,7 +152,7 @@ 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]); @@ -190,7 +164,7 @@ char *argv[]; setdefaults(); /* print all values if requested */ if (explicate) - printvals(); + printvars(stdout); /* build octree (and run mkillum) */ oconv(); /* check date on ambient file */ @@ -226,253 +200,6 @@ 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]; - 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 && !nowarn) { - 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); -} - - -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; - if (!nowarn) - 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++ = ' '; - } -} - - -int -badmatch(tv, cv) /* case insensitive truncated comparison */ -register char *tv, *cv; -{ - if (!*tv) return(1); /* null string cannot match */ - do - if (UPPER(*tv) != *cv++) - return(1); - while (*++tv); - return(0); /* OK */ -} - - -boolvalue(vp) /* check boolean for legal values */ -register VARIABLE *vp; -{ - if (!vp->nass) return; - onevalue(vp); - switch (UPPER(vp->value[0])) { - case 'T': - if (badmatch(vp->value, "TRUE")) break; - return; - case 'F': - if (badmatch(vp->value, "FALSE")) break; - return; - } - fprintf(stderr, "%s: illegal value for boolean variable '%s'\n", - progname, vp->name); - exit(1); -} - - -qualvalue(vp) /* check qualitative var. for legal values */ -register VARIABLE *vp; -{ - if (!vp->nass) return; - onevalue(vp); - switch (UPPER(vp->value[0])) { - case 'L': - if (badmatch(vp->value, "LOW")) break; - return; - case 'M': - if (badmatch(vp->value, "MEDIUM")) break; - return; - case 'H': - if (badmatch(vp->value, "HIGH")) break; - return; - } - fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n", - progname, vp->name); - exit(1); -} - - -intvalue(vp) /* check integer variable for legal values */ -register VARIABLE *vp; -{ - if (!vp->nass) return; - onevalue(vp); - if (isint(vp->value)) return; - fprintf(stderr, "%s: illegal value for integer variable '%s'\n", - progname, vp->name); - exit(1); -} - - -fltvalue(vp) /* check float variable for legal values */ -register VARIABLE *vp; -{ - if (!vp->nass) return; - onevalue(vp); - if (isflt(vp->value)) return; - fprintf(stderr, "%s: illegal value for real variable '%s'\n", - progname, vp->name); - exit(1); -} - - time_t checklast(fnames) /* check files and find most recent */ register char *fnames; @@ -561,7 +288,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; @@ -649,49 +376,13 @@ setdefaults() /* set default values for unassigned v vval(VARIABILITY) = "L"; vdef(VARIABILITY)++; } - if (!vdef(RAWSAVE)) { - vval(RAWSAVE) = "F"; - vdef(RAWSAVE)++; - } } -printvals() /* print variable values */ -{ - int i, j, clipline; - register char *cp; - register int k; - - for (i = 0; i < NVARS; i++) /* print each variable */ - for (j = 0; j < vdef(i); j++) { /* print each assignment */ - fputs(vnam(i), stdout); - fputs("= ", stdout); - k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 ) - - strlen(vnam(i)) ; - cp = nvalue(vv+i, j); - while (*cp) { - putchar(*cp++); - if (--k <= 0) { /* line too long */ - while (*cp && !isspace(*cp)) - putchar(*cp++); /* finish this word */ - if (*cp) { /* start new line */ - putchar('\n'); - fputs(vnam(i), stdout); - putchar('='); - k = clipline; - } - } - } - putchar('\n'); - } - 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 */ @@ -779,6 +470,7 @@ oconv() /* run oconv and mkillum if necessary */ "%s: error generating octree\n\t%s removed\n", progname, oct1name); unlink(oct1name); + unlink(illumtmp); exit(1); } rmfile(illumtmp); @@ -843,8 +535,8 @@ ambval() /* compute ambient value */ { if (vdef(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.); @@ -943,7 +635,7 @@ 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'; @@ -954,25 +646,32 @@ char *po; 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: 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: 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: 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; } po = addarg(po, "-pt .08"); @@ -1014,7 +713,7 @@ 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'; @@ -1025,25 +724,32 @@ char *po; 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: 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: 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: 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; } po = addarg(po, "-pt .04"); @@ -1090,7 +796,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]; @@ -1185,7 +892,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! */ @@ -1240,6 +947,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 */ @@ -1388,7 +1098,8 @@ rpict(opts, po) /* run rpict and pfilt for each vie 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; @@ -1441,12 +1152,17 @@ char *opts, *po; 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 */ pfdt = fdate(picfile); if (pfdt >= oct1date) continue; /* get raw file name */ - sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); + sprintf(rawfile, "%s_%s.unf", + vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs); rfdt = fdate(rawfile); if (touchonly) { /* update times only */ if (rfdt) { @@ -1458,8 +1174,8 @@ char *opts, *po; } /* build rpict command */ if (rfdt >= oct1date) /* recover */ - sprintf(combuf, "rpict%s%s%s -ro %s %s", - rep, po, opts, rawfile, oct1name); + sprintf(combuf, "rpict%s%s%s%s -ro %s %s", + rep, po, opts, zopt, rawfile, oct1name); else { if (overture) { /* run overture calculation */ sprintf(combuf, @@ -1476,32 +1192,34 @@ char *opts, *po; rmfile(overfile); #endif } - sprintf(combuf, "rpict%s %s %s%s%s %s > %s", - rep, vw, res, po, opts, - oct1name, rawfile); + 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); } + 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); + exit(1); + } } /* remove/rename raw file */ - if (vbool(RAWSAVE)) { - sprintf(combuf, "%s_%s.rwp", vval(PICTURE), vs); + if (vdef(RAWFILE)) { + sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs); mvfile(rawfile, combuf); } else rmfile(rawfile);