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

Comparing ray/src/util/rad.c (file contents):
Revision 2.2 by greg, Thu Mar 11 11:39:48 1993 UTC vs.
Revision 2.31 by greg, Thu Nov 11 13:17:01 1993 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines