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(); |
94 |
|
|
95 |
|
double pixvalue(); |
96 |
|
|
97 |
+ |
#ifdef NIX |
98 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
99 |
+ |
#else |
100 |
+ |
#include <sys/types.h> |
101 |
+ |
#include <sys/stat.h> |
102 |
+ |
int |
103 |
+ |
file_exists(fname) /* ordinary file exists? */ |
104 |
+ |
char *fname; |
105 |
+ |
{ |
106 |
+ |
struct stat sbuf; |
107 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
108 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
109 |
+ |
} |
110 |
+ |
#endif |
111 |
|
|
112 |
+ |
|
113 |
|
quit(code) /* quit program */ |
114 |
|
int code; |
115 |
|
{ |
116 |
|
if (code) /* report status */ |
117 |
|
report(); |
118 |
< |
if (hfname != NULL) { /* delete header file */ |
119 |
< |
if (hfp != NULL) |
101 |
< |
fclose(hfp); |
102 |
< |
unlink(hfname); |
103 |
< |
} |
118 |
> |
headclean(); /* delete header file */ |
119 |
> |
pfclean(); /* clean up persist files */ |
120 |
|
exit(code); |
121 |
|
} |
122 |
|
|
134 |
|
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
135 |
|
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
136 |
|
|
137 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
137 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n", |
138 |
|
nrays, pctdone, t/3600.0); |
139 |
|
eputs(errmsg); |
140 |
|
tlastrept = time((long *)0); |
143 |
|
report() /* report progress */ |
144 |
|
{ |
145 |
|
tlastrept = time((long *)0); |
146 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
146 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n", |
147 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
148 |
|
eputs(errmsg); |
149 |
< |
signal(SIGALRM, report); |
149 |
> |
signal(SIGCONT, report); |
150 |
|
} |
151 |
|
#endif |
152 |
|
|
153 |
|
|
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 |
– |
|
154 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
155 |
|
int seq; |
156 |
|
char *pout, *zout, *prvr; |
166 |
|
* sequenced file naming. |
167 |
|
*/ |
168 |
|
{ |
169 |
< |
extern char *rindex(), *strncpy(), *strcat(); |
169 |
> |
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
170 |
|
char fbuf[128], fbuf2[128]; |
171 |
+ |
int npicts; |
172 |
|
register char *cp; |
173 |
|
RESOLU rs; |
174 |
|
double pa; |
188 |
– |
/* finished writing header */ |
189 |
– |
closeheader(); |
175 |
|
/* check sampling */ |
176 |
|
if (psample < 1) |
177 |
|
psample = 1; |
195 |
|
error(USER, "unexpected EOF on view input"); |
196 |
|
prvr = fbuf; /* mark for renaming */ |
197 |
|
} |
198 |
< |
if (pout != NULL) { |
198 |
> |
if (pout != NULL & prvr != NULL) { |
199 |
|
sprintf(fbuf, pout, seq); |
200 |
< |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
201 |
< |
fbuf2[0] = '\0'; |
202 |
< |
if ((cp = rindex(fbuf, '/')) != NULL) |
203 |
< |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
204 |
< |
strcat(fbuf2, RFTEMPLATE); |
200 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
201 |
> |
strcpy(fbuf2, fbuf); |
202 |
> |
for (cp = fbuf2; *cp; cp++) |
203 |
> |
; |
204 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
205 |
> |
cp--; |
206 |
> |
strcpy(cp, RFTEMPLATE); |
207 |
|
prvr = mktemp(fbuf2); |
208 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
209 |
< |
sprintf(errmsg, |
208 |
> |
if (rename(fbuf, prvr) < 0) |
209 |
> |
if (errno == ENOENT) { /* ghost file */ |
210 |
> |
sprintf(errmsg, |
211 |
> |
"new output file \"%s\"", |
212 |
> |
fbuf); |
213 |
> |
error(WARNING, errmsg); |
214 |
> |
prvr = NULL; |
215 |
> |
} else { /* serious error */ |
216 |
> |
sprintf(errmsg, |
217 |
|
"cannot rename \"%s\" to \"%s\"", |
218 |
|
fbuf, prvr); |
219 |
< |
error(SYSTEM, errmsg); |
220 |
< |
} |
219 |
> |
error(SYSTEM, errmsg); |
220 |
> |
} |
221 |
|
} |
222 |
|
} |
223 |
< |
/* render sequence */ |
223 |
> |
npicts = 0; /* render sequence */ |
224 |
|
do { |
225 |
|
if (seq && nextview(stdin) == EOF) |
226 |
|
break; |
227 |
+ |
pctdone = 0.0; |
228 |
|
if (pout != NULL) { |
229 |
|
sprintf(fbuf, pout, seq); |
230 |
+ |
if (file_exists(fbuf)) { |
231 |
+ |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
232 |
+ |
sprintf(errmsg, |
233 |
+ |
"output file \"%s\" exists", |
234 |
+ |
fbuf); |
235 |
+ |
error(USER, errmsg); |
236 |
+ |
} |
237 |
+ |
continue; /* don't clobber */ |
238 |
+ |
} |
239 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
240 |
|
sprintf(errmsg, |
241 |
|
"cannot open output file \"%s\"", fbuf); |
242 |
|
error(SYSTEM, errmsg); |
243 |
|
} |
244 |
+ |
#ifdef MSDOS |
245 |
+ |
setmode(fileno(stdout), O_BINARY); |
246 |
+ |
#endif |
247 |
|
dupheader(); |
248 |
|
} |
249 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
283 |
|
cp = NULL; |
284 |
|
render(cp, prvr); |
285 |
|
prvr = NULL; |
286 |
+ |
npicts++; |
287 |
|
} while (seq++); |
288 |
+ |
/* check that we did something */ |
289 |
+ |
if (npicts == 0) |
290 |
+ |
error(WARNING, "no output produced"); |
291 |
|
} |
292 |
|
|
293 |
|
|
333 |
|
sampdens[i] = hstep; |
334 |
|
} else |
335 |
|
sampdens = NULL; |
336 |
< |
/* open z file */ |
336 |
> |
/* open z-file */ |
337 |
|
if (zfile != NULL) { |
338 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
339 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
339 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
340 |
|
error(SYSTEM, errmsg); |
341 |
|
} |
342 |
+ |
#ifdef MSDOS |
343 |
+ |
setmode(zfd, O_BINARY); |
344 |
+ |
#endif |
345 |
|
for (i = 0; i <= psample; i++) { |
346 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
347 |
|
if (zbar[i] == NULL) |
358 |
|
i = salvage(oldfile); |
359 |
|
if (zfd != -1 && i > 0 && |
360 |
|
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
361 |
< |
error(SYSTEM, "z file seek error in render"); |
361 |
> |
error(SYSTEM, "z-file seek error in render"); |
362 |
|
pctdone = 100.0*i/vres; |
363 |
|
if (ralrm > 0) /* report init stats */ |
364 |
|
report(); |
365 |
|
#ifndef BSD |
366 |
|
else |
367 |
|
#endif |
368 |
< |
signal(SIGALRM, report); |
368 |
> |
signal(SIGCONT, report); |
369 |
|
ypos = vres-1 - i; |
370 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
371 |
|
/* compute scanlines */ |
388 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
389 |
|
/* write it out */ |
390 |
|
#ifndef BSD |
391 |
< |
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
391 |
> |
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
392 |
|
#endif |
393 |
|
for (i = ystep; i > 0; i--) { |
394 |
|
if (zfd != -1 && write(zfd, (char *)zbar[i], |
406 |
|
report(); |
407 |
|
#ifndef BSD |
408 |
|
else |
409 |
< |
signal(SIGALRM, report); |
409 |
> |
signal(SIGCONT, report); |
410 |
|
#endif |
411 |
|
} |
412 |
|
/* clean up */ |
413 |
< |
signal(SIGALRM, SIG_IGN); |
413 |
> |
signal(SIGCONT, SIG_IGN); |
414 |
|
if (zfd != -1) { |
415 |
|
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
416 |
|
< hres*sizeof(float)) |
430 |
|
pctdone = 100.0; |
431 |
|
if (ralrm > 0) |
432 |
|
report(); |
433 |
+ |
signal(SIGCONT, SIG_DFL); |
434 |
|
return; |
435 |
|
writerr: |
436 |
|
error(SYSTEM, "write error in render"); |
513 |
|
int xlen, ylen; |
514 |
|
int b; |
515 |
|
{ |
501 |
– |
extern double fabs(); |
516 |
|
double ratio; |
517 |
|
double z; |
518 |
|
COLOR ctmp; |
600 |
|
error(WARNING, errmsg); |
601 |
|
return(0); |
602 |
|
} |
603 |
+ |
#ifdef MSDOS |
604 |
+ |
setmode(fileno(fp), O_BINARY); |
605 |
+ |
#endif |
606 |
|
/* discard header */ |
607 |
< |
getheader(fp, NULL); |
607 |
> |
getheader(fp, NULL, NULL); |
608 |
|
/* get picture size */ |
609 |
|
if (!fscnresolu(&x, &y, fp)) { |
610 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
610 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
611 |
> |
oldfile); |
612 |
|
error(WARNING, errmsg); |
613 |
|
fclose(fp); |
614 |
|
return(0); |