| 133 |
|
int header = 1; /* output header? */ |
| 134 |
|
int accumulate = 0; /* accumulate ray values? */ |
| 135 |
|
int force_open = 0; /* truncate existing output? */ |
| 136 |
+ |
int recover = 0; /* recover previous output? */ |
| 137 |
|
int xres = 0; /* horiz. output resolution */ |
| 138 |
|
int yres = 0; /* vert. output resolution */ |
| 139 |
|
|
| 221 |
|
{ |
| 222 |
|
int contrib = 0; |
| 223 |
|
int nprocs = 1; |
| 223 |
– |
int recover = 0; |
| 224 |
|
char *curout = NULL; |
| 225 |
|
char *binval = NULL; |
| 226 |
|
int bincnt = 0; |
| 293 |
|
break; |
| 294 |
|
case 'r': /* recover output */ |
| 295 |
|
if (argv[i][2]) break; |
| 296 |
< |
recover++; |
| 296 |
> |
recover = 1; |
| 297 |
|
continue; |
| 298 |
|
case 'h': /* output header? */ |
| 299 |
|
switch (argv[i][2]) { |
| 328 |
|
continue; |
| 329 |
|
} |
| 330 |
|
if (argv[i][2] == 'o') { |
| 331 |
< |
force_open++; |
| 331 |
> |
force_open = 1; |
| 332 |
|
continue; |
| 333 |
|
} |
| 334 |
|
setformat(argv[i]+2); |
| 437 |
|
error(USER, "missing octree argument"); |
| 438 |
|
rtargv[rtargc++] = octree = argv[i]; |
| 439 |
|
rtargv[rtargc] = NULL; |
| 440 |
< |
/* start rtrace */ |
| 440 |
> |
/* start rtrace & recover if requested */ |
| 441 |
|
init(nprocs); |
| 442 |
< |
if (recover) /* perform recovery if requested */ |
| 443 |
< |
if ((force_open = accumulate)) |
| 444 |
< |
reload_output(); |
| 445 |
< |
else |
| 446 |
< |
recover_output(stdin); |
| 447 |
< |
trace_contribs(stdin); /* compute contributions */ |
| 442 |
> |
/* compute contributions */ |
| 443 |
> |
trace_contribs(stdin); |
| 444 |
> |
/* clean up */ |
| 445 |
|
quit(0); |
| 446 |
|
} |
| 447 |
|
|
| 555 |
|
} else |
| 556 |
|
raysleft = 0; |
| 557 |
|
waitflush = xres; |
| 558 |
+ |
if (!recover) |
| 559 |
+ |
return; |
| 560 |
+ |
/* recover previous values */ |
| 561 |
+ |
if (accumulate) |
| 562 |
+ |
reload_output(); |
| 563 |
+ |
else |
| 564 |
+ |
recover_output(stdin); |
| 565 |
|
} |
| 566 |
|
|
| 567 |
|
/* grow modifier to accommodate more bins */ |
| 783 |
|
sop->ofp = NULL; /* open iff noopen==0 */ |
| 784 |
|
sop->xr = xres; sop->yr = yres; |
| 785 |
|
lep->data = (char *)sop; |
| 786 |
< |
if (!force_open && access(oname, F_OK) == 0) { |
| 786 |
> |
if (!sop->outpipe & !force_open & !recover && |
| 787 |
> |
access(oname, F_OK) == 0) { |
| 788 |
|
errno = EEXIST; /* file exists */ |
| 789 |
|
goto openerr; |
| 790 |
|
} |
| 940 |
|
fprintf(fout, "%.6e\t%.6e\t%.6e\t", cnt[0], cnt[1], cnt[2]); |
| 941 |
|
break; |
| 942 |
|
case 'f': |
| 943 |
< |
fv[0] = cnt[0]; |
| 939 |
< |
fv[1] = cnt[1]; |
| 940 |
< |
fv[2] = cnt[2]; |
| 943 |
> |
copycolor(fv, cnt); |
| 944 |
|
fwrite(fv, sizeof(float), 3, fout); |
| 945 |
|
break; |
| 946 |
|
case 'd': |
| 1171 |
|
lu_done(&ofiletab); /* close output files */ |
| 1172 |
|
} |
| 1173 |
|
|
| 1174 |
< |
/* seek on the given output file */ |
| 1174 |
> |
/* get ray contribution from previous file */ |
| 1175 |
|
static int |
| 1176 |
< |
myseeko(const LUENT *e, void *p) |
| 1176 |
> |
get_contrib(DCOLOR cnt, FILE *finp) |
| 1177 |
|
{ |
| 1178 |
+ |
COLOR fv; |
| 1179 |
+ |
COLR cv; |
| 1180 |
+ |
|
| 1181 |
+ |
switch (outfmt) { |
| 1182 |
+ |
case 'a': |
| 1183 |
+ |
return(fscanf(finp,"%lf %lf %lf",&cnt[0],&cnt[1],&cnt[2]) == 3); |
| 1184 |
+ |
case 'f': |
| 1185 |
+ |
if (fread(fv, sizeof(fv[0]), 3, finp) != 3) |
| 1186 |
+ |
return(0); |
| 1187 |
+ |
copycolor(cnt, fv); |
| 1188 |
+ |
return(1); |
| 1189 |
+ |
case 'd': |
| 1190 |
+ |
return(fread(cnt, sizeof(cnt[0]), 3, finp) == 3); |
| 1191 |
+ |
case 'c': |
| 1192 |
+ |
if (fread(cv, sizeof(cv), 1, finp) != 1) |
| 1193 |
+ |
return(0); |
| 1194 |
+ |
colr_color(fv, cv); |
| 1195 |
+ |
copycolor(cnt, fv); |
| 1196 |
+ |
return(1); |
| 1197 |
+ |
default: |
| 1198 |
+ |
error(INTERNAL, "botched output format"); |
| 1199 |
+ |
} |
| 1200 |
+ |
return(0); /* pro forma return */ |
| 1201 |
+ |
} |
| 1202 |
+ |
|
| 1203 |
+ |
/* close output file opened for input */ |
| 1204 |
+ |
static int |
| 1205 |
+ |
myclose(const LUENT *e, void *p) |
| 1206 |
+ |
{ |
| 1207 |
|
STREAMOUT *sop = (STREAMOUT *)e->data; |
| 1176 |
– |
off_t nbytes = *(off_t *)p; |
| 1208 |
|
|
| 1209 |
< |
if (sop->reclen > 1) |
| 1210 |
< |
nbytes = nbytes * sop->reclen; |
| 1211 |
< |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
| 1212 |
< |
sprintf(errmsg, "seek error on file '%s'", e->key); |
| 1182 |
< |
error(SYSTEM, errmsg); |
| 1183 |
< |
} |
| 1184 |
< |
return 0; |
| 1209 |
> |
if (sop->ofp == NULL) |
| 1210 |
> |
return; |
| 1211 |
> |
fclose(sop->ofp); |
| 1212 |
> |
sop->ofp = NULL; |
| 1213 |
|
} |
| 1214 |
|
|
| 1215 |
|
/* load previously accumulated values */ |
| 1223 |
|
char *fmode = "rb"; |
| 1224 |
|
char *outvfmt; |
| 1225 |
|
LUENT *ment, *oent; |
| 1226 |
+ |
int xr, yr; |
| 1227 |
|
STREAMOUT sout; |
| 1228 |
+ |
DCOLOR rgbv; |
| 1229 |
|
|
| 1200 |
– |
error(INTERNAL, "-r option not yet implemented with -c"); |
| 1201 |
– |
|
| 1230 |
|
switch (outfmt) { |
| 1231 |
|
case 'a': |
| 1232 |
|
outvfmt = "ascii"; |
| 1245 |
|
error(INTERNAL, "botched output format"); |
| 1246 |
|
return; |
| 1247 |
|
} |
| 1248 |
< |
/* check modifier outputs */ |
| 1248 |
> |
/* reload modifier values */ |
| 1249 |
|
for (i = 0; i < nmods; i++) { |
| 1250 |
|
ment = lu_find(&modconttab,modname[i]); |
| 1251 |
|
mp = (MODCONT *)ment->data; |
| 1253 |
|
error(USER, "cannot reload from stdout"); |
| 1254 |
|
if (mp->outspec[0] == '!') |
| 1255 |
|
error(USER, "cannot reload from command"); |
| 1256 |
< |
for (j = 0; ; j++) { /* check each bin's file */ |
| 1256 |
> |
for (j = 0; ; j++) { /* load each modifier bin */ |
| 1257 |
|
ofl = ofname(oname, mp->outspec, mp->modname, j); |
| 1258 |
|
if (ofl < 0) |
| 1259 |
|
error(USER, "bad output file specification"); |
| 1262 |
|
sout = *(STREAMOUT *)oent->data; |
| 1263 |
|
} else { |
| 1264 |
|
sout.reclen = 0; |
| 1265 |
+ |
sout.outpipe = 0; |
| 1266 |
+ |
sout.xr = xres; sout.yr = yres; |
| 1267 |
|
sout.ofp = NULL; |
| 1268 |
|
} |
| 1269 |
< |
if (sout.ofp != NULL) { /* already open? */ |
| 1270 |
< |
if (ofl & OF_BIN) |
| 1271 |
< |
continue; |
| 1272 |
< |
break; |
| 1269 |
> |
if (sout.ofp == NULL) { /* open output as input */ |
| 1270 |
> |
sout.ofp = fopen(oname, fmode); |
| 1271 |
> |
if (sout.ofp == NULL) { |
| 1272 |
> |
if (j) |
| 1273 |
> |
break; /* assume end of modifier */ |
| 1274 |
> |
sprintf(errmsg, "missing reload file '%s'", |
| 1275 |
> |
oname); |
| 1276 |
> |
error(WARNING, errmsg); |
| 1277 |
> |
break; |
| 1278 |
> |
} |
| 1279 |
> |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
| 1280 |
> |
sprintf(errmsg, "format mismatch for '%s'", |
| 1281 |
> |
oname); |
| 1282 |
> |
error(USER, errmsg); |
| 1283 |
> |
} |
| 1284 |
> |
if ((sout.xr > 0) & (sout.yr > 0) && |
| 1285 |
> |
(!fscnresolu(&xr, &yr, sout.ofp) || |
| 1286 |
> |
xr != sout.xr || |
| 1287 |
> |
yr != sout.yr)) { |
| 1288 |
> |
sprintf(errmsg, "resolution mismatch for '%s'", |
| 1289 |
> |
oname); |
| 1290 |
> |
error(USER, errmsg); |
| 1291 |
> |
} |
| 1292 |
|
} |
| 1293 |
< |
/* open output */ |
| 1245 |
< |
sout.ofp = fopen(oname, fmode); |
| 1246 |
< |
if (sout.ofp == NULL) { |
| 1247 |
< |
if (j) |
| 1248 |
< |
break; /* assume end of modifier */ |
| 1249 |
< |
sprintf(errmsg, "missing reload file '%s'", |
| 1250 |
< |
oname); |
| 1251 |
< |
error(WARNING, errmsg); |
| 1252 |
< |
break; |
| 1253 |
< |
} |
| 1254 |
< |
if (oent->key == NULL) /* new entry */ |
| 1293 |
> |
if (oent->key == NULL) /* new file entry */ |
| 1294 |
|
oent->key = strcpy((char *) |
| 1295 |
|
malloc(strlen(oname)+1), oname); |
| 1296 |
|
if (oent->data == NULL) |
| 1297 |
|
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
| 1298 |
|
*(STREAMOUT *)oent->data = sout; |
| 1299 |
< |
if (!(ofl & OF_BIN)) |
| 1300 |
< |
break; /* no bin separation */ |
| 1299 |
> |
/* read in RGB value */ |
| 1300 |
> |
if (!get_contrib(rgbv, sout.ofp)) { |
| 1301 |
> |
if (!j) |
| 1302 |
> |
break; /* ignore empty file */ |
| 1303 |
> |
if (j && j < mp->nbins) { |
| 1304 |
> |
sprintf(errmsg, "missing data in '%s'", |
| 1305 |
> |
oname); |
| 1306 |
> |
error(USER, errmsg); |
| 1307 |
> |
} |
| 1308 |
> |
break; |
| 1309 |
> |
} |
| 1310 |
> |
if (j >= mp->nbins) /* grow modifier size */ |
| 1311 |
> |
ment->data = (char *)(mp = growmodifier(mp, j+1)); |
| 1312 |
> |
copycolor(mp->cbin[j], rgbv); |
| 1313 |
|
} |
| 1263 |
– |
if (j > mp->nbins) /* reallocate modifier bins */ |
| 1264 |
– |
ment->data = (char *)(mp = growmodifier(mp, j)); |
| 1314 |
|
} |
| 1315 |
< |
lu_done(&ofiletab); /* close all files */ |
| 1315 |
> |
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
| 1316 |
|
} |
| 1317 |
|
|
| 1318 |
+ |
/* seek on the given output file */ |
| 1319 |
+ |
static int |
| 1320 |
+ |
myseeko(const LUENT *e, void *p) |
| 1321 |
+ |
{ |
| 1322 |
+ |
STREAMOUT *sop = (STREAMOUT *)e->data; |
| 1323 |
+ |
off_t nbytes = *(off_t *)p; |
| 1324 |
+ |
|
| 1325 |
+ |
if (sop->reclen > 1) |
| 1326 |
+ |
nbytes = nbytes * sop->reclen; |
| 1327 |
+ |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
| 1328 |
+ |
sprintf(errmsg, "seek error on file '%s'", e->key); |
| 1329 |
+ |
error(SYSTEM, errmsg); |
| 1330 |
+ |
} |
| 1331 |
+ |
return 0; |
| 1332 |
+ |
} |
| 1333 |
+ |
|
| 1334 |
|
/* recover output if possible */ |
| 1335 |
|
void |
| 1336 |
|
recover_output(FILE *fin) |
| 1384 |
|
sout = *(STREAMOUT *)oent->data; |
| 1385 |
|
} else { |
| 1386 |
|
sout.reclen = 0; |
| 1387 |
+ |
sout.outpipe = 0; |
| 1388 |
+ |
sout.xr = xres; sout.yr = yres; |
| 1389 |
|
sout.ofp = NULL; |
| 1390 |
|
} |
| 1391 |
|
if (sout.ofp != NULL) { /* already open? */ |