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 |
|
} |
813 |
|
*cp = '\0'; |
814 |
|
printheader(sop->ofp, info); |
815 |
|
} |
816 |
+ |
if (!accumulate) { /* global res. for -c- */ |
817 |
+ |
sop->xr = xres; sop->yr = yres; |
818 |
+ |
} |
819 |
|
printresolu(sop->ofp, sop->xr, sop->yr); |
820 |
|
/* play catch-up */ |
821 |
|
for (i = accumulate ? 0 : lastdone; i--; ) { |
943 |
|
fprintf(fout, "%.6e\t%.6e\t%.6e\t", cnt[0], cnt[1], cnt[2]); |
944 |
|
break; |
945 |
|
case 'f': |
946 |
< |
fv[0] = cnt[0]; |
939 |
< |
fv[1] = cnt[1]; |
940 |
< |
fv[2] = cnt[2]; |
946 |
> |
copycolor(fv, cnt); |
947 |
|
fwrite(fv, sizeof(float), 3, fout); |
948 |
|
break; |
949 |
|
case 'd': |
1174 |
|
lu_done(&ofiletab); /* close output files */ |
1175 |
|
} |
1176 |
|
|
1177 |
< |
/* seek on the given output file */ |
1177 |
> |
/* get ray contribution from previous file */ |
1178 |
|
static int |
1179 |
< |
myseeko(const LUENT *e, void *p) |
1179 |
> |
get_contrib(DCOLOR cnt, FILE *finp) |
1180 |
|
{ |
1181 |
+ |
COLOR fv; |
1182 |
+ |
COLR cv; |
1183 |
+ |
|
1184 |
+ |
switch (outfmt) { |
1185 |
+ |
case 'a': |
1186 |
+ |
return(fscanf(finp,"%lf %lf %lf",&cnt[0],&cnt[1],&cnt[2]) == 3); |
1187 |
+ |
case 'f': |
1188 |
+ |
if (fread(fv, sizeof(fv[0]), 3, finp) != 3) |
1189 |
+ |
return(0); |
1190 |
+ |
copycolor(cnt, fv); |
1191 |
+ |
return(1); |
1192 |
+ |
case 'd': |
1193 |
+ |
return(fread(cnt, sizeof(cnt[0]), 3, finp) == 3); |
1194 |
+ |
case 'c': |
1195 |
+ |
if (fread(cv, sizeof(cv), 1, finp) != 1) |
1196 |
+ |
return(0); |
1197 |
+ |
colr_color(fv, cv); |
1198 |
+ |
copycolor(cnt, fv); |
1199 |
+ |
return(1); |
1200 |
+ |
default: |
1201 |
+ |
error(INTERNAL, "botched output format"); |
1202 |
+ |
} |
1203 |
+ |
return(0); /* pro forma return */ |
1204 |
+ |
} |
1205 |
+ |
|
1206 |
+ |
/* close output file opened for input */ |
1207 |
+ |
static int |
1208 |
+ |
myclose(const LUENT *e, void *p) |
1209 |
+ |
{ |
1210 |
|
STREAMOUT *sop = (STREAMOUT *)e->data; |
1176 |
– |
off_t nbytes = *(off_t *)p; |
1211 |
|
|
1212 |
< |
if (sop->reclen > 1) |
1213 |
< |
nbytes = nbytes * sop->reclen; |
1214 |
< |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
1215 |
< |
sprintf(errmsg, "seek error on file '%s'", e->key); |
1182 |
< |
error(SYSTEM, errmsg); |
1183 |
< |
} |
1184 |
< |
return 0; |
1212 |
> |
if (sop->ofp == NULL) |
1213 |
> |
return; |
1214 |
> |
fclose(sop->ofp); |
1215 |
> |
sop->ofp = NULL; |
1216 |
|
} |
1217 |
|
|
1218 |
|
/* load previously accumulated values */ |
1226 |
|
char *fmode = "rb"; |
1227 |
|
char *outvfmt; |
1228 |
|
LUENT *ment, *oent; |
1229 |
+ |
int xr, yr; |
1230 |
|
STREAMOUT sout; |
1231 |
+ |
DCOLOR rgbv; |
1232 |
|
|
1200 |
– |
error(INTERNAL, "-r option not yet implemented with -c"); |
1201 |
– |
|
1233 |
|
switch (outfmt) { |
1234 |
|
case 'a': |
1235 |
|
outvfmt = "ascii"; |
1248 |
|
error(INTERNAL, "botched output format"); |
1249 |
|
return; |
1250 |
|
} |
1251 |
< |
/* check modifier outputs */ |
1251 |
> |
/* reload modifier values */ |
1252 |
|
for (i = 0; i < nmods; i++) { |
1253 |
|
ment = lu_find(&modconttab,modname[i]); |
1254 |
|
mp = (MODCONT *)ment->data; |
1256 |
|
error(USER, "cannot reload from stdout"); |
1257 |
|
if (mp->outspec[0] == '!') |
1258 |
|
error(USER, "cannot reload from command"); |
1259 |
< |
for (j = 0; ; j++) { /* check each bin's file */ |
1259 |
> |
for (j = 0; ; j++) { /* load each modifier bin */ |
1260 |
|
ofl = ofname(oname, mp->outspec, mp->modname, j); |
1261 |
|
if (ofl < 0) |
1262 |
|
error(USER, "bad output file specification"); |
1265 |
|
sout = *(STREAMOUT *)oent->data; |
1266 |
|
} else { |
1267 |
|
sout.reclen = 0; |
1268 |
+ |
sout.outpipe = 0; |
1269 |
+ |
sout.xr = xres; sout.yr = yres; |
1270 |
|
sout.ofp = NULL; |
1271 |
|
} |
1272 |
< |
if (sout.ofp != NULL) { /* already open? */ |
1273 |
< |
if (ofl & OF_BIN) |
1274 |
< |
continue; |
1275 |
< |
break; |
1272 |
> |
if (sout.ofp == NULL) { /* open output as input */ |
1273 |
> |
sout.ofp = fopen(oname, fmode); |
1274 |
> |
if (sout.ofp == NULL) { |
1275 |
> |
if (j) |
1276 |
> |
break; /* assume end of modifier */ |
1277 |
> |
sprintf(errmsg, "missing reload file '%s'", |
1278 |
> |
oname); |
1279 |
> |
error(WARNING, errmsg); |
1280 |
> |
break; |
1281 |
> |
} |
1282 |
> |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
1283 |
> |
sprintf(errmsg, "format mismatch for '%s'", |
1284 |
> |
oname); |
1285 |
> |
error(USER, errmsg); |
1286 |
> |
} |
1287 |
> |
if ((sout.xr > 0) & (sout.yr > 0) && |
1288 |
> |
(!fscnresolu(&xr, &yr, sout.ofp) || |
1289 |
> |
(xr != sout.xr) | |
1290 |
> |
(yr != sout.yr))) { |
1291 |
> |
sprintf(errmsg, "resolution mismatch for '%s'", |
1292 |
> |
oname); |
1293 |
> |
error(USER, errmsg); |
1294 |
> |
} |
1295 |
|
} |
1296 |
< |
/* 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 */ |
1296 |
> |
if (oent->key == NULL) /* new file entry */ |
1297 |
|
oent->key = strcpy((char *) |
1298 |
|
malloc(strlen(oname)+1), oname); |
1299 |
|
if (oent->data == NULL) |
1300 |
|
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
1301 |
|
*(STREAMOUT *)oent->data = sout; |
1302 |
< |
if (!(ofl & OF_BIN)) |
1303 |
< |
break; /* no bin separation */ |
1302 |
> |
/* read in RGB value */ |
1303 |
> |
if (!get_contrib(rgbv, sout.ofp)) { |
1304 |
> |
if (!j) |
1305 |
> |
break; /* ignore empty file */ |
1306 |
> |
if (j < mp->nbins) { |
1307 |
> |
sprintf(errmsg, "missing data in '%s'", |
1308 |
> |
oname); |
1309 |
> |
error(USER, errmsg); |
1310 |
> |
} |
1311 |
> |
break; |
1312 |
> |
} |
1313 |
> |
if (j >= mp->nbins) /* grow modifier size */ |
1314 |
> |
ment->data = (char *)(mp = growmodifier(mp, j+1)); |
1315 |
> |
copycolor(mp->cbin[j], rgbv); |
1316 |
|
} |
1263 |
– |
if (j > mp->nbins) /* reallocate modifier bins */ |
1264 |
– |
ment->data = (char *)(mp = growmodifier(mp, j)); |
1317 |
|
} |
1318 |
< |
lu_done(&ofiletab); /* close all files */ |
1318 |
> |
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
1319 |
|
} |
1320 |
|
|
1321 |
+ |
/* seek on the given output file */ |
1322 |
+ |
static int |
1323 |
+ |
myseeko(const LUENT *e, void *p) |
1324 |
+ |
{ |
1325 |
+ |
STREAMOUT *sop = (STREAMOUT *)e->data; |
1326 |
+ |
off_t nbytes = *(off_t *)p; |
1327 |
+ |
|
1328 |
+ |
if (sop->reclen > 1) |
1329 |
+ |
nbytes = nbytes * sop->reclen; |
1330 |
+ |
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
1331 |
+ |
sprintf(errmsg, "seek error on file '%s'", e->key); |
1332 |
+ |
error(SYSTEM, errmsg); |
1333 |
+ |
} |
1334 |
+ |
return 0; |
1335 |
+ |
} |
1336 |
+ |
|
1337 |
|
/* recover output if possible */ |
1338 |
|
void |
1339 |
|
recover_output(FILE *fin) |
1387 |
|
sout = *(STREAMOUT *)oent->data; |
1388 |
|
} else { |
1389 |
|
sout.reclen = 0; |
1390 |
+ |
sout.outpipe = 0; |
1391 |
+ |
sout.xr = xres; sout.yr = yres; |
1392 |
|
sout.ofp = NULL; |
1393 |
|
} |
1394 |
|
if (sout.ofp != NULL) { /* already open? */ |
1431 |
|
} |
1432 |
|
if ((xres > 0) & (yres > 0) && |
1433 |
|
(!fscnresolu(&xr, &yr, sout.ofp) || |
1434 |
< |
xr != xres || |
1435 |
< |
yr != yres)) { |
1434 |
> |
(xr != xres) | |
1435 |
> |
(yr != yres))) { |
1436 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
1437 |
|
oname); |
1438 |
|
error(USER, errmsg); |