14 |
|
|
15 |
|
|
16 |
|
packrays(rod, p) /* pack ray origins and directions */ |
17 |
< |
register float *rod; |
17 |
> |
float *rod; |
18 |
|
register PACKET *p; |
19 |
|
{ |
20 |
< |
static FVECT ro, rd; |
20 |
> |
static int nmh = 0; |
21 |
> |
static int *mhtab; |
22 |
> |
FVECT ro, rd; |
23 |
> |
register BEAM *bp; |
24 |
|
GCOORD gc[2]; |
25 |
< |
int ila[2], hsh; |
25 |
> |
int ila[4], offset; |
26 |
|
double d, sl[4]; |
27 |
< |
register int i; |
27 |
> |
register int i, j, k; |
28 |
|
|
29 |
|
if (!hdbcoord(gc, hdlist[p->hd], p->bi)) |
30 |
|
error(CONSISTENCY, "bad beam index in packrays"); |
31 |
+ |
/* uniqueness hash */ |
32 |
+ |
if ((bp = hdgetbeam(hdlist[p->hd], p->bi)) != NULL) { |
33 |
+ |
if (2*bp->nrm > nmh) { |
34 |
+ |
if (nmh) free((char *)mhtab); |
35 |
+ |
nmh = 2*bp->nrm + 1; |
36 |
+ |
mhtab = (int *)malloc(nmh*sizeof(int)); |
37 |
+ |
if (mhtab == NULL) |
38 |
+ |
error(SYSTEM, "out of memory in packrays"); |
39 |
+ |
} |
40 |
+ |
for (k = nmh; k--; ) |
41 |
+ |
mhtab[k] = -1; |
42 |
+ |
for (i = bp->nrm; i--; ) { |
43 |
+ |
ila[0] = hdbray(bp)[i].r[0][0]; |
44 |
+ |
ila[1] = hdbray(bp)[i].r[0][1]; |
45 |
+ |
ila[2] = hdbray(bp)[i].r[1][0]; |
46 |
+ |
ila[3] = hdbray(bp)[i].r[1][1]; |
47 |
+ |
for (k = ilhash(ila,4); mhtab[k%nmh] >= 0; k++) |
48 |
+ |
; |
49 |
+ |
mhtab[k%nmh] = i; |
50 |
+ |
} |
51 |
+ |
} |
52 |
+ |
/* init each ray */ |
53 |
|
ila[0] = p->hd; ila[1] = p->bi; |
54 |
< |
hsh = ilhash(ila,2) + p->nc; |
54 |
> |
offset = ilhash(ila,2) + p->nc; |
55 |
|
for (i = 0; i < p->nr; i++) { |
56 |
< |
multisamp(sl, 4, urand(hsh+i)); |
57 |
< |
p->ra[i].r[0][0] = sl[0] * 256.; |
58 |
< |
p->ra[i].r[0][1] = sl[1] * 256.; |
59 |
< |
p->ra[i].r[1][0] = sl[2] * 256.; |
60 |
< |
p->ra[i].r[1][1] = sl[3] * 256.; |
56 |
> |
do { /* next unique ray */ |
57 |
> |
multisamp(sl, 4, urand(offset+i)); |
58 |
> |
p->ra[i].r[0][0] = ila[0] = sl[0] * 256.; |
59 |
> |
p->ra[i].r[0][1] = ila[1] = sl[1] * 256.; |
60 |
> |
p->ra[i].r[1][0] = ila[2] = sl[2] * 256.; |
61 |
> |
p->ra[i].r[1][1] = ila[3] = sl[3] * 256.; |
62 |
> |
if (bp == NULL) |
63 |
> |
break; |
64 |
> |
for (k = ilhash(ila,4); (j = mhtab[k%nmh]) >= 0; k++) |
65 |
> |
if (hdbray(bp)[j].r[0][0] == |
66 |
> |
p->ra[i].r[0][0] && |
67 |
> |
hdbray(bp)[j].r[0][1] == |
68 |
> |
p->ra[i].r[0][1] && |
69 |
> |
hdbray(bp)[j].r[1][0] == |
70 |
> |
p->ra[i].r[1][0] && |
71 |
> |
hdbray(bp)[j].r[1][1] == |
72 |
> |
p->ra[i].r[1][1]) { |
73 |
> |
offset += bp->nrm - j; |
74 |
> |
break; |
75 |
> |
} |
76 |
> |
} while (j >= 0); |
77 |
|
d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r); |
78 |
|
if (!vdef(OBSTRUCTIONS)) |
79 |
|
d *= frandom(); /* random offset */ |