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.23 by greg, Tue Sep 7 11:57:04 1993 UTC vs.
Revision 2.27 by greg, Sat Sep 25 13:21:35 1993 UTC

# Line 27 | Line 27 | int    onevalue(), catvalues();
27   #define OBJECT          0               /* object files */
28   #define SCENE           1               /* scene files */
29   #define MATERIAL        2               /* material files */
30 < #define RENDER          3               /* rendering options */
31 < #define OCONV           4               /* oconv options */
32 < #define PFILT           5               /* pfilt options */
33 < #define VIEW            6               /* view(s) for picture(s) */
34 < #define ZONE            7               /* simulation zone */
35 < #define QUALITY         8               /* desired rendering quality */
36 < #define OCTREE          9               /* octree file name */
37 < #define PICTURE         10              /* picture file name */
38 < #define AMBFILE         11              /* ambient file name */
39 < #define OPTFILE         12              /* rendering options file */
40 < #define EXPOSURE        13              /* picture exposure setting */
41 < #define RESOLUTION      14              /* maximum picture resolution */
42 < #define UP              15              /* view up (X, Y or Z) */
43 < #define INDIRECT        16              /* indirection in lighting */
44 < #define DETAIL          17              /* level of scene detail */
45 < #define PENUMBRAS       18              /* shadow penumbras are desired */
46 < #define VARIABILITY     19              /* level of light variability */
47 < #define REPORT          20              /* report frequency and errfile */
30 > #define ILLUM           3               /* mkillum input files */
31 > #define MKILLUM         4               /* mkillum options */
32 > #define RENDER          5               /* rendering options */
33 > #define OCONV           6               /* oconv options */
34 > #define PFILT           7               /* pfilt options */
35 > #define VIEW            8               /* view(s) for picture(s) */
36 > #define ZONE            9               /* simulation zone */
37 > #define QUALITY         10              /* desired rendering quality */
38 > #define OCTREE          11              /* octree file name */
39 > #define PICTURE         12              /* picture file name */
40 > #define AMBFILE         13              /* ambient file name */
41 > #define OPTFILE         14              /* rendering options file */
42 > #define EXPOSURE        15              /* picture exposure setting */
43 > #define RESOLUTION      16              /* maximum picture resolution */
44 > #define UP              17              /* view up (X, Y or Z) */
45 > #define INDIRECT        18              /* indirection in lighting */
46 > #define DETAIL          19              /* level of scene detail */
47 > #define PENUMBRAS       20              /* shadow penumbras are desired */
48 > #define VARIABILITY     21              /* level of light variability */
49 > #define REPORT          22              /* report frequency and errfile */
50                                  /* total number of variables */
51 < #define NVARS           21
51 > #define NVARS           23
52  
53   VARIABLE        vv[NVARS] = {           /* variable-value pairs */
54          {"objects",     3,      0,      NULL,   catvalues},
55          {"scene",       3,      0,      NULL,   catvalues},
56          {"materials",   3,      0,      NULL,   catvalues},
57 +        {"illum",       3,      0,      NULL,   catvalues},
58 +        {"mkillum",     3,      0,      NULL,   catvalues},
59          {"render",      3,      0,      NULL,   catvalues},
60          {"oconv",       3,      0,      NULL,   catvalues},
61          {"pfilt",       2,      0,      NULL,   catvalues},
# Line 101 | Line 105 | char   overfile[] = "overture.raw";
105   char    overfile[] = "/dev/null";
106   #endif
107  
108 < extern long     fdate(), time();
108 > extern unsigned long    fdate(), time();
109  
110 < long    scenedate;              /* date of latest scene or object file */
111 < long    octreedate;             /* date of octree */
112 < long    matdate;                /* date of latest material file */
110 > unsigned long   scenedate;      /* date of latest scene or object file */
111 > unsigned long   octreedate;     /* date of octree */
112 > unsigned long   matdate;        /* date of latest material file */
113 > unsigned long   illumdate;      /* date of last illum file */
114  
115 + char    *oct0name;              /* name of pre-mkillum octree */
116 + unsigned long   oct0date;       /* date of pre-mkillum octree */
117 + char    *oct1name;              /* name of post-mkillum octree */
118 + unsigned long   oct1date;       /* date of post-mkillum octree (>= matdate) */
119 +
120   int     explicate = 0;          /* explicate variables */
121   int     silent = 0;             /* do work silently */
122   int     noaction = 0;           /* don't do anything */
# Line 173 | Line 183 | char   *argv[];
183                                  /* print all values if requested */
184          if (explicate)
185                  printvals();
186 <                                /* build octree */
186 >                                /* build octree (and run mkillum) */
187          oconv();
188                                  /* check date on ambient file */
189          checkambfile();
# Line 187 | Line 197 | char   *argv[];
197          exit(0);
198   userr:
199          fprintf(stderr,
200 <        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
200 >        "Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
201                          progname);
202          exit(1);
203   }
# Line 208 | Line 218 | register char  *rn, *fn;
218   }
219  
220  
221 + #define NOCHAR  127             /* constant for character to delete */
222 +
223 +
224   load(rfname)                    /* load Radiance simulation file */
225   char    *rfname;
226   {
# Line 223 | Line 236 | char   *rfname;
236                  for (cp = buf; *cp; cp++) {
237                          switch (*cp) {
238                          case '\\':
239 <                        case '\n':
227 <                                *cp = ' ';
239 >                                *cp++ = NOCHAR;
240                                  continue;
241                          case '#':
242                                  *cp = '\0';
# Line 244 | Line 256 | setvariable(ass)               /* assign variable according to stri
256   register char   *ass;
257   {
258          char    varname[32];
259 +        char    varval[512];
260 +        int     n;
261          register char   *cp;
262          register VARIABLE       *vp;
263          register int    i;
250        int     n;
264  
265          while (isspace(*ass))           /* skip leading space */
266                  ass++;
# Line 261 | Line 274 | register char  *ass;
274                                          /* trim value */
275          while (isspace(*ass) || *ass == '=')
276                  ass++;
277 <        cp = ass + strlen(ass);
278 <        do
279 <                *cp-- = '\0';
267 <        while (cp >= ass && isspace(*cp));
268 <        n = cp - ass + 1;
277 >        for (n = strlen(ass); n > 0; n--)
278 >                if (!isspace(ass[n-1]))
279 >                        break;
280          if (!n) {
281                  fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
282                                  progname, varname);
# Line 290 | Line 301 | register char  *ass;
301                  vp->value = malloc(n+1);
302          if (vp->value == NULL)
303                  syserr(progname);
304 <        strcpy(vp->value+i, ass);
304 >        cp = vp->value+i;               /* copy value, squeezing spaces */
305 >        *cp = *ass;
306 >        for (i = 1; i <= n; i++) {
307 >                if (ass[i] == NOCHAR)
308 >                        continue;
309 >                if (isspace(*cp))
310 >                        while (isspace(ass[i]))
311 >                                i++;
312 >                *++cp = ass[i];
313 >        }
314 >        if (isspace(*cp))               /* remove trailing space */
315 >                *cp = '\0';
316          vp->nass++;
317   }
318  
# Line 380 | Line 402 | register VARIABLE      *vp;
402   }
403  
404  
405 < long
405 > unsigned long
406   checklast(fnames)                       /* check files and find most recent */
407   register char   *fnames;
408   {
409          char    thisfile[MAXPATH];
410 <        long    thisdate, lastdate = -1;
410 >        unsigned long   thisdate, lastdate = 0;
411          register char   *cp;
412  
413 +        if (fnames == NULL)
414 +                return(0);
415          while (*fnames) {
416                  while (isspace(*fnames)) fnames++;
417                  cp = thisfile;
418                  while (*fnames && !isspace(*fnames))
419                          *cp++ = *fnames++;
420                  *cp = '\0';
421 <                if ((thisdate = fdate(thisfile)) < 0)
421 >                if (!(thisdate = fdate(thisfile)))
422                          syserr(thisfile);
423                  if (thisdate > lastdate)
424                          lastdate = thisdate;
# Line 403 | Line 427 | register char  *fnames;
427   }
428  
429  
430 + char *
431 + newfname(orig, pred)            /* create modified file name */
432 + char    *orig;
433 + int     pred;
434 + {
435 +        extern char     *rindex();
436 +        register char   *cp;
437 +        register int    n;
438 +        int     suffix;
439 +
440 +        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
441 +        while (*cp) {
442 +                if (*cp == '.') suffix = n;
443 +                else if (ISDIRSEP(*cp)) suffix = -1;
444 +                cp++; n++;
445 +        }
446 +        if (suffix == -1) suffix = n;
447 +        if ((cp = bmalloc(n+2)) == NULL)
448 +                syserr(progname);
449 +        strncpy(cp, orig, suffix);
450 +        cp[suffix] = pred;                      /* root name + pred + suffix */
451 +        strcpy(cp+suffix+1, orig+suffix);
452 +        return(cp);
453 + }
454 +
455 +
456   checkfiles()                    /* check for existence and modified times */
457   {
458 <        char    *cp;
409 <        long    objdate;
458 >        unsigned long   objdate;
459  
460          if (!vdef(OCTREE)) {
461 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
461 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
462                          syserr(progname);
463 <                sprintf(cp, "%s.oct", radname);
415 <                vval(OCTREE) = cp;
463 >                sprintf(vval(OCTREE), "%s.oct", radname);
464                  vdef(OCTREE)++;
465          }
466          octreedate = fdate(vval(OCTREE));
467 <        scenedate = -1;
468 <        if (vdef(SCENE)) {
469 <                scenedate = checklast(vval(SCENE));
470 <                if (vdef(OBJECT)) {
471 <                        objdate = checklast(vval(OBJECT));
472 <                        if (objdate > scenedate)
473 <                                scenedate = objdate;
474 <                }
475 <        }
476 <        if (octreedate < 0 & scenedate < 0) {
477 <                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
478 <                                vnam(OCTREE), vnam(SCENE));
467 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
468 >                oct0name = newfname(vval(OCTREE), '0');
469 >                oct1name = newfname(vval(OCTREE), '1');
470 >                oct0date = fdate(oct0name);
471 >                oct1date = fdate(oct1name);
472 >        } else
473 >                oct0name = oct1name = vval(OCTREE);
474 >        if ((scenedate = checklast(vval(SCENE))) &&
475 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
476 >                scenedate = objdate;
477 >        illumdate = checklast(vval(ILLUM));
478 >        if (!octreedate & !scenedate & !illumdate) {
479 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
480 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
481                  exit(1);
482          }
483 <        matdate = -1;
434 <        if (vdef(MATERIAL))
435 <                matdate = checklast(vval(MATERIAL));
483 >        matdate = checklast(vval(MATERIAL));
484   }      
485  
486  
# Line 441 | Line 489 | double org[3], *sizp;
489   {
490          extern FILE     *popen();
491          static double   oorg[3], osiz = 0.;
492 <        char    buf[MAXPATH+16];
492 >        double  min[3], max[3];
493 >        char    buf[512];
494          FILE    *fp;
495 +        register int    i;
496  
497 <        if (osiz <= FTINY) {
498 <                oconv();                /* does nothing if done already */
499 <                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
500 <                if ((fp = popen(buf, "r")) == NULL)
501 <                        syserr("getinfo");
502 <                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
503 <                                &oorg[2], &osiz) != 4) {
504 <                        fprintf(stderr,
497 >        if (osiz <= FTINY)
498 >                if (noaction && fdate(oct1name) <
499 >                                (scenedate>illumdate?scenedate:illumdate)) {
500 >                                                        /* run getbbox */
501 >                        sprintf(buf, "getbbox -w -h %s",
502 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
503 >                        if ((fp = popen(buf, "r")) == NULL)
504 >                                syserr("getbbox");
505 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
506 >                                        &min[0], &max[0], &min[1], &max[1],
507 >                                        &min[2], &max[2]) != 6) {
508 >                                fprintf(stderr,
509 >                        "%s: error reading bounding box from getbbox\n",
510 >                                                progname);
511 >                                exit(1);
512 >                        }
513 >                        for (i = 0; i < 3; i++)
514 >                                if (max[i] - min[i] > osiz)
515 >                                        osiz = max[i] - min[i];
516 >                        for (i = 0; i < 3; i++)
517 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
518 >                        pclose(fp);
519 >                } else {                                /* from octree */
520 >                        oconv();        /* does nothing if done already */
521 >                        sprintf(buf, "getinfo -d < %s", oct1name);
522 >                        if ((fp = popen(buf, "r")) == NULL)
523 >                                syserr("getinfo");
524 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
525 >                                        &oorg[2], &osiz) != 4) {
526 >                                fprintf(stderr,
527                          "%s: error reading bounding cube from getinfo\n",
528 <                                        progname);
529 <                        exit(1);
528 >                                                progname);
529 >                                exit(1);
530 >                        }
531 >                        pclose(fp);
532                  }
459                pclose(fp);
460        }
533          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
534   }
535  
# Line 520 | Line 592 | printvals()                    /* print variable values */
592   }
593  
594  
595 < oconv()                         /* run oconv if necessary */
595 > oconv()                         /* run oconv and mkillum if necessary */
596   {
597 <        char    combuf[512], ocopts[64];
597 >        static char     illumtmp[] = "ilXXXXXX";
598 >        char    combuf[512], ocopts[64], mkopts[64];
599  
600 <        if (octreedate >= scenedate)    /* check dates */
601 <                return;
602 <                                        /* build command */
603 <        oconvopts(ocopts);
604 <        if (vdef(MATERIAL))
532 <                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
600 >        oconvopts(ocopts);              /* get options */
601 >        if (octreedate < scenedate) {   /* check date on original octree */
602 >                                                /* build command */
603 >                if (vdef(MATERIAL))
604 >                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
605                                  vval(MATERIAL), vval(SCENE), vval(OCTREE));
606 +                else
607 +                        sprintf(combuf, "oconv%s %s > %s", ocopts,
608 +                                        vval(SCENE), vval(OCTREE));
609 +                
610 +                if (runcom(combuf)) {           /* run it */
611 +                        fprintf(stderr,
612 +                                "%s: error generating octree\n\t%s removed\n",
613 +                                        progname, vval(OCTREE));
614 +                        unlink(vval(OCTREE));
615 +                        exit(1);
616 +                }
617 +                octreedate = time(0);
618 +        }
619 +        if (oct1name == vval(OCTREE))           /* no mkillum? */
620 +                oct1date = octreedate > matdate ? octreedate : matdate;
621 +        if (oct1date >= octreedate & oct1date >= matdate
622 +                        & oct1date >= illumdate)        /* all done */
623 +                return;
624 +                                                /* make octree0 */
625 +        if (oct0date < scenedate | oct0date < illumdate) {
626 +                                                /* build command */
627 +                if (octreedate)
628 +                        sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
629 +                                vval(OCTREE), vval(ILLUM), oct0name);
630 +                else if (vdef(MATERIAL))
631 +                        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
632 +                                vval(MATERIAL), vval(ILLUM), oct0name);
633 +                else
634 +                        sprintf(combuf, "oconv%s %s > %s", ocopts,
635 +                                vval(ILLUM), oct0name);
636 +                if (runcom(combuf)) {           /* run it */
637 +                        fprintf(stderr,
638 +                                "%s: error generating octree\n\t%s removed\n",
639 +                                        progname, oct0name);
640 +                        unlink(oct0name);
641 +                        exit(1);
642 +                }
643 +                oct0date = time(0);
644 +        }
645 +        mkillumopts(mkopts);                    /* build mkillum command */
646 +        mktemp(illumtmp);
647 +        sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
648 +                        oct0name, vval(ILLUM), illumtmp);
649 +        if (runcom(combuf)) {                   /* run it */
650 +                fprintf(stderr, "%s: error running mkillum\n", progname);
651 +                unlink(illumtmp);
652 +                exit(1);
653 +        }
654 +                                                /* make octree1 (frozen) */
655 +        if (octreedate)
656 +                sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
657 +                        vval(OCTREE), illumtmp, oct1name);
658 +        else if (vdef(MATERIAL))
659 +                sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
660 +                        vval(MATERIAL), illumtmp, oct1name);
661          else
662 <                sprintf(combuf, "oconv%s %s > %s", ocopts,
663 <                                vval(SCENE), vval(OCTREE));
537 <        
662 >                sprintf(combuf, "oconv%s -f %s > %s", ocopts,
663 >                        illumtmp, oct1name);
664          if (runcom(combuf)) {           /* run it */
665 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
666 <                                progname, vval(OCTREE));
667 <                unlink(vval(OCTREE));
665 >                fprintf(stderr,
666 >                        "%s: error generating octree\n\t%s removed\n",
667 >                                progname, oct1name);
668 >                unlink(oct1name);
669                  exit(1);
670          }
671 <        octreedate = time(0);
671 >        oct1date = time(0);
672 >        rmfile(illumtmp);
673   }
674  
675  
# Line 567 | Line 695 | register char  *oo;
695   }
696  
697  
698 + mkillumopts(mo)                         /* get mkillum options */
699 + register char   *mo;
700 + {
701 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
702 +
703 +        *mo = '\0';
704 +        if (vdef(MKILLUM))
705 +                addarg(mo, vval(MKILLUM));
706 + }
707 +
708 +
709   checkambfile()                  /* check date on ambient file */
710   {
711 <        long    afdate;
711 >        unsigned long   afdate;
712  
713          if (!vdef(AMBFILE))
714                  return;
715 <        if ((afdate = fdate(vval(AMBFILE))) < 0)
715 >        if (!(afdate = fdate(vval(AMBFILE))))
716                  return;
717 <        if (octreedate > afdate | matdate > afdate)
717 >        if (oct1date > afdate)
718                  rmfile(vval(AMBFILE));
719   }
720  
# Line 960 | Line 1099 | register char  *vs;
1099                          cp += strlen(cp);
1100                  }
1101          }
1102 <        strcpy(cp, vs);                 /* append any additional options */
1102 >        if (cp == viewopts)             /* append any additional options */
1103 >                vs++;           /* skip prefixed space if unneeded */
1104 >        strcpy(cp, vs);
1105   #ifdef MSDOS
1106          if (strlen(viewopts) > 40) {
1107                  setenv("VIEW", viewopts);
# Line 1015 | Line 1156 | char   *vn;            /* returned view name */
1156   printview(vopts)                        /* print out selected view */
1157   register char   *vopts;
1158   {
1159 <        extern char     *atos();
1159 >        extern char     *atos(), *getenv();
1160          char    buf[256];
1161          FILE    *fp;
1162          register char   *cp;
# Line 1050 | Line 1191 | register char  *vopts;
1191                          while (isspace(*vopts))
1192                                  vopts++;
1193                          putchar(' ');
1194 <                        while (*vopts && !isspace(*vopts))
1195 <                                putchar(*vopts++);
1194 > #ifdef MSDOS
1195 >                        if (*vopts == '$') {            /* expand env. var. */
1196 >                                if (!*atos(buf, sizeof(buf), vopts+1))
1197 >                                        return(-1);
1198 >                                if ((cp = getenv(buf)) == NULL)
1199 >                                        return(-1);
1200 >                                fputs(cp, stdout);
1201 >                                vopts = sskip(vopts);
1202 >                        } else
1203 > #endif
1204 >                                while (*vopts && !isspace(*vopts))
1205 >                                        putchar(*vopts++);
1206                  }
1207          } while (*vopts++);
1208          putchar('\n');
# Line 1072 | Line 1223 | char   *opts;
1223          sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1224          if (rvdevice != NULL)
1225                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1226 <        strcat(combuf, vval(OCTREE));
1226 >        strcat(combuf, oct1name);
1227          if (runcom(combuf)) {           /* run it */
1228                  fprintf(stderr, "%s: error running rview\n", progname);
1229                  exit(1);
# Line 1088 | Line 1239 | char   *opts;
1239          char    pfopts[128];
1240          char    vs[32], *vw;
1241          int     vn, mult;
1091        long    lastdate;
1242                                          /* get pfilt options */
1243          pfiltopts(pfopts);
1244                                          /* get resolution, reporting */
# Line 1119 | Line 1269 | char   *opts;
1269                  else
1270                          badvalue(REPORT);
1271          }
1122                                        /* get update time */
1123        lastdate = octreedate > matdate ? octreedate : matdate;
1272                                          /* do each view */
1273          vn = 0;
1274          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1130 | Line 1278 | char   *opts;
1278                          sprintf(vs, "%d", vn);
1279                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1280                                                  /* check date on picture */
1281 <                if (fdate(picfile) >= lastdate)
1281 >                if (fdate(picfile) >= oct1date)
1282                          continue;
1283                                                  /* build rpict command */
1284                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1285 <                if (fdate(rawfile) >= octreedate)       /* recover */
1285 >                if (fdate(rawfile) >= oct1date)         /* recover */
1286                          sprintf(combuf, "rpict%s%s -ro %s %s",
1287 <                                        rep, opts, rawfile, vval(OCTREE));
1287 >                                        rep, opts, rawfile, oct1name);
1288                  else {
1289                          if (overture) {         /* run overture calculation */
1290                                  sprintf(combuf,
1291                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1292                                                  rep, vw, opts,
1293 <                                                vval(OCTREE), overfile);
1293 >                                                oct1name, overfile);
1294                                  if (runcom(combuf)) {
1295                                          fprintf(stderr,
1296                                          "%s: error in overture for view %s\n",
# Line 1155 | Line 1303 | char   *opts;
1303                          }
1304                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1305                                          rep, vw, res, opts,
1306 <                                        vval(OCTREE), rawfile);
1306 >                                        oct1name, rawfile);
1307                  }
1308                  if (runcom(combuf)) {           /* run rpict */
1309                          fprintf(stderr, "%s: error rendering view %s\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines