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.91 by greg, Thu Dec 18 23:26:57 2008 UTC vs.
Revision 2.102 by greg, Sun Oct 10 09:25:45 2010 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 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 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 1123 | Line 1123 | specview(                              /* get proper view spec from vs */
1123                  while (!isspace(*vs))           /* else skip id */
1124                          if (!*vs++)
1125                                  return(NULL);
1126 <                if (upax) {                     /* specify up vector */
1126 >                if (upax) {                     /* prepend up vector */
1127                          strcpy(cp, vup[upax+3]);
1128                          cp += strlen(cp);
1129                  }
# Line 1152 | Line 1152 | getview(                               /* get view n, or NULL if none */
1152          if (viewselect != NULL) {               /* command-line selected */
1153                  if (n)                          /* only do one */
1154                          return(NULL);
1155 +                                        
1156 +                if (isint(viewselect)) {        /* view number? */
1157 +                        n = atoi(viewselect)-1;
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 1162 | Line 1168 | getview(                               /* get view n, or NULL if none */
1168                                  ;
1169                          *vn = '\0';
1170                  }
1165                                                /* view number? */
1166                if (isint(viewselect))
1167                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1171                                                  /* check list */
1172                  while ((mv = nvalue(VIEWS, n++)) != NULL)
1173                          if (matchword(viewselect, mv))
1174                                  return(specview(mv));
1175 +
1176                  return(specview(viewselect));   /* standard view? */
1177          }
1178 + numview:
1179          mv = nvalue(VIEWS, n);          /* use view n */
1180 <        if ((vn != NULL) & (mv != NULL)) {
1181 <                register char   *mv2 = mv;
1182 <                if (*mv2 != '-')
1180 >        if ((vn != NULL) & (mv != NULL))
1181 >                if (*mv != '-') {
1182 >                        register char   *mv2 = mv;
1183                          while (*mv2 && !isspace(*mv2))
1184                                  *vn++ = *mv2++;
1185 <                *vn = '\0';
1186 <        }
1185 >                        *vn = '\0';
1186 >                } else
1187 >                        sprintf(vn, "%d", n+1);
1188 >
1189          return(specview(mv));
1190   }
1191  
# Line 1253 | 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;
# Line 1303 | Line 1311 | rpict(                         /* run rpict and pfilt for each view */
1311                          badvalue(REPORT);
1312          }
1313                                          /* set up parallel rendering */
1314 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1315 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1316 <                pfile = rppopt+9;
1317 <                if (mktemp(pfile) == NULL)
1314 >        sfile[0] = '\0';
1315 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1316 >                                        getview(0, vs) != NULL) {
1317 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1318 >                                getview(1, NULL) == NULL) {
1319 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1320 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1321 >                                        vs);
1322 >                        strcpy(rppopt, "-PP pfXXXXXX");
1323 >                } else {
1324 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1325 >                }
1326 >                pfile = rppopt + strlen(rppopt) - 8;
1327 >                if (mktemp(pfile) == NULL) {
1328 >                        if (do_rpiece) {
1329 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1330 >                                quit(1);
1331 >                        }
1332                          pfile = NULL;
1333 +                }
1334          }
1335          vn = 0;                                 /* do each view */
1336          while ((vw = getview(vn++, vs)) != NULL) {
1337                  if (sayview)
1338                          myprintview(vw, stdout);
1316                if (!vs[0])
1317                        sprintf(vs, "%d", vn);
1339                  sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1340                  if (vdef(ZFILE))
1341                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
# Line 1336 | Line 1357 | rpict(                         /* run rpict and pfilt for each view */
1357                                  touch(picfile);
1358                          continue;
1359                  }
1360 <                if (next_process()) {           /* parallel running? */
1360 >                                                /* parallel running? */
1361 >                if (do_rpiece) {
1362 >                        if (rfdt < oct1date || !fdate(sfile)) {
1363 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1364 >                                if (rfdt >= oct1date) {
1365 >                                        fprintf(stderr,
1366 >                "%s: partial output not created with rpiece\n", rawfile);
1367 >                                        quit(1);
1368 >                                }
1369 >                                rfdt = 0;               /* start fresh */
1370 >                                if (!silent)
1371 >                                        printf("\techo %d %d > %s\n",
1372 >                                                        xdiv, ydiv, sfile);
1373 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1374 >                                        fprintf(stderr, "%s: cannot create\n",
1375 >                                                        sfile);
1376 >                                        quit(1);
1377 >                                }
1378 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1379 >                                fclose(fp);
1380 >                        }
1381 >                } else if (next_process(0)) {
1382                          if (pfile != NULL)
1383 <                                sleep(20);
1383 >                                sleep(10);
1384                          continue;
1385 <                }
1385 >                } else if (!inchild())
1386 >                        pfile = NULL;
1387                  /* XXX Remember to call finish_process() */
1388                                                  /* build rpict command */
1389 <                if (rfdt >= oct1date) {         /* recover */
1390 <                        sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1391 <                                rep, opts, po, zopt, rawfile, oct1name);
1392 <                        if (runcom(combuf))     /* run rpict */
1389 >                if (rfdt >= oct1date) {         /* already in progress */
1390 >                        if (do_rpiece) {
1391 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1392 >                                                c_rpiece, sfile, rppopt, rep, vw,
1393 >                                                res, opts, po, rawfile, oct1name);
1394 >                                while (next_process(1)) {
1395 >                                        sleep(10);
1396 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1397 >                                }
1398 >                        } else
1399 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1400 >                                        rep, opts, po, zopt, rawfile, oct1name);
1401 >                        if (runcom(combuf))     /* run rpict/rpiece */
1402                                  goto rperror;
1403                  } else {
1404                          if (overture) {         /* run overture calculation */
1405                                  sprintf(combuf,
1406 <                                "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1406 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1407                                                  c_rpict, rep, vw, opts,
1408                                                  oct1name, overfile);
1409 <                                if (runcom(combuf)) {
1410 <                                        fprintf(stderr,
1409 >                                if (!do_rpiece || !next_process(0)) {
1410 >                                        if (runcom(combuf)) {
1411 >                                                fprintf(stderr,
1412                                          "%s: error in overture for view %s\n",
1413 <                                                progname, vs);
1414 <                                        quit(1);
1415 <                                }
1413 >                                                        progname, vs);
1414 >                                                quit(1);
1415 >                                        }
1416   #ifndef NULL_DEVICE
1417 <                                rmfile(overfile);
1417 >                                        rmfile(overfile);
1418   #endif
1419 +                                } else if (do_rpiece)
1420 +                                        sleep(20);
1421                          }
1422 <                        sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1423 <                                        c_rpict, rep, vw, res, opts, po,
1424 <                                        zopt, oct1name, rawfile);
1425 <                        if (pfile != NULL && inchild()) {
1426 <                                                /* rpict persistent mode */
1422 >                        if (do_rpiece) {
1423 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1424 >                                                c_rpiece, sfile, rppopt, rep, vw,
1425 >                                                res, opts, po, rawfile, oct1name);
1426 >                                while (next_process(1))
1427 >                                        sleep(10);
1428 >                        } else {
1429 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1430 >                                                c_rpict, rep, vw, res, opts, po,
1431 >                                                zopt, oct1name, rawfile);
1432 >                        }
1433 >                        if ((pfile != NULL) & !do_rpiece) {
1434                                  if (!silent)
1435                                          printf("\t%s\n", combuf);
1436                                  fflush(stdout);
1437                                  sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1438 <                                                c_rpict, rep, rppopt, res, opts,
1439 <                                                po, oct1name, rawfile);
1438 >                                                c_rpict, rep, rppopt, res,
1439 >                                                opts, po, oct1name, rawfile);
1440                                  fp = popen(combuf, "w");
1441                                  if (fp == NULL)
1442                                          goto rperror;
1443                                  myprintview(vw, fp);
1444                                  if (pclose(fp))
1445                                          goto rperror;
1446 <                        } else {                /* rpict normal mode */
1447 <                                if (runcom(combuf))
1386 <                                        goto rperror;
1387 <                        }
1446 >                        } else if (runcom(combuf))
1447 >                                goto rperror;
1448                  }
1449 +                if (do_rpiece) {                /* need to finish raw, first */
1450 +                        finish_process();
1451 +                        wait_process(1);
1452 +                        /* XXX should check sync file to see if really done? */
1453 +                }
1454                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1455                                                  /* build pfilt command */
1456                          if (mult > 1)
# Line 1409 | Line 1474 | rpict(                         /* run rpict and pfilt for each view */
1474                          mvfile(rawfile, combuf);
1475                  } else
1476                          rmfile(rawfile);
1477 <                finish_process();               /* exit if child */
1477 >                if (do_rpiece)                  /* done with sync file */
1478 >                        rmfile(sfile);
1479 >                else
1480 >                        finish_process();       /* exit if child */
1481          }
1482          wait_process(1);                /* wait for children to finish */
1483 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1483 >        if (pfile != NULL) {            /* clean up persistent rpict */
1484                  RT_PID  pid;
1485                  fp = fopen(pfile, "r");
1486                  if (fp != NULL) {
# Line 1426 | Line 1494 | rpict(                         /* run rpict and pfilt for each view */
1494   rperror:
1495          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1496          quit(1);
1497 + #undef do_rpiece
1498   }
1499  
1500  
# Line 1438 | Line 1507 | touch(                 /* update a file */
1507                  printf("\ttouch %s\n", fn);
1508          if (!nprocs)
1509                  return(0);
1441 #ifdef notused
1442        if (access(fn, F_OK) == -1)             /* create it */
1443                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1444                        return(-1);
1445 #endif
1510          return(setfdate(fn, time((time_t *)NULL)));
1511   }
1512  
# Line 1490 | Line 1554 | mvfile(                /* move a file */
1554  
1555   #ifdef RHAS_FORK_EXEC
1556   static int
1557 < next_process(void)                      /* fork the next process (max. nprocs) */
1557 > next_process(int reserve)               /* fork the next process */
1558   {
1559          RT_PID  child_pid;
1560  
# Line 1501 | Line 1565 | next_process(void)                     /* fork the next process (max. np
1565                                  progname);
1566                  quit(1);
1567          }
1568 +        if (reserve > 0 && children_running >= nprocs-reserve)
1569 +                return(0);              /* caller holding back process(es) */
1570          if (children_running >= nprocs)
1571                  wait_process(0);        /* wait for someone to finish */
1572          fflush(NULL);                   /* flush output */
1573          child_pid = fork();             /* split process */
1574          if (child_pid == 0) {           /* we're the child */
1575                  children_running = -1;
1576 +                nprocs = 1;
1577                  return(0);
1578          }
1579          if (child_pid > 0) {            /* we're the parent */
# Line 1548 | Line 1615 | wait_process(                  /* wait for process(es) to finish */
1615   }
1616   #else   /* ! RHAS_FORK_EXEC */
1617   static int
1618 < next_process(void)
1618 > next_process(int reserve)
1619   {
1620          return(0);                      /* cannot start new process */
1621   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines