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.36 by greg, Thu Dec 30 08:20:45 1993 UTC

# 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 +
86   #define vnam(vc)        (vv[vc].name)
87   #define vdef(vc)        (vv[vc].nass)
88   #define vval(vc)        (vv[vc].value)
89   #define vint(vc)        atoi(vval(vc))
90 < #define vlet(vc)        (vval(vc)[0]&~0x20)
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     explicate = 0;          /* explicate variables */
118   int     silent = 0;             /* do work silently */
119   int     noaction = 0;           /* don't do anything */
120 + int     sayview = 0;            /* print view out */
121   char    *rvdevice = NULL;       /* rview output device */
122   char    *viewselect = NULL;     /* specific view only */
123  
124   int     overture = 0;           /* overture calculation needed */
125  
126   char    *progname;              /* global argv[0] */
127 + char    *rifname;               /* global rad input file name */
128  
129   char    radname[MAXPATH];       /* root Radiance file name */
130  
# Line 133 | Line 152 | char   *argv[];
152                  case 'o':
153                          rvdevice = argv[++i];
154                          break;
155 +                case 'V':
156 +                        sayview++;
157 +                        break;
158                  case 'v':
159                          viewselect = argv[++i];
160                          break;
# Line 141 | Line 163 | char   *argv[];
163                  }
164          if (i >= argc)
165                  goto userr;
166 +        rifname = argv[i];
167                                  /* assign Radiance root file name */
168 <        rootname(radname, argv[i]);
168 >        rootname(radname, rifname);
169                                  /* load variable values */
170 <        load(argv[i]);
170 >        load(rifname);
171                                  /* get any additional assignments */
172          for (i++; i < argc; i++)
173                  setvariable(argv[i]);
# Line 157 | Line 180 | char   *argv[];
180                                  /* print all values if requested */
181          if (explicate)
182                  printvals();
183 <                                /* run simulation */
183 >                                /* build octree (and run mkillum) */
184          oconv();
185 +                                /* check date on ambient file */
186 +        checkambfile();
187 +                                /* run simulation */
188          renderopts(ropts);
189          xferopts(ropts);
190          if (rvdevice != NULL)
# Line 168 | Line 194 | char   *argv[];
194          exit(0);
195   userr:
196          fprintf(stderr,
197 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
197 >        "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
198                          progname);
199          exit(1);
200   }
# Line 189 | Line 215 | register char  *rn, *fn;
215   }
216  
217  
218 + #define NOCHAR  127             /* constant for character to delete */
219 +
220 +
221   load(rfname)                    /* load Radiance simulation file */
222   char    *rfname;
223   {
224          FILE    *fp;
225 <        char    buf[256];
225 >        char    buf[512];
226          register char   *cp;
227  
228          if (rfname == NULL)
229                  fp = stdin;
230 <        else if ((fp = fopen(rfname, "r")) == NULL) {
231 <                perror(rfname);
203 <                exit(1);
204 <        }
230 >        else if ((fp = fopen(rfname, "r")) == NULL)
231 >                syserr(rfname);
232          while (fgetline(buf, sizeof(buf), fp) != NULL) {
233                  for (cp = buf; *cp; cp++) {
234                          switch (*cp) {
235                          case '\\':
236 <                        case '\n':
210 <                                *cp = ' ';
236 >                                *cp++ = NOCHAR;
237                                  continue;
238                          case '#':
239                                  *cp = '\0';
240                                  break;
241 +                        default:
242 +                                continue;
243                          }
244                          break;
245                  }
# Line 225 | Line 253 | setvariable(ass)               /* assign variable according to stri
253   register char   *ass;
254   {
255          char    varname[32];
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 > time_t
464   checklast(fnames)                       /* check files and find most recent */
465   register char   *fnames;
466   {
467          char    thisfile[MAXPATH];
468 <        long    thisdate, lastdate = -1;
468 >        time_t  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 >        time_t  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 499 | Line 641 | setdefaults()                  /* set default values for unassigned v
641  
642   printvals()                     /* print variable values */
643   {
644 <        register int    i, j;
644 >        int     i, j, clipline;
645 >        register char   *cp;
646 >        register int    k;
647  
648 <        for (i = 0; i < NVARS; i++)
649 <                for (j = 0; j < vv[i].nass; j++)
650 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
648 >        for (i = 0; i < NVARS; i++)             /* print each variable */
649 >            for (j = 0; j < vdef(i); j++) {     /* print each assignment */
650 >                fputs(vnam(i), stdout);
651 >                fputs("= ", stdout);
652 >                k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
653 >                                - strlen(vnam(i)) ;
654 >                cp = nvalue(vv+i, j);
655 >                while (*cp) {
656 >                    putchar(*cp++);
657 >                    if (--k <= 0) {             /* line too long */
658 >                        while (*cp && !isspace(*cp))
659 >                            putchar(*cp++);     /* finish this word */
660 >                        if (*cp) {              /* start new line */
661 >                            putchar('\n');
662 >                            fputs(vnam(i), stdout);
663 >                            putchar('=');
664 >                            k = clipline;
665 >                        }
666 >                    }
667 >                }
668 >                putchar('\n');
669 >            }
670          fflush(stdout);
671   }
672  
673  
674 < oconv()                         /* run oconv if necessary */
674 > oconv()                         /* run oconv and mkillum if necessary */
675   {
676 <        char    combuf[512], ocopts[64];
676 >        static char     illumtmp[] = "ilXXXXXX";
677 >        char    combuf[512], ocopts[64], mkopts[64];
678  
679 <        if (octreedate >= scenedate)    /* check dates */
680 <                return;
681 <                                        /* build command */
682 <        oconvopts(ocopts);
683 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
684 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
685 <                        vval(SCENE), vval(OCTREE));
686 <        if (!silent) {                  /* echo it */
687 <                printf("\t%s\n", combuf);
688 <                fflush(stdout);
679 >        oconvopts(ocopts);              /* get options */
680 >        if (octreedate < scenedate) {   /* check date on original octree */
681 >                                                /* build command */
682 >                if (vdef(MATERIAL))
683 >                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
684 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
685 >                else
686 >                        sprintf(combuf, "oconv%s %s > %s", ocopts,
687 >                                        vval(SCENE), vval(OCTREE));
688 >                
689 >                if (runcom(combuf)) {           /* run it */
690 >                        fprintf(stderr,
691 >                                "%s: error generating octree\n\t%s removed\n",
692 >                                        progname, vval(OCTREE));
693 >                        unlink(vval(OCTREE));
694 >                        exit(1);
695 >                }
696 >                octreedate = time((time_t *)NULL);
697          }
698 <        if (noaction)
698 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
699 >                oct1date = octreedate > matdate ? octreedate : matdate;
700 >        if (oct1date >= octreedate & oct1date >= matdate
701 >                        & oct1date >= illumdate)        /* all done */
702                  return;
703 <        if (system(combuf)) {           /* run it */
704 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
705 <                                progname, vval(OCTREE));
706 <                unlink(vval(OCTREE));
703 >                                                /* make octree0 */
704 >        if (oct0date < scenedate | oct0date < illumdate) {
705 >                                                /* build command */
706 >                if (octreedate)
707 >                        sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
708 >                                vval(OCTREE), vval(ILLUM), oct0name);
709 >                else if (vdef(MATERIAL))
710 >                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
711 >                                vval(MATERIAL), vval(ILLUM), oct0name);
712 >                else
713 >                        sprintf(combuf, "oconv%s %s > %s", ocopts,
714 >                                vval(ILLUM), oct0name);
715 >                if (runcom(combuf)) {           /* run it */
716 >                        fprintf(stderr,
717 >                                "%s: error generating octree\n\t%s removed\n",
718 >                                        progname, oct0name);
719 >                        unlink(oct0name);
720 >                        exit(1);
721 >                }
722 >                oct0date = time((time_t *)NULL);
723 >        }
724 >        mkillumopts(mkopts);                    /* build mkillum command */
725 >        mktemp(illumtmp);
726 >        sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
727 >                        oct0name, vval(ILLUM), illumtmp);
728 >        if (runcom(combuf)) {                   /* run it */
729 >                fprintf(stderr, "%s: error running mkillum\n", progname);
730 >                unlink(illumtmp);
731                  exit(1);
732          }
733 <        octreedate = time(0);
733 >                                                /* make octree1 (frozen) */
734 >        if (octreedate)
735 >                sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
736 >                        vval(OCTREE), illumtmp, oct1name);
737 >        else if (vdef(MATERIAL))
738 >                sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
739 >                        vval(MATERIAL), illumtmp, oct1name);
740 >        else
741 >                sprintf(combuf, "oconv%s -f %s > %s", ocopts,
742 >                        illumtmp, oct1name);
743 >        if (runcom(combuf)) {           /* run it */
744 >                fprintf(stderr,
745 >                        "%s: error generating octree\n\t%s removed\n",
746 >                                progname, oct1name);
747 >                unlink(oct1name);
748 >                exit(1);
749 >        }
750 >        oct1date = time((time_t *)NULL);
751 >        rmfile(illumtmp);
752   }
753  
754  
# Line 557 | Line 774 | register char  *oo;
774   }
775  
776  
777 + mkillumopts(mo)                         /* get mkillum options */
778 + register char   *mo;
779 + {
780 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
781 +
782 +        *mo = '\0';
783 +        if (vdef(MKILLUM))
784 +                addarg(mo, vval(MKILLUM));
785 + }
786 +
787 +
788 + checkambfile()                  /* check date on ambient file */
789 + {
790 +        time_t  afdate;
791 +
792 +        if (!vdef(AMBFILE))
793 +                return;
794 +        if (!(afdate = fdate(vval(AMBFILE))))
795 +                return;
796 +        if (oct1date > afdate)
797 +                rmfile(vval(AMBFILE));
798 + }
799 +
800 +
801   double
802   ambval()                                /* compute ambient value */
803   {
804 <        if (vdef(EXPOSURE))
804 >        if (vdef(EXPOSURE)) {
805                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
806                          return(.5/pow(2.,atof(vval(EXPOSURE))));
807 <                else
808 <                        return(.5/atof(vval(EXPOSURE)));
807 >                return(.5/atof(vval(EXPOSURE)));
808 >        }
809          if (vlet(ZONE) == 'E')
810                  return(10.);
811 <        else
811 >        if (vlet(ZONE) == 'I')
812                  return(.01);
813 +        badvalue(ZONE);
814   }
815  
816  
817 + renderopts(op)                          /* set rendering options */
818 + char    *op;
819 + {
820 +        switch(vscale(QUALITY)) {
821 +        case LOW:
822 +                lowqopts(op);
823 +                break;
824 +        case MEDIUM:
825 +                medqopts(op);
826 +                break;
827 +        case HIGH:
828 +                hiqopts(op);
829 +                break;
830 +        }
831 + }
832 +
833 +
834   lowqopts(op)                            /* low quality rendering options */
835   register char   *op;
836   {
# Line 579 | Line 838 | register char  *op;
838  
839          *op = '\0';
840          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
841 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
842 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
841 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
842 >                badvalue(ZONE);
843          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
844          getoctcube(org, &d);
845          d *= 3./(siz[0]+siz[1]+siz[2]);
846          switch (vscale(DETAIL)) {
847          case LOW:
848 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
848 >                op = addarg(op, "-ps 16 -dp 64");
849                  sprintf(op, " -ar %d", (int)(4*d));
850                  op += strlen(op);
851                  break;
852          case MEDIUM:
853 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
853 >                op = addarg(op, "-ps 8 -dp 128");
854                  sprintf(op, " -ar %d", (int)(8*d));
855                  op += strlen(op);
856                  break;
857          case HIGH:
858 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
858 >                op = addarg(op, "-ps 4 -dp 256");
859                  sprintf(op, " -ar %d", (int)(16*d));
860                  op += strlen(op);
861                  break;
# Line 610 | Line 863 | register char  *op;
863          op = addarg(op, "-pt .16");
864          if (vbool(PENUMBRAS))
865                  op = addarg(op, "-ds .4");
866 <        op = addarg(op, "-dt .2");
867 <        op = addarg(op, "-dc .25");
868 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
866 >        else
867 >                op = addarg(op, "-ds 0");
868 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
869          if (vdef(AMBFILE)) {
870                  sprintf(op, " -af %s", vval(AMBFILE));
871                  op += strlen(op);
# Line 623 | Line 873 | register char  *op;
873                  overture = 0;
874          switch (vscale(VARIABILITY)) {
875          case LOW:
876 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
876 >                op = addarg(op, "-aa .4 -ad 64");
877                  break;
878          case MEDIUM:
879 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
879 >                op = addarg(op, "-aa .3 -ad 128");
880                  break;
881          case HIGH:
882 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
882 >                op = addarg(op, "-aa .25 -ad 256");
883                  break;
884          }
885          op = addarg(op, "-as 0");
886          d = ambval();
887          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
888          op += strlen(op);
889 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
889 >        op = addarg(op, "-lr 3 -lw .02");
890          if (vdef(RENDER))
891                  op = addarg(op, vval(RENDER));
892   }
# Line 653 | Line 899 | register char  *op;
899  
900          *op = '\0';
901          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
902 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
903 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
902 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
903 >                badvalue(ZONE);
904          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
905          getoctcube(org, &d);
906          d *= 3./(siz[0]+siz[1]+siz[2]);
907          switch (vscale(DETAIL)) {
908          case LOW:
909                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
910 <                op = addarg(op, "-dp 64");
910 >                op = addarg(op, "-dp 256");
911                  sprintf(op, " -ar %d", (int)(8*d));
912                  op += strlen(op);
913                  break;
914          case MEDIUM:
915                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
916 <                op = addarg(op, "-dp 128");
916 >                op = addarg(op, "-dp 512");
917                  sprintf(op, " -ar %d", (int)(16*d));
918                  op += strlen(op);
919                  break;
920          case HIGH:
921                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
922 <                op = addarg(op, "-dp 256");
922 >                op = addarg(op, "-dp 1024");
923                  sprintf(op, " -ar %d", (int)(32*d));
924                  op += strlen(op);
925                  break;
926          }
927          op = addarg(op, "-pt .08");
928 <        if (vbool(PENUMBRAS)) {
929 <                op = addarg(op, "-ds .2");
930 <                op = addarg(op, "-dj .35");
688 <        } else
928 >        if (vbool(PENUMBRAS))
929 >                op = addarg(op, "-ds .2 -dj .5");
930 >        else
931                  op = addarg(op, "-ds .3");
932 <        op = addarg(op, "-dt .1");
933 <        op = addarg(op, "-dc .5");
934 <        op = addarg(op, "-dr 1");
935 <        op = addarg(op, "-sj .7");
936 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
932 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
933 >        if (overture = vint(INDIRECT)) {
934 >                sprintf(op, " -ab %d", overture);
935 >                op += strlen(op);
936 >        }
937          if (vdef(AMBFILE)) {
938                  sprintf(op, " -af %s", vval(AMBFILE));
939                  op += strlen(op);
# Line 701 | Line 941 | register char  *op;
941                  overture = 0;
942          switch (vscale(VARIABILITY)) {
943          case LOW:
944 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
944 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
945                  break;
946          case MEDIUM:
947 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
947 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
948                  break;
949          case HIGH:
950 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
950 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
951                  break;
952          }
953          d = ambval();
954          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
955          op += strlen(op);
956 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
956 >        op = addarg(op, "-lr 6 -lw .002");
957          if (vdef(RENDER))
958                  op = addarg(op, vval(RENDER));
959   }
# Line 733 | Line 966 | register char  *op;
966  
967          *op = '\0';
968          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
969 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
970 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
969 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
970 >                badvalue(ZONE);
971          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
972          getoctcube(org, &d);
973          d *= 3./(siz[0]+siz[1]+siz[2]);
974          switch (vscale(DETAIL)) {
975          case LOW:
976                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
977 <                op = addarg(op, "-dp 256");
977 >                op = addarg(op, "-dp 1024");
978                  sprintf(op, " -ar %d", (int)(16*d));
979                  op += strlen(op);
980                  break;
981          case MEDIUM:
982                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
983 <                op = addarg(op, "-dp 512");
983 >                op = addarg(op, "-dp 2048");
984                  sprintf(op, " -ar %d", (int)(32*d));
985                  op += strlen(op);
986                  break;
987          case HIGH:
988                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
989 <                op = addarg(op, "-dp 1024");
989 >                op = addarg(op, "-dp 4096");
990                  sprintf(op, " -ar %d", (int)(64*d));
991                  op += strlen(op);
992                  break;
993          }
994          op = addarg(op, "-pt .04");
995 <        if (vbool(PENUMBRAS)) {
996 <                op = addarg(op, "-ds .1");
997 <                op = addarg(op, "-dj .7");
768 <        } else
995 >        if (vbool(PENUMBRAS))
996 >                op = addarg(op, "-ds .1 -dj .7");
997 >        else
998                  op = addarg(op, "-ds .2");
999 <        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");
999 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1000          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1001          op += strlen(op);
1002          if (vdef(AMBFILE)) {
# Line 781 | Line 1006 | register char  *op;
1006                  overture = 0;
1007          switch (vscale(VARIABILITY)) {
1008          case LOW:
1009 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
1009 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
1010                  break;
1011          case MEDIUM:
1012 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
1012 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
1013                  break;
1014          case HIGH:
1015 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
1015 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
1016                  break;
1017          }
1018          d = ambval();
1019          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1020          op += strlen(op);
1021 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
1021 >        op = addarg(op, "-lr 12 -lw .0005");
1022          if (vdef(RENDER))
1023                  op = addarg(op, vval(RENDER));
1024   }
# Line 810 | Line 1028 | xferopts(ro)                           /* transfer options if indicated */
1028   char    *ro;
1029   {
1030          int     fd, n;
1031 +        register char   *cp;
1032          
1033          n = strlen(ro);
1034          if (n < 2)
1035                  return;
1036          if (vdef(OPTFILE)) {
1037 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
1038 <                        perror(vval(OPTFILE));
1039 <                        exit(1);
1040 <                }
1041 <                if (write(fd, ro+1, n-1) != n-1) {
1042 <                        perror(vval(OPTFILE));
1043 <                        exit(1);
1044 <                }
1045 <                write(fd, "\n", 1);
1046 <                close(fd);
828 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
1037 >                for (cp = ro; cp[1]; cp++)
1038 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1039 >                                *cp = '\n';
1040 >                        else
1041 >                                *cp = cp[1];
1042 >                *cp = '\n';
1043 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1044 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1045 >                        syserr(vval(OPTFILE));
1046 >                sprintf(ro, " @%s", vval(OPTFILE));
1047          }
1048   #ifdef MSDOS
1049          else if (n > 50) {
1050 <                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 <                }
1050 >                setenv("ROPT", ro+1);
1051                  strcpy(ro, " $ROPT");
1052          }
1053   #endif
# Line 857 | Line 1062 | register char  *po;
1062                  po = addarg(po, "-1 -e");
1063                  po = addarg(po, vval(EXPOSURE));
1064          }
1065 <        if (vscale(QUALITY) == HIGH)
1066 <                po = addarg(po, "-r .65");
1065 >        switch (vscale(QUALITY)) {
1066 >        case MEDIUM:
1067 >                po = addarg(po, "-r 1");
1068 >                break;
1069 >        case HIGH:
1070 >                po = addarg(po, "-m .25");
1071 >                break;
1072 >        }
1073          if (vdef(PFILT))
1074                  po = addarg(po, vval(PFILT));
1075   }
# Line 880 | Line 1091 | char *
1091   specview(vs)                            /* get proper view spec from vs */
1092   register char   *vs;
1093   {
1094 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1095 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1096          static char     viewopts[128];
1097          register char   *cp;
1098 <        int     xpos, ypos, zpos, viewtype;
1099 <        int     exterior;
1098 >        int     xpos, ypos, zpos, viewtype, upax;
1099 >        register int    i;
1100          double  cent[3], dim[3], mult, d;
1101  
1102          if (vs == NULL || *vs == '-')
1103                  return(vs);
1104 +        upax = 0;                       /* get the up vector */
1105 +        if (vdef(UP)) {
1106 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
1107 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
1108 +                else
1109 +                        upax = 1-'X'+vlet(UP);
1110 +                if (upax < 1 | upax > 3)
1111 +                        badvalue(UP);
1112 +                if (vval(UP)[0] == '-')
1113 +                        upax = -upax;
1114 +        }
1115                                          /* check standard view names */
1116          xpos = ypos = zpos = 0;
893        viewtype = 0;
1117          if (*vs == 'X') {
1118                  xpos = 1; vs++;
1119          } else if (*vs == 'x') {
# Line 906 | Line 1129 | register char  *vs;
1129          } else if (*vs == 'z') {
1130                  zpos = -1; vs++;
1131          }
1132 +        viewtype = 'v';
1133          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1134                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
1135          cp = viewopts;
1136 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
1136 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1137                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
1138                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
1139                                  &cent[0], &dim[0], &cent[1], &dim[1],
1140 <                                &cent[2], &dim[2]) != 6) {
1141 <                        fprintf(stderr, "%s: bad zone specification\n",
1142 <                                        progname);
1143 <                        exit(1);
1140 >                                &cent[2], &dim[2]) != 6)
1141 >                        badvalue(ZONE);
1142 >                for (i = 0; i < 3; i++) {
1143 >                        dim[i] -= cent[i];
1144 >                        cent[i] += .5*dim[i];
1145                  }
1146 <                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 ;
1146 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
1147                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1148                                  cent[0]+xpos*mult*dim[0],
1149                                  cent[1]+ypos*mult*dim[1],
1150                                  cent[2]+zpos*mult*dim[2],
1151                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
1152                  cp += strlen(cp);
1153 <                switch (vlet(UP)) {
1154 <                case 'Z':
1155 <                        if (xpos|ypos) {
1156 <                                cp = addarg(cp, "-vu 0 0 1");
1157 <                                break;
1158 <                        }
1159 <                /* 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");
1153 >                                        /* redirect up axis if necessary */
1154 >                switch (upax) {
1155 >                case 3:                 /* plus or minus Z axis */
1156 >                case -3:
1157 >                case 0:
1158 >                        if (!(xpos|ypos))
1159 >                                upax = 2;
1160                          break;
1161 <                default:
1162 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
1163 <                                        progname, vnam(UP));
1164 <                        exit(1);
1161 >                case 2:                 /* plus or minus Y axis */
1162 >                case -2:
1163 >                        if (!(xpos|zpos))
1164 >                                upax = 1;
1165 >                        break;
1166 >                case 1:                 /* plus or minus X axis */
1167 >                case -1:
1168 >                        if (!(ypos|zpos))
1169 >                                upax = 3;
1170 >                        break;
1171                  }
1172 +                cp = addarg(cp, vup[upax+3]);
1173                  switch (viewtype) {
1174                  case 'v':
1175                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 1184 | register char  *vs;
1184                          cp = addarg(cp, "-vh 180 -vv 180");
1185                          break;
1186                  }
1187 <        } else
1188 <                while (*vs && !isspace(*vs))    /* else skip id */
1189 <                        vs++;
1190 <                                        /* append any additional options */
1191 <        while (isspace(*vs)) vs++;
1187 >        } else {
1188 >                while (!isspace(*vs))           /* else skip id */
1189 >                        if (!*vs++)
1190 >                                return(NULL);
1191 >                if (upax) {                     /* specify up vector */
1192 >                        strcpy(cp, vup[upax+3]);
1193 >                        cp += strlen(cp);
1194 >                }
1195 >        }
1196 >        if (cp == viewopts)             /* append any additional options */
1197 >                vs++;           /* skip prefixed space if unneeded */
1198          strcpy(cp, vs);
1199 + #ifdef MSDOS
1200 +        if (strlen(viewopts) > 40) {
1201 +                setenv("VIEW", viewopts);
1202 +                return("$VIEW");
1203 +        }
1204 + #endif
1205          return(viewopts);
1206   }
1207  
# Line 982 | Line 1209 | register char  *vs;
1209   char *
1210   getview(n, vn)                          /* get view n, or NULL if none */
1211   int     n;
1212 < char    *vn;
1212 > char    *vn;            /* returned view name */
1213   {
1214          register char   *mv;
1215  
1216 <        if (viewselect != NULL) {
1216 >        if (viewselect != NULL) {               /* command-line selected */
1217                  if (n)                          /* only do one */
1218                          return(NULL);
1219                  if (viewselect[0] == '-') {     /* already specified */
# Line 999 | Line 1226 | char   *vn;
1226                                  ;
1227                          *vn = '\0';
1228                  }
1229 +                                                /* view number? */
1230 +                if (isint(viewselect))
1231 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1232                                                  /* check list */
1233                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1234                          if (matchword(viewselect, mv))
1235                                  return(specview(mv));
1236                  return(specview(viewselect));   /* standard view? */
1237          }
1238 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1239 <                if (*mv != '-')
1240 <                        while (*mv && !isspace(*mv))
1241 <                                *vn++ = *mv++;
1238 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1239 >        if (vn != NULL & mv != NULL) {
1240 >                register char   *mv2 = mv;
1241 >                if (*mv2 != '-')
1242 >                        while (*mv2 && !isspace(*mv2))
1243 >                                *vn++ = *mv2++;
1244                  *vn = '\0';
1245          }
1246 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1246 >        return(specview(mv));
1247   }
1248  
1249  
1250 + printview(vopts)                        /* print out selected view */
1251 + register char   *vopts;
1252 + {
1253 +        extern char     *atos(), *getenv();
1254 +        char    buf[256];
1255 +        FILE    *fp;
1256 +        register char   *cp;
1257 +
1258 +        if (vopts == NULL)
1259 +                return(-1);
1260 +        fputs("VIEW=", stdout);
1261 +        do {
1262 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1263 +                        vopts = sskip(vopts);
1264 +                        if (!*atos(buf, sizeof(buf), vopts))
1265 +                                return(-1);
1266 +                        if ((fp = fopen(buf, "r")) == NULL)
1267 +                                return(-1);
1268 +                        for (buf[sizeof(buf)-2] = '\n';
1269 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1270 +                                                buf[0] != '\n';
1271 +                                        buf[sizeof(buf)-2] = '\n') {
1272 +                                if (buf[sizeof(buf)-2] != '\n') {
1273 +                                        ungetc(buf[sizeof(buf)-2], fp);
1274 +                                        buf[sizeof(buf)-2] = '\0';
1275 +                                }
1276 +                                if (matchword(buf, "VIEW=") ||
1277 +                                                matchword(buf, "rview")) {
1278 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1279 +                                                putchar(*cp);
1280 +                                }
1281 +                        }
1282 +                        fclose(fp);
1283 +                        vopts = sskip(vopts);
1284 +                } else {
1285 +                        while (isspace(*vopts))
1286 +                                vopts++;
1287 +                        putchar(' ');
1288 + #ifdef MSDOS
1289 +                        if (*vopts == '$') {            /* expand env. var. */
1290 +                                if (!*atos(buf, sizeof(buf), vopts+1))
1291 +                                        return(-1);
1292 +                                if ((cp = getenv(buf)) == NULL)
1293 +                                        return(-1);
1294 +                                fputs(cp, stdout);
1295 +                                vopts = sskip(vopts);
1296 +                        } else
1297 + #endif
1298 +                                while (*vopts && !isspace(*vopts))
1299 +                                        putchar(*vopts++);
1300 +                }
1301 +        } while (*vopts++);
1302 +        putchar('\n');
1303 +        return(0);
1304 + }
1305 +
1306 +
1307   rview(opts)                             /* run rview with first view */
1308   char    *opts;
1309   {
1310 +        char    *vw;
1311          char    combuf[512];
1312                                          /* build command */
1313 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1313 >        if ((vw = getview(0, NULL)) == NULL)
1314 >                return;
1315 >        if (sayview)
1316 >                printview(vw);
1317 >        sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1318          if (rvdevice != NULL)
1319                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1320 <        strcat(combuf, vval(OCTREE));
1321 <        if (!silent) {                  /* echo it */
1322 <                printf("\t%s\n", combuf);
1323 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        if (system(combuf)) {           /* run it */
1320 >        if (vdef(EXPOSURE))
1321 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1322 >        strcat(combuf, oct1name);
1323 >        if (runcom(combuf)) {           /* run it */
1324                  fprintf(stderr, "%s: error running rview\n", progname);
1325                  exit(1);
1326          }
# Line 1041 | Line 1331 | rpict(opts)                            /* run rpict and pfilt for each view */
1331   char    *opts;
1332   {
1333          char    combuf[1024];
1334 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1335 <        char    pfopts[64];
1334 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1335 >        char    pfopts[128];
1336          char    vs[32], *vw;
1337          int     vn, mult;
1338                                          /* get pfilt options */
1339          pfiltopts(pfopts);
1340                                          /* get resolution, reporting */
1341 <        mult = vscale(QUALITY)+1;
1341 >        switch (vscale(QUALITY)) {
1342 >        case LOW:
1343 >                mult = 1;
1344 >                break;
1345 >        case MEDIUM:
1346 >                mult = 2;
1347 >                break;
1348 >        case HIGH:
1349 >                mult = 3;
1350 >                break;
1351 >        }
1352          {
1353                  int     xres, yres;
1354                  double  aspect;
# Line 1060 | Line 1360 | char   *opts;
1360                  else if (n) {
1361                          if (n == 1) yres = xres;
1362                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1363 <                } else {
1364 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1363 >                } else
1364 >                        badvalue(RESOLUTION);
1365          }
1366          rep[0] = '\0';
1367          if (vdef(REPORT)) {
# Line 1075 | Line 1372 | char   *opts;
1372                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1373                  else if (n == 1)
1374                          sprintf(rep, " -t %d", (int)(minutes*60));
1375 <                else {
1376 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1375 >                else
1376 >                        badvalue(REPORT);
1377          }
1378                                          /* do each view */
1379          vn = 0;
1380          while ((vw = getview(vn++, vs)) != NULL) {
1381 +                if (sayview)
1382 +                        printview(vw);
1383                  if (!vs[0])
1384                          sprintf(vs, "%d", vn);
1385                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1386                                                  /* check date on picture */
1387 <                if (fdate(picfile) > octreedate)
1387 >                if (fdate(picfile) >= oct1date)
1388                          continue;
1389                                                  /* build rpict command */
1390                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1391 <                if (fdate(rawfile) > octreedate)        /* recover */
1391 >                if (fdate(rawfile) >= oct1date)         /* recover */
1392                          sprintf(combuf, "rpict%s%s -ro %s %s",
1393 <                                        rep, opts, rawfile, vval(OCTREE));
1393 >                                        rep, opts, rawfile, oct1name);
1394                  else {
1395                          if (overture) {         /* run overture calculation */
1396                                  sprintf(combuf,
1397                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1398                                                  rep, vw, opts,
1399 <                                                vval(OCTREE), rawfile);
1400 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1399 >                                                oct1name, overfile);
1400 >                                if (runcom(combuf)) {
1401                                          fprintf(stderr,
1402 <                        "%s: error in overture for view %s\n\t%s removed\n",
1403 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1402 >                                        "%s: error in overture for view %s\n",
1403 >                                                progname, vs);
1404                                          exit(1);
1405                                  }
1406 + #ifdef NIX
1407 +                                rmfile(overfile);
1408 + #endif
1409                          }
1410                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1411                                          rep, vw, res, opts,
1412 <                                        vval(OCTREE), rawfile);
1412 >                                oct1name, rawfile);
1413                  }
1414 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1414 >                if (runcom(combuf)) {           /* run rpict */
1415                          fprintf(stderr, "%s: error rendering view %s\n",
1416                                          progname, vs);
1417                          exit(1);
# Line 1133 | Line 1423 | char   *opts;
1423                  else
1424                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1425                                          rawfile, picfile);
1426 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1426 >                if (runcom(combuf)) {           /* run pfilt */
1427                          fprintf(stderr,
1428                          "%s: error filtering view %s\n\t%s removed\n",
1429                                          progname, vs, picfile);
# Line 1145 | Line 1431 | char   *opts;
1431                          exit(1);
1432                  }
1433                                                  /* remove raw file */
1434 <                if (!silent)
1434 >                rmfile(rawfile);
1435 >        }
1436 > }
1437 >
1438 >
1439 > runcom(cs)                      /* run command */
1440 > char    *cs;
1441 > {
1442 >        if (!silent)            /* echo it */
1443 >                printf("\t%s\n", cs);
1444 >        if (noaction)
1445 >                return(0);
1446 >        fflush(stdout);         /* flush output and pass to shell */
1447 >        return(system(cs));
1448 > }
1449 >
1450 >
1451 > rmfile(fn)                      /* remove a file */
1452 > char    *fn;
1453 > {
1454 >        if (!silent)
1455   #ifdef MSDOS
1456 <                        printf("\tdel %s\n", rawfile);
1456 >                printf("\tdel %s\n", fn);
1457   #else
1458 <                        printf("\trm %s\n", rawfile);
1458 >                printf("\trm -f %s\n", fn);
1459   #endif
1460 <                if (!noaction)
1461 <                        unlink(rawfile);
1460 >        if (noaction)
1461 >                return(0);
1462 >        return(unlink(fn));
1463 > }
1464 >
1465 >
1466 > #ifdef MSDOS
1467 > setenv(vname, value)            /* set an environment variable */
1468 > char    *vname, *value;
1469 > {
1470 >        register char   *evp;
1471 >
1472 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1473 >        if (evp == NULL)
1474 >                syserr(progname);
1475 >        sprintf(evp, "%s=%s", vname, value);
1476 >        if (putenv(evp) != 0) {
1477 >                fprintf(stderr, "%s: out of environment space\n", progname);
1478 >                exit(1);
1479          }
1480 +        if (!silent)
1481 +                printf("set %s\n", evp);
1482 + }
1483 + #endif
1484 +
1485 +
1486 + badvalue(vc)                    /* report bad variable value and exit */
1487 + int     vc;
1488 + {
1489 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1490 +                        progname, vnam(vc));
1491 +        exit(1);
1492 + }
1493 +
1494 +
1495 + syserr(s)                       /* report a system error and exit */
1496 + char    *s;
1497 + {
1498 +        perror(s);
1499 +        exit(1);
1500   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines