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. */ |
48 |
> |
int directvis = 1; /* sources visible? */ |
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 */ |
63 |
|
char *amblist[128]; /* ambient include/exclude list */ |
64 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
65 |
|
|
66 |
+ |
#ifdef MSDOS |
67 |
+ |
int ralrm = 60; /* seconds between reports */ |
68 |
+ |
#else |
69 |
|
int ralrm = 0; /* seconds between reports */ |
70 |
+ |
#endif |
71 |
|
|
72 |
< |
double pctdone = 0.0; /* percentage done */ |
72 |
> |
double pctdone = 0.0; /* percentage done */ |
73 |
|
|
74 |
|
long tlastrept = 0L; /* time at last report */ |
75 |
|
|
78 |
|
|
79 |
|
extern long nrays; /* number of rays traced */ |
80 |
|
|
81 |
< |
#define MAXDIV 16 /* maximum sample size */ |
81 |
> |
#define MAXDIV 16 /* maximum sample size */ |
82 |
|
|
83 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
83 |
> |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
84 |
|
|
85 |
< |
#define RFTEMPLATE "rfXXXXXX" |
86 |
< |
#define HFTEMPLATE "/tmp/hfXXXXXX" |
85 |
> |
#define RFTEMPLATE "rfXXXXXX" |
86 |
> |
#define HFTEMPLATE TEMPLATE |
87 |
|
|
88 |
|
static char *hfname = NULL; /* header file name */ |
89 |
|
static FILE *hfp = NULL; /* header file pointer */ |
92 |
|
|
93 |
|
extern char *mktemp(); |
94 |
|
|
95 |
< |
double pixvalue(); |
95 |
> |
double pixvalue(); |
96 |
|
|
97 |
|
|
98 |
|
quit(code) /* quit program */ |
113 |
|
report() /* report progress */ |
114 |
|
{ |
115 |
|
struct rusage rubuf; |
116 |
< |
double t; |
116 |
> |
double t; |
117 |
|
|
118 |
|
getrusage(RUSAGE_SELF, &rubuf); |
119 |
|
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
149 |
|
} |
150 |
|
|
151 |
|
|
147 |
– |
closeheader() /* done with header output */ |
148 |
– |
{ |
149 |
– |
if (hfname == NULL) |
150 |
– |
return; |
151 |
– |
if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL) |
152 |
– |
error(SYSTEM, "error reopening header file"); |
153 |
– |
} |
154 |
– |
|
155 |
– |
|
152 |
|
dupheader() /* repeat header on standard output */ |
153 |
|
{ |
154 |
|
register int c; |
155 |
|
|
156 |
< |
if (fseek(hfp, 0L, 0) < 0) |
156 |
> |
if (hfp == NULL) { |
157 |
> |
if ((hfp = fopen(hfname, "r")) == NULL) |
158 |
> |
error(SYSTEM, "error reopening header file"); |
159 |
> |
#ifdef MSDOS |
160 |
> |
setmode(fileno(hfp), O_BINARY); |
161 |
> |
#endif |
162 |
> |
} else if (fseek(hfp, 0L, 0) < 0) |
163 |
|
error(SYSTEM, "seek error on header file"); |
164 |
|
while ((c = getc(hfp)) != EOF) |
165 |
|
putchar(c); |
184 |
|
extern char *rindex(), *strncpy(), *strcat(); |
185 |
|
char fbuf[128], fbuf2[128]; |
186 |
|
register char *cp; |
187 |
< |
RESOLU rs; |
188 |
< |
double pa; |
187 |
< |
/* finished writing header */ |
188 |
< |
closeheader(); |
187 |
> |
RESOLU rs; |
188 |
> |
double pa; |
189 |
|
/* check sampling */ |
190 |
|
if (psample < 1) |
191 |
|
psample = 1; |
209 |
|
error(USER, "unexpected EOF on view input"); |
210 |
|
prvr = fbuf; /* mark for renaming */ |
211 |
|
} |
212 |
< |
if (pout != NULL) { |
212 |
> |
if (pout != NULL & prvr != NULL) { |
213 |
|
sprintf(fbuf, pout, seq); |
214 |
< |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
215 |
< |
fbuf2[0] = '\0'; |
216 |
< |
if ((cp = rindex(fbuf, '/')) != NULL) |
217 |
< |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
218 |
< |
strcat(fbuf2, RFTEMPLATE); |
214 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
215 |
> |
strcpy(fbuf2, fbuf); |
216 |
> |
for (cp = fbuf2; *cp; cp++) |
217 |
> |
; |
218 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
219 |
> |
cp--; |
220 |
> |
strcpy(cp, RFTEMPLATE); |
221 |
|
prvr = mktemp(fbuf2); |
222 |
|
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
223 |
|
sprintf(errmsg, |
238 |
|
"cannot open output file \"%s\"", fbuf); |
239 |
|
error(SYSTEM, errmsg); |
240 |
|
} |
241 |
+ |
#ifdef MSDOS |
242 |
+ |
setmode(fileno(stdout), O_BINARY); |
243 |
+ |
#endif |
244 |
|
dupheader(); |
245 |
|
} |
246 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
332 |
|
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
333 |
|
error(SYSTEM, errmsg); |
334 |
|
} |
335 |
+ |
#ifdef MSDOS |
336 |
+ |
setmode(zfd, O_BINARY); |
337 |
+ |
#endif |
338 |
|
for (i = 0; i <= psample; i++) { |
339 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
340 |
|
if (zbar[i] == NULL) |
355 |
|
pctdone = 100.0*i/vres; |
356 |
|
if (ralrm > 0) /* report init stats */ |
357 |
|
report(); |
358 |
< |
#ifndef BSD |
358 |
> |
#ifndef BSD |
359 |
|
else |
360 |
|
#endif |
361 |
|
signal(SIGALRM, report); |
380 |
|
/* fill bar */ |
381 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
382 |
|
/* write it out */ |
383 |
< |
#ifndef BSD |
383 |
> |
#ifndef BSD |
384 |
|
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
385 |
|
#endif |
386 |
|
for (i = ystep; i > 0; i--) { |
397 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
398 |
|
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
399 |
|
report(); |
400 |
< |
#ifndef BSD |
400 |
> |
#ifndef BSD |
401 |
|
else |
402 |
|
signal(SIGALRM, report); |
403 |
|
#endif |
421 |
|
if (sampdens != NULL) |
422 |
|
free(sampdens); |
423 |
|
pctdone = 100.0; |
424 |
+ |
if (ralrm > 0) |
425 |
+ |
report(); |
426 |
|
return; |
427 |
|
writerr: |
428 |
|
error(SYSTEM, "write error in render"); |
432 |
|
|
433 |
|
|
434 |
|
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
435 |
< |
register COLOR *scanline; |
436 |
< |
register float *zline; |
435 |
> |
register COLOR *scanline; |
436 |
> |
register float *zline; |
437 |
|
register char *sd; |
438 |
|
int xres, y, xstep; |
439 |
|
{ |
440 |
|
static int nc = 0; /* number of calls */ |
441 |
|
int bl = xstep, b = xstep; |
442 |
< |
double z; |
442 |
> |
double z; |
443 |
|
register int i; |
444 |
|
|
445 |
|
z = pixvalue(scanline[0], 0, y); |
467 |
|
|
468 |
|
|
469 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
470 |
< |
register COLOR *scanbar[]; |
471 |
< |
register float *zbar[]; |
470 |
> |
register COLOR *scanbar[]; |
471 |
> |
register float *zbar[]; |
472 |
|
int xres, y, ysize; |
473 |
|
{ |
474 |
|
COLOR vline[MAXDIV+1]; |
498 |
|
|
499 |
|
|
500 |
|
int |
501 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
502 |
< |
register COLOR *colline; |
503 |
< |
register float *zline; |
501 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
502 |
> |
register COLOR *colline; |
503 |
> |
register float *zline; |
504 |
|
int x, y; |
505 |
|
int xlen, ylen; |
506 |
|
int b; |
507 |
|
{ |
508 |
< |
extern double fabs(); |
509 |
< |
double ratio; |
500 |
< |
double z; |
508 |
> |
double ratio; |
509 |
> |
double z; |
510 |
|
COLOR ctmp; |
511 |
|
int ncut; |
512 |
|
register int len; |
592 |
|
error(WARNING, errmsg); |
593 |
|
return(0); |
594 |
|
} |
595 |
+ |
#ifdef MSDOS |
596 |
+ |
setmode(fileno(fp), O_BINARY); |
597 |
+ |
#endif |
598 |
|
/* discard header */ |
599 |
< |
getheader(fp, NULL); |
599 |
> |
getheader(fp, NULL, NULL); |
600 |
|
/* get picture size */ |
601 |
|
if (!fscnresolu(&x, &y, fp)) { |
602 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |