| 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 */ |
| 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); |
| 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 */ |
| 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); |
| 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 |
|
|
| 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); |
| 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 |
|
|
| 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)) { |
| 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 |
|
|
| 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) { |
| 1254 |
|
} |
| 1255 |
|
|
| 1256 |
|
|
| 1257 |
+ |
static int |
| 1258 |
+ |
syncf_done( /* check if an rpiece sync file is complete */ |
| 1259 |
+ |
char *sfname |
| 1260 |
+ |
) |
| 1261 |
+ |
{ |
| 1262 |
+ |
FILE *fp = fopen(sfname, "r"); |
| 1263 |
+ |
int todo = 1; |
| 1264 |
+ |
int x, y; |
| 1265 |
+ |
|
| 1266 |
+ |
if (fp == NULL) |
| 1267 |
+ |
return(0); |
| 1268 |
+ |
if (fscanf(fp, "%d %d", &x, &y) != 2) |
| 1269 |
+ |
goto checked; |
| 1270 |
+ |
todo = x*y; /* total number of tiles */ |
| 1271 |
+ |
if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0)) |
| 1272 |
+ |
goto checked; |
| 1273 |
+ |
/* XXX assume no redundant tiles */ |
| 1274 |
+ |
while (fscanf(fp, "%d %d", &x, &y) == 2) |
| 1275 |
+ |
if (!--todo) |
| 1276 |
+ |
break; |
| 1277 |
+ |
checked: |
| 1278 |
+ |
fclose(fp); |
| 1279 |
+ |
return(!todo); |
| 1280 |
+ |
} |
| 1281 |
+ |
|
| 1282 |
+ |
|
| 1283 |
|
static void |
| 1284 |
|
rpict( /* run rpict and pfilt for each view */ |
| 1285 |
|
char *opts, |
| 1286 |
|
char *po |
| 1287 |
|
) |
| 1288 |
|
{ |
| 1289 |
< |
char combuf[PATH_MAX]; |
| 1289 |
> |
#define do_rpiece (sfile[0]!='\0') |
| 1290 |
> |
char combuf[5*PATH_MAX+512]; |
| 1291 |
|
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
| 1292 |
|
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
| 1293 |
< |
char rppopt[128], *pfile = NULL; |
| 1293 |
> |
char rppopt[32], sfile[PATH_MAX], *pfile = NULL; |
| 1294 |
|
char pfopts[128]; |
| 1295 |
|
char vs[32], *vw; |
| 1296 |
|
int vn, mult; |
| 1297 |
|
FILE *fp; |
| 1298 |
|
time_t rfdt, pfdt; |
| 1299 |
+ |
int xres, yres; |
| 1300 |
+ |
double aspect; |
| 1301 |
+ |
int n; |
| 1302 |
|
/* get pfilt options */ |
| 1303 |
|
pfiltopts(pfopts); |
| 1304 |
|
/* get resolution, reporting */ |
| 1313 |
|
mult = 3; |
| 1314 |
|
break; |
| 1315 |
|
} |
| 1316 |
< |
{ |
| 1317 |
< |
int xres, yres; |
| 1318 |
< |
double aspect; |
| 1319 |
< |
int n; |
| 1320 |
< |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
| 1321 |
< |
if (n == 3) |
| 1322 |
< |
sprintf(res, "-x %d -y %d -pa %.3f", |
| 1323 |
< |
mult*xres, mult*yres, aspect); |
| 1324 |
< |
else if (n) { |
| 1325 |
< |
if (n == 1) yres = xres; |
| 1295 |
< |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
| 1296 |
< |
} else |
| 1297 |
< |
badvalue(RESOLUTION); |
| 1298 |
< |
} |
| 1316 |
> |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
| 1317 |
> |
if (n == 3) |
| 1318 |
> |
sprintf(res, "-x %d -y %d -pa %.3f", |
| 1319 |
> |
mult*xres, mult*yres, aspect); |
| 1320 |
> |
else if (n) { |
| 1321 |
> |
aspect = 1.; |
| 1322 |
> |
if (n == 1) yres = xres; |
| 1323 |
> |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
| 1324 |
> |
} else |
| 1325 |
> |
badvalue(RESOLUTION); |
| 1326 |
|
rep[0] = '\0'; |
| 1327 |
|
if (vdef(REPORT)) { |
| 1328 |
|
double minutes; |
| 1302 |
– |
int n; |
| 1329 |
|
n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); |
| 1330 |
|
if (n == 2) |
| 1331 |
|
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
| 1335 |
|
badvalue(REPORT); |
| 1336 |
|
} |
| 1337 |
|
/* set up parallel rendering */ |
| 1338 |
< |
if ((nprocs > 1) & (!vdef(ZFILE))) { |
| 1339 |
< |
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
| 1340 |
< |
pfile = rppopt+9; |
| 1341 |
< |
if (mktemp(pfile) == NULL) |
| 1338 |
> |
sfile[0] = '\0'; |
| 1339 |
> |
if ((nprocs > 1) & !touchonly & !vdef(ZFILE) && |
| 1340 |
> |
getview(0, vs) != NULL) { |
| 1341 |
> |
if (!strcmp(c_rpict, DEF_RPICT_PATH) && |
| 1342 |
> |
getview(1, NULL) == NULL) { |
| 1343 |
> |
sprintf(sfile, "%s_%s_rpsync.txt", |
| 1344 |
> |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), |
| 1345 |
> |
vs); |
| 1346 |
> |
strcpy(rppopt, "-PP pfXXXXXX"); |
| 1347 |
> |
} else { |
| 1348 |
> |
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
| 1349 |
> |
} |
| 1350 |
> |
pfile = rppopt + strlen(rppopt) - 8; |
| 1351 |
> |
if (mktemp(pfile) == NULL) { |
| 1352 |
> |
if (do_rpiece) { |
| 1353 |
> |
fprintf(stderr, "%s: cannot create\n", pfile); |
| 1354 |
> |
quit(1); |
| 1355 |
> |
} |
| 1356 |
|
pfile = NULL; |
| 1357 |
+ |
} |
| 1358 |
|
} |
| 1359 |
|
vn = 0; /* do each view */ |
| 1360 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
| 1361 |
|
if (sayview) |
| 1362 |
|
myprintview(vw, stdout); |
| 1322 |
– |
if (!vs[0]) |
| 1323 |
– |
sprintf(vs, "%d", vn); |
| 1363 |
|
sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs); |
| 1364 |
|
if (vdef(ZFILE)) |
| 1365 |
|
sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); |
| 1381 |
|
touch(picfile); |
| 1382 |
|
continue; |
| 1383 |
|
} |
| 1384 |
< |
if (next_process()) { /* parallel running? */ |
| 1384 |
> |
/* parallel running? */ |
| 1385 |
> |
if (do_rpiece) { |
| 1386 |
> |
if (rfdt < oct1date || !fdate(sfile)) { |
| 1387 |
> |
int xdiv = 8+nprocs/3, ydiv = 8+nprocs/3; |
| 1388 |
> |
if (rfdt >= oct1date) { |
| 1389 |
> |
fprintf(stderr, |
| 1390 |
> |
"%s: partial output not created with rpiece\n", rawfile); |
| 1391 |
> |
quit(1); |
| 1392 |
> |
} |
| 1393 |
> |
if (rfdt) { /* start fresh */ |
| 1394 |
> |
rmfile(rawfile); |
| 1395 |
> |
rfdt = 0; |
| 1396 |
> |
} |
| 1397 |
> |
if (!silent) |
| 1398 |
> |
printf("\techo %d %d > %s\n", |
| 1399 |
> |
xdiv, ydiv, sfile); |
| 1400 |
> |
if ((fp = fopen(sfile, "w")) == NULL) { |
| 1401 |
> |
fprintf(stderr, "%s: cannot create\n", |
| 1402 |
> |
sfile); |
| 1403 |
> |
quit(1); |
| 1404 |
> |
} |
| 1405 |
> |
fprintf(fp, "%d %d\n", xdiv, ydiv); |
| 1406 |
> |
fclose(fp); |
| 1407 |
> |
} |
| 1408 |
> |
} else if (next_process(0)) { |
| 1409 |
|
if (pfile != NULL) |
| 1410 |
< |
sleep(20); |
| 1410 |
> |
sleep(10); |
| 1411 |
|
continue; |
| 1412 |
< |
} |
| 1412 |
> |
} else if (!inchild()) |
| 1413 |
> |
pfile = NULL; |
| 1414 |
|
/* XXX Remember to call finish_process() */ |
| 1415 |
|
/* build rpict command */ |
| 1416 |
< |
if (rfdt >= oct1date) { /* recover */ |
| 1417 |
< |
sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, |
| 1418 |
< |
rep, opts, po, zopt, rawfile, oct1name); |
| 1419 |
< |
if (runcom(combuf)) /* run rpict */ |
| 1416 |
> |
if (rfdt >= oct1date) { /* already in progress */ |
| 1417 |
> |
if (do_rpiece) { |
| 1418 |
> |
sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s", |
| 1419 |
> |
c_rpiece, sfile, rppopt, rep, vw, |
| 1420 |
> |
res, opts, po, rawfile, oct1name); |
| 1421 |
> |
while (next_process(1)) { |
| 1422 |
> |
sleep(10); |
| 1423 |
> |
combuf[strlen(c_rpiece)+2] = 'F'; |
| 1424 |
> |
} |
| 1425 |
> |
} else |
| 1426 |
> |
sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, |
| 1427 |
> |
rep, opts, po, zopt, rawfile, oct1name); |
| 1428 |
> |
if (runcom(combuf)) /* run rpict/rpiece */ |
| 1429 |
|
goto rperror; |
| 1430 |
|
} else { |
| 1431 |
|
if (overture) { /* run overture calculation */ |
| 1432 |
|
sprintf(combuf, |
| 1433 |
< |
"%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
| 1433 |
> |
"%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
| 1434 |
|
c_rpict, rep, vw, opts, |
| 1435 |
|
oct1name, overfile); |
| 1436 |
< |
if (runcom(combuf)) { |
| 1437 |
< |
fprintf(stderr, |
| 1436 |
> |
if (!do_rpiece || !next_process(0)) { |
| 1437 |
> |
if (runcom(combuf)) { |
| 1438 |
> |
fprintf(stderr, |
| 1439 |
|
"%s: error in overture for view %s\n", |
| 1440 |
< |
progname, vs); |
| 1441 |
< |
quit(1); |
| 1442 |
< |
} |
| 1440 |
> |
progname, vs); |
| 1441 |
> |
quit(1); |
| 1442 |
> |
} |
| 1443 |
|
#ifndef NULL_DEVICE |
| 1444 |
< |
rmfile(overfile); |
| 1444 |
> |
rmfile(overfile); |
| 1445 |
|
#endif |
| 1446 |
+ |
} else if (do_rpiece) |
| 1447 |
+ |
sleep(20); |
| 1448 |
|
} |
| 1449 |
< |
sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", |
| 1450 |
< |
c_rpict, rep, vw, res, opts, po, |
| 1451 |
< |
zopt, oct1name, rawfile); |
| 1452 |
< |
if (pfile != NULL && inchild()) { |
| 1453 |
< |
/* rpict persistent mode */ |
| 1449 |
> |
if (do_rpiece) { |
| 1450 |
> |
sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s", |
| 1451 |
> |
c_rpiece, sfile, rppopt, rep, vw, |
| 1452 |
> |
res, opts, po, rawfile, oct1name); |
| 1453 |
> |
while (next_process(1)) |
| 1454 |
> |
sleep(10); |
| 1455 |
> |
} else { |
| 1456 |
> |
sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", |
| 1457 |
> |
c_rpict, rep, vw, res, opts, po, |
| 1458 |
> |
zopt, oct1name, rawfile); |
| 1459 |
> |
} |
| 1460 |
> |
if ((pfile != NULL) & !do_rpiece) { |
| 1461 |
|
if (!silent) |
| 1462 |
|
printf("\t%s\n", combuf); |
| 1463 |
|
fflush(stdout); |
| 1464 |
|
sprintf(combuf, "%s%s %s %s%s%s %s > %s", |
| 1465 |
< |
c_rpict, rep, rppopt, res, opts, |
| 1466 |
< |
po, oct1name, rawfile); |
| 1465 |
> |
c_rpict, rep, rppopt, res, |
| 1466 |
> |
opts, po, oct1name, rawfile); |
| 1467 |
|
fp = popen(combuf, "w"); |
| 1468 |
|
if (fp == NULL) |
| 1469 |
|
goto rperror; |
| 1470 |
|
myprintview(vw, fp); |
| 1471 |
|
if (pclose(fp)) |
| 1472 |
|
goto rperror; |
| 1473 |
< |
} else { /* rpict normal mode */ |
| 1474 |
< |
if (runcom(combuf)) |
| 1475 |
< |
goto rperror; |
| 1473 |
> |
} else if (runcom(combuf)) |
| 1474 |
> |
goto rperror; |
| 1475 |
> |
} |
| 1476 |
> |
if (do_rpiece) { /* need to finish raw, first */ |
| 1477 |
> |
finish_process(); |
| 1478 |
> |
wait_process(1); |
| 1479 |
> |
if (!syncf_done(sfile)) { |
| 1480 |
> |
fprintf(stderr, |
| 1481 |
> |
"%s: rpiece did not complete rendering of view %s\n", |
| 1482 |
> |
progname, vs); |
| 1483 |
> |
quit(1); |
| 1484 |
|
} |
| 1485 |
|
} |
| 1486 |
|
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
| 1487 |
|
/* build pfilt command */ |
| 1488 |
< |
if (mult > 1) |
| 1488 |
> |
if (do_rpiece) |
| 1489 |
> |
sprintf(combuf, |
| 1490 |
> |
"%s%s -x %d -y %d -p %.3f %s > %s", |
| 1491 |
> |
c_pfilt, pfopts, xres, yres, aspect, |
| 1492 |
> |
rawfile, picfile); |
| 1493 |
> |
else if (mult > 1) |
| 1494 |
|
sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", |
| 1495 |
|
c_pfilt, pfopts, mult, mult, |
| 1496 |
|
rawfile, picfile); |
| 1511 |
|
mvfile(rawfile, combuf); |
| 1512 |
|
} else |
| 1513 |
|
rmfile(rawfile); |
| 1514 |
< |
finish_process(); /* exit if child */ |
| 1514 |
> |
if (do_rpiece) /* done with sync file */ |
| 1515 |
> |
rmfile(sfile); |
| 1516 |
> |
else |
| 1517 |
> |
finish_process(); /* exit if child */ |
| 1518 |
|
} |
| 1519 |
|
wait_process(1); /* wait for children to finish */ |
| 1520 |
< |
if (pfile != NULL) { /* clean up rpict persistent mode */ |
| 1520 |
> |
if (pfile != NULL) { /* clean up persistent rpict */ |
| 1521 |
|
RT_PID pid; |
| 1522 |
|
fp = fopen(pfile, "r"); |
| 1523 |
|
if (fp != NULL) { |
| 1531 |
|
rperror: |
| 1532 |
|
fprintf(stderr, "%s: error rendering view %s\n", progname, vs); |
| 1533 |
|
quit(1); |
| 1534 |
+ |
#undef do_rpiece |
| 1535 |
|
} |
| 1536 |
|
|
| 1537 |
|
|
| 1544 |
|
printf("\ttouch %s\n", fn); |
| 1545 |
|
if (!nprocs) |
| 1546 |
|
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 |
| 1547 |
|
return(setfdate(fn, time((time_t *)NULL))); |
| 1548 |
|
} |
| 1549 |
|
|
| 1591 |
|
|
| 1592 |
|
#ifdef RHAS_FORK_EXEC |
| 1593 |
|
static int |
| 1594 |
< |
next_process(void) /* fork the next process (max. nprocs) */ |
| 1594 |
> |
next_process(int reserve) /* fork the next process */ |
| 1595 |
|
{ |
| 1596 |
|
RT_PID child_pid; |
| 1597 |
|
|
| 1602 |
|
progname); |
| 1603 |
|
quit(1); |
| 1604 |
|
} |
| 1605 |
+ |
if (reserve > 0 && children_running >= nprocs-reserve) |
| 1606 |
+ |
return(0); /* caller holding back process(es) */ |
| 1607 |
|
if (children_running >= nprocs) |
| 1608 |
|
wait_process(0); /* wait for someone to finish */ |
| 1609 |
|
fflush(NULL); /* flush output */ |
| 1610 |
|
child_pid = fork(); /* split process */ |
| 1611 |
|
if (child_pid == 0) { /* we're the child */ |
| 1612 |
|
children_running = -1; |
| 1613 |
+ |
nprocs = 1; |
| 1614 |
|
return(0); |
| 1615 |
|
} |
| 1616 |
|
if (child_pid > 0) { /* we're the parent */ |
| 1652 |
|
} |
| 1653 |
|
#else /* ! RHAS_FORK_EXEC */ |
| 1654 |
|
static int |
| 1655 |
< |
next_process(void) |
| 1655 |
> |
next_process(int reserve) |
| 1656 |
|
{ |
| 1657 |
|
return(0); /* cannot start new process */ |
| 1658 |
|
} |