| 1 | greg | 1.1 | #ifndef lint | 
| 2 | greg | 2.7 | static const char       RCSid[] = "$Id: multisamp.c,v 2.6 2024/04/17 15:07:29 greg Exp $"; | 
| 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 | schorsch | 2.5 |  | 
| 12 |  |  | #include <stdlib.h> | 
| 13 | greg | 2.3 |  | 
| 14 |  |  | #include "random.h" | 
| 15 |  |  |  | 
| 16 | greg | 2.6 |  | 
| 17 |  |  | /* Convert 1-dimensional sample to N dimensions */ | 
| 18 | greg | 2.3 | void | 
| 19 | greg | 2.6 | multisamp(double t[], int n, double r) | 
| 20 | greg | 1.1 | { | 
| 21 |  |  | int     j; | 
| 22 | greg | 2.6 | int     i, k; | 
| 23 | greg | 1.1 | int     ti[8]; | 
| 24 |  |  | double  s; | 
| 25 |  |  |  | 
| 26 | greg | 2.7 | while (n > 8) | 
| 27 |  |  | t[--n] = frandom(); | 
| 28 | greg | 1.1 | i = n; | 
| 29 |  |  | while (i-- > 0) | 
| 30 |  |  | ti[i] = 0; | 
| 31 |  |  | j = 8; | 
| 32 |  |  | while (j--) { | 
| 33 |  |  | k = s = r*(1<<n); | 
| 34 |  |  | r = s - k; | 
| 35 |  |  | i = n; | 
| 36 |  |  | while (i-- > 0) | 
| 37 |  |  | ti[i] += ti[i] + ((k>>i) & 1); | 
| 38 |  |  | } | 
| 39 |  |  | i = n; | 
| 40 |  |  | while (i-- > 0) | 
| 41 | greg | 2.6 | t[i] = (1./256.) * (ti[i] + frandom()); | 
| 42 | greg | 1.1 | } |