def point_poisson(): global occupation_poisson while len(active) > 0: check = np.random.randint(0, len(active)) found = None for n in range(k): s = _random_vector_function.random_vector_function( r, math.floor(r * 2)) sample = [] for i in range(0, len(s)): sample.append(s[i] + active[check][i]) gcol = math.floor(sample[0] / w) grow = math.floor(sample[1] / w) ggrid = gcol + grow * cols if gcol > -1 and grow > -1 and gcol < cols and grow < rows: ok = True #check distance between selected point and points in the around grids nums = [-1, 0, 1] num1s = [-1, 0, 1] for num in nums: for num1 in num1s: if 0 <= gcol + num1 < cols and 0 <= grow + num < rows: index = (gcol + num1) + (grow + num) * cols if grid[index] is None: pass else: d = _distance2d.dist(grid[index][0], grid[index][1], sample[0], sample[1]) if d < r: ok = None if ok is True: found = True grid[gcol + grow * cols] = sample active.append(sample) break if found is None: del active[check:(check + 1)] for i in range(len(grid)): if grid[i] is None: pass else: if (grid[i][0] < width - roundRadius[0]) and ( grid[i][0] > roundRadius[0]) and ( grid[i][1] < height - roundRadius[0]) and ( grid[i][1] > roundRadius[0]): Circles.append( _Circle.Circle(grid[i][0], grid[i][1], roundRadius[0], width, height)) occupation_poisson = occupation_poisson + 1 # enlarge the particles _generateParticle.generateCircles_p(ranges[0], (maximums[0] - 2), Circles) print('poisson disk sampling', occupation_poisson)
def point_poisson(): min_radius = roundRadius[0] global occupation_poisson while len(active) > 0: check = np.random.randint(0, len(active)) found = None for n in range(k): s = _random_vector_function.random_vector_function(r, math.floor(r * 1.5)) sample = [] for i in range(0, len(s)): sample.append(s[i] + active[check][i]) gcol = math.floor(sample[0] / w) grow = math.floor(sample[1] / w) gdepth = math.floor(sample[2] / w) ggrid = gdepth + gcol * depths + grow * cols * depths if gcol > -1 and grow > -1 and gdepth > -1 and gcol < cols and grow < rows and gdepth < depths: ok = True # check distances between selected point and points in the around grids nums = [-1, 0, 1] num1s = [-1, 0, 1] num2s = [-1, 0, 1] for num in nums: for num1 in num1s: for num2 in num2s: if 0 <= gcol + num1 < cols and 0 <= grow + num < rows and 0 <= gdepth + num2 < depths: index = (gcol + num1) * depths + (grow + num) * cols * depths + (gdepth + num2) if grid[index] is None: pass else: d = _distance3d.dist(grid[index][0], grid[index][1], grid[index][2], sample[0], sample[1], sample[2]) if d < r: ok = None if ok is True: found = True grid[gdepth + gcol * depths + grow * depths * cols] = sample active.append(sample) break if found is None: del active [check : (check + 1)] for i in range(len(grid)): if grid[i] is None: pass else: #delete points which are too close to the border if (grid[i][0] < width - min_radius) and (grid[i][0] > min_radius) and (grid[i][1] < height - min_radius) and (grid[i][1] > min_radius) and (grid[i][2] < depth - min_radius) and (grid[i][2] > min_radius): Circles.append(_Sphere.Sphere(grid[i][0], grid[i][1], grid[i][2], min_radius, width, height, depth)) occupation_poisson = occupation_poisson + 1 # enlarge the particles _generateParticle.generateCircles_p(ranges[0], (maximums[0] - 2), Circles) print('poisson disk sampling', occupation_poisson)