1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.3 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Binary space partitioning curve for multidimensional sampling. |
6 |
|
|
* |
7 |
|
|
* Written by Christophe Schlick |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.4 |
#include "copyright.h" |
11 |
greg |
2.3 |
|
12 |
|
|
#include "random.h" |
13 |
|
|
|
14 |
|
|
void |
15 |
greg |
1.1 |
multisamp(t, n, r) /* convert 1-dimensional sample to N dimensions */ |
16 |
|
|
double t[]; /* returned N-dimensional vector */ |
17 |
|
|
register int n; /* number of dimensions */ |
18 |
|
|
double r; /* 1-dimensional sample [0,1) */ |
19 |
|
|
{ |
20 |
|
|
int j; |
21 |
|
|
register int i, k; |
22 |
|
|
int ti[8]; |
23 |
|
|
double s; |
24 |
|
|
|
25 |
|
|
i = n; |
26 |
|
|
while (i-- > 0) |
27 |
|
|
ti[i] = 0; |
28 |
|
|
j = 8; |
29 |
|
|
while (j--) { |
30 |
|
|
k = s = r*(1<<n); |
31 |
|
|
r = s - k; |
32 |
|
|
i = n; |
33 |
|
|
while (i-- > 0) |
34 |
|
|
ti[i] += ti[i] + ((k>>i) & 1); |
35 |
|
|
} |
36 |
|
|
i = n; |
37 |
|
|
while (i-- > 0) |
38 |
gregl |
2.2 |
t[i] = 1./256. * (ti[i] + frandom()); |
39 |
greg |
1.1 |
} |