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.92 by greg, Mon Feb 9 16:41:29 2009 UTC vs.
Revision 2.105 by greg, Fri Feb 25 06:51:51 2011 UTC

# Line 116 | Line 116 | int    sayview = 0;            /* print view out */
116   char    *rvdevice = NULL;       /* rvu output device */
117   char    *viewselect = NULL;     /* specific view only */
118  
119 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
120 +
121                                  /* command paths */
122   char    c_oconv[256] = "oconv";
123   char    c_mkillum[256] = "mkillum";
124   char    c_rvu[256] = "rvu";
125 < char    c_rpict[256] = "rpict";
125 > char    c_rpict[256] = DEF_RPICT_PATH;
126 > char    c_rpiece[] = "rpiece";
127   char    c_pfilt[256] = "pfilt";
128  
129   int     overture = 0;           /* overture calculation needed */
# Line 162 | Line 165 | static int touch(char  *fn);
165   static int runcom(char  *cs);
166   static int rmfile(char  *fn);
167   static int mvfile(char  *fold, char     *fnew);
168 < static int next_process(void);
168 > static int next_process(int     reserve);
169   static void wait_process(int    all);
170   static void finish_process(void);
171   static void badvalue(int        vc);
# Line 218 | Line 221 | main(
221          if (i >= argc)
222                  goto userr;
223          rifname = argv[i];
221                                /* check command-line options */
222        if ((nprocs > 1) & (viewselect != NULL) & (rvdevice == NULL))
223                nprocs = 1;
224                                  /* assign Radiance root file name */
225          rootname(radname, rifname);
226                                  /* load variable values */
# Line 751 | Line 751 | lowqopts(                      /* low quality rendering options */
751                  op = addarg(op, "-ds .4");
752          else
753                  op = addarg(op, "-ds 0");
754 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
754 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
755          if (vdef(AMBFILE)) {
756                  sprintf(op, " -af %s", vval(AMBFILE));
757                  op += strlen(op);
# Line 772 | Line 772 | lowqopts(                      /* low quality rendering options */
772          d = ambval();
773          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
774          op += strlen(op);
775 <        op = addarg(op, "-lr 6 -lw .01");
775 >        op = addarg(op, "-lr 6 -lw .003");
776   }
777  
778  
# Line 826 | Line 826 | medqopts(                      /* medium quality rendering options */
826                  op = addarg(op, "-ds .2 -dj .9");
827          else
828                  op = addarg(op, "-ds .3");
829 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
829 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
830          if ( (overture = vint(INDIRECT)) ) {
831                  sprintf(op, " -ab %d", overture);
832                  op += strlen(op);
# Line 850 | Line 850 | medqopts(                      /* medium quality rendering options */
850          d = ambval();
851          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
852          op += strlen(op);
853 <        op = addarg(op, "-lr 8 -lw .002");
853 >        op = addarg(op, "-lr 8 -lw 1e-4");
854   }
855  
856  
# Line 904 | Line 904 | hiqopts(                               /* high quality rendering options */
904                  op = addarg(op, "-ds .1 -dj .9");
905          else
906                  op = addarg(op, "-ds .2");
907 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
907 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
908          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
909          op += strlen(op);
910          if (vdef(AMBFILE)) {
# Line 926 | Line 926 | hiqopts(                               /* high quality rendering options */
926          d = ambval();
927          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
928          op += strlen(op);
929 <        op = addarg(op, "-lr 12 -lw .0005");
929 >        op = addarg(op, "-lr 12 -lw 1e-5");
930   }
931  
932  
# Line 1158 | Line 1158 | getview(                               /* get view n, or NULL if none */
1158                          goto numview;
1159                  }
1160                  if (viewselect[0] == '-') {     /* already specified */
1161 <                        if (vn != NULL) *vn = '\0';
1161 >                        if (vn != NULL)
1162 >                                strcpy(vn, "0");
1163                          return(viewselect);
1164                  }
1165                  if (vn != NULL) {
# Line 1259 | Line 1260 | rpict(                         /* run rpict and pfilt for each view */
1260          char    *po
1261   )
1262   {
1263 <        char    combuf[PATH_MAX];
1263 > #define do_rpiece       (sfile[0]!='\0')
1264 >        char    combuf[5*PATH_MAX+512];
1265          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1266          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1267 <        char    rppopt[128], *pfile = NULL;
1267 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1268          char    pfopts[128];
1269          char    vs[32], *vw;
1270          int     vn, mult;
1271          FILE    *fp;
1272          time_t  rfdt, pfdt;
1273 +        int     xres, yres;
1274 +        double  aspect;
1275 +        int     n;
1276                                          /* get pfilt options */
1277          pfiltopts(pfopts);
1278                                          /* get resolution, reporting */
# Line 1282 | Line 1287 | rpict(                         /* run rpict and pfilt for each view */
1287                  mult = 3;
1288                  break;
1289          }
1290 <        {
1291 <                int     xres, yres;
1292 <                double  aspect;
1293 <                int     n;
1294 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1295 <                if (n == 3)
1296 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1297 <                                        mult*xres, mult*yres, aspect);
1298 <                else if (n) {
1299 <                        if (n == 1) yres = xres;
1295 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1296 <                } else
1297 <                        badvalue(RESOLUTION);
1298 <        }
1290 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1291 >        if (n == 3)
1292 >                sprintf(res, "-x %d -y %d -pa %.3f",
1293 >                                mult*xres, mult*yres, aspect);
1294 >        else if (n) {
1295 >                aspect = 1.;
1296 >                if (n == 1) yres = xres;
1297 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1298 >        } else
1299 >                badvalue(RESOLUTION);
1300          rep[0] = '\0';
1301          if (vdef(REPORT)) {
1302                  double  minutes;
1302                int     n;
1303                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1304                  if (n == 2)
1305                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1309 | Line 1309 | rpict(                         /* run rpict and pfilt for each view */
1309                          badvalue(REPORT);
1310          }
1311                                          /* set up parallel rendering */
1312 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1313 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1314 <                pfile = rppopt+9;
1315 <                if (mktemp(pfile) == NULL)
1312 >        sfile[0] = '\0';
1313 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1314 >                                        getview(0, vs) != NULL) {
1315 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1316 >                                getview(1, NULL) == NULL) {
1317 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1318 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1319 >                                        vs);
1320 >                        strcpy(rppopt, "-PP pfXXXXXX");
1321 >                } else {
1322 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1323 >                }
1324 >                pfile = rppopt + strlen(rppopt) - 8;
1325 >                if (mktemp(pfile) == NULL) {
1326 >                        if (do_rpiece) {
1327 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1328 >                                quit(1);
1329 >                        }
1330                          pfile = NULL;
1331 +                }
1332          }
1333          vn = 0;                                 /* do each view */
1334          while ((vw = getview(vn++, vs)) != NULL) {
1335                  if (sayview)
1336                          myprintview(vw, stdout);
1322                if (!vs[0])
1323                        sprintf(vs, "%d", vn);
1337                  sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1338                  if (vdef(ZFILE))
1339                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
# Line 1342 | Line 1355 | rpict(                         /* run rpict and pfilt for each view */
1355                                  touch(picfile);
1356                          continue;
1357                  }
1358 <                if (next_process()) {           /* parallel running? */
1358 >                                                /* parallel running? */
1359 >                if (do_rpiece) {
1360 >                        if (rfdt < oct1date || !fdate(sfile)) {
1361 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1362 >                                if (rfdt >= oct1date) {
1363 >                                        fprintf(stderr,
1364 >                "%s: partial output not created with rpiece\n", rawfile);
1365 >                                        quit(1);
1366 >                                }
1367 >                                if (rfdt) {     /* start fresh */
1368 >                                        rmfile(rawfile);
1369 >                                        rfdt = 0;
1370 >                                }
1371 >                                if (!silent)
1372 >                                        printf("\techo %d %d > %s\n",
1373 >                                                        xdiv, ydiv, sfile);
1374 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1375 >                                        fprintf(stderr, "%s: cannot create\n",
1376 >                                                        sfile);
1377 >                                        quit(1);
1378 >                                }
1379 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1380 >                                fclose(fp);
1381 >                        }
1382 >                } else if (next_process(0)) {
1383                          if (pfile != NULL)
1384 <                                sleep(20);
1384 >                                sleep(10);
1385                          continue;
1386 <                }
1386 >                } else if (!inchild())
1387 >                        pfile = NULL;
1388                  /* XXX Remember to call finish_process() */
1389                                                  /* build rpict command */
1390 <                if (rfdt >= oct1date) {         /* recover */
1391 <                        sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1392 <                                rep, opts, po, zopt, rawfile, oct1name);
1393 <                        if (runcom(combuf))     /* run rpict */
1390 >                if (rfdt >= oct1date) {         /* already in progress */
1391 >                        if (do_rpiece) {
1392 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1393 >                                                c_rpiece, sfile, rppopt, rep, vw,
1394 >                                                res, opts, po, rawfile, oct1name);
1395 >                                while (next_process(1)) {
1396 >                                        sleep(10);
1397 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1398 >                                }
1399 >                        } else
1400 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1401 >                                        rep, opts, po, zopt, rawfile, oct1name);
1402 >                        if (runcom(combuf))     /* run rpict/rpiece */
1403                                  goto rperror;
1404                  } else {
1405                          if (overture) {         /* run overture calculation */
1406                                  sprintf(combuf,
1407 <                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1407 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1408                                                  c_rpict, rep, vw, opts,
1409                                                  oct1name, overfile);
1410 <                                if (runcom(combuf)) {
1411 <                                        fprintf(stderr,
1410 >                                if (!do_rpiece || !next_process(0)) {
1411 >                                        if (runcom(combuf)) {
1412 >                                                fprintf(stderr,
1413                                          "%s: error in overture for view %s\n",
1414 <                                                progname, vs);
1415 <                                        quit(1);
1416 <                                }
1414 >                                                        progname, vs);
1415 >                                                quit(1);
1416 >                                        }
1417   #ifndef NULL_DEVICE
1418 <                                rmfile(overfile);
1418 >                                        rmfile(overfile);
1419   #endif
1420 +                                } else if (do_rpiece)
1421 +                                        sleep(20);
1422                          }
1423 <                        sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1424 <                                        c_rpict, rep, vw, res, opts, po,
1425 <                                        zopt, oct1name, rawfile);
1426 <                        if (pfile != NULL && inchild()) {
1427 <                                                /* rpict persistent mode */
1423 >                        if (do_rpiece) {
1424 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1425 >                                                c_rpiece, sfile, rppopt, rep, vw,
1426 >                                                res, opts, po, rawfile, oct1name);
1427 >                                while (next_process(1))
1428 >                                        sleep(10);
1429 >                        } else {
1430 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1431 >                                                c_rpict, rep, vw, res, opts, po,
1432 >                                                zopt, oct1name, rawfile);
1433 >                        }
1434 >                        if ((pfile != NULL) & !do_rpiece) {
1435                                  if (!silent)
1436                                          printf("\t%s\n", combuf);
1437                                  fflush(stdout);
1438                                  sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1439 <                                                c_rpict, rep, rppopt, res, opts,
1440 <                                                po, oct1name, rawfile);
1439 >                                                c_rpict, rep, rppopt, res,
1440 >                                                opts, po, oct1name, rawfile);
1441                                  fp = popen(combuf, "w");
1442                                  if (fp == NULL)
1443                                          goto rperror;
1444                                  myprintview(vw, fp);
1445                                  if (pclose(fp))
1446                                          goto rperror;
1447 <                        } else {                /* rpict normal mode */
1448 <                                if (runcom(combuf))
1392 <                                        goto rperror;
1393 <                        }
1447 >                        } else if (runcom(combuf))
1448 >                                goto rperror;
1449                  }
1450 +                if (do_rpiece) {                /* need to finish raw, first */
1451 +                        finish_process();
1452 +                        wait_process(1);
1453 +                        /* XXX should check sync file to see if really done? */
1454 +                }
1455                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1456                                                  /* build pfilt command */
1457 <                        if (mult > 1)
1457 >                        if (do_rpiece)
1458 >                                sprintf(combuf,
1459 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1460 >                                        c_pfilt, pfopts, xres, yres, aspect,
1461 >                                        rawfile, picfile);
1462 >                        else if (mult > 1)
1463                                  sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1464                                          c_pfilt, pfopts, mult, mult,
1465                                          rawfile, picfile);
# Line 1415 | Line 1480 | rpict(                         /* run rpict and pfilt for each view */
1480                          mvfile(rawfile, combuf);
1481                  } else
1482                          rmfile(rawfile);
1483 <                finish_process();               /* exit if child */
1483 >                if (do_rpiece)                  /* done with sync file */
1484 >                        rmfile(sfile);
1485 >                else
1486 >                        finish_process();       /* exit if child */
1487          }
1488          wait_process(1);                /* wait for children to finish */
1489 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1489 >        if (pfile != NULL) {            /* clean up persistent rpict */
1490                  RT_PID  pid;
1491                  fp = fopen(pfile, "r");
1492                  if (fp != NULL) {
# Line 1432 | Line 1500 | rpict(                         /* run rpict and pfilt for each view */
1500   rperror:
1501          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1502          quit(1);
1503 + #undef do_rpiece
1504   }
1505  
1506  
# Line 1444 | Line 1513 | touch(                 /* update a file */
1513                  printf("\ttouch %s\n", fn);
1514          if (!nprocs)
1515                  return(0);
1447 #ifdef notused
1448        if (access(fn, F_OK) == -1)             /* create it */
1449                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1450                        return(-1);
1451 #endif
1516          return(setfdate(fn, time((time_t *)NULL)));
1517   }
1518  
# Line 1496 | Line 1560 | mvfile(                /* move a file */
1560  
1561   #ifdef RHAS_FORK_EXEC
1562   static int
1563 < next_process(void)                      /* fork the next process (max. nprocs) */
1563 > next_process(int reserve)               /* fork the next process */
1564   {
1565          RT_PID  child_pid;
1566  
# Line 1507 | Line 1571 | next_process(void)                     /* fork the next process (max. np
1571                                  progname);
1572                  quit(1);
1573          }
1574 +        if (reserve > 0 && children_running >= nprocs-reserve)
1575 +                return(0);              /* caller holding back process(es) */
1576          if (children_running >= nprocs)
1577                  wait_process(0);        /* wait for someone to finish */
1578          fflush(NULL);                   /* flush output */
1579          child_pid = fork();             /* split process */
1580          if (child_pid == 0) {           /* we're the child */
1581                  children_running = -1;
1582 +                nprocs = 1;
1583                  return(0);
1584          }
1585          if (child_pid > 0) {            /* we're the parent */
# Line 1554 | Line 1621 | wait_process(                  /* wait for process(es) to finish */
1621   }
1622   #else   /* ! RHAS_FORK_EXEC */
1623   static int
1624 < next_process(void)
1624 > next_process(int reserve)
1625   {
1626          return(0);                      /* cannot start new process */
1627   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines