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.7 by greg, Tue Apr 6 17:21:04 1993 UTC vs.
Revision 2.47 by greg, Fri Dec 8 19:55:50 1995 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 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   #include "standard.h"
12   #include "paths.h"
13   #include <ctype.h>
14 + #include <sys/types.h>
15  
16  
17   typedef struct {
# Line 21 | Line 22 | typedef struct {
22          int     (*fixval)();    /* assignment checking function */
23   } VARIABLE;
24  
25 < int     onevalue(), catvalues();
25 > int     onevalue(), catvalues(), boolvalue(),
26 >        qualvalue(), fltvalue(), intvalue();
27  
28                                  /* variables */
29   #define OBJECT          0               /* object files */
30   #define SCENE           1               /* scene files */
31   #define MATERIAL        2               /* material files */
32 < #define RENDER          3               /* rendering options */
33 < #define OCONV           4               /* oconv options */
34 < #define PFILT           5               /* pfilt options */
35 < #define VIEW            6               /* view(s) for picture(s) */
36 < #define ZONE            7               /* simulation zone */
37 < #define QUALITY         8               /* desired rendering quality */
38 < #define OCTREE          9               /* octree file name */
39 < #define PICTURE         10              /* picture file name */
40 < #define AMBFILE         11              /* ambient file name */
41 < #define OPTFILE         12              /* rendering options file */
42 < #define EXPOSURE        13              /* picture exposure setting */
43 < #define RESOLUTION      14              /* maximum picture resolution */
44 < #define UP              15              /* view up (X, Y or Z) */
45 < #define INDIRECT        16              /* indirection in lighting */
46 < #define DETAIL          17              /* level of scene detail */
47 < #define PENUMBRAS       18              /* shadow penumbras are desired */
48 < #define VARIABILITY     19              /* level of light variability */
49 < #define REPORT          20              /* report frequency and errfile */
32 > #define ILLUM           3               /* mkillum input files */
33 > #define MKILLUM         4               /* mkillum options */
34 > #define RENDER          5               /* rendering options */
35 > #define OCONV           6               /* oconv options */
36 > #define PFILT           7               /* pfilt options */
37 > #define VIEW            8               /* view(s) for picture(s) */
38 > #define ZONE            9               /* simulation zone */
39 > #define QUALITY         10              /* desired rendering quality */
40 > #define OCTREE          11              /* octree file name */
41 > #define PICTURE         12              /* picture file root name */
42 > #define AMBFILE         13              /* ambient file name */
43 > #define OPTFILE         14              /* rendering options file */
44 > #define EXPOSURE        15              /* picture exposure setting */
45 > #define RESOLUTION      16              /* maximum picture resolution */
46 > #define UP              17              /* view up (X, Y or Z) */
47 > #define INDIRECT        18              /* indirection in lighting */
48 > #define DETAIL          19              /* level of scene detail */
49 > #define PENUMBRAS       20              /* shadow penumbras are desired */
50 > #define VARIABILITY     21              /* level of light variability */
51 > #define REPORT          22              /* report frequency and errfile */
52 > #define RAWFILE         23              /* raw picture file root name */
53 > #define ZFILE           24              /* distance file root name */
54                                  /* total number of variables */
55 < #define NVARS           21
55 > #define NVARS           25
56  
57   VARIABLE        vv[NVARS] = {           /* variable-value pairs */
58          {"objects",     3,      0,      NULL,   catvalues},
59          {"scene",       3,      0,      NULL,   catvalues},
60          {"materials",   3,      0,      NULL,   catvalues},
61 +        {"illum",       3,      0,      NULL,   catvalues},
62 +        {"mkillum",     3,      0,      NULL,   catvalues},
63          {"render",      3,      0,      NULL,   catvalues},
64          {"oconv",       3,      0,      NULL,   catvalues},
65          {"pfilt",       2,      0,      NULL,   catvalues},
66          {"view",        2,      0,      NULL,   NULL},
67          {"ZONE",        2,      0,      NULL,   onevalue},
68 <        {"QUALITY",     3,      0,      NULL,   onevalue},
68 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
69          {"OCTREE",      3,      0,      NULL,   onevalue},
70          {"PICTURE",     3,      0,      NULL,   onevalue},
71          {"AMBFILE",     3,      0,      NULL,   onevalue},
72          {"OPTFILE",     3,      0,      NULL,   onevalue},
73 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
73 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
74          {"RESOLUTION",  3,      0,      NULL,   onevalue},
75          {"UP",          2,      0,      NULL,   onevalue},
76 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
77 <        {"DETAIL",      3,      0,      NULL,   onevalue},
78 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
79 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
76 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
77 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
78 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
79 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
80          {"REPORT",      3,      0,      NULL,   onevalue},
81 +        {"RAWFILE",     3,      0,      NULL,   onevalue},
82 +        {"ZFILE",       2,      0,      NULL,   onevalue},
83   };
84  
85   VARIABLE        *matchvar();
86   char    *nvalue();
77 int     vscale();
87  
88   #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
89  
# Line 83 | Line 92 | int    vscale();
92   #define vval(vc)        (vv[vc].value)
93   #define vint(vc)        atoi(vval(vc))
94   #define vlet(vc)        UPPER(vval(vc)[0])
95 + #define vscale          vlet
96   #define vbool(vc)       (vlet(vc)=='T')
97  
98 < #define HIGH            2
99 < #define MEDIUM          1
100 < #define LOW             0
98 > #define HIGH            'H'
99 > #define MEDIUM          'M'
100 > #define LOW             'L'
101  
92 int     lowqopts(), medqopts(), hiqopts();
93 int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94
95 #define renderopts      (*setqopts[vscale(QUALITY)])
96
102                                  /* overture calculation file */
103   #ifdef NIX
104 < char    overfile[] = "overture.raw";
104 > char    overfile[] = "overture.unf";
105   #else
106   char    overfile[] = "/dev/null";
107   #endif
108  
109 < extern long     fdate(), time();
109 > extern time_t   fdate(), time();
110  
111 < long    scenedate;              /* date of latest scene or object file */
112 < long    octreedate;             /* date of octree */
111 > time_t  scenedate;              /* date of latest scene or object file */
112 > time_t  octreedate;             /* date of octree */
113 > time_t  matdate;                /* date of latest material file */
114 > time_t  illumdate;              /* date of last illum file */
115  
116 + char    *oct0name;              /* name of pre-mkillum octree */
117 + time_t  oct0date;               /* date of pre-mkillum octree */
118 + char    *oct1name;              /* name of post-mkillum octree */
119 + time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
120 +
121 + int     nowarn = 0;             /* no warnings */
122   int     explicate = 0;          /* explicate variables */
123   int     silent = 0;             /* do work silently */
124 + int     touchonly = 0;          /* touch files only */
125   int     noaction = 0;           /* don't do anything */
126 + int     sayview = 0;            /* print view out */
127   char    *rvdevice = NULL;       /* rview output device */
128   char    *viewselect = NULL;     /* specific view only */
129  
130   int     overture = 0;           /* overture calculation needed */
131  
132   char    *progname;              /* global argv[0] */
133 + char    *rifname;               /* global rad input file name */
134  
135   char    radname[MAXPATH];       /* root Radiance file name */
136  
# Line 124 | Line 140 | int    argc;
140   char    *argv[];
141   {
142          char    ropts[512];
143 +        char    popts[64];
144          int     i;
145  
146          progname = argv[0];
# Line 136 | Line 153 | char   *argv[];
153                  case 'n':
154                          noaction++;
155                          break;
156 +                case 't':
157 +                        touchonly++;
158 +                        break;
159                  case 'e':
160                          explicate++;
161                          break;
162                  case 'o':
163                          rvdevice = argv[++i];
164                          break;
165 +                case 'V':
166 +                        sayview++;
167 +                        break;
168                  case 'v':
169                          viewselect = argv[++i];
170                          break;
171 +                case 'w':
172 +                        nowarn++;
173 +                        break;
174                  default:
175                          goto userr;
176                  }
177          if (i >= argc)
178                  goto userr;
179 +        rifname = argv[i];
180                                  /* assign Radiance root file name */
181 <        rootname(radname, argv[i]);
181 >        rootname(radname, rifname);
182                                  /* load variable values */
183 <        load(argv[i]);
183 >        load(rifname);
184                                  /* get any additional assignments */
185          for (i++; i < argc; i++)
186                  setvariable(argv[i]);
# Line 166 | Line 193 | char   *argv[];
193                                  /* print all values if requested */
194          if (explicate)
195                  printvals();
196 <                                /* build octree */
196 >                                /* build octree (and run mkillum) */
197          oconv();
198                                  /* check date on ambient file */
199          checkambfile();
200                                  /* run simulation */
201 <        renderopts(ropts);
201 >        renderopts(ropts, popts);
202          xferopts(ropts);
203          if (rvdevice != NULL)
204 <                rview(ropts);
204 >                rview(ropts, popts);
205          else
206 <                rpict(ropts);
206 >                rpict(ropts, popts);
207          exit(0);
208   userr:
209          fprintf(stderr,
210 <        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
210 > "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
211                          progname);
212          exit(1);
213   }
# Line 201 | Line 228 | register char  *rn, *fn;
228   }
229  
230  
231 + #define NOCHAR  127             /* constant for character to delete */
232 +
233 +
234   load(rfname)                    /* load Radiance simulation file */
235   char    *rfname;
236   {
# Line 216 | Line 246 | char   *rfname;
246                  for (cp = buf; *cp; cp++) {
247                          switch (*cp) {
248                          case '\\':
249 <                        case '\n':
220 <                                *cp = ' ';
249 >                                *cp++ = NOCHAR;
250                                  continue;
251                          case '#':
252                                  *cp = '\0';
# Line 237 | Line 266 | setvariable(ass)               /* assign variable according to stri
266   register char   *ass;
267   {
268          char    varname[32];
269 +        int     n;
270          register char   *cp;
271          register VARIABLE       *vp;
272          register int    i;
243        int     n;
273  
274          while (isspace(*ass))           /* skip leading space */
275                  ass++;
# Line 254 | Line 283 | register char  *ass;
283                                          /* trim value */
284          while (isspace(*ass) || *ass == '=')
285                  ass++;
286 <        cp = ass + strlen(ass);
287 <        do
288 <                *cp-- = '\0';
289 <        while (cp >= ass && isspace(*cp));
261 <        n = cp - ass + 1;
262 <        if (!n) {
286 >        for (n = strlen(ass); n > 0; n--)
287 >                if (!isspace(ass[n-1]))
288 >                        break;
289 >        if (!n && !nowarn) {
290                  fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
291                                  progname, varname);
292                  return;
# Line 283 | Line 310 | register char  *ass;
310                  vp->value = malloc(n+1);
311          if (vp->value == NULL)
312                  syserr(progname);
313 <        strcpy(vp->value+i, ass);
313 >        cp = vp->value+i;               /* copy value, squeezing spaces */
314 >        *cp = *ass;
315 >        for (i = 1; i <= n; i++) {
316 >                if (ass[i] == NOCHAR)
317 >                        continue;
318 >                if (isspace(*cp))
319 >                        while (isspace(ass[i]))
320 >                                i++;
321 >                *++cp = ass[i];
322 >        }
323 >        if (isspace(*cp))               /* remove trailing space */
324 >                *cp = '\0';
325          vp->nass++;
326   }
327  
# Line 309 | Line 347 | register int   n;
347   {
348          register char   *cp;
349  
350 <        if (vp == NULL || n < 0 || n >= vp->nass)
350 >        if (vp == NULL | n < 0 | n >= vp->nass)
351                  return(NULL);
352          cp = vp->value;
353          while (n--)
# Line 319 | Line 357 | register int   n;
357   }
358  
359  
322 int
323 vscale(vc)                      /* return scale for variable vc */
324 int     vc;
325 {
326        switch(vlet(vc)) {
327        case 'H':
328                return(HIGH);
329        case 'M':
330                return(MEDIUM);
331        case 'L':
332                return(LOW);
333        }
334        badvalue(vc);
335 }
336
337
360   checkvalues()                   /* check assignments */
361   {
362          register int    i;
# Line 350 | Line 372 | register VARIABLE      *vp;
372   {
373          if (vp->nass < 2)
374                  return;
375 <        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
375 >        if (!nowarn)
376 >                fprintf(stderr,
377 >                "%s: warning - multiple assignment of variable '%s'\n",
378                          progname, vp->name);
379          do
380                  vp->value += strlen(vp->value)+1;
# Line 373 | Line 397 | register VARIABLE      *vp;
397   }
398  
399  
400 < long
400 > int
401 > badmatch(tv, cv)                /* case insensitive truncated comparison */
402 > register char   *tv, *cv;
403 > {
404 >        if (!*tv) return(1);            /* null string cannot match */
405 >        do
406 >                if (UPPER(*tv) != *cv++)
407 >                        return(1);
408 >        while (*++tv);
409 >        return(0);              /* OK */
410 > }
411 >
412 >
413 > boolvalue(vp)                   /* check boolean for legal values */
414 > register VARIABLE       *vp;
415 > {
416 >        if (!vp->nass) return;
417 >        onevalue(vp);
418 >        switch (UPPER(vp->value[0])) {
419 >        case 'T':
420 >                if (badmatch(vp->value, "TRUE")) break;
421 >                return;
422 >        case 'F':
423 >                if (badmatch(vp->value, "FALSE")) break;
424 >                return;
425 >        }
426 >        fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
427 >                        progname, vp->name);
428 >        exit(1);
429 > }
430 >
431 >
432 > qualvalue(vp)                   /* check qualitative var. for legal values */
433 > register VARIABLE       *vp;
434 > {
435 >        if (!vp->nass) return;
436 >        onevalue(vp);
437 >        switch (UPPER(vp->value[0])) {
438 >        case 'L':
439 >                if (badmatch(vp->value, "LOW")) break;
440 >                return;
441 >        case 'M':
442 >                if (badmatch(vp->value, "MEDIUM")) break;
443 >                return;
444 >        case 'H':
445 >                if (badmatch(vp->value, "HIGH")) break;
446 >                return;
447 >        }
448 >        fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
449 >                        progname, vp->name);
450 >        exit(1);
451 > }
452 >
453 >
454 > intvalue(vp)                    /* check integer variable for legal values */
455 > register VARIABLE       *vp;
456 > {
457 >        if (!vp->nass) return;
458 >        onevalue(vp);
459 >        if (isint(vp->value)) return;
460 >        fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
461 >                        progname, vp->name);
462 >        exit(1);
463 > }
464 >
465 >
466 > fltvalue(vp)                    /* check float variable for legal values */
467 > register VARIABLE       *vp;
468 > {
469 >        if (!vp->nass) return;
470 >        onevalue(vp);
471 >        if (isflt(vp->value)) return;
472 >        fprintf(stderr, "%s: illegal value for real variable '%s'\n",
473 >                        progname, vp->name);
474 >        exit(1);
475 > }
476 >
477 >
478 > time_t
479   checklast(fnames)                       /* check files and find most recent */
480   register char   *fnames;
481   {
482          char    thisfile[MAXPATH];
483 <        long    thisdate, lastdate = -1;
483 >        time_t  thisdate, lastdate = 0;
484          register char   *cp;
485  
486 +        if (fnames == NULL)
487 +                return(0);
488          while (*fnames) {
489                  while (isspace(*fnames)) fnames++;
490                  cp = thisfile;
491                  while (*fnames && !isspace(*fnames))
492                          *cp++ = *fnames++;
493                  *cp = '\0';
494 <                if ((thisdate = fdate(thisfile)) < 0)
494 >                if (!(thisdate = fdate(thisfile)))
495                          syserr(thisfile);
496                  if (thisdate > lastdate)
497                          lastdate = thisdate;
# Line 396 | Line 500 | register char  *fnames;
500   }
501  
502  
503 + char *
504 + newfname(orig, pred)            /* create modified file name */
505 + char    *orig;
506 + int     pred;
507 + {
508 +        extern char     *rindex();
509 +        register char   *cp;
510 +        register int    n;
511 +        int     suffix;
512 +
513 +        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
514 +        while (*cp) {
515 +                if (*cp == '.') suffix = n;
516 +                else if (ISDIRSEP(*cp)) suffix = -1;
517 +                cp++; n++;
518 +        }
519 +        if (suffix == -1) suffix = n;
520 +        if ((cp = bmalloc(n+2)) == NULL)
521 +                syserr(progname);
522 +        strncpy(cp, orig, suffix);
523 +        cp[suffix] = pred;                      /* root name + pred + suffix */
524 +        strcpy(cp+suffix+1, orig+suffix);
525 +        return(cp);
526 + }
527 +
528 +
529   checkfiles()                    /* check for existence and modified times */
530   {
531 <        char    *cp;
402 <        long    objdate;
531 >        time_t  objdate;
532  
533          if (!vdef(OCTREE)) {
534 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
534 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
535                          syserr(progname);
536 <                sprintf(cp, "%s.oct", radname);
408 <                vval(OCTREE) = cp;
536 >                sprintf(vval(OCTREE), "%s.oct", radname);
537                  vdef(OCTREE)++;
538          }
539          octreedate = fdate(vval(OCTREE));
540 <        scenedate = -1;
541 <        if (vdef(SCENE)) {
542 <                scenedate = checklast(vval(SCENE));
543 <                if (vdef(OBJECT)) {
544 <                        objdate = checklast(vval(OBJECT));
545 <                        if (objdate > scenedate)
546 <                                scenedate = objdate;
547 <                }
548 <        }
549 <        if (octreedate < 0 & scenedate < 0) {
550 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
551 <                                vnam(OCTREE), vnam(SCENE));
540 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
541 >                oct0name = newfname(vval(OCTREE), '0');
542 >                oct1name = newfname(vval(OCTREE), '1');
543 >                oct0date = fdate(oct0name);
544 >                oct1date = fdate(oct1name);
545 >        } else
546 >                oct0name = oct1name = vval(OCTREE);
547 >        if ((scenedate = checklast(vval(SCENE))) &&
548 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
549 >                scenedate = objdate;
550 >        illumdate = checklast(vval(ILLUM));
551 >        if (!octreedate & !scenedate & !illumdate) {
552 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
553 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
554                  exit(1);
555          }
556 +        matdate = checklast(vval(MATERIAL));
557   }      
558  
559  
# Line 431 | Line 562 | double org[3], *sizp;
562   {
563          extern FILE     *popen();
564          static double   oorg[3], osiz = 0.;
565 <        char    buf[MAXPATH+16];
565 >        double  min[3], max[3];
566 >        char    buf[1024];
567          FILE    *fp;
568 +        register int    i;
569  
570 <        if (osiz <= FTINY) {
571 <                oconv();                /* does nothing if done already */
572 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
573 <                if ((fp = popen(buf, "r")) == NULL)
574 <                        syserr("getinfo");
575 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
576 <                                &oorg[2], &osiz) != 4) {
577 <                        fprintf(stderr,
570 >        if (osiz <= FTINY)
571 >                if (noaction && fdate(oct1name) <
572 >                                (scenedate>illumdate?scenedate:illumdate)) {
573 >                                                        /* run getbbox */
574 >                        sprintf(buf, "getbbox -w -h %s",
575 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
576 >                        if ((fp = popen(buf, "r")) == NULL)
577 >                                syserr("getbbox");
578 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
579 >                                        &min[0], &max[0], &min[1], &max[1],
580 >                                        &min[2], &max[2]) != 6) {
581 >                                fprintf(stderr,
582 >                        "%s: error reading bounding box from getbbox\n",
583 >                                                progname);
584 >                                exit(1);
585 >                        }
586 >                        for (i = 0; i < 3; i++)
587 >                                if (max[i] - min[i] > osiz)
588 >                                        osiz = max[i] - min[i];
589 >                        for (i = 0; i < 3; i++)
590 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
591 >                        pclose(fp);
592 >                } else {                                /* from octree */
593 >                        oconv();        /* does nothing if done already */
594 >                        sprintf(buf, "getinfo -d < %s", oct1name);
595 >                        if ((fp = popen(buf, "r")) == NULL)
596 >                                syserr("getinfo");
597 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
598 >                                        &oorg[2], &osiz) != 4) {
599 >                                fprintf(stderr,
600                          "%s: error reading bounding cube from getinfo\n",
601 <                                        progname);
602 <                        exit(1);
601 >                                                progname);
602 >                                exit(1);
603 >                        }
604 >                        pclose(fp);
605                  }
449                pclose(fp);
450        }
606          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
607   }
608  
# Line 501 | Line 656 | setdefaults()                  /* set default values for unassigned v
656  
657   printvals()                     /* print variable values */
658   {
659 <        register int    i, j;
659 >        int     i, j, clipline;
660 >        register char   *cp;
661 >        register int    k;
662  
663 <        for (i = 0; i < NVARS; i++)
664 <                for (j = 0; j < vdef(i); j++)
665 <                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
663 >        for (i = 0; i < NVARS; i++)             /* print each variable */
664 >            for (j = 0; j < vdef(i); j++) {     /* print each assignment */
665 >                fputs(vnam(i), stdout);
666 >                fputs("= ", stdout);
667 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
668 >                                - strlen(vnam(i)) ;
669 >                cp = nvalue(vv+i, j);
670 >                while (*cp) {
671 >                    putchar(*cp++);
672 >                    if (--k <= 0) {             /* line too long */
673 >                        while (*cp && !isspace(*cp))
674 >                            putchar(*cp++);     /* finish this word */
675 >                        if (*cp) {              /* start new line */
676 >                            putchar('\n');
677 >                            fputs(vnam(i), stdout);
678 >                            putchar('=');
679 >                            k = clipline;
680 >                        }
681 >                    }
682 >                }
683 >                putchar('\n');
684 >            }
685          fflush(stdout);
686   }
687  
688  
689 < oconv()                         /* run oconv if necessary */
689 > oconv()                         /* run oconv and mkillum if necessary */
690   {
691 <        char    combuf[512], ocopts[64];
691 >        static char     illumtmp[] = "ilXXXXXX";
692 >        char    combuf[1024], ocopts[64], mkopts[64];
693  
694 <        if (octreedate >= scenedate)    /* check dates */
694 >        oconvopts(ocopts);              /* get options */
695 >        if (octreedate < scenedate) {   /* check date on original octree */
696 >                if (touchonly && octreedate)
697 >                        touch(vval(OCTREE));
698 >                else {                          /* build command */
699 >                        if (vdef(MATERIAL))
700 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
701 >                                                vval(MATERIAL), vval(SCENE),
702 >                                                vval(OCTREE));
703 >                        else
704 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
705 >                                                vval(SCENE), vval(OCTREE));
706 >                        
707 >                        if (runcom(combuf)) {           /* run it */
708 >                                fprintf(stderr,
709 >                                "%s: error generating octree\n\t%s removed\n",
710 >                                                progname, vval(OCTREE));
711 >                                unlink(vval(OCTREE));
712 >                                exit(1);
713 >                        }
714 >                }
715 >                octreedate = time((time_t *)NULL);
716 >                if (octreedate < scenedate)     /* in case clock is off */
717 >                        octreedate = scenedate;
718 >        }
719 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
720 >                oct1date = octreedate > matdate ? octreedate : matdate;
721 >        if (oct1date >= octreedate & oct1date >= matdate
722 >                        & oct1date >= illumdate)        /* all done */
723                  return;
724 <                                        /* build command */
725 <        oconvopts(ocopts);
726 <        if (vdef(MATERIAL))
727 <                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
728 <                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
729 <        else
730 <                sprintf(combuf, "oconv%s %s > %s", ocopts,
731 <                                vval(SCENE), vval(OCTREE));
732 <        
733 <        if (runcom(combuf)) {           /* run it */
734 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
735 <                                progname, vval(OCTREE));
736 <                unlink(vval(OCTREE));
737 <                exit(1);
724 >                                                /* make octree0 */
725 >        if (oct0date < scenedate | oct0date < illumdate) {
726 >                if (touchonly && oct0date)
727 >                        touch(oct0name);
728 >                else {                          /* build command */
729 >                        if (octreedate)
730 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
731 >                                        vval(OCTREE), vval(ILLUM), oct0name);
732 >                        else if (vdef(MATERIAL))
733 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
734 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
735 >                        else
736 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
737 >                                        vval(ILLUM), oct0name);
738 >                        if (runcom(combuf)) {           /* run it */
739 >                                fprintf(stderr,
740 >                                "%s: error generating octree\n\t%s removed\n",
741 >                                                progname, oct0name);
742 >                                unlink(oct0name);
743 >                                exit(1);
744 >                        }
745 >                }
746 >                oct0date = time((time_t *)NULL);
747 >                if (oct0date < octreedate)      /* in case clock is off */
748 >                        oct0date = octreedate;
749 >                if (oct0date < illumdate)       /* ditto */
750 >                        oct0date = illumdate;
751 >                }
752 >        if (touchonly && oct1date)
753 >                touch(oct1name);
754 >        else {
755 >                mkillumopts(mkopts);            /* build mkillum command */
756 >                mktemp(illumtmp);
757 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
758 >                                oct0name, vval(ILLUM), illumtmp);
759 >                if (runcom(combuf)) {                   /* run it */
760 >                        fprintf(stderr, "%s: error running mkillum\n",
761 >                                        progname);
762 >                        unlink(illumtmp);
763 >                        exit(1);
764 >                }
765 >                                                /* make octree1 (frozen) */
766 >                if (octreedate)
767 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
768 >                                vval(OCTREE), illumtmp, oct1name);
769 >                else if (vdef(MATERIAL))
770 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
771 >                                vval(MATERIAL), illumtmp, oct1name);
772 >                else
773 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
774 >                                illumtmp, oct1name);
775 >                if (runcom(combuf)) {           /* run it */
776 >                        fprintf(stderr,
777 >                                "%s: error generating octree\n\t%s removed\n",
778 >                                        progname, oct1name);
779 >                        unlink(oct1name);
780 >                        unlink(illumtmp);
781 >                        exit(1);
782 >                }
783 >                rmfile(illumtmp);
784          }
785 <        octreedate = time(0);
785 >        oct1date = time((time_t *)NULL);
786 >        if (oct1date < oct0date)        /* in case clock is off */
787 >                oct1date = oct0date;
788   }
789  
790  
# Line 557 | Line 810 | register char  *oo;
810   }
811  
812  
813 + mkillumopts(mo)                         /* get mkillum options */
814 + register char   *mo;
815 + {
816 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
817 +
818 +        *mo = '\0';
819 +        if (vdef(MKILLUM))
820 +                addarg(mo, vval(MKILLUM));
821 + }
822 +
823 +
824   checkambfile()                  /* check date on ambient file */
825   {
826 <        long    afdate;
826 >        time_t  afdate;
827  
828 <        if (vdef(AMBFILE)) {
829 <                afdate = fdate(vval(AMBFILE));
830 <                if (afdate >= 0 & octreedate > afdate)
828 >        if (!vdef(AMBFILE))
829 >                return;
830 >        if (!(afdate = fdate(vval(AMBFILE))))
831 >                return;
832 >        if (oct1date > afdate)
833 >                if (touchonly)
834 >                        touch(vval(AMBFILE));
835 >                else
836                          rmfile(vval(AMBFILE));
568        }
837   }
838  
839  
# Line 575 | Line 843 | ambval()                               /* compute ambient value */
843          if (vdef(EXPOSURE)) {
844                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
845                          return(.5/pow(2.,atof(vval(EXPOSURE))));
846 <                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
579 <                        return(.5/atof(vval(EXPOSURE)));
580 <                badvalue(EXPOSURE);
846 >                return(.5/atof(vval(EXPOSURE)));
847          }
848          if (vlet(ZONE) == 'E')
849                  return(10.);
# Line 587 | Line 853 | ambval()                               /* compute ambient value */
853   }
854  
855  
856 < lowqopts(op)                            /* low quality rendering options */
856 > renderopts(op, po)                      /* set rendering options */
857 > char    *op, *po;
858 > {
859 >        switch(vscale(QUALITY)) {
860 >        case LOW:
861 >                lowqopts(op, po);
862 >                break;
863 >        case MEDIUM:
864 >                medqopts(op, po);
865 >                break;
866 >        case HIGH:
867 >                hiqopts(op, po);
868 >                break;
869 >        }
870 > }
871 >
872 >
873 > lowqopts(op, po)                        /* low quality rendering options */
874   register char   *op;
875 + char    *po;
876   {
877          double  d, org[3], siz[3];
878  
879          *op = '\0';
880 +        *po = '\0';
881          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
882                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
883                  badvalue(ZONE);
884          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
885 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
886 +                badvalue(ZONE);
887          getoctcube(org, &d);
888          d *= 3./(siz[0]+siz[1]+siz[2]);
889          switch (vscale(DETAIL)) {
890          case LOW:
891 <                op = addarg(op, "-ps 16 -dp 16");
891 >                po = addarg(po, "-ps 16");
892 >                op = addarg(op, "-dp 64");
893                  sprintf(op, " -ar %d", (int)(4*d));
894                  op += strlen(op);
895                  break;
896          case MEDIUM:
897 <                op = addarg(op, "-ps 8 -dp 32");
897 >                po = addarg(po, "-ps 8");
898 >                op = addarg(op, "-dp 128");
899                  sprintf(op, " -ar %d", (int)(8*d));
900                  op += strlen(op);
901                  break;
902          case HIGH:
903 <                op = addarg(op, "-ps 4 -dp 64");
903 >                po = addarg(po, "-ps 4");
904 >                op = addarg(op, "-dp 256");
905                  sprintf(op, " -ar %d", (int)(16*d));
906                  op += strlen(op);
907                  break;
908          }
909 <        op = addarg(op, "-pt .16");
909 >        po = addarg(po, "-pt .16");
910          if (vbool(PENUMBRAS))
911                  op = addarg(op, "-ds .4");
912          else
913                  op = addarg(op, "-ds 0");
914 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
914 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
915          if (vdef(AMBFILE)) {
916                  sprintf(op, " -af %s", vval(AMBFILE));
917                  op += strlen(op);
# Line 629 | Line 919 | register char  *op;
919                  overture = 0;
920          switch (vscale(VARIABILITY)) {
921          case LOW:
922 <                op = addarg(op, "-aa .4 -ad 32");
922 >                op = addarg(op, "-aa .4 -ad 64");
923                  break;
924          case MEDIUM:
925 <                op = addarg(op, "-aa .3 -ad 64");
925 >                op = addarg(op, "-aa .3 -ad 128");
926                  break;
927          case HIGH:
928 <                op = addarg(op, "-aa .25 -ad 128");
928 >                op = addarg(op, "-aa .25 -ad 256");
929                  break;
930          }
931          op = addarg(op, "-as 0");
# Line 648 | Line 938 | register char  *op;
938   }
939  
940  
941 < medqopts(op)                            /* medium quality rendering options */
941 > medqopts(op, po)                        /* medium quality rendering options */
942   register char   *op;
943 + char    *po;
944   {
945 <        double  d, org[3], siz[3];
945 >        double  d, org[3], siz[3], asz;
946  
947          *op = '\0';
948 +        *po = '\0';
949          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
950                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
951                  badvalue(ZONE);
952          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
953 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
954 +                badvalue(ZONE);
955          getoctcube(org, &d);
956 <        d *= 3./(siz[0]+siz[1]+siz[2]);
956 >        asz = (siz[0]+siz[1]+siz[2])/3.;
957 >        d /= asz;
958          switch (vscale(DETAIL)) {
959          case LOW:
960 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
961 <                op = addarg(op, "-dp 64");
960 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
961 >                op = addarg(op, "-dp 256");
962                  sprintf(op, " -ar %d", (int)(8*d));
963                  op += strlen(op);
964 +                sprintf(op, " -ms %.2g", asz/20.);
965 +                op += strlen(op);
966                  break;
967          case MEDIUM:
968 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
969 <                op = addarg(op, "-dp 128");
968 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
969 >                op = addarg(op, "-dp 512");
970                  sprintf(op, " -ar %d", (int)(16*d));
971                  op += strlen(op);
972 +                sprintf(op, " -ms %.2g", asz/40.);
973 +                op += strlen(op);
974                  break;
975          case HIGH:
976 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
977 <                op = addarg(op, "-dp 256");
976 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
977 >                op = addarg(op, "-dp 1024");
978                  sprintf(op, " -ar %d", (int)(32*d));
979                  op += strlen(op);
980 +                sprintf(op, " -ms %.2g", asz/80.);
981 +                op += strlen(op);
982                  break;
983          }
984 <        op = addarg(op, "-pt .08");
984 >        po = addarg(po, "-pt .08");
985          if (vbool(PENUMBRAS))
986 <                op = addarg(op, "-ds .2 -dj .35");
986 >                op = addarg(op, "-ds .2 -dj .5");
987          else
988                  op = addarg(op, "-ds .3");
989 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
989 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
990          if (overture = vint(INDIRECT)) {
991                  sprintf(op, " -ab %d", overture);
992                  op += strlen(op);
# Line 697 | Line 998 | register char  *op;
998                  overture = 0;
999          switch (vscale(VARIABILITY)) {
1000          case LOW:
1001 <                op = addarg(op, "-aa .25 -ad 128 -as 0");
1001 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
1002                  break;
1003          case MEDIUM:
1004 <                op = addarg(op, "-aa .2 -ad 300 -as 64");
1004 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
1005                  break;
1006          case HIGH:
1007 <                op = addarg(op, "-aa .15 -ad 500 -as 128");
1007 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
1008                  break;
1009          }
1010          d = ambval();
# Line 715 | Line 1016 | register char  *op;
1016   }
1017  
1018  
1019 < hiqopts(op)                             /* high quality rendering options */
1019 > hiqopts(op, po)                         /* high quality rendering options */
1020   register char   *op;
1021 + char    *po;
1022   {
1023 <        double  d, org[3], siz[3];
1023 >        double  d, org[3], siz[3], asz;
1024  
1025          *op = '\0';
1026 +        *po = '\0';
1027          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
1028                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
1029                  badvalue(ZONE);
1030          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
1031 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
1032 +                badvalue(ZONE);
1033          getoctcube(org, &d);
1034 <        d *= 3./(siz[0]+siz[1]+siz[2]);
1034 >        asz = (siz[0]+siz[1]+siz[2])/3.;
1035 >        d /= asz;
1036          switch (vscale(DETAIL)) {
1037          case LOW:
1038 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1039 <                op = addarg(op, "-dp 256");
1038 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1039 >                op = addarg(op, "-dp 1024");
1040                  sprintf(op, " -ar %d", (int)(16*d));
1041                  op += strlen(op);
1042 +                sprintf(op, " -ms %.2g", asz/40.);
1043 +                op += strlen(op);
1044                  break;
1045          case MEDIUM:
1046 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1047 <                op = addarg(op, "-dp 512");
1046 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1047 >                op = addarg(op, "-dp 2048");
1048                  sprintf(op, " -ar %d", (int)(32*d));
1049                  op += strlen(op);
1050 +                sprintf(op, " -ms %.2g", asz/80.);
1051 +                op += strlen(op);
1052                  break;
1053          case HIGH:
1054 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1055 <                op = addarg(op, "-dp 1024");
1054 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1055 >                op = addarg(op, "-dp 4096");
1056                  sprintf(op, " -ar %d", (int)(64*d));
1057                  op += strlen(op);
1058 +                sprintf(op, " -ms %.2g", asz/160.);
1059 +                op += strlen(op);
1060                  break;
1061          }
1062 <        op = addarg(op, "-pt .04");
1062 >        po = addarg(po, "-pt .04");
1063          if (vbool(PENUMBRAS))
1064 <                op = addarg(op, "-ds .1 -dj .7");
1064 >                op = addarg(op, "-ds .1 -dj .65");
1065          else
1066                  op = addarg(op, "-ds .2");
1067 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
1067 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1068          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1069          op += strlen(op);
1070          if (vdef(AMBFILE)) {
# Line 762 | Line 1074 | register char  *op;
1074                  overture = 0;
1075          switch (vscale(VARIABILITY)) {
1076          case LOW:
1077 <                op = addarg(op, "-aa .15 -ad 200 -as 0");
1077 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
1078                  break;
1079          case MEDIUM:
1080 <                op = addarg(op, "-aa .125 -ad 512 -as 128");
1080 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
1081                  break;
1082          case HIGH:
1083 <                op = addarg(op, "-aa .08 -ad 850 -as 256");
1083 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
1084                  break;
1085          }
1086          d = ambval();
# Line 784 | Line 1096 | xferopts(ro)                           /* transfer options if indicated */
1096   char    *ro;
1097   {
1098          int     fd, n;
1099 +        register char   *cp;
1100          
1101          n = strlen(ro);
1102          if (n < 2)
1103                  return;
1104          if (vdef(OPTFILE)) {
1105 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
1105 >                for (cp = ro; cp[1]; cp++)
1106 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1107 >                                *cp = '\n';
1108 >                        else
1109 >                                *cp = cp[1];
1110 >                *cp = '\n';
1111 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1112 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1113                          syserr(vval(OPTFILE));
1114 <                if (write(fd, ro+1, n-1) != n-1)
795 <                        syserr(vval(OPTFILE));
796 <                write(fd, "\n", 1);
797 <                close(fd);
798 <                sprintf(ro, " \"^%s\"", vval(OPTFILE));
1114 >                sprintf(ro, " @%s", vval(OPTFILE));
1115          }
1116   #ifdef MSDOS
1117          else if (n > 50) {
1118 <                register char   *evp = bmalloc(n+6);
803 <                if (evp == NULL)
804 <                        syserr(progname);
805 <                strcpy(evp, "ROPT=");
806 <                strcat(evp, ro);
807 <                if (putenv(evp) != 0) {
808 <                        fprintf(stderr, "%s: out of environment space\n",
809 <                                        progname);
810 <                        exit(1);
811 <                }
1118 >                setenv("ROPT", ro+1);
1119                  strcpy(ro, " $ROPT");
1120          }
1121   #endif
# Line 823 | Line 1130 | register char  *po;
1130                  po = addarg(po, "-1 -e");
1131                  po = addarg(po, vval(EXPOSURE));
1132          }
1133 <        if (vscale(QUALITY) == HIGH)
1134 <                po = addarg(po, "-r .65");
1133 >        switch (vscale(QUALITY)) {
1134 >        case MEDIUM:
1135 >                po = addarg(po, "-r 1");
1136 >                break;
1137 >        case HIGH:
1138 >                po = addarg(po, "-m .25");
1139 >                break;
1140 >        }
1141          if (vdef(PFILT))
1142                  po = addarg(po, vval(PFILT));
1143   }
# Line 885 | Line 1198 | register char  *vs;
1198                  zpos = -1; vs++;
1199          }
1200          viewtype = 'v';
1201 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1201 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
1202                  viewtype = *vs++;
1203          cp = viewopts;
1204          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
# Line 896 | Line 1209 | register char  *vs;
1209                          badvalue(ZONE);
1210                  for (i = 0; i < 3; i++) {
1211                          dim[i] -= cent[i];
1212 +                        if (dim[i] <= FTINY)
1213 +                                badvalue(ZONE);
1214                          cent[i] += .5*dim[i];
1215                  }
1216                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
# Line 938 | Line 1253 | register char  *vs;
1253                  case 'h':
1254                          cp = addarg(cp, "-vh 180 -vv 180");
1255                          break;
1256 +                case 'c':
1257 +                        cp = addarg(cp, "-vh 180 -vv 90");
1258 +                        break;
1259                  }
1260          } else {
1261                  while (!isspace(*vs))           /* else skip id */
# Line 948 | Line 1266 | register char  *vs;
1266                          cp += strlen(cp);
1267                  }
1268          }
1269 <                                        /* append any additional options */
1269 >        if (cp == viewopts)             /* append any additional options */
1270 >                vs++;           /* skip prefixed space if unneeded */
1271          strcpy(cp, vs);
1272 + #ifdef MSDOS
1273 +        if (strlen(viewopts) > 40) {
1274 +                setenv("VIEW", viewopts);
1275 +                return("$VIEW");
1276 +        }
1277 + #endif
1278          return(viewopts);
1279   }
1280  
# Line 957 | Line 1282 | register char  *vs;
1282   char *
1283   getview(n, vn)                          /* get view n, or NULL if none */
1284   int     n;
1285 < char    *vn;
1285 > char    *vn;            /* returned view name */
1286   {
1287          register char   *mv;
1288  
1289 <        if (viewselect != NULL) {
1289 >        if (viewselect != NULL) {               /* command-line selected */
1290                  if (n)                          /* only do one */
1291                          return(NULL);
1292                  if (viewselect[0] == '-') {     /* already specified */
# Line 974 | Line 1299 | char   *vn;
1299                                  ;
1300                          *vn = '\0';
1301                  }
1302 +                                                /* view number? */
1303 +                if (isint(viewselect))
1304 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1305                                                  /* check list */
1306                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1307                          if (matchword(viewselect, mv))
1308                                  return(specview(mv));
1309                  return(specview(viewselect));   /* standard view? */
1310          }
1311 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1312 <                if (*mv != '-')
1313 <                        while (*mv && !isspace(*mv))
1314 <                                *vn++ = *mv++;
1311 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1312 >        if (vn != NULL & mv != NULL) {
1313 >                register char   *mv2 = mv;
1314 >                if (*mv2 != '-')
1315 >                        while (*mv2 && !isspace(*mv2))
1316 >                                *vn++ = *mv2++;
1317                  *vn = '\0';
1318          }
1319 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1319 >        return(specview(mv));
1320   }
1321  
1322  
1323 < rview(opts)                             /* run rview with first view */
1324 < char    *opts;
1323 > printview(vopts)                        /* print out selected view */
1324 > register char   *vopts;
1325   {
1326 +        extern char     *atos(), *getenv();
1327 +        char    buf[256];
1328 +        FILE    *fp;
1329 +        register char   *cp;
1330 +
1331 +        if (vopts == NULL)
1332 +                return(-1);
1333 +        fputs("VIEW=", stdout);
1334 +        do {
1335 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1336 +                        vopts = sskip(vopts);
1337 +                        if (!*atos(buf, sizeof(buf), vopts))
1338 +                                return(-1);
1339 +                        if ((fp = fopen(buf, "r")) == NULL)
1340 +                                return(-1);
1341 +                        for (buf[sizeof(buf)-2] = '\n';
1342 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1343 +                                                buf[0] != '\n';
1344 +                                        buf[sizeof(buf)-2] = '\n') {
1345 +                                if (buf[sizeof(buf)-2] != '\n') {
1346 +                                        ungetc(buf[sizeof(buf)-2], fp);
1347 +                                        buf[sizeof(buf)-2] = '\0';
1348 +                                }
1349 +                                if (matchword(buf, "VIEW=") ||
1350 +                                                matchword(buf, "rview")) {
1351 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1352 +                                                putchar(*cp);
1353 +                                }
1354 +                        }
1355 +                        fclose(fp);
1356 +                        vopts = sskip(vopts);
1357 +                } else {
1358 +                        while (isspace(*vopts))
1359 +                                vopts++;
1360 +                        putchar(' ');
1361 + #ifdef MSDOS
1362 +                        if (*vopts == '$') {            /* expand env. var. */
1363 +                                if (!*atos(buf, sizeof(buf), vopts+1))
1364 +                                        return(-1);
1365 +                                if ((cp = getenv(buf)) == NULL)
1366 +                                        return(-1);
1367 +                                fputs(cp, stdout);
1368 +                                vopts = sskip(vopts);
1369 +                        } else
1370 + #endif
1371 +                                while (*vopts && !isspace(*vopts))
1372 +                                        putchar(*vopts++);
1373 +                }
1374 +        } while (*vopts++);
1375 +        putchar('\n');
1376 +        return(0);
1377 + }
1378 +
1379 +
1380 + rview(opts, po)                         /* run rview with first view */
1381 + char    *opts, *po;
1382 + {
1383 +        char    *vw;
1384          char    combuf[512];
1385                                          /* build command */
1386 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1386 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1387 >                return;
1388 >        if (sayview)
1389 >                printview(vw);
1390 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1391          if (rvdevice != NULL)
1392                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1393 <        strcat(combuf, vval(OCTREE));
1393 >        if (vdef(EXPOSURE))
1394 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1395 >        strcat(combuf, oct1name);
1396          if (runcom(combuf)) {           /* run it */
1397                  fprintf(stderr, "%s: error running rview\n", progname);
1398                  exit(1);
# Line 1006 | Line 1400 | char   *opts;
1400   }
1401  
1402  
1403 < rpict(opts)                             /* run rpict and pfilt for each view */
1404 < char    *opts;
1403 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1404 > char    *opts, *po;
1405   {
1406          char    combuf[1024];
1407 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1407 >        char    rawfile[MAXPATH], picfile[MAXPATH];
1408 >        char    zopt[MAXPATH+4], rep[MAXPATH+16], res[32];
1409          char    pfopts[128];
1410          char    vs[32], *vw;
1411          int     vn, mult;
1412 +        time_t  rfdt, pfdt;
1413                                          /* get pfilt options */
1414          pfiltopts(pfopts);
1415                                          /* get resolution, reporting */
1416 <        mult = vscale(QUALITY)+1;
1416 >        switch (vscale(QUALITY)) {
1417 >        case LOW:
1418 >                mult = 1;
1419 >                break;
1420 >        case MEDIUM:
1421 >                mult = 2;
1422 >                break;
1423 >        case HIGH:
1424 >                mult = 3;
1425 >                break;
1426 >        }
1427          {
1428                  int     xres, yres;
1429                  double  aspect;
# Line 1047 | Line 1453 | char   *opts;
1453                                          /* do each view */
1454          vn = 0;
1455          while ((vw = getview(vn++, vs)) != NULL) {
1456 +                if (sayview)
1457 +                        printview(vw);
1458                  if (!vs[0])
1459                          sprintf(vs, "%d", vn);
1460                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1461 +                if (vdef(ZFILE))
1462 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1463 +                else
1464 +                        zopt[0] = '\0';
1465                                                  /* check date on picture */
1466 <                if (fdate(picfile) > octreedate)
1466 >                pfdt = fdate(picfile);
1467 >                if (pfdt >= oct1date)
1468                          continue;
1469 +                                                /* get raw file name */
1470 +                sprintf(rawfile, "%s_%s.unf",
1471 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1472 +                rfdt = fdate(rawfile);
1473 +                if (touchonly) {                /* update times only */
1474 +                        if (rfdt) {
1475 +                                if (rfdt < oct1date)
1476 +                                        touch(rawfile);
1477 +                        } else if (pfdt && pfdt < oct1date)
1478 +                                touch(picfile);
1479 +                        continue;
1480 +                }
1481                                                  /* build rpict command */
1482 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1483 <                if (fdate(rawfile) > octreedate)        /* recover */
1484 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1060 <                                        rep, opts, rawfile, vval(OCTREE));
1482 >                if (rfdt >= oct1date)           /* recover */
1483 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1484 >                                rep, po, opts, zopt, rawfile, oct1name);
1485                  else {
1486                          if (overture) {         /* run overture calculation */
1487                                  sprintf(combuf,
1488                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1489                                                  rep, vw, opts,
1490 <                                                vval(OCTREE), overfile);
1490 >                                                oct1name, overfile);
1491                                  if (runcom(combuf)) {
1492                                          fprintf(stderr,
1493                                          "%s: error in overture for view %s\n",
# Line 1074 | Line 1498 | char   *opts;
1498                                  rmfile(overfile);
1499   #endif
1500                          }
1501 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1502 <                                        rep, vw, res, opts,
1503 <                                        vval(OCTREE), rawfile);
1501 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1502 >                                        rep, vw, res, po, opts, zopt,
1503 >                                        oct1name, rawfile);
1504                  }
1505                  if (runcom(combuf)) {           /* run rpict */
1506                          fprintf(stderr, "%s: error rendering view %s\n",
1507                                          progname, vs);
1508                          exit(1);
1509                  }
1510 +                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1511                                                  /* build pfilt command */
1512 <                if (mult > 1)
1513 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1512 >                        if (mult > 1)
1513 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1514                                          pfopts, mult, mult, rawfile, picfile);
1515 <                else
1516 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1517 <                                        rawfile, picfile);
1518 <                if (runcom(combuf)) {           /* run pfilt */
1519 <                        fprintf(stderr,
1520 <                        "%s: error filtering view %s\n\t%s removed\n",
1521 <                                        progname, vs, picfile);
1522 <                        unlink(picfile);
1523 <                        exit(1);
1515 >                        else
1516 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1517 >                                                rawfile, picfile);
1518 >                        if (runcom(combuf)) {           /* run pfilt */
1519 >                                fprintf(stderr,
1520 >                                "%s: error filtering view %s\n\t%s removed\n",
1521 >                                                progname, vs, picfile);
1522 >                                unlink(picfile);
1523 >                                exit(1);
1524 >                        }
1525                  }
1526 <                                                /* remove raw file */
1527 <                rmfile(rawfile);
1526 >                                                /* remove/rename raw file */
1527 >                if (vdef(RAWFILE)) {
1528 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1529 >                        mvfile(rawfile, combuf);
1530 >                } else
1531 >                        rmfile(rawfile);
1532          }
1533   }
1534  
1535  
1536 + touch(fn)                       /* update a file */
1537 + char    *fn;
1538 + {
1539 +        if (!silent)
1540 +                printf("\ttouch %s\n", fn);
1541 +        if (noaction)
1542 +                return(0);
1543 + #ifdef notused
1544 +        if (access(fn, F_OK) == -1)             /* create it */
1545 +                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1546 +                        return(-1);
1547 + #endif
1548 +        return(setfdate(fn, time((time_t *)NULL)));
1549 + }
1550 +
1551 +
1552   runcom(cs)                      /* run command */
1553   char    *cs;
1554   {
# Line 1128 | Line 1574 | char   *fn;
1574                  return(0);
1575          return(unlink(fn));
1576   }
1577 +
1578 +
1579 + mvfile(fold, fnew)              /* move a file */
1580 + char    *fold, *fnew;
1581 + {
1582 +        if (!silent)
1583 + #ifdef MSDOS
1584 +                printf("\trename %s %s\n", fold, fnew);
1585 + #else
1586 +                printf("\tmv %s %s\n", fold, fnew);
1587 + #endif
1588 +        if (noaction)
1589 +                return(0);
1590 +        return(rename(fold, fnew));
1591 + }
1592 +
1593 +
1594 + #ifdef MSDOS
1595 + setenv(vname, value)            /* set an environment variable */
1596 + char    *vname, *value;
1597 + {
1598 +        register char   *evp;
1599 +
1600 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1601 +        if (evp == NULL)
1602 +                syserr(progname);
1603 +        sprintf(evp, "%s=%s", vname, value);
1604 +        if (putenv(evp) != 0) {
1605 +                fprintf(stderr, "%s: out of environment space\n", progname);
1606 +                exit(1);
1607 +        }
1608 +        if (!silent)
1609 +                printf("set %s\n", evp);
1610 + }
1611 + #endif
1612  
1613  
1614   badvalue(vc)                    /* report bad variable value and exit */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines