18 |
|
#endif |
19 |
|
|
20 |
|
#include <signal.h> |
21 |
– |
#include <fcntl.h> |
21 |
|
|
22 |
|
#include "view.h" |
23 |
|
|
27 |
|
|
28 |
|
#include "paths.h" |
29 |
|
|
30 |
+ |
#define RFTEMPLATE "rfXXXXXX" |
31 |
+ |
|
32 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
33 |
|
int ndims = 0; /* number of sampling dimensions */ |
34 |
|
int samplendx; /* sample index number */ |
36 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
37 |
|
int hresolu = 512; /* horizontal resolution */ |
38 |
|
int vresolu = 512; /* vertical resolution */ |
39 |
< |
double pixaspect = 1.0; /* pixel aspect ratio */ |
39 |
> |
double pixaspect = 1.0; /* pixel aspect ratio */ |
40 |
|
|
41 |
|
int psample = 4; /* pixel sample size */ |
42 |
< |
double maxdiff = .05; /* max. difference for interpolation */ |
43 |
< |
double dstrpix = 0.67; /* square pixel distribution */ |
42 |
> |
double maxdiff = .05; /* max. difference for interpolation */ |
43 |
> |
double dstrpix = 0.67; /* square pixel distribution */ |
44 |
|
|
45 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
46 |
< |
double shadthresh = .05; /* shadow threshold */ |
47 |
< |
double shadcert = .5; /* shadow certainty */ |
45 |
> |
double dstrsrc = 0.0; /* square source distribution */ |
46 |
> |
double shadthresh = .05; /* shadow threshold */ |
47 |
> |
double shadcert = .5; /* shadow certainty */ |
48 |
|
int directrelay = 1; /* number of source relays */ |
49 |
|
int vspretest = 512; /* virtual source pretest density */ |
50 |
< |
int directinvis = 0; /* sources invisible? */ |
51 |
< |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
50 |
> |
int directvis = 1; /* sources visible? */ |
51 |
> |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
52 |
|
|
53 |
< |
double specthresh = .15; /* specular sampling threshold */ |
54 |
< |
double specjitter = 1.; /* specular sampling jitter */ |
53 |
> |
double specthresh = .15; /* specular sampling threshold */ |
54 |
> |
double specjitter = 1.; /* specular sampling jitter */ |
55 |
|
|
56 |
|
int maxdepth = 6; /* maximum recursion depth */ |
57 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
57 |
> |
double minweight = 5e-3; /* minimum ray weight */ |
58 |
|
|
59 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
60 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
60 |
> |
double ambacc = 0.2; /* ambient accuracy */ |
61 |
|
int ambres = 32; /* ambient resolution */ |
62 |
|
int ambdiv = 128; /* ambient divisions */ |
63 |
|
int ambssamp = 0; /* ambient super-samples */ |
65 |
|
char *amblist[128]; /* ambient include/exclude list */ |
66 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
67 |
|
|
68 |
+ |
#ifdef MSDOS |
69 |
+ |
int ralrm = 60; /* seconds between reports */ |
70 |
+ |
#else |
71 |
|
int ralrm = 0; /* seconds between reports */ |
72 |
+ |
#endif |
73 |
|
|
74 |
< |
double pctdone = 0.0; /* percentage done */ |
74 |
> |
double pctdone = 0.0; /* percentage done */ |
75 |
|
|
76 |
|
long tlastrept = 0L; /* time at last report */ |
77 |
|
|
80 |
|
|
81 |
|
extern long nrays; /* number of rays traced */ |
82 |
|
|
83 |
< |
#define MAXDIV 16 /* maximum sample size */ |
83 |
> |
#define MAXDIV 16 /* maximum sample size */ |
84 |
|
|
85 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
85 |
> |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
86 |
|
|
82 |
– |
#define RFTEMPLATE "rfXXXXXX" |
83 |
– |
#define HFTEMPLATE TEMPLATE |
84 |
– |
|
85 |
– |
static char *hfname = NULL; /* header file name */ |
86 |
– |
static FILE *hfp = NULL; /* header file pointer */ |
87 |
– |
|
87 |
|
static int hres, vres; /* resolution for this frame */ |
88 |
|
|
89 |
|
extern char *mktemp(); |
90 |
|
|
91 |
< |
double pixvalue(); |
91 |
> |
double pixvalue(); |
92 |
|
|
93 |
|
|
94 |
|
quit(code) /* quit program */ |
96 |
|
{ |
97 |
|
if (code) /* report status */ |
98 |
|
report(); |
99 |
< |
if (hfname != NULL) { /* delete header file */ |
100 |
< |
if (hfp != NULL) |
102 |
< |
fclose(hfp); |
103 |
< |
unlink(hfname); |
104 |
< |
} |
99 |
> |
headclean(); /* delete header file */ |
100 |
> |
pfclean(); /* clean up persist files */ |
101 |
|
exit(code); |
102 |
|
} |
103 |
|
|
106 |
|
report() /* report progress */ |
107 |
|
{ |
108 |
|
struct rusage rubuf; |
109 |
< |
double t; |
109 |
> |
double t; |
110 |
|
|
111 |
|
getrusage(RUSAGE_SELF, &rubuf); |
112 |
|
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
132 |
|
#endif |
133 |
|
|
134 |
|
|
139 |
– |
openheader() /* save standard output to header file */ |
140 |
– |
{ |
141 |
– |
hfname = mktemp(HFTEMPLATE); |
142 |
– |
if (freopen(hfname, "w", stdout) == NULL) { |
143 |
– |
sprintf(errmsg, "cannot open header file \"%s\"", hfname); |
144 |
– |
error(SYSTEM, errmsg); |
145 |
– |
} |
146 |
– |
} |
147 |
– |
|
148 |
– |
|
149 |
– |
closeheader() /* done with header output */ |
150 |
– |
{ |
151 |
– |
if (hfname == NULL) |
152 |
– |
return; |
153 |
– |
if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL) |
154 |
– |
error(SYSTEM, "error reopening header file"); |
155 |
– |
} |
156 |
– |
|
157 |
– |
|
158 |
– |
dupheader() /* repeat header on standard output */ |
159 |
– |
{ |
160 |
– |
register int c; |
161 |
– |
|
162 |
– |
if (fseek(hfp, 0L, 0) < 0) |
163 |
– |
error(SYSTEM, "seek error on header file"); |
164 |
– |
while ((c = getc(hfp)) != EOF) |
165 |
– |
putchar(c); |
166 |
– |
} |
167 |
– |
|
168 |
– |
|
135 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
136 |
|
int seq; |
137 |
|
char *pout, *zout, *prvr; |
147 |
|
* sequenced file naming. |
148 |
|
*/ |
149 |
|
{ |
150 |
< |
extern char *rindex(), *strncpy(), *strcat(); |
150 |
> |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
151 |
|
char fbuf[128], fbuf2[128]; |
152 |
|
register char *cp; |
153 |
< |
RESOLU rs; |
154 |
< |
double pa; |
189 |
< |
/* finished writing header */ |
190 |
< |
closeheader(); |
153 |
> |
RESOLU rs; |
154 |
> |
double pa; |
155 |
|
/* check sampling */ |
156 |
|
if (psample < 1) |
157 |
|
psample = 1; |
175 |
|
error(USER, "unexpected EOF on view input"); |
176 |
|
prvr = fbuf; /* mark for renaming */ |
177 |
|
} |
178 |
< |
if (pout != NULL) { |
178 |
> |
if (pout != NULL & prvr != NULL) { |
179 |
|
sprintf(fbuf, pout, seq); |
180 |
< |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
181 |
< |
fbuf2[0] = '\0'; |
182 |
< |
if ((cp = rindex(fbuf, '/')) != NULL) |
183 |
< |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
184 |
< |
strcat(fbuf2, RFTEMPLATE); |
180 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
181 |
> |
strcpy(fbuf2, fbuf); |
182 |
> |
for (cp = fbuf2; *cp; cp++) |
183 |
> |
; |
184 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
185 |
> |
cp--; |
186 |
> |
strcpy(cp, RFTEMPLATE); |
187 |
|
prvr = mktemp(fbuf2); |
188 |
|
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
189 |
|
sprintf(errmsg, |
204 |
|
"cannot open output file \"%s\"", fbuf); |
205 |
|
error(SYSTEM, errmsg); |
206 |
|
} |
207 |
+ |
#ifdef MSDOS |
208 |
+ |
setmode(fileno(stdout), O_BINARY); |
209 |
+ |
#endif |
210 |
|
dupheader(); |
211 |
|
} |
212 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
298 |
|
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
299 |
|
error(SYSTEM, errmsg); |
300 |
|
} |
301 |
+ |
#ifdef MSDOS |
302 |
+ |
setmode(zfd, O_BINARY); |
303 |
+ |
#endif |
304 |
|
for (i = 0; i <= psample; i++) { |
305 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
306 |
|
if (zbar[i] == NULL) |
321 |
|
pctdone = 100.0*i/vres; |
322 |
|
if (ralrm > 0) /* report init stats */ |
323 |
|
report(); |
324 |
< |
#ifndef BSD |
324 |
> |
#ifndef BSD |
325 |
|
else |
326 |
|
#endif |
327 |
|
signal(SIGALRM, report); |
346 |
|
/* fill bar */ |
347 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
348 |
|
/* write it out */ |
349 |
< |
#ifndef BSD |
349 |
> |
#ifndef BSD |
350 |
|
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
351 |
|
#endif |
352 |
|
for (i = ystep; i > 0; i--) { |
363 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
364 |
|
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
365 |
|
report(); |
366 |
< |
#ifndef BSD |
366 |
> |
#ifndef BSD |
367 |
|
else |
368 |
|
signal(SIGALRM, report); |
369 |
|
#endif |
387 |
|
if (sampdens != NULL) |
388 |
|
free(sampdens); |
389 |
|
pctdone = 100.0; |
390 |
+ |
if (ralrm > 0) |
391 |
+ |
report(); |
392 |
|
return; |
393 |
|
writerr: |
394 |
|
error(SYSTEM, "write error in render"); |
398 |
|
|
399 |
|
|
400 |
|
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
401 |
< |
register COLOR *scanline; |
402 |
< |
register float *zline; |
401 |
> |
register COLOR *scanline; |
402 |
> |
register float *zline; |
403 |
|
register char *sd; |
404 |
|
int xres, y, xstep; |
405 |
|
{ |
406 |
|
static int nc = 0; /* number of calls */ |
407 |
|
int bl = xstep, b = xstep; |
408 |
< |
double z; |
408 |
> |
double z; |
409 |
|
register int i; |
410 |
|
|
411 |
|
z = pixvalue(scanline[0], 0, y); |
433 |
|
|
434 |
|
|
435 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
436 |
< |
register COLOR *scanbar[]; |
437 |
< |
register float *zbar[]; |
436 |
> |
register COLOR *scanbar[]; |
437 |
> |
register float *zbar[]; |
438 |
|
int xres, y, ysize; |
439 |
|
{ |
440 |
|
COLOR vline[MAXDIV+1]; |
464 |
|
|
465 |
|
|
466 |
|
int |
467 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
468 |
< |
register COLOR *colline; |
469 |
< |
register float *zline; |
467 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
468 |
> |
register COLOR *colline; |
469 |
> |
register float *zline; |
470 |
|
int x, y; |
471 |
|
int xlen, ylen; |
472 |
|
int b; |
473 |
|
{ |
474 |
< |
extern double fabs(); |
475 |
< |
double ratio; |
502 |
< |
double z; |
474 |
> |
double ratio; |
475 |
> |
double z; |
476 |
|
COLOR ctmp; |
477 |
|
int ncut; |
478 |
|
register int len; |
558 |
|
error(WARNING, errmsg); |
559 |
|
return(0); |
560 |
|
} |
561 |
+ |
#ifdef MSDOS |
562 |
+ |
setmode(fileno(fp), O_BINARY); |
563 |
+ |
#endif |
564 |
|
/* discard header */ |
565 |
< |
getheader(fp, NULL); |
565 |
> |
getheader(fp, NULL, NULL); |
566 |
|
/* get picture size */ |
567 |
|
if (!fscnresolu(&x, &y, fp)) { |
568 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |