ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.2 by greg, Thu Mar 11 11:39:48 1993 UTC vs.
Revision 2.20 by greg, Tue Aug 24 21:44:55 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 +                                /* 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     vwonly = 0;             /* print view only */
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 +                        vwonly++;
149 +                /* fall through */
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 >                                /* print view and exit? */
175 >        if (vwonly)
176 >                exit(printview()==0 ? 0 : 1);
177 >                                /* build octree */
178          oconv();
179 +                                /* check date on ambient file */
180 +        checkambfile();
181 +                                /* run simulation */
182          renderopts(ropts);
183          xferopts(ropts);
184          if (rvdevice != NULL)
# Line 168 | Line 188 | char   *argv[];
188          exit(0);
189   userr:
190          fprintf(stderr,
191 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
191 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
192                          progname);
193          exit(1);
194   }
# Line 193 | Line 213 | load(rfname)                   /* load Radiance simulation file */
213   char    *rfname;
214   {
215          FILE    *fp;
216 <        char    buf[256];
216 >        char    buf[512];
217          register char   *cp;
218  
219          if (rfname == NULL)
220                  fp = stdin;
221 <        else if ((fp = fopen(rfname, "r")) == NULL) {
222 <                perror(rfname);
203 <                exit(1);
204 <        }
221 >        else if ((fp = fopen(rfname, "r")) == NULL)
222 >                syserr(rfname);
223          while (fgetline(buf, sizeof(buf), fp) != NULL) {
224                  for (cp = buf; *cp; cp++) {
225                          switch (*cp) {
# Line 212 | Line 230 | char   *rfname;
230                          case '#':
231                                  *cp = '\0';
232                                  break;
233 +                        default:
234 +                                continue;
235                          }
236                          break;
237                  }
# Line 260 | Line 280 | register char  *ass;
280                  exit(1);
281          }
282                                          /* assign new value */
283 <        cp = vp->value; i = vp->nass;
284 <        while (i--)
285 <                while (*cp++)
286 <                        ;
287 <        i = cp - vp->value;
288 <        vp->value = realloc(vp->value, i+n+1);
289 <        if (vp->value == NULL) {
290 <                perror(progname);
291 <                exit(1);
292 <        }
283 >        if (i = vp->nass) {
284 >                cp = vp->value;
285 >                while (i--)
286 >                        while (*cp++)
287 >                                ;
288 >                i = cp - vp->value;
289 >                vp->value = realloc(vp->value, i+n+1);
290 >        } else
291 >                vp->value = malloc(n+1);
292 >        if (vp->value == NULL)
293 >                syserr(progname);
294          strcpy(vp->value+i, ass);
295          vp->nass++;
296   }
# Line 296 | Line 317 | register int   n;
317   {
318          register char   *cp;
319  
320 <        if (vp == NULL || n < 0 || n >= vp->nass)
320 >        if (vp == NULL | n < 0 | n >= vp->nass)
321                  return(NULL);
322          cp = vp->value;
323          while (n--)
# Line 318 | Line 339 | int    vc;
339          case 'L':
340                  return(LOW);
341          }
342 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
342 >        badvalue(vc);
343   }
344  
345  
# Line 373 | Line 392 | register char  *fnames;
392          while (*fnames) {
393                  while (isspace(*fnames)) fnames++;
394                  cp = thisfile;
395 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
395 >                while (*fnames && !isspace(*fnames))
396 >                        *cp++ = *fnames++;
397                  *cp = '\0';
398 <                if ((thisdate = fdate(thisfile)) < 0) {
399 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
398 >                if ((thisdate = fdate(thisfile)) < 0)
399 >                        syserr(thisfile);
400                  if (thisdate > lastdate)
401                          lastdate = thisdate;
402          }
# Line 392 | Line 410 | checkfiles()                   /* check for existence and modified tim
410          long    objdate;
411  
412          if (!vdef(OCTREE)) {
413 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
414 <                        perror(progname);
397 <                        exit(1);
398 <                }
413 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
414 >                        syserr(progname);
415                  sprintf(cp, "%s.oct", radname);
416                  vval(OCTREE) = cp;
417                  vdef(OCTREE)++;
# Line 415 | Line 431 | checkfiles()                   /* check for existence and modified tim
431                                  vnam(OCTREE), vnam(SCENE));
432                  exit(1);
433          }
434 +        matdate = -1;
435 +        if (vdef(MATERIAL))
436 +                matdate = checklast(vval(MATERIAL));
437   }      
438  
439  
# Line 429 | Line 448 | double org[3], *sizp;
448          if (osiz <= FTINY) {
449                  oconv();                /* does nothing if done already */
450                  sprintf(buf, "getinfo -d < %s", vval(OCTREE));
451 <                if ((fp = popen(buf, "r")) == NULL) {
452 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
451 >                if ((fp = popen(buf, "r")) == NULL)
452 >                        syserr("getinfo");
453                  if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
454                                  &oorg[2], &osiz) != 4) {
455                          fprintf(stderr,
# Line 458 | Line 475 | setdefaults()                  /* set default values for unassigned v
475                  vval(ZONE) = savqstr(buf);
476                  vdef(ZONE)++;
477          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
478          if (!vdef(INDIRECT)) {
479                  vval(INDIRECT) = "0";
480                  vdef(INDIRECT)++;
# Line 502 | Line 515 | printvals()                    /* print variable values */
515          register int    i, j;
516  
517          for (i = 0; i < NVARS; i++)
518 <                for (j = 0; j < vv[i].nass; j++)
519 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
518 >                for (j = 0; j < vdef(i); j++)
519 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
520          fflush(stdout);
521   }
522  
# Line 516 | Line 529 | oconv()                                /* run oconv if necessary */
529                  return;
530                                          /* build command */
531          oconvopts(ocopts);
532 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
533 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
534 <                        vval(SCENE), vval(OCTREE));
535 <        if (!silent) {                  /* echo it */
536 <                printf("\t%s\n", combuf);
537 <                fflush(stdout);
538 <        }
539 <        if (noaction)
527 <                return;
528 <        if (system(combuf)) {           /* run it */
532 >        if (vdef(MATERIAL))
533 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
534 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
535 >        else
536 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
537 >                                vval(SCENE), vval(OCTREE));
538 >        
539 >        if (runcom(combuf)) {           /* run it */
540                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
541                                  progname, vval(OCTREE));
542                  unlink(vval(OCTREE));
# Line 557 | Line 568 | register char  *oo;
568   }
569  
570  
571 + checkambfile()                  /* check date on ambient file */
572 + {
573 +        long    afdate;
574 +
575 +        if (!vdef(AMBFILE))
576 +                return;
577 +        if ((afdate = fdate(vval(AMBFILE))) < 0)
578 +                return;
579 +        if (octreedate > afdate | matdate > afdate)
580 +                rmfile(vval(AMBFILE));
581 + }
582 +
583 +
584   double
585   ambval()                                /* compute ambient value */
586   {
587 <        if (vdef(EXPOSURE))
587 >        if (vdef(EXPOSURE)) {
588 >                if (!isflt(vval(EXPOSURE)))
589 >                        badvalue(EXPOSURE);
590                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
591                          return(.5/pow(2.,atof(vval(EXPOSURE))));
592 <                else
593 <                        return(.5/atof(vval(EXPOSURE)));
592 >                return(.5/atof(vval(EXPOSURE)));
593 >        }
594          if (vlet(ZONE) == 'E')
595                  return(10.);
596 <        else
596 >        if (vlet(ZONE) == 'I')
597                  return(.01);
598 +        badvalue(ZONE);
599   }
600  
601  
# Line 579 | Line 606 | register char  *op;
606  
607          *op = '\0';
608          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
609 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
610 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
609 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
610 >                badvalue(ZONE);
611          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
612          getoctcube(org, &d);
613          d *= 3./(siz[0]+siz[1]+siz[2]);
614          switch (vscale(DETAIL)) {
615          case LOW:
616 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
616 >                op = addarg(op, "-ps 16 -dp 16");
617                  sprintf(op, " -ar %d", (int)(4*d));
618                  op += strlen(op);
619                  break;
620          case MEDIUM:
621 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
621 >                op = addarg(op, "-ps 8 -dp 32");
622                  sprintf(op, " -ar %d", (int)(8*d));
623                  op += strlen(op);
624                  break;
625          case HIGH:
626 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
626 >                op = addarg(op, "-ps 4 -dp 64");
627                  sprintf(op, " -ar %d", (int)(16*d));
628                  op += strlen(op);
629                  break;
# Line 610 | Line 631 | register char  *op;
631          op = addarg(op, "-pt .16");
632          if (vbool(PENUMBRAS))
633                  op = addarg(op, "-ds .4");
634 <        op = addarg(op, "-dt .2");
635 <        op = addarg(op, "-dc .25");
636 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
634 >        else
635 >                op = addarg(op, "-ds 0");
636 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
637          if (vdef(AMBFILE)) {
638                  sprintf(op, " -af %s", vval(AMBFILE));
639                  op += strlen(op);
# Line 623 | Line 641 | register char  *op;
641                  overture = 0;
642          switch (vscale(VARIABILITY)) {
643          case LOW:
644 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
644 >                op = addarg(op, "-aa .4 -ad 64");
645                  break;
646          case MEDIUM:
647 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
647 >                op = addarg(op, "-aa .3 -ad 128");
648                  break;
649          case HIGH:
650 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
650 >                op = addarg(op, "-aa .25 -ad 256");
651                  break;
652          }
653          op = addarg(op, "-as 0");
654          d = ambval();
655          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
656          op += strlen(op);
657 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
657 >        op = addarg(op, "-lr 3 -lw .02");
658          if (vdef(RENDER))
659                  op = addarg(op, vval(RENDER));
660   }
# Line 653 | Line 667 | register char  *op;
667  
668          *op = '\0';
669          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
670 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
671 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
670 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
671 >                badvalue(ZONE);
672          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
673          getoctcube(org, &d);
674          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 682 | Line 693 | register char  *op;
693                  break;
694          }
695          op = addarg(op, "-pt .08");
696 <        if (vbool(PENUMBRAS)) {
697 <                op = addarg(op, "-ds .2");
698 <                op = addarg(op, "-dj .35");
688 <        } else
696 >        if (vbool(PENUMBRAS))
697 >                op = addarg(op, "-ds .2 -dj .35");
698 >        else
699                  op = addarg(op, "-ds .3");
700 <        op = addarg(op, "-dt .1");
701 <        op = addarg(op, "-dc .5");
702 <        op = addarg(op, "-dr 1");
703 <        op = addarg(op, "-sj .7");
704 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
700 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
701 >        if (overture = vint(INDIRECT)) {
702 >                sprintf(op, " -ab %d", overture);
703 >                op += strlen(op);
704 >        }
705          if (vdef(AMBFILE)) {
706                  sprintf(op, " -af %s", vval(AMBFILE));
707                  op += strlen(op);
# Line 701 | Line 709 | register char  *op;
709                  overture = 0;
710          switch (vscale(VARIABILITY)) {
711          case LOW:
712 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
712 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
713                  break;
714          case MEDIUM:
715 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
715 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
716                  break;
717          case HIGH:
718 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
718 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
719                  break;
720          }
721          d = ambval();
722          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
723          op += strlen(op);
724 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
724 >        op = addarg(op, "-lr 6 -lw .002");
725          if (vdef(RENDER))
726                  op = addarg(op, vval(RENDER));
727   }
# Line 733 | Line 734 | register char  *op;
734  
735          *op = '\0';
736          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
737 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
738 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
737 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
738 >                badvalue(ZONE);
739          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
740          getoctcube(org, &d);
741          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 762 | Line 760 | register char  *op;
760                  break;
761          }
762          op = addarg(op, "-pt .04");
763 <        if (vbool(PENUMBRAS)) {
764 <                op = addarg(op, "-ds .1");
765 <                op = addarg(op, "-dj .7");
768 <        } else
763 >        if (vbool(PENUMBRAS))
764 >                op = addarg(op, "-ds .1 -dj .7");
765 >        else
766                  op = addarg(op, "-ds .2");
767 <        op = addarg(op, "-dt .05");
771 <        op = addarg(op, "-dc .75");
772 <        op = addarg(op, "-dr 3");
773 <        op = addarg(op, "-sj 1");
774 <        op = addarg(op, "-st .03");
767 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
768          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
769          op += strlen(op);
770          if (vdef(AMBFILE)) {
# Line 781 | Line 774 | register char  *op;
774                  overture = 0;
775          switch (vscale(VARIABILITY)) {
776          case LOW:
777 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
777 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
778                  break;
779          case MEDIUM:
780 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
780 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
781                  break;
782          case HIGH:
783 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
783 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
784                  break;
785          }
786          d = ambval();
787          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
788          op += strlen(op);
789 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
789 >        op = addarg(op, "-lr 12 -lw .0005");
790          if (vdef(RENDER))
791                  op = addarg(op, vval(RENDER));
792   }
# Line 810 | Line 796 | xferopts(ro)                           /* transfer options if indicated */
796   char    *ro;
797   {
798          int     fd, n;
799 +        register char   *cp;
800          
801          n = strlen(ro);
802          if (n < 2)
803                  return;
804          if (vdef(OPTFILE)) {
805 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
806 <                        perror(vval(OPTFILE));
807 <                        exit(1);
808 <                }
809 <                if (write(fd, ro+1, n-1) != n-1) {
810 <                        perror(vval(OPTFILE));
811 <                        exit(1);
812 <                }
813 <                write(fd, "\n", 1);
814 <                close(fd);
828 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
805 >                for (cp = ro; cp[1]; cp++)
806 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
807 >                                *cp = '\n';
808 >                        else
809 >                                *cp = cp[1];
810 >                *cp = '\n';
811 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
812 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
813 >                        syserr(vval(OPTFILE));
814 >                sprintf(ro, " @%s", vval(OPTFILE));
815          }
816   #ifdef MSDOS
817          else if (n > 50) {
818 <                register char   *evp = bmalloc(n+6);
835 <                if (evp == NULL) {
836 <                        perror(progname);
837 <                        exit(1);
838 <                }
839 <                strcpy(evp, "ROPT=");
840 <                strcat(evp, ro);
841 <                if (putenv(evp) != 0) {
842 <                        fprintf(stderr, "%s: out of environment space\n",
843 <                                        progname);
844 <                        exit(1);
845 <                }
818 >                setenv("ROPT", ro+1);
819                  strcpy(ro, " $ROPT");
820          }
821   #endif
# Line 857 | Line 830 | register char  *po;
830                  po = addarg(po, "-1 -e");
831                  po = addarg(po, vval(EXPOSURE));
832          }
833 <        if (vscale(QUALITY) == HIGH)
834 <                po = addarg(po, "-r .65");
833 >        switch (vscale(QUALITY)) {
834 >        case MEDIUM:
835 >                po = addarg(po, "-r 1");
836 >                break;
837 >        case HIGH:
838 >                po = addarg(po, "-m .25");
839 >                break;
840 >        }
841          if (vdef(PFILT))
842                  po = addarg(po, vval(PFILT));
843   }
# Line 880 | Line 859 | char *
859   specview(vs)                            /* get proper view spec from vs */
860   register char   *vs;
861   {
862 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
863 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
864          static char     viewopts[128];
865          register char   *cp;
866 <        int     xpos, ypos, zpos, viewtype;
867 <        int     exterior;
866 >        int     xpos, ypos, zpos, viewtype, upax;
867 >        register int    i;
868          double  cent[3], dim[3], mult, d;
869  
870          if (vs == NULL || *vs == '-')
871                  return(vs);
872 +        upax = 0;                       /* get the up vector */
873 +        if (vdef(UP)) {
874 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
875 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
876 +                else
877 +                        upax = 1-'X'+vlet(UP);
878 +                if (upax < 1 | upax > 3)
879 +                        badvalue(UP);
880 +                if (vval(UP)[0] == '-')
881 +                        upax = -upax;
882 +        }
883                                          /* check standard view names */
884          xpos = ypos = zpos = 0;
893        viewtype = 0;
885          if (*vs == 'X') {
886                  xpos = 1; vs++;
887          } else if (*vs == 'x') {
# Line 906 | Line 897 | register char  *vs;
897          } else if (*vs == 'z') {
898                  zpos = -1; vs++;
899          }
900 +        viewtype = 'v';
901          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
902                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
903          cp = viewopts;
904 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
904 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
905                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
906                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
907                                  &cent[0], &dim[0], &cent[1], &dim[1],
908 <                                &cent[2], &dim[2]) != 6) {
909 <                        fprintf(stderr, "%s: bad zone specification\n",
910 <                                        progname);
911 <                        exit(1);
908 >                                &cent[2], &dim[2]) != 6)
909 >                        badvalue(ZONE);
910 >                for (i = 0; i < 3; i++) {
911 >                        dim[i] -= cent[i];
912 >                        cent[i] += .5*dim[i];
913                  }
914 <                dim[0] -= cent[0]; cent[0] += .5*dim[0];
924 <                dim[1] -= cent[1]; cent[1] += .5*dim[1];
925 <                dim[2] -= cent[2]; cent[2] += .5*dim[2];
926 <                exterior = vlet(ZONE) == 'E';
927 <                mult = exterior ? 2. : .45 ;
914 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
915                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
916                                  cent[0]+xpos*mult*dim[0],
917                                  cent[1]+ypos*mult*dim[1],
918                                  cent[2]+zpos*mult*dim[2],
919                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
920                  cp += strlen(cp);
921 <                switch (vlet(UP)) {
922 <                case 'Z':
923 <                        if (xpos|ypos) {
924 <                                cp = addarg(cp, "-vu 0 0 1");
925 <                                break;
926 <                        }
927 <                /* fall through */
941 <                case 'Y':
942 <                        if (xpos|zpos) {
943 <                                cp = addarg(cp, "-vu 0 1 0");
944 <                                break;
945 <                        }
946 <                /* fall through */
947 <                case 'X':
948 <                        if (ypos|zpos)
949 <                                cp = addarg(cp, "-vu 1 0 0");
950 <                        else
951 <                                cp = addarg(cp, "-vu 0 0 1");
921 >                                        /* redirect up axis if necessary */
922 >                switch (upax) {
923 >                case 3:                 /* plus or minus Z axis */
924 >                case -3:
925 >                case 0:
926 >                        if (!(xpos|ypos))
927 >                                upax = 2;
928                          break;
929 <                default:
930 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
931 <                                        progname, vnam(UP));
932 <                        exit(1);
929 >                case 2:                 /* plus or minus Y axis */
930 >                case -2:
931 >                        if (!(xpos|zpos))
932 >                                upax = 1;
933 >                        break;
934 >                case 1:                 /* plus or minus X axis */
935 >                case -1:
936 >                        if (!(ypos|zpos))
937 >                                upax = 3;
938 >                        break;
939                  }
940 +                cp = addarg(cp, vup[upax+3]);
941                  switch (viewtype) {
942                  case 'v':
943                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 952 | register char  *vs;
952                          cp = addarg(cp, "-vh 180 -vv 180");
953                          break;
954                  }
955 <        } else
956 <                while (*vs && !isspace(*vs))    /* else skip id */
957 <                        vs++;
958 <                                        /* append any additional options */
959 <        while (isspace(*vs)) vs++;
960 <        strcpy(cp, vs);
955 >        } else {
956 >                while (!isspace(*vs))           /* else skip id */
957 >                        if (!*vs++)
958 >                                return(NULL);
959 >                if (upax) {                     /* specify up vector */
960 >                        strcpy(cp, vup[upax+3]);
961 >                        cp += strlen(cp);
962 >                }
963 >        }
964 >        strcpy(cp, vs);                 /* append any additional options */
965 > #ifdef MSDOS
966 >        if (strlen(viewopts) > 40) {
967 >                setenv("VIEW", viewopts);
968 >                return("$VIEW");
969 >        }
970 > #endif
971          return(viewopts);
972   }
973  
# Line 982 | Line 975 | register char  *vs;
975   char *
976   getview(n, vn)                          /* get view n, or NULL if none */
977   int     n;
978 < char    *vn;
978 > char    *vn;            /* returned view name */
979   {
980          register char   *mv;
981  
982 <        if (viewselect != NULL) {
982 >        if (viewselect != NULL) {               /* command-line selected */
983                  if (n)                          /* only do one */
984                          return(NULL);
985                  if (viewselect[0] == '-') {     /* already specified */
# Line 999 | Line 992 | char   *vn;
992                                  ;
993                          *vn = '\0';
994                  }
995 +                                                /* view number? */
996 +                if (isint(viewselect))
997 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
998                                                  /* check list */
999                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1000                          if (matchword(viewselect, mv))
1001                                  return(specview(mv));
1002                  return(specview(viewselect));   /* standard view? */
1003          }
1004 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1005 <                if (*mv != '-')
1006 <                        while (*mv && !isspace(*mv))
1007 <                                *vn++ = *mv++;
1004 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1005 >        if (vn != NULL & mv != NULL) {
1006 >                register char   *mv2 = mv;
1007 >                if (*mv2 != '-')
1008 >                        while (*mv2 && !isspace(*mv2))
1009 >                                *vn++ = *mv2++;
1010                  *vn = '\0';
1011          }
1012 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1012 >        return(specview(mv));
1013   }
1014  
1015  
1016 + printview()                     /* print out selected view */
1017 + {
1018 +        extern char     *atos();
1019 +        char    buf[256];
1020 +        FILE    *fp;
1021 +        register char   *vopts, *cp;
1022 +
1023 +        vopts = getview(0, NULL);
1024 +        if (vopts == NULL)
1025 +                return(-1);
1026 +        fputs("VIEW=", stdout);
1027 +        do {
1028 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1029 +                        vopts = sskip(vopts);
1030 +                        if (!*atos(buf, sizeof(buf), vopts))
1031 +                                return(-1);
1032 +                        if ((fp = fopen(buf, "r")) == NULL)
1033 +                                return(-1);
1034 +                        for (buf[sizeof(buf)-2] = '\n';
1035 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1036 +                                                buf[0] != '\n';
1037 +                                        buf[sizeof(buf)-2] = '\n') {
1038 +                                if (buf[sizeof(buf)-2] != '\n') {
1039 +                                        ungetc(buf[sizeof(buf)-2], fp);
1040 +                                        buf[sizeof(buf)-2] = '\0';
1041 +                                }
1042 +                                if (matchword(buf, "VIEW=") ||
1043 +                                                matchword(buf, "rview")) {
1044 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1045 +                                                putchar(*cp);
1046 +                                }
1047 +                        }
1048 +                        fclose(fp);
1049 +                        vopts = sskip(vopts);
1050 +                } else {
1051 +                        while (isspace(*vopts))
1052 +                                vopts++;
1053 +                        putchar(' ');
1054 +                        while (*vopts && !isspace(*vopts))
1055 +                                putchar(*vopts++);
1056 +                }
1057 +        } while (*vopts++);
1058 +        putchar('\n');
1059 +        return(0);
1060 + }
1061 +
1062 +
1063   rview(opts)                             /* run rview with first view */
1064   char    *opts;
1065   {
# Line 1024 | Line 1069 | char   *opts;
1069          if (rvdevice != NULL)
1070                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1071          strcat(combuf, vval(OCTREE));
1072 <        if (!silent) {                  /* echo it */
1028 <                printf("\t%s\n", combuf);
1029 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        if (system(combuf)) {           /* run it */
1072 >        if (runcom(combuf)) {           /* run it */
1073                  fprintf(stderr, "%s: error running rview\n", progname);
1074                  exit(1);
1075          }
# Line 1041 | Line 1080 | rpict(opts)                            /* run rpict and pfilt for each view */
1080   char    *opts;
1081   {
1082          char    combuf[1024];
1083 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1084 <        char    pfopts[64];
1083 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1084 >        char    pfopts[128];
1085          char    vs[32], *vw;
1086          int     vn, mult;
1087 +        long    lastdate;
1088                                          /* get pfilt options */
1089          pfiltopts(pfopts);
1090                                          /* get resolution, reporting */
# Line 1060 | Line 1100 | char   *opts;
1100                  else if (n) {
1101                          if (n == 1) yres = xres;
1102                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1103 <                } else {
1104 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1103 >                } else
1104 >                        badvalue(RESOLUTION);
1105          }
1106          rep[0] = '\0';
1107          if (vdef(REPORT)) {
# Line 1075 | Line 1112 | char   *opts;
1112                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1113                  else if (n == 1)
1114                          sprintf(rep, " -t %d", (int)(minutes*60));
1115 <                else {
1116 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1115 >                else
1116 >                        badvalue(REPORT);
1117          }
1118 +                                        /* get update time */
1119 +        lastdate = octreedate > matdate ? octreedate : matdate;
1120                                          /* do each view */
1121          vn = 0;
1122          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1088 | Line 1124 | char   *opts;
1124                          sprintf(vs, "%d", vn);
1125                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1126                                                  /* check date on picture */
1127 <                if (fdate(picfile) > octreedate)
1127 >                if (fdate(picfile) >= lastdate)
1128                          continue;
1129                                                  /* build rpict command */
1130                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1131 <                if (fdate(rawfile) > octreedate)        /* recover */
1131 >                if (fdate(rawfile) >= octreedate)       /* recover */
1132                          sprintf(combuf, "rpict%s%s -ro %s %s",
1133                                          rep, opts, rawfile, vval(OCTREE));
1134                  else {
# Line 1100 | Line 1136 | char   *opts;
1136                                  sprintf(combuf,
1137                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1138                                                  rep, vw, opts,
1139 <                                                vval(OCTREE), rawfile);
1140 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1139 >                                                vval(OCTREE), overfile);
1140 >                                if (runcom(combuf)) {
1141                                          fprintf(stderr,
1142 <                        "%s: error in overture for view %s\n\t%s removed\n",
1143 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1142 >                                        "%s: error in overture for view %s\n",
1143 >                                                progname, vs);
1144                                          exit(1);
1145                                  }
1146 + #ifdef NIX
1147 +                                rmfile(overfile);
1148 + #endif
1149                          }
1150                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1151                                          rep, vw, res, opts,
1152                                          vval(OCTREE), rawfile);
1153                  }
1154 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1154 >                if (runcom(combuf)) {           /* run rpict */
1155                          fprintf(stderr, "%s: error rendering view %s\n",
1156                                          progname, vs);
1157                          exit(1);
# Line 1133 | Line 1163 | char   *opts;
1163                  else
1164                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1165                                          rawfile, picfile);
1166 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1166 >                if (runcom(combuf)) {           /* run pfilt */
1167                          fprintf(stderr,
1168                          "%s: error filtering view %s\n\t%s removed\n",
1169                                          progname, vs, picfile);
# Line 1145 | Line 1171 | char   *opts;
1171                          exit(1);
1172                  }
1173                                                  /* remove raw file */
1174 <                if (!silent)
1174 >                rmfile(rawfile);
1175 >        }
1176 > }
1177 >
1178 >
1179 > runcom(cs)                      /* run command */
1180 > char    *cs;
1181 > {
1182 >        if (!silent)            /* echo it */
1183 >                printf("\t%s\n", cs);
1184 >        if (noaction)
1185 >                return(0);
1186 >        fflush(stdout);         /* flush output and pass to shell */
1187 >        return(system(cs));
1188 > }
1189 >
1190 >
1191 > rmfile(fn)                      /* remove a file */
1192 > char    *fn;
1193 > {
1194 >        if (!silent)
1195   #ifdef MSDOS
1196 <                        printf("\tdel %s\n", rawfile);
1196 >                printf("\tdel %s\n", fn);
1197   #else
1198 <                        printf("\trm %s\n", rawfile);
1198 >                printf("\trm -f %s\n", fn);
1199   #endif
1200 <                if (!noaction)
1201 <                        unlink(rawfile);
1200 >        if (noaction)
1201 >                return(0);
1202 >        return(unlink(fn));
1203 > }
1204 >
1205 >
1206 > #ifdef MSDOS
1207 > setenv(vname, value)            /* set an environment variable */
1208 > char    *vname, *value;
1209 > {
1210 >        register char   *evp;
1211 >
1212 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1213 >        if (evp == NULL)
1214 >                syserr(progname);
1215 >        sprintf(evp, "%s=%s", vname, value);
1216 >        if (putenv(evp) != 0) {
1217 >                fprintf(stderr, "%s: out of environment space\n", progname);
1218 >                exit(1);
1219          }
1220 +        if (!silent)
1221 +                printf("set %s\n", evp);
1222 + }
1223 + #endif
1224 +
1225 +
1226 + badvalue(vc)                    /* report bad variable value and exit */
1227 + int     vc;
1228 + {
1229 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1230 +                        progname, vnam(vc));
1231 +        exit(1);
1232 + }
1233 +
1234 +
1235 + syserr(s)                       /* report a system error and exit */
1236 + char    *s;
1237 + {
1238 +        perror(s);
1239 +        exit(1);
1240   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines