--- ray/src/util/rad.c 1997/03/20 12:50:07 2.53 +++ ray/src/util/rad.c 2003/06/05 19:29:35 2.63 @@ -1,74 +1,73 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: rad.c,v 2.63 2003/06/05 19:29:35 schorsch Exp $"; #endif - /* * Executive program for oconv, rpict and pfilt */ #include "standard.h" +#include "view.h" #include "paths.h" #include "vars.h" #include -#include - /* variables */ -#define OBJECT 0 /* object files */ -#define SCENE 1 /* scene files */ -#define MATERIAL 2 /* material files */ -#define ILLUM 3 /* mkillum input files */ -#define MKILLUM 4 /* mkillum options */ -#define RENDER 5 /* rendering options */ -#define OCONV 6 /* oconv options */ -#define PFILT 7 /* pfilt options */ -#define VIEW 8 /* view(s) for picture(s) */ -#define ZONE 9 /* simulation zone */ -#define QUALITY 10 /* desired rendering quality */ -#define OCTREE 11 /* octree 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 */ -#define RESOLUTION 16 /* maximum picture resolution */ -#define UP 17 /* view up (X, Y or Z) */ -#define INDIRECT 18 /* indirection in lighting */ -#define DETAIL 19 /* level of scene detail */ -#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 */ + /* variables (alphabetical by name) */ +#define AMBFILE 0 /* ambient file name */ +#define DETAIL 1 /* level of scene detail */ +#define EXPOSURE 2 /* picture exposure setting */ +#define EYESEP 3 /* interocular distance */ +#define ILLUM 4 /* mkillum input files */ +#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 SCENE 20 /* scene files */ +#define UP 21 /* view up (X, Y or Z) */ +#define VARIABILITY 22 /* level of light variability */ +#define VIEWS 23 /* view(s) for picture(s) */ #define ZFILE 24 /* distance file root name */ +#define ZONE 25 /* simulation zone */ /* total number of variables */ -int NVARS = 25; +int NVARS = 26; VARIABLE vv[] = { /* variable-value pairs */ - {"objects", 3, 0, NULL, catvalues}, - {"scene", 3, 0, NULL, catvalues}, - {"materials", 3, 0, NULL, catvalues}, + {"AMBFILE", 3, 0, NULL, onevalue}, + {"DETAIL", 3, 0, NULL, qualvalue}, + {"EXPOSURE", 3, 0, NULL, fltvalue}, + {"EYESEP", 3, 0, NULL, fltvalue}, {"illum", 3, 0, NULL, catvalues}, + {"INDIRECT", 3, 0, NULL, intvalue}, + {"materials", 3, 0, NULL, catvalues}, {"mkillum", 3, 0, NULL, catvalues}, - {"render", 3, 0, NULL, catvalues}, + {"objects", 3, 0, NULL, catvalues}, {"oconv", 3, 0, NULL, catvalues}, - {"pfilt", 2, 0, NULL, catvalues}, - {"view", 2, 0, NULL, NULL}, - {"ZONE", 2, 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, fltvalue}, + {"PENUMBRAS", 3, 0, NULL, boolvalue}, + {"pfilt", 2, 0, NULL, catvalues}, + {"PICTURE", 3, 0, NULL, onevalue}, + {"QUALITY", 3, 0, NULL, qualvalue}, + {"RAWFILE", 3, 0, NULL, onevalue}, + {"render", 3, 0, NULL, catvalues}, + {"REPORT", 3, 0, NULL, onevalue}, {"RESOLUTION", 3, 0, NULL, onevalue}, + {"scene", 3, 0, NULL, catvalues}, {"UP", 2, 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}, + {"view", 2, 0, NULL, NULL}, {"ZFILE", 2, 0, NULL, onevalue}, + {"ZONE", 2, 0, NULL, onevalue}, }; /* overture calculation file */ @@ -78,7 +77,7 @@ char overfile[] = "overture.unf"; char overfile[] = "/dev/null"; #endif -extern time_t fdate(), time(); +extern time_t time(); time_t scenedate; /* date of latest scene or object file */ time_t octreedate; /* date of octree */ @@ -183,7 +182,7 @@ char *argv[]; quit(0); userr: fprintf(stderr, -"Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", +"Usage: %s [-w][-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", progname); quit(1); } @@ -210,16 +209,13 @@ register char *fnames; { char thisfile[MAXPATH]; time_t thisdate, lastdate = 0; - register char *cp; if (fnames == NULL) return(0); - while (*fnames) { - while (isspace(*fnames)) fnames++; - cp = thisfile; - while (*fnames && !isspace(*fnames)) - *cp++ = *fnames++; - *cp = '\0'; + while ((fnames = nextword(thisfile, MAXPATH, fnames)) != NULL) { + if (thisfile[0] == '!' || + (thisfile[0] == '\\' && thisfile[1] == '!')) + continue; if (!(thisdate = fdate(thisfile))) syserr(thisfile); if (thisdate > lastdate) @@ -264,6 +260,10 @@ checkfiles() /* check for existence and modified tim syserr(progname); sprintf(vval(OCTREE), "%s.oct", radname); vdef(OCTREE)++; + } else if (vval(OCTREE)[0] == '!') { + fprintf(stderr, "%s: illegal '%s' specification\n", + progname, vnam(OCTREE)); + quit(1); } octreedate = fdate(vval(OCTREE)); if (vdef(ILLUM)) { /* illum requires secondary octrees */ @@ -338,7 +338,7 @@ double org[3], *sizp; setdefaults() /* set default values for unassigned var's */ { - double org[3], size; + double org[3], lim[3], size; char buf[128]; if (!vdef(ZONE)) { @@ -348,6 +348,16 @@ setdefaults() /* set default values for unassigned v vval(ZONE) = savqstr(buf); vdef(ZONE)++; } + if (!vdef(EYESEP)) { + if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", + &org[0], &lim[0], &org[1], &lim[1], + &org[2], &lim[2]) != 6) + badvalue(ZONE); + sprintf(buf, "%f", + 0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2])); + vval(EYESEP) = savqstr(buf); + vdef(EYESEP)++; + } if (!vdef(INDIRECT)) { vval(INDIRECT) = "0"; vdef(INDIRECT)++; @@ -364,9 +374,9 @@ setdefaults() /* set default values for unassigned v vval(PICTURE) = radname; vdef(PICTURE)++; } - if (!vdef(VIEW)) { - vval(VIEW) = "X"; - vdef(VIEW)++; + if (!vdef(VIEWS)) { + vval(VIEWS) = "X"; + vdef(VIEWS)++; } if (!vdef(DETAIL)) { vval(DETAIL) = "M"; @@ -616,10 +626,10 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .4 -ad 64"); + op = addarg(op, "-aa .4 -ad 64"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .3 -ad 128"); + op = addarg(op, "-aa .3 -ad 128"); break; case HIGH: op = addarg(op, "-aa .25 -ad 256"); @@ -695,10 +705,10 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .25 -ad 196 -as 0"); + op = addarg(op, "-aa .25 -ad 196 -as 0"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .2 -ad 400 -as 64"); + op = addarg(op, "-aa .2 -ad 400 -as 64"); break; case HIGH: op = addarg(op, "-aa .15 -ad 768 -as 196"); @@ -771,10 +781,10 @@ char *po; overture = 0; switch (vscale(VARIABILITY)) { case LOW: - op = addarg(op, "-aw 128 -aa .15 -ad 256 -as 0"); + op = addarg(op, "-aa .15 -ad 256 -as 0"); break; case MEDIUM: - op = addarg(op, "-aw 1024 -aa .125 -ad 512 -as 256"); + op = addarg(op, "-aa .125 -ad 512 -as 256"); break; case HIGH: op = addarg(op, "-aa .08 -ad 1024 -as 512"); @@ -811,7 +821,7 @@ char *ro; syserr(vval(OPTFILE)); sprintf(ro, " @%s", vval(OPTFILE)); } -#ifdef MSDOS +#ifdef _WIN32 else if (n > 50) { setenv("ROPT", ro+1); strcpy(ro, " $ROPT"); @@ -830,7 +840,7 @@ register char *po; } switch (vscale(QUALITY)) { case MEDIUM: - po = addarg(po, "-r 1"); + po = addarg(po, "-r .6"); break; case HIGH: po = addarg(po, "-m .25"); @@ -967,7 +977,7 @@ register char *vs; if (cp == viewopts) /* append any additional options */ vs++; /* skip prefixed space if unneeded */ strcpy(cp, vs); -#ifdef MSDOS +#ifdef _WIN32 if (strlen(viewopts) > 40) { setenv("VIEW", viewopts); return("$VIEW"); @@ -999,14 +1009,14 @@ char *vn; /* returned view name */ } /* view number? */ if (isint(viewselect)) - return(specview(nvalue(VIEW, atoi(viewselect)-1))); + return(specview(nvalue(VIEWS, atoi(viewselect)-1))); /* check list */ - while ((mv = nvalue(VIEW, n++)) != NULL) + while ((mv = nvalue(VIEWS, n++)) != NULL) if (matchword(viewselect, mv)) return(specview(mv)); return(specview(viewselect)); /* standard view? */ } - mv = nvalue(VIEW, n); /* use view n */ + mv = nvalue(VIEWS, n); /* use view n */ if (vn != NULL & mv != NULL) { register char *mv2 = mv; if (*mv2 != '-') @@ -1021,56 +1031,28 @@ char *vn; /* returned view name */ printview(vopts) /* print out selected view */ register char *vopts; { - extern char *atos(), *getenv(); - char buf[256]; - FILE *fp; + VIEW vwr; + char buf[128]; register char *cp; - +again: 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 +#ifdef _WIN32 + if (vopts[0] == '$') { + vopts = getenv(vopts+1); + goto again; + } #endif - while (*vopts && !isspace(*vopts)) - putchar(*vopts++); - } - } while (*vopts++); - putchar('\n'); + copystruct(&vwr, &stdview); + sscanview(&vwr, cp=vopts); /* set initial options */ + while ((cp = strstr(cp, "-vf ")) != NULL && + *atos(buf, sizeof(buf), cp += 4)) { + viewfile(buf, &vwr, NULL); /* load -vf file */ + sscanview(&vwr, cp); /* reset tail */ + } + fputs(VIEWSTR, stdout); + fprintview(&vwr, stdout); /* print full spec. */ + fputc('\n', stdout); return(0); } @@ -1263,7 +1245,7 @@ rmfile(fn) /* remove a file */ char *fn; { if (!silent) -#ifdef MSDOS +#ifdef _WIN32 printf("\tdel %s\n", fn); #else printf("\trm -f %s\n", fn); @@ -1278,7 +1260,7 @@ mvfile(fold, fnew) /* move a file */ char *fold, *fnew; { if (!silent) -#ifdef MSDOS +#ifdef _WIN32 printf("\trename %s %s\n", fold, fnew); #else printf("\tmv %s %s\n", fold, fnew); @@ -1289,7 +1271,7 @@ char *fold, *fnew; } -#ifdef MSDOS +#ifdef _WIN32 setenv(vname, value) /* set an environment variable */ char *vname, *value; { @@ -1326,6 +1308,7 @@ char *s; } +void quit(ec) /* exit program */ int ec; {