22 |
|
|
23 |
|
#include "view.h" |
24 |
|
|
25 |
+ |
#include "resolu.h" |
26 |
+ |
|
27 |
|
#include "random.h" |
28 |
|
|
29 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
42 |
|
double dstrsrc = 0.0; /* square source distribution */ |
43 |
|
double shadthresh = .05; /* shadow threshold */ |
44 |
|
double shadcert = .5; /* shadow certainty */ |
45 |
< |
int directrelay = 0; /* number of source relays */ |
45 |
> |
int directrelay = 1; /* number of source relays */ |
46 |
|
int vspretest = 512; /* virtual source pretest density */ |
47 |
|
int directinvis = 0; /* sources invisible? */ |
48 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
49 |
|
|
50 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
51 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
52 |
+ |
|
53 |
|
int maxdepth = 6; /* maximum recursion depth */ |
54 |
|
double minweight = 5e-3; /* minimum ray weight */ |
55 |
|
|
73 |
|
|
74 |
|
extern long nrays; /* number of rays traced */ |
75 |
|
|
76 |
< |
#define MAXDIV 15 /* maximum sample size */ |
76 |
> |
#define MAXDIV 16 /* maximum sample size */ |
77 |
|
|
78 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
79 |
|
|
111 |
|
#else |
112 |
|
report() /* report progress */ |
113 |
|
{ |
108 |
– |
signal(SIGALRM, report); |
114 |
|
tlastrept = time((long *)0); |
115 |
|
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
116 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
117 |
|
eputs(errmsg); |
118 |
+ |
signal(SIGALRM, report); |
119 |
|
} |
120 |
|
#endif |
121 |
|
|
126 |
|
extern long lseek(); |
127 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
128 |
|
float *zbar[MAXDIV+1]; /* z values */ |
129 |
+ |
char *sampdens; /* previous sample density */ |
130 |
|
int ypos; /* current scanline */ |
131 |
|
int ystep; /* current y step size */ |
132 |
|
int hstep; /* h step size */ |
149 |
|
if (scanbar[i] == NULL) |
150 |
|
goto memerr; |
151 |
|
} |
152 |
+ |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
153 |
+ |
ystep = (psample*99+70)/140; |
154 |
+ |
if (hstep > 2) { |
155 |
+ |
i = hresolu/hstep + 2; |
156 |
+ |
if ((sampdens = malloc(i)) == NULL) |
157 |
+ |
goto memerr; |
158 |
+ |
while (i--) |
159 |
+ |
sampdens[i] = hstep; |
160 |
+ |
} else |
161 |
+ |
sampdens = NULL; |
162 |
|
/* open z file */ |
163 |
|
if (zfile != NULL) { |
164 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
176 |
|
zbar[i] = NULL; |
177 |
|
} |
178 |
|
/* write out boundaries */ |
179 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
179 |
> |
fprtresolu(hresolu, vresolu, stdout); |
180 |
|
/* recover file and compute first */ |
181 |
|
i = salvage(oldfile); |
182 |
|
if (zfd != -1 && i > 0 && |
190 |
|
#endif |
191 |
|
signal(SIGALRM, report); |
192 |
|
ypos = vresolu-1 - i; |
193 |
< |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
177 |
< |
ystep = (psample*99+70)/140; |
178 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); |
193 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, hresolu, ypos, hstep); |
194 |
|
/* compute scanlines */ |
195 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
196 |
|
/* bottom adjust? */ |
205 |
|
zbar[ystep] = zbar[0]; |
206 |
|
zbar[0] = zptr; |
207 |
|
/* fill base line */ |
208 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); |
208 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, |
209 |
> |
hresolu, ypos, hstep); |
210 |
|
/* fill bar */ |
211 |
|
fillscanbar(scanbar, zbar, hresolu, ypos, ystep); |
212 |
|
/* write it out */ |
233 |
|
#endif |
234 |
|
} |
235 |
|
/* clean up */ |
236 |
+ |
signal(SIGALRM, SIG_IGN); |
237 |
|
if (zfd != -1) { |
238 |
|
if (write(zfd, (char *)zbar[0], hresolu*sizeof(float)) |
239 |
|
< hresolu*sizeof(float)) |
248 |
|
goto writerr; |
249 |
|
for (i = 0; i <= psample; i++) |
250 |
|
free((char *)scanbar[i]); |
251 |
+ |
if (sampdens != NULL) |
252 |
+ |
free(sampdens); |
253 |
|
pctdone = 100.0; |
254 |
|
return; |
255 |
|
writerr: |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
< |
fillscanline(scanline, zline, xres, y, xstep) /* fill scan line at y */ |
262 |
> |
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
263 |
|
register COLOR *scanline; |
264 |
|
register float *zline; |
265 |
+ |
register char *sd; |
266 |
|
int xres, y, xstep; |
267 |
|
{ |
268 |
|
static int nc = 0; /* number of calls */ |
269 |
< |
int b = xstep; |
269 |
> |
int bl = xstep, b = xstep; |
270 |
|
double z; |
271 |
|
register int i; |
272 |
|
|
273 |
|
z = pixvalue(scanline[0], 0, y); |
274 |
|
if (zline) zline[0] = z; |
275 |
|
/* zig-zag start for quincunx pattern */ |
276 |
< |
for (i = nc++ & 1 ? xstep/2 : xstep; i < xres-1+xstep; i += xstep) { |
276 |
> |
for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) { |
277 |
|
if (i >= xres) { |
278 |
|
xstep += xres-1-i; |
279 |
|
i = xres-1; |
280 |
|
} |
281 |
|
z = pixvalue(scanline[i], i, y); |
282 |
|
if (zline) zline[i] = z; |
283 |
< |
|
284 |
< |
b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, |
285 |
< |
i-xstep, y, xstep, 0, b/2); |
283 |
> |
if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1]; |
284 |
> |
if (i <= xstep) |
285 |
> |
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
286 |
> |
else |
287 |
> |
b = fillsample(scanline+i-xstep, |
288 |
> |
zline ? zline+i-xstep : NULL, |
289 |
> |
i-xstep, y, xstep, 0, b/2); |
290 |
> |
if (sd) *sd++ = nc & 1 ? bl : b; |
291 |
> |
bl = b; |
292 |
|
} |
293 |
+ |
if (sd && nc & 1) *sd = bl; |
294 |
|
} |
295 |
|
|
296 |
|
|
424 |
|
/* discard header */ |
425 |
|
getheader(fp, NULL); |
426 |
|
/* get picture size */ |
427 |
< |
if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) { |
427 |
> |
if (!fscnresolu(&x, &y, fp)) { |
428 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
429 |
|
error(WARNING, errmsg); |
430 |
|
fclose(fp); |