27 |
|
|
28 |
|
#include "paths.h" |
29 |
|
|
30 |
+ |
#define RFTEMPLATE "rfXXXXXX" |
31 |
+ |
|
32 |
+ |
#ifndef SIGCONT |
33 |
+ |
#define SIGCONT SIGIO |
34 |
+ |
#endif |
35 |
+ |
|
36 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
37 |
|
int ndims = 0; /* number of sampling dimensions */ |
38 |
|
int samplendx; /* sample index number */ |
51 |
|
double shadcert = .5; /* shadow certainty */ |
52 |
|
int directrelay = 1; /* number of source relays */ |
53 |
|
int vspretest = 512; /* virtual source pretest density */ |
54 |
< |
int directinvis = 0; /* sources invisible? */ |
54 |
> |
int directvis = 1; /* sources visible? */ |
55 |
|
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
56 |
|
|
57 |
|
double specthresh = .15; /* specular sampling threshold */ |
69 |
|
char *amblist[128]; /* ambient include/exclude list */ |
70 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
71 |
|
|
72 |
+ |
#ifdef MSDOS |
73 |
+ |
int ralrm = 60; /* seconds between reports */ |
74 |
+ |
#else |
75 |
|
int ralrm = 0; /* seconds between reports */ |
76 |
+ |
#endif |
77 |
|
|
78 |
|
double pctdone = 0.0; /* percentage done */ |
79 |
|
|
82 |
|
extern long time(); |
83 |
|
extern long tstart; /* starting time */ |
84 |
|
|
85 |
< |
extern long nrays; /* number of rays traced */ |
85 |
> |
extern unsigned long nrays; /* number of rays traced */ |
86 |
|
|
87 |
|
#define MAXDIV 16 /* maximum sample size */ |
88 |
|
|
89 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
90 |
|
|
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 */ |
86 |
– |
|
91 |
|
static int hres, vres; /* resolution for this frame */ |
92 |
|
|
93 |
|
extern char *mktemp(); |
100 |
|
{ |
101 |
|
if (code) /* report status */ |
102 |
|
report(); |
103 |
< |
if (hfname != NULL) { /* delete header file */ |
104 |
< |
if (hfp != NULL) |
101 |
< |
fclose(hfp); |
102 |
< |
unlink(hfname); |
103 |
< |
} |
103 |
> |
headclean(); /* delete header file */ |
104 |
> |
pfclean(); /* clean up persist files */ |
105 |
|
exit(code); |
106 |
|
} |
107 |
|
|
119 |
|
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
120 |
|
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
121 |
|
|
122 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
122 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n", |
123 |
|
nrays, pctdone, t/3600.0); |
124 |
|
eputs(errmsg); |
125 |
|
tlastrept = time((long *)0); |
128 |
|
report() /* report progress */ |
129 |
|
{ |
130 |
|
tlastrept = time((long *)0); |
131 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
131 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n", |
132 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
133 |
|
eputs(errmsg); |
134 |
< |
signal(SIGALRM, report); |
134 |
> |
signal(SIGCONT, report); |
135 |
|
} |
136 |
|
#endif |
137 |
|
|
138 |
|
|
138 |
– |
openheader() /* save standard output to header file */ |
139 |
– |
{ |
140 |
– |
hfname = mktemp(HFTEMPLATE); |
141 |
– |
if (freopen(hfname, "w", stdout) == NULL) { |
142 |
– |
sprintf(errmsg, "cannot open header file \"%s\"", hfname); |
143 |
– |
error(SYSTEM, errmsg); |
144 |
– |
} |
145 |
– |
} |
146 |
– |
|
147 |
– |
|
148 |
– |
closeheader() /* done with header output */ |
149 |
– |
{ |
150 |
– |
if (hfname == NULL) |
151 |
– |
return; |
152 |
– |
if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL) |
153 |
– |
error(SYSTEM, "error reopening header file"); |
154 |
– |
} |
155 |
– |
|
156 |
– |
|
157 |
– |
dupheader() /* repeat header on standard output */ |
158 |
– |
{ |
159 |
– |
register int c; |
160 |
– |
|
161 |
– |
if (fseek(hfp, 0L, 0) < 0) |
162 |
– |
error(SYSTEM, "seek error on header file"); |
163 |
– |
while ((c = getc(hfp)) != EOF) |
164 |
– |
putchar(c); |
165 |
– |
} |
166 |
– |
|
167 |
– |
|
139 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
140 |
|
int seq; |
141 |
|
char *pout, *zout, *prvr; |
151 |
|
* sequenced file naming. |
152 |
|
*/ |
153 |
|
{ |
154 |
< |
extern char *rindex(), *strncpy(), *strcat(); |
154 |
> |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
155 |
|
char fbuf[128], fbuf2[128]; |
156 |
|
register char *cp; |
157 |
|
RESOLU rs; |
158 |
|
double pa; |
188 |
– |
/* finished writing header */ |
189 |
– |
closeheader(); |
159 |
|
/* check sampling */ |
160 |
|
if (psample < 1) |
161 |
|
psample = 1; |
179 |
|
error(USER, "unexpected EOF on view input"); |
180 |
|
prvr = fbuf; /* mark for renaming */ |
181 |
|
} |
182 |
< |
if (pout != NULL) { |
182 |
> |
if (pout != NULL & prvr != NULL) { |
183 |
|
sprintf(fbuf, pout, seq); |
184 |
< |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
185 |
< |
fbuf2[0] = '\0'; |
186 |
< |
if ((cp = rindex(fbuf, '/')) != NULL) |
187 |
< |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
188 |
< |
strcat(fbuf2, RFTEMPLATE); |
184 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
185 |
> |
strcpy(fbuf2, fbuf); |
186 |
> |
for (cp = fbuf2; *cp; cp++) |
187 |
> |
; |
188 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
189 |
> |
cp--; |
190 |
> |
strcpy(cp, RFTEMPLATE); |
191 |
|
prvr = mktemp(fbuf2); |
192 |
|
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
193 |
|
sprintf(errmsg, |
201 |
|
do { |
202 |
|
if (seq && nextview(stdin) == EOF) |
203 |
|
break; |
204 |
+ |
pctdone = 0.0; |
205 |
|
if (pout != NULL) { |
206 |
|
sprintf(fbuf, pout, seq); |
207 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
209 |
|
"cannot open output file \"%s\"", fbuf); |
210 |
|
error(SYSTEM, errmsg); |
211 |
|
} |
212 |
+ |
#ifdef MSDOS |
213 |
+ |
setmode(fileno(stdout), O_BINARY); |
214 |
+ |
#endif |
215 |
|
dupheader(); |
216 |
|
} |
217 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
303 |
|
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
304 |
|
error(SYSTEM, errmsg); |
305 |
|
} |
306 |
+ |
#ifdef MSDOS |
307 |
+ |
setmode(zfd, O_BINARY); |
308 |
+ |
#endif |
309 |
|
for (i = 0; i <= psample; i++) { |
310 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
311 |
|
if (zbar[i] == NULL) |
329 |
|
#ifndef BSD |
330 |
|
else |
331 |
|
#endif |
332 |
< |
signal(SIGALRM, report); |
332 |
> |
signal(SIGCONT, report); |
333 |
|
ypos = vres-1 - i; |
334 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
335 |
|
/* compute scanlines */ |
352 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
353 |
|
/* write it out */ |
354 |
|
#ifndef BSD |
355 |
< |
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
355 |
> |
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
356 |
|
#endif |
357 |
|
for (i = ystep; i > 0; i--) { |
358 |
|
if (zfd != -1 && write(zfd, (char *)zbar[i], |
370 |
|
report(); |
371 |
|
#ifndef BSD |
372 |
|
else |
373 |
< |
signal(SIGALRM, report); |
373 |
> |
signal(SIGCONT, report); |
374 |
|
#endif |
375 |
|
} |
376 |
|
/* clean up */ |
377 |
< |
signal(SIGALRM, SIG_IGN); |
377 |
> |
signal(SIGCONT, SIG_IGN); |
378 |
|
if (zfd != -1) { |
379 |
|
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
380 |
|
< hres*sizeof(float)) |
394 |
|
pctdone = 100.0; |
395 |
|
if (ralrm > 0) |
396 |
|
report(); |
397 |
+ |
signal(SIGCONT, SIG_DFL); |
398 |
|
return; |
399 |
|
writerr: |
400 |
|
error(SYSTEM, "write error in render"); |
477 |
|
int xlen, ylen; |
478 |
|
int b; |
479 |
|
{ |
501 |
– |
extern double fabs(); |
480 |
|
double ratio; |
481 |
|
double z; |
482 |
|
COLOR ctmp; |
564 |
|
error(WARNING, errmsg); |
565 |
|
return(0); |
566 |
|
} |
567 |
+ |
#ifdef MSDOS |
568 |
+ |
setmode(fileno(fp), O_BINARY); |
569 |
+ |
#endif |
570 |
|
/* discard header */ |
571 |
< |
getheader(fp, NULL); |
571 |
> |
getheader(fp, NULL, NULL); |
572 |
|
/* get picture size */ |
573 |
|
if (!fscnresolu(&x, &y, fp)) { |
574 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |