--- ray/src/util/rad.c 1998/06/03 16:37:51 2.56 +++ ray/src/util/rad.c 2003/06/30 14:59:13 2.65 @@ -1,53 +1,54 @@ -/* 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.65 2003/06/30 14:59:13 schorsch Exp $"; #endif - /* * Executive program for oconv, rpict and pfilt */ #include "standard.h" + +#include + +#include "platform.h" #include "view.h" #include "paths.h" #include "vars.h" -#include -#include /* variables (alphabetical by name) */ #define AMBFILE 0 /* ambient file name */ #define DETAIL 1 /* level of scene detail */ #define EXPOSURE 2 /* picture exposure setting */ -#define ILLUM 3 /* mkillum input files */ -#define INDIRECT 4 /* indirection in lighting */ -#define MATERIAL 5 /* material files */ -#define MKILLUM 6 /* mkillum options */ -#define OBJECT 7 /* object files */ -#define OCONV 8 /* oconv options */ -#define OCTREE 9 /* octree file name */ -#define OPTFILE 10 /* rendering options file */ -#define PENUMBRAS 11 /* shadow penumbras are desired */ -#define PFILT 12 /* pfilt options */ -#define PICTURE 13 /* picture file root name */ -#define QUALITY 14 /* desired rendering quality */ -#define RAWFILE 15 /* raw picture file root name */ -#define RENDER 16 /* rendering options */ -#define REPORT 17 /* report frequency and errfile */ -#define RESOLUTION 18 /* maximum picture resolution */ -#define SCENE 19 /* scene files */ -#define UP 20 /* view up (X, Y or Z) */ -#define VARIABILITY 21 /* level of light variability */ -#define VIEWS 22 /* view(s) for picture(s) */ -#define ZFILE 23 /* distance file root name */ -#define ZONE 24 /* simulation zone */ +#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 */ {"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}, @@ -73,13 +74,13 @@ VARIABLE vv[] = { /* variable-value pairs */ }; /* overture calculation file */ -#ifdef NIX -char overfile[] = "overture.unf"; +#ifdef NULL_DEVICE +char overfile[] = NULL_DEVICE; #else -char overfile[] = "/dev/null"; +char overfile[] = "overture.unf"; #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 */ @@ -105,7 +106,7 @@ 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 */ +char radname[PATH_MAX]; /* root Radiance file name */ main(argc, argv) @@ -184,7 +185,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); } @@ -209,18 +210,15 @@ time_t checklast(fnames) /* check files and find most recent */ register char *fnames; { - char thisfile[MAXPATH]; + char thisfile[PATH_MAX]; 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, PATH_MAX, fnames)) != NULL) { + if (thisfile[0] == '!' || + (thisfile[0] == '\\' && thisfile[1] == '!')) + continue; if (!(thisdate = fdate(thisfile))) syserr(thisfile); if (thisdate > lastdate) @@ -235,7 +233,6 @@ newfname(orig, pred) /* create modified file name */ char *orig; int pred; { - extern char *rindex(); register char *cp; register int n; int suffix; @@ -265,6 +262,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 */ @@ -339,7 +340,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)) { @@ -349,6 +350,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)++; @@ -387,7 +398,7 @@ setdefaults() /* set default values for unassigned v oconv() /* run oconv and mkillum if necessary */ { static char illumtmp[] = "ilXXXXXX"; - char combuf[1024], ocopts[64], mkopts[64]; + char combuf[PATH_MAX], ocopts[64], mkopts[64]; oconvopts(ocopts); /* get options */ if (octreedate < scenedate) { /* check date on original octree */ @@ -812,7 +823,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"); @@ -831,7 +842,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"); @@ -968,7 +979,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"); @@ -1022,25 +1033,25 @@ char *vn; /* returned view name */ printview(vopts) /* print out selected view */ register char *vopts; { - extern char *strstr(), *atos(), *getenv(); VIEW vwr; char buf[128]; register char *cp; again: if (vopts == NULL) return(-1); -#ifdef MSDOS +#ifdef _WIN32 if (vopts[0] == '$') { vopts = getenv(vopts+1); goto again; } #endif copystruct(&vwr, &stdview); - cp = vopts; /* get -vf files first */ + sscanview(&vwr, cp=vopts); /* set initial options */ while ((cp = strstr(cp, "-vf ")) != NULL && - *atos(buf, sizeof(buf), cp += 4)) - viewfile(buf, &vwr, NULL); - sscanview(&vwr, vopts); /* get the rest */ + *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); @@ -1052,7 +1063,7 @@ rview(opts, po) /* run rview with first view */ char *opts, *po; { char *vw; - char combuf[512]; + char combuf[PATH_MAX]; /* build command */ if (touchonly || (vw = getview(0, NULL)) == NULL) return; @@ -1074,9 +1085,9 @@ char *opts, *po; rpict(opts, po) /* run rpict and pfilt for each view */ char *opts, *po; { - char combuf[1024]; - char rawfile[MAXPATH], picfile[MAXPATH]; - char zopt[MAXPATH+4], rep[MAXPATH+16], res[32]; + char combuf[PATH_MAX]; + char rawfile[PATH_MAX], picfile[PATH_MAX]; + char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; char pfopts[128]; char vs[32], *vw; int vn, mult; @@ -1165,7 +1176,7 @@ char *opts, *po; progname, vs); quit(1); } -#ifdef NIX +#ifndef NULL_DEVICE rmfile(overfile); #endif } @@ -1236,7 +1247,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); @@ -1251,7 +1262,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); @@ -1262,7 +1273,7 @@ char *fold, *fnew; } -#ifdef MSDOS +#ifdef _WIN32 setenv(vname, value) /* set an environment variable */ char *vname, *value; { @@ -1299,6 +1310,7 @@ char *s; } +void quit(ec) /* exit program */ int ec; {