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.75 by greg, Thu Jan 1 19:31:46 2004 UTC vs.
Revision 2.88 by greg, Fri Dec 5 00:51:59 2008 UTC

# Line 22 | Line 22 | static const char      RCSid[] = "$Id$";
22   #else
23    #define DELCMD "rm -f"
24    #define RENAMECMD "mv"
25 +  #include <sys/types.h>
26 +  #include <sys/wait.h>
27   #endif
28  
29                                  /* variables (alphabetical by name) */
# Line 121 | Line 123 | char   radname[PATH_MAX];      /* root Radiance file name */
123  
124   #define inchild()       (children_running < 0)
125  
126 + static void rootname(char       *rn, char       *fn);
127 + static time_t checklast(char    *fnames);
128 + static char * newfname(char     *orig, int      pred);
129 + static void checkfiles(void);
130 + static void getoctcube(double   org[3], double  *sizp);
131 + static void setdefaults(void);
132 + static void oconv(void);
133 + static char * addarg(char       *op, char       *arg);
134 + static void oconvopts(char      *oo);
135 + static void mkillumopts(char    *mo);
136 + static void checkambfile(void);
137 + static double ambval(void);
138 + static void renderopts(char     *op, char       *po);
139 + static void lowqopts(char       *op, char       *po);
140 + static void medqopts(char       *op, char       *po);
141 + static void hiqopts(char        *op, char       *po);
142 + static void xferopts(char       *ro);
143 + static void pfiltopts(char      *po);
144 + static int matchword(char       *s1, char       *s2);
145 + static char * specview(char     *vs);
146 + static char * getview(int       n, char *vn);
147 + static int myprintview(char     *vopts, FILE    *fp);
148 + static void rvu(char    *opts, char     *po);
149 + static void rpict(char  *opts, char     *po);
150 + static int touch(char   *fn);
151 + static int runcom(char  *cs);
152 + static int rmfile(char  *fn);
153 + static int mvfile(char  *fold, char     *fnew);
154 + static int next_process(void);
155 + static void wait_process(int    all);
156 + static void finish_process(void);
157 + static void badvalue(int        vc);
158 + static void syserr(char *s);
159  
160 < main(argc, argv)
161 < int     argc;
162 < char    *argv[];
160 >
161 > int
162 > main(
163 >        int     argc,
164 >        char    *argv[]
165 > )
166   {
167          char    ropts[512];
168          char    popts[64];
# Line 170 | Line 208 | char   *argv[];
208                  goto userr;
209          rifname = argv[i];
210                                  /* check command-line options */
211 <        if ((nprocs > 1) & (viewselect != NULL))
211 >        if ((nprocs > 1) & (viewselect != NULL) & (rvdevice == NULL))
212                  nprocs = 1;
213                                  /* assign Radiance root file name */
214          rootname(radname, rifname);
# Line 209 | Line 247 | userr:
247   "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
248                          progname);
249          quit(1);
250 +        return 1; /* pro forma return */
251   }
252  
253  
254 < rootname(rn, fn)                /* remove tail from end of fn */
255 < register char   *rn, *fn;
254 > static void
255 > rootname(               /* remove tail from end of fn */
256 >        register char   *rn,
257 >        register char   *fn
258 > )
259   {
260          char    *tp, *dp;
261  
# Line 227 | Line 269 | register char  *rn, *fn;
269   }
270  
271  
272 < time_t
273 < checklast(fnames)                       /* check files and find most recent */
274 < register char   *fnames;
272 > static time_t
273 > checklast(                      /* check files and find most recent */
274 >        register char   *fnames
275 > )
276   {
277          char    thisfile[PATH_MAX];
278          time_t  thisdate, lastdate = 0;
# Line 238 | Line 281 | register char  *fnames;
281                  return(0);
282          while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
283                  if (thisfile[0] == '!' ||
284 <                                (thisfile[0] == '\\' && thisfile[1] == '!'))
284 >                                (thisfile[0] == '\\' && thisfile[1] == '!')) {
285 >                        if (!lastdate)
286 >                                lastdate = 1;
287                          continue;
288 +                }
289                  if (!(thisdate = fdate(thisfile)))
290                          syserr(thisfile);
291                  if (thisdate > lastdate)
# Line 249 | Line 295 | register char  *fnames;
295   }
296  
297  
298 < char *
299 < newfname(orig, pred)            /* create modified file name */
300 < char    *orig;
301 < int     pred;
298 > static char *
299 > newfname(               /* create modified file name */
300 >        char    *orig,
301 >        int     pred
302 > )
303   {
304          register char   *cp;
305          register int    n;
# Line 274 | Line 321 | int    pred;
321   }
322  
323  
324 < checkfiles()                    /* check for existence and modified times */
324 > static void
325 > checkfiles(void)                        /* check for existence and modified times */
326   {
327          time_t  objdate;
328  
# Line 309 | Line 357 | checkfiles()                   /* check for existence and modified tim
357   }      
358  
359  
360 < getoctcube(org, sizp)           /* get octree bounding cube */
361 < double  org[3], *sizp;
360 > static void
361 > getoctcube(             /* get octree bounding cube */
362 >        double  org[3],
363 >        double  *sizp
364 > )
365   {
366          static double   oorg[3], osiz = 0.;
367          double  min[3], max[3];
# Line 359 | Line 410 | double org[3], *sizp;
410   }
411  
412  
413 < setdefaults()                   /* set default values for unassigned var's */
413 > static void
414 > setdefaults(void)                       /* set default values for unassigned var's */
415   {
416          double  org[3], lim[3], size;
417          char    buf[128];
# Line 416 | Line 468 | setdefaults()                  /* set default values for unassigned v
468   }
469  
470  
471 < oconv()                         /* run oconv and mkillum if necessary */
471 > static void
472 > oconv(void)                             /* run oconv and mkillum if necessary */
473   {
474          static char     illumtmp[] = "ilXXXXXX";
475 <        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
475 >        char    combuf[PATH_MAX], ocopts[64], mkopts[1024];
476  
477          oconvopts(ocopts);              /* get options */
478          if (octreedate < scenedate) {   /* check date on original octree */
# Line 518 | Line 571 | oconv()                                /* run oconv and mkillum if necessary */
571   }
572  
573  
574 < char *
575 < addarg(op, arg)                         /* add argument and advance pointer */
576 < register char   *op, *arg;
574 > static char *
575 > addarg(                         /* add argument and advance pointer */
576 > register char   *op,
577 > register char   *arg
578 > )
579   {
580          *op = ' ';
581          while ( (*++op = *arg++) )
# Line 529 | Line 584 | register char  *op, *arg;
584   }
585  
586  
587 < oconvopts(oo)                           /* get oconv options */
588 < register char   *oo;
587 > static void
588 > oconvopts(                              /* get oconv options */
589 >        register char   *oo
590 > )
591   {
592          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
593  
# Line 540 | Line 597 | register char  *oo;
597   }
598  
599  
600 < mkillumopts(mo)                         /* get mkillum options */
601 < register char   *mo;
600 > static void
601 > mkillumopts(                            /* get mkillum options */
602 >        char    *mo
603 > )
604   {
605          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
606  
607 <        *mo = '\0';
607 >        if (nprocs > 1) {
608 >                sprintf(mo, " -n %d", nprocs);
609 >                while (*mo)
610 >                        mo++;
611 >        } else
612 >                *mo = '\0';
613          if (vdef(MKILLUM))
614                  addarg(mo, vval(MKILLUM));
615   }
616  
617  
618 < checkambfile()                  /* check date on ambient file */
618 > static void
619 > checkambfile(void)                      /* check date on ambient file */
620   {
621          time_t  afdate;
622  
# Line 568 | Line 633 | checkambfile()                 /* check date on ambient file */
633   }
634  
635  
636 < double
637 < ambval()                                /* compute ambient value */
636 > static double
637 > ambval(void)                            /* compute ambient value */
638   {
639          if (vdef(EXPOSURE)) {
640                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
# Line 581 | Line 646 | ambval()                               /* compute ambient value */
646          if (vlet(ZONE) == 'I')
647                  return(.01);
648          badvalue(ZONE);
649 +        return 0; /* pro forma return */
650   }
651  
652  
653 < renderopts(op, po)                      /* set rendering options */
654 < char    *op, *po;
653 > static void
654 > renderopts(                     /* set rendering options */
655 >        char    *op,
656 >        char    *po
657 > )
658   {
659          switch(vscale(QUALITY)) {
660          case LOW:
# Line 601 | Line 670 | char   *op, *po;
670   }
671  
672  
673 < lowqopts(op, po)                        /* low quality rendering options */
674 < register char   *op;
675 < char    *po;
673 > static void
674 > lowqopts(                       /* low quality rendering options */
675 >        register char   *op,
676 >        char    *po
677 > )
678   {
679          double  d, org[3], siz[3];
680  
# Line 669 | Line 740 | char   *po;
740   }
741  
742  
743 < medqopts(op, po)                        /* medium quality rendering options */
744 < register char   *op;
745 < char    *po;
743 > static void
744 > medqopts(                       /* medium quality rendering options */
745 >        register char   *op,
746 >        char    *po
747 > )
748   {
749          double  d, org[3], siz[3], asz;
750  
# Line 747 | Line 820 | char   *po;
820   }
821  
822  
823 < hiqopts(op, po)                         /* high quality rendering options */
824 < register char   *op;
825 < char    *po;
823 > static void
824 > hiqopts(                                /* high quality rendering options */
825 >        register char   *op,
826 >        char    *po
827 > )
828   {
829          double  d, org[3], siz[3], asz;
830  
# Line 823 | Line 898 | char   *po;
898   }
899  
900  
901 < xferopts(ro)                            /* transfer options if indicated */
902 < char    *ro;
901 > static void
902 > xferopts(                               /* transfer options if indicated */
903 >        char    *ro
904 > )
905   {
906          int     fd, n;
907          register char   *cp;
# Line 854 | Line 931 | char   *ro;
931   }
932  
933  
934 < pfiltopts(po)                           /* get pfilt options */
935 < register char   *po;
934 > static void
935 > pfiltopts(                              /* get pfilt options */
936 >        register char   *po
937 > )
938   {
939          *po = '\0';
940          if (vdef(EXPOSURE)) {
# Line 875 | Line 954 | register char  *po;
954   }
955  
956  
957 < matchword(s1, s2)                       /* match white-delimited words */
958 < register char   *s1, *s2;
957 > static int
958 > matchword(                      /* match white-delimited words */
959 >        register char   *s1,
960 >        register char   *s2
961 > )
962   {
963          while (isspace(*s1)) s1++;
964          while (isspace(*s2)) s2++;
# Line 887 | Line 969 | register char  *s1, *s2;
969   }
970  
971  
972 < char *
973 < specview(vs)                            /* get proper view spec from vs */
974 < register char   *vs;
972 > static char *
973 > specview(                               /* get proper view spec from vs */
974 >        register char   *vs
975 > )
976   {
977          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
978                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
# Line 929 | Line 1012 | register char  *vs;
1012          } else if (*vs == 'z') {
1013                  zpos = -1; vs++;
1014          }
1015 <        viewtype = 'v';
1016 <        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
1015 >        switch (*vs) {
1016 >        case VT_PER:
1017 >        case VT_PAR:
1018 >        case VT_ANG:
1019 >        case VT_HEM:
1020 >        case VT_PLS:
1021 >        case VT_CYL:
1022                  viewtype = *vs++;
1023 +                break;
1024 +        default:
1025 +                viewtype = VT_PER;
1026 +                break;
1027 +        }
1028          cp = viewopts;
1029          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1030                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 973 | Line 1066 | register char  *vs;
1066                  }
1067                  cp = addarg(cp, vup[upax+3]);
1068                  switch (viewtype) {
1069 <                case 'v':
1069 >                case VT_PER:
1070                          cp = addarg(cp, "-vh 45 -vv 45");
1071                          break;
1072 <                case 'l':
1072 >                case VT_PAR:
1073                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1074                          sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1075                          cp += strlen(cp);
1076                          break;
1077 <                case 'a':
1078 <                case 'h':
1077 >                case VT_ANG:
1078 >                case VT_HEM:
1079 >                case VT_PLS:
1080                          cp = addarg(cp, "-vh 180 -vv 180");
1081                          break;
1082 <                case 'c':
1082 >                case VT_CYL:
1083                          cp = addarg(cp, "-vh 180 -vv 90");
1084                          break;
1085                  }
# Line 1011 | Line 1105 | register char  *vs;
1105   }
1106  
1107  
1108 < char *
1109 < getview(n, vn)                          /* get view n, or NULL if none */
1110 < int     n;
1111 < char    *vn;            /* returned view name */
1108 > static char *
1109 > getview(                                /* get view n, or NULL if none */
1110 >        int     n,
1111 >        char    *vn             /* returned view name */
1112 > )
1113   {
1114          register char   *mv;
1115  
# Line 1052 | Line 1147 | char   *vn;            /* returned view name */
1147   }
1148  
1149  
1150 < int
1151 < myprintview(vopts, fp)                  /* print out selected view */
1152 < register char   *vopts;
1153 < FILE    *fp;
1150 > static int
1151 > myprintview(                    /* print out selected view */
1152 >        register char   *vopts,
1153 >        FILE    *fp
1154 > )
1155   {
1156          VIEW    vwr;
1157          char    buf[128];
1158          register char   *cp;
1159 + #ifdef _WIN32
1160 + /* XXX Should we allow something like this for all platforms? */
1161 + /* XXX Or is it still required at all? */
1162   again:
1163 + #endif
1164          if (vopts == NULL)
1165                  return(-1);
1166   #ifdef _WIN32
# Line 1083 | Line 1183 | again:
1183   }
1184  
1185  
1186 < rvu(opts, po)                           /* run rvu with first view */
1187 < char    *opts, *po;
1186 > static void
1187 > rvu(                            /* run rvu with first view */
1188 >        char    *opts,
1189 >        char    *po
1190 > )
1191   {
1192          char    *vw;
1193          char    combuf[PATH_MAX];
# Line 1094 | Line 1197 | char   *opts, *po;
1197          if (sayview)
1198                  myprintview(vw, stdout);
1199          sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1200 +        if (nprocs > 1)
1201 +                sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1202          if (rvdevice != NULL)
1203                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1204          if (vdef(EXPOSURE))
# Line 1106 | Line 1211 | char   *opts, *po;
1211   }
1212  
1213  
1214 < rpict(opts, po)                         /* run rpict and pfilt for each view */
1215 < char    *opts, *po;
1214 > static void
1215 > rpict(                          /* run rpict and pfilt for each view */
1216 >        char    *opts,
1217 >        char    *po
1218 > )
1219   {
1220          char    combuf[PATH_MAX];
1221          char    rawfile[PATH_MAX], picfile[PATH_MAX];
# Line 1171 | Line 1279 | char   *opts, *po;
1279                          myprintview(vw, stdout);
1280                  if (!vs[0])
1281                          sprintf(vs, "%d", vn);
1282 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1282 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1283                  if (vdef(ZFILE))
1284                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1285                  else
# Line 1227 | Line 1335 | char   *opts, *po;
1335                                                  /* rpict persistent mode */
1336                                  if (!silent)
1337                                          printf("\t%s\n", combuf);
1338 +                                fflush(stdout);
1339                                  sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1340                                                  rep, rppopt, res, po, opts,
1341                                                  oct1name, rawfile);
1233                                fflush(stdout);
1342                                  fp = popen(combuf, "w");
1343                                  if (fp == NULL)
1344                                          goto rperror;
# Line 1260 | Line 1368 | char   *opts, *po;
1368                  }
1369                                                  /* remove/rename raw file */
1370                  if (vdef(RAWFILE)) {
1371 <                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1371 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1372                          mvfile(rawfile, combuf);
1373                  } else
1374                          rmfile(rawfile);
# Line 1268 | Line 1376 | char   *opts, *po;
1376          }
1377          wait_process(1);                /* wait for children to finish */
1378          if (pfile != NULL) {            /* clean up rpict persistent mode */
1379 <                int     pid;
1379 >                RT_PID  pid;
1380                  fp = fopen(pfile, "r");
1381                  if (fp != NULL) {
1382                          if (fscanf(fp, "%*s %d", &pid) != 1 ||
# Line 1284 | Line 1392 | rperror:
1392   }
1393  
1394  
1395 < touch(fn)                       /* update a file */
1396 < char    *fn;
1395 > static int
1396 > touch(                  /* update a file */
1397 >        char    *fn
1398 > )
1399   {
1400          if (!silent)
1401                  printf("\ttouch %s\n", fn);
# Line 1300 | Line 1410 | char   *fn;
1410   }
1411  
1412  
1413 < runcom(cs)                      /* run command */
1414 < char    *cs;
1413 > static int
1414 > runcom(                 /* run command */
1415 >        char    *cs
1416 > )
1417   {
1418          if (!silent)            /* echo it */
1419                  printf("\t%s\n", cs);
1420          if (!nprocs)
1421                  return(0);
1422 <        fflush(stdout);         /* flush output and pass to shell */
1422 >        fflush(NULL);           /* flush output and pass to shell */
1423          return(system(cs));
1424   }
1425  
1426  
1427 < rmfile(fn)                      /* remove a file */
1428 < char    *fn;
1427 > static int
1428 > rmfile(                 /* remove a file */
1429 >        char    *fn
1430 > )
1431   {
1432          if (!silent)
1433                  printf("\t%s %s\n", DELCMD, fn);
# Line 1323 | Line 1437 | char   *fn;
1437   }
1438  
1439  
1440 < mvfile(fold, fnew)              /* move a file */
1441 < char    *fold, *fnew;
1440 > static int
1441 > mvfile(         /* move a file */
1442 >        char    *fold,
1443 >        char    *fnew
1444 > )
1445   {
1446          if (!silent)
1447                  printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
# Line 1335 | Line 1452 | char   *fold, *fnew;
1452  
1453  
1454   #ifdef RHAS_FORK_EXEC
1455 < int
1456 < next_process()                  /* fork the next process (max. nprocs) */
1455 > static int
1456 > next_process(void)                      /* fork the next process (max. nprocs) */
1457   {
1458 <        int     child_pid;
1458 >        RT_PID  child_pid;
1459  
1460          if (nprocs <= 1)
1461                  return(0);              /* it's us or no one */
# Line 1349 | Line 1466 | next_process()                 /* fork the next process (max. nprocs
1466          }
1467          if (children_running >= nprocs)
1468                  wait_process(0);        /* wait for someone to finish */
1469 <        fflush(stdout);
1469 >        fflush(NULL);                   /* flush output */
1470          child_pid = fork();             /* split process */
1471          if (child_pid == 0) {           /* we're the child */
1472                  children_running = -1;
# Line 1363 | Line 1480 | next_process()                 /* fork the next process (max. nprocs
1480          return(0);
1481   }
1482  
1483 < wait_process(all)                       /* wait for process(es) to finish */
1484 < int     all;
1483 > static void
1484 > wait_process(                   /* wait for process(es) to finish */
1485 >        int     all
1486 > )
1487   {
1488 <        int     ourstatus = 0;
1489 <        int     pid, status;
1488 >        int     ourstatus = 0, status;
1489 >        RT_PID  pid;
1490  
1491          if (all)
1492                  all = children_running;
# Line 1391 | Line 1510 | int    all;
1510                  quit(ourstatus);        /* bad status from child */
1511   }
1512   #else   /* ! RHAS_FORK_EXEC */
1513 < int
1514 < next_process()
1513 > static int
1514 > next_process(void)
1515   {
1516          return(0);                      /* cannot start new process */
1517   }
1518 + static void
1519   wait_process(all)
1520   int     all;
1521   {
# Line 1403 | Line 1523 | int    all;
1523   }
1524   int
1525   kill(pid, sig) /* win|unix_process.c should also wait and kill */
1526 < int pid, sig;
1526 > RT_PID pid;
1527 > int sig;
1528   {
1529          return 0;
1530   }
1531   #endif  /* ! RHAS_FORK_EXEC */
1532  
1533 < finish_process()                        /* exit a child process */
1533 > static void
1534 > finish_process(void)                    /* exit a child process */
1535   {
1536          if (!inchild())
1537                  return;                 /* in parent -- noop */
# Line 1436 | Line 1558 | char   *vname, *value;
1558   #endif
1559  
1560  
1561 < badvalue(vc)                    /* report bad variable value and exit */
1562 < int     vc;
1561 > static void
1562 > badvalue(                       /* report bad variable value and exit */
1563 >        int     vc
1564 > )
1565   {
1566          fprintf(stderr, "%s: bad value for variable '%s'\n",
1567                          progname, vnam(vc));
# Line 1445 | Line 1569 | int    vc;
1569   }
1570  
1571  
1572 < syserr(s)                       /* report a system error and exit */
1573 < char    *s;
1572 > static void
1573 > syserr(                 /* report a system error and exit */
1574 >        char    *s
1575 > )
1576   {
1577          perror(s);
1578          quit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines