1 |
gregl |
2.2 |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
greg |
1.1 |
|
3 |
|
|
#ifndef lint |
4 |
gregl |
2.2 |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
greg |
1.1 |
#endif |
6 |
|
|
|
7 |
gregl |
2.2 |
#include "random.h" |
8 |
|
|
|
9 |
greg |
1.1 |
/* |
10 |
|
|
* Binary space partitioning curve for multidimensional sampling. |
11 |
|
|
* |
12 |
|
|
* Written by Christophe Schlick |
13 |
|
|
*/ |
14 |
|
|
|
15 |
|
|
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 |
} |