CoolFace
Apppublic

souging/TRELLIS_TextTo3D

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
random_utils.py30 linesDownload Raw Back to utils
1import numpy as np2 3PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53]4 5def radical_inverse(base, n):6    val = 07    inv_base = 1.0 / base8    inv_base_n = inv_base9    while n > 0:10        digit = n % base11        val += digit * inv_base_n12        n //= base13        inv_base_n *= inv_base14    return val15 16def halton_sequence(dim, n):17    return [radical_inverse(PRIMES[dim], n) for dim in range(dim)]18 19def hammersley_sequence(dim, n, num_samples):20    return [n / num_samples] + halton_sequence(dim - 1, n)21 22def sphere_hammersley_sequence(n, num_samples, offset=(0, 0), remap=False):23    u, v = hammersley_sequence(2, n, num_samples)24    u += offset[0] / num_samples25    v += offset[1]26    if remap:27        u = 2 * u if u < 0.25 else 2 / 3 * u + 1 / 328    theta = np.arccos(1 - 2 * u) - np.pi / 229    phi = v * 2 * np.pi30    return [phi, theta]