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.14 by greg, Thu Jul 15 18:32:57 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 */
# Line 157 | Line 167 | char   *argv[];
167                                  /* print all values if requested */
168          if (explicate)
169                  printvals();
170 <                                /* run simulation */
170 >                                /* build octree */
171          oconv();
172 +                                /* check date on ambient file */
173 +        checkambfile();
174 +                                /* run simulation */
175          renderopts(ropts);
176          xferopts(ropts);
177          if (rvdevice != NULL)
# Line 168 | Line 181 | char   *argv[];
181          exit(0);
182   userr:
183          fprintf(stderr,
184 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
184 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
185                          progname);
186          exit(1);
187   }
# Line 193 | Line 206 | load(rfname)                   /* load Radiance simulation file */
206   char    *rfname;
207   {
208          FILE    *fp;
209 <        char    buf[256];
209 >        char    buf[512];
210          register char   *cp;
211  
212          if (rfname == NULL)
213                  fp = stdin;
214 <        else if ((fp = fopen(rfname, "r")) == NULL) {
215 <                perror(rfname);
203 <                exit(1);
204 <        }
214 >        else if ((fp = fopen(rfname, "r")) == NULL)
215 >                syserr(rfname);
216          while (fgetline(buf, sizeof(buf), fp) != NULL) {
217                  for (cp = buf; *cp; cp++) {
218                          switch (*cp) {
# Line 212 | Line 223 | char   *rfname;
223                          case '#':
224                                  *cp = '\0';
225                                  break;
226 +                        default:
227 +                                continue;
228                          }
229                          break;
230                  }
# Line 260 | Line 273 | register char  *ass;
273                  exit(1);
274          }
275                                          /* assign new value */
276 <        cp = vp->value; i = vp->nass;
277 <        while (i--)
278 <                while (*cp++)
279 <                        ;
280 <        i = cp - vp->value;
281 <        vp->value = realloc(vp->value, i+n+1);
282 <        if (vp->value == NULL) {
283 <                perror(progname);
284 <                exit(1);
285 <        }
276 >        if (i = vp->nass) {
277 >                cp = vp->value;
278 >                while (i--)
279 >                        while (*cp++)
280 >                                ;
281 >                i = cp - vp->value;
282 >                vp->value = realloc(vp->value, i+n+1);
283 >        } else
284 >                vp->value = malloc(n+1);
285 >        if (vp->value == NULL)
286 >                syserr(progname);
287          strcpy(vp->value+i, ass);
288          vp->nass++;
289   }
# Line 318 | Line 332 | int    vc;
332          case 'L':
333                  return(LOW);
334          }
335 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
335 >        badvalue(vc);
336   }
337  
338  
# Line 373 | Line 385 | register char  *fnames;
385          while (*fnames) {
386                  while (isspace(*fnames)) fnames++;
387                  cp = thisfile;
388 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
388 >                while (*fnames && !isspace(*fnames))
389 >                        *cp++ = *fnames++;
390                  *cp = '\0';
391 <                if ((thisdate = fdate(thisfile)) < 0) {
392 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
391 >                if ((thisdate = fdate(thisfile)) < 0)
392 >                        syserr(thisfile);
393                  if (thisdate > lastdate)
394                          lastdate = thisdate;
395          }
# Line 392 | Line 403 | checkfiles()                   /* check for existence and modified tim
403          long    objdate;
404  
405          if (!vdef(OCTREE)) {
406 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
407 <                        perror(progname);
397 <                        exit(1);
398 <                }
406 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
407 >                        syserr(progname);
408                  sprintf(cp, "%s.oct", radname);
409                  vval(OCTREE) = cp;
410                  vdef(OCTREE)++;
# Line 415 | Line 424 | checkfiles()                   /* check for existence and modified tim
424                                  vnam(OCTREE), vnam(SCENE));
425                  exit(1);
426          }
427 +        matdate = -1;
428 +        if (vdef(MATERIAL))
429 +                matdate = checklast(vval(MATERIAL));
430   }      
431  
432  
# Line 429 | Line 441 | double org[3], *sizp;
441          if (osiz <= FTINY) {
442                  oconv();                /* does nothing if done already */
443                  sprintf(buf, "getinfo -d < %s", vval(OCTREE));
444 <                if ((fp = popen(buf, "r")) == NULL) {
445 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
444 >                if ((fp = popen(buf, "r")) == NULL)
445 >                        syserr("getinfo");
446                  if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
447                                  &oorg[2], &osiz) != 4) {
448                          fprintf(stderr,
# Line 458 | Line 468 | setdefaults()                  /* set default values for unassigned v
468                  vval(ZONE) = savqstr(buf);
469                  vdef(ZONE)++;
470          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
471          if (!vdef(INDIRECT)) {
472                  vval(INDIRECT) = "0";
473                  vdef(INDIRECT)++;
# Line 502 | Line 508 | printvals()                    /* print variable values */
508          register int    i, j;
509  
510          for (i = 0; i < NVARS; i++)
511 <                for (j = 0; j < vv[i].nass; j++)
512 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
511 >                for (j = 0; j < vdef(i); j++)
512 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
513          fflush(stdout);
514   }
515  
# Line 516 | Line 522 | oconv()                                /* run oconv if necessary */
522                  return;
523                                          /* build command */
524          oconvopts(ocopts);
525 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
526 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
527 <                        vval(SCENE), vval(OCTREE));
528 <        if (!silent) {                  /* echo it */
529 <                printf("\t%s\n", combuf);
530 <                fflush(stdout);
531 <        }
532 <        if (noaction)
527 <                return;
528 <        if (system(combuf)) {           /* run it */
525 >        if (vdef(MATERIAL))
526 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
527 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
528 >        else
529 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
530 >                                vval(SCENE), vval(OCTREE));
531 >        
532 >        if (runcom(combuf)) {           /* run it */
533                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
534                                  progname, vval(OCTREE));
535                  unlink(vval(OCTREE));
# Line 557 | Line 561 | register char  *oo;
561   }
562  
563  
564 + checkambfile()                  /* check date on ambient file */
565 + {
566 +        long    afdate;
567 +
568 +        if (!vdef(AMBFILE))
569 +                return;
570 +        if ((afdate = fdate(vval(AMBFILE))) < 0)
571 +                return;
572 +        if (octreedate > afdate | matdate > afdate)
573 +                rmfile(vval(AMBFILE));
574 + }
575 +
576 +
577   double
578   ambval()                                /* compute ambient value */
579   {
580 <        if (vdef(EXPOSURE))
580 >        if (vdef(EXPOSURE)) {
581                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
582                          return(.5/pow(2.,atof(vval(EXPOSURE))));
583 <                else
583 >                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
584                          return(.5/atof(vval(EXPOSURE)));
585 +                badvalue(EXPOSURE);
586 +        }
587          if (vlet(ZONE) == 'E')
588                  return(10.);
589 <        else
589 >        if (vlet(ZONE) == 'I')
590                  return(.01);
591 +        badvalue(ZONE);
592   }
593  
594  
# Line 579 | Line 599 | register char  *op;
599  
600          *op = '\0';
601          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
602 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
603 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
602 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
603 >                badvalue(ZONE);
604          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
605          getoctcube(org, &d);
606          d *= 3./(siz[0]+siz[1]+siz[2]);
607          switch (vscale(DETAIL)) {
608          case LOW:
609 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
609 >                op = addarg(op, "-ps 16 -dp 16");
610                  sprintf(op, " -ar %d", (int)(4*d));
611                  op += strlen(op);
612                  break;
613          case MEDIUM:
614 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
614 >                op = addarg(op, "-ps 8 -dp 32");
615                  sprintf(op, " -ar %d", (int)(8*d));
616                  op += strlen(op);
617                  break;
618          case HIGH:
619 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
619 >                op = addarg(op, "-ps 4 -dp 64");
620                  sprintf(op, " -ar %d", (int)(16*d));
621                  op += strlen(op);
622                  break;
# Line 610 | Line 624 | register char  *op;
624          op = addarg(op, "-pt .16");
625          if (vbool(PENUMBRAS))
626                  op = addarg(op, "-ds .4");
627 <        op = addarg(op, "-dt .2");
628 <        op = addarg(op, "-dc .25");
629 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
627 >        else
628 >                op = addarg(op, "-ds 0");
629 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
630          if (vdef(AMBFILE)) {
631                  sprintf(op, " -af %s", vval(AMBFILE));
632                  op += strlen(op);
# Line 623 | Line 634 | register char  *op;
634                  overture = 0;
635          switch (vscale(VARIABILITY)) {
636          case LOW:
637 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
637 >                op = addarg(op, "-aa .4 -ad 32");
638                  break;
639          case MEDIUM:
640 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
640 >                op = addarg(op, "-aa .3 -ad 64");
641                  break;
642          case HIGH:
643 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
643 >                op = addarg(op, "-aa .25 -ad 128");
644                  break;
645          }
646          op = addarg(op, "-as 0");
647          d = ambval();
648          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
649          op += strlen(op);
650 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
650 >        op = addarg(op, "-lr 3 -lw .02");
651          if (vdef(RENDER))
652                  op = addarg(op, vval(RENDER));
653   }
# Line 653 | Line 660 | register char  *op;
660  
661          *op = '\0';
662          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
663 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
664 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
663 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
664 >                badvalue(ZONE);
665          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
666          getoctcube(org, &d);
667          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 682 | Line 686 | register char  *op;
686                  break;
687          }
688          op = addarg(op, "-pt .08");
689 <        if (vbool(PENUMBRAS)) {
690 <                op = addarg(op, "-ds .2");
691 <                op = addarg(op, "-dj .35");
688 <        } else
689 >        if (vbool(PENUMBRAS))
690 >                op = addarg(op, "-ds .2 -dj .35");
691 >        else
692                  op = addarg(op, "-ds .3");
693 <        op = addarg(op, "-dt .1");
694 <        op = addarg(op, "-dc .5");
695 <        op = addarg(op, "-dr 1");
696 <        op = addarg(op, "-sj .7");
697 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
693 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
694 >        if (overture = vint(INDIRECT)) {
695 >                sprintf(op, " -ab %d", overture);
696 >                op += strlen(op);
697 >        }
698          if (vdef(AMBFILE)) {
699                  sprintf(op, " -af %s", vval(AMBFILE));
700                  op += strlen(op);
# Line 701 | Line 702 | register char  *op;
702                  overture = 0;
703          switch (vscale(VARIABILITY)) {
704          case LOW:
705 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
705 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
706                  break;
707          case MEDIUM:
708 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
708 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
709                  break;
710          case HIGH:
711 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
711 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
712                  break;
713          }
714          d = ambval();
715          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
716          op += strlen(op);
717 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
717 >        op = addarg(op, "-lr 6 -lw .002");
718          if (vdef(RENDER))
719                  op = addarg(op, vval(RENDER));
720   }
# Line 733 | Line 727 | register char  *op;
727  
728          *op = '\0';
729          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
730 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
731 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
730 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
731 >                badvalue(ZONE);
732          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
733          getoctcube(org, &d);
734          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 762 | Line 753 | register char  *op;
753                  break;
754          }
755          op = addarg(op, "-pt .04");
756 <        if (vbool(PENUMBRAS)) {
757 <                op = addarg(op, "-ds .1");
758 <                op = addarg(op, "-dj .7");
768 <        } else
756 >        if (vbool(PENUMBRAS))
757 >                op = addarg(op, "-ds .1 -dj .7");
758 >        else
759                  op = addarg(op, "-ds .2");
760 <        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");
760 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
761          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
762          op += strlen(op);
763          if (vdef(AMBFILE)) {
# Line 781 | Line 767 | register char  *op;
767                  overture = 0;
768          switch (vscale(VARIABILITY)) {
769          case LOW:
770 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
770 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
771                  break;
772          case MEDIUM:
773 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
773 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
774                  break;
775          case HIGH:
776 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
776 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
777                  break;
778          }
779          d = ambval();
780          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
781          op += strlen(op);
782 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
782 >        op = addarg(op, "-lr 12 -lw .0005");
783          if (vdef(RENDER))
784                  op = addarg(op, vval(RENDER));
785   }
# Line 810 | Line 789 | xferopts(ro)                           /* transfer options if indicated */
789   char    *ro;
790   {
791          int     fd, n;
792 +        register char   *cp;
793          
794          n = strlen(ro);
795          if (n < 2)
796                  return;
797          if (vdef(OPTFILE)) {
798 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
799 <                        perror(vval(OPTFILE));
800 <                        exit(1);
801 <                }
802 <                if (write(fd, ro+1, n-1) != n-1) {
803 <                        perror(vval(OPTFILE));
804 <                        exit(1);
805 <                }
806 <                write(fd, "\n", 1);
807 <                close(fd);
828 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
798 >                for (cp = ro; cp[1]; cp++)
799 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
800 >                                *cp = '\n';
801 >                        else
802 >                                *cp = cp[1];
803 >                *cp = '\n';
804 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
805 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
806 >                        syserr(vval(OPTFILE));
807 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
808          }
809   #ifdef MSDOS
810          else if (n > 50) {
811 <                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 <                }
811 >                setenv("ROPT", ro+1);
812                  strcpy(ro, " $ROPT");
813          }
814   #endif
# Line 857 | Line 823 | register char  *po;
823                  po = addarg(po, "-1 -e");
824                  po = addarg(po, vval(EXPOSURE));
825          }
826 <        if (vscale(QUALITY) == HIGH)
827 <                po = addarg(po, "-r .65");
826 >        switch (vscale(QUALITY)) {
827 >        case MEDIUM:
828 >                po = addarg(po, "-r 1");
829 >                break;
830 >        case HIGH:
831 >                po = addarg(po, "-m .25");
832 >                break;
833 >        }
834          if (vdef(PFILT))
835                  po = addarg(po, vval(PFILT));
836   }
# Line 880 | Line 852 | char *
852   specview(vs)                            /* get proper view spec from vs */
853   register char   *vs;
854   {
855 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
856 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
857          static char     viewopts[128];
858          register char   *cp;
859 <        int     xpos, ypos, zpos, viewtype;
860 <        int     exterior;
859 >        int     xpos, ypos, zpos, viewtype, upax;
860 >        register int    i;
861          double  cent[3], dim[3], mult, d;
862  
863          if (vs == NULL || *vs == '-')
864                  return(vs);
865 +        upax = 0;                       /* get the up vector */
866 +        if (vdef(UP)) {
867 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
868 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
869 +                else
870 +                        upax = 1-'X'+vlet(UP);
871 +                if (upax < 1 | upax > 3)
872 +                        badvalue(UP);
873 +                if (vval(UP)[0] == '-')
874 +                        upax = -upax;
875 +        }
876                                          /* check standard view names */
877          xpos = ypos = zpos = 0;
893        viewtype = 0;
878          if (*vs == 'X') {
879                  xpos = 1; vs++;
880          } else if (*vs == 'x') {
# Line 906 | Line 890 | register char  *vs;
890          } else if (*vs == 'z') {
891                  zpos = -1; vs++;
892          }
893 +        viewtype = 'v';
894          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
895                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
896          cp = viewopts;
897 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
897 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
898                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
899                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
900                                  &cent[0], &dim[0], &cent[1], &dim[1],
901 <                                &cent[2], &dim[2]) != 6) {
902 <                        fprintf(stderr, "%s: bad zone specification\n",
903 <                                        progname);
904 <                        exit(1);
901 >                                &cent[2], &dim[2]) != 6)
902 >                        badvalue(ZONE);
903 >                for (i = 0; i < 3; i++) {
904 >                        dim[i] -= cent[i];
905 >                        cent[i] += .5*dim[i];
906                  }
907 <                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 ;
907 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
908                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
909                                  cent[0]+xpos*mult*dim[0],
910                                  cent[1]+ypos*mult*dim[1],
911                                  cent[2]+zpos*mult*dim[2],
912                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
913                  cp += strlen(cp);
914 <                switch (vlet(UP)) {
915 <                case 'Z':
916 <                        if (xpos|ypos) {
917 <                                cp = addarg(cp, "-vu 0 0 1");
918 <                                break;
919 <                        }
920 <                /* 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");
914 >                                        /* redirect up axis if necessary */
915 >                switch (upax) {
916 >                case 3:                 /* plus or minus Z axis */
917 >                case -3:
918 >                case 0:
919 >                        if (!(xpos|ypos))
920 >                                upax = 2;
921                          break;
922 <                default:
923 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
924 <                                        progname, vnam(UP));
925 <                        exit(1);
922 >                case 2:                 /* plus or minus Y axis */
923 >                case -2:
924 >                        if (!(xpos|zpos))
925 >                                upax = 1;
926 >                        break;
927 >                case 1:                 /* plus or minus X axis */
928 >                case -1:
929 >                        if (!(ypos|zpos))
930 >                                upax = 3;
931 >                        break;
932                  }
933 +                cp = addarg(cp, vup[upax+3]);
934                  switch (viewtype) {
935                  case 'v':
936                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 945 | register char  *vs;
945                          cp = addarg(cp, "-vh 180 -vv 180");
946                          break;
947                  }
948 <        } else
949 <                while (*vs && !isspace(*vs))    /* else skip id */
950 <                        vs++;
951 <                                        /* append any additional options */
952 <        while (isspace(*vs)) vs++;
953 <        strcpy(cp, vs);
948 >        } else {
949 >                while (!isspace(*vs))           /* else skip id */
950 >                        if (!*vs++)
951 >                                return(NULL);
952 >                if (upax) {                     /* specify up vector */
953 >                        strcpy(cp, vup[upax+3]);
954 >                        cp += strlen(cp);
955 >                }
956 >        }
957 >        strcpy(cp, vs);                 /* append any additional options */
958 > #ifdef MSDOS
959 >        if (strlen(viewopts) > 40) {
960 >                setenv("VIEW", viewopts);
961 >                return("$VIEW");
962 >        }
963 > #endif
964          return(viewopts);
965   }
966  
# Line 982 | Line 968 | register char  *vs;
968   char *
969   getview(n, vn)                          /* get view n, or NULL if none */
970   int     n;
971 < char    *vn;
971 > char    *vn;            /* returned view name */
972   {
973 <        register char   *mv;
973 >        register char   *mv = NULL;
974  
975 <        if (viewselect != NULL) {
975 >        if (viewselect != NULL) {               /* command-line selected */
976                  if (n)                          /* only do one */
977                          return(NULL);
978                  if (viewselect[0] == '-') {     /* already specified */
# Line 1005 | Line 991 | char   *vn;
991                                  return(specview(mv));
992                  return(specview(viewselect));   /* standard view? */
993          }
994 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
994 >        mv = nvalue(vv+VIEW, n);                /* use view n */
995 >        if (vn != NULL & mv != NULL) {
996                  if (*mv != '-')
997                          while (*mv && !isspace(*mv))
998                                  *vn++ = *mv++;
999                  *vn = '\0';
1000          }
1001 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1001 >        return(specview(mv));
1002   }
1003  
1004  
# Line 1024 | Line 1011 | char   *opts;
1011          if (rvdevice != NULL)
1012                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1013          strcat(combuf, vval(OCTREE));
1014 <        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 */
1014 >        if (runcom(combuf)) {           /* run it */
1015                  fprintf(stderr, "%s: error running rview\n", progname);
1016                  exit(1);
1017          }
# Line 1041 | Line 1022 | rpict(opts)                            /* run rpict and pfilt for each view */
1022   char    *opts;
1023   {
1024          char    combuf[1024];
1025 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1026 <        char    pfopts[64];
1025 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1026 >        char    pfopts[128];
1027          char    vs[32], *vw;
1028          int     vn, mult;
1029 +        long    lastdate;
1030                                          /* get pfilt options */
1031          pfiltopts(pfopts);
1032                                          /* get resolution, reporting */
# Line 1060 | Line 1042 | char   *opts;
1042                  else if (n) {
1043                          if (n == 1) yres = xres;
1044                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1045 <                } else {
1046 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1045 >                } else
1046 >                        badvalue(RESOLUTION);
1047          }
1048          rep[0] = '\0';
1049          if (vdef(REPORT)) {
# Line 1075 | Line 1054 | char   *opts;
1054                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1055                  else if (n == 1)
1056                          sprintf(rep, " -t %d", (int)(minutes*60));
1057 <                else {
1058 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1057 >                else
1058 >                        badvalue(REPORT);
1059          }
1060 +                                        /* get update time */
1061 +        lastdate = octreedate > matdate ? octreedate : matdate;
1062                                          /* do each view */
1063          vn = 0;
1064          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1088 | Line 1066 | char   *opts;
1066                          sprintf(vs, "%d", vn);
1067                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1068                                                  /* check date on picture */
1069 <                if (fdate(picfile) > octreedate)
1069 >                if (fdate(picfile) >= lastdate)
1070                          continue;
1071                                                  /* build rpict command */
1072                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1073 <                if (fdate(rawfile) > octreedate)        /* recover */
1073 >                if (fdate(rawfile) >= octreedate)       /* recover */
1074                          sprintf(combuf, "rpict%s%s -ro %s %s",
1075                                          rep, opts, rawfile, vval(OCTREE));
1076                  else {
# Line 1100 | Line 1078 | char   *opts;
1078                                  sprintf(combuf,
1079                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1080                                                  rep, vw, opts,
1081 <                                                vval(OCTREE), rawfile);
1082 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1081 >                                                vval(OCTREE), overfile);
1082 >                                if (runcom(combuf)) {
1083                                          fprintf(stderr,
1084 <                        "%s: error in overture for view %s\n\t%s removed\n",
1085 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1084 >                                        "%s: error in overture for view %s\n",
1085 >                                                progname, vs);
1086                                          exit(1);
1087                                  }
1088 + #ifdef NIX
1089 +                                rmfile(overfile);
1090 + #endif
1091                          }
1092                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1093                                          rep, vw, res, opts,
1094                                          vval(OCTREE), rawfile);
1095                  }
1096 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1096 >                if (runcom(combuf)) {           /* run rpict */
1097                          fprintf(stderr, "%s: error rendering view %s\n",
1098                                          progname, vs);
1099                          exit(1);
# Line 1133 | Line 1105 | char   *opts;
1105                  else
1106                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1107                                          rawfile, picfile);
1108 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1108 >                if (runcom(combuf)) {           /* run pfilt */
1109                          fprintf(stderr,
1110                          "%s: error filtering view %s\n\t%s removed\n",
1111                                          progname, vs, picfile);
# Line 1145 | Line 1113 | char   *opts;
1113                          exit(1);
1114                  }
1115                                                  /* remove raw file */
1116 <                if (!silent)
1116 >                rmfile(rawfile);
1117 >        }
1118 > }
1119 >
1120 >
1121 > runcom(cs)                      /* run command */
1122 > char    *cs;
1123 > {
1124 >        if (!silent)            /* echo it */
1125 >                printf("\t%s\n", cs);
1126 >        if (noaction)
1127 >                return(0);
1128 >        fflush(stdout);         /* flush output and pass to shell */
1129 >        return(system(cs));
1130 > }
1131 >
1132 >
1133 > rmfile(fn)                      /* remove a file */
1134 > char    *fn;
1135 > {
1136 >        if (!silent)
1137   #ifdef MSDOS
1138 <                        printf("\tdel %s\n", rawfile);
1138 >                printf("\tdel %s\n", fn);
1139   #else
1140 <                        printf("\trm %s\n", rawfile);
1140 >                printf("\trm -f %s\n", fn);
1141   #endif
1142 <                if (!noaction)
1143 <                        unlink(rawfile);
1142 >        if (noaction)
1143 >                return(0);
1144 >        return(unlink(fn));
1145 > }
1146 >
1147 >
1148 > #ifdef MSDOS
1149 > setenv(vname, value)            /* set an environment variable */
1150 > char    *vname, *value;
1151 > {
1152 >        register char   *evp;
1153 >
1154 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1155 >        if (evp == NULL)
1156 >                syserr(progname);
1157 >        sprintf(evp, "%s=%s", vname, value);
1158 >        if (putenv(evp) != 0) {
1159 >                fprintf(stderr, "%s: out of environment space\n", progname);
1160 >                exit(1);
1161          }
1162 +        if (!silent)
1163 +                printf("set %s\n", evp);
1164 + }
1165 + #endif
1166 +
1167 +
1168 + badvalue(vc)                    /* report bad variable value and exit */
1169 + int     vc;
1170 + {
1171 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1172 +                        progname, vnam(vc));
1173 +        exit(1);
1174 + }
1175 +
1176 +
1177 + syserr(s)                       /* report a system error and exit */
1178 + char    *s;
1179 + {
1180 +        perror(s);
1181 +        exit(1);
1182   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines