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.12 by greg, Fri Jun 25 17:35:49 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 >                                /* 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 341 | Line 353 | register VARIABLE      *vp;
353                  return;
354          fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
355                          progname, vp->name);
356 <        while (vp->nass-- > 1)
356 >        do
357                  vp->value += strlen(vp->value)+1;
358 +        while (--vp->nass > 1);
359   }
360  
361  
# Line 372 | 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);
379 <                        exit(1);
380 <                }
391 >                if ((thisdate = fdate(thisfile)) < 0)
392 >                        syserr(thisfile);
393                  if (thisdate > lastdate)
394                          lastdate = thisdate;
395          }
# Line 387 | Line 399 | register char  *fnames;
399  
400   checkfiles()                    /* check for existence and modified times */
401   {
402 +        char    *cp;
403          long    objdate;
404  
405 <        octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
405 >        if (!vdef(OCTREE)) {
406 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
407 >                        syserr(progname);
408 >                sprintf(cp, "%s.oct", radname);
409 >                vval(OCTREE) = cp;
410 >                vdef(OCTREE)++;
411 >        }
412 >        octreedate = fdate(vval(OCTREE));
413          scenedate = -1;
414          if (vdef(SCENE)) {
415                  scenedate = checklast(vval(SCENE));
# Line 400 | Line 420 | checkfiles()                   /* check for existence and modified tim
420                  }
421          }
422          if (octreedate < 0 & scenedate < 0) {
423 <                fprintf(stderr, "%s: need scene or octree\n", progname);
423 >                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
424 >                                vnam(OCTREE), vnam(SCENE));
425                  exit(1);
426          }
427 +        matdate = -1;
428 +        if (vdef(MATERIAL))
429 +                matdate = checklast(vval(MATERIAL));
430   }      
431  
432  
433 < setdefaults()                   /* set default values for unassigned var's */
433 > getoctcube(org, sizp)           /* get octree bounding cube */
434 > double  org[3], *sizp;
435   {
436 +        extern FILE     *popen();
437 +        static double   oorg[3], osiz = 0.;
438 +        char    buf[MAXPATH+16];
439          FILE    *fp;
412        double  xmin, ymin, zmin, size;
413        char    buf[512];
414        char    *cp;
440  
441 <        if (!vdef(OCTREE)) {
442 <                sprintf(buf, "%s.oct", radname);
443 <                vval(OCTREE) = savqstr(buf);
444 <                vdef(OCTREE)++;
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 >                        syserr("getinfo");
446 >                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
447 >                                &oorg[2], &osiz) != 4) {
448 >                        fprintf(stderr,
449 >                        "%s: error reading bounding cube from getinfo\n",
450 >                                        progname);
451 >                        exit(1);
452 >                }
453 >                pclose(fp);
454          }
455 +        org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
456 + }
457 +
458 +
459 + setdefaults()                   /* set default values for unassigned var's */
460 + {
461 +        double  org[3], size;
462 +        char    buf[128];
463 +
464          if (!vdef(ZONE)) {
465 <                if (scenedate > octreedate) {
466 <                        sprintf(buf, "getbbox -w -h %s", vval(SCENE));
467 <                        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 <                }
465 >                getoctcube(org, &size);
466 >                sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
467 >                                org[1], org[1]+size, org[2], org[2]+size);
468                  vval(ZONE) = savqstr(buf);
469                  vdef(ZONE)++;
470          }
450        if (!vdef(UP)) {
451                vval(UP) = "Z";
452                vdef(UP)++;
453        }
471          if (!vdef(INDIRECT)) {
472                  vval(INDIRECT) = "0";
473                  vdef(INDIRECT)++;
# Line 467 | Line 484 | setdefaults()                  /* set default values for unassigned v
484                  vval(PICTURE) = radname;
485                  vdef(PICTURE)++;
486          }
470        if (!vdef(AMBFILE)) {
471                sprintf(buf, "%s.amb", radname);
472                vval(AMBFILE) = savqstr(buf);
473                vdef(AMBFILE)++;
474        }
487          if (!vdef(VIEW)) {
488                  vval(VIEW) = "X";
489                  vdef(VIEW)++;
# Line 496 | 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 506 | Line 518 | oconv()                                /* run oconv if necessary */
518   {
519          char    combuf[512], ocopts[64];
520  
521 <        if (octreedate > scenedate)     /* check dates */
521 >        if (octreedate >= scenedate)    /* check dates */
522                  return;
523                                          /* build command */
524          oconvopts(ocopts);
525 <        sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
526 <        if (!silent) {                  /* echo it */
527 <                printf("\t%s\n", combuf);
528 <                fflush(stdout);
529 <        }
530 <        if (noaction)
531 <                return;
532 <        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));
536                  exit(1);
537          }
538 +        octreedate = time(0);
539   }
540  
541  
# Line 538 | Line 551 | register char  *op, *arg;
551  
552  
553   oconvopts(oo)                           /* get oconv options */
554 < char    *oo;
554 > register char   *oo;
555   {
556 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
557 +
558          *oo = '\0';
559          if (vdef(OCONV))
560                  addarg(oo, vval(OCONV));
561   }
562  
563  
564 < lowqopts(ro)                            /* low quality rendering options */
550 < char    *ro;
564 > checkambfile()                  /* check date on ambient file */
565   {
566 <        register char   *op = ro;
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)) {
581 +                if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
582 +                        return(.5/pow(2.,atof(vval(EXPOSURE))));
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 +        if (vlet(ZONE) == 'I')
590 +                return(.01);
591 +        badvalue(ZONE);
592 + }
593 +
594 +
595 + lowqopts(op)                            /* low quality rendering options */
596 + register char   *op;
597 + {
598 +        double  d, org[3], siz[3];
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 +                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 -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 -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 -dp 64");
620 +                sprintf(op, " -ar %d", (int)(16*d));
621 +                op += strlen(op);
622 +                break;
623 +        }
624 +        op = addarg(op, "-pt .16");
625 +        if (vbool(PENUMBRAS))
626 +                op = addarg(op, "-ds .4");
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);
633 +        } else
634 +                overture = 0;
635 +        switch (vscale(VARIABILITY)) {
636 +        case LOW:
637 +                op = addarg(op, "-aa .4 -ad 32");
638 +                break;
639 +        case MEDIUM:
640 +                op = addarg(op, "-aa .3 -ad 64");
641 +                break;
642 +        case HIGH:
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 -lw .02");
651          if (vdef(RENDER))
652                  op = addarg(op, vval(RENDER));
653   }
654  
655  
656 < medqopts(ro)                            /* medium quality rendering options */
657 < char    *ro;
656 > medqopts(op)                            /* medium quality rendering options */
657 > register char   *op;
658   {
659 <        register char   *op = ro;
659 >        double  d, org[3], siz[3];
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 +                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]);
668 +        switch (vscale(DETAIL)) {
669 +        case LOW:
670 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
671 +                op = addarg(op, "-dp 64");
672 +                sprintf(op, " -ar %d", (int)(8*d));
673 +                op += strlen(op);
674 +                break;
675 +        case MEDIUM:
676 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
677 +                op = addarg(op, "-dp 128");
678 +                sprintf(op, " -ar %d", (int)(16*d));
679 +                op += strlen(op);
680 +                break;
681 +        case HIGH:
682 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
683 +                op = addarg(op, "-dp 256");
684 +                sprintf(op, " -ar %d", (int)(32*d));
685 +                op += strlen(op);
686 +                break;
687 +        }
688 +        op = addarg(op, "-pt .08");
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 -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);
701 +        } else
702 +                overture = 0;
703 +        switch (vscale(VARIABILITY)) {
704 +        case LOW:
705 +                op = addarg(op, "-aa .25 -ad 128 -as 0");
706 +                break;
707 +        case MEDIUM:
708 +                op = addarg(op, "-aa .2 -ad 300 -as 64");
709 +                break;
710 +        case HIGH:
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 -lw .002");
718          if (vdef(RENDER))
719                  op = addarg(op, vval(RENDER));
720   }
721  
722  
723 < hiqopts(ro)                             /* high quality rendering options */
724 < char    *ro;
723 > hiqopts(op)                             /* high quality rendering options */
724 > register char   *op;
725   {
726 <        register char   *op = ro;
726 >        double  d, org[3], siz[3];
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 +                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]);
735 +        switch (vscale(DETAIL)) {
736 +        case LOW:
737 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
738 +                op = addarg(op, "-dp 256");
739 +                sprintf(op, " -ar %d", (int)(16*d));
740 +                op += strlen(op);
741 +                break;
742 +        case MEDIUM:
743 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
744 +                op = addarg(op, "-dp 512");
745 +                sprintf(op, " -ar %d", (int)(32*d));
746 +                op += strlen(op);
747 +                break;
748 +        case HIGH:
749 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
750 +                op = addarg(op, "-dp 1024");
751 +                sprintf(op, " -ar %d", (int)(64*d));
752 +                op += strlen(op);
753 +                break;
754 +        }
755 +        op = addarg(op, "-pt .04");
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 -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)) {
764 +                sprintf(op, " -af %s", vval(AMBFILE));
765 +                op += strlen(op);
766 +        } else
767 +                overture = 0;
768 +        switch (vscale(VARIABILITY)) {
769 +        case LOW:
770 +                op = addarg(op, "-aa .15 -ad 200 -as 0");
771 +                break;
772 +        case MEDIUM:
773 +                op = addarg(op, "-aa .125 -ad 512 -as 128");
774 +                break;
775 +        case HIGH:
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 -lw .0005");
783          if (vdef(RENDER))
784                  op = addarg(op, vval(RENDER));
785   }
# Line 583 | 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);
601 <                ro[0] = ' ';
602 <                ro[1] = '^';
603 <                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);
608 <                if (evp == NULL) {
609 <                        perror(progname);
610 <                        exit(1);
611 <                }
612 <                strcpy(evp, "ROPT=");
613 <                strcat(evp, ro);
614 <                putenv(evp);
811 >                setenv("ROPT", ro+1);
812                  strcpy(ro, " $ROPT");
813          }
814   #endif
# Line 626 | 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 .15");
832 >                break;
833 >        }
834          if (vdef(PFILT))
835                  po = addarg(po, vval(PFILT));
836   }
# Line 649 | 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;
662        viewtype = 0;
878          if (*vs == 'X') {
879                  xpos = 1; vs++;
880          } else if (*vs == 'x') {
# Line 675 | 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++;
680        else if (!*vs || isspace(*vs))
681                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];
693 <                dim[1] -= cent[1];
694 <                dim[2] -= cent[2];
695 <                exterior = vlet(ZONE) == 'E';
696 <                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 */
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");
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 738 | 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 751 | 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 774 | 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 793 | 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 */
797 <                printf("\t%s\n", combuf);
798 <                fflush(stdout);
799 <        }
800 <        if (noaction)
801 <                return;
802 <        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 809 | Line 1021 | char   *opts;
1021   rpict(opts)                             /* run rpict and pfilt for each view */
1022   char    *opts;
1023   {
1024 <        char    combuf[512];
1025 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1026 <        char    pfopts[64];
1024 >        char    combuf[1024];
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                                          /* get pfilt options */
# Line 829 | Line 1041 | char   *opts;
1041                  else if (n) {
1042                          if (n == 1) yres = xres;
1043                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1044 <                } else {
1045 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
834 <                                        progname, vnam(RESOLUTION));
835 <                        exit(1);
836 <                }
1044 >                } else
1045 >                        badvalue(RESOLUTION);
1046          }
1047          rep[0] = '\0';
1048          if (vdef(REPORT)) {
# Line 844 | Line 1053 | char   *opts;
1053                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1054                  else if (n == 1)
1055                          sprintf(rep, " -t %d", (int)(minutes*60));
1056 <                else {
1057 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
849 <                                        progname, vnam(REPORT));
850 <                        exit(1);
851 <                }
1056 >                else
1057 >                        badvalue(REPORT);
1058          }
1059                                          /* do each view */
1060          vn = 0;
# Line 857 | Line 1063 | char   *opts;
1063                          sprintf(vs, "%d", vn);
1064                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1065                                                  /* check date on picture */
1066 <                if (fdate(picfile) > octreedate)
1066 >                if (fdate(picfile) >= octreedate)
1067                          continue;
1068                                                  /* build rpict command */
1069                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1070 <                if (fdate(rawfile) > octreedate)        /* recover */
1070 >                if (fdate(rawfile) >= octreedate)       /* recover */
1071                          sprintf(combuf, "rpict%s%s -ro %s %s",
1072                                          rep, opts, rawfile, vval(OCTREE));
1073                  else {
# Line 869 | Line 1075 | char   *opts;
1075                                  sprintf(combuf,
1076                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1077                                                  rep, vw, opts,
1078 <                                                vval(OCTREE), rawfile);
1079 <                                if (!silent) {
874 <                                        printf("\t%s\n", combuf);
875 <                                        fflush(stdout);
876 <                                }
877 <                                if (!noaction && system(combuf)) {
1078 >                                                vval(OCTREE), overfile);
1079 >                                if (runcom(combuf)) {
1080                                          fprintf(stderr,
1081 <                        "%s: error in overture for view %s\n\t%s removed\n",
1082 <                                                progname, vs, rawfile);
881 <                                        unlink(rawfile);
1081 >                                        "%s: error in overture for view %s\n",
1082 >                                                progname, vs);
1083                                          exit(1);
1084                                  }
1085 + #ifdef NIX
1086 +                                rmfile(overfile);
1087 + #endif
1088                          }
1089                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1090                                          rep, vw, res, opts,
1091                                          vval(OCTREE), rawfile);
1092                  }
1093 <                if (!silent) {                  /* echo rpict command */
890 <                        printf("\t%s\n", combuf);
891 <                        fflush(stdout);
892 <                }
893 <                if (!noaction && system(combuf)) {      /* run rpict */
1093 >                if (runcom(combuf)) {           /* run rpict */
1094                          fprintf(stderr, "%s: error rendering view %s\n",
1095                                          progname, vs);
1096                          exit(1);
# Line 902 | Line 1102 | char   *opts;
1102                  else
1103                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1104                                          rawfile, picfile);
1105 <                if (!silent) {                  /* echo pfilt command */
906 <                        printf("\t%s\n", combuf);
907 <                        fflush(stdout);
908 <                }
909 <                if (!noaction && system(combuf)) {      /* run pfilt */
1105 >                if (runcom(combuf)) {           /* run pfilt */
1106                          fprintf(stderr,
1107                          "%s: error filtering view %s\n\t%s removed\n",
1108                                          progname, vs, picfile);
# Line 914 | Line 1110 | char   *opts;
1110                          exit(1);
1111                  }
1112                                                  /* remove raw file */
1113 <                if (!silent)
1113 >                rmfile(rawfile);
1114 >        }
1115 > }
1116 >
1117 >
1118 > runcom(cs)                      /* run command */
1119 > char    *cs;
1120 > {
1121 >        if (!silent)            /* echo it */
1122 >                printf("\t%s\n", cs);
1123 >        if (noaction)
1124 >                return(0);
1125 >        fflush(stdout);         /* flush output and pass to shell */
1126 >        return(system(cs));
1127 > }
1128 >
1129 >
1130 > rmfile(fn)                      /* remove a file */
1131 > char    *fn;
1132 > {
1133 >        if (!silent)
1134   #ifdef MSDOS
1135 <                        printf("\tdel %s\n", rawfile);
1135 >                printf("\tdel %s\n", fn);
1136   #else
1137 <                        printf("\trm %s\n", rawfile);
1137 >                printf("\trm -f %s\n", fn);
1138   #endif
1139 <                if (!noaction)
1140 <                        unlink(rawfile);
1139 >        if (noaction)
1140 >                return(0);
1141 >        return(unlink(fn));
1142 > }
1143 >
1144 >
1145 > #ifdef MSDOS
1146 > setenv(vname, value)            /* set an environment variable */
1147 > char    *vname, *value;
1148 > {
1149 >        register char   *evp;
1150 >
1151 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1152 >        if (evp == NULL)
1153 >                syserr(progname);
1154 >        sprintf(evp, "%s=%s", vname, value);
1155 >        if (putenv(evp) != 0) {
1156 >                fprintf(stderr, "%s: out of environment space\n", progname);
1157 >                exit(1);
1158          }
1159 +        if (!silent)
1160 +                printf("set %s\n", evp);
1161 + }
1162 + #endif
1163 +
1164 +
1165 + badvalue(vc)                    /* report bad variable value and exit */
1166 + int     vc;
1167 + {
1168 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1169 +                        progname, vnam(vc));
1170 +        exit(1);
1171 + }
1172 +
1173 +
1174 + syserr(s)                       /* report a system error and exit */
1175 + char    *s;
1176 + {
1177 +        perror(s);
1178 +        exit(1);
1179   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines