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.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 +                                /* 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 373 | 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);
380 <                        exit(1);
381 <                }
395 >                if ((thisdate = fdate(thisfile)) < 0)
396 >                        syserr(thisfile);
397                  if (thisdate > lastdate)
398                          lastdate = thisdate;
399          }
# Line 392 | Line 407 | checkfiles()                   /* check for existence and modified tim
407          long    objdate;
408  
409          if (!vdef(OCTREE)) {
410 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
411 <                        perror(progname);
397 <                        exit(1);
398 <                }
410 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
411 >                        syserr(progname);
412                  sprintf(cp, "%s.oct", radname);
413                  vval(OCTREE) = cp;
414                  vdef(OCTREE)++;
# Line 415 | Line 428 | checkfiles()                   /* check for existence and modified tim
428                                  vnam(OCTREE), vnam(SCENE));
429                  exit(1);
430          }
431 +        matdate = -1;
432 +        if (vdef(MATERIAL))
433 +                matdate = checklast(vval(MATERIAL));
434   }      
435  
436  
# Line 429 | Line 445 | double org[3], *sizp;
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 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
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,
# Line 458 | Line 472 | setdefaults()                  /* set default values for unassigned v
472                  vval(ZONE) = savqstr(buf);
473                  vdef(ZONE)++;
474          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
475          if (!vdef(INDIRECT)) {
476                  vval(INDIRECT) = "0";
477                  vdef(INDIRECT)++;
# Line 502 | 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 516 | Line 526 | oconv()                                /* run oconv if necessary */
526                  return;
527                                          /* build command */
528          oconvopts(ocopts);
529 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
530 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
531 <                        vval(SCENE), vval(OCTREE));
532 <        if (!silent) {                  /* echo it */
533 <                printf("\t%s\n", combuf);
534 <                fflush(stdout);
535 <        }
536 <        if (noaction)
527 <                return;
528 <        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));
# Line 557 | Line 565 | register char  *oo;
565   }
566  
567  
568 + checkambfile()                  /* check date on ambient file */
569 + {
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))
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 <                else
590 <                        return(.5/atof(vval(EXPOSURE)));
589 >                return(.5/atof(vval(EXPOSURE)));
590 >        }
591          if (vlet(ZONE) == 'E')
592                  return(10.);
593 <        else
593 >        if (vlet(ZONE) == 'I')
594                  return(.01);
595 +        badvalue(ZONE);
596   }
597  
598  
# Line 579 | Line 603 | register char  *op;
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 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
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");
593 <                op = addarg(op, "-dp 16");
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");
599 <                op = addarg(op, "-dp 32");
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");
605 <                op = addarg(op, "-dp 64");
623 >                op = addarg(op, "-ps 4 -dp 64");
624                  sprintf(op, " -ar %d", (int)(16*d));
625                  op += strlen(op);
626                  break;
# Line 610 | Line 628 | register char  *op;
628          op = addarg(op, "-pt .16");
629          if (vbool(PENUMBRAS))
630                  op = addarg(op, "-ds .4");
631 <        op = addarg(op, "-dt .2");
632 <        op = addarg(op, "-dc .25");
633 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
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);
# Line 623 | Line 638 | register char  *op;
638                  overture = 0;
639          switch (vscale(VARIABILITY)) {
640          case LOW:
641 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
641 >                op = addarg(op, "-aa .4 -ad 64");
642                  break;
643          case MEDIUM:
644 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
644 >                op = addarg(op, "-aa .3 -ad 128");
645                  break;
646          case HIGH:
647 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
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");
643 <        op = addarg(op, "-lw .02");
654 >        op = addarg(op, "-lr 3 -lw .02");
655          if (vdef(RENDER))
656                  op = addarg(op, vval(RENDER));
657   }
# Line 653 | Line 664 | register char  *op;
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 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
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]);
# Line 682 | Line 690 | register char  *op;
690                  break;
691          }
692          op = addarg(op, "-pt .08");
693 <        if (vbool(PENUMBRAS)) {
694 <                op = addarg(op, "-ds .2");
695 <                op = addarg(op, "-dj .35");
688 <        } else
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");
698 <        op = addarg(op, "-dc .5");
699 <        op = addarg(op, "-dr 1");
700 <        op = addarg(op, "-sj .7");
701 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
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);
# Line 701 | Line 706 | register char  *op;
706                  overture = 0;
707          switch (vscale(VARIABILITY)) {
708          case LOW:
709 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
709 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
710                  break;
711          case MEDIUM:
712 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
712 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
713                  break;
714          case HIGH:
715 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
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");
723 <        op = addarg(op, "-lw .002");
721 >        op = addarg(op, "-lr 6 -lw .002");
722          if (vdef(RENDER))
723                  op = addarg(op, vval(RENDER));
724   }
# Line 733 | Line 731 | register char  *op;
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 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
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]);
# Line 762 | Line 757 | register char  *op;
757                  break;
758          }
759          op = addarg(op, "-pt .04");
760 <        if (vbool(PENUMBRAS)) {
761 <                op = addarg(op, "-ds .1");
762 <                op = addarg(op, "-dj .7");
768 <        } else
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");
771 <        op = addarg(op, "-dc .75");
772 <        op = addarg(op, "-dr 3");
773 <        op = addarg(op, "-sj 1");
774 <        op = addarg(op, "-st .03");
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)) {
# Line 781 | Line 771 | register char  *op;
771                  overture = 0;
772          switch (vscale(VARIABILITY)) {
773          case LOW:
774 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
774 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
775                  break;
776          case MEDIUM:
777 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
777 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
778                  break;
779          case HIGH:
780 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
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");
803 <        op = addarg(op, "-lw .0005");
786 >        op = addarg(op, "-lr 12 -lw .0005");
787          if (vdef(RENDER))
788                  op = addarg(op, vval(RENDER));
789   }
# Line 810 | 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);
828 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                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);
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 <                }
815 >                setenv("ROPT", ro+1);
816                  strcpy(ro, " $ROPT");
817          }
818   #endif
# Line 857 | 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 880 | 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;
893        viewtype = 0;
882          if (*vs == 'X') {
883                  xpos = 1; vs++;
884          } else if (*vs == 'x') {
# Line 906 | 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++;
911        else if (!*vs || isspace(*vs))
912                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]; 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 ;
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 */
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");
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 969 | 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 982 | 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 999 | 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 */
1028 <                printf("\t%s\n", combuf);
1029 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        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 1041 | Line 1082 | rpict(opts)                            /* run rpict and pfilt for each view */
1082   char    *opts;
1083   {
1084          char    combuf[1024];
1085 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1086 <        char    pfopts[64];
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 1060 | 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",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1105 >                } else
1106 >                        badvalue(RESOLUTION);
1107          }
1108          rep[0] = '\0';
1109          if (vdef(REPORT)) {
# Line 1075 | 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",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
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 1100 | 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) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                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);
1112 <                                        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 */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                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 1133 | Line 1167 | char   *opts;
1167                  else
1168                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1169                                          rawfile, picfile);
1170 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                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 1145 | 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