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.53 by greg, Thu Mar 20 12:50:07 1997 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines