--- ray/src/util/rad.c 1993/05/26 11:37:42 2.9 +++ ray/src/util/rad.c 1993/09/09 13:07:13 2.24 @@ -105,16 +105,19 @@ extern long fdate(), time(); long scenedate; /* date of latest scene or object file */ long octreedate; /* date of octree */ +long matdate; /* date of latest material file */ int explicate = 0; /* explicate variables */ int silent = 0; /* do work silently */ int noaction = 0; /* don't do anything */ +int sayview = 0; /* print view out */ char *rvdevice = NULL; /* rview output device */ char *viewselect = NULL; /* specific view only */ int overture = 0; /* overture calculation needed */ char *progname; /* global argv[0] */ +char *rifname; /* global rad input file name */ char radname[MAXPATH]; /* root Radiance file name */ @@ -142,6 +145,9 @@ char *argv[]; case 'o': rvdevice = argv[++i]; break; + case 'V': + sayview++; + break; case 'v': viewselect = argv[++i]; break; @@ -150,10 +156,11 @@ char *argv[]; } if (i >= argc) goto userr; + rifname = argv[i]; /* assign Radiance root file name */ - rootname(radname, argv[i]); + rootname(radname, rifname); /* load variable values */ - load(argv[i]); + load(rifname); /* get any additional assignments */ for (i++; i < argc; i++) setvariable(argv[i]); @@ -309,7 +316,7 @@ register int n; { register char *cp; - if (vp == NULL || n < 0 || n >= vp->nass) + if (vp == NULL | n < 0 | n >= vp->nass) return(NULL); cp = vp->value; while (n--) @@ -423,6 +430,9 @@ checkfiles() /* check for existence and modified tim vnam(OCTREE), vnam(SCENE)); exit(1); } + matdate = -1; + if (vdef(MATERIAL)) + matdate = checklast(vval(MATERIAL)); } @@ -561,11 +571,12 @@ checkambfile() /* check date on ambient file */ { long afdate; - if (vdef(AMBFILE)) { - afdate = fdate(vval(AMBFILE)); - if (afdate >= 0 & octreedate > afdate) - rmfile(vval(AMBFILE)); - } + if (!vdef(AMBFILE)) + return; + if ((afdate = fdate(vval(AMBFILE))) < 0) + return; + if (octreedate > afdate | matdate > afdate) + rmfile(vval(AMBFILE)); } @@ -573,11 +584,11 @@ 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)))); - if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.') - return(.5/atof(vval(EXPOSURE))); - badvalue(EXPOSURE); + return(.5/atof(vval(EXPOSURE))); } if (vlet(ZONE) == 'E') return(10.); @@ -601,17 +612,17 @@ register char *op; d *= 3./(siz[0]+siz[1]+siz[2]); switch (vscale(DETAIL)) { case LOW: - op = addarg(op, "-ps 16 -dp 16"); + op = addarg(op, "-ps 16 -dp 64"); sprintf(op, " -ar %d", (int)(4*d)); op += strlen(op); break; case MEDIUM: - op = addarg(op, "-ps 8 -dp 32"); + op = addarg(op, "-ps 8 -dp 128"); sprintf(op, " -ar %d", (int)(8*d)); op += strlen(op); break; case HIGH: - op = addarg(op, "-ps 4 -dp 64"); + op = addarg(op, "-ps 4 -dp 256"); sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); break; @@ -621,7 +632,7 @@ register char *op; op = addarg(op, "-ds .4"); else op = addarg(op, "-ds 0"); - op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7"); + op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5"); if (vdef(AMBFILE)) { sprintf(op, " -af %s", vval(AMBFILE)); op += strlen(op); @@ -629,13 +640,13 @@ register char *op; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aa .4 -ad 32"); + op = addarg(op, "-aa .4 -ad 64"); break; case MEDIUM: - op = addarg(op, "-aa .3 -ad 64"); + op = addarg(op, "-aa .3 -ad 128"); break; case HIGH: - op = addarg(op, "-aa .25 -ad 128"); + op = addarg(op, "-aa .25 -ad 256"); break; } op = addarg(op, "-as 0"); @@ -663,19 +674,19 @@ register char *op; switch (vscale(DETAIL)) { case LOW: op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); - op = addarg(op, "-dp 64"); + op = addarg(op, "-dp 256"); sprintf(op, " -ar %d", (int)(8*d)); op += strlen(op); break; case MEDIUM: op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); - op = addarg(op, "-dp 128"); + op = addarg(op, "-dp 512"); sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); break; case HIGH: op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); - op = addarg(op, "-dp 256"); + op = addarg(op, "-dp 1024"); sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); break; @@ -685,7 +696,7 @@ register char *op; op = addarg(op, "-ds .2 -dj .35"); else op = addarg(op, "-ds .3"); - op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15"); + op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); if (overture = vint(INDIRECT)) { sprintf(op, " -ab %d", overture); op += strlen(op); @@ -697,13 +708,13 @@ register char *op; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aa .25 -ad 128 -as 0"); + op = addarg(op, "-aa .25 -ad 196 -as 0"); break; case MEDIUM: - op = addarg(op, "-aa .2 -ad 300 -as 64"); + op = addarg(op, "-aa .2 -ad 400 -as 64"); break; case HIGH: - op = addarg(op, "-aa .15 -ad 500 -as 128"); + op = addarg(op, "-aa .15 -ad 768 -as 196"); break; } d = ambval(); @@ -730,19 +741,19 @@ register char *op; switch (vscale(DETAIL)) { case LOW: op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); - op = addarg(op, "-dp 256"); + op = addarg(op, "-dp 1024"); sprintf(op, " -ar %d", (int)(16*d)); op += strlen(op); break; case MEDIUM: op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); - op = addarg(op, "-dp 512"); + op = addarg(op, "-dp 2048"); sprintf(op, " -ar %d", (int)(32*d)); op += strlen(op); break; case HIGH: op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); - op = addarg(op, "-dp 1024"); + op = addarg(op, "-dp 4096"); sprintf(op, " -ar %d", (int)(64*d)); op += strlen(op); break; @@ -752,7 +763,7 @@ register char *op; op = addarg(op, "-ds .1 -dj .7"); else op = addarg(op, "-ds .2"); - op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03"); + op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); op += strlen(op); if (vdef(AMBFILE)) { @@ -762,13 +773,13 @@ register char *op; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aa .15 -ad 200 -as 0"); + op = addarg(op, "-aa .15 -ad 256 -as 0"); break; case MEDIUM: - op = addarg(op, "-aa .125 -ad 512 -as 128"); + op = addarg(op, "-aa .125 -ad 512 -as 256"); break; case HIGH: - op = addarg(op, "-aa .08 -ad 850 -as 256"); + op = addarg(op, "-aa .08 -ad 1024 -as 512"); break; } d = ambval(); @@ -784,18 +795,22 @@ xferopts(ro) /* transfer options if indicated */ char *ro; { int fd, n; + register char *cp; n = strlen(ro); if (n < 2) return; if (vdef(OPTFILE)) { - if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) + for (cp = ro; cp[1]; cp++) + if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) + *cp = '\n'; + else + *cp = cp[1]; + *cp = '\n'; + fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0) syserr(vval(OPTFILE)); - if (write(fd, ro+1, n-1) != n-1) - syserr(vval(OPTFILE)); - write(fd, "\n", 1); - close(fd); - sprintf(ro, " \"^%s\"", vval(OPTFILE)); + sprintf(ro, " @%s", vval(OPTFILE)); } #ifdef MSDOS else if (n > 50) { @@ -814,8 +829,14 @@ register char *po; po = addarg(po, "-1 -e"); po = addarg(po, vval(EXPOSURE)); } - if (vscale(QUALITY) == HIGH) - po = addarg(po, "-r .65"); + switch (vscale(QUALITY)) { + case MEDIUM: + po = addarg(po, "-r 1"); + break; + case HIGH: + po = addarg(po, "-m .25"); + break; + } if (vdef(PFILT)) po = addarg(po, vval(PFILT)); } @@ -955,7 +976,7 @@ getview(n, vn) /* get view n, or NULL if none */ int n; char *vn; /* returned view name */ { - register char *mv = NULL; + register char *mv; if (viewselect != NULL) { /* command-line selected */ if (n) /* only do one */ @@ -970,6 +991,9 @@ char *vn; /* returned view name */ ; *vn = '\0'; } + /* view number? */ + if (isint(viewselect)) + return(specview(nvalue(vv+VIEW, atoi(viewselect)-1))); /* check list */ while ((mv = nvalue(vv+VIEW, n++)) != NULL) if (matchword(viewselect, mv)) @@ -978,21 +1002,84 @@ char *vn; /* returned view name */ } mv = nvalue(vv+VIEW, n); /* use view n */ if (vn != NULL & mv != NULL) { - if (*mv != '-') - while (*mv && !isspace(*mv)) - *vn++ = *mv++; + register char *mv2 = mv; + if (*mv2 != '-') + while (*mv2 && !isspace(*mv2)) + *vn++ = *mv2++; *vn = '\0'; } return(specview(mv)); } +printview(vopts) /* print out selected view */ +register char *vopts; +{ + extern char *atos(), *getenv(); + char buf[256]; + FILE *fp; + register char *cp; + + if (vopts == NULL) + return(-1); + fputs("VIEW=", stdout); + do { + if (matchword(vopts, "-vf")) { /* expand view file */ + vopts = sskip(vopts); + if (!*atos(buf, sizeof(buf), vopts)) + return(-1); + if ((fp = fopen(buf, "r")) == NULL) + return(-1); + for (buf[sizeof(buf)-2] = '\n'; + fgets(buf, sizeof(buf), fp) != NULL && + buf[0] != '\n'; + buf[sizeof(buf)-2] = '\n') { + if (buf[sizeof(buf)-2] != '\n') { + ungetc(buf[sizeof(buf)-2], fp); + buf[sizeof(buf)-2] = '\0'; + } + if (matchword(buf, "VIEW=") || + matchword(buf, "rview")) { + for (cp = sskip(buf); *cp && *cp != '\n'; cp++) + putchar(*cp); + } + } + fclose(fp); + vopts = sskip(vopts); + } else { + while (isspace(*vopts)) + vopts++; + putchar(' '); +#ifdef MSDOS + if (*vopts == '$') { /* expand env. var. */ + if (!*atos(buf, sizeof(buf), vopts+1)) + return(-1); + if ((cp = getenv(buf)) == NULL) + return(-1); + fputs(cp, stdout); + vopts = sskip(vopts); + } else +#endif + while (*vopts && !isspace(*vopts)) + putchar(*vopts++); + } + } while (*vopts++); + putchar('\n'); + return(0); +} + + rview(opts) /* run rview with first view */ char *opts; { + char *vw; char combuf[512]; /* build command */ - sprintf(combuf, "rview %s%s ", getview(0, NULL), opts); + if ((vw = getview(0, NULL)) == NULL) + return; + if (sayview) + printview(vw); + sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname); if (rvdevice != NULL) sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); strcat(combuf, vval(OCTREE)); @@ -1011,6 +1098,7 @@ char *opts; char pfopts[128]; char vs[32], *vw; int vn, mult; + long lastdate; /* get pfilt options */ pfiltopts(pfopts); /* get resolution, reporting */ @@ -1041,18 +1129,22 @@ char *opts; else badvalue(REPORT); } + /* get update time */ + lastdate = octreedate > matdate ? octreedate : matdate; /* do each view */ vn = 0; while ((vw = getview(vn++, vs)) != NULL) { + if (sayview) + printview(vw); if (!vs[0]) sprintf(vs, "%d", vn); sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); /* check date on picture */ - if (fdate(picfile) > octreedate) + if (fdate(picfile) >= lastdate) continue; /* build rpict command */ sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); - if (fdate(rawfile) > octreedate) /* recover */ + if (fdate(rawfile) >= octreedate) /* recover */ sprintf(combuf, "rpict%s%s -ro %s %s", rep, opts, rawfile, vval(OCTREE)); else {