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.33 by greg, Thu Nov 18 10:00:21 1993 UTC

# Line 21 | Line 21 | typedef struct {
21          int     (*fixval)();    /* assignment checking function */
22   } VARIABLE;
23  
24 < int     onevalue(), catvalues();
24 > int     onevalue(), catvalues(), boolvalue(),
25 >        qualvalue(), fltvalue(), intvalue();
26  
27                                  /* variables */
28   #define OBJECT          0               /* object files */
29   #define SCENE           1               /* scene files */
30   #define MATERIAL        2               /* material files */
31 < #define RENDER          3               /* rendering options */
32 < #define OCONV           4               /* oconv options */
33 < #define PFILT           5               /* pfilt options */
34 < #define VIEW            6               /* view(s) for picture(s) */
35 < #define ZONE            7               /* simulation zone */
36 < #define QUALITY         8               /* desired rendering quality */
37 < #define OCTREE          9               /* octree file name */
38 < #define PICTURE         10              /* picture file name */
39 < #define AMBFILE         11              /* ambient file name */
40 < #define OPTFILE         12              /* rendering options file */
41 < #define EXPOSURE        13              /* picture exposure setting */
42 < #define RESOLUTION      14              /* maximum picture resolution */
43 < #define UP              15              /* view up (X, Y or Z) */
44 < #define INDIRECT        16              /* indirection in lighting */
45 < #define DETAIL          17              /* level of scene detail */
46 < #define PENUMBRAS       18              /* shadow penumbras are desired */
47 < #define VARIABILITY     19              /* level of light variability */
48 < #define REPORT          20              /* report frequency and errfile */
31 > #define ILLUM           3               /* mkillum input files */
32 > #define MKILLUM         4               /* mkillum options */
33 > #define RENDER          5               /* rendering options */
34 > #define OCONV           6               /* oconv options */
35 > #define PFILT           7               /* pfilt options */
36 > #define VIEW            8               /* view(s) for picture(s) */
37 > #define ZONE            9               /* simulation zone */
38 > #define QUALITY         10              /* desired rendering quality */
39 > #define OCTREE          11              /* octree file name */
40 > #define PICTURE         12              /* picture file name */
41 > #define AMBFILE         13              /* ambient file name */
42 > #define OPTFILE         14              /* rendering options file */
43 > #define EXPOSURE        15              /* picture exposure setting */
44 > #define RESOLUTION      16              /* maximum picture resolution */
45 > #define UP              17              /* view up (X, Y or Z) */
46 > #define INDIRECT        18              /* indirection in lighting */
47 > #define DETAIL          19              /* level of scene detail */
48 > #define PENUMBRAS       20              /* shadow penumbras are desired */
49 > #define VARIABILITY     21              /* level of light variability */
50 > #define REPORT          22              /* report frequency and errfile */
51                                  /* total number of variables */
52 < #define NVARS           21
52 > #define NVARS           23
53  
54   VARIABLE        vv[NVARS] = {           /* variable-value pairs */
55          {"objects",     3,      0,      NULL,   catvalues},
56          {"scene",       3,      0,      NULL,   catvalues},
57          {"materials",   3,      0,      NULL,   catvalues},
58 +        {"illum",       3,      0,      NULL,   catvalues},
59 +        {"mkillum",     3,      0,      NULL,   catvalues},
60          {"render",      3,      0,      NULL,   catvalues},
61          {"oconv",       3,      0,      NULL,   catvalues},
62          {"pfilt",       2,      0,      NULL,   catvalues},
63          {"view",        2,      0,      NULL,   NULL},
64          {"ZONE",        2,      0,      NULL,   onevalue},
65 <        {"QUALITY",     3,      0,      NULL,   onevalue},
65 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
66          {"OCTREE",      3,      0,      NULL,   onevalue},
67          {"PICTURE",     3,      0,      NULL,   onevalue},
68          {"AMBFILE",     3,      0,      NULL,   onevalue},
69          {"OPTFILE",     3,      0,      NULL,   onevalue},
70 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
70 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
71          {"RESOLUTION",  3,      0,      NULL,   onevalue},
72          {"UP",          2,      0,      NULL,   onevalue},
73 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
74 <        {"DETAIL",      3,      0,      NULL,   onevalue},
75 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
76 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
73 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
74 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
75 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
76 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
77          {"REPORT",      3,      0,      NULL,   onevalue},
78   };
79  
80   VARIABLE        *matchvar();
81   char    *nvalue();
77 int     vscale();
82  
83 + #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
84 +
85   #define vnam(vc)        (vv[vc].name)
86   #define vdef(vc)        (vv[vc].nass)
87   #define vval(vc)        (vv[vc].value)
88   #define vint(vc)        atoi(vval(vc))
89 < #define vlet(vc)        (vval(vc)[0]&~0x20)
89 > #define vlet(vc)        UPPER(vval(vc)[0])
90 > #define vscale          vlet
91   #define vbool(vc)       (vlet(vc)=='T')
92  
93 < #define HIGH            2
94 < #define MEDIUM          1
95 < #define LOW             0
93 > #define HIGH            'H'
94 > #define MEDIUM          'M'
95 > #define LOW             'L'
96  
97 < int     lowqopts(), medqopts(), hiqopts();
98 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
97 >                                /* overture calculation file */
98 > #ifdef NIX
99 > char    overfile[] = "overture.raw";
100 > #else
101 > char    overfile[] = "/dev/null";
102 > #endif
103  
104 < #define renderopts      (*setqopts[vscale(QUALITY)])
104 > extern unsigned long    fdate(), time();
105  
106 < extern long     fdate(), time();
106 > unsigned long   scenedate;      /* date of latest scene or object file */
107 > unsigned long   octreedate;     /* date of octree */
108 > unsigned long   matdate;        /* date of latest material file */
109 > unsigned long   illumdate;      /* date of last illum file */
110  
111 < long    scenedate;              /* date of latest scene or object file */
112 < long    octreedate;             /* date of octree */
111 > char    *oct0name;              /* name of pre-mkillum octree */
112 > unsigned long   oct0date;       /* date of pre-mkillum octree */
113 > char    *oct1name;              /* name of post-mkillum octree */
114 > unsigned long   oct1date;       /* date of post-mkillum octree (>= matdate) */
115  
116   int     explicate = 0;          /* explicate variables */
117   int     silent = 0;             /* do work silently */
118   int     noaction = 0;           /* don't do anything */
119 + int     sayview = 0;            /* print view out */
120   char    *rvdevice = NULL;       /* rview output device */
121   char    *viewselect = NULL;     /* specific view only */
122  
123   int     overture = 0;           /* overture calculation needed */
124  
125   char    *progname;              /* global argv[0] */
126 + char    *rifname;               /* global rad input file name */
127  
128   char    radname[MAXPATH];       /* root Radiance file name */
129  
# Line 133 | Line 151 | char   *argv[];
151                  case 'o':
152                          rvdevice = argv[++i];
153                          break;
154 +                case 'V':
155 +                        sayview++;
156 +                        break;
157                  case 'v':
158                          viewselect = argv[++i];
159                          break;
# Line 141 | Line 162 | char   *argv[];
162                  }
163          if (i >= argc)
164                  goto userr;
165 +        rifname = argv[i];
166                                  /* assign Radiance root file name */
167 <        rootname(radname, argv[i]);
167 >        rootname(radname, rifname);
168                                  /* load variable values */
169 <        load(argv[i]);
169 >        load(rifname);
170                                  /* get any additional assignments */
171          for (i++; i < argc; i++)
172                  setvariable(argv[i]);
# Line 157 | Line 179 | char   *argv[];
179                                  /* print all values if requested */
180          if (explicate)
181                  printvals();
182 <                                /* run simulation */
182 >                                /* build octree (and run mkillum) */
183          oconv();
184 +                                /* check date on ambient file */
185 +        checkambfile();
186 +                                /* run simulation */
187          renderopts(ropts);
188          xferopts(ropts);
189          if (rvdevice != NULL)
# Line 168 | Line 193 | char   *argv[];
193          exit(0);
194   userr:
195          fprintf(stderr,
196 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
196 >        "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
197                          progname);
198          exit(1);
199   }
# Line 189 | Line 214 | register char  *rn, *fn;
214   }
215  
216  
217 + #define NOCHAR  127             /* constant for character to delete */
218 +
219 +
220   load(rfname)                    /* load Radiance simulation file */
221   char    *rfname;
222   {
223          FILE    *fp;
224 <        char    buf[256];
224 >        char    buf[512];
225          register char   *cp;
226  
227          if (rfname == NULL)
228                  fp = stdin;
229 <        else if ((fp = fopen(rfname, "r")) == NULL) {
230 <                perror(rfname);
203 <                exit(1);
204 <        }
229 >        else if ((fp = fopen(rfname, "r")) == NULL)
230 >                syserr(rfname);
231          while (fgetline(buf, sizeof(buf), fp) != NULL) {
232                  for (cp = buf; *cp; cp++) {
233                          switch (*cp) {
234                          case '\\':
235 <                        case '\n':
210 <                                *cp = ' ';
235 >                                *cp++ = NOCHAR;
236                                  continue;
237                          case '#':
238                                  *cp = '\0';
239                                  break;
240 +                        default:
241 +                                continue;
242                          }
243                          break;
244                  }
# Line 225 | Line 252 | setvariable(ass)               /* assign variable according to stri
252   register char   *ass;
253   {
254          char    varname[32];
255 +        int     n;
256          register char   *cp;
257          register VARIABLE       *vp;
258          register int    i;
231        int     n;
259  
260          while (isspace(*ass))           /* skip leading space */
261                  ass++;
# Line 242 | Line 269 | register char  *ass;
269                                          /* trim value */
270          while (isspace(*ass) || *ass == '=')
271                  ass++;
272 <        cp = ass + strlen(ass);
273 <        do
274 <                *cp-- = '\0';
248 <        while (cp >= ass && isspace(*cp));
249 <        n = cp - ass + 1;
272 >        for (n = strlen(ass); n > 0; n--)
273 >                if (!isspace(ass[n-1]))
274 >                        break;
275          if (!n) {
276                  fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
277                                  progname, varname);
# Line 260 | Line 285 | register char  *ass;
285                  exit(1);
286          }
287                                          /* assign new value */
288 <        cp = vp->value; i = vp->nass;
289 <        while (i--)
290 <                while (*cp++)
291 <                        ;
292 <        i = cp - vp->value;
293 <        vp->value = realloc(vp->value, i+n+1);
294 <        if (vp->value == NULL) {
295 <                perror(progname);
296 <                exit(1);
288 >        if (i = vp->nass) {
289 >                cp = vp->value;
290 >                while (i--)
291 >                        while (*cp++)
292 >                                ;
293 >                i = cp - vp->value;
294 >                vp->value = realloc(vp->value, i+n+1);
295 >        } else
296 >                vp->value = malloc(n+1);
297 >        if (vp->value == NULL)
298 >                syserr(progname);
299 >        cp = vp->value+i;               /* copy value, squeezing spaces */
300 >        *cp = *ass;
301 >        for (i = 1; i <= n; i++) {
302 >                if (ass[i] == NOCHAR)
303 >                        continue;
304 >                if (isspace(*cp))
305 >                        while (isspace(ass[i]))
306 >                                i++;
307 >                *++cp = ass[i];
308          }
309 <        strcpy(vp->value+i, ass);
309 >        if (isspace(*cp))               /* remove trailing space */
310 >                *cp = '\0';
311          vp->nass++;
312   }
313  
# Line 296 | Line 333 | register int   n;
333   {
334          register char   *cp;
335  
336 <        if (vp == NULL || n < 0 || n >= vp->nass)
336 >        if (vp == NULL | n < 0 | n >= vp->nass)
337                  return(NULL);
338          cp = vp->value;
339          while (n--)
# Line 306 | Line 343 | register int   n;
343   }
344  
345  
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
346   checkvalues()                   /* check assignments */
347   {
348          register int    i;
# Line 362 | Line 381 | register VARIABLE      *vp;
381   }
382  
383  
384 < long
384 > int
385 > badmatch(tv, cv)                /* case insensitive truncated comparison */
386 > register char   *tv, *cv;
387 > {
388 >        if (!*tv) return(1);            /* null string cannot match */
389 >        do
390 >                if (UPPER(*tv) != *cv++)
391 >                        return(1);
392 >        while (*++tv);
393 >        return(0);              /* OK */
394 > }
395 >
396 >
397 > boolvalue(vp)                   /* check boolean for legal values */
398 > register VARIABLE       *vp;
399 > {
400 >        if (!vp->nass) return;
401 >        onevalue(vp);
402 >        switch (UPPER(vp->value[0])) {
403 >        case 'T':
404 >                if (badmatch(vp->value, "TRUE")) break;
405 >                return;
406 >        case 'F':
407 >                if (badmatch(vp->value, "FALSE")) break;
408 >                return;
409 >        }
410 >        fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
411 >                        progname, vp->name);
412 >        exit(1);
413 > }
414 >
415 >
416 > qualvalue(vp)                   /* check qualitative var. for legal values */
417 > register VARIABLE       *vp;
418 > {
419 >        if (!vp->nass) return;
420 >        onevalue(vp);
421 >        switch (UPPER(vp->value[0])) {
422 >        case 'L':
423 >                if (badmatch(vp->value, "LOW")) break;
424 >                return;
425 >        case 'M':
426 >                if (badmatch(vp->value, "MEDIUM")) break;
427 >                return;
428 >        case 'H':
429 >                if (badmatch(vp->value, "HIGH")) break;
430 >                return;
431 >        }
432 >        fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
433 >                        progname, vp->name);
434 >        exit(1);
435 > }
436 >
437 >
438 > intvalue(vp)                    /* check integer variable for legal values */
439 > register VARIABLE       *vp;
440 > {
441 >        if (!vp->nass) return;
442 >        onevalue(vp);
443 >        if (isint(vp->value)) return;
444 >        fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
445 >                        progname, vp->name);
446 >        exit(1);
447 > }
448 >
449 >
450 > fltvalue(vp)                    /* check float variable for legal values */
451 > register VARIABLE       *vp;
452 > {
453 >        if (!vp->nass) return;
454 >        onevalue(vp);
455 >        if (isflt(vp->value)) return;
456 >        fprintf(stderr, "%s: illegal value for real variable '%s'\n",
457 >                        progname, vp->name);
458 >        exit(1);
459 > }
460 >
461 >
462 > unsigned long
463   checklast(fnames)                       /* check files and find most recent */
464   register char   *fnames;
465   {
466          char    thisfile[MAXPATH];
467 <        long    thisdate, lastdate = -1;
467 >        unsigned long   thisdate, lastdate = 0;
468          register char   *cp;
469  
470 +        if (fnames == NULL)
471 +                return(0);
472          while (*fnames) {
473                  while (isspace(*fnames)) fnames++;
474                  cp = thisfile;
475 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
475 >                while (*fnames && !isspace(*fnames))
476 >                        *cp++ = *fnames++;
477                  *cp = '\0';
478 <                if ((thisdate = fdate(thisfile)) < 0) {
479 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
478 >                if (!(thisdate = fdate(thisfile)))
479 >                        syserr(thisfile);
480                  if (thisdate > lastdate)
481                          lastdate = thisdate;
482          }
# Line 386 | Line 484 | register char  *fnames;
484   }
485  
486  
487 + char *
488 + newfname(orig, pred)            /* create modified file name */
489 + char    *orig;
490 + int     pred;
491 + {
492 +        extern char     *rindex();
493 +        register char   *cp;
494 +        register int    n;
495 +        int     suffix;
496 +
497 +        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
498 +        while (*cp) {
499 +                if (*cp == '.') suffix = n;
500 +                else if (ISDIRSEP(*cp)) suffix = -1;
501 +                cp++; n++;
502 +        }
503 +        if (suffix == -1) suffix = n;
504 +        if ((cp = bmalloc(n+2)) == NULL)
505 +                syserr(progname);
506 +        strncpy(cp, orig, suffix);
507 +        cp[suffix] = pred;                      /* root name + pred + suffix */
508 +        strcpy(cp+suffix+1, orig+suffix);
509 +        return(cp);
510 + }
511 +
512 +
513   checkfiles()                    /* check for existence and modified times */
514   {
515 <        char    *cp;
392 <        long    objdate;
515 >        unsigned long   objdate;
516  
517          if (!vdef(OCTREE)) {
518 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
519 <                        perror(progname);
520 <                        exit(1);
398 <                }
399 <                sprintf(cp, "%s.oct", radname);
400 <                vval(OCTREE) = cp;
518 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
519 >                        syserr(progname);
520 >                sprintf(vval(OCTREE), "%s.oct", radname);
521                  vdef(OCTREE)++;
522          }
523          octreedate = fdate(vval(OCTREE));
524 <        scenedate = -1;
525 <        if (vdef(SCENE)) {
526 <                scenedate = checklast(vval(SCENE));
527 <                if (vdef(OBJECT)) {
528 <                        objdate = checklast(vval(OBJECT));
529 <                        if (objdate > scenedate)
530 <                                scenedate = objdate;
531 <                }
532 <        }
533 <        if (octreedate < 0 & scenedate < 0) {
534 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
535 <                                vnam(OCTREE), vnam(SCENE));
524 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
525 >                oct0name = newfname(vval(OCTREE), '0');
526 >                oct1name = newfname(vval(OCTREE), '1');
527 >                oct0date = fdate(oct0name);
528 >                oct1date = fdate(oct1name);
529 >        } else
530 >                oct0name = oct1name = vval(OCTREE);
531 >        if ((scenedate = checklast(vval(SCENE))) &&
532 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
533 >                scenedate = objdate;
534 >        illumdate = checklast(vval(ILLUM));
535 >        if (!octreedate & !scenedate & !illumdate) {
536 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
537 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
538                  exit(1);
539          }
540 +        matdate = checklast(vval(MATERIAL));
541   }      
542  
543  
# Line 423 | Line 546 | double org[3], *sizp;
546   {
547          extern FILE     *popen();
548          static double   oorg[3], osiz = 0.;
549 <        char    buf[MAXPATH+16];
549 >        double  min[3], max[3];
550 >        char    buf[512];
551          FILE    *fp;
552 +        register int    i;
553  
554 <        if (osiz <= FTINY) {
555 <                oconv();                /* does nothing if done already */
556 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
557 <                if ((fp = popen(buf, "r")) == NULL) {
558 <                        perror("getinfo");
559 <                        exit(1);
560 <                }
561 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
562 <                                &oorg[2], &osiz) != 4) {
563 <                        fprintf(stderr,
554 >        if (osiz <= FTINY)
555 >                if (noaction && fdate(oct1name) <
556 >                                (scenedate>illumdate?scenedate:illumdate)) {
557 >                                                        /* run getbbox */
558 >                        sprintf(buf, "getbbox -w -h %s",
559 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
560 >                        if ((fp = popen(buf, "r")) == NULL)
561 >                                syserr("getbbox");
562 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
563 >                                        &min[0], &max[0], &min[1], &max[1],
564 >                                        &min[2], &max[2]) != 6) {
565 >                                fprintf(stderr,
566 >                        "%s: error reading bounding box from getbbox\n",
567 >                                                progname);
568 >                                exit(1);
569 >                        }
570 >                        for (i = 0; i < 3; i++)
571 >                                if (max[i] - min[i] > osiz)
572 >                                        osiz = max[i] - min[i];
573 >                        for (i = 0; i < 3; i++)
574 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
575 >                        pclose(fp);
576 >                } else {                                /* from octree */
577 >                        oconv();        /* does nothing if done already */
578 >                        sprintf(buf, "getinfo -d < %s", oct1name);
579 >                        if ((fp = popen(buf, "r")) == NULL)
580 >                                syserr("getinfo");
581 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
582 >                                        &oorg[2], &osiz) != 4) {
583 >                                fprintf(stderr,
584                          "%s: error reading bounding cube from getinfo\n",
585 <                                        progname);
586 <                        exit(1);
585 >                                                progname);
586 >                                exit(1);
587 >                        }
588 >                        pclose(fp);
589                  }
443                pclose(fp);
444        }
590          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
591   }
592  
# Line 458 | Line 603 | setdefaults()                  /* set default values for unassigned v
603                  vval(ZONE) = savqstr(buf);
604                  vdef(ZONE)++;
605          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
606          if (!vdef(INDIRECT)) {
607                  vval(INDIRECT) = "0";
608                  vdef(INDIRECT)++;
# Line 502 | Line 643 | printvals()                    /* print variable values */
643          register int    i, j;
644  
645          for (i = 0; i < NVARS; i++)
646 <                for (j = 0; j < vv[i].nass; j++)
647 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
646 >                for (j = 0; j < vdef(i); j++)
647 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
648          fflush(stdout);
649   }
650  
651  
652 < oconv()                         /* run oconv if necessary */
652 > oconv()                         /* run oconv and mkillum if necessary */
653   {
654 <        char    combuf[512], ocopts[64];
654 >        static char     illumtmp[] = "ilXXXXXX";
655 >        char    combuf[512], ocopts[64], mkopts[64];
656  
657 <        if (octreedate >= scenedate)    /* check dates */
658 <                return;
659 <                                        /* build command */
660 <        oconvopts(ocopts);
661 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
662 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
663 <                        vval(SCENE), vval(OCTREE));
664 <        if (!silent) {                  /* echo it */
665 <                printf("\t%s\n", combuf);
666 <                fflush(stdout);
657 >        oconvopts(ocopts);              /* get options */
658 >        if (octreedate < scenedate) {   /* check date on original octree */
659 >                                                /* build command */
660 >                if (vdef(MATERIAL))
661 >                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
662 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
663 >                else
664 >                        sprintf(combuf, "oconv%s %s > %s", ocopts,
665 >                                        vval(SCENE), vval(OCTREE));
666 >                
667 >                if (runcom(combuf)) {           /* run it */
668 >                        fprintf(stderr,
669 >                                "%s: error generating octree\n\t%s removed\n",
670 >                                        progname, vval(OCTREE));
671 >                        unlink(vval(OCTREE));
672 >                        exit(1);
673 >                }
674 >                octreedate = time(0);
675          }
676 <        if (noaction)
676 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
677 >                oct1date = octreedate > matdate ? octreedate : matdate;
678 >        if (oct1date >= octreedate & oct1date >= matdate
679 >                        & oct1date >= illumdate)        /* all done */
680                  return;
681 <        if (system(combuf)) {           /* run it */
682 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
683 <                                progname, vval(OCTREE));
684 <                unlink(vval(OCTREE));
681 >                                                /* make octree0 */
682 >        if (oct0date < scenedate | oct0date < illumdate) {
683 >                                                /* build command */
684 >                if (octreedate)
685 >                        sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
686 >                                vval(OCTREE), vval(ILLUM), oct0name);
687 >                else if (vdef(MATERIAL))
688 >                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
689 >                                vval(MATERIAL), vval(ILLUM), oct0name);
690 >                else
691 >                        sprintf(combuf, "oconv%s %s > %s", ocopts,
692 >                                vval(ILLUM), oct0name);
693 >                if (runcom(combuf)) {           /* run it */
694 >                        fprintf(stderr,
695 >                                "%s: error generating octree\n\t%s removed\n",
696 >                                        progname, oct0name);
697 >                        unlink(oct0name);
698 >                        exit(1);
699 >                }
700 >                oct0date = time(0);
701 >        }
702 >        mkillumopts(mkopts);                    /* build mkillum command */
703 >        mktemp(illumtmp);
704 >        sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
705 >                        oct0name, vval(ILLUM), illumtmp);
706 >        if (runcom(combuf)) {                   /* run it */
707 >                fprintf(stderr, "%s: error running mkillum\n", progname);
708 >                unlink(illumtmp);
709                  exit(1);
710          }
711 <        octreedate = time(0);
711 >                                                /* make octree1 (frozen) */
712 >        if (octreedate)
713 >                sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
714 >                        vval(OCTREE), illumtmp, oct1name);
715 >        else if (vdef(MATERIAL))
716 >                sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
717 >                        vval(MATERIAL), illumtmp, oct1name);
718 >        else
719 >                sprintf(combuf, "oconv%s -f %s > %s", ocopts,
720 >                        illumtmp, oct1name);
721 >        if (runcom(combuf)) {           /* run it */
722 >                fprintf(stderr,
723 >                        "%s: error generating octree\n\t%s removed\n",
724 >                                progname, oct1name);
725 >                unlink(oct1name);
726 >                exit(1);
727 >        }
728 >        oct1date = time(0);
729 >        rmfile(illumtmp);
730   }
731  
732  
# Line 557 | Line 752 | register char  *oo;
752   }
753  
754  
755 + mkillumopts(mo)                         /* get mkillum options */
756 + register char   *mo;
757 + {
758 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
759 +
760 +        *mo = '\0';
761 +        if (vdef(MKILLUM))
762 +                addarg(mo, vval(MKILLUM));
763 + }
764 +
765 +
766 + checkambfile()                  /* check date on ambient file */
767 + {
768 +        unsigned long   afdate;
769 +
770 +        if (!vdef(AMBFILE))
771 +                return;
772 +        if (!(afdate = fdate(vval(AMBFILE))))
773 +                return;
774 +        if (oct1date > afdate)
775 +                rmfile(vval(AMBFILE));
776 + }
777 +
778 +
779   double
780   ambval()                                /* compute ambient value */
781   {
782 <        if (vdef(EXPOSURE))
782 >        if (vdef(EXPOSURE)) {
783                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
784                          return(.5/pow(2.,atof(vval(EXPOSURE))));
785 <                else
786 <                        return(.5/atof(vval(EXPOSURE)));
785 >                return(.5/atof(vval(EXPOSURE)));
786 >        }
787          if (vlet(ZONE) == 'E')
788                  return(10.);
789 <        else
789 >        if (vlet(ZONE) == 'I')
790                  return(.01);
791 +        badvalue(ZONE);
792   }
793  
794  
795 + renderopts(op)                          /* set rendering options */
796 + char    *op;
797 + {
798 +        switch(vscale(QUALITY)) {
799 +        case LOW:
800 +                lowqopts(op);
801 +                break;
802 +        case MEDIUM:
803 +                medqopts(op);
804 +                break;
805 +        case HIGH:
806 +                hiqopts(op);
807 +                break;
808 +        }
809 + }
810 +
811 +
812   lowqopts(op)                            /* low quality rendering options */
813   register char   *op;
814   {
# Line 579 | Line 816 | register char  *op;
816  
817          *op = '\0';
818          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
819 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
820 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
819 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
820 >                badvalue(ZONE);
821          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
822          getoctcube(org, &d);
823          d *= 3./(siz[0]+siz[1]+siz[2]);
824          switch (vscale(DETAIL)) {
825          case LOW:
826 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
826 >                op = addarg(op, "-ps 16 -dp 64");
827                  sprintf(op, " -ar %d", (int)(4*d));
828                  op += strlen(op);
829                  break;
830          case MEDIUM:
831 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
831 >                op = addarg(op, "-ps 8 -dp 128");
832                  sprintf(op, " -ar %d", (int)(8*d));
833                  op += strlen(op);
834                  break;
835          case HIGH:
836 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
836 >                op = addarg(op, "-ps 4 -dp 256");
837                  sprintf(op, " -ar %d", (int)(16*d));
838                  op += strlen(op);
839                  break;
# Line 610 | Line 841 | register char  *op;
841          op = addarg(op, "-pt .16");
842          if (vbool(PENUMBRAS))
843                  op = addarg(op, "-ds .4");
844 <        op = addarg(op, "-dt .2");
845 <        op = addarg(op, "-dc .25");
846 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
844 >        else
845 >                op = addarg(op, "-ds 0");
846 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
847          if (vdef(AMBFILE)) {
848                  sprintf(op, " -af %s", vval(AMBFILE));
849                  op += strlen(op);
# Line 623 | Line 851 | register char  *op;
851                  overture = 0;
852          switch (vscale(VARIABILITY)) {
853          case LOW:
854 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
854 >                op = addarg(op, "-aa .4 -ad 64");
855                  break;
856          case MEDIUM:
857 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
857 >                op = addarg(op, "-aa .3 -ad 128");
858                  break;
859          case HIGH:
860 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
860 >                op = addarg(op, "-aa .25 -ad 256");
861                  break;
862          }
863          op = addarg(op, "-as 0");
864          d = ambval();
865          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
866          op += strlen(op);
867 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
867 >        op = addarg(op, "-lr 3 -lw .02");
868          if (vdef(RENDER))
869                  op = addarg(op, vval(RENDER));
870   }
# Line 653 | Line 877 | register char  *op;
877  
878          *op = '\0';
879          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
880 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
881 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
880 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
881 >                badvalue(ZONE);
882          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
883          getoctcube(org, &d);
884          d *= 3./(siz[0]+siz[1]+siz[2]);
885          switch (vscale(DETAIL)) {
886          case LOW:
887                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
888 <                op = addarg(op, "-dp 64");
888 >                op = addarg(op, "-dp 256");
889                  sprintf(op, " -ar %d", (int)(8*d));
890                  op += strlen(op);
891                  break;
892          case MEDIUM:
893                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
894 <                op = addarg(op, "-dp 128");
894 >                op = addarg(op, "-dp 512");
895                  sprintf(op, " -ar %d", (int)(16*d));
896                  op += strlen(op);
897                  break;
898          case HIGH:
899                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
900 <                op = addarg(op, "-dp 256");
900 >                op = addarg(op, "-dp 1024");
901                  sprintf(op, " -ar %d", (int)(32*d));
902                  op += strlen(op);
903                  break;
904          }
905          op = addarg(op, "-pt .08");
906 <        if (vbool(PENUMBRAS)) {
907 <                op = addarg(op, "-ds .2");
908 <                op = addarg(op, "-dj .35");
688 <        } else
906 >        if (vbool(PENUMBRAS))
907 >                op = addarg(op, "-ds .2 -dj .5");
908 >        else
909                  op = addarg(op, "-ds .3");
910 <        op = addarg(op, "-dt .1");
911 <        op = addarg(op, "-dc .5");
912 <        op = addarg(op, "-dr 1");
913 <        op = addarg(op, "-sj .7");
914 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
910 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
911 >        if (overture = vint(INDIRECT)) {
912 >                sprintf(op, " -ab %d", overture);
913 >                op += strlen(op);
914 >        }
915          if (vdef(AMBFILE)) {
916                  sprintf(op, " -af %s", vval(AMBFILE));
917                  op += strlen(op);
# Line 701 | Line 919 | register char  *op;
919                  overture = 0;
920          switch (vscale(VARIABILITY)) {
921          case LOW:
922 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
922 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
923                  break;
924          case MEDIUM:
925 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
925 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
926                  break;
927          case HIGH:
928 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
928 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
929                  break;
930          }
931          d = ambval();
932          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
933          op += strlen(op);
934 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
934 >        op = addarg(op, "-lr 6 -lw .002");
935          if (vdef(RENDER))
936                  op = addarg(op, vval(RENDER));
937   }
# Line 733 | Line 944 | register char  *op;
944  
945          *op = '\0';
946          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
947 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
948 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
947 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
948 >                badvalue(ZONE);
949          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
950          getoctcube(org, &d);
951          d *= 3./(siz[0]+siz[1]+siz[2]);
952          switch (vscale(DETAIL)) {
953          case LOW:
954                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
955 <                op = addarg(op, "-dp 256");
955 >                op = addarg(op, "-dp 1024");
956                  sprintf(op, " -ar %d", (int)(16*d));
957                  op += strlen(op);
958                  break;
959          case MEDIUM:
960                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
961 <                op = addarg(op, "-dp 512");
961 >                op = addarg(op, "-dp 2048");
962                  sprintf(op, " -ar %d", (int)(32*d));
963                  op += strlen(op);
964                  break;
965          case HIGH:
966                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
967 <                op = addarg(op, "-dp 1024");
967 >                op = addarg(op, "-dp 4096");
968                  sprintf(op, " -ar %d", (int)(64*d));
969                  op += strlen(op);
970                  break;
971          }
972          op = addarg(op, "-pt .04");
973 <        if (vbool(PENUMBRAS)) {
974 <                op = addarg(op, "-ds .1");
975 <                op = addarg(op, "-dj .7");
768 <        } else
973 >        if (vbool(PENUMBRAS))
974 >                op = addarg(op, "-ds .1 -dj .7");
975 >        else
976                  op = addarg(op, "-ds .2");
977 <        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");
977 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
978          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
979          op += strlen(op);
980          if (vdef(AMBFILE)) {
# Line 781 | Line 984 | register char  *op;
984                  overture = 0;
985          switch (vscale(VARIABILITY)) {
986          case LOW:
987 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
987 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
988                  break;
989          case MEDIUM:
990 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
990 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
991                  break;
992          case HIGH:
993 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
993 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
994                  break;
995          }
996          d = ambval();
997          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
998          op += strlen(op);
999 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
999 >        op = addarg(op, "-lr 12 -lw .0005");
1000          if (vdef(RENDER))
1001                  op = addarg(op, vval(RENDER));
1002   }
# Line 810 | Line 1006 | xferopts(ro)                           /* transfer options if indicated */
1006   char    *ro;
1007   {
1008          int     fd, n;
1009 +        register char   *cp;
1010          
1011          n = strlen(ro);
1012          if (n < 2)
1013                  return;
1014          if (vdef(OPTFILE)) {
1015 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
1016 <                        perror(vval(OPTFILE));
1017 <                        exit(1);
1018 <                }
1019 <                if (write(fd, ro+1, n-1) != n-1) {
1020 <                        perror(vval(OPTFILE));
1021 <                        exit(1);
1022 <                }
1023 <                write(fd, "\n", 1);
1024 <                close(fd);
828 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
1015 >                for (cp = ro; cp[1]; cp++)
1016 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1017 >                                *cp = '\n';
1018 >                        else
1019 >                                *cp = cp[1];
1020 >                *cp = '\n';
1021 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1022 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1023 >                        syserr(vval(OPTFILE));
1024 >                sprintf(ro, " @%s", vval(OPTFILE));
1025          }
1026   #ifdef MSDOS
1027          else if (n > 50) {
1028 <                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 <                }
1028 >                setenv("ROPT", ro+1);
1029                  strcpy(ro, " $ROPT");
1030          }
1031   #endif
# Line 857 | Line 1040 | register char  *po;
1040                  po = addarg(po, "-1 -e");
1041                  po = addarg(po, vval(EXPOSURE));
1042          }
1043 <        if (vscale(QUALITY) == HIGH)
1044 <                po = addarg(po, "-r .65");
1043 >        switch (vscale(QUALITY)) {
1044 >        case MEDIUM:
1045 >                po = addarg(po, "-r 1");
1046 >                break;
1047 >        case HIGH:
1048 >                po = addarg(po, "-m .25");
1049 >                break;
1050 >        }
1051          if (vdef(PFILT))
1052                  po = addarg(po, vval(PFILT));
1053   }
# Line 880 | Line 1069 | char *
1069   specview(vs)                            /* get proper view spec from vs */
1070   register char   *vs;
1071   {
1072 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1073 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1074          static char     viewopts[128];
1075          register char   *cp;
1076 <        int     xpos, ypos, zpos, viewtype;
1077 <        int     exterior;
1076 >        int     xpos, ypos, zpos, viewtype, upax;
1077 >        register int    i;
1078          double  cent[3], dim[3], mult, d;
1079  
1080          if (vs == NULL || *vs == '-')
1081                  return(vs);
1082 +        upax = 0;                       /* get the up vector */
1083 +        if (vdef(UP)) {
1084 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
1085 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
1086 +                else
1087 +                        upax = 1-'X'+vlet(UP);
1088 +                if (upax < 1 | upax > 3)
1089 +                        badvalue(UP);
1090 +                if (vval(UP)[0] == '-')
1091 +                        upax = -upax;
1092 +        }
1093                                          /* check standard view names */
1094          xpos = ypos = zpos = 0;
893        viewtype = 0;
1095          if (*vs == 'X') {
1096                  xpos = 1; vs++;
1097          } else if (*vs == 'x') {
# Line 906 | Line 1107 | register char  *vs;
1107          } else if (*vs == 'z') {
1108                  zpos = -1; vs++;
1109          }
1110 +        viewtype = 'v';
1111          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1112                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
1113          cp = viewopts;
1114 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
1114 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1115                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
1116                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
1117                                  &cent[0], &dim[0], &cent[1], &dim[1],
1118 <                                &cent[2], &dim[2]) != 6) {
1119 <                        fprintf(stderr, "%s: bad zone specification\n",
1120 <                                        progname);
1121 <                        exit(1);
1118 >                                &cent[2], &dim[2]) != 6)
1119 >                        badvalue(ZONE);
1120 >                for (i = 0; i < 3; i++) {
1121 >                        dim[i] -= cent[i];
1122 >                        cent[i] += .5*dim[i];
1123                  }
1124 <                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 ;
1124 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
1125                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1126                                  cent[0]+xpos*mult*dim[0],
1127                                  cent[1]+ypos*mult*dim[1],
1128                                  cent[2]+zpos*mult*dim[2],
1129                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
1130                  cp += strlen(cp);
1131 <                switch (vlet(UP)) {
1132 <                case 'Z':
1133 <                        if (xpos|ypos) {
1134 <                                cp = addarg(cp, "-vu 0 0 1");
1135 <                                break;
1136 <                        }
1137 <                /* 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");
1131 >                                        /* redirect up axis if necessary */
1132 >                switch (upax) {
1133 >                case 3:                 /* plus or minus Z axis */
1134 >                case -3:
1135 >                case 0:
1136 >                        if (!(xpos|ypos))
1137 >                                upax = 2;
1138                          break;
1139 <                default:
1140 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
1141 <                                        progname, vnam(UP));
1142 <                        exit(1);
1139 >                case 2:                 /* plus or minus Y axis */
1140 >                case -2:
1141 >                        if (!(xpos|zpos))
1142 >                                upax = 1;
1143 >                        break;
1144 >                case 1:                 /* plus or minus X axis */
1145 >                case -1:
1146 >                        if (!(ypos|zpos))
1147 >                                upax = 3;
1148 >                        break;
1149                  }
1150 +                cp = addarg(cp, vup[upax+3]);
1151                  switch (viewtype) {
1152                  case 'v':
1153                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 1162 | register char  *vs;
1162                          cp = addarg(cp, "-vh 180 -vv 180");
1163                          break;
1164                  }
1165 <        } else
1166 <                while (*vs && !isspace(*vs))    /* else skip id */
1167 <                        vs++;
1168 <                                        /* append any additional options */
1169 <        while (isspace(*vs)) vs++;
1165 >        } else {
1166 >                while (!isspace(*vs))           /* else skip id */
1167 >                        if (!*vs++)
1168 >                                return(NULL);
1169 >                if (upax) {                     /* specify up vector */
1170 >                        strcpy(cp, vup[upax+3]);
1171 >                        cp += strlen(cp);
1172 >                }
1173 >        }
1174 >        if (cp == viewopts)             /* append any additional options */
1175 >                vs++;           /* skip prefixed space if unneeded */
1176          strcpy(cp, vs);
1177 + #ifdef MSDOS
1178 +        if (strlen(viewopts) > 40) {
1179 +                setenv("VIEW", viewopts);
1180 +                return("$VIEW");
1181 +        }
1182 + #endif
1183          return(viewopts);
1184   }
1185  
# Line 982 | Line 1187 | register char  *vs;
1187   char *
1188   getview(n, vn)                          /* get view n, or NULL if none */
1189   int     n;
1190 < char    *vn;
1190 > char    *vn;            /* returned view name */
1191   {
1192          register char   *mv;
1193  
1194 <        if (viewselect != NULL) {
1194 >        if (viewselect != NULL) {               /* command-line selected */
1195                  if (n)                          /* only do one */
1196                          return(NULL);
1197                  if (viewselect[0] == '-') {     /* already specified */
# Line 999 | Line 1204 | char   *vn;
1204                                  ;
1205                          *vn = '\0';
1206                  }
1207 +                                                /* view number? */
1208 +                if (isint(viewselect))
1209 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1210                                                  /* check list */
1211                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1212                          if (matchword(viewselect, mv))
1213                                  return(specview(mv));
1214                  return(specview(viewselect));   /* standard view? */
1215          }
1216 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1217 <                if (*mv != '-')
1218 <                        while (*mv && !isspace(*mv))
1219 <                                *vn++ = *mv++;
1216 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1217 >        if (vn != NULL & mv != NULL) {
1218 >                register char   *mv2 = mv;
1219 >                if (*mv2 != '-')
1220 >                        while (*mv2 && !isspace(*mv2))
1221 >                                *vn++ = *mv2++;
1222                  *vn = '\0';
1223          }
1224 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1224 >        return(specview(mv));
1225   }
1226  
1227  
1228 + printview(vopts)                        /* print out selected view */
1229 + register char   *vopts;
1230 + {
1231 +        extern char     *atos(), *getenv();
1232 +        char    buf[256];
1233 +        FILE    *fp;
1234 +        register char   *cp;
1235 +
1236 +        if (vopts == NULL)
1237 +                return(-1);
1238 +        fputs("VIEW=", stdout);
1239 +        do {
1240 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1241 +                        vopts = sskip(vopts);
1242 +                        if (!*atos(buf, sizeof(buf), vopts))
1243 +                                return(-1);
1244 +                        if ((fp = fopen(buf, "r")) == NULL)
1245 +                                return(-1);
1246 +                        for (buf[sizeof(buf)-2] = '\n';
1247 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1248 +                                                buf[0] != '\n';
1249 +                                        buf[sizeof(buf)-2] = '\n') {
1250 +                                if (buf[sizeof(buf)-2] != '\n') {
1251 +                                        ungetc(buf[sizeof(buf)-2], fp);
1252 +                                        buf[sizeof(buf)-2] = '\0';
1253 +                                }
1254 +                                if (matchword(buf, "VIEW=") ||
1255 +                                                matchword(buf, "rview")) {
1256 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1257 +                                                putchar(*cp);
1258 +                                }
1259 +                        }
1260 +                        fclose(fp);
1261 +                        vopts = sskip(vopts);
1262 +                } else {
1263 +                        while (isspace(*vopts))
1264 +                                vopts++;
1265 +                        putchar(' ');
1266 + #ifdef MSDOS
1267 +                        if (*vopts == '$') {            /* expand env. var. */
1268 +                                if (!*atos(buf, sizeof(buf), vopts+1))
1269 +                                        return(-1);
1270 +                                if ((cp = getenv(buf)) == NULL)
1271 +                                        return(-1);
1272 +                                fputs(cp, stdout);
1273 +                                vopts = sskip(vopts);
1274 +                        } else
1275 + #endif
1276 +                                while (*vopts && !isspace(*vopts))
1277 +                                        putchar(*vopts++);
1278 +                }
1279 +        } while (*vopts++);
1280 +        putchar('\n');
1281 +        return(0);
1282 + }
1283 +
1284 +
1285   rview(opts)                             /* run rview with first view */
1286   char    *opts;
1287   {
1288 +        char    *vw;
1289          char    combuf[512];
1290                                          /* build command */
1291 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1291 >        if ((vw = getview(0, NULL)) == NULL)
1292 >                return;
1293 >        if (sayview)
1294 >                printview(vw);
1295 >        sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1296          if (rvdevice != NULL)
1297                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1298 <        strcat(combuf, vval(OCTREE));
1299 <        if (!silent) {                  /* echo it */
1300 <                printf("\t%s\n", combuf);
1301 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        if (system(combuf)) {           /* run it */
1298 >        if (vdef(EXPOSURE))
1299 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1300 >        strcat(combuf, oct1name);
1301 >        if (runcom(combuf)) {           /* run it */
1302                  fprintf(stderr, "%s: error running rview\n", progname);
1303                  exit(1);
1304          }
# Line 1041 | Line 1309 | rpict(opts)                            /* run rpict and pfilt for each view */
1309   char    *opts;
1310   {
1311          char    combuf[1024];
1312 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1313 <        char    pfopts[64];
1312 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1313 >        char    pfopts[128];
1314          char    vs[32], *vw;
1315          int     vn, mult;
1316                                          /* get pfilt options */
1317          pfiltopts(pfopts);
1318                                          /* get resolution, reporting */
1319 <        mult = vscale(QUALITY)+1;
1319 >        switch (vscale(QUALITY)) {
1320 >        case LOW:
1321 >                mult = 1;
1322 >                break;
1323 >        case MEDIUM:
1324 >                mult = 2;
1325 >                break;
1326 >        case HIGH:
1327 >                mult = 3;
1328 >                break;
1329 >        }
1330          {
1331                  int     xres, yres;
1332                  double  aspect;
# Line 1060 | Line 1338 | char   *opts;
1338                  else if (n) {
1339                          if (n == 1) yres = xres;
1340                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1341 <                } else {
1342 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1341 >                } else
1342 >                        badvalue(RESOLUTION);
1343          }
1344          rep[0] = '\0';
1345          if (vdef(REPORT)) {
# Line 1075 | Line 1350 | char   *opts;
1350                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1351                  else if (n == 1)
1352                          sprintf(rep, " -t %d", (int)(minutes*60));
1353 <                else {
1354 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1353 >                else
1354 >                        badvalue(REPORT);
1355          }
1356                                          /* do each view */
1357          vn = 0;
1358          while ((vw = getview(vn++, vs)) != NULL) {
1359 +                if (sayview)
1360 +                        printview(vw);
1361                  if (!vs[0])
1362                          sprintf(vs, "%d", vn);
1363                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1364                                                  /* check date on picture */
1365 <                if (fdate(picfile) > octreedate)
1365 >                if (fdate(picfile) >= oct1date)
1366                          continue;
1367                                                  /* build rpict command */
1368                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1369 <                if (fdate(rawfile) > octreedate)        /* recover */
1369 >                if (fdate(rawfile) >= oct1date)         /* recover */
1370                          sprintf(combuf, "rpict%s%s -ro %s %s",
1371 <                                        rep, opts, rawfile, vval(OCTREE));
1371 >                                        rep, opts, rawfile, oct1name);
1372                  else {
1373                          if (overture) {         /* run overture calculation */
1374                                  sprintf(combuf,
1375                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1376                                                  rep, vw, opts,
1377 <                                                vval(OCTREE), rawfile);
1378 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1377 >                                                oct1name, overfile);
1378 >                                if (runcom(combuf)) {
1379                                          fprintf(stderr,
1380 <                        "%s: error in overture for view %s\n\t%s removed\n",
1381 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1380 >                                        "%s: error in overture for view %s\n",
1381 >                                                progname, vs);
1382                                          exit(1);
1383                                  }
1384 + #ifdef NIX
1385 +                                rmfile(overfile);
1386 + #endif
1387                          }
1388                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1389                                          rep, vw, res, opts,
1390 <                                        vval(OCTREE), rawfile);
1390 >                                oct1name, rawfile);
1391                  }
1392 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1392 >                if (runcom(combuf)) {           /* run rpict */
1393                          fprintf(stderr, "%s: error rendering view %s\n",
1394                                          progname, vs);
1395                          exit(1);
# Line 1133 | Line 1401 | char   *opts;
1401                  else
1402                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1403                                          rawfile, picfile);
1404 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1404 >                if (runcom(combuf)) {           /* run pfilt */
1405                          fprintf(stderr,
1406                          "%s: error filtering view %s\n\t%s removed\n",
1407                                          progname, vs, picfile);
# Line 1145 | Line 1409 | char   *opts;
1409                          exit(1);
1410                  }
1411                                                  /* remove raw file */
1412 <                if (!silent)
1412 >                rmfile(rawfile);
1413 >        }
1414 > }
1415 >
1416 >
1417 > runcom(cs)                      /* run command */
1418 > char    *cs;
1419 > {
1420 >        if (!silent)            /* echo it */
1421 >                printf("\t%s\n", cs);
1422 >        if (noaction)
1423 >                return(0);
1424 >        fflush(stdout);         /* flush output and pass to shell */
1425 >        return(system(cs));
1426 > }
1427 >
1428 >
1429 > rmfile(fn)                      /* remove a file */
1430 > char    *fn;
1431 > {
1432 >        if (!silent)
1433   #ifdef MSDOS
1434 <                        printf("\tdel %s\n", rawfile);
1434 >                printf("\tdel %s\n", fn);
1435   #else
1436 <                        printf("\trm %s\n", rawfile);
1436 >                printf("\trm -f %s\n", fn);
1437   #endif
1438 <                if (!noaction)
1439 <                        unlink(rawfile);
1438 >        if (noaction)
1439 >                return(0);
1440 >        return(unlink(fn));
1441 > }
1442 >
1443 >
1444 > #ifdef MSDOS
1445 > setenv(vname, value)            /* set an environment variable */
1446 > char    *vname, *value;
1447 > {
1448 >        register char   *evp;
1449 >
1450 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1451 >        if (evp == NULL)
1452 >                syserr(progname);
1453 >        sprintf(evp, "%s=%s", vname, value);
1454 >        if (putenv(evp) != 0) {
1455 >                fprintf(stderr, "%s: out of environment space\n", progname);
1456 >                exit(1);
1457          }
1458 +        if (!silent)
1459 +                printf("set %s\n", evp);
1460 + }
1461 + #endif
1462 +
1463 +
1464 + badvalue(vc)                    /* report bad variable value and exit */
1465 + int     vc;
1466 + {
1467 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1468 +                        progname, vnam(vc));
1469 +        exit(1);
1470 + }
1471 +
1472 +
1473 + syserr(s)                       /* report a system error and exit */
1474 + char    *s;
1475 + {
1476 +        perror(s);
1477 +        exit(1);
1478   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines