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.21 by greg, Tue Aug 24 22:14:21 1993 UTC

# Line 76 | Line 76 | VARIABLE       *matchvar();
76   char    *nvalue();
77   int     vscale();
78  
79 + #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
80 +
81   #define vnam(vc)        (vv[vc].name)
82   #define vdef(vc)        (vv[vc].nass)
83   #define vval(vc)        (vv[vc].value)
84   #define vint(vc)        atoi(vval(vc))
85 < #define vlet(vc)        (vval(vc)[0]&~0x20)
85 > #define vlet(vc)        UPPER(vval(vc)[0])
86   #define vbool(vc)       (vlet(vc)=='T')
87  
88   #define HIGH            2
# Line 92 | Line 94 | int    (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94  
95   #define renderopts      (*setqopts[vscale(QUALITY)])
96  
97 < extern long     fdate();
97 >                                /* overture calculation file */
98 > #ifdef NIX
99 > char    overfile[] = "overture.raw";
100 > #else
101 > char    overfile[] = "/dev/null";
102 > #endif
103  
104 + extern long     fdate(), time();
105 +
106   long    scenedate;              /* date of latest scene or object file */
107   long    octreedate;             /* date of octree */
108 + long    matdate;                /* date of latest material file */
109  
110   int     explicate = 0;          /* explicate variables */
111   int     silent = 0;             /* do work silently */
112   int     noaction = 0;           /* don't do anything */
113 + int     sayview = 0;            /* print view out */
114   char    *rvdevice = NULL;       /* rview output device */
115   char    *viewselect = NULL;     /* specific view only */
116  
# Line 133 | Line 144 | char   *argv[];
144                  case 'o':
145                          rvdevice = argv[++i];
146                          break;
147 +                case 'V':
148 +                        sayview++;
149 +                        break;
150                  case 'v':
151                          viewselect = argv[++i];
152                          break;
# Line 157 | Line 171 | char   *argv[];
171                                  /* print all values if requested */
172          if (explicate)
173                  printvals();
174 <                                /* run simulation */
174 >                                /* build octree */
175          oconv();
176 +                                /* check date on ambient file */
177 +        checkambfile();
178 +                                /* run simulation */
179          renderopts(ropts);
180          xferopts(ropts);
181          if (rvdevice != NULL)
# Line 168 | Line 185 | char   *argv[];
185          exit(0);
186   userr:
187          fprintf(stderr,
188 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
188 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
189                          progname);
190          exit(1);
191   }
# Line 193 | Line 210 | load(rfname)                   /* load Radiance simulation file */
210   char    *rfname;
211   {
212          FILE    *fp;
213 <        char    buf[256];
213 >        char    buf[512];
214          register char   *cp;
215  
216          if (rfname == NULL)
217                  fp = stdin;
218 <        else if ((fp = fopen(rfname, "r")) == NULL) {
219 <                perror(rfname);
203 <                exit(1);
204 <        }
218 >        else if ((fp = fopen(rfname, "r")) == NULL)
219 >                syserr(rfname);
220          while (fgetline(buf, sizeof(buf), fp) != NULL) {
221                  for (cp = buf; *cp; cp++) {
222                          switch (*cp) {
# Line 212 | Line 227 | char   *rfname;
227                          case '#':
228                                  *cp = '\0';
229                                  break;
230 +                        default:
231 +                                continue;
232                          }
233                          break;
234                  }
# Line 260 | Line 277 | register char  *ass;
277                  exit(1);
278          }
279                                          /* assign new value */
280 <        cp = vp->value; i = vp->nass;
281 <        while (i--)
282 <                while (*cp++)
283 <                        ;
284 <        i = cp - vp->value;
285 <        vp->value = realloc(vp->value, i+n+1);
286 <        if (vp->value == NULL) {
287 <                perror(progname);
288 <                exit(1);
289 <        }
280 >        if (i = vp->nass) {
281 >                cp = vp->value;
282 >                while (i--)
283 >                        while (*cp++)
284 >                                ;
285 >                i = cp - vp->value;
286 >                vp->value = realloc(vp->value, i+n+1);
287 >        } else
288 >                vp->value = malloc(n+1);
289 >        if (vp->value == NULL)
290 >                syserr(progname);
291          strcpy(vp->value+i, ass);
292          vp->nass++;
293   }
# Line 296 | Line 314 | register int   n;
314   {
315          register char   *cp;
316  
317 <        if (vp == NULL || n < 0 || n >= vp->nass)
317 >        if (vp == NULL | n < 0 | n >= vp->nass)
318                  return(NULL);
319          cp = vp->value;
320          while (n--)
# Line 318 | Line 336 | int    vc;
336          case 'L':
337                  return(LOW);
338          }
339 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
339 >        badvalue(vc);
340   }
341  
342  
# Line 341 | Line 357 | register VARIABLE      *vp;
357                  return;
358          fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
359                          progname, vp->name);
360 <        while (vp->nass-- > 1)
360 >        do
361                  vp->value += strlen(vp->value)+1;
362 +        while (--vp->nass > 1);
363   }
364  
365  
# Line 372 | Line 389 | register char  *fnames;
389          while (*fnames) {
390                  while (isspace(*fnames)) fnames++;
391                  cp = thisfile;
392 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
392 >                while (*fnames && !isspace(*fnames))
393 >                        *cp++ = *fnames++;
394                  *cp = '\0';
395 <                if ((thisdate = fdate(thisfile)) < 0) {
396 <                        perror(thisfile);
379 <                        exit(1);
380 <                }
395 >                if ((thisdate = fdate(thisfile)) < 0)
396 >                        syserr(thisfile);
397                  if (thisdate > lastdate)
398                          lastdate = thisdate;
399          }
# Line 387 | Line 403 | register char  *fnames;
403  
404   checkfiles()                    /* check for existence and modified times */
405   {
406 +        char    *cp;
407          long    objdate;
408  
409 <        octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
409 >        if (!vdef(OCTREE)) {
410 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
411 >                        syserr(progname);
412 >                sprintf(cp, "%s.oct", radname);
413 >                vval(OCTREE) = cp;
414 >                vdef(OCTREE)++;
415 >        }
416 >        octreedate = fdate(vval(OCTREE));
417          scenedate = -1;
418          if (vdef(SCENE)) {
419                  scenedate = checklast(vval(SCENE));
# Line 400 | Line 424 | checkfiles()                   /* check for existence and modified tim
424                  }
425          }
426          if (octreedate < 0 & scenedate < 0) {
427 <                fprintf(stderr, "%s: need scene or octree\n", progname);
427 >                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
428 >                                vnam(OCTREE), vnam(SCENE));
429                  exit(1);
430          }
431 +        matdate = -1;
432 +        if (vdef(MATERIAL))
433 +                matdate = checklast(vval(MATERIAL));
434   }      
435  
436  
437 < setdefaults()                   /* set default values for unassigned var's */
437 > getoctcube(org, sizp)           /* get octree bounding cube */
438 > double  org[3], *sizp;
439   {
440 +        extern FILE     *popen();
441 +        static double   oorg[3], osiz = 0.;
442 +        char    buf[MAXPATH+16];
443          FILE    *fp;
412        double  xmin, ymin, zmin, size;
413        char    buf[512];
414        char    *cp;
444  
445 <        if (!vdef(OCTREE)) {
446 <                sprintf(buf, "%s.oct", radname);
447 <                vval(OCTREE) = savqstr(buf);
448 <                vdef(OCTREE)++;
445 >        if (osiz <= FTINY) {
446 >                oconv();                /* does nothing if done already */
447 >                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
448 >                if ((fp = popen(buf, "r")) == NULL)
449 >                        syserr("getinfo");
450 >                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
451 >                                &oorg[2], &osiz) != 4) {
452 >                        fprintf(stderr,
453 >                        "%s: error reading bounding cube from getinfo\n",
454 >                                        progname);
455 >                        exit(1);
456 >                }
457 >                pclose(fp);
458          }
459 +        org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
460 + }
461 +
462 +
463 + setdefaults()                   /* set default values for unassigned var's */
464 + {
465 +        double  org[3], size;
466 +        char    buf[128];
467 +
468          if (!vdef(ZONE)) {
469 <                if (scenedate > octreedate) {
470 <                        sprintf(buf, "getbbox -w -h %s", vval(SCENE));
471 <                        if (!silent) {
425 <                                printf("\t%s\n", buf);
426 <                                fflush(stdout);
427 <                        }
428 <                        if ((fp = popen(buf, "r")) == NULL) {
429 <                                perror("getbbox");
430 <                                exit(1);
431 <                        }
432 <                        buf[0] = 'E'; buf[1] = ' ';
433 <                        fgetline(buf+2, sizeof(buf)-2, fp);
434 <                        pclose(fp);
435 <                } else {
436 <                        sprintf(buf, "getinfo -d < %s", vval(OCTREE));
437 <                        if ((fp = popen(buf, "r")) == NULL) {
438 <                                perror("getinfo");
439 <                                exit(1);
440 <                        }
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);
445 <                        pclose(fp);
446 <                }
469 >                getoctcube(org, &size);
470 >                sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
471 >                                org[1], org[1]+size, org[2], org[2]+size);
472                  vval(ZONE) = savqstr(buf);
473                  vdef(ZONE)++;
474          }
450        if (!vdef(UP)) {
451                vval(UP) = "Z";
452                vdef(UP)++;
453        }
475          if (!vdef(INDIRECT)) {
476                  vval(INDIRECT) = "0";
477                  vdef(INDIRECT)++;
# Line 467 | Line 488 | setdefaults()                  /* set default values for unassigned v
488                  vval(PICTURE) = radname;
489                  vdef(PICTURE)++;
490          }
470        if (!vdef(AMBFILE)) {
471                sprintf(buf, "%s.amb", radname);
472                vval(AMBFILE) = savqstr(buf);
473                vdef(AMBFILE)++;
474        }
491          if (!vdef(VIEW)) {
492                  vval(VIEW) = "X";
493                  vdef(VIEW)++;
# Line 496 | Line 512 | printvals()                    /* print variable values */
512          register int    i, j;
513  
514          for (i = 0; i < NVARS; i++)
515 <                for (j = 0; j < vv[i].nass; j++)
516 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
515 >                for (j = 0; j < vdef(i); j++)
516 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
517          fflush(stdout);
518   }
519  
# Line 506 | Line 522 | oconv()                                /* run oconv if necessary */
522   {
523          char    combuf[512], ocopts[64];
524  
525 <        if (octreedate > scenedate)     /* check dates */
525 >        if (octreedate >= scenedate)    /* check dates */
526                  return;
527                                          /* build command */
528          oconvopts(ocopts);
529 <        sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
530 <        if (!silent) {                  /* echo it */
531 <                printf("\t%s\n", combuf);
532 <                fflush(stdout);
533 <        }
534 <        if (noaction)
535 <                return;
536 <        if (system(combuf)) {           /* run it */
529 >        if (vdef(MATERIAL))
530 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
531 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
532 >        else
533 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
534 >                                vval(SCENE), vval(OCTREE));
535 >        
536 >        if (runcom(combuf)) {           /* run it */
537                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
538                                  progname, vval(OCTREE));
539                  unlink(vval(OCTREE));
540                  exit(1);
541          }
542 +        octreedate = time(0);
543   }
544  
545  
# Line 538 | Line 555 | register char  *op, *arg;
555  
556  
557   oconvopts(oo)                           /* get oconv options */
558 < char    *oo;
558 > register char   *oo;
559   {
560 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
561 +
562          *oo = '\0';
563          if (vdef(OCONV))
564                  addarg(oo, vval(OCONV));
565   }
566  
567  
568 < lowqopts(ro)                            /* low quality rendering options */
550 < char    *ro;
568 > checkambfile()                  /* check date on ambient file */
569   {
570 <        register char   *op = ro;
570 >        long    afdate;
571  
572 +        if (!vdef(AMBFILE))
573 +                return;
574 +        if ((afdate = fdate(vval(AMBFILE))) < 0)
575 +                return;
576 +        if (octreedate > afdate | matdate > afdate)
577 +                rmfile(vval(AMBFILE));
578 + }
579 +
580 +
581 + double
582 + ambval()                                /* compute ambient value */
583 + {
584 +        if (vdef(EXPOSURE)) {
585 +                if (!isflt(vval(EXPOSURE)))
586 +                        badvalue(EXPOSURE);
587 +                if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
588 +                        return(.5/pow(2.,atof(vval(EXPOSURE))));
589 +                return(.5/atof(vval(EXPOSURE)));
590 +        }
591 +        if (vlet(ZONE) == 'E')
592 +                return(10.);
593 +        if (vlet(ZONE) == 'I')
594 +                return(.01);
595 +        badvalue(ZONE);
596 + }
597 +
598 +
599 + lowqopts(op)                            /* low quality rendering options */
600 + register char   *op;
601 + {
602 +        double  d, org[3], siz[3];
603 +
604          *op = '\0';
605 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
606 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
607 +                badvalue(ZONE);
608 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
609 +        getoctcube(org, &d);
610 +        d *= 3./(siz[0]+siz[1]+siz[2]);
611 +        switch (vscale(DETAIL)) {
612 +        case LOW:
613 +                op = addarg(op, "-ps 16 -dp 16");
614 +                sprintf(op, " -ar %d", (int)(4*d));
615 +                op += strlen(op);
616 +                break;
617 +        case MEDIUM:
618 +                op = addarg(op, "-ps 8 -dp 32");
619 +                sprintf(op, " -ar %d", (int)(8*d));
620 +                op += strlen(op);
621 +                break;
622 +        case HIGH:
623 +                op = addarg(op, "-ps 4 -dp 64");
624 +                sprintf(op, " -ar %d", (int)(16*d));
625 +                op += strlen(op);
626 +                break;
627 +        }
628 +        op = addarg(op, "-pt .16");
629 +        if (vbool(PENUMBRAS))
630 +                op = addarg(op, "-ds .4");
631 +        else
632 +                op = addarg(op, "-ds 0");
633 +        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
634 +        if (vdef(AMBFILE)) {
635 +                sprintf(op, " -af %s", vval(AMBFILE));
636 +                op += strlen(op);
637 +        } else
638 +                overture = 0;
639 +        switch (vscale(VARIABILITY)) {
640 +        case LOW:
641 +                op = addarg(op, "-aa .4 -ad 64");
642 +                break;
643 +        case MEDIUM:
644 +                op = addarg(op, "-aa .3 -ad 128");
645 +                break;
646 +        case HIGH:
647 +                op = addarg(op, "-aa .25 -ad 256");
648 +                break;
649 +        }
650 +        op = addarg(op, "-as 0");
651 +        d = ambval();
652 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
653 +        op += strlen(op);
654 +        op = addarg(op, "-lr 3 -lw .02");
655          if (vdef(RENDER))
656                  op = addarg(op, vval(RENDER));
657   }
658  
659  
660 < medqopts(ro)                            /* medium quality rendering options */
661 < char    *ro;
660 > medqopts(op)                            /* medium quality rendering options */
661 > register char   *op;
662   {
663 <        register char   *op = ro;
663 >        double  d, org[3], siz[3];
664  
665          *op = '\0';
666 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
667 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
668 +                badvalue(ZONE);
669 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
670 +        getoctcube(org, &d);
671 +        d *= 3./(siz[0]+siz[1]+siz[2]);
672 +        switch (vscale(DETAIL)) {
673 +        case LOW:
674 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
675 +                op = addarg(op, "-dp 64");
676 +                sprintf(op, " -ar %d", (int)(8*d));
677 +                op += strlen(op);
678 +                break;
679 +        case MEDIUM:
680 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
681 +                op = addarg(op, "-dp 128");
682 +                sprintf(op, " -ar %d", (int)(16*d));
683 +                op += strlen(op);
684 +                break;
685 +        case HIGH:
686 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
687 +                op = addarg(op, "-dp 256");
688 +                sprintf(op, " -ar %d", (int)(32*d));
689 +                op += strlen(op);
690 +                break;
691 +        }
692 +        op = addarg(op, "-pt .08");
693 +        if (vbool(PENUMBRAS))
694 +                op = addarg(op, "-ds .2 -dj .35");
695 +        else
696 +                op = addarg(op, "-ds .3");
697 +        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
698 +        if (overture = vint(INDIRECT)) {
699 +                sprintf(op, " -ab %d", overture);
700 +                op += strlen(op);
701 +        }
702 +        if (vdef(AMBFILE)) {
703 +                sprintf(op, " -af %s", vval(AMBFILE));
704 +                op += strlen(op);
705 +        } else
706 +                overture = 0;
707 +        switch (vscale(VARIABILITY)) {
708 +        case LOW:
709 +                op = addarg(op, "-aa .25 -ad 196 -as 0");
710 +                break;
711 +        case MEDIUM:
712 +                op = addarg(op, "-aa .2 -ad 400 -as 64");
713 +                break;
714 +        case HIGH:
715 +                op = addarg(op, "-aa .15 -ad 768 -as 196");
716 +                break;
717 +        }
718 +        d = ambval();
719 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
720 +        op += strlen(op);
721 +        op = addarg(op, "-lr 6 -lw .002");
722          if (vdef(RENDER))
723                  op = addarg(op, vval(RENDER));
724   }
725  
726  
727 < hiqopts(ro)                             /* high quality rendering options */
728 < char    *ro;
727 > hiqopts(op)                             /* high quality rendering options */
728 > register char   *op;
729   {
730 <        register char   *op = ro;
730 >        double  d, org[3], siz[3];
731  
732          *op = '\0';
733 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
734 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
735 +                badvalue(ZONE);
736 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
737 +        getoctcube(org, &d);
738 +        d *= 3./(siz[0]+siz[1]+siz[2]);
739 +        switch (vscale(DETAIL)) {
740 +        case LOW:
741 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
742 +                op = addarg(op, "-dp 256");
743 +                sprintf(op, " -ar %d", (int)(16*d));
744 +                op += strlen(op);
745 +                break;
746 +        case MEDIUM:
747 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
748 +                op = addarg(op, "-dp 512");
749 +                sprintf(op, " -ar %d", (int)(32*d));
750 +                op += strlen(op);
751 +                break;
752 +        case HIGH:
753 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
754 +                op = addarg(op, "-dp 1024");
755 +                sprintf(op, " -ar %d", (int)(64*d));
756 +                op += strlen(op);
757 +                break;
758 +        }
759 +        op = addarg(op, "-pt .04");
760 +        if (vbool(PENUMBRAS))
761 +                op = addarg(op, "-ds .1 -dj .7");
762 +        else
763 +                op = addarg(op, "-ds .2");
764 +        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
765 +        sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
766 +        op += strlen(op);
767 +        if (vdef(AMBFILE)) {
768 +                sprintf(op, " -af %s", vval(AMBFILE));
769 +                op += strlen(op);
770 +        } else
771 +                overture = 0;
772 +        switch (vscale(VARIABILITY)) {
773 +        case LOW:
774 +                op = addarg(op, "-aa .15 -ad 256 -as 0");
775 +                break;
776 +        case MEDIUM:
777 +                op = addarg(op, "-aa .125 -ad 512 -as 256");
778 +                break;
779 +        case HIGH:
780 +                op = addarg(op, "-aa .08 -ad 1024 -as 512");
781 +                break;
782 +        }
783 +        d = ambval();
784 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
785 +        op += strlen(op);
786 +        op = addarg(op, "-lr 12 -lw .0005");
787          if (vdef(RENDER))
788                  op = addarg(op, vval(RENDER));
789   }
# Line 583 | Line 793 | xferopts(ro)                           /* transfer options if indicated */
793   char    *ro;
794   {
795          int     fd, n;
796 +        register char   *cp;
797          
798          n = strlen(ro);
799          if (n < 2)
800                  return;
801          if (vdef(OPTFILE)) {
802 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
803 <                        perror(vval(OPTFILE));
804 <                        exit(1);
805 <                }
806 <                if (write(fd, ro+1, n-1) != n-1) {
807 <                        perror(vval(OPTFILE));
808 <                        exit(1);
809 <                }
810 <                write(fd, "\n", 1);
811 <                close(fd);
601 <                ro[0] = ' ';
602 <                ro[1] = '^';
603 <                strcpy(ro+2, vval(OPTFILE));
802 >                for (cp = ro; cp[1]; cp++)
803 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
804 >                                *cp = '\n';
805 >                        else
806 >                                *cp = cp[1];
807 >                *cp = '\n';
808 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
809 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
810 >                        syserr(vval(OPTFILE));
811 >                sprintf(ro, " @%s", vval(OPTFILE));
812          }
813   #ifdef MSDOS
814          else if (n > 50) {
815 <                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);
815 >                setenv("ROPT", ro+1);
816                  strcpy(ro, " $ROPT");
817          }
818   #endif
# Line 626 | Line 827 | register char  *po;
827                  po = addarg(po, "-1 -e");
828                  po = addarg(po, vval(EXPOSURE));
829          }
830 <        if (vscale(QUALITY) == HIGH)
831 <                po = addarg(po, "-r .65");
830 >        switch (vscale(QUALITY)) {
831 >        case MEDIUM:
832 >                po = addarg(po, "-r 1");
833 >                break;
834 >        case HIGH:
835 >                po = addarg(po, "-m .25");
836 >                break;
837 >        }
838          if (vdef(PFILT))
839                  po = addarg(po, vval(PFILT));
840   }
# Line 649 | Line 856 | char *
856   specview(vs)                            /* get proper view spec from vs */
857   register char   *vs;
858   {
859 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
860 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
861          static char     viewopts[128];
862          register char   *cp;
863 <        int     xpos, ypos, zpos, viewtype;
864 <        int     exterior;
863 >        int     xpos, ypos, zpos, viewtype, upax;
864 >        register int    i;
865          double  cent[3], dim[3], mult, d;
866  
867          if (vs == NULL || *vs == '-')
868                  return(vs);
869 +        upax = 0;                       /* get the up vector */
870 +        if (vdef(UP)) {
871 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
872 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
873 +                else
874 +                        upax = 1-'X'+vlet(UP);
875 +                if (upax < 1 | upax > 3)
876 +                        badvalue(UP);
877 +                if (vval(UP)[0] == '-')
878 +                        upax = -upax;
879 +        }
880                                          /* check standard view names */
881          xpos = ypos = zpos = 0;
662        viewtype = 0;
882          if (*vs == 'X') {
883                  xpos = 1; vs++;
884          } else if (*vs == 'x') {
# Line 675 | Line 894 | register char  *vs;
894          } else if (*vs == 'z') {
895                  zpos = -1; vs++;
896          }
897 +        viewtype = 'v';
898          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
899                  viewtype = *vs++;
680        else if (!*vs || isspace(*vs))
681                viewtype = 'v';
900          cp = viewopts;
901 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
901 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
902                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
903                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
904                                  &cent[0], &dim[0], &cent[1], &dim[1],
905 <                                &cent[2], &dim[2]) != 6) {
906 <                        fprintf(stderr, "%s: bad zone specification\n",
907 <                                        progname);
908 <                        exit(1);
905 >                                &cent[2], &dim[2]) != 6)
906 >                        badvalue(ZONE);
907 >                for (i = 0; i < 3; i++) {
908 >                        dim[i] -= cent[i];
909 >                        cent[i] += .5*dim[i];
910                  }
911 <                dim[0] -= cent[0];
693 <                dim[1] -= cent[1];
694 <                dim[2] -= cent[2];
695 <                exterior = vlet(ZONE) == 'E';
696 <                mult = exterior ? 2. : .45 ;
911 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
912                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
913                                  cent[0]+xpos*mult*dim[0],
914                                  cent[1]+ypos*mult*dim[1],
915                                  cent[2]+zpos*mult*dim[2],
916                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
917                  cp += strlen(cp);
918 <                switch (vlet(UP)) {
919 <                case 'Z':
920 <                        if (xpos|ypos) {
921 <                                cp = addarg(cp, "-vu 0 0 1");
922 <                                break;
923 <                        }
924 <                /* 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");
918 >                                        /* redirect up axis if necessary */
919 >                switch (upax) {
920 >                case 3:                 /* plus or minus Z axis */
921 >                case -3:
922 >                case 0:
923 >                        if (!(xpos|ypos))
924 >                                upax = 2;
925                          break;
926 <                default:
927 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
928 <                                        progname, vnam(UP));
929 <                        exit(1);
926 >                case 2:                 /* plus or minus Y axis */
927 >                case -2:
928 >                        if (!(xpos|zpos))
929 >                                upax = 1;
930 >                        break;
931 >                case 1:                 /* plus or minus X axis */
932 >                case -1:
933 >                        if (!(ypos|zpos))
934 >                                upax = 3;
935 >                        break;
936                  }
937 +                cp = addarg(cp, vup[upax+3]);
938                  switch (viewtype) {
939                  case 'v':
940                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 738 | Line 949 | register char  *vs;
949                          cp = addarg(cp, "-vh 180 -vv 180");
950                          break;
951                  }
952 <        } else
953 <                while (*vs && !isspace(*vs))    /* else skip id */
954 <                        vs++;
955 <                                        /* append any additional options */
956 <        while (isspace(*vs)) vs++;
957 <        strcpy(cp, vs);
952 >        } else {
953 >                while (!isspace(*vs))           /* else skip id */
954 >                        if (!*vs++)
955 >                                return(NULL);
956 >                if (upax) {                     /* specify up vector */
957 >                        strcpy(cp, vup[upax+3]);
958 >                        cp += strlen(cp);
959 >                }
960 >        }
961 >        strcpy(cp, vs);                 /* append any additional options */
962 > #ifdef MSDOS
963 >        if (strlen(viewopts) > 40) {
964 >                setenv("VIEW", viewopts);
965 >                return("$VIEW");
966 >        }
967 > #endif
968          return(viewopts);
969   }
970  
# Line 751 | Line 972 | register char  *vs;
972   char *
973   getview(n, vn)                          /* get view n, or NULL if none */
974   int     n;
975 < char    *vn;
975 > char    *vn;            /* returned view name */
976   {
977          register char   *mv;
978  
979 <        if (viewselect != NULL) {
979 >        if (viewselect != NULL) {               /* command-line selected */
980                  if (n)                          /* only do one */
981                          return(NULL);
982                  if (viewselect[0] == '-') {     /* already specified */
# Line 768 | Line 989 | char   *vn;
989                                  ;
990                          *vn = '\0';
991                  }
992 +                                                /* view number? */
993 +                if (isint(viewselect))
994 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
995                                                  /* check list */
996                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
997                          if (matchword(viewselect, mv))
998                                  return(specview(mv));
999                  return(specview(viewselect));   /* standard view? */
1000          }
1001 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1002 <                if (*mv != '-')
1003 <                        while (*mv && !isspace(*mv))
1004 <                                *vn++ = *mv++;
1001 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1002 >        if (vn != NULL & mv != NULL) {
1003 >                register char   *mv2 = mv;
1004 >                if (*mv2 != '-')
1005 >                        while (*mv2 && !isspace(*mv2))
1006 >                                *vn++ = *mv2++;
1007                  *vn = '\0';
1008          }
1009 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1009 >        return(specview(mv));
1010   }
1011  
1012  
1013 + printview(vopts)                        /* print out selected view */
1014 + register char   *vopts;
1015 + {
1016 +        extern char     *atos();
1017 +        char    buf[256];
1018 +        FILE    *fp;
1019 +        register char   *cp;
1020 +
1021 +        if (vopts == NULL)
1022 +                return(-1);
1023 +        fputs("VIEW=", stdout);
1024 +        do {
1025 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1026 +                        vopts = sskip(vopts);
1027 +                        if (!*atos(buf, sizeof(buf), vopts))
1028 +                                return(-1);
1029 +                        if ((fp = fopen(buf, "r")) == NULL)
1030 +                                return(-1);
1031 +                        for (buf[sizeof(buf)-2] = '\n';
1032 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1033 +                                                buf[0] != '\n';
1034 +                                        buf[sizeof(buf)-2] = '\n') {
1035 +                                if (buf[sizeof(buf)-2] != '\n') {
1036 +                                        ungetc(buf[sizeof(buf)-2], fp);
1037 +                                        buf[sizeof(buf)-2] = '\0';
1038 +                                }
1039 +                                if (matchword(buf, "VIEW=") ||
1040 +                                                matchword(buf, "rview")) {
1041 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1042 +                                                putchar(*cp);
1043 +                                }
1044 +                        }
1045 +                        fclose(fp);
1046 +                        vopts = sskip(vopts);
1047 +                } else {
1048 +                        while (isspace(*vopts))
1049 +                                vopts++;
1050 +                        putchar(' ');
1051 +                        while (*vopts && !isspace(*vopts))
1052 +                                putchar(*vopts++);
1053 +                }
1054 +        } while (*vopts++);
1055 +        putchar('\n');
1056 +        return(0);
1057 + }
1058 +
1059 +
1060   rview(opts)                             /* run rview with first view */
1061   char    *opts;
1062   {
1063 +        char    *vw;
1064          char    combuf[512];
1065                                          /* build command */
1066 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1066 >        if ((vw = getview(0, NULL)) == NULL)
1067 >                return;
1068 >        if (sayview)
1069 >                printview(vw);
1070 >        sprintf(combuf, "rview %s%s ", vw, opts);
1071          if (rvdevice != NULL)
1072                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1073          strcat(combuf, vval(OCTREE));
1074 <        if (!silent) {                  /* echo it */
797 <                printf("\t%s\n", combuf);
798 <                fflush(stdout);
799 <        }
800 <        if (noaction)
801 <                return;
802 <        if (system(combuf)) {           /* run it */
1074 >        if (runcom(combuf)) {           /* run it */
1075                  fprintf(stderr, "%s: error running rview\n", progname);
1076                  exit(1);
1077          }
# Line 809 | Line 1081 | char   *opts;
1081   rpict(opts)                             /* run rpict and pfilt for each view */
1082   char    *opts;
1083   {
1084 <        char    combuf[512];
1085 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1086 <        char    pfopts[64];
1084 >        char    combuf[1024];
1085 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1086 >        char    pfopts[128];
1087          char    vs[32], *vw;
1088          int     vn, mult;
1089 +        long    lastdate;
1090                                          /* get pfilt options */
1091          pfiltopts(pfopts);
1092                                          /* get resolution, reporting */
# Line 829 | Line 1102 | char   *opts;
1102                  else if (n) {
1103                          if (n == 1) yres = xres;
1104                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1105 <                } else {
1106 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
834 <                                        progname, vnam(RESOLUTION));
835 <                        exit(1);
836 <                }
1105 >                } else
1106 >                        badvalue(RESOLUTION);
1107          }
1108          rep[0] = '\0';
1109          if (vdef(REPORT)) {
# Line 844 | Line 1114 | char   *opts;
1114                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1115                  else if (n == 1)
1116                          sprintf(rep, " -t %d", (int)(minutes*60));
1117 <                else {
1118 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
849 <                                        progname, vnam(REPORT));
850 <                        exit(1);
851 <                }
1117 >                else
1118 >                        badvalue(REPORT);
1119          }
1120 +                                        /* get update time */
1121 +        lastdate = octreedate > matdate ? octreedate : matdate;
1122                                          /* do each view */
1123          vn = 0;
1124          while ((vw = getview(vn++, vs)) != NULL) {
1125 +                if (sayview)
1126 +                        printview(vw);
1127                  if (!vs[0])
1128                          sprintf(vs, "%d", vn);
1129                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1130                                                  /* check date on picture */
1131 <                if (fdate(picfile) > octreedate)
1131 >                if (fdate(picfile) >= lastdate)
1132                          continue;
1133                                                  /* build rpict command */
1134                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1135 <                if (fdate(rawfile) > octreedate)        /* recover */
1135 >                if (fdate(rawfile) >= octreedate)       /* recover */
1136                          sprintf(combuf, "rpict%s%s -ro %s %s",
1137                                          rep, opts, rawfile, vval(OCTREE));
1138                  else {
# Line 869 | Line 1140 | char   *opts;
1140                                  sprintf(combuf,
1141                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1142                                                  rep, vw, opts,
1143 <                                                vval(OCTREE), rawfile);
1144 <                                if (!silent) {
874 <                                        printf("\t%s\n", combuf);
875 <                                        fflush(stdout);
876 <                                }
877 <                                if (!noaction && system(combuf)) {
1143 >                                                vval(OCTREE), overfile);
1144 >                                if (runcom(combuf)) {
1145                                          fprintf(stderr,
1146 <                        "%s: error in overture for view %s\n\t%s removed\n",
1147 <                                                progname, vs, rawfile);
881 <                                        unlink(rawfile);
1146 >                                        "%s: error in overture for view %s\n",
1147 >                                                progname, vs);
1148                                          exit(1);
1149                                  }
1150 + #ifdef NIX
1151 +                                rmfile(overfile);
1152 + #endif
1153                          }
1154                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1155                                          rep, vw, res, opts,
1156                                          vval(OCTREE), rawfile);
1157                  }
1158 <                if (!silent) {                  /* echo rpict command */
890 <                        printf("\t%s\n", combuf);
891 <                        fflush(stdout);
892 <                }
893 <                if (!noaction && system(combuf)) {      /* run rpict */
1158 >                if (runcom(combuf)) {           /* run rpict */
1159                          fprintf(stderr, "%s: error rendering view %s\n",
1160                                          progname, vs);
1161                          exit(1);
# Line 902 | Line 1167 | char   *opts;
1167                  else
1168                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1169                                          rawfile, picfile);
1170 <                if (!silent) {                  /* echo pfilt command */
906 <                        printf("\t%s\n", combuf);
907 <                        fflush(stdout);
908 <                }
909 <                if (!noaction && system(combuf)) {      /* run pfilt */
1170 >                if (runcom(combuf)) {           /* run pfilt */
1171                          fprintf(stderr,
1172                          "%s: error filtering view %s\n\t%s removed\n",
1173                                          progname, vs, picfile);
# Line 914 | Line 1175 | char   *opts;
1175                          exit(1);
1176                  }
1177                                                  /* remove raw file */
1178 <                if (!silent)
1178 >                rmfile(rawfile);
1179 >        }
1180 > }
1181 >
1182 >
1183 > runcom(cs)                      /* run command */
1184 > char    *cs;
1185 > {
1186 >        if (!silent)            /* echo it */
1187 >                printf("\t%s\n", cs);
1188 >        if (noaction)
1189 >                return(0);
1190 >        fflush(stdout);         /* flush output and pass to shell */
1191 >        return(system(cs));
1192 > }
1193 >
1194 >
1195 > rmfile(fn)                      /* remove a file */
1196 > char    *fn;
1197 > {
1198 >        if (!silent)
1199   #ifdef MSDOS
1200 <                        printf("\tdel %s\n", rawfile);
1200 >                printf("\tdel %s\n", fn);
1201   #else
1202 <                        printf("\trm %s\n", rawfile);
1202 >                printf("\trm -f %s\n", fn);
1203   #endif
1204 <                if (!noaction)
1205 <                        unlink(rawfile);
1204 >        if (noaction)
1205 >                return(0);
1206 >        return(unlink(fn));
1207 > }
1208 >
1209 >
1210 > #ifdef MSDOS
1211 > setenv(vname, value)            /* set an environment variable */
1212 > char    *vname, *value;
1213 > {
1214 >        register char   *evp;
1215 >
1216 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1217 >        if (evp == NULL)
1218 >                syserr(progname);
1219 >        sprintf(evp, "%s=%s", vname, value);
1220 >        if (putenv(evp) != 0) {
1221 >                fprintf(stderr, "%s: out of environment space\n", progname);
1222 >                exit(1);
1223          }
1224 +        if (!silent)
1225 +                printf("set %s\n", evp);
1226 + }
1227 + #endif
1228 +
1229 +
1230 + badvalue(vc)                    /* report bad variable value and exit */
1231 + int     vc;
1232 + {
1233 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1234 +                        progname, vnam(vc));
1235 +        exit(1);
1236 + }
1237 +
1238 +
1239 + syserr(s)                       /* report a system error and exit */
1240 + char    *s;
1241 + {
1242 +        perror(s);
1243 +        exit(1);
1244   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines