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)
def single_radius(q, initial_radius, range1, maximum1, Circles, cols1, depths1,
                  w1, width, height, depth):

    valid = True
    yaxis = math.floor(q / cols1 / depths1)
    xaxis = math.floor((q - yaxis * cols1 * depths1) / depths1)
    zaxis = q - xaxis * depths1 - yaxis * cols1 * depths1

    w_use = w1
    x = np.random.randint(math.floor(xaxis * w_use),
                          math.floor((xaxis + 1) * w_use))
    y = np.random.randint(math.floor(yaxis * w_use),
                          math.floor((yaxis + 1) * w_use))
    z = np.random.randint(math.floor(zaxis * w_use),
                          math.floor((zaxis + 1) * w_use))

    #if the randomly selected point in the void grid is too close to borders, it will be deleted.
    m = initial_radius
    min_boundary = [x, y, z, (width - x), (height - y), (depth - z)]
    min_b = np.amin(min_boundary)
    if min_b < m:
        return 0

#in the reseaching sphere area with 'mindis' radius
    min_around = []
    for j in range(len(Circles)):
        if ((x - range1) < Circles[j].x <
            (x + range1)) and ((y - range1) < Circles[j].y <
                               (y + range1)) and ((z - range1) < Circles[j].z <
                                                  (z + range1)):
            k = _distance3d.dist(x, y, z, Circles[j].x, Circles[j].y,
                                 Circles[j].z) - Circles[j].r
            if (k < m):
                return 0

    #generate particles
    Circles.append(_Sphere.Sphere(x, y, z, m, width, height, depth))
    return m