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.37 by greg, Sat Jan 1 09:16:50 1994 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines