diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-10-24 03:01:10 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-10-27 23:49:15 +0300 |
commit | 660eea8cf4c21cbaf0b11e4800aa38fb83afb895 (patch) | |
tree | b22ef58b84cb60bc7be46ccfa9aad47f3afa0da8 /source/blender/blenlib | |
parent | 4de8e12adacde0d2d371eca97daf39024dd8aa53 (diff) |
BLI_rand : add BLI_halton_3D
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_rand.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h index 0ef971bf41f..69b23b2473f 100644 --- a/source/blender/blenlib/BLI_rand.h +++ b/source/blender/blenlib/BLI_rand.h @@ -106,6 +106,7 @@ int BLI_rng_thread_rand(RNG_THREAD_ARRAY *rngarr, int thread) ATTR_WARN_UNUSED /** Return the _n_th number of the given low-discrepancy sequence. */ void BLI_halton_1D(unsigned int prime, double offset, int n, double *r); void BLI_halton_2D(unsigned int prime[2], double offset[2], int n, double *r); +void BLI_halton_3D(unsigned int prime[3], double offset[3], int n, double *r); void BLI_hammersley_1D(unsigned int n, double *r); /** Return the whole low-discrepancy sequence up to _n_. */ diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index a501d38abb7..9ab39dda9d0 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -402,6 +402,17 @@ void BLI_halton_2D(unsigned int prime[2], double offset[2], int n, double *r) } } +void BLI_halton_3D(unsigned int prime[3], double offset[3], int n, double *r) +{ + const double invprimes[3] = {1.0 / (double)prime[0], 1.0 / (double)prime[1], 1.0 / (double)prime[2]}; + + for (int s = 0; s < n; s++) { + for (int i = 0; i < 3; i++) { + r[i] = halton_ex(invprimes[i], &offset[i]); + } + } +} + void BLI_halton_2D_sequence(unsigned int prime[2], double offset[2], int n, double *r) { const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]}; |