1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* rpict.c - routines and variables for picture generation. |
9 |
– |
* |
10 |
– |
* 8/14/85 |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
+ |
#include <sys/types.h> |
13 |
+ |
|
14 |
+ |
#ifndef NIX |
15 |
|
#ifdef BSD |
16 |
|
#include <sys/time.h> |
17 |
|
#include <sys/resource.h> |
18 |
+ |
#else |
19 |
+ |
#include <sys/times.h> |
20 |
+ |
#include <unistd.h> |
21 |
|
#endif |
22 |
+ |
#endif |
23 |
|
|
24 |
+ |
extern time_t time(); |
25 |
+ |
|
26 |
|
#include <signal.h> |
21 |
– |
#include <fcntl.h> |
27 |
|
|
28 |
|
#include "view.h" |
29 |
|
|
25 |
– |
#include "resolu.h" |
26 |
– |
|
30 |
|
#include "random.h" |
31 |
|
|
32 |
|
#include "paths.h" |
33 |
|
|
34 |
+ |
#define RFTEMPLATE "rfXXXXXX" |
35 |
+ |
|
36 |
+ |
#ifndef SIGCONT |
37 |
+ |
#define SIGCONT SIGIO |
38 |
+ |
#endif |
39 |
+ |
|
40 |
+ |
CUBE thescene; /* our scene */ |
41 |
+ |
OBJECT nsceneobjs; /* number of objects in our scene */ |
42 |
+ |
|
43 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
44 |
|
int ndims = 0; /* number of sampling dimensions */ |
45 |
|
int samplendx; /* sample index number */ |
46 |
|
|
47 |
+ |
extern void ambnotify(); |
48 |
+ |
void (*addobjnotify[])() = {ambnotify, NULL}; |
49 |
+ |
|
50 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
51 |
|
int hresolu = 512; /* horizontal resolution */ |
52 |
|
int vresolu = 512; /* vertical resolution */ |
53 |
< |
double pixaspect = 1.0; /* pixel aspect ratio */ |
53 |
> |
double pixaspect = 1.0; /* pixel aspect ratio */ |
54 |
|
|
55 |
|
int psample = 4; /* pixel sample size */ |
56 |
< |
double maxdiff = .05; /* max. difference for interpolation */ |
57 |
< |
double dstrpix = 0.67; /* square pixel distribution */ |
56 |
> |
double maxdiff = .05; /* max. difference for interpolation */ |
57 |
> |
double dstrpix = 0.67; /* square pixel distribution */ |
58 |
|
|
59 |
< |
double dstrsrc = 0.0; /* square source distribution */ |
60 |
< |
double shadthresh = .05; /* shadow threshold */ |
61 |
< |
double shadcert = .5; /* shadow certainty */ |
59 |
> |
double mblur = 0.; /* motion blur parameter */ |
60 |
> |
|
61 |
> |
void (*trace)() = NULL; /* trace call */ |
62 |
> |
|
63 |
> |
int do_irrad = 0; /* compute irradiance? */ |
64 |
> |
|
65 |
> |
double dstrsrc = 0.0; /* square source distribution */ |
66 |
> |
double shadthresh = .05; /* shadow threshold */ |
67 |
> |
double shadcert = .5; /* shadow certainty */ |
68 |
|
int directrelay = 1; /* number of source relays */ |
69 |
|
int vspretest = 512; /* virtual source pretest density */ |
70 |
< |
int directinvis = 0; /* sources invisible? */ |
71 |
< |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
70 |
> |
int directvis = 1; /* sources visible? */ |
71 |
> |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
72 |
|
|
73 |
< |
double specthresh = .15; /* specular sampling threshold */ |
74 |
< |
double specjitter = 1.; /* specular sampling jitter */ |
73 |
> |
COLOR cextinction = BLKCOLOR; /* global extinction coefficient */ |
74 |
> |
COLOR salbedo = BLKCOLOR; /* global scattering albedo */ |
75 |
> |
double seccg = 0.; /* global scattering eccentricity */ |
76 |
> |
double ssampdist = 0.; /* scatter sampling distance */ |
77 |
|
|
78 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
79 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
80 |
+ |
|
81 |
+ |
int backvis = 1; /* back face visibility */ |
82 |
+ |
|
83 |
|
int maxdepth = 6; /* maximum recursion depth */ |
84 |
< |
double minweight = 5e-3; /* minimum ray weight */ |
84 |
> |
double minweight = 5e-3; /* minimum ray weight */ |
85 |
|
|
86 |
+ |
char *ambfile = NULL; /* ambient file name */ |
87 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
88 |
< |
double ambacc = 0.2; /* ambient accuracy */ |
88 |
> |
int ambvwt = 0; /* initial weight for ambient value */ |
89 |
> |
double ambacc = 0.2; /* ambient accuracy */ |
90 |
|
int ambres = 32; /* ambient resolution */ |
91 |
|
int ambdiv = 128; /* ambient divisions */ |
92 |
|
int ambssamp = 0; /* ambient super-samples */ |
96 |
|
|
97 |
|
int ralrm = 0; /* seconds between reports */ |
98 |
|
|
99 |
< |
double pctdone = 0.0; /* percentage done */ |
99 |
> |
double pctdone = 0.0; /* percentage done */ |
100 |
> |
time_t tlastrept = 0L; /* time at last report */ |
101 |
> |
time_t tstart; /* starting time */ |
102 |
|
|
103 |
< |
long tlastrept = 0L; /* time at last report */ |
103 |
> |
#define MAXDIV 16 /* maximum sample size */ |
104 |
|
|
105 |
< |
extern long time(); |
74 |
< |
extern long tstart; /* starting time */ |
105 |
> |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
106 |
|
|
107 |
< |
extern long nrays; /* number of rays traced */ |
107 |
> |
int hres, vres; /* resolution for this frame */ |
108 |
|
|
109 |
< |
#define MAXDIV 16 /* maximum sample size */ |
109 |
> |
static VIEW lastview; /* the previous view input */ |
110 |
|
|
111 |
< |
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
111 |
> |
extern char *mktemp(); |
112 |
|
|
113 |
< |
#define RFTEMPLATE "rfXXXXXX" |
83 |
< |
#define HFTEMPLATE TEMPLATE |
113 |
> |
void report(); |
114 |
|
|
115 |
< |
static char *hfname = NULL; /* header file name */ |
86 |
< |
static FILE *hfp = NULL; /* header file pointer */ |
115 |
> |
double pixvalue(); |
116 |
|
|
117 |
< |
static int hres, vres; /* resolution for this frame */ |
117 |
> |
#ifdef NIX |
118 |
> |
#define file_exists(f) (access(f,F_OK)==0) |
119 |
> |
#else |
120 |
> |
#include <sys/types.h> |
121 |
> |
#include <sys/stat.h> |
122 |
> |
int |
123 |
> |
file_exists(fname) /* ordinary file exists? */ |
124 |
> |
char *fname; |
125 |
> |
{ |
126 |
> |
struct stat sbuf; |
127 |
> |
if (stat(fname, &sbuf) < 0) return(0); |
128 |
> |
return((sbuf.st_mode & S_IFREG) != 0); |
129 |
> |
} |
130 |
> |
#endif |
131 |
|
|
90 |
– |
extern char *mktemp(); |
132 |
|
|
133 |
< |
double pixvalue(); |
93 |
< |
|
94 |
< |
|
133 |
> |
void |
134 |
|
quit(code) /* quit program */ |
135 |
|
int code; |
136 |
|
{ |
137 |
|
if (code) /* report status */ |
138 |
|
report(); |
139 |
< |
if (hfname != NULL) { /* delete header file */ |
140 |
< |
if (hfp != NULL) |
141 |
< |
fclose(hfp); |
142 |
< |
unlink(hfname); |
104 |
< |
} |
139 |
> |
#ifndef NIX |
140 |
> |
headclean(); /* delete header file */ |
141 |
> |
pfclean(); /* clean up persist files */ |
142 |
> |
#endif |
143 |
|
exit(code); |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
< |
#ifdef BSD |
147 |
> |
#ifndef NIX |
148 |
> |
void |
149 |
|
report() /* report progress */ |
150 |
|
{ |
151 |
+ |
extern char *myhostname(); |
152 |
+ |
double u, s; |
153 |
+ |
#ifdef BSD |
154 |
|
struct rusage rubuf; |
155 |
< |
double t; |
155 |
> |
#else |
156 |
> |
struct tms tbuf; |
157 |
> |
double period; |
158 |
> |
#endif |
159 |
|
|
160 |
+ |
tlastrept = time((time_t *)NULL); |
161 |
+ |
#ifdef BSD |
162 |
|
getrusage(RUSAGE_SELF, &rubuf); |
163 |
< |
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
164 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
163 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
164 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
165 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
166 |
< |
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
167 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
166 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
167 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
168 |
> |
#else |
169 |
> |
times(&tbuf); |
170 |
> |
#ifdef _SC_CLK_TCK |
171 |
> |
period = 1.0 / sysconf(_SC_CLK_TCK); |
172 |
> |
#else |
173 |
> |
period = 1.0 / 60.0; |
174 |
> |
#endif |
175 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
176 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
177 |
> |
#endif |
178 |
|
|
179 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
180 |
< |
nrays, pctdone, t/3600.0); |
179 |
> |
sprintf(errmsg, |
180 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
181 |
> |
nrays, pctdone, u/3600., s/3600., |
182 |
> |
(tlastrept-tstart)/3600., myhostname()); |
183 |
|
eputs(errmsg); |
184 |
< |
tlastrept = time((long *)0); |
184 |
> |
#ifndef BSD |
185 |
> |
signal(SIGCONT, report); |
186 |
> |
#endif |
187 |
|
} |
188 |
|
#else |
189 |
+ |
void |
190 |
|
report() /* report progress */ |
191 |
|
{ |
192 |
< |
tlastrept = time((long *)0); |
193 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
192 |
> |
tlastrept = time((time_t *)NULL); |
193 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
194 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
195 |
|
eputs(errmsg); |
134 |
– |
signal(SIGALRM, report); |
196 |
|
} |
197 |
|
#endif |
198 |
|
|
199 |
|
|
200 |
< |
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 |
< |
|
200 |
> |
void |
201 |
|
rpict(seq, pout, zout, prvr) /* generate image(s) */ |
202 |
|
int seq; |
203 |
|
char *pout, *zout, *prvr; |
213 |
|
* sequenced file naming. |
214 |
|
*/ |
215 |
|
{ |
184 |
– |
extern char *rindex(), *strncpy(), *strcat(); |
216 |
|
char fbuf[128], fbuf2[128]; |
217 |
+ |
int npicts; |
218 |
|
register char *cp; |
219 |
< |
RESOLU rs; |
220 |
< |
double pa; |
189 |
< |
/* finished writing header */ |
190 |
< |
closeheader(); |
219 |
> |
RESOLU rs; |
220 |
> |
double pa; |
221 |
|
/* check sampling */ |
222 |
|
if (psample < 1) |
223 |
|
psample = 1; |
239 |
|
for ( ; seq < rn; seq++) |
240 |
|
if (nextview(stdin) == EOF) |
241 |
|
error(USER, "unexpected EOF on view input"); |
242 |
+ |
setview(&ourview); |
243 |
|
prvr = fbuf; /* mark for renaming */ |
244 |
|
} |
245 |
< |
if (pout != NULL) { |
245 |
> |
if (pout != NULL & prvr != NULL) { |
246 |
|
sprintf(fbuf, pout, seq); |
247 |
< |
if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ |
248 |
< |
fbuf2[0] = '\0'; |
249 |
< |
if ((cp = rindex(fbuf, '/')) != NULL) |
250 |
< |
strncpy(fbuf2, fbuf, cp-fbuf+1); |
251 |
< |
strcat(fbuf2, RFTEMPLATE); |
247 |
> |
if (!strcmp(prvr, fbuf)) { /* rename */ |
248 |
> |
strcpy(fbuf2, fbuf); |
249 |
> |
for (cp = fbuf2; *cp; cp++) |
250 |
> |
; |
251 |
> |
while (cp > fbuf2 && !ISDIRSEP(cp[-1])) |
252 |
> |
cp--; |
253 |
> |
strcpy(cp, RFTEMPLATE); |
254 |
|
prvr = mktemp(fbuf2); |
255 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
256 |
< |
sprintf(errmsg, |
255 |
> |
if (rename(fbuf, prvr) < 0) |
256 |
> |
if (errno == ENOENT) { /* ghost file */ |
257 |
> |
sprintf(errmsg, |
258 |
> |
"new output file \"%s\"", |
259 |
> |
fbuf); |
260 |
> |
error(WARNING, errmsg); |
261 |
> |
prvr = NULL; |
262 |
> |
} else { /* serious error */ |
263 |
> |
sprintf(errmsg, |
264 |
|
"cannot rename \"%s\" to \"%s\"", |
265 |
|
fbuf, prvr); |
266 |
< |
error(SYSTEM, errmsg); |
267 |
< |
} |
266 |
> |
error(SYSTEM, errmsg); |
267 |
> |
} |
268 |
|
} |
269 |
|
} |
270 |
< |
/* render sequence */ |
270 |
> |
npicts = 0; /* render sequence */ |
271 |
|
do { |
272 |
|
if (seq && nextview(stdin) == EOF) |
273 |
|
break; |
274 |
+ |
pctdone = 0.0; |
275 |
|
if (pout != NULL) { |
276 |
|
sprintf(fbuf, pout, seq); |
277 |
+ |
if (file_exists(fbuf)) { |
278 |
+ |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
279 |
+ |
sprintf(errmsg, |
280 |
+ |
"output file \"%s\" exists", |
281 |
+ |
fbuf); |
282 |
+ |
error(USER, errmsg); |
283 |
+ |
} |
284 |
+ |
setview(&ourview); |
285 |
+ |
continue; /* don't clobber */ |
286 |
+ |
} |
287 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
288 |
|
sprintf(errmsg, |
289 |
|
"cannot open output file \"%s\"", fbuf); |
290 |
|
error(SYSTEM, errmsg); |
291 |
|
} |
292 |
+ |
#ifdef MSDOS |
293 |
+ |
setmode(fileno(stdout), O_BINARY); |
294 |
+ |
#endif |
295 |
|
dupheader(); |
296 |
|
} |
297 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
298 |
|
if (prvr != NULL) |
299 |
|
if (viewfile(prvr, &ourview, &rs) <= 0 |
300 |
< |
|| rs.or != PIXSTANDARD) { |
300 |
> |
|| rs.rt != PIXSTANDARD) { |
301 |
|
sprintf(errmsg, |
302 |
|
"cannot recover view parameters from \"%s\"", prvr); |
303 |
|
error(WARNING, errmsg); |
331 |
|
cp = NULL; |
332 |
|
render(cp, prvr); |
333 |
|
prvr = NULL; |
334 |
+ |
npicts++; |
335 |
|
} while (seq++); |
336 |
+ |
/* check that we did something */ |
337 |
+ |
if (npicts == 0) |
338 |
+ |
error(WARNING, "no output produced"); |
339 |
|
} |
340 |
|
|
341 |
|
|
344 |
|
{ |
345 |
|
char linebuf[256]; |
346 |
|
|
347 |
+ |
copystruct(&lastview, &ourview); |
348 |
|
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) |
349 |
|
if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) |
350 |
|
return(0); |
355 |
|
render(zfile, oldfile) /* render the scene */ |
356 |
|
char *zfile, *oldfile; |
357 |
|
{ |
299 |
– |
extern long lseek(); |
358 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
359 |
|
float *zbar[MAXDIV+1]; /* z values */ |
360 |
|
char *sampdens; /* previous sample density */ |
365 |
|
COLOR *colptr; |
366 |
|
float *zptr; |
367 |
|
register int i; |
368 |
+ |
/* check for empty image */ |
369 |
+ |
if (hres <= 0 || vres <= 0) { |
370 |
+ |
error(WARNING, "empty output picture"); |
371 |
+ |
fprtresolu(0, 0, stdout); |
372 |
+ |
return; |
373 |
+ |
} |
374 |
|
/* allocate scanlines */ |
375 |
|
for (i = 0; i <= psample; i++) { |
376 |
|
scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); |
381 |
|
ystep = (psample*99+70)/140; |
382 |
|
if (hstep > 2) { |
383 |
|
i = hres/hstep + 2; |
384 |
< |
if ((sampdens = malloc(i)) == NULL) |
384 |
> |
if ((sampdens = (char *)malloc(i)) == NULL) |
385 |
|
goto memerr; |
386 |
|
while (i--) |
387 |
|
sampdens[i] = hstep; |
388 |
|
} else |
389 |
|
sampdens = NULL; |
390 |
< |
/* open z file */ |
390 |
> |
/* open z-file */ |
391 |
|
if (zfile != NULL) { |
392 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
393 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
393 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
394 |
|
error(SYSTEM, errmsg); |
395 |
|
} |
396 |
+ |
#ifdef MSDOS |
397 |
+ |
setmode(zfd, O_BINARY); |
398 |
+ |
#endif |
399 |
|
for (i = 0; i <= psample; i++) { |
400 |
|
zbar[i] = (float *)malloc(hres*sizeof(float)); |
401 |
|
if (zbar[i] == NULL) |
410 |
|
fprtresolu(hres, vres, stdout); |
411 |
|
/* recover file and compute first */ |
412 |
|
i = salvage(oldfile); |
413 |
+ |
if (i >= vres) |
414 |
+ |
goto alldone; |
415 |
|
if (zfd != -1 && i > 0 && |
416 |
< |
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
417 |
< |
error(SYSTEM, "z file seek error in render"); |
416 |
> |
lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) |
417 |
> |
error(SYSTEM, "z-file seek error in render"); |
418 |
|
pctdone = 100.0*i/vres; |
419 |
|
if (ralrm > 0) /* report init stats */ |
420 |
|
report(); |
421 |
< |
#ifndef BSD |
421 |
> |
#ifndef BSD |
422 |
|
else |
423 |
|
#endif |
424 |
< |
signal(SIGALRM, report); |
425 |
< |
ypos = vres-1 - i; |
424 |
> |
signal(SIGCONT, report); |
425 |
> |
ypos = vres-1 - i; /* initialize sampling */ |
426 |
> |
if (directvis) |
427 |
> |
init_drawsources(psample); |
428 |
|
fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); |
429 |
|
/* compute scanlines */ |
430 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
444 |
|
hres, ypos, hstep); |
445 |
|
/* fill bar */ |
446 |
|
fillscanbar(scanbar, zbar, hres, ypos, ystep); |
447 |
+ |
if (directvis) /* add bitty sources */ |
448 |
+ |
drawsources(scanbar, zbar, 0, hres, ypos, ystep); |
449 |
|
/* write it out */ |
450 |
< |
#ifndef BSD |
451 |
< |
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
450 |
> |
#ifndef BSD |
451 |
> |
signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ |
452 |
|
#endif |
453 |
|
for (i = ystep; i > 0; i--) { |
454 |
|
if (zfd != -1 && write(zfd, (char *)zbar[i], |
462 |
|
goto writerr; |
463 |
|
/* record progress */ |
464 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
465 |
< |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
465 |
> |
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
466 |
|
report(); |
467 |
< |
#ifndef BSD |
467 |
> |
#ifndef BSD |
468 |
|
else |
469 |
< |
signal(SIGALRM, report); |
469 |
> |
signal(SIGCONT, report); |
470 |
|
#endif |
471 |
|
} |
472 |
|
/* clean up */ |
473 |
< |
signal(SIGALRM, SIG_IGN); |
474 |
< |
if (zfd != -1) { |
402 |
< |
if (write(zfd, (char *)zbar[0], hres*sizeof(float)) |
473 |
> |
signal(SIGCONT, SIG_IGN); |
474 |
> |
if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float)) |
475 |
|
< hres*sizeof(float)) |
476 |
< |
goto writerr; |
476 |
> |
goto writerr; |
477 |
> |
fwritescan(scanbar[0], hres, stdout); |
478 |
> |
if (fflush(stdout) == EOF) |
479 |
> |
goto writerr; |
480 |
> |
alldone: |
481 |
> |
if (zfd != -1) { |
482 |
|
if (close(zfd) == -1) |
483 |
|
goto writerr; |
484 |
|
for (i = 0; i <= psample; i++) |
485 |
< |
free((char *)zbar[i]); |
485 |
> |
free((void *)zbar[i]); |
486 |
|
} |
410 |
– |
fwritescan(scanbar[0], hres, stdout); |
411 |
– |
if (fflush(stdout) == EOF) |
412 |
– |
goto writerr; |
487 |
|
for (i = 0; i <= psample; i++) |
488 |
< |
free((char *)scanbar[i]); |
488 |
> |
free((void *)scanbar[i]); |
489 |
|
if (sampdens != NULL) |
490 |
|
free(sampdens); |
491 |
|
pctdone = 100.0; |
492 |
|
if (ralrm > 0) |
493 |
|
report(); |
494 |
+ |
signal(SIGCONT, SIG_DFL); |
495 |
|
return; |
496 |
|
writerr: |
497 |
|
error(SYSTEM, "write error in render"); |
501 |
|
|
502 |
|
|
503 |
|
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
504 |
< |
register COLOR *scanline; |
505 |
< |
register float *zline; |
504 |
> |
register COLOR *scanline; |
505 |
> |
register float *zline; |
506 |
|
register char *sd; |
507 |
|
int xres, y, xstep; |
508 |
|
{ |
509 |
|
static int nc = 0; /* number of calls */ |
510 |
|
int bl = xstep, b = xstep; |
511 |
< |
double z; |
511 |
> |
double z; |
512 |
|
register int i; |
513 |
< |
|
513 |
> |
|
514 |
|
z = pixvalue(scanline[0], 0, y); |
515 |
|
if (zline) zline[0] = z; |
516 |
|
/* zig-zag start for quincunx pattern */ |
526 |
|
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
527 |
|
else |
528 |
|
b = fillsample(scanline+i-xstep, |
529 |
< |
zline ? zline+i-xstep : NULL, |
529 |
> |
zline ? zline+i-xstep : (float *)NULL, |
530 |
|
i-xstep, y, xstep, 0, b/2); |
531 |
|
if (sd) *sd++ = nc & 1 ? bl : b; |
532 |
|
bl = b; |
536 |
|
|
537 |
|
|
538 |
|
fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ |
539 |
< |
register COLOR *scanbar[]; |
540 |
< |
register float *zbar[]; |
539 |
> |
register COLOR *scanbar[]; |
540 |
> |
register float *zbar[]; |
541 |
|
int xres, y, ysize; |
542 |
|
{ |
543 |
|
COLOR vline[MAXDIV+1]; |
544 |
|
float zline[MAXDIV+1]; |
545 |
|
int b = ysize; |
546 |
|
register int i, j; |
547 |
< |
|
547 |
> |
|
548 |
|
for (i = 0; i < xres; i++) { |
474 |
– |
|
549 |
|
copycolor(vline[0], scanbar[0][i]); |
550 |
|
copycolor(vline[ysize], scanbar[ysize][i]); |
551 |
|
if (zbar[0]) { |
552 |
|
zline[0] = zbar[0][i]; |
553 |
|
zline[ysize] = zbar[ysize][i]; |
554 |
|
} |
555 |
< |
|
482 |
< |
b = fillsample(vline, zbar[0] ? zline : NULL, |
555 |
> |
b = fillsample(vline, zbar[0] ? zline : (float *)NULL, |
556 |
|
i, y, 0, ysize, b/2); |
557 |
< |
|
557 |
> |
|
558 |
|
for (j = 1; j < ysize; j++) |
559 |
|
copycolor(scanbar[j][i], vline[j]); |
560 |
|
if (zbar[0]) |
565 |
|
|
566 |
|
|
567 |
|
int |
568 |
< |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
569 |
< |
register COLOR *colline; |
570 |
< |
register float *zline; |
568 |
> |
fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ |
569 |
> |
register COLOR *colline; |
570 |
> |
register float *zline; |
571 |
|
int x, y; |
572 |
|
int xlen, ylen; |
573 |
|
int b; |
574 |
|
{ |
575 |
< |
extern double fabs(); |
576 |
< |
double ratio; |
504 |
< |
double z; |
575 |
> |
double ratio; |
576 |
> |
double z; |
577 |
|
COLOR ctmp; |
578 |
|
int ncut; |
579 |
|
register int len; |
580 |
< |
|
580 |
> |
|
581 |
|
if (xlen > 0) /* x or y length is zero */ |
582 |
|
len = xlen; |
583 |
|
else |
584 |
|
len = ylen; |
585 |
< |
|
585 |
> |
|
586 |
|
if (len <= 1) /* limit recursion */ |
587 |
|
return(0); |
588 |
< |
|
589 |
< |
if (b > 0 |
590 |
< |
|| (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len])) |
588 |
> |
|
589 |
> |
if (b > 0 || |
590 |
> |
(zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len])) |
591 |
|
|| bigdiff(colline[0], colline[len], maxdiff)) { |
592 |
< |
|
592 |
> |
|
593 |
|
z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1)); |
594 |
|
if (zline) zline[len>>1] = z; |
595 |
|
ncut = 1; |
524 |
– |
|
596 |
|
} else { /* interpolate */ |
526 |
– |
|
597 |
|
copycolor(colline[len>>1], colline[len]); |
598 |
|
ratio = (double)(len>>1) / len; |
599 |
|
scalecolor(colline[len>>1], ratio); |
607 |
|
} |
608 |
|
/* recurse */ |
609 |
|
ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2); |
610 |
< |
|
611 |
< |
ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL, |
610 |
> |
|
611 |
> |
ncut += fillsample(colline+(len>>1), |
612 |
> |
zline ? zline+(len>>1) : (float *)NULL, |
613 |
|
x+(xlen>>1), y+(ylen>>1), |
614 |
|
xlen-(xlen>>1), ylen-(ylen>>1), b/2); |
615 |
|
|
622 |
|
COLOR col; /* returned color */ |
623 |
|
int x, y; /* pixel position */ |
624 |
|
{ |
625 |
< |
static RAY thisray; |
626 |
< |
|
627 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
628 |
< |
(x+pixjitter())/hres, (y+pixjitter())/vres) < 0) { |
625 |
> |
RAY thisray; |
626 |
> |
FVECT lorg, ldir; |
627 |
> |
double hpos, vpos, lmax, d; |
628 |
> |
/* compute view ray */ |
629 |
> |
hpos = (x+pixjitter())/hres; |
630 |
> |
vpos = (y+pixjitter())/vres; |
631 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
632 |
> |
&ourview, hpos, vpos)) < -FTINY) { |
633 |
|
setcolor(col, 0.0, 0.0, 0.0); |
634 |
|
return(0.0); |
635 |
|
} |
636 |
|
|
562 |
– |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
563 |
– |
|
637 |
|
samplendx = pixnumber(x,y,hres,vres); /* set pixel index */ |
638 |
|
|
639 |
+ |
/* optional motion blur */ |
640 |
+ |
if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir, |
641 |
+ |
&lastview, hpos, vpos)) >= -FTINY) { |
642 |
+ |
register int i; |
643 |
+ |
register double d = mblur*(.5-urand(281+samplendx)); |
644 |
+ |
|
645 |
+ |
thisray.rmax = (1.-d)*thisray.rmax + d*lmax; |
646 |
+ |
for (i = 3; i--; ) { |
647 |
+ |
thisray.rorg[i] = (1.-d)*thisray.rorg[i] + d*lorg[i]; |
648 |
+ |
thisray.rdir[i] = (1.-d)*thisray.rdir[i] + d*ldir[i]; |
649 |
+ |
} |
650 |
+ |
if (normalize(thisray.rdir) == 0.0) |
651 |
+ |
return(0.0); |
652 |
+ |
} |
653 |
+ |
|
654 |
+ |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
655 |
+ |
|
656 |
|
rayvalue(&thisray); /* trace ray */ |
657 |
|
|
658 |
|
copycolor(col, thisray.rcol); /* return color */ |
659 |
< |
|
659 |
> |
|
660 |
|
return(thisray.rt); /* return distance */ |
661 |
|
} |
662 |
|
|
670 |
|
int x, y; |
671 |
|
|
672 |
|
if (oldfile == NULL) |
673 |
< |
return(0); |
674 |
< |
|
673 |
> |
goto gotzip; |
674 |
> |
|
675 |
|
if ((fp = fopen(oldfile, "r")) == NULL) { |
676 |
|
sprintf(errmsg, "cannot open recover file \"%s\"", oldfile); |
677 |
|
error(WARNING, errmsg); |
678 |
< |
return(0); |
678 |
> |
goto gotzip; |
679 |
|
} |
680 |
+ |
#ifdef MSDOS |
681 |
+ |
setmode(fileno(fp), O_BINARY); |
682 |
+ |
#endif |
683 |
|
/* discard header */ |
684 |
< |
getheader(fp, NULL); |
684 |
> |
getheader(fp, NULL, NULL); |
685 |
|
/* get picture size */ |
686 |
|
if (!fscnresolu(&x, &y, fp)) { |
687 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
687 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
688 |
> |
oldfile); |
689 |
|
error(WARNING, errmsg); |
690 |
|
fclose(fp); |
691 |
< |
return(0); |
691 |
> |
goto gotzip; |
692 |
|
} |
693 |
|
|
694 |
|
if (x != hres || y != vres) { |
708 |
|
} |
709 |
|
if (fflush(stdout) == EOF) |
710 |
|
goto writerr; |
711 |
< |
free((char *)scanline); |
711 |
> |
free((void *)scanline); |
712 |
|
fclose(fp); |
713 |
|
unlink(oldfile); |
714 |
|
return(y); |
715 |
+ |
gotzip: |
716 |
+ |
if (fflush(stdout) == EOF) |
717 |
+ |
error(SYSTEM, "error writing picture header"); |
718 |
+ |
return(0); |
719 |
|
writerr: |
720 |
|
sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); |
721 |
|
error(SYSTEM, errmsg); |