33 |
|
#include "view.h" |
34 |
|
#include "random.h" |
35 |
|
#include "paths.h" |
36 |
< |
#include "rtmisc.h" /* myhostname() */ |
36 |
> |
#include "hilbert.h" |
37 |
|
|
38 |
|
|
39 |
|
#define RFTEMPLATE "rfXXXXXX" |
167 |
|
static void |
168 |
|
report(int dummy) /* report progress */ |
169 |
|
{ |
170 |
< |
double u, s; |
170 |
> |
double u, s; |
171 |
|
#ifdef BSD |
172 |
< |
struct rusage rubuf; |
172 |
> |
struct rusage rubuf; |
173 |
|
#else |
174 |
< |
struct tms tbuf; |
175 |
< |
double period; |
174 |
> |
double period = 1.0 / 60.0; |
175 |
> |
struct tms tbuf; |
176 |
|
#endif |
177 |
|
|
178 |
|
tlastrept = time((time_t *)NULL); |
179 |
|
#ifdef BSD |
180 |
|
getrusage(RUSAGE_SELF, &rubuf); |
181 |
< |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
182 |
< |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
181 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; |
182 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; |
183 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
184 |
< |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
185 |
< |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
184 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; |
185 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; |
186 |
|
#else |
187 |
|
times(&tbuf); |
188 |
|
#ifdef _SC_CLK_TCK |
189 |
|
period = 1.0 / sysconf(_SC_CLK_TCK); |
190 |
– |
#else |
191 |
– |
period = 1.0 / 60.0; |
190 |
|
#endif |
191 |
|
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
192 |
|
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
193 |
|
#endif |
194 |
|
|
195 |
|
sprintf(errmsg, |
196 |
< |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
197 |
< |
nrays, pctdone, u/3600., s/3600., |
198 |
< |
(tlastrept-tstart)/3600., myhostname()); |
196 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n", |
197 |
> |
nrays, pctdone, u*(1./3600.), s*(1./3600.), |
198 |
> |
(tlastrept-tstart)*(1./3600.), myhostname(), getpid()); |
199 |
|
eputs(errmsg); |
200 |
|
#ifdef SIGCONT |
201 |
|
signal(SIGCONT, report); |
213 |
|
#endif |
214 |
|
|
215 |
|
|
216 |
< |
extern void |
216 |
> |
void |
217 |
|
rpict( /* generate image(s) */ |
218 |
|
int seq, |
219 |
|
char *pout, |
661 |
|
int y |
662 |
|
) |
663 |
|
{ |
664 |
+ |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
665 |
|
RAY thisray; |
666 |
|
FVECT lorg, ldir; |
667 |
|
double hpos, vpos, vdist, lmax; |
693 |
|
} |
694 |
|
/* optional depth-of-field */ |
695 |
|
if (dblur > FTINY) { |
696 |
< |
double vc, dfh, dfv; |
697 |
< |
/* square/circle conv. */ |
698 |
< |
dfh = vc = 1. - 2.*frandom(); |
699 |
< |
dfv = 1. - 2.*frandom(); |
700 |
< |
dfh *= .5*dblur*sqrt(1. - .5*dfv*dfv); |
702 |
< |
dfv *= .5*dblur*sqrt(1. - .5*vc*vc); |
696 |
> |
double vc, df[2]; |
697 |
> |
/* random point on disk */ |
698 |
> |
SDsquare2disk(df, frandom(), frandom()); |
699 |
> |
df[0] *= .5*dblur; |
700 |
> |
df[1] *= .5*dblur; |
701 |
|
if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) { |
702 |
|
double adj = 1.0; |
703 |
|
if (ourview.type == VT_PER) |
704 |
|
adj /= DOT(thisray.rdir, ourview.vdir); |
705 |
< |
dfh /= sqrt(ourview.hn2); |
706 |
< |
dfv /= sqrt(ourview.vn2); |
705 |
> |
df[0] /= sqrt(ourview.hn2); |
706 |
> |
df[1] /= sqrt(ourview.vn2); |
707 |
|
for (i = 3; i--; ) { |
708 |
|
vc = ourview.vp[i] + adj*vdist*thisray.rdir[i]; |
709 |
< |
thisray.rorg[i] += dfh*ourview.hvec[i] + |
710 |
< |
dfv*ourview.vvec[i] ; |
709 |
> |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
710 |
> |
df[1]*ourview.vvec[i] ; |
711 |
|
thisray.rdir[i] = vc - thisray.rorg[i]; |
712 |
|
} |
713 |
|
} else { /* non-standard view case */ |
714 |
|
double dfd = PI/4.*dblur*(.5 - frandom()); |
715 |
|
if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) { |
716 |
|
if (ourview.type != VT_CYL) |
717 |
< |
dfh /= sqrt(ourview.hn2); |
718 |
< |
dfv /= sqrt(ourview.vn2); |
717 |
> |
df[0] /= sqrt(ourview.hn2); |
718 |
> |
df[1] /= sqrt(ourview.vn2); |
719 |
|
} |
720 |
|
for (i = 3; i--; ) { |
721 |
|
vc = ourview.vp[i] + vdist*thisray.rdir[i]; |
722 |
< |
thisray.rorg[i] += dfh*ourview.hvec[i] + |
723 |
< |
dfv*ourview.vvec[i] + |
722 |
> |
thisray.rorg[i] += df[0]*ourview.hvec[i] + |
723 |
> |
df[1]*ourview.vvec[i] + |
724 |
|
dfd*ourview.vdir[i] ; |
725 |
|
thisray.rdir[i] = vc - thisray.rorg[i]; |
726 |
|
} |
800 |
|
} |
801 |
|
|
802 |
|
static int |
803 |
< |
pixnumber( /* compute pixel index (brushed) */ |
803 |
> |
pixnumber( /* compute pixel index (screen door) */ |
804 |
|
int x, |
805 |
|
int y, |
806 |
|
int xres, |
807 |
|
int yres |
808 |
|
) |
809 |
|
{ |
810 |
< |
x -= y; |
811 |
< |
while (x < 0) |
812 |
< |
x += xres; |
813 |
< |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
810 |
> |
unsigned nbits = 0; |
811 |
> |
bitmask_t coord[2]; |
812 |
> |
|
813 |
> |
if (xres < yres) xres = yres; |
814 |
> |
while (xres > 0) { |
815 |
> |
xres >>= 1; |
816 |
> |
++nbits; |
817 |
> |
} |
818 |
> |
coord[0] = x; coord[1] = y; |
819 |
> |
return ((int)hilbert_c2i(2, nbits, coord)); |
820 |
|
} |