33 |
|
#include "view.h" |
34 |
|
#include "random.h" |
35 |
|
#include "paths.h" |
36 |
< |
#include "rtmisc.h" /* myhostname() */ |
36 |
> |
#include "hilbert.h" |
37 |
> |
#include "pmapbias.h" |
38 |
> |
#include "pmapdiag.h" |
39 |
|
|
38 |
– |
|
40 |
|
#define RFTEMPLATE "rfXXXXXX" |
41 |
|
|
42 |
|
#ifndef SIGCONT |
134 |
|
|
135 |
|
|
136 |
|
|
136 |
– |
#ifdef RHAS_STAT |
137 |
– |
#include <sys/types.h> |
138 |
– |
#include <sys/stat.h> |
139 |
– |
int |
140 |
– |
file_exists(fname) /* ordinary file exists? */ |
141 |
– |
char *fname; |
142 |
– |
{ |
143 |
– |
struct stat sbuf; |
144 |
– |
if (stat(fname, &sbuf) < 0) return(0); |
145 |
– |
return((sbuf.st_mode & S_IFREG) != 0); |
146 |
– |
} |
147 |
– |
#else |
148 |
– |
#define file_exists(f) (access(f,F_OK)==0) |
149 |
– |
#endif |
150 |
– |
|
151 |
– |
|
137 |
|
void |
138 |
< |
quit(code) /* quit program */ |
154 |
< |
int code; |
138 |
> |
quit(int code) /* quit program */ |
139 |
|
{ |
140 |
|
if (code) /* report status */ |
141 |
|
report(0); |
151 |
|
static void |
152 |
|
report(int dummy) /* report progress */ |
153 |
|
{ |
154 |
< |
double u, s; |
154 |
> |
char bcStat [128]; |
155 |
> |
double u, s; |
156 |
|
#ifdef BSD |
157 |
< |
struct rusage rubuf; |
157 |
> |
struct rusage rubuf; |
158 |
|
#else |
159 |
< |
struct tms tbuf; |
160 |
< |
double period; |
159 |
> |
double period = 1.0 / 60.0; |
160 |
> |
struct tms tbuf; |
161 |
|
#endif |
162 |
|
|
163 |
|
tlastrept = time((time_t *)NULL); |
164 |
|
#ifdef BSD |
165 |
|
getrusage(RUSAGE_SELF, &rubuf); |
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; |
166 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; |
167 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; |
168 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
169 |
< |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
170 |
< |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
169 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; |
170 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; |
171 |
|
#else |
172 |
|
times(&tbuf); |
173 |
|
#ifdef _SC_CLK_TCK |
174 |
|
period = 1.0 / sysconf(_SC_CLK_TCK); |
190 |
– |
#else |
191 |
– |
period = 1.0 / 60.0; |
175 |
|
#endif |
176 |
|
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
177 |
|
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
178 |
|
#endif |
179 |
|
|
180 |
+ |
/* PMAP: Get photon map bias compensation statistics */ |
181 |
+ |
pmapBiasCompReport(bcStat); |
182 |
+ |
|
183 |
|
sprintf(errmsg, |
184 |
< |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
185 |
< |
nrays, pctdone, u/3600., s/3600., |
186 |
< |
(tlastrept-tstart)/3600., myhostname()); |
184 |
> |
"%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n", |
185 |
> |
nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.), |
186 |
> |
(tlastrept-tstart)*(1./3600.), myhostname(), getpid()); |
187 |
|
eputs(errmsg); |
188 |
|
#ifdef SIGCONT |
189 |
|
signal(SIGCONT, report); |
193 |
|
static void |
194 |
|
report(int dummy) /* report progress */ |
195 |
|
{ |
196 |
+ |
char bcStat [128]; |
197 |
+ |
|
198 |
|
tlastrept = time((time_t *)NULL); |
199 |
< |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
200 |
< |
nrays, pctdone, (tlastrept-tstart)/3600.0); |
199 |
> |
|
200 |
> |
/* PMAP: Get photon map bias compensation statistics */ |
201 |
> |
pmapBiasCompReport(bcStat); |
202 |
> |
|
203 |
> |
sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n", |
204 |
> |
nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0); |
205 |
|
eputs(errmsg); |
206 |
|
} |
207 |
|
#endif |
208 |
|
|
209 |
|
|
210 |
< |
extern void |
210 |
> |
void |
211 |
|
rpict( /* generate image(s) */ |
212 |
|
int seq, |
213 |
|
char *pout, |
287 |
|
break; |
288 |
|
pctdone = 0.0; |
289 |
|
if (pout != NULL) { |
290 |
+ |
int myfd; |
291 |
+ |
close(1); /* reassign stdout */ |
292 |
|
sprintf(fbuf, pout, seq); |
293 |
< |
if (file_exists(fbuf)) { |
294 |
< |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
293 |
> |
tryagain: |
294 |
> |
errno = 0; /* exclusive open */ |
295 |
> |
if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) { |
296 |
> |
if ((errno != EEXIST) | (prvr != NULL) || |
297 |
> |
!strcmp(fbuf, pout)) { |
298 |
|
sprintf(errmsg, |
299 |
< |
"output file \"%s\" exists", |
299 |
> |
"cannot open output file \"%s\"", |
300 |
|
fbuf); |
301 |
< |
error(USER, errmsg); |
301 |
> |
error(SYSTEM, errmsg); |
302 |
|
} |
303 |
|
setview(&ourview); |
304 |
|
continue; /* don't clobber */ |
305 |
|
} |
306 |
< |
if (freopen(fbuf, "w", stdout) == NULL) { |
307 |
< |
sprintf(errmsg, |
308 |
< |
"cannot open output file \"%s\"", fbuf); |
312 |
< |
error(SYSTEM, errmsg); |
306 |
> |
if (myfd != 1) { |
307 |
> |
unlink(fbuf); |
308 |
> |
goto tryagain; /* leave it open */ |
309 |
|
} |
310 |
< |
SET_FILE_BINARY(stdout); |
310 |
> |
SET_FD_BINARY(1); |
311 |
|
dupheader(); |
312 |
|
} |
313 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
340 |
|
if ((pa < .99) | (pa > 1.01)) |
341 |
|
fputaspect(pa, stdout); |
342 |
|
fputnow(stdout); |
343 |
+ |
fputprims(stdprims, stdout); |
344 |
|
fputformat(COLRFMT, stdout); |
345 |
|
putchar('\n'); |
346 |
|
if (zout != NULL) |
660 |
|
int y |
661 |
|
) |
662 |
|
{ |
663 |
+ |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
664 |
|
RAY thisray; |
665 |
|
FVECT lorg, ldir; |
666 |
|
double hpos, vpos, vdist, lmax; |
692 |
|
} |
693 |
|
/* optional depth-of-field */ |
694 |
|
if (dblur > FTINY) { |
695 |
< |
double vc, dfh, dfv; |
696 |
< |
/* square/circle conv. */ |
697 |
< |
dfh = vc = 1. - 2.*frandom(); |
698 |
< |
dfv = 1. - 2.*frandom(); |
699 |
< |
dfh *= .5*dblur*sqrt(1. - .5*dfv*dfv); |
702 |
< |
dfv *= .5*dblur*sqrt(1. - .5*vc*vc); |
695 |
> |
double vc, df[2]; |
696 |
> |
/* random point on disk */ |
697 |
> |
SDsquare2disk(df, frandom(), frandom()); |
698 |
> |
df[0] *= .5*dblur; |
699 |
> |
df[1] *= .5*dblur; |
700 |
|
if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) { |
701 |
|
double adj = 1.0; |
702 |
|
if (ourview.type == VT_PER) |
703 |
|
adj /= DOT(thisray.rdir, ourview.vdir); |
704 |
< |
dfh /= sqrt(ourview.hn2); |
705 |
< |
dfv /= sqrt(ourview.vn2); |
704 |
> |
df[0] /= sqrt(ourview.hn2); |
705 |
> |
df[1] /= sqrt(ourview.vn2); |
706 |
|
for (i = 3; i--; ) { |
707 |
|
vc = ourview.vp[i] + adj*vdist*thisray.rdir[i]; |
708 |
< |
thisray.rorg[i] += dfh*ourview.hvec[i] + |
709 |
< |
dfv*ourview.vvec[i] ; |
708 |
> |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
709 |
> |
df[1]*ourview.vvec[i] ; |
710 |
|
thisray.rdir[i] = vc - thisray.rorg[i]; |
711 |
|
} |
712 |
|
} else { /* non-standard view case */ |
713 |
|
double dfd = PI/4.*dblur*(.5 - frandom()); |
714 |
|
if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) { |
715 |
|
if (ourview.type != VT_CYL) |
716 |
< |
dfh /= sqrt(ourview.hn2); |
717 |
< |
dfv /= sqrt(ourview.vn2); |
716 |
> |
df[0] /= sqrt(ourview.hn2); |
717 |
> |
df[1] /= sqrt(ourview.vn2); |
718 |
|
} |
719 |
|
for (i = 3; i--; ) { |
720 |
|
vc = ourview.vp[i] + vdist*thisray.rdir[i]; |
721 |
< |
thisray.rorg[i] += dfh*ourview.hvec[i] + |
722 |
< |
dfv*ourview.vvec[i] + |
721 |
> |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
722 |
> |
df[1]*ourview.vvec[i] + |
723 |
|
dfd*ourview.vdir[i] ; |
724 |
|
thisray.rdir[i] = vc - thisray.rorg[i]; |
725 |
|
} |
734 |
|
|
735 |
|
copycolor(col, thisray.rcol); /* return color */ |
736 |
|
|
737 |
< |
return(thisray.rt); /* return distance */ |
737 |
> |
return(raydistance(&thisray)); /* return distance */ |
738 |
|
} |
739 |
|
|
740 |
|
|
799 |
|
} |
800 |
|
|
801 |
|
static int |
802 |
< |
pixnumber( /* compute pixel index (brushed) */ |
802 |
> |
pixnumber( /* compute pixel index (screen door) */ |
803 |
|
int x, |
804 |
|
int y, |
805 |
|
int xres, |
806 |
|
int yres |
807 |
|
) |
808 |
|
{ |
809 |
< |
x -= y; |
810 |
< |
while (x < 0) |
811 |
< |
x += xres; |
812 |
< |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
809 |
> |
unsigned nbits = 0; |
810 |
> |
bitmask_t coord[2]; |
811 |
> |
|
812 |
> |
if (xres < yres) xres = yres; |
813 |
> |
while (xres > 0) { |
814 |
> |
xres >>= 1; |
815 |
> |
++nbits; |
816 |
> |
} |
817 |
> |
coord[0] = x; coord[1] = y; |
818 |
> |
return ((int)hilbert_c2i(2, nbits, coord)); |
819 |
|
} |