Exemplo n.º 1
0
	def grid_coordinates((x, y, z)):
		return int_point_3d((x*inv_cell_size, y*inv_cell_size, z*inv_cell_size))
Exemplo n.º 2
0
		return False

	r_min, r_max = r_grid.min_max()
	
	#Create the grid
	cell_size = r_max/sqrt(2)
	inv_cell_size = 1 / cell_size	
	r_max_sqr = r_max*r_max
	
	grid = ListGrid3D((
		int(ceil(width/cell_size)),
		int(ceil(height/cell_size)),
		int(ceil(depth/cell_size))))
		
	process_list = RandomQueue()
	sample_points = []	
	
	#generate the first point
	put_point((rand(width), rand(height), rand(depth)))
	
	#generate other points from points in queue.
	while not process_list.empty():
		p = process_list.pop()
		r = r_grid[int_point_3d(p)]

		for i in xrange(k):			
			q = generate_random_around(p, r)
			if in_rectangle(q) and not in_neighbourhood(q, r):
					put_point(q)
	
	return sample_points
Exemplo n.º 3
0
	def grid_coordinates(p):
		x, y, z = p
		return int_point_3d((x*inv_cell_size, y*inv_cell_size, z*inv_cell_size))
Exemplo n.º 4
0
def sample_poisson_3d(width, height, depth, r_grid, k):	
	#Convert rectangle (the one to be sampled) coordinates to 
	# coordinates in the grid.
	def grid_coordinates(p):
		x, y, z = p
		return int_point_3d((x*inv_cell_size, y*inv_cell_size, z*inv_cell_size))
	
	# Puts a sample point in all the algorithm's relevant containers.
	def put_point(p):
		process_list.push(p)
		sample_points.append(p)
		grid[grid_coordinates(p)].append(p)

	# Generates a point randomly selected around
	# the given point, between r and 2*r units away.
	def generate_random_around(p, r):
		x, y, z = p
		rr = uniform(r, 2*r)		
		rs = uniform(0, 2*pi)
		rt = uniform(0, 2*pi)		
		
		return rr*sin(rs)*cos(rt) + x, rr*sin(rs)*sin(rt) + y, rr*cos(rs) + z
		
	# Is the given point in the rectangle to be sampled?
	def in_rectangle(p):
		x, y, z = p
		return 0 <= x < width and 0 <= y < height and 0 <= z < depth
	
	def in_neighbourhood(p, r):
		gp = grid_coordinates(p)
		r_sqr = r*r
		
		for cell in grid.square_iter(gp, 2):
			for q in cell:
				if sqr_dist_3d(q, p) <= r_sqr:
					return True
		return False

	r_min, r_max = r_grid.min_max()
	
	#Create the grid
	cell_size = r_max/sqrt(2)
	inv_cell_size = 1 / cell_size	
	r_max_sqr = r_max*r_max
	
	grid = ListGrid3D((
		int(ceil(width/cell_size)),
		int(ceil(height/cell_size)),
		int(ceil(depth/cell_size))))
		
	process_list = RandomQueue()
	sample_points = []	
	
	#generate the first point
	put_point((rand(width), rand(height), rand(depth)))
	
	#generate other points from points in queue.
	while not process_list.empty():
		p = process_list.pop()
		r = r_grid[int_point_3d(p)]

		for i in range(k):			
			q = generate_random_around(p, r)
			if in_rectangle(q) and not in_neighbourhood(q, r):
					put_point(q)
	
	return sample_points
Exemplo n.º 5
0
 def grid_coordinates((x, y, z)):
     return int_point_3d(
         (x * inv_cell_size, y * inv_cell_size, z * inv_cell_size))
Exemplo n.º 6
0
        return False

    r_min, r_max = r_grid.min_max()

    #Create the grid
    cell_size = r_max / sqrt(2)
    inv_cell_size = 1 / cell_size
    r_max_sqr = r_max * r_max

    grid = ListGrid3D(
        (int(ceil(width / cell_size)), int(ceil(height / cell_size)),
         int(ceil(depth / cell_size))))

    process_list = RandomQueue()
    sample_points = []

    #generate the first point
    put_point((rand(width), rand(height), rand(depth)))

    #generate other points from points in queue.
    while not process_list.empty():
        p = process_list.pop()
        r = r_grid[int_point_3d(p)]

        for i in xrange(k):
            q = generate_random_around(p, r)
            if in_rectangle(q) and not in_neighbourhood(q, r):
                put_point(q)

    return sample_points