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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines