示例#1
0
    def coords(self, size=CHUNK, numWorkers=1):
        noise = fns.Noise(seed=None, numWorkers=numWorkers)
        coords = fns.empty_coords(size)
        coords[0,:] = np.arange(size)
        coords[1,:] = np.arange(-size//2, size//2)
        coords[2,:] = np.linspace(-1.0, 1.0, size)
        noise.genFromCoords(coords)

        # Re-use coords to make sure the array isn't accidentally free'd 
        # in FastNoiseSIMD
        noise2 = fns.Noise(seed=None, numWorkers=numWorkers)
        noise2.genFromCoords(coords)
        return
示例#2
0
 def test_noise_type(self, size=CHUNK, numWorkers=1):
     noise = fns.Noise(seed=None, numWorkers=numWorkers)
     # Iterate through NoiseType
     for newNoise in fns.NoiseType:
         noise.noiseType = newNoise
         assert(noise.noiseType == newNoise)
         result = noise.genAsGrid(shape=size)
示例#3
0
def generate_terrain(seed, points):
    coords = fns.empty_coords(points.shape[0])
    coords[:] = points.T

    # Cellular, PerlinFractal, ValueFractal, Cubic, Simplex, WhiteNoise, CubicFractal, SimplexFractal, Perlin, Value

    noise = fns.Noise(seed=seed, numWorkers=1)
    noise.frequency = 0.02
    noise.noiseType = fns.NoiseType.SimplexFractal
    noise.fractal.octaves = 4
    noise.fractal.lacunarity = 2.1
    noise.fractal.gain = 0.45
    noise.perturb.perturbType = fns.PerturbType.NoPerturb
    noise_values = noise.genFromCoords(coords)

    # Create an empty array of air
    res = np.full(points.shape[:1], 0, dtype=np.uint32)

    # Assign dirt
    res[points[:, 2] + noise_values * 40 < 5.0] = 1

    # Assign water
    res[points[:, 2] < 0.0] = 2

    # # Assign clouds
    # res[(points[:, 2] - 110) ** 2 * 1e-1 + noise_values * 100 < -60.0] = 3

    return res
示例#4
0
 def __init__(self, height, width, seed=None):
     self.distortion = Distortion()
     self.height = height
     self.width = width
     if not seed:
         seed = time.time_ns()
     self.perlin_noise = fns.Noise(seed)
     self.normalizing_lambda = lambda x: x * 2 * np.pi
示例#5
0
    def grid_3d(self, size=CHUNK3, numWorkers=1):
        noise = fns.Noise(seed=None, numWorkers=numWorkers)
        noise.frequency = 0.15
        assert(noise.frequency == 0.15)
        noise.axesScales = [0.9, 0.85, 0.9]
        assert(noise.axesScales == [0.9, 0.85, 0.9])

        result = noise.genAsGrid(shape=[size,size,size])
        assert(result.shape == (size,size,size))
示例#6
0
 def fractal(self, size=CHUNK, numWorkers=1):
     # Iterate through FractalType
     noise = fns.Noise(seed=None, numWorkers=numWorkers)
     noise.fractal.octaves = 2
     assert(noise.fractal.octaves == 2)
     noise.fractal.lacunarity = 1.9
     assert(noise.fractal.lacunarity == 1.9)
     noise.fractal.gain = 0.7
     assert(noise.fractal.gain == 0.7)
     for newFractal in fns.FractalType:
         noise.fractal.fractalType = newFractal
         assert(noise.fractal.fractalType == newFractal)
         noise.genAsGrid(shape=size)
示例#7
0
def get_noise_block(shape, rx=0, rz=0):
    """
    Fill a matrix with a nice perlin noise.

    :param shape:
    :return:
    """
    perlin = fns.Noise(seed=42, numWorkers=2)
    perlin.frequency = 0.02
    perlin.noiseType = fns.NoiseType.Perlin
    perlin.fractal.octaves = 4
    perlin.fractal.lacunarity = 2.1
    perlin.fractal.gain = 0.15
    perlin.perturb.perturbType = fns.PerturbType.NoPerturb
    return perlin.genAsGrid(shape, start=[rx * 512, 0, rz * 512])
示例#8
0
 def test_perturb(self, size=CHUNK, numWorkers=1):
     # Iterate through PeturbType
     noise = fns.Noise(seed=None, numWorkers=numWorkers)
     noise.perturb.amp = 1.1
     assert(noise.perturb.amp == 1.1)
     noise.perturb.frequency = 0.44
     assert(noise.perturb.frequency == 0.44)
     noise.perturb.octaves = 2
     assert(noise.perturb.octaves == 2)
     noise.perturb.lacunarity = 2.2
     assert(noise.perturb.lacunarity == 2.2)
     noise.perturb.gain = 0.6
     assert(noise.perturb.gain == 0.6)
     for newPeturb in fns.PerturbType:
         noise.perturb.perturbType = newPeturb
         assert(noise.perturb.perturbType == newPeturb)
         noise.genAsGrid(shape=size)
示例#9
0
def get_noise_block_trees(shape, seed=27):
    """
    Fill a matrix with a nice perlin noise.

    :param shape:
    :return:
    """
    perlin = fns.Noise(seed=seed, numWorkers=2)
    perlin.frequency = 0.1
    perlin.noiseType = fns.NoiseType.Perlin
    perlin.fractal.octaves = 4
    perlin.fractal.lacunarity = 2.1
    perlin.fractal.gain = 0.30
    perlin.perturb.perturbType = fns.PerturbType.NoPerturb
    block = perlin.genAsGrid(shape)
    block -= block.min()
    block /= block.std()
    return block
示例#10
0
 def setup_fns(self,
               noise_type=fns.NoiseType.Simplex,
               frequency=0.01,
               fractal_type=fns.FractalType.FBM,
               fractal_octaves=3,
               fractal_gain=0.5,
               fractal_lacunarity=2.0,
               perturb_type=fns.PerturbType.NoPerturb,
               perturb_octaves=3,
               perturb_frequency=0.5,
               perturb_amp=1.0,
               perturb_gain=0.5,
               perturb_lacunarity=2.0,
               perturb_normalise_length=1.0,
               cell_distance_func=fns.CellularDistanceFunction.Euclidean,
               cell_distance_indices=(0, 1),
               cell_jitter=0.45,
               cell_lookup_frequency=0.2,
               cell_noise_lookup_type=fns.NoiseType.Simplex,
               cell_return_type=fns.CellularReturnType.Distance,
               seed=None):
     self.fns = fns.Noise(seed or self.seed)
     self.fns.noiseType = noise_type
     self.fns.frequency = frequency
     self.fns.fractal.fractalType = fractal_type
     self.fns.fractal.octaves = fractal_octaves
     self.fns.fractal.gain = fractal_gain
     self.fns.fractal.lacunarity = fractal_lacunarity
     self.fns.perturb.perturbType = perturb_type
     self.fns.perturb.octaves = perturb_octaves
     self.fns.perturb.frequency = perturb_frequency
     self.fns.perturb.amp = perturb_amp
     self.fns.perturb.gain = perturb_gain
     self.fns.perturb.lacunarity = perturb_lacunarity
     self.fns.perturb.normaliseLength = perturb_normalise_length
     self.fns.cell.distanceFunc = cell_distance_func
     self.fns.cell.distanceIndices = cell_distance_indices
     self.fns.cell.jitter = cell_jitter
     self.fns.cell.lookupFrequency = cell_lookup_frequency
     self.fns.cell.noiseLookupType = cell_noise_lookup_type
     self.fns.cell.returnType = cell_return_type
示例#11
0
    def test_cell(self, size=CHUNK, numWorkers=1):
        noise = fns.Noise(seed=None, numWorkers=numWorkers)
        # Iterate through cellular options
        noise.cell.jitter = 0.7
        assert(noise.cell.jitter == 0.7)
        noise.cell.lookupFrequency = 0.3
        assert(noise.cell.lookupFrequency == 0.3)
        noise.cell.distanceIndices = [0, 2]
        assert(noise.cell.distanceIndices == [0, 2])

        noise.cell.returnType = fns.CellularReturnType.NoiseLookup
        for newNoise in fns.NoiseType:
            noise.cell.noiseLookupType = newNoise
            assert(noise.cell.noiseLookupType == newNoise)
            noise.genAsGrid(shape=size)
        for retType in fns.CellularReturnType:
            noise.cell.returnType = retType
            assert(noise.cell.returnType == retType)
            noise.genAsGrid(shape=size)
        for distFunc in fns.CellularDistanceFunction:
            noise.cell.distanceFunc = distFunc
            assert(noise.cell.distanceFunc == distFunc)
            noise.genAsGrid(shape=size)
示例#12
0
def augmentDepth(depth, obj_mask, mask_ori, shadowClK, shadowMK, blurK, blurS, depthNoise, method):

    sensor = True
    simplex = True

    if method == 0:
        pass
    elif method == 1:
        sensor = True
        simplex = False
    elif method == 2:
        sensor = False
        simplex = True

    # erode and blur mask to get more realistic appearance
    partmask = mask_ori
    partmask = partmask.astype(np.float32)
    #mask = partmask > (np.median(partmask) * 0.4)
    partmask = np.where(partmask > 0.0, 255.0, 0.0)

    cv2.imwrite('/home/sthalham/partmask.png', partmask)

    # apply shadow
    kernel = np.ones((shadowClK, shadowClK))
    partmask = cv2.morphologyEx(partmask, cv2.MORPH_OPEN, kernel)
    partmask = signal.medfilt2d(partmask, kernel_size=shadowMK)
    partmask = partmask.astype(np.uint8)
    mask = partmask > 20
    depth = np.where(mask, depth, 0.0)

    if sensor is True:
        depthFinal = cv2.resize(depth, (270, 360))
        res = (((depthFinal / 1000.0) * 1.41421356) ** 2)
        depthFinal = cv2.GaussianBlur(depthFinal, (blurK, blurK), blurS, blurS)
        # quantify to depth resolution and apply gaussian
        dNonVar = np.divide(depthFinal, res, out=np.zeros_like(depthFinal), where=res != 0)
        dNonVar = np.round(dNonVar)
        dNonVar = np.multiply(dNonVar, res)
        noise = np.multiply(dNonVar, depthNoise)
        depthFinal = np.random.normal(loc=dNonVar, scale=noise, size=dNonVar.shape)

        depth = cv2.resize(depthFinal, (resX, resY))

    if simplex is True:
        # fast perlin noise
        seed = np.random.randint(2 ** 31)
        N_threads = 4
        perlin = fns.Noise(seed=seed, numWorkers=N_threads)
        drawFreq = random.uniform(0.05, 0.2)  # 0.05 - 0.2
        # drawFreq = 0.5
        perlin.frequency = drawFreq
        perlin.noiseType = fns.NoiseType.SimplexFractal
        perlin.fractal.fractalType = fns.FractalType.FBM
        drawOct = [4, 8]
        freqOct = np.bincount(drawOct)
        rndOct = np.random.choice(np.arange(len(freqOct)), 1, p=freqOct / len(drawOct), replace=False)
        perlin.fractal.octaves = rndOct
        perlin.fractal.lacunarity = 2.1
        perlin.fractal.gain = 0.45
        perlin.perturb.perturbType = fns.PerturbType.NoPerturb

        # linemod
        if not sensor:
            # noise according to keep it unreal
            #noiseX = np.random.uniform(0.0001, 0.1, resX * resY) # 0.0001 - 0.1
            #noiseY = np.random.uniform(0.0001, 0.1, resX * resY) # 0.0001 - 0.1
            #noiseZ = np.random.uniform(0.01, 0.1, resX * resY) # 0.01 - 0.1
            #Wxy = np.random.randint(0, 10) # 0 - 10
            #Wz = np.random.uniform(0.0, 0.005) #0 - 0.005
            noiseX = np.random.uniform(0.001, 0.01, resX * resY)  # 0.0001 - 0.1
            noiseY = np.random.uniform(0.001, 0.01, resX * resY)  # 0.0001 - 0.1
            noiseZ = np.random.uniform(0.01, 0.1, resX * resY)  # 0.01 - 0.1
            Wxy = np.random.randint(2, 5)  # 0 - 10
            Wz = np.random.uniform(0.0001, 0.004)  # 0 - 0.005
        else:
            noiseX = np.random.uniform(0.001, 0.01, resX * resY) # 0.0001 - 0.1
            noiseY = np.random.uniform(0.001, 0.01, resX * resY) # 0.0001 - 0.1
            noiseZ = np.random.uniform(0.01, 0.1, resX * resY) # 0.01 - 0.1
            Wxy = np.random.randint(1, 5) # 1 - 5
            Wz = np.random.uniform(0.0001, 0.004) #0.0001 - 0.004
        # tless
        #noiseX = np.random.uniform(0.001, 0.1, resX * resY)  # 0.0001 - 0.1
        #noiseY = np.random.uniform(0.001, 0.1, resX * resY)  # 0.0001 - 0.1
        #noiseZ = np.random.uniform(0.01, 0.1, resX * resY)  # 0.01 - 0.1
        #Wxy = np.random.randint(2, 8)  # 0 - 10
        #Wz = np.random.uniform(0.0, 0.005)


        X, Y = np.meshgrid(np.arange(resX), np.arange(resY))
        coords0 = fns.empty_coords(resX * resY)
        coords1 = fns.empty_coords(resX * resY)
        coords2 = fns.empty_coords(resX * resY)

        coords0[0, :] = noiseX.ravel()
        coords0[1, :] = Y.ravel()
        coords0[2, :] = X.ravel()
        VecF0 = perlin.genFromCoords(coords0)
        VecF0 = VecF0.reshape((resY, resX))

        coords1[0, :] = noiseY.ravel()
        coords1[1, :] = Y.ravel()
        coords1[2, :] = X.ravel()
        VecF1 = perlin.genFromCoords(coords1)
        VecF1 = VecF1.reshape((resY, resX))

        coords2[0, :] = noiseZ.ravel()
        coords2[1, :] = Y.ravel()
        coords2[2, :] = X.ravel()
        VecF2 = perlin.genFromCoords(coords2)
        VecF2 = VecF2.reshape((resY, resX))

        x = np.arange(resX, dtype=np.uint16)
        x = x[np.newaxis, :].repeat(resY, axis=0)
        y = np.arange(resY, dtype=np.uint16)
        y = y[:, np.newaxis].repeat(resX, axis=1)

        # vanilla
        #fx = x + Wxy * VecF0
        #fy = y + Wxy * VecF1
        #fx = np.where(fx < 0, 0, fx)
        #fx = np.where(fx >= resX, resX - 1, fx)
        #fy = np.where(fy < 0, 0, fy)
        #fy = np.where(fy >= resY, resY - 1, fy)
        #fx = fx.astype(dtype=np.uint16)
        #fy = fy.astype(dtype=np.uint16)
        #Dis = depth[fy, fx] + Wz * VecF2
        #depth = np.where(Dis > 0, Dis, 0.0)

        #print(x.shape)
        #print(np.amax(depth))
        #print(np.amin(depth))
        Wxy_scaled = depth * 0.001 * Wxy
        Wz_scaled = depth * 0.001 * Wz
        # scale with depth
        fx = x + Wxy_scaled * VecF0
        fy = y + Wxy_scaled * VecF1
        fx = np.where(fx < 0, 0, fx)
        fx = np.where(fx >= resX, resX - 1, fx)
        fy = np.where(fy < 0, 0, fy)
        fy = np.where(fy >= resY, resY - 1, fy)
        fx = fx.astype(dtype=np.uint16)
        fy = fy.astype(dtype=np.uint16)
        Dis = depth[fy, fx] + Wz_scaled * VecF2
        depth = np.where(Dis > 0, Dis, 0.0)

    return depth
示例#13
0
import pyfastnoisesimd as fns
import numpy as np
import time
from hihi import color_print as cp

n = fns.Noise()
n.numWorkers = 4
n_cycles = 12

print(cp.red('Is Numpy resizing the arrays after we exit scope?'))
coords = [None] * n_cycles
for I in range(n_cycles):
    len_coords = 4096 + I + 1
    coords[I] = fns.empty_coords(len_coords)
    print(cp.yellow("\n    Iteration #{I} with len: {len_coords}"))
    # print(f"\n\n    Iteration #{I} with len: {len_coords}")
    coords[I][0, :] = np.pi
    coords[I][1, :] = 0.5
    coords[I][2, :] = np.exp(1)
    result = n.genFromCoords(coords[I])

    # time.sleep(0.2)

print(cp.magenta('== Done =='))
# print('== Done ==')
# Generate lambda (meridian) and phi (parallel) angles in radians, from the
# projection formula
meridian = X * inverseRadius
parallel = np.arcsin((0.5 * inverseRadius) * Y)

# Show the sampling (essentially Tissot's indicatrices):
'''
plt.figure()
plt.plot( meridian, parallel, 'k.' )
plt.xlabel( 'meridian (rad)' )
plt.ylabel( 'Parallel (rad)' )
plt.title( 'meridian and parallel sampling space')
'''

# Make your Noise object
bumps = fns.Noise(seed=42)
bumps.noiseType = fns.NoiseType.Perlin
bumps.frequency = freq
print('FastNoiseSIMD maximum supported SIMD instruction level: {}'.format(
    fns.extension.SIMD_LEVEL))

# Generate an empty-array of 3D cartesian coordinates. You can use NumPy
# arrays from other sources but see the warnings in `Noise.genFromCoords()`
coords = fns.empty_aligned((3, meridian.size))
print('== coords.shape: ', coords.shape)
print('== parallel.shape: ', parallel.shape)

# Fill coords with Cartesian coordinates in 3D
# (Note that normally zenith starts at 0.0 rad, whereas we want the equator to be
# 0.0 rad, so we swap cos/sin for the `parallel` axis)
coords[0, :meridian.size] = radius * np.sin(parallel)  # Z
    print("Generated {} coords in {:.2e} s".format(maskLen, t1 - t0))
    print("Generated noise for {} coords with {} workers in {:.3e} s".format(
        maskLen, noise.numWorkers, t2 - t1))
    print("    {:.1f} ns/pixel".format(1e9 * (t2 - t1) / maskLen))
    return pmap


# Let's set the view-parallel so we can see the top of the sphere
p0 = np.pi - 0.3
# the view-meridian isn't so important, but if you wanted to rotate the
# view, this is how you do it.
l0 = 0.0

# Now create a Noise object and populate it with intelligent values. How to
# come up with 'intelligent' values is left as an exercise for the reader.
gasy = fns.Noise(numWorkers=N_thread)
gasy.frequency = 1.8
gasy.axesScales = (1.0, 0.06, 0.06)

gasy.fractal.octaves = 5
gasy.fractal.lacunarity = 1.0
gasy.fractal.gain = 0.33

gasy.perturb.perturbType = fns.PerturbType.GradientFractal
gasy.perturb.amp = 0.5
gasy.perturb.frequency = 1.2
gasy.perturb.octaves = 5
gasy.perturb.lacunarity = 2.5
gasy.perturb.gain = 0.5

gasy_map = orthoProject(gasy, tile2=1024, p0=p0, l0=l0)
示例#16
0
 def __init__(self, **kwargs):
     self.noise = OpenSimplex(**kwargs)
     self.fast_noise = fns.Noise()
示例#17
0
import numpy as np
import numpy.testing as npt
import pyfastnoisesimd as fns

noise = fns.Noise()
noise.numWorkers = 4
grid_origin = noise.genAsGrid(shape=[64, 64, 64], start=[0, 0, 0])
grid_offset = noise.genAsGrid(shape=[64, 64, 64], start=[50, 50, 50])
try:
    npt.assert_array_almost_equal(grid_origin, grid_offset)
    raise ValueError(
        'Arrays are equal, that means `start` parameter is not working')
except AssertionError:
    print('Issue 17 is ok')
示例#18
0
import numpy as np
import pyfastnoisesimd as fns

# Num workers does not seem to matter.
# It only seems to be an issue if the middle dimension is not divisible
# by the SIMD length?
n = fns.Noise(numWorkers=1)
shape = [27, 127, 1]
for I in range(10):
    # print(I)
    res = n.genAsGrid(shape)
print('Finished successfully')
示例#19
0
import numpy as np
import pyfastnoisesimd as fns
import time
import numpy.testing as npt

print(
    '**Note that if you have Hyperthreading the optimum thread count is the number of physical cores.**'
)
N_thread = fns.num_virtual_cores()

shape = [N_thread * 2, 1024, 1024]
print('Array shape: {}'.format(shape))

# Plot cellular noise with a gradient perturbation
cellular = fns.Noise(numWorkers=1)
print('SIMD level supported: {}'.format(fns.extension.SIMD_LEVEL))
# The Noise class uses properties to map to the FastNoiseSIMD library Set<...> functions
cellular.seed = 42
cellular.noiseType = fns.NoiseType.Cellular
cellular.frequency = 0.005
cellular.axesScales = [shape[-1] / shape[0], 1.0, 1.0]

cellular.cell.returnType = fns.CellularReturnType.Distance
cellular.cell.distanceFunc = fns.CellularDistanceFunction.Euclidean
cellular.cell.noiseLookupType = fns.NoiseType.Simplex
cellular.cell.lookupFrequency = 0.2
cellular.cell.jitter = 0.5
cellular.cell.distanceIndices = (0, 1)

cellular.fractal.octaves = 4
示例#20
0
def augmentDepth(depth, obj_mask, mask_ori):

    resY, resX = depth.shape
    drawKern = [3, 5, 7]
    freqKern = np.bincount(drawKern)
    kShadow = np.random.choice(np.arange(len(freqKern)),
                               1,
                               p=freqKern / len(drawKern),
                               replace=False)
    kShadow.astype(int)
    shadowClK = kShadow[0]
    kMed = np.random.choice(np.arange(len(freqKern)),
                            1,
                            p=freqKern / len(drawKern),
                            replace=False)
    kMed.astype(int)
    shadowMK = kMed[0]
    kBlur = np.random.choice(np.arange(len(freqKern)),
                             1,
                             p=freqKern / len(drawKern),
                             replace=False)
    kBlur.astype(int)
    blurK = kBlur[0]
    blurS = random.uniform(0.0, 1.5)

    # mask rendering failed for first rendered dataset
    # erode and blur mask to get more realistic appearance
    #partmask = mask_ori
    #partmask = partmask.astype(np.float32)
    #mask = partmask > (np.median(partmask) * 0.4)
    #partmask = np.where(mask_ori > 1, 255.0, 0.0)
    partmask = np.where(mask_ori > 0, 255.0, 0.0)

    #aug_dep = partmask.astype(np.uint8)
    #cv2.imwrite('/home/stefan/mask.png', aug_dep)

    # apply shadow
    kernel = np.ones((shadowClK, shadowClK))
    partmask = cv2.morphologyEx(partmask, cv2.MORPH_OPEN, kernel)
    partmask = signal.medfilt2d(partmask, kernel_size=shadowMK)
    partmask = partmask.astype(np.uint8)
    mask = partmask > 0
    depth = np.where(mask, depth, 0.0)

    depthFinal = cv2.resize(depth, None, fx=1 / 2, fy=1 / 2)
    res = (((depthFinal / 1000.0) * 1.41421356)**2)
    depthFinal = cv2.GaussianBlur(depthFinal, (blurK, blurK), blurS, blurS)
    # quantify to depth resolution and apply gaussian
    dNonVar = np.divide(depthFinal,
                        res,
                        out=np.zeros_like(depthFinal),
                        where=res != 0)
    dNonVar = np.round(dNonVar)
    dNonVar = np.multiply(dNonVar, res)
    noise = np.multiply(dNonVar,
                        random.uniform(0.002, 0.004))  # empirically determined
    depthFinal = np.random.normal(loc=dNonVar, scale=noise, size=dNonVar.shape)
    depth = cv2.resize(depthFinal, (resX, resY))

    # fast perlin noise
    seed = np.random.randint(2**31)
    N_threads = 4
    perlin = fns.Noise(seed=seed, numWorkers=N_threads)
    drawFreq = random.uniform(0.05, 0.2)  # 0.05 - 0.2
    #drawFreq = 0.5
    perlin.frequency = drawFreq
    perlin.noiseType = fns.NoiseType.SimplexFractal
    perlin.fractal.fractalType = fns.FractalType.FBM
    drawOct = [4, 8]
    freqOct = np.bincount(drawOct)
    rndOct = np.random.choice(np.arange(len(freqOct)),
                              1,
                              p=freqOct / len(drawOct),
                              replace=False)
    #rndOct = 8
    perlin.fractal.octaves = rndOct
    perlin.fractal.lacunarity = 2.1
    perlin.fractal.gain = 0.45
    perlin.perturb.perturbType = fns.PerturbType.NoPerturb

    noiseX = np.random.uniform(0.001, 0.01, resX * resY)  # 0.001, 0.01
    noiseY = np.random.uniform(0.001, 0.01, resX * resY)  # 0.0001 - 0.1
    noiseZ = np.random.uniform(0.01, 0.1, resX * resY)  # 0.01 - 0.1
    Wxy = np.random.randint(1, 5)  # 1 - 5
    Wz = np.random.uniform(0.0001, 0.004)  #0.0001 - 0.004

    X, Y = np.meshgrid(np.arange(resX), np.arange(resY))
    coords0 = fns.empty_coords(resX * resY)
    coords1 = fns.empty_coords(resX * resY)
    coords2 = fns.empty_coords(resX * resY)

    coords0[0, :] = noiseX.ravel()
    coords0[1, :] = Y.ravel()
    coords0[2, :] = X.ravel()
    VecF0 = perlin.genFromCoords(coords0)
    VecF0 = VecF0.reshape((resY, resX))

    coords1[0, :] = noiseY.ravel()
    coords1[1, :] = Y.ravel()
    coords1[2, :] = X.ravel()
    VecF1 = perlin.genFromCoords(coords1)
    VecF1 = VecF1.reshape((resY, resX))

    coords2[0, :] = noiseZ.ravel()
    coords2[1, :] = Y.ravel()
    coords2[2, :] = X.ravel()
    VecF2 = perlin.genFromCoords(coords2)
    VecF2 = VecF2.reshape((resY, resX))

    # vanilla
    # fx = x + Wxy * VecF0
    # fy = y + Wxy * VecF1
    # fx = np.where(fx < 0, 0, fx)
    # fx = np.where(fx >= resX, resX - 1, fx)
    # fy = np.where(fy < 0, 0, fy)
    # fy = np.where(fy >= resY, resY - 1, fy)
    # fx = fx.astype(dtype=np.uint16)
    # fy = fy.astype(dtype=np.uint16)
    # Dis = depth[fy, fx] + Wz * VecF2
    # depth = np.where(Dis > 0, Dis, 0.0)

    x = np.arange(resX, dtype=np.uint16)
    x = x[np.newaxis, :].repeat(resY, axis=0)
    y = np.arange(resY, dtype=np.uint16)
    y = y[:, np.newaxis].repeat(resX, axis=1)

    Wxy_scaled = depth * 0.001 * Wxy
    Wz_scaled = depth * 0.001 * Wz
    # scale with depth
    fx = x + Wxy_scaled * VecF0
    fy = y + Wxy_scaled * VecF1
    fx = np.where(fx < 0, 0, fx)
    fx = np.where(fx >= resX, resX - 1, fx)
    fy = np.where(fy < 0, 0, fy)
    fy = np.where(fy >= resY, resY - 1, fy)
    fx = fx.astype(dtype=np.uint16)
    fy = fy.astype(dtype=np.uint16)
    Dis = depth[fy, fx] + Wz_scaled * VecF2
    depth = np.where(Dis > 0, Dis, 0.0)

    return depth
示例#21
0
 def grid_2d(self, size=CHUNK2, numWorkers=1):
     noise = fns.Noise(seed=None, numWorkers=numWorkers)
     # Test 2D
     result = noise.genAsGrid(shape=[size,size])
     assert(result.shape == (size,size))
示例#22
0
 def grid_1d(self, size=CHUNK, numWorkers=1):
     # Test 1D
     noise = fns.Noise(seed=None, numWorkers=numWorkers)
     result = noise.genAsGrid(shape=size)
     assert(result.shape == (size,))