18 |
|
#endif |
19 |
|
|
20 |
|
#include <signal.h> |
21 |
– |
#include <fcntl.h> |
21 |
|
|
22 |
|
#include "view.h" |
23 |
|
|
25 |
|
|
26 |
|
#include "random.h" |
27 |
|
|
28 |
+ |
#include "paths.h" |
29 |
+ |
|
30 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
31 |
|
int ndims = 0; /* number of sampling dimensions */ |
32 |
|
int samplendx; /* sample index number */ |
34 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
35 |
|
int hresolu = 512; /* horizontal resolution */ |
36 |
|
int vresolu = 512; /* vertical resolution */ |
37 |
< |
double pixaspect = 1.0; /* pixel aspect ratio */ |
37 |
> |
double pixaspect = 1.0; /* pixel aspect ratio */ |
38 |
|
|
39 |
|
int psample = 4; /* pixel sample size */ |
40 |
< |
double maxdiff = .05; /* max. difference for interpolation */ |
41 |
< |
double dstrpix = 0.67; /* square pixel distribution */ |
40 |
> |
double maxdiff = .05; /* max. difference for interpolation */ |
41 |
> |
double dstrpix = 0.67; /* square pixel distribution */ |
42 |
|
|
43 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
44 |
< |
double shadthresh = .05; /* shadow threshold */ |
45 |
< |
double shadcert = .5; /* shadow certainty */ |
43 |
> |
double dstrsrc = 0.0; /* square source distribution */ |
44 |
> |
double shadthresh = .05; /* shadow threshold */ |
45 |
> |
double shadcert = .5; /* shadow certainty */ |
46 |
|
int directrelay = 1; /* number of source relays */ |
47 |
|
int vspretest = 512; /* virtual source pretest density */ |
48 |
|
int directinvis = 0; /* sources invisible? */ |
49 |
< |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
49 |
> |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
50 |
|
|
51 |
< |
double specthresh = .15; /* specular sampling threshold */ |
52 |
< |
double specjitter = 1.; /* specular sampling jitter */ |
51 |
> |
double specthresh = .15; /* specular sampling threshold */ |
52 |
> |
double specjitter = 1.; /* specular sampling jitter */ |
53 |
|
|
54 |
|
int maxdepth = 6; /* maximum recursion depth */ |
55 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
55 |
> |
double minweight = 5e-3; /* minimum ray weight */ |
56 |
|
|
57 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
58 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
58 |
> |
double ambacc = 0.2; /* ambient accuracy */ |
59 |
|
int ambres = 32; /* ambient resolution */ |
60 |
|
int ambdiv = 128; /* ambient divisions */ |
61 |
|
int ambssamp = 0; /* ambient super-samples */ |
65 |
|
|
66 |
|
int ralrm = 0; /* seconds between reports */ |
67 |
|
|
68 |
< |
double pctdone = 0.0; /* percentage done */ |
68 |
> |
double pctdone = 0.0; /* percentage done */ |
69 |
|
|
70 |
|
long tlastrept = 0L; /* time at last report */ |
71 |
|
|
74 |
|
|
75 |
|
extern long nrays; /* number of rays traced */ |
76 |
|
|
77 |
< |
#define MAXDIV 16 /* maximum sample size */ |
77 |
> |
#define MAXDIV 16 /* maximum sample size */ |
78 |
|
|
79 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
79 |
> |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
80 |
|
|
81 |
< |
#define HFTEMPLATE "/tmp/hfXXXXXX" |
81 |
> |
#define RFTEMPLATE "rfXXXXXX" |
82 |
> |
#define HFTEMPLATE TEMPLATE |
83 |
|
|
84 |
|
static char *hfname = NULL; /* header file name */ |
85 |
|
static FILE *hfp = NULL; /* header file pointer */ |
88 |
|
|
89 |
|
extern char *mktemp(); |
90 |
|
|
91 |
< |
double pixvalue(); |
91 |
> |
double pixvalue(); |
92 |
|
|
93 |
|
|
94 |
|
quit(code) /* quit program */ |
109 |
|
report() /* report progress */ |
110 |
|
{ |
111 |
|
struct rusage rubuf; |
112 |
< |
double t; |
112 |
> |
double t; |
113 |
|
|
114 |
|
getrusage(RUSAGE_SELF, &rubuf); |
115 |
|
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
181 |
|
*/ |
182 |
|
{ |
183 |
|
extern char *rindex(), *strncpy(), *strcat(); |
184 |
< |
char fbuf[128], fbuf2[128], *zf; |
185 |
< |
RESOLU rs; |
186 |
< |
double pa; |
184 |
> |
char fbuf[128], fbuf2[128]; |
185 |
> |
register char *cp; |
186 |
> |
RESOLU rs; |
187 |
> |
double pa; |
188 |
|
/* finished writing header */ |
189 |
|
closeheader(); |
190 |
|
/* check sampling */ |
200 |
|
if (seq <= 0) |
201 |
|
seq = 0; |
202 |
|
else if (prvr != NULL && isint(prvr)) { |
203 |
< |
int rn; /* skip to specified view */ |
203 |
> |
register int rn; /* skip to specified view */ |
204 |
|
if ((rn = atoi(prvr)) < seq) |
205 |
|
error(USER, "recover frame less than start frame"); |
206 |
|
if (pout == NULL) |
212 |
|
} |
213 |
|
if (pout != NULL) { |
214 |
|
sprintf(fbuf, pout, seq); |
215 |
< |
if (!strcmp(prvr, fbuf)) { /* rename recover file */ |
215 |
> |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
216 |
|
fbuf2[0] = '\0'; |
217 |
< |
if ((prvr = rindex(fbuf, '/')) != NULL) |
218 |
< |
strncpy(fbuf2, fbuf, prvr-fbuf+1); |
219 |
< |
strcat(fbuf2, "rfXXXXXX"); |
217 |
> |
if ((cp = rindex(fbuf, '/')) != NULL) |
218 |
> |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
219 |
> |
strcat(fbuf2, RFTEMPLATE); |
220 |
|
prvr = mktemp(fbuf2); |
221 |
|
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
222 |
|
sprintf(errmsg, |
247 |
|
"cannot recover view parameters from \"%s\"", prvr); |
248 |
|
error(WARNING, errmsg); |
249 |
|
} else { |
247 |
– |
char *err; |
248 |
– |
if ((err = setview(&ourview)) != NULL) |
249 |
– |
error(USER, err); |
250 |
|
pa = 0.0; |
251 |
|
hres = scanlen(&rs); |
252 |
|
vres = numscans(&rs); |
253 |
|
} |
254 |
+ |
if ((cp = setview(&ourview)) != NULL) |
255 |
+ |
error(USER, cp); |
256 |
|
normaspect(viewaspect(&ourview), &pa, &hres, &vres); |
257 |
|
if (seq) { |
258 |
|
if (ralrm > 0) { |
259 |
< |
sprintf(errmsg, "starting frame %d\n", seq); |
260 |
< |
eputs(errmsg); |
259 |
> |
fprintf(stderr, "FRAME %d:", seq); |
260 |
> |
fprintview(&ourview, stderr); |
261 |
> |
putc('\n', stderr); |
262 |
> |
fflush(stderr); |
263 |
|
} |
264 |
|
printf("FRAME=%d\n", seq); |
265 |
|
} |
271 |
|
fputformat(COLRFMT, stdout); |
272 |
|
putchar('\n'); |
273 |
|
if (zout != NULL) |
274 |
< |
sprintf(zf=fbuf, zout, seq); |
274 |
> |
sprintf(cp=fbuf, zout, seq); |
275 |
|
else |
276 |
< |
zf = NULL; |
277 |
< |
render(zf, prvr); |
276 |
> |
cp = NULL; |
277 |
> |
render(cp, prvr); |
278 |
|
prvr = NULL; |
279 |
|
} while (seq++); |
280 |
|
} |
283 |
|
nextview(fp) /* get next view from fp */ |
284 |
|
FILE *fp; |
285 |
|
{ |
286 |
< |
char linebuf[256], *err; |
286 |
> |
char linebuf[256]; |
287 |
|
|
288 |
|
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
289 |
< |
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) { |
286 |
< |
if ((err = setview(&ourview)) != NULL) |
287 |
< |
error(USER, err); |
289 |
> |
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
290 |
|
return(0); |
289 |
– |
} |
291 |
|
return(EOF); |
292 |
|
} |
293 |
|
|
348 |
|
pctdone = 100.0*i/vres; |
349 |
|
if (ralrm > 0) /* report init stats */ |
350 |
|
report(); |
351 |
< |
#ifndef BSD |
351 |
> |
#ifndef BSD |
352 |
|
else |
353 |
|
#endif |
354 |
|
signal(SIGALRM, report); |
373 |
|
/* fill bar */ |
374 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
375 |
|
/* write it out */ |
376 |
< |
#ifndef BSD |
376 |
> |
#ifndef BSD |
377 |
|
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
378 |
|
#endif |
379 |
|
for (i = ystep; i > 0; i--) { |
390 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
391 |
|
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
392 |
|
report(); |
393 |
< |
#ifndef BSD |
393 |
> |
#ifndef BSD |
394 |
|
else |
395 |
|
signal(SIGALRM, report); |
396 |
|
#endif |
414 |
|
if (sampdens != NULL) |
415 |
|
free(sampdens); |
416 |
|
pctdone = 100.0; |
417 |
+ |
if (ralrm > 0) |
418 |
+ |
report(); |
419 |
|
return; |
420 |
|
writerr: |
421 |
|
error(SYSTEM, "write error in render"); |
425 |
|
|
426 |
|
|
427 |
|
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
428 |
< |
register COLOR *scanline; |
429 |
< |
register float *zline; |
428 |
> |
register COLOR *scanline; |
429 |
> |
register float *zline; |
430 |
|
register char *sd; |
431 |
|
int xres, y, xstep; |
432 |
|
{ |
433 |
|
static int nc = 0; /* number of calls */ |
434 |
|
int bl = xstep, b = xstep; |
435 |
< |
double z; |
435 |
> |
double z; |
436 |
|
register int i; |
437 |
|
|
438 |
|
z = pixvalue(scanline[0], 0, y); |
460 |
|
|
461 |
|
|
462 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
463 |
< |
register COLOR *scanbar[]; |
464 |
< |
register float *zbar[]; |
463 |
> |
register COLOR *scanbar[]; |
464 |
> |
register float *zbar[]; |
465 |
|
int xres, y, ysize; |
466 |
|
{ |
467 |
|
COLOR vline[MAXDIV+1]; |
491 |
|
|
492 |
|
|
493 |
|
int |
494 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
495 |
< |
register COLOR *colline; |
496 |
< |
register float *zline; |
494 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
495 |
> |
register COLOR *colline; |
496 |
> |
register float *zline; |
497 |
|
int x, y; |
498 |
|
int xlen, ylen; |
499 |
|
int b; |
500 |
|
{ |
501 |
< |
extern double fabs(); |
502 |
< |
double ratio; |
500 |
< |
double z; |
501 |
> |
double ratio; |
502 |
> |
double z; |
503 |
|
COLOR ctmp; |
504 |
|
int ncut; |
505 |
|
register int len; |
617 |
|
unlink(oldfile); |
618 |
|
return(y); |
619 |
|
writerr: |
620 |
< |
error(SYSTEM, "write error in salvage"); |
620 |
> |
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
621 |
> |
error(SYSTEM, errmsg); |
622 |
|
} |
623 |
|
|
624 |
|
|