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.7 by greg, Tue Apr 6 17:21:04 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 */
# Line 157 | Line 166 | char   *argv[];
166                                  /* print all values if requested */
167          if (explicate)
168                  printvals();
169 <                                /* run simulation */
169 >                                /* build octree */
170          oconv();
171 +                                /* check date on ambient file */
172 +        checkambfile();
173 +                                /* run simulation */
174          renderopts(ropts);
175          xferopts(ropts);
176          if (rvdevice != NULL)
# Line 168 | Line 180 | char   *argv[];
180          exit(0);
181   userr:
182          fprintf(stderr,
183 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
183 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
184                          progname);
185          exit(1);
186   }
# Line 193 | Line 205 | load(rfname)                   /* load Radiance simulation file */
205   char    *rfname;
206   {
207          FILE    *fp;
208 <        char    buf[256];
208 >        char    buf[512];
209          register char   *cp;
210  
211          if (rfname == NULL)
212                  fp = stdin;
213 <        else if ((fp = fopen(rfname, "r")) == NULL) {
214 <                perror(rfname);
203 <                exit(1);
204 <        }
213 >        else if ((fp = fopen(rfname, "r")) == NULL)
214 >                syserr(rfname);
215          while (fgetline(buf, sizeof(buf), fp) != NULL) {
216                  for (cp = buf; *cp; cp++) {
217                          switch (*cp) {
# Line 212 | Line 222 | char   *rfname;
222                          case '#':
223                                  *cp = '\0';
224                                  break;
225 +                        default:
226 +                                continue;
227                          }
228                          break;
229                  }
# Line 260 | Line 272 | register char  *ass;
272                  exit(1);
273          }
274                                          /* assign new value */
275 <        cp = vp->value; i = vp->nass;
276 <        while (i--)
277 <                while (*cp++)
278 <                        ;
279 <        i = cp - vp->value;
280 <        vp->value = realloc(vp->value, i+n+1);
281 <        if (vp->value == NULL) {
282 <                perror(progname);
283 <                exit(1);
284 <        }
275 >        if (i = vp->nass) {
276 >                cp = vp->value;
277 >                while (i--)
278 >                        while (*cp++)
279 >                                ;
280 >                i = cp - vp->value;
281 >                vp->value = realloc(vp->value, i+n+1);
282 >        } else
283 >                vp->value = malloc(n+1);
284 >        if (vp->value == NULL)
285 >                syserr(progname);
286          strcpy(vp->value+i, ass);
287          vp->nass++;
288   }
# Line 318 | Line 331 | int    vc;
331          case 'L':
332                  return(LOW);
333          }
334 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
334 >        badvalue(vc);
335   }
336  
337  
# Line 373 | Line 384 | register char  *fnames;
384          while (*fnames) {
385                  while (isspace(*fnames)) fnames++;
386                  cp = thisfile;
387 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
387 >                while (*fnames && !isspace(*fnames))
388 >                        *cp++ = *fnames++;
389                  *cp = '\0';
390 <                if ((thisdate = fdate(thisfile)) < 0) {
391 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
390 >                if ((thisdate = fdate(thisfile)) < 0)
391 >                        syserr(thisfile);
392                  if (thisdate > lastdate)
393                          lastdate = thisdate;
394          }
# Line 392 | Line 402 | checkfiles()                   /* check for existence and modified tim
402          long    objdate;
403  
404          if (!vdef(OCTREE)) {
405 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
406 <                        perror(progname);
397 <                        exit(1);
398 <                }
405 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
406 >                        syserr(progname);
407                  sprintf(cp, "%s.oct", radname);
408                  vval(OCTREE) = cp;
409                  vdef(OCTREE)++;
# Line 429 | Line 437 | double org[3], *sizp;
437          if (osiz <= FTINY) {
438                  oconv();                /* does nothing if done already */
439                  sprintf(buf, "getinfo -d < %s", vval(OCTREE));
440 <                if ((fp = popen(buf, "r")) == NULL) {
441 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
440 >                if ((fp = popen(buf, "r")) == NULL)
441 >                        syserr("getinfo");
442                  if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
443                                  &oorg[2], &osiz) != 4) {
444                          fprintf(stderr,
# Line 458 | Line 464 | setdefaults()                  /* set default values for unassigned v
464                  vval(ZONE) = savqstr(buf);
465                  vdef(ZONE)++;
466          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
467          if (!vdef(INDIRECT)) {
468                  vval(INDIRECT) = "0";
469                  vdef(INDIRECT)++;
# Line 502 | Line 504 | printvals()                    /* print variable values */
504          register int    i, j;
505  
506          for (i = 0; i < NVARS; i++)
507 <                for (j = 0; j < vv[i].nass; j++)
508 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
507 >                for (j = 0; j < vdef(i); j++)
508 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
509          fflush(stdout);
510   }
511  
# Line 516 | Line 518 | oconv()                                /* run oconv if necessary */
518                  return;
519                                          /* build command */
520          oconvopts(ocopts);
521 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
522 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
523 <                        vval(SCENE), vval(OCTREE));
524 <        if (!silent) {                  /* echo it */
525 <                printf("\t%s\n", combuf);
526 <                fflush(stdout);
527 <        }
528 <        if (noaction)
527 <                return;
528 <        if (system(combuf)) {           /* run it */
521 >        if (vdef(MATERIAL))
522 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
523 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
524 >        else
525 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
526 >                                vval(SCENE), vval(OCTREE));
527 >        
528 >        if (runcom(combuf)) {           /* run it */
529                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
530                                  progname, vval(OCTREE));
531                  unlink(vval(OCTREE));
# Line 557 | Line 557 | register char  *oo;
557   }
558  
559  
560 + checkambfile()                  /* check date on ambient file */
561 + {
562 +        long    afdate;
563 +
564 +        if (vdef(AMBFILE)) {
565 +                afdate = fdate(vval(AMBFILE));
566 +                if (afdate >= 0 & octreedate > afdate)
567 +                        rmfile(vval(AMBFILE));
568 +        }
569 + }
570 +
571 +
572   double
573   ambval()                                /* compute ambient value */
574   {
575 <        if (vdef(EXPOSURE))
575 >        if (vdef(EXPOSURE)) {
576                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
577                          return(.5/pow(2.,atof(vval(EXPOSURE))));
578 <                else
578 >                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
579                          return(.5/atof(vval(EXPOSURE)));
580 +                badvalue(EXPOSURE);
581 +        }
582          if (vlet(ZONE) == 'E')
583                  return(10.);
584 <        else
584 >        if (vlet(ZONE) == 'I')
585                  return(.01);
586 +        badvalue(ZONE);
587   }
588  
589  
# Line 579 | Line 594 | register char  *op;
594  
595          *op = '\0';
596          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
597 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
598 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
597 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
598 >                badvalue(ZONE);
599          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
600          getoctcube(org, &d);
601          d *= 3./(siz[0]+siz[1]+siz[2]);
602          switch (vscale(DETAIL)) {
603          case LOW:
604 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
604 >                op = addarg(op, "-ps 16 -dp 16");
605                  sprintf(op, " -ar %d", (int)(4*d));
606                  op += strlen(op);
607                  break;
608          case MEDIUM:
609 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
609 >                op = addarg(op, "-ps 8 -dp 32");
610                  sprintf(op, " -ar %d", (int)(8*d));
611                  op += strlen(op);
612                  break;
613          case HIGH:
614 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
614 >                op = addarg(op, "-ps 4 -dp 64");
615                  sprintf(op, " -ar %d", (int)(16*d));
616                  op += strlen(op);
617                  break;
# Line 610 | Line 619 | register char  *op;
619          op = addarg(op, "-pt .16");
620          if (vbool(PENUMBRAS))
621                  op = addarg(op, "-ds .4");
622 <        op = addarg(op, "-dt .2");
623 <        op = addarg(op, "-dc .25");
624 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
622 >        else
623 >                op = addarg(op, "-ds 0");
624 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
625          if (vdef(AMBFILE)) {
626                  sprintf(op, " -af %s", vval(AMBFILE));
627                  op += strlen(op);
# Line 623 | Line 629 | register char  *op;
629                  overture = 0;
630          switch (vscale(VARIABILITY)) {
631          case LOW:
632 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
632 >                op = addarg(op, "-aa .4 -ad 32");
633                  break;
634          case MEDIUM:
635 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
635 >                op = addarg(op, "-aa .3 -ad 64");
636                  break;
637          case HIGH:
638 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
638 >                op = addarg(op, "-aa .25 -ad 128");
639                  break;
640          }
641          op = addarg(op, "-as 0");
642          d = ambval();
643          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
644          op += strlen(op);
645 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
645 >        op = addarg(op, "-lr 3 -lw .02");
646          if (vdef(RENDER))
647                  op = addarg(op, vval(RENDER));
648   }
# Line 653 | Line 655 | register char  *op;
655  
656          *op = '\0';
657          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
658 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
659 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
658 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
659 >                badvalue(ZONE);
660          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
661          getoctcube(org, &d);
662          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 682 | Line 681 | register char  *op;
681                  break;
682          }
683          op = addarg(op, "-pt .08");
684 <        if (vbool(PENUMBRAS)) {
685 <                op = addarg(op, "-ds .2");
686 <                op = addarg(op, "-dj .35");
688 <        } else
684 >        if (vbool(PENUMBRAS))
685 >                op = addarg(op, "-ds .2 -dj .35");
686 >        else
687                  op = addarg(op, "-ds .3");
688 <        op = addarg(op, "-dt .1");
689 <        op = addarg(op, "-dc .5");
690 <        op = addarg(op, "-dr 1");
691 <        op = addarg(op, "-sj .7");
692 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
688 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
689 >        if (overture = vint(INDIRECT)) {
690 >                sprintf(op, " -ab %d", overture);
691 >                op += strlen(op);
692 >        }
693          if (vdef(AMBFILE)) {
694                  sprintf(op, " -af %s", vval(AMBFILE));
695                  op += strlen(op);
# Line 701 | Line 697 | register char  *op;
697                  overture = 0;
698          switch (vscale(VARIABILITY)) {
699          case LOW:
700 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
700 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
701                  break;
702          case MEDIUM:
703 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
703 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
704                  break;
705          case HIGH:
706 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
706 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
707                  break;
708          }
709          d = ambval();
710          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
711          op += strlen(op);
712 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
712 >        op = addarg(op, "-lr 6 -lw .002");
713          if (vdef(RENDER))
714                  op = addarg(op, vval(RENDER));
715   }
# Line 733 | Line 722 | register char  *op;
722  
723          *op = '\0';
724          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
725 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
726 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
725 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
726 >                badvalue(ZONE);
727          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
728          getoctcube(org, &d);
729          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 762 | Line 748 | register char  *op;
748                  break;
749          }
750          op = addarg(op, "-pt .04");
751 <        if (vbool(PENUMBRAS)) {
752 <                op = addarg(op, "-ds .1");
753 <                op = addarg(op, "-dj .7");
768 <        } else
751 >        if (vbool(PENUMBRAS))
752 >                op = addarg(op, "-ds .1 -dj .7");
753 >        else
754                  op = addarg(op, "-ds .2");
755 <        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");
755 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
756          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
757          op += strlen(op);
758          if (vdef(AMBFILE)) {
# Line 781 | Line 762 | register char  *op;
762                  overture = 0;
763          switch (vscale(VARIABILITY)) {
764          case LOW:
765 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
765 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
766                  break;
767          case MEDIUM:
768 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
768 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
769                  break;
770          case HIGH:
771 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
771 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
772                  break;
773          }
774          d = ambval();
775          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
776          op += strlen(op);
777 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
777 >        op = addarg(op, "-lr 12 -lw .0005");
778          if (vdef(RENDER))
779                  op = addarg(op, vval(RENDER));
780   }
# Line 815 | Line 789 | char   *ro;
789          if (n < 2)
790                  return;
791          if (vdef(OPTFILE)) {
792 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
793 <                        perror(vval(OPTFILE));
794 <                        exit(1);
795 <                }
822 <                if (write(fd, ro+1, n-1) != n-1) {
823 <                        perror(vval(OPTFILE));
824 <                        exit(1);
825 <                }
792 >                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
793 >                        syserr(vval(OPTFILE));
794 >                if (write(fd, ro+1, n-1) != n-1)
795 >                        syserr(vval(OPTFILE));
796                  write(fd, "\n", 1);
797                  close(fd);
798 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
798 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
799          }
800   #ifdef MSDOS
801          else if (n > 50) {
802                  register char   *evp = bmalloc(n+6);
803 <                if (evp == NULL) {
804 <                        perror(progname);
837 <                        exit(1);
838 <                }
803 >                if (evp == NULL)
804 >                        syserr(progname);
805                  strcpy(evp, "ROPT=");
806                  strcat(evp, ro);
807                  if (putenv(evp) != 0) {
# Line 880 | Line 846 | char *
846   specview(vs)                            /* get proper view spec from vs */
847   register char   *vs;
848   {
849 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
850 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
851          static char     viewopts[128];
852          register char   *cp;
853 <        int     xpos, ypos, zpos, viewtype;
854 <        int     exterior;
853 >        int     xpos, ypos, zpos, viewtype, upax;
854 >        register int    i;
855          double  cent[3], dim[3], mult, d;
856  
857          if (vs == NULL || *vs == '-')
858                  return(vs);
859 +        upax = 0;                       /* get the up vector */
860 +        if (vdef(UP)) {
861 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
862 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
863 +                else
864 +                        upax = 1-'X'+vlet(UP);
865 +                if (upax < 1 | upax > 3)
866 +                        badvalue(UP);
867 +                if (vval(UP)[0] == '-')
868 +                        upax = -upax;
869 +        }
870                                          /* check standard view names */
871          xpos = ypos = zpos = 0;
893        viewtype = 0;
872          if (*vs == 'X') {
873                  xpos = 1; vs++;
874          } else if (*vs == 'x') {
# Line 906 | Line 884 | register char  *vs;
884          } else if (*vs == 'z') {
885                  zpos = -1; vs++;
886          }
887 +        viewtype = 'v';
888          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
889                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
890          cp = viewopts;
891 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
891 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
892                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
893                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
894                                  &cent[0], &dim[0], &cent[1], &dim[1],
895 <                                &cent[2], &dim[2]) != 6) {
896 <                        fprintf(stderr, "%s: bad zone specification\n",
897 <                                        progname);
898 <                        exit(1);
895 >                                &cent[2], &dim[2]) != 6)
896 >                        badvalue(ZONE);
897 >                for (i = 0; i < 3; i++) {
898 >                        dim[i] -= cent[i];
899 >                        cent[i] += .5*dim[i];
900                  }
901 <                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 ;
901 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
902                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
903                                  cent[0]+xpos*mult*dim[0],
904                                  cent[1]+ypos*mult*dim[1],
905                                  cent[2]+zpos*mult*dim[2],
906                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
907                  cp += strlen(cp);
908 <                switch (vlet(UP)) {
909 <                case 'Z':
910 <                        if (xpos|ypos) {
911 <                                cp = addarg(cp, "-vu 0 0 1");
912 <                                break;
913 <                        }
914 <                /* 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");
908 >                                        /* redirect up axis if necessary */
909 >                switch (upax) {
910 >                case 3:                 /* plus or minus Z axis */
911 >                case -3:
912 >                case 0:
913 >                        if (!(xpos|ypos))
914 >                                upax = 2;
915                          break;
916 <                default:
917 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
918 <                                        progname, vnam(UP));
919 <                        exit(1);
916 >                case 2:                 /* plus or minus Y axis */
917 >                case -2:
918 >                        if (!(xpos|zpos))
919 >                                upax = 1;
920 >                        break;
921 >                case 1:                 /* plus or minus X axis */
922 >                case -1:
923 >                        if (!(ypos|zpos))
924 >                                upax = 3;
925 >                        break;
926                  }
927 +                cp = addarg(cp, vup[upax+3]);
928                  switch (viewtype) {
929                  case 'v':
930                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 939 | register char  *vs;
939                          cp = addarg(cp, "-vh 180 -vv 180");
940                          break;
941                  }
942 <        } else
943 <                while (*vs && !isspace(*vs))    /* else skip id */
944 <                        vs++;
942 >        } else {
943 >                while (!isspace(*vs))           /* else skip id */
944 >                        if (!*vs++)
945 >                                return(NULL);
946 >                if (upax) {                     /* specify up vector */
947 >                        strcpy(cp, vup[upax+3]);
948 >                        cp += strlen(cp);
949 >                }
950 >        }
951                                          /* append any additional options */
976        while (isspace(*vs)) vs++;
952          strcpy(cp, vs);
953          return(viewopts);
954   }
# Line 1024 | Line 999 | char   *opts;
999          if (rvdevice != NULL)
1000                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1001          strcat(combuf, vval(OCTREE));
1002 <        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 */
1002 >        if (runcom(combuf)) {           /* run it */
1003                  fprintf(stderr, "%s: error running rview\n", progname);
1004                  exit(1);
1005          }
# Line 1041 | Line 1010 | rpict(opts)                            /* run rpict and pfilt for each view */
1010   char    *opts;
1011   {
1012          char    combuf[1024];
1013 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1014 <        char    pfopts[64];
1013 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1014 >        char    pfopts[128];
1015          char    vs[32], *vw;
1016          int     vn, mult;
1017                                          /* get pfilt options */
# Line 1060 | Line 1029 | char   *opts;
1029                  else if (n) {
1030                          if (n == 1) yres = xres;
1031                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1032 <                } else {
1033 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1032 >                } else
1033 >                        badvalue(RESOLUTION);
1034          }
1035          rep[0] = '\0';
1036          if (vdef(REPORT)) {
# Line 1075 | Line 1041 | char   *opts;
1041                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1042                  else if (n == 1)
1043                          sprintf(rep, " -t %d", (int)(minutes*60));
1044 <                else {
1045 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1044 >                else
1045 >                        badvalue(REPORT);
1046          }
1047                                          /* do each view */
1048          vn = 0;
# Line 1100 | Line 1063 | char   *opts;
1063                                  sprintf(combuf,
1064                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1065                                                  rep, vw, opts,
1066 <                                                vval(OCTREE), rawfile);
1067 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1066 >                                                vval(OCTREE), overfile);
1067 >                                if (runcom(combuf)) {
1068                                          fprintf(stderr,
1069 <                        "%s: error in overture for view %s\n\t%s removed\n",
1070 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1069 >                                        "%s: error in overture for view %s\n",
1070 >                                                progname, vs);
1071                                          exit(1);
1072                                  }
1073 + #ifdef NIX
1074 +                                rmfile(overfile);
1075 + #endif
1076                          }
1077                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1078                                          rep, vw, res, opts,
1079                                          vval(OCTREE), rawfile);
1080                  }
1081 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1081 >                if (runcom(combuf)) {           /* run rpict */
1082                          fprintf(stderr, "%s: error rendering view %s\n",
1083                                          progname, vs);
1084                          exit(1);
# Line 1133 | Line 1090 | char   *opts;
1090                  else
1091                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1092                                          rawfile, picfile);
1093 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1093 >                if (runcom(combuf)) {           /* run pfilt */
1094                          fprintf(stderr,
1095                          "%s: error filtering view %s\n\t%s removed\n",
1096                                          progname, vs, picfile);
# Line 1145 | Line 1098 | char   *opts;
1098                          exit(1);
1099                  }
1100                                                  /* remove raw file */
1101 <                if (!silent)
1101 >                rmfile(rawfile);
1102 >        }
1103 > }
1104 >
1105 >
1106 > runcom(cs)                      /* run command */
1107 > char    *cs;
1108 > {
1109 >        if (!silent)            /* echo it */
1110 >                printf("\t%s\n", cs);
1111 >        if (noaction)
1112 >                return(0);
1113 >        fflush(stdout);         /* flush output and pass to shell */
1114 >        return(system(cs));
1115 > }
1116 >
1117 >
1118 > rmfile(fn)                      /* remove a file */
1119 > char    *fn;
1120 > {
1121 >        if (!silent)
1122   #ifdef MSDOS
1123 <                        printf("\tdel %s\n", rawfile);
1123 >                printf("\tdel %s\n", fn);
1124   #else
1125 <                        printf("\trm %s\n", rawfile);
1125 >                printf("\trm -f %s\n", fn);
1126   #endif
1127 <                if (!noaction)
1128 <                        unlink(rawfile);
1129 <        }
1127 >        if (noaction)
1128 >                return(0);
1129 >        return(unlink(fn));
1130 > }
1131 >
1132 >
1133 > badvalue(vc)                    /* report bad variable value and exit */
1134 > int     vc;
1135 > {
1136 >        fprintf(stderr, "%s: bad value for variable '%s'\n",
1137 >                        progname, vnam(vc));
1138 >        exit(1);
1139 > }
1140 >
1141 >
1142 > syserr(s)                       /* report a system error and exit */
1143 > char    *s;
1144 > {
1145 >        perror(s);
1146 >        exit(1);
1147   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines