ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.2 by greg, Thu Mar 11 11:39:48 1993 UTC vs.
Revision 2.57 by gwlarson, Wed Jun 10 17:51:06 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1993 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include "standard.h"
12 + #include "view.h"
13   #include "paths.h"
14 + #include "vars.h"
15   #include <ctype.h>
16 + #include <sys/types.h>
17  
18 <
19 < typedef struct {
20 <        char    *name;          /* variable name */
21 <        short   nick;           /* # characters required for nickname */
22 <        short   nass;           /* # assignments made */
23 <        char    *value;         /* assigned value(s) */
24 <        int     (*fixval)();    /* assignment checking function */
25 < } VARIABLE;
26 <
27 < int     onevalue(), catvalues();
28 <
29 <                                /* variables */
30 < #define OBJECT          0               /* object files */
31 < #define SCENE           1               /* scene files */
32 < #define MATERIAL        2               /* material files */
33 < #define RENDER          3               /* rendering options */
34 < #define OCONV           4               /* oconv options */
35 < #define PFILT           5               /* pfilt options */
36 < #define VIEW            6               /* view(s) for picture(s) */
37 < #define ZONE            7               /* simulation zone */
38 < #define QUALITY         8               /* desired rendering quality */
39 < #define OCTREE          9               /* octree file name */
40 < #define PICTURE         10              /* picture file name */
41 < #define AMBFILE         11              /* ambient file name */
42 < #define OPTFILE         12              /* rendering options file */
43 < #define EXPOSURE        13              /* picture exposure setting */
44 < #define RESOLUTION      14              /* maximum picture resolution */
42 < #define UP              15              /* view up (X, Y or Z) */
43 < #define INDIRECT        16              /* indirection in lighting */
44 < #define DETAIL          17              /* level of scene detail */
45 < #define PENUMBRAS       18              /* shadow penumbras are desired */
46 < #define VARIABILITY     19              /* level of light variability */
47 < #define REPORT          20              /* report frequency and errfile */
18 >                                /* variables (alphabetical by name) */
19 > #define AMBFILE         0               /* ambient file name */
20 > #define DETAIL          1               /* level of scene detail */
21 > #define EXPOSURE        2               /* picture exposure setting */
22 > #define EYESEP          3               /* interocular distance */
23 > #define ILLUM           4               /* mkillum input files */
24 > #define INDIRECT        5               /* indirection in lighting */
25 > #define MATERIAL        6               /* material files */
26 > #define MKILLUM         7               /* mkillum options */
27 > #define OBJECT          8               /* object files */
28 > #define OCONV           9               /* oconv options */
29 > #define OCTREE          10              /* octree file name */
30 > #define OPTFILE         11              /* rendering options file */
31 > #define PENUMBRAS       12              /* shadow penumbras are desired */
32 > #define PFILT           13              /* pfilt options */
33 > #define PICTURE         14              /* picture file root name */
34 > #define QUALITY         15              /* desired rendering quality */
35 > #define RAWFILE         16              /* raw picture file root name */
36 > #define RENDER          17              /* rendering options */
37 > #define REPORT          18              /* report frequency and errfile */
38 > #define RESOLUTION      19              /* maximum picture resolution */
39 > #define SCENE           20              /* scene files */
40 > #define UP              21              /* view up (X, Y or Z) */
41 > #define VARIABILITY     22              /* level of light variability */
42 > #define VIEWS           23              /* view(s) for picture(s) */
43 > #define ZFILE           24              /* distance file root name */
44 > #define ZONE            25              /* simulation zone */
45                                  /* total number of variables */
46 < #define NVARS           21
46 > int NVARS = 26;
47  
48 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
49 <        {"objects",     3,      0,      NULL,   catvalues},
50 <        {"scene",       3,      0,      NULL,   catvalues},
48 > VARIABLE        vv[] = {                /* variable-value pairs */
49 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
50 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
51 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
52 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
53 >        {"illum",       3,      0,      NULL,   catvalues},
54 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
55          {"materials",   3,      0,      NULL,   catvalues},
56 <        {"render",      3,      0,      NULL,   catvalues},
56 >        {"mkillum",     3,      0,      NULL,   catvalues},
57 >        {"objects",     3,      0,      NULL,   catvalues},
58          {"oconv",       3,      0,      NULL,   catvalues},
57        {"pfilt",       2,      0,      NULL,   catvalues},
58        {"view",        2,      0,      NULL,   NULL},
59        {"ZONE",        2,      0,      NULL,   onevalue},
60        {"QUALITY",     3,      0,      NULL,   onevalue},
59          {"OCTREE",      3,      0,      NULL,   onevalue},
62        {"PICTURE",     3,      0,      NULL,   onevalue},
63        {"AMBFILE",     3,      0,      NULL,   onevalue},
60          {"OPTFILE",     3,      0,      NULL,   onevalue},
61 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
61 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
62 >        {"pfilt",       2,      0,      NULL,   catvalues},
63 >        {"PICTURE",     3,      0,      NULL,   onevalue},
64 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
65 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
66 >        {"render",      3,      0,      NULL,   catvalues},
67 >        {"REPORT",      3,      0,      NULL,   onevalue},
68          {"RESOLUTION",  3,      0,      NULL,   onevalue},
69 +        {"scene",       3,      0,      NULL,   catvalues},
70          {"UP",          2,      0,      NULL,   onevalue},
71 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
72 <        {"DETAIL",      3,      0,      NULL,   onevalue},
73 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
74 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
72 <        {"REPORT",      3,      0,      NULL,   onevalue},
71 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
72 >        {"view",        2,      0,      NULL,   NULL},
73 >        {"ZFILE",       2,      0,      NULL,   onevalue},
74 >        {"ZONE",        2,      0,      NULL,   onevalue},
75   };
76  
77 < VARIABLE        *matchvar();
78 < char    *nvalue();
79 < int     vscale();
77 >                                /* overture calculation file */
78 > #ifdef NIX
79 > char    overfile[] = "overture.unf";
80 > #else
81 > char    overfile[] = "/dev/null";
82 > #endif
83  
84 < #define vnam(vc)        (vv[vc].name)
80 < #define vdef(vc)        (vv[vc].nass)
81 < #define vval(vc)        (vv[vc].value)
82 < #define vint(vc)        atoi(vval(vc))
83 < #define vlet(vc)        (vval(vc)[0]&~0x20)
84 < #define vbool(vc)       (vlet(vc)=='T')
84 > extern time_t   fdate(), time();
85  
86 < #define HIGH            2
87 < #define MEDIUM          1
88 < #define LOW             0
86 > time_t  scenedate;              /* date of latest scene or object file */
87 > time_t  octreedate;             /* date of octree */
88 > time_t  matdate;                /* date of latest material file */
89 > time_t  illumdate;              /* date of last illum file */
90  
91 < int     lowqopts(), medqopts(), hiqopts();
92 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
91 > char    *oct0name;              /* name of pre-mkillum octree */
92 > time_t  oct0date;               /* date of pre-mkillum octree */
93 > char    *oct1name;              /* name of post-mkillum octree */
94 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
95  
96 < #define renderopts      (*setqopts[vscale(QUALITY)])
94 <
95 < extern long     fdate(), time();
96 <
97 < long    scenedate;              /* date of latest scene or object file */
98 < long    octreedate;             /* date of octree */
99 <
96 > int     nowarn = 0;             /* no warnings */
97   int     explicate = 0;          /* explicate variables */
98   int     silent = 0;             /* do work silently */
99 + int     touchonly = 0;          /* touch files only */
100   int     noaction = 0;           /* don't do anything */
101 + int     sayview = 0;            /* print view out */
102   char    *rvdevice = NULL;       /* rview output device */
103   char    *viewselect = NULL;     /* specific view only */
104  
105   int     overture = 0;           /* overture calculation needed */
106  
107   char    *progname;              /* global argv[0] */
108 + char    *rifname;               /* global rad input file name */
109  
110   char    radname[MAXPATH];       /* root Radiance file name */
111  
# Line 115 | Line 115 | int    argc;
115   char    *argv[];
116   {
117          char    ropts[512];
118 +        char    popts[64];
119          int     i;
120  
121          progname = argv[0];
# Line 127 | Line 128 | char   *argv[];
128                  case 'n':
129                          noaction++;
130                          break;
131 +                case 't':
132 +                        touchonly++;
133 +                        break;
134                  case 'e':
135                          explicate++;
136                          break;
137                  case 'o':
138                          rvdevice = argv[++i];
139                          break;
140 +                case 'V':
141 +                        sayview++;
142 +                        break;
143                  case 'v':
144                          viewselect = argv[++i];
145                          break;
146 +                case 'w':
147 +                        nowarn++;
148 +                        break;
149                  default:
150                          goto userr;
151                  }
152          if (i >= argc)
153                  goto userr;
154 +        rifname = argv[i];
155                                  /* assign Radiance root file name */
156 <        rootname(radname, argv[i]);
156 >        rootname(radname, rifname);
157                                  /* load variable values */
158 <        load(argv[i]);
158 >        loadvars(rifname);
159                                  /* get any additional assignments */
160          for (i++; i < argc; i++)
161 <                setvariable(argv[i]);
161 >                if (setvariable(argv[i], matchvar) < 0) {
162 >                        fprintf(stderr, "%s: unknown variable: %s\n",
163 >                                        progname, argv[i]);
164 >                        quit(1);
165 >                }
166                                  /* check assignments */
167          checkvalues();
168                                  /* check files and dates */
# Line 156 | Line 171 | char   *argv[];
171          setdefaults();
172                                  /* print all values if requested */
173          if (explicate)
174 <                printvals();
175 <                                /* run simulation */
174 >                printvars(stdout);
175 >                                /* build octree (and run mkillum) */
176          oconv();
177 <        renderopts(ropts);
177 >                                /* check date on ambient file */
178 >        checkambfile();
179 >                                /* run simulation */
180 >        renderopts(ropts, popts);
181          xferopts(ropts);
182          if (rvdevice != NULL)
183 <                rview(ropts);
183 >                rview(ropts, popts);
184          else
185 <                rpict(ropts);
186 <        exit(0);
185 >                rpict(ropts, popts);
186 >        quit(0);
187   userr:
188          fprintf(stderr,
189 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
189 > "Usage: %s [-w][-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
190                          progname);
191 <        exit(1);
191 >        quit(1);
192   }
193  
194  
# Line 189 | Line 207 | register char  *rn, *fn;
207   }
208  
209  
210 < load(rfname)                    /* load Radiance simulation file */
193 < char    *rfname;
194 < {
195 <        FILE    *fp;
196 <        char    buf[256];
197 <        register char   *cp;
198 <
199 <        if (rfname == NULL)
200 <                fp = stdin;
201 <        else if ((fp = fopen(rfname, "r")) == NULL) {
202 <                perror(rfname);
203 <                exit(1);
204 <        }
205 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
206 <                for (cp = buf; *cp; cp++) {
207 <                        switch (*cp) {
208 <                        case '\\':
209 <                        case '\n':
210 <                                *cp = ' ';
211 <                                continue;
212 <                        case '#':
213 <                                *cp = '\0';
214 <                                break;
215 <                        }
216 <                        break;
217 <                }
218 <                setvariable(buf);
219 <        }
220 <        fclose(fp);
221 < }
222 <
223 <
224 < setvariable(ass)                /* assign variable according to string */
225 < register char   *ass;
226 < {
227 <        char    varname[32];
228 <        register char   *cp;
229 <        register VARIABLE       *vp;
230 <        register int    i;
231 <        int     n;
232 <
233 <        while (isspace(*ass))           /* skip leading space */
234 <                ass++;
235 <        cp = varname;                   /* extract name */
236 <        while (cp < varname+sizeof(varname)-1
237 <                        && *ass && !isspace(*ass) && *ass != '=')
238 <                *cp++ = *ass++;
239 <        *cp = '\0';
240 <        if (!varname[0])
241 <                return;         /* no variable name! */
242 <                                        /* trim value */
243 <        while (isspace(*ass) || *ass == '=')
244 <                ass++;
245 <        cp = ass + strlen(ass);
246 <        do
247 <                *cp-- = '\0';
248 <        while (cp >= ass && isspace(*cp));
249 <        n = cp - ass + 1;
250 <        if (!n) {
251 <                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
252 <                                progname, varname);
253 <                return;
254 <        }
255 <                                        /* match variable from list */
256 <        vp = matchvar(varname);
257 <        if (vp == NULL) {
258 <                fprintf(stderr, "%s: unknown variable '%s'\n",
259 <                                progname, varname);
260 <                exit(1);
261 <        }
262 <                                        /* assign new value */
263 <        cp = vp->value; i = vp->nass;
264 <        while (i--)
265 <                while (*cp++)
266 <                        ;
267 <        i = cp - vp->value;
268 <        vp->value = realloc(vp->value, i+n+1);
269 <        if (vp->value == NULL) {
270 <                perror(progname);
271 <                exit(1);
272 <        }
273 <        strcpy(vp->value+i, ass);
274 <        vp->nass++;
275 < }
276 <
277 <
278 < VARIABLE *
279 < matchvar(nam)                   /* match a variable by its name */
280 < char    *nam;
281 < {
282 <        int     n = strlen(nam);
283 <        register int    i;
284 <
285 <        for (i = 0; i < NVARS; i++)
286 <                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
287 <                        return(vv+i);
288 <        return(NULL);
289 < }
290 <
291 <
292 < char *
293 < nvalue(vp, n)                   /* return nth variable value */
294 < VARIABLE        *vp;
295 < register int    n;
296 < {
297 <        register char   *cp;
298 <
299 <        if (vp == NULL || n < 0 || n >= vp->nass)
300 <                return(NULL);
301 <        cp = vp->value;
302 <        while (n--)
303 <                while (*cp++)
304 <                        ;
305 <        return(cp);
306 < }
307 <
308 <
309 < int
310 < vscale(vc)                      /* return scale for variable vc */
311 < int     vc;
312 < {
313 <        switch(vlet(vc)) {
314 <        case 'H':
315 <                return(HIGH);
316 <        case 'M':
317 <                return(MEDIUM);
318 <        case 'L':
319 <                return(LOW);
320 <        }
321 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
324 < }
325 <
326 <
327 < checkvalues()                   /* check assignments */
328 < {
329 <        register int    i;
330 <
331 <        for (i = 0; i < NVARS; i++)
332 <                if (vv[i].fixval != NULL)
333 <                        (*vv[i].fixval)(vv+i);
334 < }
335 <
336 <
337 < onevalue(vp)                    /* only one assignment for this variable */
338 < register VARIABLE       *vp;
339 < {
340 <        if (vp->nass < 2)
341 <                return;
342 <        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
343 <                        progname, vp->name);
344 <        do
345 <                vp->value += strlen(vp->value)+1;
346 <        while (--vp->nass > 1);
347 < }
348 <
349 <
350 < catvalues(vp)                   /* concatenate variable values */
351 < register VARIABLE       *vp;
352 < {
353 <        register char   *cp;
354 <
355 <        if (vp->nass < 2)
356 <                return;
357 <        for (cp = vp->value; vp->nass > 1; vp->nass--) {
358 <                while (*cp)
359 <                        cp++;
360 <                *cp++ = ' ';
361 <        }
362 < }
363 <
364 <
365 < long
210 > time_t
211   checklast(fnames)                       /* check files and find most recent */
212   register char   *fnames;
213   {
214          char    thisfile[MAXPATH];
215 <        long    thisdate, lastdate = -1;
215 >        time_t  thisdate, lastdate = 0;
216          register char   *cp;
217  
218 +        if (fnames == NULL)
219 +                return(0);
220          while (*fnames) {
221                  while (isspace(*fnames)) fnames++;
222                  cp = thisfile;
223 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
223 >                while (*fnames && !isspace(*fnames))
224 >                        *cp++ = *fnames++;
225                  *cp = '\0';
226 <                if ((thisdate = fdate(thisfile)) < 0) {
227 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
226 >                if (!(thisdate = fdate(thisfile)))
227 >                        syserr(thisfile);
228                  if (thisdate > lastdate)
229                          lastdate = thisdate;
230          }
# Line 386 | Line 232 | register char  *fnames;
232   }
233  
234  
235 + char *
236 + newfname(orig, pred)            /* create modified file name */
237 + char    *orig;
238 + int     pred;
239 + {
240 +        extern char     *rindex();
241 +        register char   *cp;
242 +        register int    n;
243 +        int     suffix;
244 +
245 +        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
246 +        while (*cp) {
247 +                if (*cp == '.') suffix = n;
248 +                else if (ISDIRSEP(*cp)) suffix = -1;
249 +                cp++; n++;
250 +        }
251 +        if (suffix == -1) suffix = n;
252 +        if ((cp = bmalloc(n+2)) == NULL)
253 +                syserr(progname);
254 +        strncpy(cp, orig, suffix);
255 +        cp[suffix] = pred;                      /* root name + pred + suffix */
256 +        strcpy(cp+suffix+1, orig+suffix);
257 +        return(cp);
258 + }
259 +
260 +
261   checkfiles()                    /* check for existence and modified times */
262   {
263 <        char    *cp;
392 <        long    objdate;
263 >        time_t  objdate;
264  
265          if (!vdef(OCTREE)) {
266 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
267 <                        perror(progname);
268 <                        exit(1);
398 <                }
399 <                sprintf(cp, "%s.oct", radname);
400 <                vval(OCTREE) = cp;
266 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
267 >                        syserr(progname);
268 >                sprintf(vval(OCTREE), "%s.oct", radname);
269                  vdef(OCTREE)++;
270          }
271          octreedate = fdate(vval(OCTREE));
272 <        scenedate = -1;
273 <        if (vdef(SCENE)) {
274 <                scenedate = checklast(vval(SCENE));
275 <                if (vdef(OBJECT)) {
276 <                        objdate = checklast(vval(OBJECT));
277 <                        if (objdate > scenedate)
278 <                                scenedate = objdate;
279 <                }
272 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
273 >                oct0name = newfname(vval(OCTREE), '0');
274 >                oct1name = newfname(vval(OCTREE), '1');
275 >                oct0date = fdate(oct0name);
276 >                oct1date = fdate(oct1name);
277 >        } else
278 >                oct0name = oct1name = vval(OCTREE);
279 >        if ((scenedate = checklast(vval(SCENE))) &&
280 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
281 >                scenedate = objdate;
282 >        illumdate = checklast(vval(ILLUM));
283 >        if (!octreedate & !scenedate & !illumdate) {
284 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
285 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
286 >                quit(1);
287          }
288 <        if (octreedate < 0 & scenedate < 0) {
414 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
415 <                                vnam(OCTREE), vnam(SCENE));
416 <                exit(1);
417 <        }
288 >        matdate = checklast(vval(MATERIAL));
289   }      
290  
291  
# Line 423 | Line 294 | double org[3], *sizp;
294   {
295          extern FILE     *popen();
296          static double   oorg[3], osiz = 0.;
297 <        char    buf[MAXPATH+16];
297 >        double  min[3], max[3];
298 >        char    buf[1024];
299          FILE    *fp;
300 +        register int    i;
301  
302 <        if (osiz <= FTINY) {
303 <                oconv();                /* does nothing if done already */
304 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
305 <                if ((fp = popen(buf, "r")) == NULL) {
306 <                        perror("getinfo");
307 <                        exit(1);
308 <                }
309 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
310 <                                &oorg[2], &osiz) != 4) {
311 <                        fprintf(stderr,
302 >        if (osiz <= FTINY)
303 >                if (noaction && fdate(oct1name) <
304 >                                (scenedate>illumdate?scenedate:illumdate)) {
305 >                                                        /* run getbbox */
306 >                        sprintf(buf, "getbbox -w -h %s",
307 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
308 >                        if ((fp = popen(buf, "r")) == NULL)
309 >                                syserr("getbbox");
310 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
311 >                                        &min[0], &max[0], &min[1], &max[1],
312 >                                        &min[2], &max[2]) != 6) {
313 >                                fprintf(stderr,
314 >                        "%s: error reading bounding box from getbbox\n",
315 >                                                progname);
316 >                                quit(1);
317 >                        }
318 >                        for (i = 0; i < 3; i++)
319 >                                if (max[i] - min[i] > osiz)
320 >                                        osiz = max[i] - min[i];
321 >                        for (i = 0; i < 3; i++)
322 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
323 >                        pclose(fp);
324 >                } else {                                /* from octree */
325 >                        oconv();        /* does nothing if done already */
326 >                        sprintf(buf, "getinfo -d < %s", oct1name);
327 >                        if ((fp = popen(buf, "r")) == NULL)
328 >                                syserr("getinfo");
329 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
330 >                                        &oorg[2], &osiz) != 4) {
331 >                                fprintf(stderr,
332                          "%s: error reading bounding cube from getinfo\n",
333 <                                        progname);
334 <                        exit(1);
333 >                                                progname);
334 >                                quit(1);
335 >                        }
336 >                        pclose(fp);
337                  }
443                pclose(fp);
444        }
338          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
339   }
340  
# Line 458 | Line 351 | setdefaults()                  /* set default values for unassigned v
351                  vval(ZONE) = savqstr(buf);
352                  vdef(ZONE)++;
353          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
354          if (!vdef(INDIRECT)) {
355                  vval(INDIRECT) = "0";
356                  vdef(INDIRECT)++;
# Line 478 | Line 367 | setdefaults()                  /* set default values for unassigned v
367                  vval(PICTURE) = radname;
368                  vdef(PICTURE)++;
369          }
370 <        if (!vdef(VIEW)) {
371 <                vval(VIEW) = "X";
372 <                vdef(VIEW)++;
370 >        if (!vdef(VIEWS)) {
371 >                vval(VIEWS) = "X";
372 >                vdef(VIEWS)++;
373          }
374          if (!vdef(DETAIL)) {
375                  vval(DETAIL) = "M";
# Line 497 | Line 386 | setdefaults()                  /* set default values for unassigned v
386   }
387  
388  
389 < printvals()                     /* print variable values */
389 > oconv()                         /* run oconv and mkillum if necessary */
390   {
391 <        register int    i, j;
391 >        static char     illumtmp[] = "ilXXXXXX";
392 >        char    combuf[1024], ocopts[64], mkopts[64];
393  
394 <        for (i = 0; i < NVARS; i++)
395 <                for (j = 0; j < vv[i].nass; j++)
396 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
397 <        fflush(stdout);
398 < }
399 <
400 <
401 < oconv()                         /* run oconv if necessary */
402 < {
403 <        char    combuf[512], ocopts[64];
404 <
405 <        if (octreedate >= scenedate)    /* check dates */
406 <                return;
407 <                                        /* build command */
408 <        oconvopts(ocopts);
409 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
410 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
411 <                        vval(SCENE), vval(OCTREE));
412 <        if (!silent) {                  /* echo it */
413 <                printf("\t%s\n", combuf);
414 <                fflush(stdout);
394 >        oconvopts(ocopts);              /* get options */
395 >        if (octreedate < scenedate) {   /* check date on original octree */
396 >                if (touchonly && octreedate)
397 >                        touch(vval(OCTREE));
398 >                else {                          /* build command */
399 >                        if (vdef(MATERIAL))
400 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
401 >                                                vval(MATERIAL), vval(SCENE),
402 >                                                vval(OCTREE));
403 >                        else
404 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
405 >                                                vval(SCENE), vval(OCTREE));
406 >                        
407 >                        if (runcom(combuf)) {           /* run it */
408 >                                fprintf(stderr,
409 >                                "%s: error generating octree\n\t%s removed\n",
410 >                                                progname, vval(OCTREE));
411 >                                unlink(vval(OCTREE));
412 >                                quit(1);
413 >                        }
414 >                }
415 >                octreedate = time((time_t *)NULL);
416 >                if (octreedate < scenedate)     /* in case clock is off */
417 >                        octreedate = scenedate;
418          }
419 <        if (noaction)
419 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
420 >                oct1date = octreedate > matdate ? octreedate : matdate;
421 >        if (oct1date >= octreedate & oct1date >= matdate
422 >                        & oct1date >= illumdate)        /* all done */
423                  return;
424 <        if (system(combuf)) {           /* run it */
425 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
426 <                                progname, vval(OCTREE));
427 <                unlink(vval(OCTREE));
428 <                exit(1);
424 >                                                /* make octree0 */
425 >        if (oct0date < scenedate | oct0date < illumdate) {
426 >                if (touchonly && oct0date)
427 >                        touch(oct0name);
428 >                else {                          /* build command */
429 >                        if (octreedate)
430 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
431 >                                        vval(OCTREE), vval(ILLUM), oct0name);
432 >                        else if (vdef(MATERIAL))
433 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
434 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
435 >                        else
436 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
437 >                                        vval(ILLUM), oct0name);
438 >                        if (runcom(combuf)) {           /* run it */
439 >                                fprintf(stderr,
440 >                                "%s: error generating octree\n\t%s removed\n",
441 >                                                progname, oct0name);
442 >                                unlink(oct0name);
443 >                                quit(1);
444 >                        }
445 >                }
446 >                oct0date = time((time_t *)NULL);
447 >                if (oct0date < octreedate)      /* in case clock is off */
448 >                        oct0date = octreedate;
449 >                if (oct0date < illumdate)       /* ditto */
450 >                        oct0date = illumdate;
451 >                }
452 >        if (touchonly && oct1date)
453 >                touch(oct1name);
454 >        else {
455 >                mkillumopts(mkopts);            /* build mkillum command */
456 >                mktemp(illumtmp);
457 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
458 >                                oct0name, vval(ILLUM), illumtmp);
459 >                if (runcom(combuf)) {                   /* run it */
460 >                        fprintf(stderr, "%s: error running mkillum\n",
461 >                                        progname);
462 >                        unlink(illumtmp);
463 >                        quit(1);
464 >                }
465 >                                                /* make octree1 (frozen) */
466 >                if (octreedate)
467 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
468 >                                vval(OCTREE), illumtmp, oct1name);
469 >                else if (vdef(MATERIAL))
470 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
471 >                                vval(MATERIAL), illumtmp, oct1name);
472 >                else
473 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
474 >                                illumtmp, oct1name);
475 >                if (runcom(combuf)) {           /* run it */
476 >                        fprintf(stderr,
477 >                                "%s: error generating octree\n\t%s removed\n",
478 >                                        progname, oct1name);
479 >                        unlink(oct1name);
480 >                        unlink(illumtmp);
481 >                        quit(1);
482 >                }
483 >                rmfile(illumtmp);
484          }
485 <        octreedate = time(0);
485 >        oct1date = time((time_t *)NULL);
486 >        if (oct1date < oct0date)        /* in case clock is off */
487 >                oct1date = oct0date;
488   }
489  
490  
# Line 557 | Line 510 | register char  *oo;
510   }
511  
512  
513 + mkillumopts(mo)                         /* get mkillum options */
514 + register char   *mo;
515 + {
516 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
517 +
518 +        *mo = '\0';
519 +        if (vdef(MKILLUM))
520 +                addarg(mo, vval(MKILLUM));
521 + }
522 +
523 +
524 + checkambfile()                  /* check date on ambient file */
525 + {
526 +        time_t  afdate;
527 +
528 +        if (!vdef(AMBFILE))
529 +                return;
530 +        if (!(afdate = fdate(vval(AMBFILE))))
531 +                return;
532 +        if (oct1date > afdate)
533 +                if (touchonly)
534 +                        touch(vval(AMBFILE));
535 +                else
536 +                        rmfile(vval(AMBFILE));
537 + }
538 +
539 +
540   double
541   ambval()                                /* compute ambient value */
542   {
543 <        if (vdef(EXPOSURE))
543 >        if (vdef(EXPOSURE)) {
544                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
545 <                        return(.5/pow(2.,atof(vval(EXPOSURE))));
546 <                else
547 <                        return(.5/atof(vval(EXPOSURE)));
545 >                        return(.5/pow(2.,vflt(EXPOSURE)));
546 >                return(.5/vflt(EXPOSURE));
547 >        }
548          if (vlet(ZONE) == 'E')
549                  return(10.);
550 <        else
550 >        if (vlet(ZONE) == 'I')
551                  return(.01);
552 +        badvalue(ZONE);
553   }
554  
555  
556 < lowqopts(op)                            /* low quality rendering options */
556 > renderopts(op, po)                      /* set rendering options */
557 > char    *op, *po;
558 > {
559 >        switch(vscale(QUALITY)) {
560 >        case LOW:
561 >                lowqopts(op, po);
562 >                break;
563 >        case MEDIUM:
564 >                medqopts(op, po);
565 >                break;
566 >        case HIGH:
567 >                hiqopts(op, po);
568 >                break;
569 >        }
570 > }
571 >
572 >
573 > lowqopts(op, po)                        /* low quality rendering options */
574   register char   *op;
575 + char    *po;
576   {
577          double  d, org[3], siz[3];
578  
579          *op = '\0';
580 +        *po = '\0';
581          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
582 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
583 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
582 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
583 >                badvalue(ZONE);
584          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
585 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
586 +                badvalue(ZONE);
587          getoctcube(org, &d);
588          d *= 3./(siz[0]+siz[1]+siz[2]);
589          switch (vscale(DETAIL)) {
590          case LOW:
591 <                op = addarg(op, "-ps 16");
592 <                op = addarg(op, "-dp 16");
591 >                po = addarg(po, "-ps 16");
592 >                op = addarg(op, "-dp 64");
593                  sprintf(op, " -ar %d", (int)(4*d));
594                  op += strlen(op);
595                  break;
596          case MEDIUM:
597 <                op = addarg(op, "-ps 8");
598 <                op = addarg(op, "-dp 32");
597 >                po = addarg(po, "-ps 8");
598 >                op = addarg(op, "-dp 128");
599                  sprintf(op, " -ar %d", (int)(8*d));
600                  op += strlen(op);
601                  break;
602          case HIGH:
603 <                op = addarg(op, "-ps 4");
604 <                op = addarg(op, "-dp 64");
603 >                po = addarg(po, "-ps 4");
604 >                op = addarg(op, "-dp 256");
605                  sprintf(op, " -ar %d", (int)(16*d));
606                  op += strlen(op);
607                  break;
608          }
609 <        op = addarg(op, "-pt .16");
609 >        po = addarg(po, "-pt .16");
610          if (vbool(PENUMBRAS))
611                  op = addarg(op, "-ds .4");
612 <        op = addarg(op, "-dt .2");
613 <        op = addarg(op, "-dc .25");
614 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
612 >        else
613 >                op = addarg(op, "-ds 0");
614 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
615          if (vdef(AMBFILE)) {
616                  sprintf(op, " -af %s", vval(AMBFILE));
617                  op += strlen(op);
# Line 623 | Line 619 | register char  *op;
619                  overture = 0;
620          switch (vscale(VARIABILITY)) {
621          case LOW:
622 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
622 >                op = addarg(op, "-aa .4 -ad 64");
623                  break;
624          case MEDIUM:
625 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
625 >                op = addarg(op, "-aa .3 -ad 128");
626                  break;
627          case HIGH:
628 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
628 >                op = addarg(op, "-aa .25 -ad 256");
629                  break;
630          }
631          op = addarg(op, "-as 0");
632          d = ambval();
633          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
634          op += strlen(op);
635 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
635 >        op = addarg(op, "-lr 3 -lw .02");
636          if (vdef(RENDER))
637                  op = addarg(op, vval(RENDER));
638   }
639  
640  
641 < medqopts(op)                            /* medium quality rendering options */
641 > medqopts(op, po)                        /* medium quality rendering options */
642   register char   *op;
643 + char    *po;
644   {
645 <        double  d, org[3], siz[3];
645 >        double  d, org[3], siz[3], asz;
646  
647          *op = '\0';
648 +        *po = '\0';
649          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
650 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
651 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
650 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
651 >                badvalue(ZONE);
652          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
653 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
654 +                badvalue(ZONE);
655          getoctcube(org, &d);
656 <        d *= 3./(siz[0]+siz[1]+siz[2]);
656 >        asz = (siz[0]+siz[1]+siz[2])/3.;
657 >        d /= asz;
658          switch (vscale(DETAIL)) {
659          case LOW:
660 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
661 <                op = addarg(op, "-dp 64");
660 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
661 >                op = addarg(op, "-dp 256");
662                  sprintf(op, " -ar %d", (int)(8*d));
663                  op += strlen(op);
664 +                sprintf(op, " -ms %.2g", asz/20.);
665 +                op += strlen(op);
666                  break;
667          case MEDIUM:
668 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
669 <                op = addarg(op, "-dp 128");
668 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
669 >                op = addarg(op, "-dp 512");
670                  sprintf(op, " -ar %d", (int)(16*d));
671                  op += strlen(op);
672 +                sprintf(op, " -ms %.2g", asz/40.);
673 +                op += strlen(op);
674                  break;
675          case HIGH:
676 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
677 <                op = addarg(op, "-dp 256");
676 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
677 >                op = addarg(op, "-dp 1024");
678                  sprintf(op, " -ar %d", (int)(32*d));
679                  op += strlen(op);
680 +                sprintf(op, " -ms %.2g", asz/80.);
681 +                op += strlen(op);
682                  break;
683          }
684 <        op = addarg(op, "-pt .08");
685 <        if (vbool(PENUMBRAS)) {
686 <                op = addarg(op, "-ds .2");
687 <                op = addarg(op, "-dj .35");
688 <        } else
684 >        po = addarg(po, "-pt .08");
685 >        if (vbool(PENUMBRAS))
686 >                op = addarg(op, "-ds .2 -dj .5");
687 >        else
688                  op = addarg(op, "-ds .3");
689 <        op = addarg(op, "-dt .1");
690 <        op = addarg(op, "-dc .5");
691 <        op = addarg(op, "-dr 1");
692 <        op = addarg(op, "-sj .7");
693 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
689 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
690 >        if (overture = vint(INDIRECT)) {
691 >                sprintf(op, " -ab %d", overture);
692 >                op += strlen(op);
693 >        }
694          if (vdef(AMBFILE)) {
695                  sprintf(op, " -af %s", vval(AMBFILE));
696                  op += strlen(op);
# Line 701 | Line 698 | register char  *op;
698                  overture = 0;
699          switch (vscale(VARIABILITY)) {
700          case LOW:
701 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
701 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
702                  break;
703          case MEDIUM:
704 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
704 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
705                  break;
706          case HIGH:
707 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
707 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
708                  break;
709          }
710          d = ambval();
711          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
712          op += strlen(op);
713 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
713 >        op = addarg(op, "-lr 6 -lw .002");
714          if (vdef(RENDER))
715                  op = addarg(op, vval(RENDER));
716   }
717  
718  
719 < hiqopts(op)                             /* high quality rendering options */
719 > hiqopts(op, po)                         /* high quality rendering options */
720   register char   *op;
721 + char    *po;
722   {
723 <        double  d, org[3], siz[3];
723 >        double  d, org[3], siz[3], asz;
724  
725          *op = '\0';
726 +        *po = '\0';
727          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
728 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
729 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
728 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
729 >                badvalue(ZONE);
730          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
731 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
732 +                badvalue(ZONE);
733          getoctcube(org, &d);
734 <        d *= 3./(siz[0]+siz[1]+siz[2]);
734 >        asz = (siz[0]+siz[1]+siz[2])/3.;
735 >        d /= asz;
736          switch (vscale(DETAIL)) {
737          case LOW:
738 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
739 <                op = addarg(op, "-dp 256");
738 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
739 >                op = addarg(op, "-dp 1024");
740                  sprintf(op, " -ar %d", (int)(16*d));
741                  op += strlen(op);
742 +                sprintf(op, " -ms %.2g", asz/40.);
743 +                op += strlen(op);
744                  break;
745          case MEDIUM:
746 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
747 <                op = addarg(op, "-dp 512");
746 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
747 >                op = addarg(op, "-dp 2048");
748                  sprintf(op, " -ar %d", (int)(32*d));
749                  op += strlen(op);
750 +                sprintf(op, " -ms %.2g", asz/80.);
751 +                op += strlen(op);
752                  break;
753          case HIGH:
754 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
755 <                op = addarg(op, "-dp 1024");
754 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
755 >                op = addarg(op, "-dp 4096");
756                  sprintf(op, " -ar %d", (int)(64*d));
757                  op += strlen(op);
758 +                sprintf(op, " -ms %.2g", asz/160.);
759 +                op += strlen(op);
760                  break;
761          }
762 <        op = addarg(op, "-pt .04");
763 <        if (vbool(PENUMBRAS)) {
764 <                op = addarg(op, "-ds .1");
765 <                op = addarg(op, "-dj .7");
768 <        } else
762 >        po = addarg(po, "-pt .04");
763 >        if (vbool(PENUMBRAS))
764 >                op = addarg(op, "-ds .1 -dj .65");
765 >        else
766                  op = addarg(op, "-ds .2");
767 <        op = addarg(op, "-dt .05");
771 <        op = addarg(op, "-dc .75");
772 <        op = addarg(op, "-dr 3");
773 <        op = addarg(op, "-sj 1");
774 <        op = addarg(op, "-st .03");
767 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
768          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
769          op += strlen(op);
770          if (vdef(AMBFILE)) {
# Line 781 | Line 774 | register char  *op;
774                  overture = 0;
775          switch (vscale(VARIABILITY)) {
776          case LOW:
777 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
777 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
778                  break;
779          case MEDIUM:
780 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
780 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
781                  break;
782          case HIGH:
783 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
783 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
784                  break;
785          }
786          d = ambval();
787          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
788          op += strlen(op);
789 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
789 >        op = addarg(op, "-lr 12 -lw .0005");
790          if (vdef(RENDER))
791                  op = addarg(op, vval(RENDER));
792   }
# Line 810 | Line 796 | xferopts(ro)                           /* transfer options if indicated */
796   char    *ro;
797   {
798          int     fd, n;
799 +        register char   *cp;
800          
801          n = strlen(ro);
802          if (n < 2)
803                  return;
804          if (vdef(OPTFILE)) {
805 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
806 <                        perror(vval(OPTFILE));
807 <                        exit(1);
808 <                }
809 <                if (write(fd, ro+1, n-1) != n-1) {
810 <                        perror(vval(OPTFILE));
811 <                        exit(1);
812 <                }
813 <                write(fd, "\n", 1);
814 <                close(fd);
815 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
805 >                for (cp = ro; cp[1]; cp++)
806 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
807 >                                        (cp[2] == '-' && isalpha(cp[3]))))
808 >                                *cp = '\n';
809 >                        else
810 >                                *cp = cp[1];
811 >                *cp = '\n';
812 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
813 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
814 >                        syserr(vval(OPTFILE));
815 >                sprintf(ro, " @%s", vval(OPTFILE));
816          }
817   #ifdef MSDOS
818          else if (n > 50) {
819 <                register char   *evp = bmalloc(n+6);
835 <                if (evp == NULL) {
836 <                        perror(progname);
837 <                        exit(1);
838 <                }
839 <                strcpy(evp, "ROPT=");
840 <                strcat(evp, ro);
841 <                if (putenv(evp) != 0) {
842 <                        fprintf(stderr, "%s: out of environment space\n",
843 <                                        progname);
844 <                        exit(1);
845 <                }
819 >                setenv("ROPT", ro+1);
820                  strcpy(ro, " $ROPT");
821          }
822   #endif
# Line 857 | Line 831 | register char  *po;
831                  po = addarg(po, "-1 -e");
832                  po = addarg(po, vval(EXPOSURE));
833          }
834 <        if (vscale(QUALITY) == HIGH)
835 <                po = addarg(po, "-r .65");
834 >        switch (vscale(QUALITY)) {
835 >        case MEDIUM:
836 >                po = addarg(po, "-r 1");
837 >                break;
838 >        case HIGH:
839 >                po = addarg(po, "-m .25");
840 >                break;
841 >        }
842          if (vdef(PFILT))
843                  po = addarg(po, vval(PFILT));
844   }
# Line 880 | Line 860 | char *
860   specview(vs)                            /* get proper view spec from vs */
861   register char   *vs;
862   {
863 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
864 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
865          static char     viewopts[128];
866          register char   *cp;
867 <        int     xpos, ypos, zpos, viewtype;
868 <        int     exterior;
867 >        int     xpos, ypos, zpos, viewtype, upax;
868 >        register int    i;
869          double  cent[3], dim[3], mult, d;
870  
871          if (vs == NULL || *vs == '-')
872                  return(vs);
873 +        upax = 0;                       /* get the up vector */
874 +        if (vdef(UP)) {
875 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
876 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
877 +                else
878 +                        upax = 1-'X'+vlet(UP);
879 +                if (upax < 1 | upax > 3)
880 +                        badvalue(UP);
881 +                if (vval(UP)[0] == '-')
882 +                        upax = -upax;
883 +        }
884                                          /* check standard view names */
885          xpos = ypos = zpos = 0;
893        viewtype = 0;
886          if (*vs == 'X') {
887                  xpos = 1; vs++;
888          } else if (*vs == 'x') {
# Line 906 | Line 898 | register char  *vs;
898          } else if (*vs == 'z') {
899                  zpos = -1; vs++;
900          }
901 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
901 >        viewtype = 'v';
902 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
903                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
904          cp = viewopts;
905 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
905 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
906                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
907                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
908                                  &cent[0], &dim[0], &cent[1], &dim[1],
909 <                                &cent[2], &dim[2]) != 6) {
910 <                        fprintf(stderr, "%s: bad zone specification\n",
911 <                                        progname);
912 <                        exit(1);
909 >                                &cent[2], &dim[2]) != 6)
910 >                        badvalue(ZONE);
911 >                for (i = 0; i < 3; i++) {
912 >                        dim[i] -= cent[i];
913 >                        if (dim[i] <= FTINY)
914 >                                badvalue(ZONE);
915 >                        cent[i] += .5*dim[i];
916                  }
917 <                dim[0] -= cent[0]; cent[0] += .5*dim[0];
924 <                dim[1] -= cent[1]; cent[1] += .5*dim[1];
925 <                dim[2] -= cent[2]; cent[2] += .5*dim[2];
926 <                exterior = vlet(ZONE) == 'E';
927 <                mult = exterior ? 2. : .45 ;
917 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
918                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
919                                  cent[0]+xpos*mult*dim[0],
920                                  cent[1]+ypos*mult*dim[1],
921                                  cent[2]+zpos*mult*dim[2],
922                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
923                  cp += strlen(cp);
924 <                switch (vlet(UP)) {
925 <                case 'Z':
926 <                        if (xpos|ypos) {
927 <                                cp = addarg(cp, "-vu 0 0 1");
928 <                                break;
929 <                        }
930 <                /* fall through */
941 <                case 'Y':
942 <                        if (xpos|zpos) {
943 <                                cp = addarg(cp, "-vu 0 1 0");
944 <                                break;
945 <                        }
946 <                /* fall through */
947 <                case 'X':
948 <                        if (ypos|zpos)
949 <                                cp = addarg(cp, "-vu 1 0 0");
950 <                        else
951 <                                cp = addarg(cp, "-vu 0 0 1");
924 >                                        /* redirect up axis if necessary */
925 >                switch (upax) {
926 >                case 3:                 /* plus or minus Z axis */
927 >                case -3:
928 >                case 0:
929 >                        if (!(xpos|ypos))
930 >                                upax = 2;
931                          break;
932 <                default:
933 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
934 <                                        progname, vnam(UP));
935 <                        exit(1);
932 >                case 2:                 /* plus or minus Y axis */
933 >                case -2:
934 >                        if (!(xpos|zpos))
935 >                                upax = 1;
936 >                        break;
937 >                case 1:                 /* plus or minus X axis */
938 >                case -1:
939 >                        if (!(ypos|zpos))
940 >                                upax = 3;
941 >                        break;
942                  }
943 +                cp = addarg(cp, vup[upax+3]);
944                  switch (viewtype) {
945                  case 'v':
946                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 968 | Line 954 | register char  *vs;
954                  case 'h':
955                          cp = addarg(cp, "-vh 180 -vv 180");
956                          break;
957 +                case 'c':
958 +                        cp = addarg(cp, "-vh 180 -vv 90");
959 +                        break;
960                  }
961 <        } else
962 <                while (*vs && !isspace(*vs))    /* else skip id */
963 <                        vs++;
964 <                                        /* append any additional options */
965 <        while (isspace(*vs)) vs++;
961 >        } else {
962 >                while (!isspace(*vs))           /* else skip id */
963 >                        if (!*vs++)
964 >                                return(NULL);
965 >                if (upax) {                     /* specify up vector */
966 >                        strcpy(cp, vup[upax+3]);
967 >                        cp += strlen(cp);
968 >                }
969 >        }
970 >        if (cp == viewopts)             /* append any additional options */
971 >                vs++;           /* skip prefixed space if unneeded */
972          strcpy(cp, vs);
973 + #ifdef MSDOS
974 +        if (strlen(viewopts) > 40) {
975 +                setenv("VIEW", viewopts);
976 +                return("$VIEW");
977 +        }
978 + #endif
979          return(viewopts);
980   }
981  
# Line 982 | Line 983 | register char  *vs;
983   char *
984   getview(n, vn)                          /* get view n, or NULL if none */
985   int     n;
986 < char    *vn;
986 > char    *vn;            /* returned view name */
987   {
988          register char   *mv;
989  
990 <        if (viewselect != NULL) {
990 >        if (viewselect != NULL) {               /* command-line selected */
991                  if (n)                          /* only do one */
992                          return(NULL);
993                  if (viewselect[0] == '-') {     /* already specified */
# Line 999 | Line 1000 | char   *vn;
1000                                  ;
1001                          *vn = '\0';
1002                  }
1003 +                                                /* view number? */
1004 +                if (isint(viewselect))
1005 +                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1006                                                  /* check list */
1007 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1007 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1008                          if (matchword(viewselect, mv))
1009                                  return(specview(mv));
1010                  return(specview(viewselect));   /* standard view? */
1011          }
1012 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1013 <                if (*mv != '-')
1014 <                        while (*mv && !isspace(*mv))
1015 <                                *vn++ = *mv++;
1012 >        mv = nvalue(VIEWS, n);          /* use view n */
1013 >        if (vn != NULL & mv != NULL) {
1014 >                register char   *mv2 = mv;
1015 >                if (*mv2 != '-')
1016 >                        while (*mv2 && !isspace(*mv2))
1017 >                                *vn++ = *mv2++;
1018                  *vn = '\0';
1019          }
1020 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1020 >        return(specview(mv));
1021   }
1022  
1023  
1024 < rview(opts)                             /* run rview with first view */
1025 < char    *opts;
1024 > printview(vopts)                        /* print out selected view */
1025 > register char   *vopts;
1026   {
1027 +        extern char     *strstr(), *atos(), *getenv();
1028 +        VIEW    vwr;
1029 +        char    buf[128];
1030 +        register char   *cp;
1031 + again:
1032 +        if (vopts == NULL)
1033 +                return(-1);
1034 + #ifdef MSDOS
1035 +        if (vopts[0] == '$') {
1036 +                vopts = getenv(vopts+1);
1037 +                goto again;
1038 +        }
1039 + #endif
1040 +        copystruct(&vwr, &stdview);
1041 +        cp = vopts;                             /* get -vf files first */
1042 +        while ((cp = strstr(cp, "-vf ")) != NULL &&
1043 +                        *atos(buf, sizeof(buf), cp += 4))
1044 +                viewfile(buf, &vwr, NULL);
1045 +        sscanview(&vwr, vopts);                 /* get the rest */
1046 +        fputs(VIEWSTR, stdout);
1047 +        fprintview(&vwr, stdout);               /* print full spec. */
1048 +        fputc('\n', stdout);
1049 +        return(0);
1050 + }
1051 +
1052 +
1053 + rview(opts, po)                         /* run rview with first view */
1054 + char    *opts, *po;
1055 + {
1056 +        char    *vw;
1057          char    combuf[512];
1058                                          /* build command */
1059 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1059 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1060 >                return;
1061 >        if (sayview)
1062 >                printview(vw);
1063 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1064          if (rvdevice != NULL)
1065                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1066 <        strcat(combuf, vval(OCTREE));
1067 <        if (!silent) {                  /* echo it */
1068 <                printf("\t%s\n", combuf);
1069 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        if (system(combuf)) {           /* run it */
1066 >        if (vdef(EXPOSURE))
1067 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1068 >        strcat(combuf, oct1name);
1069 >        if (runcom(combuf)) {           /* run it */
1070                  fprintf(stderr, "%s: error running rview\n", progname);
1071 <                exit(1);
1071 >                quit(1);
1072          }
1073   }
1074  
1075  
1076 < rpict(opts)                             /* run rpict and pfilt for each view */
1077 < char    *opts;
1076 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1077 > char    *opts, *po;
1078   {
1079          char    combuf[1024];
1080 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1081 <        char    pfopts[64];
1080 >        char    rawfile[MAXPATH], picfile[MAXPATH];
1081 >        char    zopt[MAXPATH+4], rep[MAXPATH+16], res[32];
1082 >        char    pfopts[128];
1083          char    vs[32], *vw;
1084          int     vn, mult;
1085 +        time_t  rfdt, pfdt;
1086                                          /* get pfilt options */
1087          pfiltopts(pfopts);
1088                                          /* get resolution, reporting */
1089 <        mult = vscale(QUALITY)+1;
1089 >        switch (vscale(QUALITY)) {
1090 >        case LOW:
1091 >                mult = 1;
1092 >                break;
1093 >        case MEDIUM:
1094 >                mult = 2;
1095 >                break;
1096 >        case HIGH:
1097 >                mult = 3;
1098 >                break;
1099 >        }
1100          {
1101                  int     xres, yres;
1102                  double  aspect;
# Line 1060 | Line 1108 | char   *opts;
1108                  else if (n) {
1109                          if (n == 1) yres = xres;
1110                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1111 <                } else {
1112 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1111 >                } else
1112 >                        badvalue(RESOLUTION);
1113          }
1114          rep[0] = '\0';
1115          if (vdef(REPORT)) {
# Line 1075 | Line 1120 | char   *opts;
1120                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1121                  else if (n == 1)
1122                          sprintf(rep, " -t %d", (int)(minutes*60));
1123 <                else {
1124 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1123 >                else
1124 >                        badvalue(REPORT);
1125          }
1126                                          /* do each view */
1127          vn = 0;
1128          while ((vw = getview(vn++, vs)) != NULL) {
1129 +                if (sayview)
1130 +                        printview(vw);
1131                  if (!vs[0])
1132                          sprintf(vs, "%d", vn);
1133                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1134 +                if (vdef(ZFILE))
1135 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1136 +                else
1137 +                        zopt[0] = '\0';
1138                                                  /* check date on picture */
1139 <                if (fdate(picfile) > octreedate)
1139 >                pfdt = fdate(picfile);
1140 >                if (pfdt >= oct1date)
1141                          continue;
1142 +                                                /* get raw file name */
1143 +                sprintf(rawfile, "%s_%s.unf",
1144 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1145 +                rfdt = fdate(rawfile);
1146 +                if (touchonly) {                /* update times only */
1147 +                        if (rfdt) {
1148 +                                if (rfdt < oct1date)
1149 +                                        touch(rawfile);
1150 +                        } else if (pfdt && pfdt < oct1date)
1151 +                                touch(picfile);
1152 +                        continue;
1153 +                }
1154                                                  /* build rpict command */
1155 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1156 <                if (fdate(rawfile) > octreedate)        /* recover */
1157 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1097 <                                        rep, opts, rawfile, vval(OCTREE));
1155 >                if (rfdt >= oct1date)           /* recover */
1156 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1157 >                                rep, po, opts, zopt, rawfile, oct1name);
1158                  else {
1159                          if (overture) {         /* run overture calculation */
1160                                  sprintf(combuf,
1161                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1162                                                  rep, vw, opts,
1163 <                                                vval(OCTREE), rawfile);
1164 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1163 >                                                oct1name, overfile);
1164 >                                if (runcom(combuf)) {
1165                                          fprintf(stderr,
1166 <                        "%s: error in overture for view %s\n\t%s removed\n",
1167 <                                                progname, vs, rawfile);
1168 <                                        unlink(rawfile);
1113 <                                        exit(1);
1166 >                                        "%s: error in overture for view %s\n",
1167 >                                                progname, vs);
1168 >                                        quit(1);
1169                                  }
1170 + #ifdef NIX
1171 +                                rmfile(overfile);
1172 + #endif
1173                          }
1174 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1175 <                                        rep, vw, res, opts,
1176 <                                        vval(OCTREE), rawfile);
1174 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1175 >                                        rep, vw, res, po, opts, zopt,
1176 >                                        oct1name, rawfile);
1177                  }
1178 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1178 >                if (runcom(combuf)) {           /* run rpict */
1179                          fprintf(stderr, "%s: error rendering view %s\n",
1180                                          progname, vs);
1181 <                        exit(1);
1181 >                        quit(1);
1182                  }
1183 +                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1184                                                  /* build pfilt command */
1185 <                if (mult > 1)
1186 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1185 >                        if (mult > 1)
1186 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1187                                          pfopts, mult, mult, rawfile, picfile);
1188 <                else
1189 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1190 <                                        rawfile, picfile);
1191 <                if (!silent) {                  /* echo pfilt command */
1192 <                        printf("\t%s\n", combuf);
1193 <                        fflush(stdout);
1188 >                        else
1189 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1190 >                                                rawfile, picfile);
1191 >                        if (runcom(combuf)) {           /* run pfilt */
1192 >                                fprintf(stderr,
1193 >                                "%s: error filtering view %s\n\t%s removed\n",
1194 >                                                progname, vs, picfile);
1195 >                                unlink(picfile);
1196 >                                quit(1);
1197 >                        }
1198                  }
1199 <                if (!noaction && system(combuf)) {      /* run pfilt */
1200 <                        fprintf(stderr,
1201 <                        "%s: error filtering view %s\n\t%s removed\n",
1202 <                                        progname, vs, picfile);
1203 <                        unlink(picfile);
1204 <                        exit(1);
1205 <                }
1206 <                                                /* remove raw file */
1207 <                if (!silent)
1199 >                                                /* remove/rename raw file */
1200 >                if (vdef(RAWFILE)) {
1201 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1202 >                        mvfile(rawfile, combuf);
1203 >                } else
1204 >                        rmfile(rawfile);
1205 >        }
1206 > }
1207 >
1208 >
1209 > touch(fn)                       /* update a file */
1210 > char    *fn;
1211 > {
1212 >        if (!silent)
1213 >                printf("\ttouch %s\n", fn);
1214 >        if (noaction)
1215 >                return(0);
1216 > #ifdef notused
1217 >        if (access(fn, F_OK) == -1)             /* create it */
1218 >                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1219 >                        return(-1);
1220 > #endif
1221 >        return(setfdate(fn, time((time_t *)NULL)));
1222 > }
1223 >
1224 >
1225 > runcom(cs)                      /* run command */
1226 > char    *cs;
1227 > {
1228 >        if (!silent)            /* echo it */
1229 >                printf("\t%s\n", cs);
1230 >        if (noaction)
1231 >                return(0);
1232 >        fflush(stdout);         /* flush output and pass to shell */
1233 >        return(system(cs));
1234 > }
1235 >
1236 >
1237 > rmfile(fn)                      /* remove a file */
1238 > char    *fn;
1239 > {
1240 >        if (!silent)
1241   #ifdef MSDOS
1242 <                        printf("\tdel %s\n", rawfile);
1242 >                printf("\tdel %s\n", fn);
1243   #else
1244 <                        printf("\trm %s\n", rawfile);
1244 >                printf("\trm -f %s\n", fn);
1245   #endif
1246 <                if (!noaction)
1247 <                        unlink(rawfile);
1246 >        if (noaction)
1247 >                return(0);
1248 >        return(unlink(fn));
1249 > }
1250 >
1251 >
1252 > mvfile(fold, fnew)              /* move a file */
1253 > char    *fold, *fnew;
1254 > {
1255 >        if (!silent)
1256 > #ifdef MSDOS
1257 >                printf("\trename %s %s\n", fold, fnew);
1258 > #else
1259 >                printf("\tmv %s %s\n", fold, fnew);
1260 > #endif
1261 >        if (noaction)
1262 >                return(0);
1263 >        return(rename(fold, fnew));
1264 > }
1265 >
1266 >
1267 > #ifdef MSDOS
1268 > setenv(vname, value)            /* set an environment variable */
1269 > char    *vname, *value;
1270 > {
1271 >        register char   *evp;
1272 >
1273 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1274 >        if (evp == NULL)
1275 >                syserr(progname);
1276 >        sprintf(evp, "%s=%s", vname, value);
1277 >        if (putenv(evp) != 0) {
1278 >                fprintf(stderr, "%s: out of environment space\n", progname);
1279 >                quit(1);
1280          }
1281 +        if (!silent)
1282 +                printf("set %s\n", evp);
1283 + }
1284 + #endif
1285 +
1286 +
1287 + badvalue(vc)                    /* report bad variable value and exit */
1288 + int     vc;
1289 + {
1290 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1291 +                        progname, vnam(vc));
1292 +        quit(1);
1293 + }
1294 +
1295 +
1296 + syserr(s)                       /* report a system error and exit */
1297 + char    *s;
1298 + {
1299 +        perror(s);
1300 +        quit(1);
1301 + }
1302 +
1303 +
1304 + quit(ec)                        /* exit program */
1305 + int     ec;
1306 + {
1307 +        exit(ec);
1308   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines