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.9 by greg, Wed May 26 11:37:42 1993 UTC vs.
Revision 2.33 by greg, Thu Nov 18 10:00:21 1993 UTC

# Line 21 | Line 21 | typedef struct {
21          int     (*fixval)();    /* assignment checking function */
22   } VARIABLE;
23  
24 < int     onevalue(), catvalues();
24 > int     onevalue(), catvalues(), boolvalue(),
25 >        qualvalue(), fltvalue(), intvalue();
26  
27                                  /* variables */
28   #define OBJECT          0               /* object files */
29   #define SCENE           1               /* scene files */
30   #define MATERIAL        2               /* material files */
31 < #define RENDER          3               /* rendering options */
32 < #define OCONV           4               /* oconv options */
33 < #define PFILT           5               /* pfilt options */
34 < #define VIEW            6               /* view(s) for picture(s) */
35 < #define ZONE            7               /* simulation zone */
36 < #define QUALITY         8               /* desired rendering quality */
37 < #define OCTREE          9               /* octree file name */
38 < #define PICTURE         10              /* picture file name */
39 < #define AMBFILE         11              /* ambient file name */
40 < #define OPTFILE         12              /* rendering options file */
41 < #define EXPOSURE        13              /* picture exposure setting */
42 < #define RESOLUTION      14              /* maximum picture resolution */
43 < #define UP              15              /* view up (X, Y or Z) */
44 < #define INDIRECT        16              /* indirection in lighting */
45 < #define DETAIL          17              /* level of scene detail */
46 < #define PENUMBRAS       18              /* shadow penumbras are desired */
47 < #define VARIABILITY     19              /* level of light variability */
48 < #define REPORT          20              /* report frequency and errfile */
31 > #define ILLUM           3               /* mkillum input files */
32 > #define MKILLUM         4               /* mkillum options */
33 > #define RENDER          5               /* rendering options */
34 > #define OCONV           6               /* oconv options */
35 > #define PFILT           7               /* pfilt options */
36 > #define VIEW            8               /* view(s) for picture(s) */
37 > #define ZONE            9               /* simulation zone */
38 > #define QUALITY         10              /* desired rendering quality */
39 > #define OCTREE          11              /* octree file name */
40 > #define PICTURE         12              /* picture file name */
41 > #define AMBFILE         13              /* ambient file name */
42 > #define OPTFILE         14              /* rendering options file */
43 > #define EXPOSURE        15              /* picture exposure setting */
44 > #define RESOLUTION      16              /* maximum picture resolution */
45 > #define UP              17              /* view up (X, Y or Z) */
46 > #define INDIRECT        18              /* indirection in lighting */
47 > #define DETAIL          19              /* level of scene detail */
48 > #define PENUMBRAS       20              /* shadow penumbras are desired */
49 > #define VARIABILITY     21              /* level of light variability */
50 > #define REPORT          22              /* report frequency and errfile */
51                                  /* total number of variables */
52 < #define NVARS           21
52 > #define NVARS           23
53  
54   VARIABLE        vv[NVARS] = {           /* variable-value pairs */
55          {"objects",     3,      0,      NULL,   catvalues},
56          {"scene",       3,      0,      NULL,   catvalues},
57          {"materials",   3,      0,      NULL,   catvalues},
58 +        {"illum",       3,      0,      NULL,   catvalues},
59 +        {"mkillum",     3,      0,      NULL,   catvalues},
60          {"render",      3,      0,      NULL,   catvalues},
61          {"oconv",       3,      0,      NULL,   catvalues},
62          {"pfilt",       2,      0,      NULL,   catvalues},
63          {"view",        2,      0,      NULL,   NULL},
64          {"ZONE",        2,      0,      NULL,   onevalue},
65 <        {"QUALITY",     3,      0,      NULL,   onevalue},
65 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
66          {"OCTREE",      3,      0,      NULL,   onevalue},
67          {"PICTURE",     3,      0,      NULL,   onevalue},
68          {"AMBFILE",     3,      0,      NULL,   onevalue},
69          {"OPTFILE",     3,      0,      NULL,   onevalue},
70 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
70 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
71          {"RESOLUTION",  3,      0,      NULL,   onevalue},
72          {"UP",          2,      0,      NULL,   onevalue},
73 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
74 <        {"DETAIL",      3,      0,      NULL,   onevalue},
75 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
76 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
73 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
74 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
75 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
76 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
77          {"REPORT",      3,      0,      NULL,   onevalue},
78   };
79  
80   VARIABLE        *matchvar();
81   char    *nvalue();
77 int     vscale();
82  
83   #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
84  
# Line 83 | Line 87 | int    vscale();
87   #define vval(vc)        (vv[vc].value)
88   #define vint(vc)        atoi(vval(vc))
89   #define vlet(vc)        UPPER(vval(vc)[0])
90 + #define vscale          vlet
91   #define vbool(vc)       (vlet(vc)=='T')
92  
93 < #define HIGH            2
94 < #define MEDIUM          1
95 < #define LOW             0
93 > #define HIGH            'H'
94 > #define MEDIUM          'M'
95 > #define LOW             'L'
96  
92 int     lowqopts(), medqopts(), hiqopts();
93 int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94
95 #define renderopts      (*setqopts[vscale(QUALITY)])
96
97                                  /* overture calculation file */
98   #ifdef NIX
99   char    overfile[] = "overture.raw";
# Line 101 | Line 101 | char   overfile[] = "overture.raw";
101   char    overfile[] = "/dev/null";
102   #endif
103  
104 < extern long     fdate(), time();
104 > extern unsigned long    fdate(), time();
105  
106 < long    scenedate;              /* date of latest scene or object file */
107 < long    octreedate;             /* date of octree */
106 > unsigned long   scenedate;      /* date of latest scene or object file */
107 > unsigned long   octreedate;     /* date of octree */
108 > unsigned long   matdate;        /* date of latest material file */
109 > unsigned long   illumdate;      /* date of last illum file */
110  
111 + char    *oct0name;              /* name of pre-mkillum octree */
112 + unsigned long   oct0date;       /* date of pre-mkillum octree */
113 + char    *oct1name;              /* name of post-mkillum octree */
114 + unsigned long   oct1date;       /* date of post-mkillum octree (>= matdate) */
115 +
116   int     explicate = 0;          /* explicate variables */
117   int     silent = 0;             /* do work silently */
118   int     noaction = 0;           /* don't do anything */
119 + int     sayview = 0;            /* print view out */
120   char    *rvdevice = NULL;       /* rview output device */
121   char    *viewselect = NULL;     /* specific view only */
122  
123   int     overture = 0;           /* overture calculation needed */
124  
125   char    *progname;              /* global argv[0] */
126 + char    *rifname;               /* global rad input file name */
127  
128   char    radname[MAXPATH];       /* root Radiance file name */
129  
# Line 142 | Line 151 | char   *argv[];
151                  case 'o':
152                          rvdevice = argv[++i];
153                          break;
154 +                case 'V':
155 +                        sayview++;
156 +                        break;
157                  case 'v':
158                          viewselect = argv[++i];
159                          break;
# Line 150 | Line 162 | char   *argv[];
162                  }
163          if (i >= argc)
164                  goto userr;
165 +        rifname = argv[i];
166                                  /* assign Radiance root file name */
167 <        rootname(radname, argv[i]);
167 >        rootname(radname, rifname);
168                                  /* load variable values */
169 <        load(argv[i]);
169 >        load(rifname);
170                                  /* get any additional assignments */
171          for (i++; i < argc; i++)
172                  setvariable(argv[i]);
# Line 166 | Line 179 | char   *argv[];
179                                  /* print all values if requested */
180          if (explicate)
181                  printvals();
182 <                                /* build octree */
182 >                                /* build octree (and run mkillum) */
183          oconv();
184                                  /* check date on ambient file */
185          checkambfile();
# Line 180 | Line 193 | char   *argv[];
193          exit(0);
194   userr:
195          fprintf(stderr,
196 <        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
196 >        "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
197                          progname);
198          exit(1);
199   }
# Line 201 | Line 214 | register char  *rn, *fn;
214   }
215  
216  
217 + #define NOCHAR  127             /* constant for character to delete */
218 +
219 +
220   load(rfname)                    /* load Radiance simulation file */
221   char    *rfname;
222   {
# Line 216 | Line 232 | char   *rfname;
232                  for (cp = buf; *cp; cp++) {
233                          switch (*cp) {
234                          case '\\':
235 <                        case '\n':
220 <                                *cp = ' ';
235 >                                *cp++ = NOCHAR;
236                                  continue;
237                          case '#':
238                                  *cp = '\0';
# Line 237 | Line 252 | setvariable(ass)               /* assign variable according to stri
252   register char   *ass;
253   {
254          char    varname[32];
255 +        int     n;
256          register char   *cp;
257          register VARIABLE       *vp;
258          register int    i;
243        int     n;
259  
260          while (isspace(*ass))           /* skip leading space */
261                  ass++;
# Line 254 | Line 269 | register char  *ass;
269                                          /* trim value */
270          while (isspace(*ass) || *ass == '=')
271                  ass++;
272 <        cp = ass + strlen(ass);
273 <        do
274 <                *cp-- = '\0';
260 <        while (cp >= ass && isspace(*cp));
261 <        n = cp - ass + 1;
272 >        for (n = strlen(ass); n > 0; n--)
273 >                if (!isspace(ass[n-1]))
274 >                        break;
275          if (!n) {
276                  fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
277                                  progname, varname);
# Line 283 | Line 296 | register char  *ass;
296                  vp->value = malloc(n+1);
297          if (vp->value == NULL)
298                  syserr(progname);
299 <        strcpy(vp->value+i, ass);
299 >        cp = vp->value+i;               /* copy value, squeezing spaces */
300 >        *cp = *ass;
301 >        for (i = 1; i <= n; i++) {
302 >                if (ass[i] == NOCHAR)
303 >                        continue;
304 >                if (isspace(*cp))
305 >                        while (isspace(ass[i]))
306 >                                i++;
307 >                *++cp = ass[i];
308 >        }
309 >        if (isspace(*cp))               /* remove trailing space */
310 >                *cp = '\0';
311          vp->nass++;
312   }
313  
# Line 309 | Line 333 | register int   n;
333   {
334          register char   *cp;
335  
336 <        if (vp == NULL || n < 0 || n >= vp->nass)
336 >        if (vp == NULL | n < 0 | n >= vp->nass)
337                  return(NULL);
338          cp = vp->value;
339          while (n--)
# Line 319 | Line 343 | register int   n;
343   }
344  
345  
322 int
323 vscale(vc)                      /* return scale for variable vc */
324 int     vc;
325 {
326        switch(vlet(vc)) {
327        case 'H':
328                return(HIGH);
329        case 'M':
330                return(MEDIUM);
331        case 'L':
332                return(LOW);
333        }
334        badvalue(vc);
335 }
336
337
346   checkvalues()                   /* check assignments */
347   {
348          register int    i;
# Line 373 | Line 381 | register VARIABLE      *vp;
381   }
382  
383  
384 < long
384 > int
385 > badmatch(tv, cv)                /* case insensitive truncated comparison */
386 > register char   *tv, *cv;
387 > {
388 >        if (!*tv) return(1);            /* null string cannot match */
389 >        do
390 >                if (UPPER(*tv) != *cv++)
391 >                        return(1);
392 >        while (*++tv);
393 >        return(0);              /* OK */
394 > }
395 >
396 >
397 > boolvalue(vp)                   /* check boolean for legal values */
398 > register VARIABLE       *vp;
399 > {
400 >        if (!vp->nass) return;
401 >        onevalue(vp);
402 >        switch (UPPER(vp->value[0])) {
403 >        case 'T':
404 >                if (badmatch(vp->value, "TRUE")) break;
405 >                return;
406 >        case 'F':
407 >                if (badmatch(vp->value, "FALSE")) break;
408 >                return;
409 >        }
410 >        fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
411 >                        progname, vp->name);
412 >        exit(1);
413 > }
414 >
415 >
416 > qualvalue(vp)                   /* check qualitative var. for legal values */
417 > register VARIABLE       *vp;
418 > {
419 >        if (!vp->nass) return;
420 >        onevalue(vp);
421 >        switch (UPPER(vp->value[0])) {
422 >        case 'L':
423 >                if (badmatch(vp->value, "LOW")) break;
424 >                return;
425 >        case 'M':
426 >                if (badmatch(vp->value, "MEDIUM")) break;
427 >                return;
428 >        case 'H':
429 >                if (badmatch(vp->value, "HIGH")) break;
430 >                return;
431 >        }
432 >        fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
433 >                        progname, vp->name);
434 >        exit(1);
435 > }
436 >
437 >
438 > intvalue(vp)                    /* check integer variable for legal values */
439 > register VARIABLE       *vp;
440 > {
441 >        if (!vp->nass) return;
442 >        onevalue(vp);
443 >        if (isint(vp->value)) return;
444 >        fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
445 >                        progname, vp->name);
446 >        exit(1);
447 > }
448 >
449 >
450 > fltvalue(vp)                    /* check float variable for legal values */
451 > register VARIABLE       *vp;
452 > {
453 >        if (!vp->nass) return;
454 >        onevalue(vp);
455 >        if (isflt(vp->value)) return;
456 >        fprintf(stderr, "%s: illegal value for real variable '%s'\n",
457 >                        progname, vp->name);
458 >        exit(1);
459 > }
460 >
461 >
462 > unsigned long
463   checklast(fnames)                       /* check files and find most recent */
464   register char   *fnames;
465   {
466          char    thisfile[MAXPATH];
467 <        long    thisdate, lastdate = -1;
467 >        unsigned long   thisdate, lastdate = 0;
468          register char   *cp;
469  
470 +        if (fnames == NULL)
471 +                return(0);
472          while (*fnames) {
473                  while (isspace(*fnames)) fnames++;
474                  cp = thisfile;
475                  while (*fnames && !isspace(*fnames))
476                          *cp++ = *fnames++;
477                  *cp = '\0';
478 <                if ((thisdate = fdate(thisfile)) < 0)
478 >                if (!(thisdate = fdate(thisfile)))
479                          syserr(thisfile);
480                  if (thisdate > lastdate)
481                          lastdate = thisdate;
# Line 396 | Line 484 | register char  *fnames;
484   }
485  
486  
487 + char *
488 + newfname(orig, pred)            /* create modified file name */
489 + char    *orig;
490 + int     pred;
491 + {
492 +        extern char     *rindex();
493 +        register char   *cp;
494 +        register int    n;
495 +        int     suffix;
496 +
497 +        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
498 +        while (*cp) {
499 +                if (*cp == '.') suffix = n;
500 +                else if (ISDIRSEP(*cp)) suffix = -1;
501 +                cp++; n++;
502 +        }
503 +        if (suffix == -1) suffix = n;
504 +        if ((cp = bmalloc(n+2)) == NULL)
505 +                syserr(progname);
506 +        strncpy(cp, orig, suffix);
507 +        cp[suffix] = pred;                      /* root name + pred + suffix */
508 +        strcpy(cp+suffix+1, orig+suffix);
509 +        return(cp);
510 + }
511 +
512 +
513   checkfiles()                    /* check for existence and modified times */
514   {
515 <        char    *cp;
402 <        long    objdate;
515 >        unsigned long   objdate;
516  
517          if (!vdef(OCTREE)) {
518 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
518 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
519                          syserr(progname);
520 <                sprintf(cp, "%s.oct", radname);
408 <                vval(OCTREE) = cp;
520 >                sprintf(vval(OCTREE), "%s.oct", radname);
521                  vdef(OCTREE)++;
522          }
523          octreedate = fdate(vval(OCTREE));
524 <        scenedate = -1;
525 <        if (vdef(SCENE)) {
526 <                scenedate = checklast(vval(SCENE));
527 <                if (vdef(OBJECT)) {
528 <                        objdate = checklast(vval(OBJECT));
529 <                        if (objdate > scenedate)
530 <                                scenedate = objdate;
531 <                }
532 <        }
533 <        if (octreedate < 0 & scenedate < 0) {
534 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
535 <                                vnam(OCTREE), vnam(SCENE));
524 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
525 >                oct0name = newfname(vval(OCTREE), '0');
526 >                oct1name = newfname(vval(OCTREE), '1');
527 >                oct0date = fdate(oct0name);
528 >                oct1date = fdate(oct1name);
529 >        } else
530 >                oct0name = oct1name = vval(OCTREE);
531 >        if ((scenedate = checklast(vval(SCENE))) &&
532 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
533 >                scenedate = objdate;
534 >        illumdate = checklast(vval(ILLUM));
535 >        if (!octreedate & !scenedate & !illumdate) {
536 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
537 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
538                  exit(1);
539          }
540 +        matdate = checklast(vval(MATERIAL));
541   }      
542  
543  
# Line 431 | Line 546 | double org[3], *sizp;
546   {
547          extern FILE     *popen();
548          static double   oorg[3], osiz = 0.;
549 <        char    buf[MAXPATH+16];
549 >        double  min[3], max[3];
550 >        char    buf[512];
551          FILE    *fp;
552 +        register int    i;
553  
554 <        if (osiz <= FTINY) {
555 <                oconv();                /* does nothing if done already */
556 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
557 <                if ((fp = popen(buf, "r")) == NULL)
558 <                        syserr("getinfo");
559 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
560 <                                &oorg[2], &osiz) != 4) {
561 <                        fprintf(stderr,
554 >        if (osiz <= FTINY)
555 >                if (noaction && fdate(oct1name) <
556 >                                (scenedate>illumdate?scenedate:illumdate)) {
557 >                                                        /* run getbbox */
558 >                        sprintf(buf, "getbbox -w -h %s",
559 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
560 >                        if ((fp = popen(buf, "r")) == NULL)
561 >                                syserr("getbbox");
562 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
563 >                                        &min[0], &max[0], &min[1], &max[1],
564 >                                        &min[2], &max[2]) != 6) {
565 >                                fprintf(stderr,
566 >                        "%s: error reading bounding box from getbbox\n",
567 >                                                progname);
568 >                                exit(1);
569 >                        }
570 >                        for (i = 0; i < 3; i++)
571 >                                if (max[i] - min[i] > osiz)
572 >                                        osiz = max[i] - min[i];
573 >                        for (i = 0; i < 3; i++)
574 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
575 >                        pclose(fp);
576 >                } else {                                /* from octree */
577 >                        oconv();        /* does nothing if done already */
578 >                        sprintf(buf, "getinfo -d < %s", oct1name);
579 >                        if ((fp = popen(buf, "r")) == NULL)
580 >                                syserr("getinfo");
581 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
582 >                                        &oorg[2], &osiz) != 4) {
583 >                                fprintf(stderr,
584                          "%s: error reading bounding cube from getinfo\n",
585 <                                        progname);
586 <                        exit(1);
585 >                                                progname);
586 >                                exit(1);
587 >                        }
588 >                        pclose(fp);
589                  }
449                pclose(fp);
450        }
590          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
591   }
592  
# Line 510 | Line 649 | printvals()                    /* print variable values */
649   }
650  
651  
652 < oconv()                         /* run oconv if necessary */
652 > oconv()                         /* run oconv and mkillum if necessary */
653   {
654 <        char    combuf[512], ocopts[64];
654 >        static char     illumtmp[] = "ilXXXXXX";
655 >        char    combuf[512], ocopts[64], mkopts[64];
656  
657 <        if (octreedate >= scenedate)    /* check dates */
658 <                return;
659 <                                        /* build command */
660 <        oconvopts(ocopts);
661 <        if (vdef(MATERIAL))
522 <                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
657 >        oconvopts(ocopts);              /* get options */
658 >        if (octreedate < scenedate) {   /* check date on original octree */
659 >                                                /* build command */
660 >                if (vdef(MATERIAL))
661 >                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
662                                  vval(MATERIAL), vval(SCENE), vval(OCTREE));
663 +                else
664 +                        sprintf(combuf, "oconv%s %s > %s", ocopts,
665 +                                        vval(SCENE), vval(OCTREE));
666 +                
667 +                if (runcom(combuf)) {           /* run it */
668 +                        fprintf(stderr,
669 +                                "%s: error generating octree\n\t%s removed\n",
670 +                                        progname, vval(OCTREE));
671 +                        unlink(vval(OCTREE));
672 +                        exit(1);
673 +                }
674 +                octreedate = time(0);
675 +        }
676 +        if (oct1name == vval(OCTREE))           /* no mkillum? */
677 +                oct1date = octreedate > matdate ? octreedate : matdate;
678 +        if (oct1date >= octreedate & oct1date >= matdate
679 +                        & oct1date >= illumdate)        /* all done */
680 +                return;
681 +                                                /* make octree0 */
682 +        if (oct0date < scenedate | oct0date < illumdate) {
683 +                                                /* build command */
684 +                if (octreedate)
685 +                        sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
686 +                                vval(OCTREE), vval(ILLUM), oct0name);
687 +                else if (vdef(MATERIAL))
688 +                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
689 +                                vval(MATERIAL), vval(ILLUM), oct0name);
690 +                else
691 +                        sprintf(combuf, "oconv%s %s > %s", ocopts,
692 +                                vval(ILLUM), oct0name);
693 +                if (runcom(combuf)) {           /* run it */
694 +                        fprintf(stderr,
695 +                                "%s: error generating octree\n\t%s removed\n",
696 +                                        progname, oct0name);
697 +                        unlink(oct0name);
698 +                        exit(1);
699 +                }
700 +                oct0date = time(0);
701 +        }
702 +        mkillumopts(mkopts);                    /* build mkillum command */
703 +        mktemp(illumtmp);
704 +        sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
705 +                        oct0name, vval(ILLUM), illumtmp);
706 +        if (runcom(combuf)) {                   /* run it */
707 +                fprintf(stderr, "%s: error running mkillum\n", progname);
708 +                unlink(illumtmp);
709 +                exit(1);
710 +        }
711 +                                                /* make octree1 (frozen) */
712 +        if (octreedate)
713 +                sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
714 +                        vval(OCTREE), illumtmp, oct1name);
715 +        else if (vdef(MATERIAL))
716 +                sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
717 +                        vval(MATERIAL), illumtmp, oct1name);
718          else
719 <                sprintf(combuf, "oconv%s %s > %s", ocopts,
720 <                                vval(SCENE), vval(OCTREE));
527 <        
719 >                sprintf(combuf, "oconv%s -f %s > %s", ocopts,
720 >                        illumtmp, oct1name);
721          if (runcom(combuf)) {           /* run it */
722 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
723 <                                progname, vval(OCTREE));
724 <                unlink(vval(OCTREE));
722 >                fprintf(stderr,
723 >                        "%s: error generating octree\n\t%s removed\n",
724 >                                progname, oct1name);
725 >                unlink(oct1name);
726                  exit(1);
727          }
728 <        octreedate = time(0);
728 >        oct1date = time(0);
729 >        rmfile(illumtmp);
730   }
731  
732  
# Line 557 | Line 752 | register char  *oo;
752   }
753  
754  
755 + mkillumopts(mo)                         /* get mkillum options */
756 + register char   *mo;
757 + {
758 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
759 +
760 +        *mo = '\0';
761 +        if (vdef(MKILLUM))
762 +                addarg(mo, vval(MKILLUM));
763 + }
764 +
765 +
766   checkambfile()                  /* check date on ambient file */
767   {
768 <        long    afdate;
768 >        unsigned long   afdate;
769  
770 <        if (vdef(AMBFILE)) {
771 <                afdate = fdate(vval(AMBFILE));
772 <                if (afdate >= 0 & octreedate > afdate)
773 <                        rmfile(vval(AMBFILE));
774 <        }
770 >        if (!vdef(AMBFILE))
771 >                return;
772 >        if (!(afdate = fdate(vval(AMBFILE))))
773 >                return;
774 >        if (oct1date > afdate)
775 >                rmfile(vval(AMBFILE));
776   }
777  
778  
# Line 575 | Line 782 | ambval()                               /* compute ambient value */
782          if (vdef(EXPOSURE)) {
783                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
784                          return(.5/pow(2.,atof(vval(EXPOSURE))));
785 <                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
579 <                        return(.5/atof(vval(EXPOSURE)));
580 <                badvalue(EXPOSURE);
785 >                return(.5/atof(vval(EXPOSURE)));
786          }
787          if (vlet(ZONE) == 'E')
788                  return(10.);
# Line 587 | Line 792 | ambval()                               /* compute ambient value */
792   }
793  
794  
795 + renderopts(op)                          /* set rendering options */
796 + char    *op;
797 + {
798 +        switch(vscale(QUALITY)) {
799 +        case LOW:
800 +                lowqopts(op);
801 +                break;
802 +        case MEDIUM:
803 +                medqopts(op);
804 +                break;
805 +        case HIGH:
806 +                hiqopts(op);
807 +                break;
808 +        }
809 + }
810 +
811 +
812   lowqopts(op)                            /* low quality rendering options */
813   register char   *op;
814   {
# Line 601 | Line 823 | register char  *op;
823          d *= 3./(siz[0]+siz[1]+siz[2]);
824          switch (vscale(DETAIL)) {
825          case LOW:
826 <                op = addarg(op, "-ps 16 -dp 16");
826 >                op = addarg(op, "-ps 16 -dp 64");
827                  sprintf(op, " -ar %d", (int)(4*d));
828                  op += strlen(op);
829                  break;
830          case MEDIUM:
831 <                op = addarg(op, "-ps 8 -dp 32");
831 >                op = addarg(op, "-ps 8 -dp 128");
832                  sprintf(op, " -ar %d", (int)(8*d));
833                  op += strlen(op);
834                  break;
835          case HIGH:
836 <                op = addarg(op, "-ps 4 -dp 64");
836 >                op = addarg(op, "-ps 4 -dp 256");
837                  sprintf(op, " -ar %d", (int)(16*d));
838                  op += strlen(op);
839                  break;
# Line 621 | Line 843 | register char  *op;
843                  op = addarg(op, "-ds .4");
844          else
845                  op = addarg(op, "-ds 0");
846 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
846 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
847          if (vdef(AMBFILE)) {
848                  sprintf(op, " -af %s", vval(AMBFILE));
849                  op += strlen(op);
# Line 629 | Line 851 | register char  *op;
851                  overture = 0;
852          switch (vscale(VARIABILITY)) {
853          case LOW:
854 <                op = addarg(op, "-aa .4 -ad 32");
854 >                op = addarg(op, "-aa .4 -ad 64");
855                  break;
856          case MEDIUM:
857 <                op = addarg(op, "-aa .3 -ad 64");
857 >                op = addarg(op, "-aa .3 -ad 128");
858                  break;
859          case HIGH:
860 <                op = addarg(op, "-aa .25 -ad 128");
860 >                op = addarg(op, "-aa .25 -ad 256");
861                  break;
862          }
863          op = addarg(op, "-as 0");
# Line 663 | Line 885 | register char  *op;
885          switch (vscale(DETAIL)) {
886          case LOW:
887                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
888 <                op = addarg(op, "-dp 64");
888 >                op = addarg(op, "-dp 256");
889                  sprintf(op, " -ar %d", (int)(8*d));
890                  op += strlen(op);
891                  break;
892          case MEDIUM:
893                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
894 <                op = addarg(op, "-dp 128");
894 >                op = addarg(op, "-dp 512");
895                  sprintf(op, " -ar %d", (int)(16*d));
896                  op += strlen(op);
897                  break;
898          case HIGH:
899                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
900 <                op = addarg(op, "-dp 256");
900 >                op = addarg(op, "-dp 1024");
901                  sprintf(op, " -ar %d", (int)(32*d));
902                  op += strlen(op);
903                  break;
904          }
905          op = addarg(op, "-pt .08");
906          if (vbool(PENUMBRAS))
907 <                op = addarg(op, "-ds .2 -dj .35");
907 >                op = addarg(op, "-ds .2 -dj .5");
908          else
909                  op = addarg(op, "-ds .3");
910 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
910 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
911          if (overture = vint(INDIRECT)) {
912                  sprintf(op, " -ab %d", overture);
913                  op += strlen(op);
# Line 697 | Line 919 | register char  *op;
919                  overture = 0;
920          switch (vscale(VARIABILITY)) {
921          case LOW:
922 <                op = addarg(op, "-aa .25 -ad 128 -as 0");
922 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
923                  break;
924          case MEDIUM:
925 <                op = addarg(op, "-aa .2 -ad 300 -as 64");
925 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
926                  break;
927          case HIGH:
928 <                op = addarg(op, "-aa .15 -ad 500 -as 128");
928 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
929                  break;
930          }
931          d = ambval();
# Line 730 | Line 952 | register char  *op;
952          switch (vscale(DETAIL)) {
953          case LOW:
954                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
955 <                op = addarg(op, "-dp 256");
955 >                op = addarg(op, "-dp 1024");
956                  sprintf(op, " -ar %d", (int)(16*d));
957                  op += strlen(op);
958                  break;
959          case MEDIUM:
960                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
961 <                op = addarg(op, "-dp 512");
961 >                op = addarg(op, "-dp 2048");
962                  sprintf(op, " -ar %d", (int)(32*d));
963                  op += strlen(op);
964                  break;
965          case HIGH:
966                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
967 <                op = addarg(op, "-dp 1024");
967 >                op = addarg(op, "-dp 4096");
968                  sprintf(op, " -ar %d", (int)(64*d));
969                  op += strlen(op);
970                  break;
# Line 752 | Line 974 | register char  *op;
974                  op = addarg(op, "-ds .1 -dj .7");
975          else
976                  op = addarg(op, "-ds .2");
977 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
977 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
978          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
979          op += strlen(op);
980          if (vdef(AMBFILE)) {
# Line 762 | Line 984 | register char  *op;
984                  overture = 0;
985          switch (vscale(VARIABILITY)) {
986          case LOW:
987 <                op = addarg(op, "-aa .15 -ad 200 -as 0");
987 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
988                  break;
989          case MEDIUM:
990 <                op = addarg(op, "-aa .125 -ad 512 -as 128");
990 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
991                  break;
992          case HIGH:
993 <                op = addarg(op, "-aa .08 -ad 850 -as 256");
993 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
994                  break;
995          }
996          d = ambval();
# Line 784 | Line 1006 | xferopts(ro)                           /* transfer options if indicated */
1006   char    *ro;
1007   {
1008          int     fd, n;
1009 +        register char   *cp;
1010          
1011          n = strlen(ro);
1012          if (n < 2)
1013                  return;
1014          if (vdef(OPTFILE)) {
1015 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
1015 >                for (cp = ro; cp[1]; cp++)
1016 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1017 >                                *cp = '\n';
1018 >                        else
1019 >                                *cp = cp[1];
1020 >                *cp = '\n';
1021 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1022 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1023                          syserr(vval(OPTFILE));
1024 <                if (write(fd, ro+1, n-1) != n-1)
795 <                        syserr(vval(OPTFILE));
796 <                write(fd, "\n", 1);
797 <                close(fd);
798 <                sprintf(ro, " \"^%s\"", vval(OPTFILE));
1024 >                sprintf(ro, " @%s", vval(OPTFILE));
1025          }
1026   #ifdef MSDOS
1027          else if (n > 50) {
# Line 814 | Line 1040 | register char  *po;
1040                  po = addarg(po, "-1 -e");
1041                  po = addarg(po, vval(EXPOSURE));
1042          }
1043 <        if (vscale(QUALITY) == HIGH)
1044 <                po = addarg(po, "-r .65");
1043 >        switch (vscale(QUALITY)) {
1044 >        case MEDIUM:
1045 >                po = addarg(po, "-r 1");
1046 >                break;
1047 >        case HIGH:
1048 >                po = addarg(po, "-m .25");
1049 >                break;
1050 >        }
1051          if (vdef(PFILT))
1052                  po = addarg(po, vval(PFILT));
1053   }
# Line 939 | Line 1171 | register char  *vs;
1171                          cp += strlen(cp);
1172                  }
1173          }
1174 <        strcpy(cp, vs);                 /* append any additional options */
1174 >        if (cp == viewopts)             /* append any additional options */
1175 >                vs++;           /* skip prefixed space if unneeded */
1176 >        strcpy(cp, vs);
1177   #ifdef MSDOS
1178          if (strlen(viewopts) > 40) {
1179                  setenv("VIEW", viewopts);
# Line 955 | Line 1189 | getview(n, vn)                         /* get view n, or NULL if none */
1189   int     n;
1190   char    *vn;            /* returned view name */
1191   {
1192 <        register char   *mv = NULL;
1192 >        register char   *mv;
1193  
1194          if (viewselect != NULL) {               /* command-line selected */
1195                  if (n)                          /* only do one */
# Line 970 | Line 1204 | char   *vn;            /* returned view name */
1204                                  ;
1205                          *vn = '\0';
1206                  }
1207 +                                                /* view number? */
1208 +                if (isint(viewselect))
1209 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1210                                                  /* check list */
1211                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1212                          if (matchword(viewselect, mv))
# Line 978 | Line 1215 | char   *vn;            /* returned view name */
1215          }
1216          mv = nvalue(vv+VIEW, n);                /* use view n */
1217          if (vn != NULL & mv != NULL) {
1218 <                if (*mv != '-')
1219 <                        while (*mv && !isspace(*mv))
1220 <                                *vn++ = *mv++;
1218 >                register char   *mv2 = mv;
1219 >                if (*mv2 != '-')
1220 >                        while (*mv2 && !isspace(*mv2))
1221 >                                *vn++ = *mv2++;
1222                  *vn = '\0';
1223          }
1224          return(specview(mv));
1225   }
1226  
1227  
1228 + printview(vopts)                        /* print out selected view */
1229 + register char   *vopts;
1230 + {
1231 +        extern char     *atos(), *getenv();
1232 +        char    buf[256];
1233 +        FILE    *fp;
1234 +        register char   *cp;
1235 +
1236 +        if (vopts == NULL)
1237 +                return(-1);
1238 +        fputs("VIEW=", stdout);
1239 +        do {
1240 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1241 +                        vopts = sskip(vopts);
1242 +                        if (!*atos(buf, sizeof(buf), vopts))
1243 +                                return(-1);
1244 +                        if ((fp = fopen(buf, "r")) == NULL)
1245 +                                return(-1);
1246 +                        for (buf[sizeof(buf)-2] = '\n';
1247 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1248 +                                                buf[0] != '\n';
1249 +                                        buf[sizeof(buf)-2] = '\n') {
1250 +                                if (buf[sizeof(buf)-2] != '\n') {
1251 +                                        ungetc(buf[sizeof(buf)-2], fp);
1252 +                                        buf[sizeof(buf)-2] = '\0';
1253 +                                }
1254 +                                if (matchword(buf, "VIEW=") ||
1255 +                                                matchword(buf, "rview")) {
1256 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1257 +                                                putchar(*cp);
1258 +                                }
1259 +                        }
1260 +                        fclose(fp);
1261 +                        vopts = sskip(vopts);
1262 +                } else {
1263 +                        while (isspace(*vopts))
1264 +                                vopts++;
1265 +                        putchar(' ');
1266 + #ifdef MSDOS
1267 +                        if (*vopts == '$') {            /* expand env. var. */
1268 +                                if (!*atos(buf, sizeof(buf), vopts+1))
1269 +                                        return(-1);
1270 +                                if ((cp = getenv(buf)) == NULL)
1271 +                                        return(-1);
1272 +                                fputs(cp, stdout);
1273 +                                vopts = sskip(vopts);
1274 +                        } else
1275 + #endif
1276 +                                while (*vopts && !isspace(*vopts))
1277 +                                        putchar(*vopts++);
1278 +                }
1279 +        } while (*vopts++);
1280 +        putchar('\n');
1281 +        return(0);
1282 + }
1283 +
1284 +
1285   rview(opts)                             /* run rview with first view */
1286   char    *opts;
1287   {
1288 +        char    *vw;
1289          char    combuf[512];
1290                                          /* build command */
1291 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1291 >        if ((vw = getview(0, NULL)) == NULL)
1292 >                return;
1293 >        if (sayview)
1294 >                printview(vw);
1295 >        sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1296          if (rvdevice != NULL)
1297                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1298 <        strcat(combuf, vval(OCTREE));
1298 >        if (vdef(EXPOSURE))
1299 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1300 >        strcat(combuf, oct1name);
1301          if (runcom(combuf)) {           /* run it */
1302                  fprintf(stderr, "%s: error running rview\n", progname);
1303                  exit(1);
# Line 1014 | Line 1316 | char   *opts;
1316                                          /* get pfilt options */
1317          pfiltopts(pfopts);
1318                                          /* get resolution, reporting */
1319 <        mult = vscale(QUALITY)+1;
1319 >        switch (vscale(QUALITY)) {
1320 >        case LOW:
1321 >                mult = 1;
1322 >                break;
1323 >        case MEDIUM:
1324 >                mult = 2;
1325 >                break;
1326 >        case HIGH:
1327 >                mult = 3;
1328 >                break;
1329 >        }
1330          {
1331                  int     xres, yres;
1332                  double  aspect;
# Line 1044 | Line 1356 | char   *opts;
1356                                          /* do each view */
1357          vn = 0;
1358          while ((vw = getview(vn++, vs)) != NULL) {
1359 +                if (sayview)
1360 +                        printview(vw);
1361                  if (!vs[0])
1362                          sprintf(vs, "%d", vn);
1363                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1364                                                  /* check date on picture */
1365 <                if (fdate(picfile) > octreedate)
1365 >                if (fdate(picfile) >= oct1date)
1366                          continue;
1367                                                  /* build rpict command */
1368                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1369 <                if (fdate(rawfile) > octreedate)        /* recover */
1369 >                if (fdate(rawfile) >= oct1date)         /* recover */
1370                          sprintf(combuf, "rpict%s%s -ro %s %s",
1371 <                                        rep, opts, rawfile, vval(OCTREE));
1371 >                                        rep, opts, rawfile, oct1name);
1372                  else {
1373                          if (overture) {         /* run overture calculation */
1374                                  sprintf(combuf,
1375                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1376                                                  rep, vw, opts,
1377 <                                                vval(OCTREE), overfile);
1377 >                                                oct1name, overfile);
1378                                  if (runcom(combuf)) {
1379                                          fprintf(stderr,
1380                                          "%s: error in overture for view %s\n",
# Line 1073 | Line 1387 | char   *opts;
1387                          }
1388                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1389                                          rep, vw, res, opts,
1390 <                                        vval(OCTREE), rawfile);
1390 >                                oct1name, rawfile);
1391                  }
1392                  if (runcom(combuf)) {           /* run rpict */
1393                          fprintf(stderr, "%s: error rendering view %s\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines