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.3 by greg, Thu Mar 11 17:23:33 1993 UTC vs.
Revision 2.12 by greg, Fri Jun 25 17:35:49 1993 UTC

# Line 94 | Line 94 | int    (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94  
95   #define renderopts      (*setqopts[vscale(QUALITY)])
96  
97 +                                /* overture calculation file */
98 + #ifdef NIX
99 + char    overfile[] = "overture.raw";
100 + #else
101 + char    overfile[] = "/dev/null";
102 + #endif
103 +
104   extern long     fdate(), time();
105  
106   long    scenedate;              /* date of latest scene or object file */
107   long    octreedate;             /* date of octree */
108 + long    matdate;                /* date of latest material file */
109  
110   int     explicate = 0;          /* explicate variables */
111   int     silent = 0;             /* do work silently */
# Line 159 | 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 195 | 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)
# 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);
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);
# Line 369 | 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                          syserr(thisfile);
# Line 407 | Line 424 | checkfiles()                   /* check for existence and modified tim
424                                  vnam(OCTREE), vnam(SCENE));
425                  exit(1);
426          }
427 +        matdate = -1;
428 +        if (vdef(MATERIAL))
429 +                matdate = checklast(vval(MATERIAL));
430   }      
431  
432  
# Line 488 | 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 502 | Line 522 | oconv()                                /* run oconv if necessary */
522                  return;
523                                          /* build command */
524          oconvopts(ocopts);
525 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
526 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
527 <                        vval(SCENE), vval(OCTREE));
528 <        if (!silent) {                  /* echo it */
529 <                printf("\t%s\n", combuf);
530 <                fflush(stdout);
531 <        }
532 <        if (noaction)
513 <                return;
514 <        if (system(combuf)) {           /* run it */
525 >        if (vdef(MATERIAL))
526 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
527 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
528 >        else
529 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
530 >                                vval(SCENE), vval(OCTREE));
531 >        
532 >        if (runcom(combuf)) {           /* run it */
533                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
534                                  progname, vval(OCTREE));
535                  unlink(vval(OCTREE));
# Line 543 | Line 561 | register char  *oo;
561   }
562  
563  
564 + checkambfile()                  /* check date on ambient file */
565 + {
566 +        long    afdate;
567 +
568 +        if (!vdef(AMBFILE))
569 +                return;
570 +        if ((afdate = fdate(vval(AMBFILE))) < 0)
571 +                return;
572 +        if (octreedate > afdate | matdate > afdate)
573 +                rmfile(vval(AMBFILE));
574 + }
575 +
576 +
577   double
578   ambval()                                /* compute ambient value */
579   {
# Line 575 | Line 606 | register char  *op;
606          d *= 3./(siz[0]+siz[1]+siz[2]);
607          switch (vscale(DETAIL)) {
608          case LOW:
609 <                op = addarg(op, "-ps 16");
579 <                op = addarg(op, "-dp 16");
609 >                op = addarg(op, "-ps 16 -dp 16");
610                  sprintf(op, " -ar %d", (int)(4*d));
611                  op += strlen(op);
612                  break;
613          case MEDIUM:
614 <                op = addarg(op, "-ps 8");
585 <                op = addarg(op, "-dp 32");
614 >                op = addarg(op, "-ps 8 -dp 32");
615                  sprintf(op, " -ar %d", (int)(8*d));
616                  op += strlen(op);
617                  break;
618          case HIGH:
619 <                op = addarg(op, "-ps 4");
591 <                op = addarg(op, "-dp 64");
619 >                op = addarg(op, "-ps 4 -dp 64");
620                  sprintf(op, " -ar %d", (int)(16*d));
621                  op += strlen(op);
622                  break;
# Line 596 | Line 624 | register char  *op;
624          op = addarg(op, "-pt .16");
625          if (vbool(PENUMBRAS))
626                  op = addarg(op, "-ds .4");
627 <        op = addarg(op, "-dt .2");
628 <        op = addarg(op, "-dc .25");
629 <        op = addarg(op, "-dr 0");
602 <        op = addarg(op, "-sj 0");
603 <        op = addarg(op, "-st .7");
604 <        op = addarg(op, "-ab 0");
627 >        else
628 >                op = addarg(op, "-ds 0");
629 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
630          if (vdef(AMBFILE)) {
631                  sprintf(op, " -af %s", vval(AMBFILE));
632                  op += strlen(op);
# Line 609 | Line 634 | register char  *op;
634                  overture = 0;
635          switch (vscale(VARIABILITY)) {
636          case LOW:
637 <                op = addarg(op, "-aa .4");
613 <                op = addarg(op, "-ad 32");
637 >                op = addarg(op, "-aa .4 -ad 32");
638                  break;
639          case MEDIUM:
640 <                op = addarg(op, "-aa .3");
617 <                op = addarg(op, "-ad 64");
640 >                op = addarg(op, "-aa .3 -ad 64");
641                  break;
642          case HIGH:
643 <                op = addarg(op, "-aa .25");
621 <                op = addarg(op, "-ad 128");
643 >                op = addarg(op, "-aa .25 -ad 128");
644                  break;
645          }
646          op = addarg(op, "-as 0");
647          d = ambval();
648          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
649          op += strlen(op);
650 <        op = addarg(op, "-lr 3");
629 <        op = addarg(op, "-lw .02");
650 >        op = addarg(op, "-lr 3 -lw .02");
651          if (vdef(RENDER))
652                  op = addarg(op, vval(RENDER));
653   }
# Line 665 | Line 686 | register char  *op;
686                  break;
687          }
688          op = addarg(op, "-pt .08");
689 <        if (vbool(PENUMBRAS)) {
690 <                op = addarg(op, "-ds .2");
691 <                op = addarg(op, "-dj .35");
671 <        } else
689 >        if (vbool(PENUMBRAS))
690 >                op = addarg(op, "-ds .2 -dj .35");
691 >        else
692                  op = addarg(op, "-ds .3");
693 <        op = addarg(op, "-dt .1");
694 <        op = addarg(op, "-dc .5");
695 <        op = addarg(op, "-dr 1");
696 <        op = addarg(op, "-sj .7");
697 <        op = addarg(op, "-st .15");
678 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
679 <        op += strlen(op);
693 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
694 >        if (overture = vint(INDIRECT)) {
695 >                sprintf(op, " -ab %d", overture);
696 >                op += strlen(op);
697 >        }
698          if (vdef(AMBFILE)) {
699                  sprintf(op, " -af %s", vval(AMBFILE));
700                  op += strlen(op);
# Line 684 | Line 702 | register char  *op;
702                  overture = 0;
703          switch (vscale(VARIABILITY)) {
704          case LOW:
705 <                op = addarg(op, "-aa .25");
688 <                op = addarg(op, "-ad 128");
689 <                op = addarg(op, "-as 0");
705 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
706                  break;
707          case MEDIUM:
708 <                op = addarg(op, "-aa .2");
693 <                op = addarg(op, "-ad 300");
694 <                op = addarg(op, "-as 64");
708 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
709                  break;
710          case HIGH:
711 <                op = addarg(op, "-aa .15");
698 <                op = addarg(op, "-ad 500");
699 <                op = addarg(op, "-as 128");
711 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
712                  break;
713          }
714          d = ambval();
715          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
716          op += strlen(op);
717 <        op = addarg(op, "-lr 6");
706 <        op = addarg(op, "-lw .002");
717 >        op = addarg(op, "-lr 6 -lw .002");
718          if (vdef(RENDER))
719                  op = addarg(op, vval(RENDER));
720   }
# Line 742 | Line 753 | register char  *op;
753                  break;
754          }
755          op = addarg(op, "-pt .04");
756 <        if (vbool(PENUMBRAS)) {
757 <                op = addarg(op, "-ds .1");
758 <                op = addarg(op, "-dj .7");
748 <        } else
756 >        if (vbool(PENUMBRAS))
757 >                op = addarg(op, "-ds .1 -dj .7");
758 >        else
759                  op = addarg(op, "-ds .2");
760 <        op = addarg(op, "-dt .05");
751 <        op = addarg(op, "-dc .75");
752 <        op = addarg(op, "-dr 3");
753 <        op = addarg(op, "-sj 1");
754 <        op = addarg(op, "-st .03");
760 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
761          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
762          op += strlen(op);
763          if (vdef(AMBFILE)) {
# Line 761 | Line 767 | register char  *op;
767                  overture = 0;
768          switch (vscale(VARIABILITY)) {
769          case LOW:
770 <                op = addarg(op, "-aa .15");
765 <                op = addarg(op, "-ad 200");
766 <                op = addarg(op, "-as 0");
770 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
771                  break;
772          case MEDIUM:
773 <                op = addarg(op, "-aa .125");
770 <                op = addarg(op, "-ad 512");
771 <                op = addarg(op, "-as 128");
773 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
774                  break;
775          case HIGH:
776 <                op = addarg(op, "-aa .08");
775 <                op = addarg(op, "-ad 850");
776 <                op = addarg(op, "-as 256");
776 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
777                  break;
778          }
779          d = ambval();
780          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
781          op += strlen(op);
782 <        op = addarg(op, "-lr 12");
783 <        op = addarg(op, "-lw .0005");
782 >        op = addarg(op, "-lr 12 -lw .0005");
783          if (vdef(RENDER))
784                  op = addarg(op, vval(RENDER));
785   }
# Line 790 | 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)
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 <                if (write(fd, ro+1, n-1) != n-1)
801 <                        syserr(vval(OPTFILE));
802 <                write(fd, "\n", 1);
803 <                close(fd);
804 <                ro[0] = ' ';
805 <                ro[1] = '^';
806 <                strcpy(ro+2, vval(OPTFILE));
807 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
808          }
809   #ifdef MSDOS
810          else if (n > 50) {
811 <                register char   *evp = bmalloc(n+6);
811 <                if (evp == NULL)
812 <                        syserr(progname);
813 <                strcpy(evp, "ROPT=");
814 <                strcat(evp, ro);
815 <                if (putenv(evp) != 0) {
816 <                        fprintf(stderr, "%s: out of environment space\n",
817 <                                        progname);
818 <                        exit(1);
819 <                }
811 >                setenv("ROPT", ro+1);
812                  strcpy(ro, " $ROPT");
813          }
814   #endif
# Line 831 | 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 948 | Line 946 | register char  *vs;
946                          break;
947                  }
948          } else {
949 <                while (*vs && !isspace(*vs))    /* else skip id */
950 <                        vs++;
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 <                                        /* append any additional options */
958 <        strcpy(cp, vs);
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 964 | 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 987 | 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 1006 | 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 */
1010 <                printf("\t%s\n", combuf);
1011 <                fflush(stdout);
1012 <        }
1013 <        if (noaction)
1014 <                return;
1015 <        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 1057 | Line 1056 | char   *opts;
1056                  else
1057                          badvalue(REPORT);
1058          }
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        }
1059                                          /* do each view */
1060          vn = 0;
1061          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1078 | 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 1090 | 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) {
1095 <                                        printf("\t%s\n", combuf);
1096 <                                        fflush(stdout);
1097 <                                }
1098 <                                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);
1102 <                                        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 */
1111 <                        printf("\t%s\n", combuf);
1112 <                        fflush(stdout);
1113 <                }
1114 <                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 1123 | Line 1102 | char   *opts;
1102                  else
1103                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1104                                          rawfile, picfile);
1105 <                if (!silent) {                  /* echo pfilt command */
1127 <                        printf("\t%s\n", combuf);
1128 <                        fflush(stdout);
1129 <                }
1130 <                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 1135 | 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 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines