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.4 by greg, Fri Mar 12 13:37:03 1993 UTC vs.
Revision 2.41 by greg, Mon Oct 24 13:49:16 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1993 Regents of the University of California */
1 > /* Copyright (c) 1994 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 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                                  /* total number of variables */
53 < #define NVARS           21
53 > #define NVARS           23
54  
55   VARIABLE        vv[NVARS] = {           /* variable-value pairs */
56          {"objects",     3,      0,      NULL,   catvalues},
57          {"scene",       3,      0,      NULL,   catvalues},
58          {"materials",   3,      0,      NULL,   catvalues},
59 +        {"illum",       3,      0,      NULL,   catvalues},
60 +        {"mkillum",     3,      0,      NULL,   catvalues},
61          {"render",      3,      0,      NULL,   catvalues},
62          {"oconv",       3,      0,      NULL,   catvalues},
63          {"pfilt",       2,      0,      NULL,   catvalues},
64          {"view",        2,      0,      NULL,   NULL},
65          {"ZONE",        2,      0,      NULL,   onevalue},
66 <        {"QUALITY",     3,      0,      NULL,   onevalue},
66 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
67          {"OCTREE",      3,      0,      NULL,   onevalue},
68          {"PICTURE",     3,      0,      NULL,   onevalue},
69          {"AMBFILE",     3,      0,      NULL,   onevalue},
70          {"OPTFILE",     3,      0,      NULL,   onevalue},
71 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
71 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
72          {"RESOLUTION",  3,      0,      NULL,   onevalue},
73          {"UP",          2,      0,      NULL,   onevalue},
74 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
75 <        {"DETAIL",      3,      0,      NULL,   onevalue},
76 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
77 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
74 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
75 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
76 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
77 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
78          {"REPORT",      3,      0,      NULL,   onevalue},
79   };
80  
81   VARIABLE        *matchvar();
82   char    *nvalue();
77 int     vscale();
83  
84   #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
85  
# Line 83 | Line 88 | int    vscale();
88   #define vval(vc)        (vv[vc].value)
89   #define vint(vc)        atoi(vval(vc))
90   #define vlet(vc)        UPPER(vval(vc)[0])
91 + #define vscale          vlet
92   #define vbool(vc)       (vlet(vc)=='T')
93  
94 < #define HIGH            2
95 < #define MEDIUM          1
96 < #define LOW             0
94 > #define HIGH            'H'
95 > #define MEDIUM          'M'
96 > #define LOW             'L'
97  
98 < int     lowqopts(), medqopts(), hiqopts();
99 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
98 >                                /* overture calculation file */
99 > #ifdef NIX
100 > char    overfile[] = "overture.raw";
101 > #else
102 > char    overfile[] = "/dev/null";
103 > #endif
104  
105 < #define renderopts      (*setqopts[vscale(QUALITY)])
105 > extern time_t   fdate(), time();
106  
107 < extern long     fdate(), time();
107 > time_t  scenedate;              /* date of latest scene or object file */
108 > time_t  octreedate;             /* date of octree */
109 > time_t  matdate;                /* date of latest material file */
110 > time_t  illumdate;              /* date of last illum file */
111  
112 < long    scenedate;              /* date of latest scene or object file */
113 < long    octreedate;             /* date of octree */
112 > char    *oct0name;              /* name of pre-mkillum octree */
113 > time_t  oct0date;               /* date of pre-mkillum octree */
114 > char    *oct1name;              /* name of post-mkillum octree */
115 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
116  
117 + int     nowarn = 0;             /* no warnings */
118   int     explicate = 0;          /* explicate variables */
119   int     silent = 0;             /* do work silently */
120 + int     touchonly = 0;          /* touch files only */
121   int     noaction = 0;           /* don't do anything */
122 + int     sayview = 0;            /* print view out */
123   char    *rvdevice = NULL;       /* rview output device */
124   char    *viewselect = NULL;     /* specific view only */
125  
126   int     overture = 0;           /* overture calculation needed */
127  
128   char    *progname;              /* global argv[0] */
129 + char    *rifname;               /* global rad input file name */
130  
131   char    radname[MAXPATH];       /* root Radiance file name */
132  
# Line 117 | Line 136 | int    argc;
136   char    *argv[];
137   {
138          char    ropts[512];
139 +        char    popts[64];
140          int     i;
141  
142          progname = argv[0];
# Line 129 | Line 149 | char   *argv[];
149                  case 'n':
150                          noaction++;
151                          break;
152 +                case 't':
153 +                        touchonly++;
154 +                        break;
155                  case 'e':
156                          explicate++;
157                          break;
158                  case 'o':
159                          rvdevice = argv[++i];
160                          break;
161 +                case 'V':
162 +                        sayview++;
163 +                        break;
164                  case 'v':
165                          viewselect = argv[++i];
166                          break;
167 +                case 'w':
168 +                        nowarn++;
169 +                        break;
170                  default:
171                          goto userr;
172                  }
173          if (i >= argc)
174                  goto userr;
175 +        rifname = argv[i];
176                                  /* assign Radiance root file name */
177 <        rootname(radname, argv[i]);
177 >        rootname(radname, rifname);
178                                  /* load variable values */
179 <        load(argv[i]);
179 >        load(rifname);
180                                  /* get any additional assignments */
181          for (i++; i < argc; i++)
182                  setvariable(argv[i]);
# Line 159 | Line 189 | char   *argv[];
189                                  /* print all values if requested */
190          if (explicate)
191                  printvals();
192 <                                /* run simulation */
192 >                                /* build octree (and run mkillum) */
193          oconv();
194 <        renderopts(ropts);
194 >                                /* check date on ambient file */
195 >        checkambfile();
196 >                                /* run simulation */
197 >        renderopts(ropts, popts);
198          xferopts(ropts);
199          if (rvdevice != NULL)
200 <                rview(ropts);
200 >                rview(ropts, popts);
201          else
202 <                rpict(ropts);
202 >                rpict(ropts, popts);
203          exit(0);
204   userr:
205          fprintf(stderr,
206 <        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
206 > "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
207                          progname);
208          exit(1);
209   }
# Line 191 | Line 224 | register char  *rn, *fn;
224   }
225  
226  
227 + #define NOCHAR  127             /* constant for character to delete */
228 +
229 +
230   load(rfname)                    /* load Radiance simulation file */
231   char    *rfname;
232   {
# Line 206 | Line 242 | char   *rfname;
242                  for (cp = buf; *cp; cp++) {
243                          switch (*cp) {
244                          case '\\':
245 <                        case '\n':
210 <                                *cp = ' ';
245 >                                *cp++ = NOCHAR;
246                                  continue;
247                          case '#':
248                                  *cp = '\0';
# Line 227 | Line 262 | setvariable(ass)               /* assign variable according to stri
262   register char   *ass;
263   {
264          char    varname[32];
265 +        int     n;
266          register char   *cp;
267          register VARIABLE       *vp;
268          register int    i;
233        int     n;
269  
270          while (isspace(*ass))           /* skip leading space */
271                  ass++;
# Line 244 | Line 279 | register char  *ass;
279                                          /* trim value */
280          while (isspace(*ass) || *ass == '=')
281                  ass++;
282 <        cp = ass + strlen(ass);
283 <        do
284 <                *cp-- = '\0';
285 <        while (cp >= ass && isspace(*cp));
251 <        n = cp - ass + 1;
252 <        if (!n) {
282 >        for (n = strlen(ass); n > 0; n--)
283 >                if (!isspace(ass[n-1]))
284 >                        break;
285 >        if (!n && !nowarn) {
286                  fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
287                                  progname, varname);
288                  return;
# Line 273 | Line 306 | register char  *ass;
306                  vp->value = malloc(n+1);
307          if (vp->value == NULL)
308                  syserr(progname);
309 <        strcpy(vp->value+i, ass);
309 >        cp = vp->value+i;               /* copy value, squeezing spaces */
310 >        *cp = *ass;
311 >        for (i = 1; i <= n; i++) {
312 >                if (ass[i] == NOCHAR)
313 >                        continue;
314 >                if (isspace(*cp))
315 >                        while (isspace(ass[i]))
316 >                                i++;
317 >                *++cp = ass[i];
318 >        }
319 >        if (isspace(*cp))               /* remove trailing space */
320 >                *cp = '\0';
321          vp->nass++;
322   }
323  
# Line 299 | Line 343 | register int   n;
343   {
344          register char   *cp;
345  
346 <        if (vp == NULL || n < 0 || n >= vp->nass)
346 >        if (vp == NULL | n < 0 | n >= vp->nass)
347                  return(NULL);
348          cp = vp->value;
349          while (n--)
# Line 309 | Line 353 | register int   n;
353   }
354  
355  
312 int
313 vscale(vc)                      /* return scale for variable vc */
314 int     vc;
315 {
316        switch(vlet(vc)) {
317        case 'H':
318                return(HIGH);
319        case 'M':
320                return(MEDIUM);
321        case 'L':
322                return(LOW);
323        }
324        badvalue(vc);
325 }
326
327
356   checkvalues()                   /* check assignments */
357   {
358          register int    i;
# Line 340 | Line 368 | register VARIABLE      *vp;
368   {
369          if (vp->nass < 2)
370                  return;
371 <        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
371 >        if (!nowarn)
372 >                fprintf(stderr,
373 >                "%s: warning - multiple assignment of variable '%s'\n",
374                          progname, vp->name);
375          do
376                  vp->value += strlen(vp->value)+1;
# Line 363 | Line 393 | register VARIABLE      *vp;
393   }
394  
395  
396 < long
396 > int
397 > badmatch(tv, cv)                /* case insensitive truncated comparison */
398 > register char   *tv, *cv;
399 > {
400 >        if (!*tv) return(1);            /* null string cannot match */
401 >        do
402 >                if (UPPER(*tv) != *cv++)
403 >                        return(1);
404 >        while (*++tv);
405 >        return(0);              /* OK */
406 > }
407 >
408 >
409 > boolvalue(vp)                   /* check boolean for legal values */
410 > register VARIABLE       *vp;
411 > {
412 >        if (!vp->nass) return;
413 >        onevalue(vp);
414 >        switch (UPPER(vp->value[0])) {
415 >        case 'T':
416 >                if (badmatch(vp->value, "TRUE")) break;
417 >                return;
418 >        case 'F':
419 >                if (badmatch(vp->value, "FALSE")) break;
420 >                return;
421 >        }
422 >        fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
423 >                        progname, vp->name);
424 >        exit(1);
425 > }
426 >
427 >
428 > qualvalue(vp)                   /* check qualitative var. for legal values */
429 > register VARIABLE       *vp;
430 > {
431 >        if (!vp->nass) return;
432 >        onevalue(vp);
433 >        switch (UPPER(vp->value[0])) {
434 >        case 'L':
435 >                if (badmatch(vp->value, "LOW")) break;
436 >                return;
437 >        case 'M':
438 >                if (badmatch(vp->value, "MEDIUM")) break;
439 >                return;
440 >        case 'H':
441 >                if (badmatch(vp->value, "HIGH")) break;
442 >                return;
443 >        }
444 >        fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
445 >                        progname, vp->name);
446 >        exit(1);
447 > }
448 >
449 >
450 > intvalue(vp)                    /* check integer variable for legal values */
451 > register VARIABLE       *vp;
452 > {
453 >        if (!vp->nass) return;
454 >        onevalue(vp);
455 >        if (isint(vp->value)) return;
456 >        fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
457 >                        progname, vp->name);
458 >        exit(1);
459 > }
460 >
461 >
462 > fltvalue(vp)                    /* check float variable for legal values */
463 > register VARIABLE       *vp;
464 > {
465 >        if (!vp->nass) return;
466 >        onevalue(vp);
467 >        if (isflt(vp->value)) return;
468 >        fprintf(stderr, "%s: illegal value for real variable '%s'\n",
469 >                        progname, vp->name);
470 >        exit(1);
471 > }
472 >
473 >
474 > time_t
475   checklast(fnames)                       /* check files and find most recent */
476   register char   *fnames;
477   {
478          char    thisfile[MAXPATH];
479 <        long    thisdate, lastdate = -1;
479 >        time_t  thisdate, lastdate = 0;
480          register char   *cp;
481  
482 +        if (fnames == NULL)
483 +                return(0);
484          while (*fnames) {
485                  while (isspace(*fnames)) fnames++;
486                  cp = thisfile;
487                  while (*fnames && !isspace(*fnames))
488                          *cp++ = *fnames++;
489                  *cp = '\0';
490 <                if ((thisdate = fdate(thisfile)) < 0)
490 >                if (!(thisdate = fdate(thisfile)))
491                          syserr(thisfile);
492                  if (thisdate > lastdate)
493                          lastdate = thisdate;
# Line 386 | Line 496 | register char  *fnames;
496   }
497  
498  
499 + char *
500 + newfname(orig, pred)            /* create modified file name */
501 + char    *orig;
502 + int     pred;
503 + {
504 +        extern char     *rindex();
505 +        register char   *cp;
506 +        register int    n;
507 +        int     suffix;
508 +
509 +        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
510 +        while (*cp) {
511 +                if (*cp == '.') suffix = n;
512 +                else if (ISDIRSEP(*cp)) suffix = -1;
513 +                cp++; n++;
514 +        }
515 +        if (suffix == -1) suffix = n;
516 +        if ((cp = bmalloc(n+2)) == NULL)
517 +                syserr(progname);
518 +        strncpy(cp, orig, suffix);
519 +        cp[suffix] = pred;                      /* root name + pred + suffix */
520 +        strcpy(cp+suffix+1, orig+suffix);
521 +        return(cp);
522 + }
523 +
524 +
525   checkfiles()                    /* check for existence and modified times */
526   {
527 <        char    *cp;
392 <        long    objdate;
527 >        time_t  objdate;
528  
529          if (!vdef(OCTREE)) {
530 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
530 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
531                          syserr(progname);
532 <                sprintf(cp, "%s.oct", radname);
398 <                vval(OCTREE) = cp;
532 >                sprintf(vval(OCTREE), "%s.oct", radname);
533                  vdef(OCTREE)++;
534          }
535          octreedate = fdate(vval(OCTREE));
536 <        scenedate = -1;
537 <        if (vdef(SCENE)) {
538 <                scenedate = checklast(vval(SCENE));
539 <                if (vdef(OBJECT)) {
540 <                        objdate = checklast(vval(OBJECT));
541 <                        if (objdate > scenedate)
542 <                                scenedate = objdate;
543 <                }
544 <        }
545 <        if (octreedate < 0 & scenedate < 0) {
546 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
547 <                                vnam(OCTREE), vnam(SCENE));
536 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
537 >                oct0name = newfname(vval(OCTREE), '0');
538 >                oct1name = newfname(vval(OCTREE), '1');
539 >                oct0date = fdate(oct0name);
540 >                oct1date = fdate(oct1name);
541 >        } else
542 >                oct0name = oct1name = vval(OCTREE);
543 >        if ((scenedate = checklast(vval(SCENE))) &&
544 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
545 >                scenedate = objdate;
546 >        illumdate = checklast(vval(ILLUM));
547 >        if (!octreedate & !scenedate & !illumdate) {
548 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
549 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
550                  exit(1);
551          }
552 +        matdate = checklast(vval(MATERIAL));
553   }      
554  
555  
# Line 421 | Line 558 | double org[3], *sizp;
558   {
559          extern FILE     *popen();
560          static double   oorg[3], osiz = 0.;
561 <        char    buf[MAXPATH+16];
561 >        double  min[3], max[3];
562 >        char    buf[512];
563          FILE    *fp;
564 +        register int    i;
565  
566 <        if (osiz <= FTINY) {
567 <                oconv();                /* does nothing if done already */
568 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
569 <                if ((fp = popen(buf, "r")) == NULL)
570 <                        syserr("getinfo");
571 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
572 <                                &oorg[2], &osiz) != 4) {
573 <                        fprintf(stderr,
566 >        if (osiz <= FTINY)
567 >                if (noaction && fdate(oct1name) <
568 >                                (scenedate>illumdate?scenedate:illumdate)) {
569 >                                                        /* run getbbox */
570 >                        sprintf(buf, "getbbox -w -h %s",
571 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
572 >                        if ((fp = popen(buf, "r")) == NULL)
573 >                                syserr("getbbox");
574 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
575 >                                        &min[0], &max[0], &min[1], &max[1],
576 >                                        &min[2], &max[2]) != 6) {
577 >                                fprintf(stderr,
578 >                        "%s: error reading bounding box from getbbox\n",
579 >                                                progname);
580 >                                exit(1);
581 >                        }
582 >                        for (i = 0; i < 3; i++)
583 >                                if (max[i] - min[i] > osiz)
584 >                                        osiz = max[i] - min[i];
585 >                        for (i = 0; i < 3; i++)
586 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
587 >                        pclose(fp);
588 >                } else {                                /* from octree */
589 >                        oconv();        /* does nothing if done already */
590 >                        sprintf(buf, "getinfo -d < %s", oct1name);
591 >                        if ((fp = popen(buf, "r")) == NULL)
592 >                                syserr("getinfo");
593 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
594 >                                        &oorg[2], &osiz) != 4) {
595 >                                fprintf(stderr,
596                          "%s: error reading bounding cube from getinfo\n",
597 <                                        progname);
598 <                        exit(1);
597 >                                                progname);
598 >                                exit(1);
599 >                        }
600 >                        pclose(fp);
601                  }
439                pclose(fp);
440        }
602          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
603   }
604  
# Line 491 | Line 652 | setdefaults()                  /* set default values for unassigned v
652  
653   printvals()                     /* print variable values */
654   {
655 <        register int    i, j;
655 >        int     i, j, clipline;
656 >        register char   *cp;
657 >        register int    k;
658  
659 <        for (i = 0; i < NVARS; i++)
660 <                for (j = 0; j < vdef(i); j++)
661 <                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
659 >        for (i = 0; i < NVARS; i++)             /* print each variable */
660 >            for (j = 0; j < vdef(i); j++) {     /* print each assignment */
661 >                fputs(vnam(i), stdout);
662 >                fputs("= ", stdout);
663 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
664 >                                - strlen(vnam(i)) ;
665 >                cp = nvalue(vv+i, j);
666 >                while (*cp) {
667 >                    putchar(*cp++);
668 >                    if (--k <= 0) {             /* line too long */
669 >                        while (*cp && !isspace(*cp))
670 >                            putchar(*cp++);     /* finish this word */
671 >                        if (*cp) {              /* start new line */
672 >                            putchar('\n');
673 >                            fputs(vnam(i), stdout);
674 >                            putchar('=');
675 >                            k = clipline;
676 >                        }
677 >                    }
678 >                }
679 >                putchar('\n');
680 >            }
681          fflush(stdout);
682   }
683  
684  
685 < oconv()                         /* run oconv if necessary */
685 > oconv()                         /* run oconv and mkillum if necessary */
686   {
687 <        char    combuf[512], ocopts[64];
687 >        static char     illumtmp[] = "ilXXXXXX";
688 >        char    combuf[512], ocopts[64], mkopts[64];
689  
690 <        if (octreedate >= scenedate)    /* check dates */
690 >        oconvopts(ocopts);              /* get options */
691 >        if (octreedate < scenedate) {   /* check date on original octree */
692 >                if (touchonly && octreedate)
693 >                        touch(vval(OCTREE));
694 >                else {                          /* build command */
695 >                        if (vdef(MATERIAL))
696 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
697 >                                                vval(MATERIAL), vval(SCENE),
698 >                                                vval(OCTREE));
699 >                        else
700 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
701 >                                                vval(SCENE), vval(OCTREE));
702 >                        
703 >                        if (runcom(combuf)) {           /* run it */
704 >                                fprintf(stderr,
705 >                                "%s: error generating octree\n\t%s removed\n",
706 >                                                progname, vval(OCTREE));
707 >                                unlink(vval(OCTREE));
708 >                                exit(1);
709 >                        }
710 >                }
711 >                octreedate = time((time_t *)NULL);
712 >                if (octreedate < scenedate)     /* in case clock is off */
713 >                        octreedate = scenedate;
714 >        }
715 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
716 >                oct1date = octreedate > matdate ? octreedate : matdate;
717 >        if (oct1date >= octreedate & oct1date >= matdate
718 >                        & oct1date >= illumdate)        /* all done */
719                  return;
720 <                                        /* build command */
721 <        oconvopts(ocopts);
722 <        if (vdef(MATERIAL))
723 <                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
724 <                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
725 <        else
726 <                sprintf(combuf, "oconv%s %s > %s", ocopts,
727 <                                vval(SCENE), vval(OCTREE));
728 <        
729 <        if (runcom(combuf)) {           /* run it */
730 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
731 <                                progname, vval(OCTREE));
732 <                unlink(vval(OCTREE));
733 <                exit(1);
720 >                                                /* make octree0 */
721 >        if (oct0date < scenedate | oct0date < illumdate) {
722 >                if (touchonly && oct0date)
723 >                        touch(oct0name);
724 >                else {                          /* build command */
725 >                        if (octreedate)
726 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
727 >                                        vval(OCTREE), vval(ILLUM), oct0name);
728 >                        else if (vdef(MATERIAL))
729 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
730 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
731 >                        else
732 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
733 >                                        vval(ILLUM), oct0name);
734 >                        if (runcom(combuf)) {           /* run it */
735 >                                fprintf(stderr,
736 >                                "%s: error generating octree\n\t%s removed\n",
737 >                                                progname, oct0name);
738 >                                unlink(oct0name);
739 >                                exit(1);
740 >                        }
741 >                }
742 >                oct0date = time((time_t *)NULL);
743 >                if (oct0date < octreedate)      /* in case clock is off */
744 >                        oct0date = octreedate;
745 >                if (oct0date < illumdate)       /* ditto */
746 >                        oct0date = illumdate;
747 >                }
748 >        if (touchonly && oct1date)
749 >                touch(oct1name);
750 >        else {
751 >                mkillumopts(mkopts);            /* build mkillum command */
752 >                mktemp(illumtmp);
753 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
754 >                                oct0name, vval(ILLUM), illumtmp);
755 >                if (runcom(combuf)) {                   /* run it */
756 >                        fprintf(stderr, "%s: error running mkillum\n",
757 >                                        progname);
758 >                        unlink(illumtmp);
759 >                        exit(1);
760 >                }
761 >                                                /* make octree1 (frozen) */
762 >                if (octreedate)
763 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
764 >                                vval(OCTREE), illumtmp, oct1name);
765 >                else if (vdef(MATERIAL))
766 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
767 >                                vval(MATERIAL), illumtmp, oct1name);
768 >                else
769 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
770 >                                illumtmp, oct1name);
771 >                if (runcom(combuf)) {           /* run it */
772 >                        fprintf(stderr,
773 >                                "%s: error generating octree\n\t%s removed\n",
774 >                                        progname, oct1name);
775 >                        unlink(oct1name);
776 >                        exit(1);
777 >                }
778 >                rmfile(illumtmp);
779          }
780 <        octreedate = time(0);
780 >        oct1date = time((time_t *)NULL);
781 >        if (oct1date < oct0date)        /* in case clock is off */
782 >                oct1date = oct0date;
783   }
784  
785  
# Line 547 | Line 805 | register char  *oo;
805   }
806  
807  
808 + mkillumopts(mo)                         /* get mkillum options */
809 + register char   *mo;
810 + {
811 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
812 +
813 +        *mo = '\0';
814 +        if (vdef(MKILLUM))
815 +                addarg(mo, vval(MKILLUM));
816 + }
817 +
818 +
819 + checkambfile()                  /* check date on ambient file */
820 + {
821 +        time_t  afdate;
822 +
823 +        if (!vdef(AMBFILE))
824 +                return;
825 +        if (!(afdate = fdate(vval(AMBFILE))))
826 +                return;
827 +        if (oct1date > afdate)
828 +                if (touchonly)
829 +                        touch(vval(AMBFILE));
830 +                else
831 +                        rmfile(vval(AMBFILE));
832 + }
833 +
834 +
835   double
836   ambval()                                /* compute ambient value */
837   {
838          if (vdef(EXPOSURE)) {
839                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
840                          return(.5/pow(2.,atof(vval(EXPOSURE))));
841 <                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
557 <                        return(.5/atof(vval(EXPOSURE)));
558 <                badvalue(EXPOSURE);
841 >                return(.5/atof(vval(EXPOSURE)));
842          }
843          if (vlet(ZONE) == 'E')
844                  return(10.);
# Line 565 | Line 848 | ambval()                               /* compute ambient value */
848   }
849  
850  
851 < lowqopts(op)                            /* low quality rendering options */
851 > renderopts(op, po)                      /* set rendering options */
852 > char    *op, *po;
853 > {
854 >        switch(vscale(QUALITY)) {
855 >        case LOW:
856 >                lowqopts(op, po);
857 >                break;
858 >        case MEDIUM:
859 >                medqopts(op, po);
860 >                break;
861 >        case HIGH:
862 >                hiqopts(op, po);
863 >                break;
864 >        }
865 > }
866 >
867 >
868 > lowqopts(op, po)                        /* low quality rendering options */
869   register char   *op;
870 + char    *po;
871   {
872          double  d, org[3], siz[3];
873  
874          *op = '\0';
875 +        *po = '\0';
876          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
877                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
878                  badvalue(ZONE);
879          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
880 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
881 +                badvalue(ZONE);
882          getoctcube(org, &d);
883          d *= 3./(siz[0]+siz[1]+siz[2]);
884          switch (vscale(DETAIL)) {
885          case LOW:
886 <                op = addarg(op, "-ps 16 -dp 16");
886 >                po = addarg(po, "-ps 16");
887 >                op = addarg(op, "-dp 64");
888                  sprintf(op, " -ar %d", (int)(4*d));
889                  op += strlen(op);
890                  break;
891          case MEDIUM:
892 <                op = addarg(op, "-ps 8 -dp 32");
892 >                po = addarg(po, "-ps 8");
893 >                op = addarg(op, "-dp 128");
894                  sprintf(op, " -ar %d", (int)(8*d));
895                  op += strlen(op);
896                  break;
897          case HIGH:
898 <                op = addarg(op, "-ps 4 -dp 64");
898 >                po = addarg(po, "-ps 4");
899 >                op = addarg(op, "-dp 256");
900                  sprintf(op, " -ar %d", (int)(16*d));
901                  op += strlen(op);
902                  break;
903          }
904 <        op = addarg(op, "-pt .16");
904 >        po = addarg(po, "-pt .16");
905          if (vbool(PENUMBRAS))
906                  op = addarg(op, "-ds .4");
907          else
908                  op = addarg(op, "-ds 0");
909 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
909 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
910          if (vdef(AMBFILE)) {
911                  sprintf(op, " -af %s", vval(AMBFILE));
912                  op += strlen(op);
# Line 607 | Line 914 | register char  *op;
914                  overture = 0;
915          switch (vscale(VARIABILITY)) {
916          case LOW:
917 <                op = addarg(op, "-aa .4 -ad 32");
917 >                op = addarg(op, "-aa .4 -ad 64");
918                  break;
919          case MEDIUM:
920 <                op = addarg(op, "-aa .3 -ad 64");
920 >                op = addarg(op, "-aa .3 -ad 128");
921                  break;
922          case HIGH:
923 <                op = addarg(op, "-aa .25 -ad 128");
923 >                op = addarg(op, "-aa .25 -ad 256");
924                  break;
925          }
926          op = addarg(op, "-as 0");
# Line 626 | Line 933 | register char  *op;
933   }
934  
935  
936 < medqopts(op)                            /* medium quality rendering options */
936 > medqopts(op, po)                        /* medium quality rendering options */
937   register char   *op;
938 + char    *po;
939   {
940          double  d, org[3], siz[3];
941  
942          *op = '\0';
943 +        *po = '\0';
944          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
945                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
946                  badvalue(ZONE);
947          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
948 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
949 +                badvalue(ZONE);
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 4" : "-ps 8");
955 <                op = addarg(op, "-dp 64");
954 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
955 >                op = addarg(op, "-dp 256");
956                  sprintf(op, " -ar %d", (int)(8*d));
957                  op += strlen(op);
958                  break;
959          case MEDIUM:
960 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
961 <                op = addarg(op, "-dp 128");
960 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
961 >                op = addarg(op, "-dp 512");
962                  sprintf(op, " -ar %d", (int)(16*d));
963                  op += strlen(op);
964                  break;
965          case HIGH:
966 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
967 <                op = addarg(op, "-dp 256");
966 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
967 >                op = addarg(op, "-dp 1024");
968                  sprintf(op, " -ar %d", (int)(32*d));
969                  op += strlen(op);
970                  break;
971          }
972 <        op = addarg(op, "-pt .08");
972 >        po = addarg(po, "-pt .08");
973          if (vbool(PENUMBRAS))
974 <                op = addarg(op, "-ds .2 -dj .35");
974 >                op = addarg(op, "-ds .2 -dj .5");
975          else
976                  op = addarg(op, "-ds .3");
977 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
978 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
979 <        op += strlen(op);
977 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
978 >        if (overture = vint(INDIRECT)) {
979 >                sprintf(op, " -ab %d", overture);
980 >                op += strlen(op);
981 >        }
982          if (vdef(AMBFILE)) {
983                  sprintf(op, " -af %s", vval(AMBFILE));
984                  op += strlen(op);
# Line 673 | Line 986 | register char  *op;
986                  overture = 0;
987          switch (vscale(VARIABILITY)) {
988          case LOW:
989 <                op = addarg(op, "-aa .25 -ad 128 -as 0");
989 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
990                  break;
991          case MEDIUM:
992 <                op = addarg(op, "-aa .2 -ad 300 -as 64");
992 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
993                  break;
994          case HIGH:
995 <                op = addarg(op, "-aa .15 -ad 500 -as 128");
995 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
996                  break;
997          }
998          d = ambval();
# Line 691 | Line 1004 | register char  *op;
1004   }
1005  
1006  
1007 < hiqopts(op)                             /* high quality rendering options */
1007 > hiqopts(op, po)                         /* high quality rendering options */
1008   register char   *op;
1009 + char    *po;
1010   {
1011          double  d, org[3], siz[3];
1012  
1013          *op = '\0';
1014 +        *po = '\0';
1015          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
1016                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
1017                  badvalue(ZONE);
1018          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
1019 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
1020 +                badvalue(ZONE);
1021          getoctcube(org, &d);
1022          d *= 3./(siz[0]+siz[1]+siz[2]);
1023          switch (vscale(DETAIL)) {
1024          case LOW:
1025 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1026 <                op = addarg(op, "-dp 256");
1025 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1026 >                op = addarg(op, "-dp 1024");
1027                  sprintf(op, " -ar %d", (int)(16*d));
1028                  op += strlen(op);
1029                  break;
1030          case MEDIUM:
1031 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1032 <                op = addarg(op, "-dp 512");
1031 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1032 >                op = addarg(op, "-dp 2048");
1033                  sprintf(op, " -ar %d", (int)(32*d));
1034                  op += strlen(op);
1035                  break;
1036          case HIGH:
1037 <                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1038 <                op = addarg(op, "-dp 1024");
1037 >                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1038 >                op = addarg(op, "-dp 4096");
1039                  sprintf(op, " -ar %d", (int)(64*d));
1040                  op += strlen(op);
1041                  break;
1042          }
1043 <        op = addarg(op, "-pt .04");
1043 >        po = addarg(po, "-pt .04");
1044          if (vbool(PENUMBRAS))
1045                  op = addarg(op, "-ds .1 -dj .7");
1046          else
1047                  op = addarg(op, "-ds .2");
1048 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
1048 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1049          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1050          op += strlen(op);
1051          if (vdef(AMBFILE)) {
# Line 738 | Line 1055 | register char  *op;
1055                  overture = 0;
1056          switch (vscale(VARIABILITY)) {
1057          case LOW:
1058 <                op = addarg(op, "-aa .15 -ad 200 -as 0");
1058 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
1059                  break;
1060          case MEDIUM:
1061 <                op = addarg(op, "-aa .125 -ad 512 -as 128");
1061 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
1062                  break;
1063          case HIGH:
1064 <                op = addarg(op, "-aa .08 -ad 850 -as 256");
1064 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
1065                  break;
1066          }
1067          d = ambval();
# Line 760 | Line 1077 | xferopts(ro)                           /* transfer options if indicated */
1077   char    *ro;
1078   {
1079          int     fd, n;
1080 +        register char   *cp;
1081          
1082          n = strlen(ro);
1083          if (n < 2)
1084                  return;
1085          if (vdef(OPTFILE)) {
1086 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
1086 >                for (cp = ro; cp[1]; cp++)
1087 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1088 >                                *cp = '\n';
1089 >                        else
1090 >                                *cp = cp[1];
1091 >                *cp = '\n';
1092 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1093 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1094                          syserr(vval(OPTFILE));
1095 <                if (write(fd, ro+1, n-1) != n-1)
771 <                        syserr(vval(OPTFILE));
772 <                write(fd, "\n", 1);
773 <                close(fd);
774 <                sprintf(ro, " \"^%s\"", vval(OPTFILE));
1095 >                sprintf(ro, " @%s", vval(OPTFILE));
1096          }
1097   #ifdef MSDOS
1098          else if (n > 50) {
1099 <                register char   *evp = bmalloc(n+6);
779 <                if (evp == NULL)
780 <                        syserr(progname);
781 <                strcpy(evp, "ROPT=");
782 <                strcat(evp, ro);
783 <                if (putenv(evp) != 0) {
784 <                        fprintf(stderr, "%s: out of environment space\n",
785 <                                        progname);
786 <                        exit(1);
787 <                }
1099 >                setenv("ROPT", ro+1);
1100                  strcpy(ro, " $ROPT");
1101          }
1102   #endif
# Line 799 | Line 1111 | register char  *po;
1111                  po = addarg(po, "-1 -e");
1112                  po = addarg(po, vval(EXPOSURE));
1113          }
1114 <        if (vscale(QUALITY) == HIGH)
1115 <                po = addarg(po, "-r .65");
1114 >        switch (vscale(QUALITY)) {
1115 >        case MEDIUM:
1116 >                po = addarg(po, "-r 1");
1117 >                break;
1118 >        case HIGH:
1119 >                po = addarg(po, "-m .25");
1120 >                break;
1121 >        }
1122          if (vdef(PFILT))
1123                  po = addarg(po, vval(PFILT));
1124   }
# Line 872 | Line 1190 | register char  *vs;
1190                          badvalue(ZONE);
1191                  for (i = 0; i < 3; i++) {
1192                          dim[i] -= cent[i];
1193 +                        if (dim[i] <= FTINY)
1194 +                                badvalue(ZONE);
1195                          cent[i] += .5*dim[i];
1196                  }
1197                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
# Line 924 | Line 1244 | register char  *vs;
1244                          cp += strlen(cp);
1245                  }
1246          }
1247 <                                        /* append any additional options */
1247 >        if (cp == viewopts)             /* append any additional options */
1248 >                vs++;           /* skip prefixed space if unneeded */
1249          strcpy(cp, vs);
1250 + #ifdef MSDOS
1251 +        if (strlen(viewopts) > 40) {
1252 +                setenv("VIEW", viewopts);
1253 +                return("$VIEW");
1254 +        }
1255 + #endif
1256          return(viewopts);
1257   }
1258  
# Line 933 | Line 1260 | register char  *vs;
1260   char *
1261   getview(n, vn)                          /* get view n, or NULL if none */
1262   int     n;
1263 < char    *vn;
1263 > char    *vn;            /* returned view name */
1264   {
1265          register char   *mv;
1266  
1267 <        if (viewselect != NULL) {
1267 >        if (viewselect != NULL) {               /* command-line selected */
1268                  if (n)                          /* only do one */
1269                          return(NULL);
1270                  if (viewselect[0] == '-') {     /* already specified */
# Line 950 | Line 1277 | char   *vn;
1277                                  ;
1278                          *vn = '\0';
1279                  }
1280 +                                                /* view number? */
1281 +                if (isint(viewselect))
1282 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1283                                                  /* check list */
1284                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1285                          if (matchword(viewselect, mv))
1286                                  return(specview(mv));
1287                  return(specview(viewselect));   /* standard view? */
1288          }
1289 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1290 <                if (*mv != '-')
1291 <                        while (*mv && !isspace(*mv))
1292 <                                *vn++ = *mv++;
1289 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1290 >        if (vn != NULL & mv != NULL) {
1291 >                register char   *mv2 = mv;
1292 >                if (*mv2 != '-')
1293 >                        while (*mv2 && !isspace(*mv2))
1294 >                                *vn++ = *mv2++;
1295                  *vn = '\0';
1296          }
1297 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1297 >        return(specview(mv));
1298   }
1299  
1300  
1301 < rview(opts)                             /* run rview with first view */
1302 < char    *opts;
1301 > printview(vopts)                        /* print out selected view */
1302 > register char   *vopts;
1303   {
1304 +        extern char     *atos(), *getenv();
1305 +        char    buf[256];
1306 +        FILE    *fp;
1307 +        register char   *cp;
1308 +
1309 +        if (vopts == NULL)
1310 +                return(-1);
1311 +        fputs("VIEW=", stdout);
1312 +        do {
1313 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1314 +                        vopts = sskip(vopts);
1315 +                        if (!*atos(buf, sizeof(buf), vopts))
1316 +                                return(-1);
1317 +                        if ((fp = fopen(buf, "r")) == NULL)
1318 +                                return(-1);
1319 +                        for (buf[sizeof(buf)-2] = '\n';
1320 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1321 +                                                buf[0] != '\n';
1322 +                                        buf[sizeof(buf)-2] = '\n') {
1323 +                                if (buf[sizeof(buf)-2] != '\n') {
1324 +                                        ungetc(buf[sizeof(buf)-2], fp);
1325 +                                        buf[sizeof(buf)-2] = '\0';
1326 +                                }
1327 +                                if (matchword(buf, "VIEW=") ||
1328 +                                                matchword(buf, "rview")) {
1329 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1330 +                                                putchar(*cp);
1331 +                                }
1332 +                        }
1333 +                        fclose(fp);
1334 +                        vopts = sskip(vopts);
1335 +                } else {
1336 +                        while (isspace(*vopts))
1337 +                                vopts++;
1338 +                        putchar(' ');
1339 + #ifdef MSDOS
1340 +                        if (*vopts == '$') {            /* expand env. var. */
1341 +                                if (!*atos(buf, sizeof(buf), vopts+1))
1342 +                                        return(-1);
1343 +                                if ((cp = getenv(buf)) == NULL)
1344 +                                        return(-1);
1345 +                                fputs(cp, stdout);
1346 +                                vopts = sskip(vopts);
1347 +                        } else
1348 + #endif
1349 +                                while (*vopts && !isspace(*vopts))
1350 +                                        putchar(*vopts++);
1351 +                }
1352 +        } while (*vopts++);
1353 +        putchar('\n');
1354 +        return(0);
1355 + }
1356 +
1357 +
1358 + rview(opts, po)                         /* run rview with first view */
1359 + char    *opts, *po;
1360 + {
1361 +        char    *vw;
1362          char    combuf[512];
1363                                          /* build command */
1364 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1364 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1365 >                return;
1366 >        if (sayview)
1367 >                printview(vw);
1368 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1369          if (rvdevice != NULL)
1370                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1371 <        strcat(combuf, vval(OCTREE));
1371 >        if (vdef(EXPOSURE))
1372 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1373 >        strcat(combuf, oct1name);
1374          if (runcom(combuf)) {           /* run it */
1375                  fprintf(stderr, "%s: error running rview\n", progname);
1376                  exit(1);
# Line 982 | Line 1378 | char   *opts;
1378   }
1379  
1380  
1381 < rpict(opts)                             /* run rpict and pfilt for each view */
1382 < char    *opts;
1381 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1382 > char    *opts, *po;
1383   {
1384          char    combuf[1024];
1385          char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1386          char    pfopts[128];
1387          char    vs[32], *vw;
1388          int     vn, mult;
1389 +        time_t  rfdt, pfdt;
1390                                          /* get pfilt options */
1391          pfiltopts(pfopts);
1392                                          /* get resolution, reporting */
1393 <        mult = vscale(QUALITY)+1;
1393 >        switch (vscale(QUALITY)) {
1394 >        case LOW:
1395 >                mult = 1;
1396 >                break;
1397 >        case MEDIUM:
1398 >                mult = 2;
1399 >                break;
1400 >        case HIGH:
1401 >                mult = 3;
1402 >                break;
1403 >        }
1404          {
1405                  int     xres, yres;
1406                  double  aspect;
# Line 1020 | Line 1427 | char   *opts;
1427                  else
1428                          badvalue(REPORT);
1429          }
1023                                        /* check date on ambient file */
1024        if (vdef(AMBFILE)) {
1025                long    afdate = fdate(vval(AMBFILE));
1026                if (afdate >= 0 & octreedate > afdate)
1027                        rmfile(vval(AMBFILE));
1028        }
1430                                          /* do each view */
1431          vn = 0;
1432          while ((vw = getview(vn++, vs)) != NULL) {
1433 +                if (sayview)
1434 +                        printview(vw);
1435                  if (!vs[0])
1436                          sprintf(vs, "%d", vn);
1437                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1438                                                  /* check date on picture */
1439 <                if (fdate(picfile) > octreedate)
1439 >                pfdt = fdate(picfile);
1440 >                if (pfdt >= oct1date)
1441                          continue;
1442 <                                                /* build rpict command */
1442 >                                                /* get raw file name */
1443                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1444 <                if (fdate(rawfile) > octreedate)        /* recover */
1445 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
1446 <                                        rep, opts, rawfile, vval(OCTREE));
1444 >                rfdt = fdate(rawfile);
1445 >                if (touchonly) {                /* update times only */
1446 >                        if (rfdt) {
1447 >                                if (rfdt < oct1date)
1448 >                                        touch(rawfile);
1449 >                        } else if (pfdt && pfdt < oct1date)
1450 >                                touch(picfile);
1451 >                        continue;
1452 >                }
1453 >                                                /* build rpict command */
1454 >                if (rfdt >= oct1date)           /* recover */
1455 >                        sprintf(combuf, "rpict%s%s%s -ro %s %s",
1456 >                                        rep, po, opts, rawfile, oct1name);
1457                  else {
1458                          if (overture) {         /* run overture calculation */
1459                                  sprintf(combuf,
1460                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1461                                                  rep, vw, opts,
1462 <                                                vval(OCTREE), rawfile);
1462 >                                                oct1name, overfile);
1463                                  if (runcom(combuf)) {
1464                                          fprintf(stderr,
1465 <                        "%s: error in overture for view %s\n\t%s removed\n",
1466 <                                                progname, vs, rawfile);
1053 <                                        unlink(rawfile);
1465 >                                        "%s: error in overture for view %s\n",
1466 >                                                progname, vs);
1467                                          exit(1);
1468                                  }
1469 + #ifdef NIX
1470 +                                rmfile(overfile);
1471 + #endif
1472                          }
1473 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1474 <                                        rep, vw, res, opts,
1475 <                                        vval(OCTREE), rawfile);
1473 >                        sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1474 >                                        rep, vw, res, po, opts,
1475 >                                oct1name, rawfile);
1476                  }
1477                  if (runcom(combuf)) {           /* run rpict */
1478                          fprintf(stderr, "%s: error rendering view %s\n",
# Line 1083 | Line 1499 | char   *opts;
1499   }
1500  
1501  
1502 + touch(fn)                       /* update a file */
1503 + char    *fn;
1504 + {
1505 +        if (!silent)
1506 +                printf("\ttouch %s\n", fn);
1507 +        if (noaction)
1508 +                return(0);
1509 + #ifdef notused
1510 +        if (access(fn, F_OK) == -1)             /* create it */
1511 +                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1512 +                        return(-1);
1513 + #endif
1514 +        return(setfdate(fn, time((time_t *)NULL)));
1515 + }
1516 +
1517 +
1518   runcom(cs)                      /* run command */
1519   char    *cs;
1520   {
# Line 1108 | Line 1540 | char   *fn;
1540                  return(0);
1541          return(unlink(fn));
1542   }
1543 +
1544 +
1545 + #ifdef MSDOS
1546 + setenv(vname, value)            /* set an environment variable */
1547 + char    *vname, *value;
1548 + {
1549 +        register char   *evp;
1550 +
1551 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1552 +        if (evp == NULL)
1553 +                syserr(progname);
1554 +        sprintf(evp, "%s=%s", vname, value);
1555 +        if (putenv(evp) != 0) {
1556 +                fprintf(stderr, "%s: out of environment space\n", progname);
1557 +                exit(1);
1558 +        }
1559 +        if (!silent)
1560 +                printf("set %s\n", evp);
1561 + }
1562 + #endif
1563  
1564  
1565   badvalue(vc)                    /* report bad variable value and exit */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines