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 |
52 |
|
int ndims = 0; /* number of sampling dimensions */ |
53 |
|
int samplendx; /* sample index number */ |
54 |
|
|
54 |
– |
//extern void ambnotify(); |
55 |
|
void (*addobjnotify[])() = {ambnotify, NULL}; |
56 |
|
|
57 |
|
VIEW ourview = STDVIEW; /* view parameters */ |
92 |
|
int backvis = 1; /* back face visibility */ |
93 |
|
|
94 |
|
int maxdepth = 7; /* maximum recursion depth */ |
95 |
< |
double minweight = 4e-3; /* minimum ray weight */ |
95 |
> |
double minweight = 1e-3; /* minimum ray weight */ |
96 |
|
|
97 |
|
char *ambfile = NULL; /* ambient file name */ |
98 |
|
COLOR ambval = BLKCOLOR; /* ambient value */ |
119 |
|
|
120 |
|
static VIEW lastview; /* the previous view input */ |
121 |
|
|
122 |
– |
//extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ |
123 |
– |
|
124 |
– |
//double pixvalue(); |
125 |
– |
|
122 |
|
static void report(int); |
123 |
|
static int nextview(FILE *fp); |
124 |
|
static void render(char *zfile, char *oldfile); |
168 |
|
static void |
169 |
|
report(int dummy) /* report progress */ |
170 |
|
{ |
171 |
< |
double u, s; |
171 |
> |
char bcStat [128]; |
172 |
> |
double u, s; |
173 |
|
#ifdef BSD |
174 |
< |
struct rusage rubuf; |
174 |
> |
struct rusage rubuf; |
175 |
|
#else |
176 |
< |
struct tms tbuf; |
177 |
< |
double period; |
176 |
> |
double period = 1.0 / 60.0; |
177 |
> |
struct tms tbuf; |
178 |
|
#endif |
179 |
|
|
180 |
|
tlastrept = time((time_t *)NULL); |
181 |
|
#ifdef BSD |
182 |
|
getrusage(RUSAGE_SELF, &rubuf); |
183 |
< |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
184 |
< |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
183 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; |
184 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; |
185 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
186 |
< |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
187 |
< |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
186 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; |
187 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; |
188 |
|
#else |
189 |
|
times(&tbuf); |
190 |
|
#ifdef _SC_CLK_TCK |
191 |
|
period = 1.0 / sysconf(_SC_CLK_TCK); |
195 |
– |
#else |
196 |
– |
period = 1.0 / 60.0; |
192 |
|
#endif |
193 |
|
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
194 |
|
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
195 |
|
#endif |
196 |
|
|
197 |
+ |
/* PMAP: Get photon map bias compensation statistics */ |
198 |
+ |
pmapBiasCompReport(bcStat); |
199 |
+ |
|
200 |
|
sprintf(errmsg, |
201 |
< |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
202 |
< |
nrays, pctdone, u/3600., s/3600., |
203 |
< |
(tlastrept-tstart)/3600., myhostname()); |
201 |
> |
"%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n", |
202 |
> |
nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.), |
203 |
> |
(tlastrept-tstart)*(1./3600.), myhostname(), getpid()); |
204 |
|
eputs(errmsg); |
205 |
|
#ifdef SIGCONT |
206 |
|
signal(SIGCONT, report); |
210 |
|
static void |
211 |
|
report(int dummy) /* report progress */ |
212 |
|
{ |
213 |
+ |
char bcStat [128]; |
214 |
+ |
|
215 |
|
tlastrept = time((time_t *)NULL); |
216 |
< |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
217 |
< |
nrays, pctdone, (tlastrept-tstart)/3600.0); |
216 |
> |
|
217 |
> |
/* PMAP: Get photon map bias compensation statistics */ |
218 |
> |
pmapBiasCompReport(bcStat); |
219 |
> |
|
220 |
> |
sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n", |
221 |
> |
nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0); |
222 |
|
eputs(errmsg); |
223 |
|
} |
224 |
|
#endif |
225 |
|
|
226 |
|
|
227 |
< |
extern void |
227 |
> |
void |
228 |
|
rpict( /* generate image(s) */ |
229 |
|
int seq, |
230 |
|
char *pout, |
245 |
|
{ |
246 |
|
char fbuf[128], fbuf2[128]; |
247 |
|
int npicts; |
248 |
< |
register char *cp; |
248 |
> |
char *cp; |
249 |
|
RESOLU rs; |
250 |
|
double pa; |
251 |
|
/* check sampling */ |
261 |
|
if (seq <= 0) |
262 |
|
seq = 0; |
263 |
|
else if (prvr != NULL && isint(prvr)) { |
264 |
< |
register int rn; /* skip to specified view */ |
264 |
> |
int rn; /* skip to specified view */ |
265 |
|
if ((rn = atoi(prvr)) < seq) |
266 |
|
error(USER, "recover frame less than start frame"); |
267 |
|
if (pout == NULL) |
350 |
|
fputs(VIEWSTR, stdout); |
351 |
|
fprintview(&ourview, stdout); |
352 |
|
putchar('\n'); |
353 |
< |
if (pa < .99 || pa > 1.01) |
353 |
> |
if ((pa < .99) | (pa > 1.01)) |
354 |
|
fputaspect(pa, stdout); |
355 |
|
fputnow(stdout); |
356 |
|
fputformat(COLRFMT, stdout); |
399 |
|
int zfd; |
400 |
|
COLOR *colptr; |
401 |
|
float *zptr; |
402 |
< |
register int i; |
402 |
> |
int i; |
403 |
|
/* check for empty image */ |
404 |
< |
if (hres <= 0 || vres <= 0) { |
404 |
> |
if ((hres <= 0) | (vres <= 0)) { |
405 |
|
error(WARNING, "empty output picture"); |
406 |
|
fprtresolu(0, 0, stdout); |
407 |
|
return; |
445 |
|
i = salvage(oldfile); |
446 |
|
if (i >= vres) |
447 |
|
goto alldone; |
448 |
< |
if (zfd != -1 && i > 0 && |
448 |
> |
if ((zfd != -1) & (i > 0) && |
449 |
|
lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0) |
450 |
|
error(SYSTEM, "z-file seek error in render"); |
451 |
|
pctdone = 100.0*i/vres; |
539 |
|
|
540 |
|
static void |
541 |
|
fillscanline( /* fill scan at y */ |
542 |
< |
register COLOR *scanline, |
543 |
< |
register float *zline, |
544 |
< |
register char *sd, |
542 |
> |
COLOR *scanline, |
543 |
> |
float *zline, |
544 |
> |
char *sd, |
545 |
|
int xres, |
546 |
|
int y, |
547 |
|
int xstep |
550 |
|
static int nc = 0; /* number of calls */ |
551 |
|
int bl = xstep, b = xstep; |
552 |
|
double z; |
553 |
< |
register int i; |
553 |
> |
int i; |
554 |
|
|
555 |
|
z = pixvalue(scanline[0], 0, y); |
556 |
|
if (zline) zline[0] = z; |
578 |
|
|
579 |
|
static void |
580 |
|
fillscanbar( /* fill interior */ |
581 |
< |
register COLOR *scanbar[], |
582 |
< |
register float *zbar[], |
581 |
> |
COLOR *scanbar[], |
582 |
> |
float *zbar[], |
583 |
|
int xres, |
584 |
|
int y, |
585 |
|
int ysize |
588 |
|
COLOR vline[MAXDIV+1]; |
589 |
|
float zline[MAXDIV+1]; |
590 |
|
int b = ysize; |
591 |
< |
register int i, j; |
591 |
> |
int i, j; |
592 |
|
|
593 |
|
for (i = 0; i < xres; i++) { |
594 |
|
copycolor(vline[0], scanbar[0][i]); |
611 |
|
|
612 |
|
static int |
613 |
|
fillsample( /* fill interior points */ |
614 |
< |
register COLOR *colline, |
615 |
< |
register float *zline, |
614 |
> |
COLOR *colline, |
615 |
> |
float *zline, |
616 |
|
int x, |
617 |
|
int y, |
618 |
|
int xlen, |
624 |
|
double z; |
625 |
|
COLOR ctmp; |
626 |
|
int ncut; |
627 |
< |
register int len; |
627 |
> |
int len; |
628 |
|
|
629 |
|
if (xlen > 0) /* x or y length is zero */ |
630 |
|
len = xlen; |
672 |
|
int y |
673 |
|
) |
674 |
|
{ |
675 |
+ |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
676 |
|
RAY thisray; |
677 |
|
FVECT lorg, ldir; |
678 |
|
double hpos, vpos, vdist, lmax; |
679 |
< |
register int i; |
679 |
> |
int i; |
680 |
|
/* compute view ray */ |
681 |
+ |
setcolor(col, 0.0, 0.0, 0.0); |
682 |
|
hpos = (x+pixjitter())/hres; |
683 |
|
vpos = (y+pixjitter())/vres; |
684 |
|
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
685 |
< |
&ourview, hpos, vpos)) < -FTINY) { |
680 |
< |
setcolor(col, 0.0, 0.0, 0.0); |
685 |
> |
&ourview, hpos, vpos)) < -FTINY) |
686 |
|
return(0.0); |
687 |
< |
} |
687 |
> |
|
688 |
|
vdist = ourview.vdist; |
689 |
|
/* set pixel index */ |
690 |
|
samplendx = pixnumber(x,y,hres,vres); |
691 |
|
/* optional motion blur */ |
692 |
|
if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir, |
693 |
|
&lastview, hpos, vpos)) >= -FTINY) { |
694 |
< |
register double d = mblur*(.5-urand(281+samplendx)); |
694 |
> |
double d = mblur*(.5-urand(281+samplendx)); |
695 |
|
|
696 |
|
thisray.rmax = (1.-d)*thisray.rmax + d*lmax; |
697 |
|
for (i = 3; i--; ) { |
703 |
|
vdist = (1.-d)*vdist + d*lastview.vdist; |
704 |
|
} |
705 |
|
/* optional depth-of-field */ |
706 |
< |
if (dblur > FTINY && vdist > FTINY) { |
707 |
< |
double vc, dfh, dfv; |
708 |
< |
/* PI/4. square/circle conv. */ |
709 |
< |
dfh = PI/4.*dblur*(.5 - frandom()); |
710 |
< |
dfv = PI/4.*dblur*(.5 - frandom()); |
711 |
< |
if (ourview.type == VT_PER || ourview.type == VT_PAR) { |
712 |
< |
dfh /= sqrt(ourview.hn2); |
713 |
< |
dfv /= sqrt(ourview.vn2); |
706 |
> |
if (dblur > FTINY) { |
707 |
> |
double vc, df[2]; |
708 |
> |
/* random point on disk */ |
709 |
> |
SDsquare2disk(df, frandom(), frandom()); |
710 |
> |
df[0] *= .5*dblur; |
711 |
> |
df[1] *= .5*dblur; |
712 |
> |
if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) { |
713 |
> |
double adj = 1.0; |
714 |
> |
if (ourview.type == VT_PER) |
715 |
> |
adj /= DOT(thisray.rdir, ourview.vdir); |
716 |
> |
df[0] /= sqrt(ourview.hn2); |
717 |
> |
df[1] /= sqrt(ourview.vn2); |
718 |
|
for (i = 3; i--; ) { |
719 |
< |
vc = thisray.rorg[i] + vdist*thisray.rdir[i]; |
720 |
< |
thisray.rorg[i] += dfh*ourview.hvec[i] + |
721 |
< |
dfv*ourview.vvec[i] ; |
719 |
> |
vc = ourview.vp[i] + adj*vdist*thisray.rdir[i]; |
720 |
> |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
721 |
> |
df[1]*ourview.vvec[i] ; |
722 |
|
thisray.rdir[i] = vc - thisray.rorg[i]; |
723 |
|
} |
724 |
|
} else { /* non-standard view case */ |
725 |
|
double dfd = PI/4.*dblur*(.5 - frandom()); |
726 |
< |
if (ourview.type != VT_ANG && ourview.type != VT_PLS) { |
726 |
> |
if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) { |
727 |
|
if (ourview.type != VT_CYL) |
728 |
< |
dfh /= sqrt(ourview.hn2); |
729 |
< |
dfv /= sqrt(ourview.vn2); |
728 |
> |
df[0] /= sqrt(ourview.hn2); |
729 |
> |
df[1] /= sqrt(ourview.vn2); |
730 |
|
} |
731 |
|
for (i = 3; i--; ) { |
732 |
< |
vc = thisray.rorg[i] + vdist*thisray.rdir[i]; |
733 |
< |
thisray.rorg[i] += dfh*ourview.hvec[i] + |
734 |
< |
dfv*ourview.vvec[i] + |
732 |
> |
vc = ourview.vp[i] + vdist*thisray.rdir[i]; |
733 |
> |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
734 |
> |
df[1]*ourview.vvec[i] + |
735 |
|
dfd*ourview.vdir[i] ; |
736 |
|
thisray.rdir[i] = vc - thisray.rorg[i]; |
737 |
|
} |
746 |
|
|
747 |
|
copycolor(col, thisray.rcol); /* return color */ |
748 |
|
|
749 |
< |
return(thisray.rt); /* return distance */ |
749 |
> |
return(raydistance(&thisray)); /* return distance */ |
750 |
|
} |
751 |
|
|
752 |
|
|
779 |
|
goto gotzip; |
780 |
|
} |
781 |
|
|
782 |
< |
if (x != hres || y != vres) { |
782 |
> |
if ((x != hres) | (y != vres)) { |
783 |
|
sprintf(errmsg, "resolution mismatch in recover file \"%s\"", |
784 |
|
oldfile); |
785 |
|
error(USER, errmsg); |
811 |
|
} |
812 |
|
|
813 |
|
static int |
814 |
< |
pixnumber( /* compute pixel index (brushed) */ |
815 |
< |
register int x, |
816 |
< |
register int y, |
814 |
> |
pixnumber( /* compute pixel index (screen door) */ |
815 |
> |
int x, |
816 |
> |
int y, |
817 |
|
int xres, |
818 |
|
int yres |
819 |
|
) |
820 |
|
{ |
821 |
< |
x -= y; |
822 |
< |
while (x < 0) |
823 |
< |
x += xres; |
824 |
< |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
821 |
> |
unsigned nbits = 0; |
822 |
> |
bitmask_t coord[2]; |
823 |
> |
|
824 |
> |
if (xres < yres) xres = yres; |
825 |
> |
while (xres > 0) { |
826 |
> |
xres >>= 1; |
827 |
> |
++nbits; |
828 |
> |
} |
829 |
> |
coord[0] = x; coord[1] = y; |
830 |
> |
return ((int)hilbert_c2i(2, nbits, coord)); |
831 |
|
} |