| 1 | 
#ifndef lint | 
| 2 | 
static const char       RCSid[] = "$Id: multisamp.c,v 2.6 2024/04/17 15:07:29 greg Exp $"; | 
| 3 | 
#endif | 
| 4 | 
/* | 
| 5 | 
 * Binary space partitioning curve for multidimensional sampling. | 
| 6 | 
 * | 
| 7 | 
 *      Written by Christophe Schlick | 
| 8 | 
 */ | 
| 9 | 
 | 
| 10 | 
#include "copyright.h" | 
| 11 | 
 | 
| 12 | 
#include <stdlib.h> | 
| 13 | 
 | 
| 14 | 
#include "random.h" | 
| 15 | 
 | 
| 16 | 
 | 
| 17 | 
/* Convert 1-dimensional sample to N dimensions */ | 
| 18 | 
void | 
| 19 | 
multisamp(double t[], int n, double r) | 
| 20 | 
{ | 
| 21 | 
        int     j; | 
| 22 | 
        int     i, k; | 
| 23 | 
        int     ti[8]; | 
| 24 | 
        double  s; | 
| 25 | 
 | 
| 26 | 
        while (n > 8) | 
| 27 | 
                t[--n] = frandom(); | 
| 28 | 
        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 | 
                t[i] = (1./256.) * (ti[i] + frandom()); | 
| 42 | 
} |