Ejemplo n.º 1
0
def remove_cells(roundRadius, Circles, w1, grid1, cols1, rows1, depths1):
    for i in range(len(Circles)):
        col_sub = math.floor(Circles[i].x / w1)
        row_sub = math.floor(Circles[i].y / w1)
        depth_sub = math.floor(Circles[i].z / w1)
        if Circles[i].r > w1:
            range_circles = math.ceil((Circles[i].r + 2) / w1)
            nums = list(range(-range_circles, range_circles + 1))
            num1s = list(range(-range_circles, range_circles + 1))
            num2s = list(range(-range_circles, range_circles + 1))
            for num in nums:
                for num1 in num1s:
                    for num2 in num2s:
                        if 0 <= col_sub + num1 < cols1 and 0 <= row_sub + num < rows1 and 0 <= depth_sub + num2 < depths1:
                            index = (col_sub + num1) * depths1 + (
                                row_sub + num) * cols1 * depths1 + (depth_sub +
                                                                    num2)
                            y_grid = math.floor(index / cols1 / depths1)
                            x_grid = math.floor(
                                (index - y_grid * cols1 * depths1) / depths1)
                            z_grid = index - x_grid * depths1 - y_grid * cols1 * depths1
                            y1 = y_grid * w1
                            x1 = x_grid * w1
                            z1 = z_grid * w1
                            # distances of the eight corners of the cell and the particle center
                            d1 = _distance3d.dist(x1, y1, z1, Circles[i].x,
                                                  Circles[i].y, Circles[i].z)
                            d2 = _distance3d.dist((x1 + w1), y1, z1,
                                                  Circles[i].x, Circles[i].y,
                                                  Circles[i].z)
                            d3 = _distance3d.dist(x1, (y1 + w1), z1,
                                                  Circles[i].x, Circles[i].y,
                                                  Circles[i].z)
                            d4 = _distance3d.dist(x1, y1, (z1 + w1),
                                                  Circles[i].x, Circles[i].y,
                                                  Circles[i].z)
                            d5 = _distance3d.dist((x1 + w1), (y1 + w1), z1,
                                                  Circles[i].x, Circles[i].y,
                                                  Circles[i].z)
                            d6 = _distance3d.dist(x1, (y1 + w1), (z1 + w1),
                                                  Circles[i].x, Circles[i].y,
                                                  Circles[i].z)
                            d7 = _distance3d.dist((x1 + w1), y1, (z1 + w1),
                                                  Circles[i].x, Circles[i].y,
                                                  Circles[i].z)
                            d8 = _distance3d.dist((x1 + w1), (y1 + w1),
                                                  (z1 + w1), Circles[i].x,
                                                  Circles[i].y, Circles[i].z)
                            distance_around = [d1, d2, d3, d4, d5, d6, d7, d8]
                            distance_around.sort()
                            distance_max = distance_around[6]
                            # if the maximum distance is smaller than the particle radius plus the minimun value of the radius range for the next round
                            # mark this cell as minus one
                            if distance_max <= Circles[i].r + roundRadius:
                                grid1[index] = -1
        else:
            # if the particle radius is smaller than the cell size, this cell will be marked as occupied directly
            index = col_sub * depths1 + row_sub * cols1 * depths1 + depth_sub
            grid1[index] = -1
    print("filter the non-filled cells")
Ejemplo n.º 2
0
def generateCircles_p(mindis, maxi, Circles):
	growing = []

	for k in range(len(Circles)):
		if Circles[k].g is True:
			growing.append([Circles[k].x, Circles[k].y, Circles[k].z])

	while len(growing) > 0:
		for i in range(len(Circles)):
			if Circles[i].g is True:
				if Circles[i].r > maxi:
					Circles[i].g = None
					growing.remove([Circles[i].x, Circles[i].y, Circles[i].z])
					break
				elif Circles[i].edge() is None:
					growing.remove([Circles[i].x, Circles[i].y, Circles[i].z])
					break
				else:
					for j in range(len(Circles)):
						if (j != i) and ((Circles[i].x - mindis) < Circles[j].x < (Circles[i].x + mindis)) and ((Circles[i].y - mindis) < Circles[j].y < (Circles[i].y + mindis)) and ((Circles[i].z - mindis) < Circles[j].z < (Circles[i].z + mindis)):
							dis = _distance3d.dist(Circles[i].x, Circles[i].y, Circles[i].z, Circles[j].x, Circles[j].y, Circles[j].z)
							if dis < (Circles[i].r + Circles[j].r - 1):
								Circles[i].g = None
								growing.remove([Circles[i].x, Circles[i].y, Circles[i].z])
								break
			Circles[i].grow()
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