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.99 by greg, Fri Oct 8 22:11:57 2010 UTC vs.
Revision 2.111 by greg, Sun Oct 26 17:35:53 2014 UTC

# Line 24 | Line 24 | static const char      RCSid[] = "$Id$";
24    #define RENAMECMD "mv"
25    #include <sys/types.h>
26    #include <sys/wait.h>
27 +  #include <signal.h>
28   #endif
29  
30                                  /* variables (alphabetical by name) */
# Line 264 | Line 265 | userr:
265  
266   static void
267   rootname(               /* remove tail from end of fn */
268 <        register char   *rn,
269 <        register char   *fn
268 >        char    *rn,
269 >        char    *fn
270   )
271   {
272          char    *tp, *dp;
# Line 282 | Line 283 | rootname(              /* remove tail from end of fn */
283  
284   static time_t
285   checklast(                      /* check files and find most recent */
286 <        register char   *fnames
286 >        char    *fnames
287   )
288   {
289          char    thisfile[PATH_MAX];
# Line 312 | Line 313 | newfname(              /* create modified file name */
313          int     pred
314   )
315   {
316 <        register char   *cp;
317 <        register int    n;
316 >        char    *cp;
317 >        int     n;
318          int     suffix;
319  
320          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 378 | Line 379 | getoctcube(            /* get octree bounding cube */
379          double  min[3], max[3];
380          char    buf[1024];
381          FILE    *fp;
382 <        register int    i;
382 >        int     i;
383  
384          if (osiz <= FTINY) {
385                  if (!nprocs && fdate(oct1name) <
# Line 558 | Line 559 | oconv(void)                            /* run oconv and mkillum if necessary *
559                          unlink(illumtmp);
560                          quit(1);
561                  }
562 +                rmfile(oct0name);
563                                                  /* make octree1 (frozen) */
564                  if (octreedate)
565                          sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
# Line 586 | Line 588 | oconv(void)                            /* run oconv and mkillum if necessary *
588  
589   static char *
590   addarg(                         /* append argument and advance pointer */
591 < register char   *op,
592 < register char   *arg
591 > char    *op,
592 > char    *arg
593   )
594   {
595          while (*op)
# Line 601 | Line 603 | register char  *arg
603  
604   static void
605   oconvopts(                              /* get oconv options */
606 <        register char   *oo
606 >        char    *oo
607   )
608   {
609          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
# Line 710 | Line 712 | renderopts(                    /* set rendering options */
712  
713   static void
714   lowqopts(                       /* low quality rendering options */
715 <        register char   *op,
715 >        char    *op,
716          char    *po
717   )
718   {
# Line 772 | Line 774 | lowqopts(                      /* low quality rendering options */
774          d = ambval();
775          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
776          op += strlen(op);
777 <        op = addarg(op, "-lr 6 -lw .01");
777 >        op = addarg(op, "-lr 6 -lw .003");
778   }
779  
780  
781   static void
782   medqopts(                       /* medium quality rendering options */
783 <        register char   *op,
783 >        char    *op,
784          char    *po
785   )
786   {
# Line 826 | Line 828 | medqopts(                      /* medium quality rendering options */
828                  op = addarg(op, "-ds .2 -dj .9");
829          else
830                  op = addarg(op, "-ds .3");
831 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss .7 -st .1");
831 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
832          if ( (overture = vint(INDIRECT)) ) {
833                  sprintf(op, " -ab %d", overture);
834                  op += strlen(op);
# Line 850 | Line 852 | medqopts(                      /* medium quality rendering options */
852          d = ambval();
853          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
854          op += strlen(op);
855 <        op = addarg(op, "-lr 8 -lw .002");
855 >        op = addarg(op, "-lr 8 -lw 1e-4");
856   }
857  
858  
859   static void
860   hiqopts(                                /* high quality rendering options */
861 <        register char   *op,
861 >        char    *op,
862          char    *po
863   )
864   {
# Line 904 | Line 906 | hiqopts(                               /* high quality rendering options */
906                  op = addarg(op, "-ds .1 -dj .9");
907          else
908                  op = addarg(op, "-ds .2");
909 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 1 -st .01");
909 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
910          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
911          op += strlen(op);
912          if (vdef(AMBFILE)) {
# Line 926 | Line 928 | hiqopts(                               /* high quality rendering options */
928          d = ambval();
929          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
930          op += strlen(op);
931 <        op = addarg(op, "-lr 12 -lw .0005");
931 >        op = addarg(op, "-lr 12 -lw 1e-5");
932   }
933  
934  
935 + #ifdef _WIN32
936   static void
937 + setenv(                 /* set an environment variable */
938 +        char    *vname,
939 +        char    *value
940 + )
941 + {
942 +        char    *evp;
943 +
944 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
945 +        if (evp == NULL)
946 +                syserr(progname);
947 +        sprintf(evp, "%s=%s", vname, value);
948 +        if (putenv(evp) != 0) {
949 +                fprintf(stderr, "%s: out of environment space\n", progname);
950 +                quit(1);
951 +        }
952 +        if (!silent)
953 +                printf("set %s\n", evp);
954 + }
955 + #endif
956 +
957 +
958 + static void
959   xferopts(                               /* transfer options if indicated */
960          char    *ro
961   )
962   {
963          int     fd, n;
964 <        register char   *cp;
964 >        char    *cp;
965          
966          n = strlen(ro);
967          if (n < 2)
# Line 965 | Line 990 | xferopts(                              /* transfer options if indicated */
990  
991   static void
992   pfiltopts(                              /* get pfilt options */
993 <        register char   *po
993 >        char    *po
994   )
995   {
996          *po = '\0';
# Line 992 | Line 1017 | pfiltopts(                             /* get pfilt options */
1017  
1018   static int
1019   matchword(                      /* match white-delimited words */
1020 <        register char   *s1,
1021 <        register char   *s2
1020 >        char    *s1,
1021 >        char    *s2
1022   )
1023   {
1024          while (isspace(*s1)) s1++;
# Line 1007 | Line 1032 | matchword(                     /* match white-delimited words */
1032  
1033   static char *
1034   specview(                               /* get proper view spec from vs */
1035 <        register char   *vs
1035 >        char    *vs
1036   )
1037   {
1038          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1039                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1040          static char     viewopts[128];
1041 <        register char   *cp;
1041 >        char    *cp;
1042          int     xpos, ypos, zpos, viewtype, upax;
1043 <        register int    i;
1043 >        int     i;
1044          double  cent[3], dim[3], mult, d;
1045  
1046          if (vs == NULL || *vs == '-')
# Line 1075 | Line 1100 | specview(                              /* get proper view spec from vs */
1100                          cent[i] += .5*dim[i];
1101                  }
1102                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1103 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1103 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1104                                  cent[0]+xpos*mult*dim[0],
1105                                  cent[1]+ypos*mult*dim[1],
1106                                  cent[2]+zpos*mult*dim[2],
# Line 1107 | Line 1132 | specview(                              /* get proper view spec from vs */
1132                          break;
1133                  case VT_PAR:
1134                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1135 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1135 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1136                          cp += strlen(cp);
1137                          break;
1138                  case VT_ANG:
# Line 1147 | Line 1172 | getview(                               /* get view n, or NULL if none */
1172          char    *vn             /* returned view name */
1173   )
1174   {
1175 <        register char   *mv;
1175 >        char    *mv;
1176  
1177          if (viewselect != NULL) {               /* command-line selected */
1178                  if (n)                          /* only do one */
# Line 1179 | Line 1204 | numview:
1204          mv = nvalue(VIEWS, n);          /* use view n */
1205          if ((vn != NULL) & (mv != NULL))
1206                  if (*mv != '-') {
1207 <                        register char   *mv2 = mv;
1207 >                        char    *mv2 = mv;
1208                          while (*mv2 && !isspace(*mv2))
1209                                  *vn++ = *mv2++;
1210                          *vn = '\0';
# Line 1192 | Line 1217 | numview:
1217  
1218   static int
1219   myprintview(                    /* print out selected view */
1220 <        register char   *vopts,
1220 >        char    *vopts,
1221          FILE    *fp
1222   )
1223   {
1224          VIEW    vwr;
1225          char    buf[128];
1226 <        register char   *cp;
1226 >        char    *cp;
1227   #ifdef _WIN32
1228   /* XXX Should we allow something like this for all platforms? */
1229   /* XXX Or is it still required at all? */
# Line 1254 | Line 1279 | rvu(                           /* run rvu with first view */
1279   }
1280  
1281  
1282 + static int
1283 + syncf_done(                     /* check if an rpiece sync file is complete */
1284 +        char *sfname
1285 + )
1286 + {
1287 +        FILE    *fp = fopen(sfname, "r");
1288 +        int     todo = 1;
1289 +        int     x, y;
1290 +
1291 +        if (fp == NULL)
1292 +                return(0);
1293 +        if (fscanf(fp, "%d %d", &x, &y) != 2)
1294 +                goto checked;
1295 +        todo = x*y;             /* total number of tiles */
1296 +        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1297 +                goto checked;
1298 +                                /* XXX assume no redundant tiles */
1299 +        while (fscanf(fp, "%d %d", &x, &y) == 2)
1300 +                if (!--todo)
1301 +                        break;
1302 + checked:
1303 +        fclose(fp);
1304 +        return(!todo);
1305 + }
1306 +
1307 +
1308   static void
1309   rpict(                          /* run rpict and pfilt for each view */
1310          char    *opts,
# Line 1261 | Line 1312 | rpict(                         /* run rpict and pfilt for each view */
1312   )
1313   {
1314   #define do_rpiece       (sfile[0]!='\0')
1315 <        char    combuf[4*PATH_MAX+512];
1315 >        char    combuf[5*PATH_MAX+512];
1316          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1317          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1318 <        char    rppopt[128], sfile[64], *pfile = NULL;
1318 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1319          char    pfopts[128];
1320          char    vs[32], *vw;
1321          int     vn, mult;
1322          FILE    *fp;
1323          time_t  rfdt, pfdt;
1324 +        int     xres, yres;
1325 +        double  aspect;
1326 +        int     n;
1327                                          /* get pfilt options */
1328          pfiltopts(pfopts);
1329                                          /* get resolution, reporting */
# Line 1284 | Line 1338 | rpict(                         /* run rpict and pfilt for each view */
1338                  mult = 3;
1339                  break;
1340          }
1341 <        {
1342 <                int     xres, yres;
1343 <                double  aspect;
1344 <                int     n;
1345 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1346 <                if (n == 3)
1347 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1348 <                                        mult*xres, mult*yres, aspect);
1349 <                else if (n) {
1350 <                        if (n == 1) yres = xres;
1297 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1298 <                } else
1299 <                        badvalue(RESOLUTION);
1300 <        }
1341 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1342 >        if (n == 3)
1343 >                sprintf(res, "-x %d -y %d -pa %.3f",
1344 >                                mult*xres, mult*yres, aspect);
1345 >        else if (n) {
1346 >                aspect = 1.;
1347 >                if (n == 1) yres = xres;
1348 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1349 >        } else
1350 >                badvalue(RESOLUTION);
1351          rep[0] = '\0';
1352          if (vdef(REPORT)) {
1353                  double  minutes;
1304                int     n;
1354                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1355                  if (n == 2)
1356                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1316 | Line 1365 | rpict(                         /* run rpict and pfilt for each view */
1365                                          getview(0, vs) != NULL) {
1366                  if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1367                                  getview(1, NULL) == NULL) {
1368 <                        sprintf(sfile, "rpsync_%s.txt", vs);
1368 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1369 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1370 >                                        vs);
1371                          strcpy(rppopt, "-PP pfXXXXXX");
1372                  } else {
1373                          strcpy(rppopt, "-S 1 -PP pfXXXXXX");
# Line 1359 | Line 1410 | rpict(                         /* run rpict and pfilt for each view */
1410                  if (do_rpiece) {
1411                          if (rfdt < oct1date || !fdate(sfile)) {
1412                                  int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1413 <                                rfdt = 0;               /* start fresh */
1413 >                                if (rfdt >= oct1date) {
1414 >                                        fprintf(stderr,
1415 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1416 >                                        quit(1);
1417 >                                }
1418 >                                if (rfdt) {     /* start fresh */
1419 >                                        rmfile(rawfile);
1420 >                                        rfdt = 0;
1421 >                                }
1422                                  if (!silent)
1423                                          printf("\techo %d %d > %s\n",
1424                                                          xdiv, ydiv, sfile);
# Line 1396 | Line 1455 | rpict(                         /* run rpict and pfilt for each view */
1455                  } else {
1456                          if (overture) {         /* run overture calculation */
1457                                  sprintf(combuf,
1458 <                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1458 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1459                                                  c_rpict, rep, vw, opts,
1460                                                  oct1name, overfile);
1461 <                                if (do_rpiece)
1462 <                                        while (next_process(1))
1463 <                                                sleep(5);
1405 <                                if (runcom(combuf)) {
1406 <                                        fprintf(stderr,
1461 >                                if (!do_rpiece || !next_process(0)) {
1462 >                                        if (runcom(combuf)) {
1463 >                                                fprintf(stderr,
1464                                          "%s: error in overture for view %s\n",
1465 <                                                progname, vs);
1466 <                                        quit(1);
1467 <                                }
1411 <                                if (do_rpiece) {
1412 <                                        finish_process();
1413 <                                        wait_process(1);
1414 <                                }
1465 >                                                        progname, vs);
1466 >                                                quit(1);
1467 >                                        }
1468   #ifndef NULL_DEVICE
1469 <                                rmfile(overfile);
1469 >                                        rmfile(overfile);
1470   #endif
1471 +                                } else if (do_rpiece)
1472 +                                        sleep(20);
1473                          }
1474                          if (do_rpiece) {
1475                                  sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
# Line 1446 | Line 1501 | rpict(                         /* run rpict and pfilt for each view */
1501                  if (do_rpiece) {                /* need to finish raw, first */
1502                          finish_process();
1503                          wait_process(1);
1504 <                        /* XXX should check sync file to see if really done? */
1504 >                        if (!syncf_done(sfile)) {
1505 >                                fprintf(stderr,
1506 >                        "%s: %s did not complete rendering of view %s\n",
1507 >                                                progname, c_rpiece, vs);
1508 >                                quit(1);
1509 >                        }
1510                  }
1511                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1512                                                  /* build pfilt command */
1513 <                        if (mult > 1)
1513 >                        if (do_rpiece)
1514 >                                sprintf(combuf,
1515 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1516 >                                        c_pfilt, pfopts, xres, yres, aspect,
1517 >                                        rawfile, picfile);
1518 >                        else if (mult > 1)
1519                                  sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1520                                          c_pfilt, pfopts, mult, mult,
1521                                          rawfile, picfile);
# Line 1570 | Line 1635 | next_process(int reserve)              /* fork the next process */
1635          child_pid = fork();             /* split process */
1636          if (child_pid == 0) {           /* we're the child */
1637                  children_running = -1;
1638 +                nprocs = 1;
1639                  return(0);
1640          }
1641          if (child_pid > 0) {            /* we're the parent */
# Line 1637 | Line 1703 | finish_process(void)                   /* exit a child process */
1703                  return;                 /* in parent -- noop */
1704          exit(0);
1705   }
1640
1641 #ifdef _WIN32
1642 setenv(vname, value)            /* set an environment variable */
1643 char    *vname, *value;
1644 {
1645        register char   *evp;
1646
1647        evp = bmalloc(strlen(vname)+strlen(value)+2);
1648        if (evp == NULL)
1649                syserr(progname);
1650        sprintf(evp, "%s=%s", vname, value);
1651        if (putenv(evp) != 0) {
1652                fprintf(stderr, "%s: out of environment space\n", progname);
1653                quit(1);
1654        }
1655        if (!silent)
1656                printf("set %s\n", evp);
1657 }
1658 #endif
1706  
1707  
1708   static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines