--- ray/src/util/rad.c 1993/03/12 13:37:03 2.4 +++ ray/src/util/rad.c 1993/08/25 13:48:37 2.22 @@ -94,20 +94,30 @@ int (*setqopts[3])() = {lowqopts, medqopts, hiqopts}; #define renderopts (*setqopts[vscale(QUALITY)]) + /* overture calculation file */ +#ifdef NIX +char overfile[] = "overture.raw"; +#else +char overfile[] = "/dev/null"; +#endif + 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 */ @@ -135,6 +145,9 @@ char *argv[]; case 'o': rvdevice = argv[++i]; break; + case 'V': + sayview++; + break; case 'v': viewselect = argv[++i]; break; @@ -143,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]); @@ -159,8 +173,11 @@ char *argv[]; /* print all values if requested */ if (explicate) printvals(); - /* run simulation */ + /* build octree */ oconv(); + /* check date on ambient file */ + checkambfile(); + /* run simulation */ renderopts(ropts); xferopts(ropts); if (rvdevice != NULL) @@ -299,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--) @@ -413,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)); } @@ -547,15 +567,28 @@ register char *oo; } +checkambfile() /* check date on ambient file */ +{ + long afdate; + + if (!vdef(AMBFILE)) + return; + if ((afdate = fdate(vval(AMBFILE))) < 0) + return; + if (octreedate > afdate | matdate > afdate) + rmfile(vval(AMBFILE)); +} + + 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.); @@ -599,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); @@ -607,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,9 +696,11 @@ 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"); - sprintf(op, " -ab %d", overture=vint(INDIRECT)); - op += strlen(op); + 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); + } if (vdef(AMBFILE)) { sprintf(op, " -af %s", vval(AMBFILE)); op += strlen(op); @@ -673,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(); @@ -728,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)) { @@ -738,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(); @@ -760,31 +795,26 @@ 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) { - register char *evp = bmalloc(n+6); - if (evp == NULL) - syserr(progname); - strcpy(evp, "ROPT="); - strcat(evp, ro); - if (putenv(evp) != 0) { - fprintf(stderr, "%s: out of environment space\n", - progname); - exit(1); - } + setenv("ROPT", ro+1); strcpy(ro, " $ROPT"); } #endif @@ -799,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)); } @@ -924,8 +960,13 @@ register char *vs; cp += strlen(cp); } } - /* append any additional options */ - strcpy(cp, vs); + strcpy(cp, vs); /* append any additional options */ +#ifdef MSDOS + if (strlen(viewopts) > 40) { + setenv("VIEW", viewopts); + return("$VIEW"); + } +#endif return(viewopts); } @@ -933,11 +974,11 @@ register char *vs; char * getview(n, vn) /* get view n, or NULL if none */ int n; -char *vn; +char *vn; /* returned view name */ { register char *mv; - if (viewselect != NULL) { + if (viewselect != NULL) { /* command-line selected */ if (n) /* only do one */ return(NULL); if (viewselect[0] == '-') { /* already specified */ @@ -950,28 +991,85 @@ char *vn; ; *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)) return(specview(mv)); return(specview(viewselect)); /* standard view? */ } - if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) { - if (*mv != '-') - while (*mv && !isspace(*mv)) - *vn++ = *mv++; + mv = nvalue(vv+VIEW, n); /* use view n */ + if (vn != NULL & mv != NULL) { + register char *mv2 = mv; + if (*mv2 != '-') + while (*mv2 && !isspace(*mv2)) + *vn++ = *mv2++; *vn = '\0'; } - return(specview(nvalue(vv+VIEW, n))); /* use view n */ + return(specview(mv)); } +printview(vopts) /* print out selected view */ +register char *vopts; +{ + extern char *atos(); + 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(' '); + 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)); @@ -990,6 +1088,7 @@ char *opts; char pfopts[128]; char vs[32], *vw; int vn, mult; + long lastdate; /* get pfilt options */ pfiltopts(pfopts); /* get resolution, reporting */ @@ -1020,24 +1119,22 @@ char *opts; else badvalue(REPORT); } - /* check date on ambient file */ - if (vdef(AMBFILE)) { - long afdate = fdate(vval(AMBFILE)); - if (afdate >= 0 & octreedate > afdate) - rmfile(vval(AMBFILE)); - } + /* 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 { @@ -1045,14 +1142,16 @@ char *opts; sprintf(combuf, "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", rep, vw, opts, - vval(OCTREE), rawfile); + vval(OCTREE), overfile); if (runcom(combuf)) { fprintf(stderr, - "%s: error in overture for view %s\n\t%s removed\n", - progname, vs, rawfile); - unlink(rawfile); + "%s: error in overture for view %s\n", + progname, vs); exit(1); } +#ifdef NIX + rmfile(overfile); +#endif } sprintf(combuf, "rpict%s %s %s%s %s > %s", rep, vw, res, opts, @@ -1108,6 +1207,26 @@ char *fn; return(0); return(unlink(fn)); } + + +#ifdef MSDOS +setenv(vname, value) /* set an environment variable */ +char *vname, *value; +{ + register char *evp; + + evp = bmalloc(strlen(vname)+strlen(value)+2); + if (evp == NULL) + syserr(progname); + sprintf(evp, "%s=%s", vname, value); + if (putenv(evp) != 0) { + fprintf(stderr, "%s: out of environment space\n", progname); + exit(1); + } + if (!silent) + printf("set %s\n", evp); +} +#endif badvalue(vc) /* report bad variable value and exit */