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

Comparing ray/src/util/rad.c (file contents):
Revision 2.1 by greg, Thu Mar 11 09:11:00 1993 UTC vs.
Revision 2.3 by greg, Thu Mar 11 17:23:33 1993 UTC

# Line 76 | Line 76 | VARIABLE       *matchvar();
76   char    *nvalue();
77   int     vscale();
78  
79 + #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */
80 +
81   #define vnam(vc)        (vv[vc].name)
82   #define vdef(vc)        (vv[vc].nass)
83   #define vval(vc)        (vv[vc].value)
84   #define vint(vc)        atoi(vval(vc))
85 < #define vlet(vc)        (vval(vc)[0]&~0x20)
85 > #define vlet(vc)        UPPER(vval(vc)[0])
86   #define vbool(vc)       (vlet(vc)=='T')
87  
88   #define HIGH            2
# Line 92 | Line 94 | int    (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94  
95   #define renderopts      (*setqopts[vscale(QUALITY)])
96  
97 < extern long     fdate();
97 > extern long     fdate(), time();
98  
99   long    scenedate;              /* date of latest scene or object file */
100   long    octreedate;             /* date of octree */
# Line 168 | Line 170 | char   *argv[];
170          exit(0);
171   userr:
172          fprintf(stderr,
173 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
173 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
174                          progname);
175          exit(1);
176   }
# Line 198 | Line 200 | char   *rfname;
200  
201          if (rfname == NULL)
202                  fp = stdin;
203 <        else if ((fp = fopen(rfname, "r")) == NULL) {
204 <                perror(rfname);
203 <                exit(1);
204 <        }
203 >        else if ((fp = fopen(rfname, "r")) == NULL)
204 >                syserr(rfname);
205          while (fgetline(buf, sizeof(buf), fp) != NULL) {
206                  for (cp = buf; *cp; cp++) {
207                          switch (*cp) {
# Line 266 | Line 266 | register char  *ass;
266                          ;
267          i = cp - vp->value;
268          vp->value = realloc(vp->value, i+n+1);
269 <        if (vp->value == NULL) {
270 <                perror(progname);
271 <                exit(1);
272 <        }
269 >        if (vp->value == NULL)
270 >                syserr(progname);
271          strcpy(vp->value+i, ass);
272          vp->nass++;
273   }
# Line 318 | Line 316 | int    vc;
316          case 'L':
317                  return(LOW);
318          }
319 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
319 >        badvalue(vc);
320   }
321  
322  
# Line 341 | Line 337 | register VARIABLE      *vp;
337                  return;
338          fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
339                          progname, vp->name);
340 <        while (vp->nass-- > 1)
340 >        do
341                  vp->value += strlen(vp->value)+1;
342 +        while (--vp->nass > 1);
343   }
344  
345  
# Line 374 | Line 371 | register char  *fnames;
371                  cp = thisfile;
372                  while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
373                  *cp = '\0';
374 <                if ((thisdate = fdate(thisfile)) < 0) {
375 <                        perror(thisfile);
379 <                        exit(1);
380 <                }
374 >                if ((thisdate = fdate(thisfile)) < 0)
375 >                        syserr(thisfile);
376                  if (thisdate > lastdate)
377                          lastdate = thisdate;
378          }
# Line 387 | Line 382 | register char  *fnames;
382  
383   checkfiles()                    /* check for existence and modified times */
384   {
385 +        char    *cp;
386          long    objdate;
387  
388 <        octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
388 >        if (!vdef(OCTREE)) {
389 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
390 >                        syserr(progname);
391 >                sprintf(cp, "%s.oct", radname);
392 >                vval(OCTREE) = cp;
393 >                vdef(OCTREE)++;
394 >        }
395 >        octreedate = fdate(vval(OCTREE));
396          scenedate = -1;
397          if (vdef(SCENE)) {
398                  scenedate = checklast(vval(SCENE));
# Line 400 | Line 403 | checkfiles()                   /* check for existence and modified tim
403                  }
404          }
405          if (octreedate < 0 & scenedate < 0) {
406 <                fprintf(stderr, "%s: need scene or octree\n", progname);
406 >                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
407 >                                vnam(OCTREE), vnam(SCENE));
408                  exit(1);
409          }
410   }      
411  
412  
413 < setdefaults()                   /* set default values for unassigned var's */
413 > getoctcube(org, sizp)           /* get octree bounding cube */
414 > double  org[3], *sizp;
415   {
416 +        extern FILE     *popen();
417 +        static double   oorg[3], osiz = 0.;
418 +        char    buf[MAXPATH+16];
419          FILE    *fp;
412        double  xmin, ymin, zmin, size;
413        char    buf[512];
414        char    *cp;
420  
421 <        if (!vdef(OCTREE)) {
422 <                sprintf(buf, "%s.oct", radname);
423 <                vval(OCTREE) = savqstr(buf);
424 <                vdef(OCTREE)++;
421 >        if (osiz <= FTINY) {
422 >                oconv();                /* does nothing if done already */
423 >                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
424 >                if ((fp = popen(buf, "r")) == NULL)
425 >                        syserr("getinfo");
426 >                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
427 >                                &oorg[2], &osiz) != 4) {
428 >                        fprintf(stderr,
429 >                        "%s: error reading bounding cube from getinfo\n",
430 >                                        progname);
431 >                        exit(1);
432 >                }
433 >                pclose(fp);
434          }
435 +        org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
436 + }
437 +
438 +
439 + setdefaults()                   /* set default values for unassigned var's */
440 + {
441 +        double  org[3], size;
442 +        char    buf[128];
443 +
444          if (!vdef(ZONE)) {
445 <                if (scenedate > octreedate) {
446 <                        sprintf(buf, "getbbox -w -h %s", vval(SCENE));
447 <                        if (!silent) {
425 <                                printf("\t%s\n", buf);
426 <                                fflush(stdout);
427 <                        }
428 <                        if ((fp = popen(buf, "r")) == NULL) {
429 <                                perror("getbbox");
430 <                                exit(1);
431 <                        }
432 <                        buf[0] = 'E'; buf[1] = ' ';
433 <                        fgetline(buf+2, sizeof(buf)-2, fp);
434 <                        pclose(fp);
435 <                } else {
436 <                        sprintf(buf, "getinfo -d < %s", vval(OCTREE));
437 <                        if ((fp = popen(buf, "r")) == NULL) {
438 <                                perror("getinfo");
439 <                                exit(1);
440 <                        }
441 <                        fscanf(fp, "%lf %lf %lf %lf",
442 <                                        &xmin, &ymin, &zmin, &size);
443 <                        sprintf(buf, "E %g %g %g %g %g %g", xmin, xmin+size,
444 <                                        ymin, ymin+size, zmin, zmin+size);
445 <                        pclose(fp);
446 <                }
445 >                getoctcube(org, &size);
446 >                sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
447 >                                org[1], org[1]+size, org[2], org[2]+size);
448                  vval(ZONE) = savqstr(buf);
449                  vdef(ZONE)++;
450          }
450        if (!vdef(UP)) {
451                vval(UP) = "Z";
452                vdef(UP)++;
453        }
451          if (!vdef(INDIRECT)) {
452                  vval(INDIRECT) = "0";
453                  vdef(INDIRECT)++;
# Line 467 | Line 464 | setdefaults()                  /* set default values for unassigned v
464                  vval(PICTURE) = radname;
465                  vdef(PICTURE)++;
466          }
470        if (!vdef(AMBFILE)) {
471                sprintf(buf, "%s.amb", radname);
472                vval(AMBFILE) = savqstr(buf);
473                vdef(AMBFILE)++;
474        }
467          if (!vdef(VIEW)) {
468                  vval(VIEW) = "X";
469                  vdef(VIEW)++;
# Line 506 | Line 498 | oconv()                                /* run oconv if necessary */
498   {
499          char    combuf[512], ocopts[64];
500  
501 <        if (octreedate > scenedate)     /* check dates */
501 >        if (octreedate >= scenedate)    /* check dates */
502                  return;
503                                          /* build command */
504          oconvopts(ocopts);
505 <        sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
505 >        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
506 >                        vdef(MATERIAL) ? vval(MATERIAL) : "",
507 >                        vval(SCENE), vval(OCTREE));
508          if (!silent) {                  /* echo it */
509                  printf("\t%s\n", combuf);
510                  fflush(stdout);
# Line 523 | Line 517 | oconv()                                /* run oconv if necessary */
517                  unlink(vval(OCTREE));
518                  exit(1);
519          }
520 +        octreedate = time(0);
521   }
522  
523  
# Line 538 | Line 533 | register char  *op, *arg;
533  
534  
535   oconvopts(oo)                           /* get oconv options */
536 < char    *oo;
536 > register char   *oo;
537   {
538 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
539 +
540          *oo = '\0';
541          if (vdef(OCONV))
542                  addarg(oo, vval(OCONV));
543   }
544  
545  
546 < lowqopts(ro)                            /* low quality rendering options */
547 < char    *ro;
546 > double
547 > ambval()                                /* compute ambient value */
548   {
549 <        register char   *op = ro;
549 >        if (vdef(EXPOSURE)) {
550 >                if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
551 >                        return(.5/pow(2.,atof(vval(EXPOSURE))));
552 >                if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.')
553 >                        return(.5/atof(vval(EXPOSURE)));
554 >                badvalue(EXPOSURE);
555 >        }
556 >        if (vlet(ZONE) == 'E')
557 >                return(10.);
558 >        if (vlet(ZONE) == 'I')
559 >                return(.01);
560 >        badvalue(ZONE);
561 > }
562  
563 +
564 + lowqopts(op)                            /* low quality rendering options */
565 + register char   *op;
566 + {
567 +        double  d, org[3], siz[3];
568 +
569          *op = '\0';
570 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
571 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
572 +                badvalue(ZONE);
573 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
574 +        getoctcube(org, &d);
575 +        d *= 3./(siz[0]+siz[1]+siz[2]);
576 +        switch (vscale(DETAIL)) {
577 +        case LOW:
578 +                op = addarg(op, "-ps 16");
579 +                op = addarg(op, "-dp 16");
580 +                sprintf(op, " -ar %d", (int)(4*d));
581 +                op += strlen(op);
582 +                break;
583 +        case MEDIUM:
584 +                op = addarg(op, "-ps 8");
585 +                op = addarg(op, "-dp 32");
586 +                sprintf(op, " -ar %d", (int)(8*d));
587 +                op += strlen(op);
588 +                break;
589 +        case HIGH:
590 +                op = addarg(op, "-ps 4");
591 +                op = addarg(op, "-dp 64");
592 +                sprintf(op, " -ar %d", (int)(16*d));
593 +                op += strlen(op);
594 +                break;
595 +        }
596 +        op = addarg(op, "-pt .16");
597 +        if (vbool(PENUMBRAS))
598 +                op = addarg(op, "-ds .4");
599 +        op = addarg(op, "-dt .2");
600 +        op = addarg(op, "-dc .25");
601 +        op = addarg(op, "-dr 0");
602 +        op = addarg(op, "-sj 0");
603 +        op = addarg(op, "-st .7");
604 +        op = addarg(op, "-ab 0");
605 +        if (vdef(AMBFILE)) {
606 +                sprintf(op, " -af %s", vval(AMBFILE));
607 +                op += strlen(op);
608 +        } else
609 +                overture = 0;
610 +        switch (vscale(VARIABILITY)) {
611 +        case LOW:
612 +                op = addarg(op, "-aa .4");
613 +                op = addarg(op, "-ad 32");
614 +                break;
615 +        case MEDIUM:
616 +                op = addarg(op, "-aa .3");
617 +                op = addarg(op, "-ad 64");
618 +                break;
619 +        case HIGH:
620 +                op = addarg(op, "-aa .25");
621 +                op = addarg(op, "-ad 128");
622 +                break;
623 +        }
624 +        op = addarg(op, "-as 0");
625 +        d = ambval();
626 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
627 +        op += strlen(op);
628 +        op = addarg(op, "-lr 3");
629 +        op = addarg(op, "-lw .02");
630          if (vdef(RENDER))
631                  op = addarg(op, vval(RENDER));
632   }
633  
634  
635 < medqopts(ro)                            /* medium quality rendering options */
636 < char    *ro;
635 > medqopts(op)                            /* medium quality rendering options */
636 > register char   *op;
637   {
638 <        register char   *op = ro;
638 >        double  d, org[3], siz[3];
639  
640          *op = '\0';
641 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
642 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
643 +                badvalue(ZONE);
644 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
645 +        getoctcube(org, &d);
646 +        d *= 3./(siz[0]+siz[1]+siz[2]);
647 +        switch (vscale(DETAIL)) {
648 +        case LOW:
649 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
650 +                op = addarg(op, "-dp 64");
651 +                sprintf(op, " -ar %d", (int)(8*d));
652 +                op += strlen(op);
653 +                break;
654 +        case MEDIUM:
655 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
656 +                op = addarg(op, "-dp 128");
657 +                sprintf(op, " -ar %d", (int)(16*d));
658 +                op += strlen(op);
659 +                break;
660 +        case HIGH:
661 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
662 +                op = addarg(op, "-dp 256");
663 +                sprintf(op, " -ar %d", (int)(32*d));
664 +                op += strlen(op);
665 +                break;
666 +        }
667 +        op = addarg(op, "-pt .08");
668 +        if (vbool(PENUMBRAS)) {
669 +                op = addarg(op, "-ds .2");
670 +                op = addarg(op, "-dj .35");
671 +        } else
672 +                op = addarg(op, "-ds .3");
673 +        op = addarg(op, "-dt .1");
674 +        op = addarg(op, "-dc .5");
675 +        op = addarg(op, "-dr 1");
676 +        op = addarg(op, "-sj .7");
677 +        op = addarg(op, "-st .15");
678 +        sprintf(op, " -ab %d", overture=vint(INDIRECT));
679 +        op += strlen(op);
680 +        if (vdef(AMBFILE)) {
681 +                sprintf(op, " -af %s", vval(AMBFILE));
682 +                op += strlen(op);
683 +        } else
684 +                overture = 0;
685 +        switch (vscale(VARIABILITY)) {
686 +        case LOW:
687 +                op = addarg(op, "-aa .25");
688 +                op = addarg(op, "-ad 128");
689 +                op = addarg(op, "-as 0");
690 +                break;
691 +        case MEDIUM:
692 +                op = addarg(op, "-aa .2");
693 +                op = addarg(op, "-ad 300");
694 +                op = addarg(op, "-as 64");
695 +                break;
696 +        case HIGH:
697 +                op = addarg(op, "-aa .15");
698 +                op = addarg(op, "-ad 500");
699 +                op = addarg(op, "-as 128");
700 +                break;
701 +        }
702 +        d = ambval();
703 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
704 +        op += strlen(op);
705 +        op = addarg(op, "-lr 6");
706 +        op = addarg(op, "-lw .002");
707          if (vdef(RENDER))
708                  op = addarg(op, vval(RENDER));
709   }
710  
711  
712 < hiqopts(ro)                             /* high quality rendering options */
713 < char    *ro;
712 > hiqopts(op)                             /* high quality rendering options */
713 > register char   *op;
714   {
715 <        register char   *op = ro;
715 >        double  d, org[3], siz[3];
716  
717          *op = '\0';
718 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
719 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
720 +                badvalue(ZONE);
721 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
722 +        getoctcube(org, &d);
723 +        d *= 3./(siz[0]+siz[1]+siz[2]);
724 +        switch (vscale(DETAIL)) {
725 +        case LOW:
726 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
727 +                op = addarg(op, "-dp 256");
728 +                sprintf(op, " -ar %d", (int)(16*d));
729 +                op += strlen(op);
730 +                break;
731 +        case MEDIUM:
732 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
733 +                op = addarg(op, "-dp 512");
734 +                sprintf(op, " -ar %d", (int)(32*d));
735 +                op += strlen(op);
736 +                break;
737 +        case HIGH:
738 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
739 +                op = addarg(op, "-dp 1024");
740 +                sprintf(op, " -ar %d", (int)(64*d));
741 +                op += strlen(op);
742 +                break;
743 +        }
744 +        op = addarg(op, "-pt .04");
745 +        if (vbool(PENUMBRAS)) {
746 +                op = addarg(op, "-ds .1");
747 +                op = addarg(op, "-dj .7");
748 +        } else
749 +                op = addarg(op, "-ds .2");
750 +        op = addarg(op, "-dt .05");
751 +        op = addarg(op, "-dc .75");
752 +        op = addarg(op, "-dr 3");
753 +        op = addarg(op, "-sj 1");
754 +        op = addarg(op, "-st .03");
755 +        sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
756 +        op += strlen(op);
757 +        if (vdef(AMBFILE)) {
758 +                sprintf(op, " -af %s", vval(AMBFILE));
759 +                op += strlen(op);
760 +        } else
761 +                overture = 0;
762 +        switch (vscale(VARIABILITY)) {
763 +        case LOW:
764 +                op = addarg(op, "-aa .15");
765 +                op = addarg(op, "-ad 200");
766 +                op = addarg(op, "-as 0");
767 +                break;
768 +        case MEDIUM:
769 +                op = addarg(op, "-aa .125");
770 +                op = addarg(op, "-ad 512");
771 +                op = addarg(op, "-as 128");
772 +                break;
773 +        case HIGH:
774 +                op = addarg(op, "-aa .08");
775 +                op = addarg(op, "-ad 850");
776 +                op = addarg(op, "-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");
783 +        op = addarg(op, "-lw .0005");
784          if (vdef(RENDER))
785                  op = addarg(op, vval(RENDER));
786   }
# Line 588 | Line 795 | char   *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 <                }
595 <                if (write(fd, ro+1, n-1) != n-1) {
596 <                        perror(vval(OPTFILE));
597 <                        exit(1);
598 <                }
798 >                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
799 >                        syserr(vval(OPTFILE));
800 >                if (write(fd, ro+1, n-1) != n-1)
801 >                        syserr(vval(OPTFILE));
802                  write(fd, "\n", 1);
803                  close(fd);
804                  ro[0] = ' ';
# Line 605 | Line 808 | char   *ro;
808   #ifdef MSDOS
809          else if (n > 50) {
810                  register char   *evp = bmalloc(n+6);
811 <                if (evp == NULL) {
812 <                        perror(progname);
610 <                        exit(1);
611 <                }
811 >                if (evp == NULL)
812 >                        syserr(progname);
813                  strcpy(evp, "ROPT=");
814                  strcat(evp, ro);
815 <                putenv(evp);
815 >                if (putenv(evp) != 0) {
816 >                        fprintf(stderr, "%s: out of environment space\n",
817 >                                        progname);
818 >                        exit(1);
819 >                }
820                  strcpy(ro, " $ROPT");
821          }
822   #endif
# Line 649 | Line 854 | char *
854   specview(vs)                            /* get proper view spec from vs */
855   register char   *vs;
856   {
857 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
858 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
859          static char     viewopts[128];
860          register char   *cp;
861 <        int     xpos, ypos, zpos, viewtype;
862 <        int     exterior;
861 >        int     xpos, ypos, zpos, viewtype, upax;
862 >        register int    i;
863          double  cent[3], dim[3], mult, d;
864  
865          if (vs == NULL || *vs == '-')
866                  return(vs);
867 +        upax = 0;                       /* get the up vector */
868 +        if (vdef(UP)) {
869 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
870 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
871 +                else
872 +                        upax = 1-'X'+vlet(UP);
873 +                if (upax < 1 | upax > 3)
874 +                        badvalue(UP);
875 +                if (vval(UP)[0] == '-')
876 +                        upax = -upax;
877 +        }
878                                          /* check standard view names */
879          xpos = ypos = zpos = 0;
662        viewtype = 0;
880          if (*vs == 'X') {
881                  xpos = 1; vs++;
882          } else if (*vs == 'x') {
# Line 675 | Line 892 | register char  *vs;
892          } else if (*vs == 'z') {
893                  zpos = -1; vs++;
894          }
895 +        viewtype = 'v';
896          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
897                  viewtype = *vs++;
680        else if (!*vs || isspace(*vs))
681                viewtype = 'v';
898          cp = viewopts;
899 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
899 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
900                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
901                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
902                                  &cent[0], &dim[0], &cent[1], &dim[1],
903 <                                &cent[2], &dim[2]) != 6) {
904 <                        fprintf(stderr, "%s: bad zone specification\n",
905 <                                        progname);
906 <                        exit(1);
903 >                                &cent[2], &dim[2]) != 6)
904 >                        badvalue(ZONE);
905 >                for (i = 0; i < 3; i++) {
906 >                        dim[i] -= cent[i];
907 >                        cent[i] += .5*dim[i];
908                  }
909 <                dim[0] -= cent[0];
693 <                dim[1] -= cent[1];
694 <                dim[2] -= cent[2];
695 <                exterior = vlet(ZONE) == 'E';
696 <                mult = exterior ? 2. : .45 ;
909 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
910                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
911                                  cent[0]+xpos*mult*dim[0],
912                                  cent[1]+ypos*mult*dim[1],
913                                  cent[2]+zpos*mult*dim[2],
914                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
915                  cp += strlen(cp);
916 <                switch (vlet(UP)) {
917 <                case 'Z':
918 <                        if (xpos|ypos) {
919 <                                cp = addarg(cp, "-vu 0 0 1");
920 <                                break;
921 <                        }
922 <                /* fall through */
710 <                case 'Y':
711 <                        if (xpos|zpos) {
712 <                                cp = addarg(cp, "-vu 0 1 0");
713 <                                break;
714 <                        }
715 <                /* fall through */
716 <                case 'X':
717 <                        if (ypos|zpos)
718 <                                cp = addarg(cp, "-vu 1 0 0");
719 <                        else
720 <                                cp = addarg(cp, "-vu 0 0 1");
916 >                                        /* redirect up axis if necessary */
917 >                switch (upax) {
918 >                case 3:                 /* plus or minus Z axis */
919 >                case -3:
920 >                case 0:
921 >                        if (!(xpos|ypos))
922 >                                upax = 2;
923                          break;
924 <                default:
925 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
926 <                                        progname, vnam(UP));
927 <                        exit(1);
924 >                case 2:                 /* plus or minus Y axis */
925 >                case -2:
926 >                        if (!(xpos|zpos))
927 >                                upax = 1;
928 >                        break;
929 >                case 1:                 /* plus or minus X axis */
930 >                case -1:
931 >                        if (!(ypos|zpos))
932 >                                upax = 3;
933 >                        break;
934                  }
935 +                cp = addarg(cp, vup[upax+3]);
936                  switch (viewtype) {
937                  case 'v':
938                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 738 | Line 947 | register char  *vs;
947                          cp = addarg(cp, "-vh 180 -vv 180");
948                          break;
949                  }
950 <        } else
950 >        } else {
951                  while (*vs && !isspace(*vs))    /* else skip id */
952                          vs++;
953 +                if (upax) {                     /* specify up vector */
954 +                        strcpy(cp, vup[upax+3]);
955 +                        cp += strlen(cp);
956 +                }
957 +        }
958                                          /* append any additional options */
745        while (isspace(*vs)) vs++;
959          strcpy(cp, vs);
960          return(viewopts);
961   }
# Line 809 | Line 1022 | char   *opts;
1022   rpict(opts)                             /* run rpict and pfilt for each view */
1023   char    *opts;
1024   {
1025 <        char    combuf[512];
1026 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1027 <        char    pfopts[64];
1025 >        char    combuf[1024];
1026 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1027 >        char    pfopts[128];
1028          char    vs[32], *vw;
1029          int     vn, mult;
1030                                          /* get pfilt options */
# Line 829 | 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",
834 <                                        progname, vnam(RESOLUTION));
835 <                        exit(1);
836 <                }
1045 >                } else
1046 >                        badvalue(RESOLUTION);
1047          }
1048          rep[0] = '\0';
1049          if (vdef(REPORT)) {
# Line 844 | 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",
1059 <                                        progname, vnam(REPORT));
1060 <                        exit(1);
1057 >                else
1058 >                        badvalue(REPORT);
1059 >        }
1060 >                                        /* check date on ambient file */
1061 >        if (vdef(AMBFILE)) {
1062 >                long    afdate = fdate(vval(AMBFILE));
1063 >                if (afdate >= 0 & octreedate > afdate) {
1064 >                        if (!silent)
1065 > #ifdef MSDOS
1066 >                                printf("\tdel %s\n", vval(AMBFILE));
1067 > #else
1068 >                                printf("\trm %s\n", vval(AMBFILE));
1069 > #endif
1070 >                        if (!noaction)
1071 >                                unlink(vval(AMBFILE));
1072                  }
1073          }
1074                                          /* do each view */
# Line 923 | Line 1144 | char   *opts;
1144                  if (!noaction)
1145                          unlink(rawfile);
1146          }
1147 + }
1148 +
1149 +
1150 + badvalue(vc)                    /* report bad variable value and exit */
1151 + int     vc;
1152 + {
1153 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1154 +                        progname, vnam(vc));
1155 +        exit(1);
1156 + }
1157 +
1158 +
1159 + syserr(s)                       /* report a system error and exit */
1160 + char    *s;
1161 + {
1162 +        perror(s);
1163 +        exit(1);
1164   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines