def setup(pyscreen): # Initialize the game engine pygame.init() pygame.display.set_caption("Raycasting") pyscreen.fill((0, 0, 0)) walls = [] for w in range(0, 5): x1 = randint(off, width - off) x2 = randint(off, width - off) y1 = randint(off, height - off) y2 = randint(off, height - off) walls.append(Boundary(pyscreen, x1, y1, x2, y2)) # Build outer edge walls walls.append(Boundary(pyscreen, off, off, off, height - off)) walls.append(Boundary(pyscreen, off, off, width - off, off)) walls.append( Boundary(pyscreen, width - off, off, width - off, height - off)) walls.append( Boundary(pyscreen, off, height - off, width - off, height - off)) particle = Particle(pyscreen, width, height, 0, fovHors) return (walls, particle)
class TestMovingObjectAndBoundary(unittest.TestCase): def setUp(self): points = [ (0 ,0), (100 ,0), (100 ,100), (0 ,100), ] self.boundary = Boundary(points) self.inside_point = (50, 10) self.outside_point = (110, 50) self.moving_object = RandomlyMovingObject(self.boundary) def test_random_point_on_boundary_is_on_boundary(self): rp = Point(self.boundary.random_point()) self.assertTrue(self.boundary.exterior.contains(rp)) def test_angle_to_centroid(self): self.assertEqual(self.boundary.angle_to_centroid(self.outside_point), math.pi) def test_random_distance(self): d = self.moving_object.random_distance() self.assertLessEqual(d, self.moving_object.max_dist_per_timestamp) self.assertGreaterEqual(d, self.moving_object.min_dist_per_timestamp) def test_position_history(self): self.moving_object.get_position_history()
def __init__(self, n_points=50, dimension=2, function_id=1, max_evaluations=10000, verbose=False, plot=0, fig_dir=None): print('\nACOR: Solving F%d in %dD with population size %d...\n' % (function_id, dimension, n_points)) from optproblems.cec2005 import CEC2005 from boundary import Boundary self.n_points = n_points self.dimension = dimension self.function_id = function_id - 1 self.function = CEC2005(dimension)[self.function_id].objective_function self.max_bounds = Boundary(dimension, self.function_id).max_bounds self.min_bounds = Boundary(dimension, self.function_id).min_bounds # Termination parameters self.FE = 0 self.iteration = 0 self.max_evaluations = max_evaluations * dimension self.termination_error = 1e-08 self.should_terminate = False self.optimal_position = CEC2005(dimension)[ self.function_id].get_optimal_solutions()[0].phenome self.optimal_fitness = self.function(self.optimal_position) self.best_position = np.zeros_like(self.optimal_position) self.best_fitness = np.inf self.verbose = verbose self.plot = plot self.fig_config = { 'fig_dir': fig_dir, 'angle': 240, 'xlim': [self.min_bounds[0], self.max_bounds[0]], 'ylim': [self.min_bounds[1], self.max_bounds[1]], 'optimal': self.optimal_position } self.algo = ACOR(self.obj, self.dimension, min_bounds=self.min_bounds, max_bounds=self.max_bounds, ants_num=2, archive_size=self.n_points, q=1e-4, xi=0.85) if self.plot > 0: error = self.best_fitness - self.optimal_fitness fig_name = ('F%d_%d.png' % (self.function_id + 1, self.iteration)) self.fig_config['fig_title'] = ( 'F%d, FE=%d, error=%.2e' % (self.function_id + 1, self.FE, error)) draw_quiver(self.algo, self.function, fig_name, **self.fig_config)
def setUp(self): self.border = Boundary() self.border.append(Vect(0, 0), 'F') self.border.append(Vect(1, 0), 'F') self.border.append(Vect(2, 0), 'T') self.border.append(Vect(2, 1), 'P') self.border.append(Vect(1, 1), 'F') self.border.append(Vect(0, 1), 'P')
def setUp(self): points = [ (0 ,0), (100 ,0), (100 ,100), (0 ,100), ] self.boundary = Boundary(points) self.inside_point = (50, 10) self.outside_point = (110, 50) self.moving_object = RandomlyMovingObject(self.boundary)
def main(): ### CONFIG screen_w = 500 screen_h = 500 border_on = True num_walls = 6 num_rays = 180 ### END CONFIG pg.init() screen = pg.display.set_mode((screen_w, screen_h)) running = True pg.event.set_allowed([pg.QUIT, pg.KEYDOWN, pg.KEYUP]) p = Particle() boundaries = [] rays = [] if border_on: boundaries.append(Boundary(screen, (0, 0), (screen_w, 0))) boundaries.append(Boundary(screen, (screen_w, 0), (screen_w, screen_h))) boundaries.append(Boundary(screen, (screen_w, screen_h), (0, screen_h))) boundaries.append(Boundary(screen, (0, screen_h), (0, 0))) for i in range(num_walls): boundaries.append( Boundary(screen, (randint(0, screen_w), randint(0, screen_h)), (randint(0, screen_w), randint(0, screen_h)))) for i in range(num_rays): rays.append(Ray(p, i * 360 / num_rays)) while running: for event in pg.event.get(): if event.type == pg.QUIT: running = False screen.fill((0, 0, 0)) for b in boundaries: b.update(screen) p.update(screen) for r in rays: r.update(screen, p, boundaries) pg.display.update() pg.time.wait(75)
def find_candidate_placements(tile, border, candidate_tiles, max_candidates = -1, force_edge_label = None): assert isinstance(tile, Tile) assert isinstance(border, Boundary) assert len(border) > 0 assert isinstance(candidate_tiles, CandidateTiles) assert len(candidate_tiles) > 0 candidate_placements = [] for pos_tile in candidate_tiles.iterate(): (i0, j0, L0) = pos_tile.get_segment() assert L0 > 0 tile_border = pos_tile.get_boundary(list(tile.desc)) # Recompute PositionedTile because the common segment's 'i' index will not match pos_tile = PositionedTile(pos_tile.pos, border.common_segments(tile_border)) (i1, j1, L1) = pos_tile.get_segment() if (j0, L0) != (j1, L1): warn('Incoherent common segments for tile at {} in candidate_tiles: {} and computed against the current border: {}'.format(pos_tile.pos, (i0, j0, L0), (i1, j1, L1))) continue if force_edge_label is not None and force_edge_label not in Boundary.label_getter(border.iter_slice(i1, i1 + L1)): continue for r in border.find_matching_rotations(tile_border, pos_tile.get_segment()): placed_tile = PlacedTile.from_positioned_tile(pos_tile, tile, r) if validate_tile_placement(placed_tile, border): candidate_placements.append(placed_tile) if max_candidates > 0 and len(candidate_placements) >= max_candidates: break return candidate_placements
def build_walls(self, polygon_result, local_coords): rospy.loginfo("Planner recieved information about the house. Building walls for detailed model") #model_walls = [] for i in range(len(local_coords) - 1): # Use the local coordinates to build walls self.model_walls.append(Boundary(local_coords[i][0], local_coords[i][1], 0.0, local_coords[i+1][0], local_coords[i+1][1], 0.0, local_coords[i][0], local_coords[i][1], polygon_result.building_height, "wall", self.s.get_lightsource())) # Let's also initiate the figure and plot all the walls self.fig = plt.figure(num=1, clear=True) self.ax = self.fig.add_subplot(1, 1, 1, projection='3d') # For loop that goes through all the model walls and plots them for wall in self.model_walls: wall.plot(self.ax) #ground_plane.plot(ax) self.ax.set_xlabel('X: East') self.ax.set_xlim(-50, 50) self.ax.set_ylabel('Y: North') self.ax.set_ylim(-50, 50) self.ax.set_zlabel('Z: Up') self.ax.set_zlim(-20, 20) axsolarbutton = plt.axes([0.85, 0.25, 0.10, 0.075]) self.solar_button = Button(axsolarbutton, 'Solar Check') self.m.draw_mission_planes(self.model_walls, self.ax) axbrushfirebutton = plt.axes([0.85, 0.10, 0.10, 0.075]) self.brushfirebutton = Button(axbrushfirebutton, 'Generate mission')
def draw_original_contour(function_id, **kwargs): dim = 2 func = CEC2005(dim)[function_id] population = kwargs.get('population', []) angle = kwargs.get('angle', 240) rotate = kwargs.get('rotate', False) fig_name = kwargs.get('fig_name', None) fig_title = kwargs.get('fig_title', str(func)) cmap = cm.coolwarm scatter_cmap = cm.jet(np.linspace(0.1, 0.9, len(population))) boundary = Boundary(dim, function_id) step = (boundary.max_bounds[0] - boundary.min_bounds[0]) / 100 X = np.arange(boundary.min_bounds[0], boundary.max_bounds[0] + step, step) Y = np.arange(boundary.min_bounds[1], boundary.max_bounds[1] + step, step) (X, Y) = np.meshgrid(X, Y) positions = (lambda .0: continue[ [ x, y] for (x, y) in .0 ])(zip(X.ravel(), Y.ravel())) solutions = (lambda .0: continue[ Individual(position) for position in .0 ])(positions) problem = Problem(func.objective_function) problem.batch_evaluate(solutions) Z = np.array((lambda .0: continue[ solution.objective_values for solution in .0 ])(solutions)) vmin = min(Z) vmax = max(Z) vmin = vmin - (vmax - vmin) * 0.2 vmax = vmax + (vmax - vmin) * 0.2 Z = Z.reshape(X.shape) inch_size = 4 fig_w = 1 fig_h = 1 fig = plt.figure(figsize = (fig_w * inch_size, fig_h * inch_size)) ax = fig.add_subplot(fig_h, fig_w, 1) ax.set_xlim([ boundary.min_bounds[0], boundary.max_bounds[0]]) ax.set_ylim([ boundary.min_bounds[1], boundary.max_bounds[1]]) cset = ax.contourf(X, Y, Z, cmap = cmap, vmin = vmin, vmax = vmax) fig.colorbar(cset, aspect = 20) colors = iter(scatter_cmap) color = next(colors) x = np.array((lambda .0: continue[ individual.phenome[0] for individual in .0 ])(population)) y = np.array((lambda .0: continue[ individual.phenome[1] for individual in .0 ])(population)) ax.scatter(x, y, color = color, marker = 'o', s = 10) for opt in func.get_optimal_solutions(): optimal_pos = opt.phenome ax.scatter(optimal_pos[0], optimal_pos[1], color = 'w', marker = 'x', s = 100) fig.tight_layout() st = fig.suptitle(fig_title, fontsize = 16) st.set_y(0.95) fig.subplots_adjust(top = 0.85) if fig_name is not None: plt.savefig(fig_name) else: plt.show() input('Press Enter to continue...') plt.close(fig)
def get_boundary(self, pos, r = 0): assert isinstance(pos, Vect) def merge_boundary(border, elt): border.merge(PlacedTile(elt.tile, pos + elt.offset.rotate(r), r).get_boundary()) return border return self.__reduce(merge_boundary, Boundary())
def setUp(self): self.initial_num_timestamps = 100 self.boundary = Boundary([(0, 0), (100, 0), (100, 100), (0, 100)]) self.moving_object = RandomlyMovingObject( self.boundary, num_timestamps=self.initial_num_timestamps) self.stationary_object = StationaryObject( (100, 100), num_timestamps=self.initial_num_timestamps) self.viewable_objects = [self.moving_object, self.stationary_object] self.object_universe = ObjectUniverse()
def setUp(self): self.canvas_width = 2000 self.canvas_height = 1000 self.bounary_points = [(100, 100), (300, 100), (300, 200), (100, 200)] self.tk_renderer = TKRenderer(scale=2, canvas_width=self.canvas_width, canvas_height=self.canvas_height) self.boundary = Boundary(self.bounary_points) return self
def draw_surface3d(function_id, **kwargs): dim = 2 func = CEC2005(dim)[function_id] clusters = kwargs.get('clusters', []) angle = kwargs.get('angle', 240) rotate = kwargs.get('rotate', False) fig_name = kwargs.get('fig_name', None) boundary = Boundary(func) step = (boundary.max_bounds[0] - boundary.min_bounds[0]) / 100 X = np.arange(boundary.min_bounds[0], boundary.max_bounds[0] + step, step) Y = np.arange(boundary.min_bounds[1], boundary.max_bounds[1] + step, step) (X, Y) = np.meshgrid(X, Y) positions = (lambda .0: continue[ [ x, y] for (x, y) in .0 ])(zip(X.ravel(), Y.ravel())) solutions = (lambda .0: continue[ Individual(position) for position in .0 ])(positions) problem = Problem(func.objective_function) problem.batch_evaluate(solutions) Z = np.array((lambda .0: continue[ solution.objective_values for solution in .0 ])(solutions)) Z = Z.reshape(X.shape) fig = plt.figure(figsize = plt.figaspect(0.5)) fig.suptitle(str(func)) ax = fig.add_subplot(1, 2, 1) cset = ax.contourf(X, Y, Z, cmap = cm.coolwarm) colors = iter(cm.rainbow(np.linspace(0, 1, len(clusters)))) for cluster in clusters: color = next(colors) x = np.array((lambda .0: continue[ individual.phenome[0] for individual in .0 ])(cluster.population)) y = np.array((lambda .0: continue[ individual.phenome[1] for individual in .0 ])(cluster.population)) ax.scatter(x, y, color = color, marker = 'o', s = 10) x_border = (lambda .0: continue[ vertice[0] for vertice in .0 ])(cluster.border) x_border.append(x_border[0]) y_border = (lambda .0: continue[ vertice[1] for vertice in .0 ])(cluster.border) y_border.append(y_border[0]) ax.plot(x_border, y_border, color = color) optimal_pos = func.get_optimal_solutions()[0].phenome ax.scatter(optimal_pos[0], optimal_pos[1], color = 'w', marker = 'x', s = 100) ax = fig.add_subplot(1, 2, 2, projection = '3d') surf = ax.plot_surface(X, Y, Z, alpha = 0.8, zorder = -1, cmap = cm.coolwarm, linewidth = 0, edgecolors = 'k', antialiased = False) fig.colorbar(surf, shrink = 0.5, aspect = 5) cset = ax.contourf(X, Y, Z, zdir = 'z', zorder = -2, offset = np.amin(Z), cmap = cm.coolwarm) if rotate: for ang in range(angle, angle + 360, 10): ax.view_init(30, ang) plt.draw() plt.pause(0.001) else: ax.view_init(30, angle) plt.show() if fig_name is not None: plt.savefig(fig_name) input('Press Enter to continue...')
def __init__(self, *args, **kwargs): super(App, self).__init__(caption='Kirchhoff-Plateau Surfaces', resizable=True, width=950, height=480, *args, **kwargs) self.set_minimum_size(950, 480) # инициализируются в on_resize self.container2D, self.container3D = None, None # создаём Boundary self.boundary = Boundary() # для рисования Point.set_radius(5) glEnable(GL_POINT_SMOOTH) glEnable(GL_LINE_SMOOTH) glEnable(GL_DEPTH_TEST) # чёрный фон glClearColor(0., 0., 0., 1)
def __init__(self): self.run = False self.menu = True self.rows = 3 self.columns = int((Game.WIDTH - Game.OFFSET_X) / Block.WIDTH) self.score = 0 self.lives = 5 self.level = 1 self.the_ball = Ball(Ball.START_POSITION[0], Ball.START_POSITION[1], 0, 0, white, Game.WIN) self.the_paddle = Paddle(Paddle.START_POSITION[0], Paddle.START_POSITION[1], Paddle.START_SIZE[0], Paddle.START_SIZE[1], white, Game.WIN) self.score_text = TextGUI(Game.WIDTH / 100 * 15, Game.HEIGHT // 60, Game.WIN, "SCORE: " + str(self.score), 50) self.lives_text = TextGUI(Game.WIDTH / 100 * 73, Game.HEIGHT - Game.HEIGHT // 12, Game.WIN, "LIVES: " + str(self.lives), 20) self.level_text = TextGUI(Game.WIDTH / 100 * 60, Game.HEIGHT // 60, Game.WIN, "LEVEL: " + str(self.level), 50) self.left_boundary = Boundary(0, 0 + Game.OFFSET_Y, Game.OFFSET_X // 2, Game.HEIGHT, gray, Game.WIN) self.right_boundary = Boundary(Game.WIDTH - Game.OFFSET_X // 2, 0 + Game.OFFSET_Y, Game.OFFSET_X // 2, Game.HEIGHT, gray, Game.WIN) self.top_boundary = Boundary(0, Game.OFFSET_Y // 2, Game.WIDTH, Game.OFFSET_Y // 2, gray, Game.WIN)
def insert_boundary(self): for i in range(self.columns): self.grid[0][i] = Boundary() self.grid[1][i] = Boundary() self.grid[2][i] = Boundary() self.grid[self.rows-1][i] = Boundary() self.grid[self.rows-2][i] = Boundary() self.grid[self.rows-3][i] = Boundary()
def __init__(self, max_evaluations, n_points, dimension, function_id, **kwargs): self.function_id = function_id self.n_points = n_points self.dimension = dimension self.function = CEC2005(dimension)[function_id].objective_function self.max_evaluations = max_evaluations * dimension self.max_bounds = Boundary(dimension, function_id).max_bounds self.min_bounds = Boundary(dimension, function_id).min_bounds self.optimal_position = CEC2005( dimension)[function_id].get_optimal_solutions()[0].phenome self.optimal_fitness = self.function(self.optimal_position) #self.problem = Problem(self.function.objective_function, max_evaluations=max_evaluations) self.boundary = Boundary(dimension, function_id) self.verbose = kwargs.get('verbose', False) self.population = [ ] #self.init_population( self.n_points, self.dimension ) self.algo_type = kwargs.get('algo_type', 'CMA') self.init_algo() self.iteration = 0 self.should_terminate = False self.optimal_solution = self.find_optimal_solution() self.stats = OrderedDict([ ('iteration', []), ('FEs', []), ('error', []), ('best_value', []), #('best_position',[]) ]) self.run() self.best_solution = min(self.population, key=attrgetter('objective_values'))
def put_up_windows(self, facade_image, windows, wall_length, model_wall): rospy.loginfo("Planner received information about the windows. Putting windows on walls") # Generate an array that takes the time from now and the next 30 minutes, which we will say is the estimated mission duration # We assume that the image itself is the plane, which is harsh to assume, but it's the best we've got... # Based on the size of the image (width, height), we make translation factors for x and y to be able to place the windows on the planes. # Let's then generate windows in the form that our mission class can understand, taking the bounding boxes of the instance segmentation, aka the rois and make windows out of them for i in range(len(windows)): # Remember that the coordinates of the rois (windows) are upside down on the y-axis # The rois are in the following form : y1,x1, y2,x2 n_xy_tiles = len(model_wall.x) n_z_tiles = len(model_wall.z) # this is the y coordinate of the image, but the z coordinate in the world-frame x1 = n_xy_tiles - round((windows[i].roi[1] / facade_image.width) * n_xy_tiles) - 1 y1 = n_z_tiles - round((windows[i].roi[0] / facade_image.height) * n_z_tiles) - 1 x2 = n_xy_tiles - round((windows[i].roi[3] / facade_image.width) * n_xy_tiles) - 1 y2 = n_z_tiles - round((windows[i].roi[2] / facade_image.height) * n_z_tiles) - 1 #rospy.loginfo([x1, y1, x2, y2]) # We are going to find indecies for the plane and just select the ones that the window covers # TODO: COrrect this method. It's not quite right... p1 = np.array([model_wall.x[x1], model_wall.y[x1], model_wall.z[y2]]) p2 = np.array([model_wall.x[x2], model_wall.y[x2], model_wall.z[y2]]) p3 = np.array([model_wall.x[x1], model_wall.y[x1], model_wall.z[y1]]) window = Boundary(p1[0], p1[1], p1[2], p2[0], p2[1], p2[2], p3[0], p3[2], p3[2], "window", self.s.get_lightsource()) window.plot(self.ax) self.model_windows.append(window) rospy.loginfo(self.s.date.timestamp()) return PoseArray()
def generate_random_boundary(n): """ Generate n random boundaries :param n: {int} :return: {list} List of boundaries created """ walls = [] for i in range(n): x1 = randint(0, 1000) x2 = randint(0, 1000) y1 = randint(0, 600) y2 = randint(0, 600) walls.append(Boundary(x1, y1, x2, y2)) return walls
def validate_tile_placement(placed_tile, border): # Trivial except for river tiles if 'R' in Boundary.label_getter(placed_tile.iter_segment()): test_border = border.copy() test_border.merge(placed_tile.get_boundary()) for (point, edge, label) in placed_tile.iter_complement_segment(): if label == 'R': test_tile_border = boundary.from_edge(point, edge, Orientation.COUNTERCLOCKWISE, Domain.EXTERIOR) common_segments = test_border.common_segments(test_tile_border) if len(common_segments) != 1: return False (_, _, L) = common_segments[0] if L != 1: return False return True
def test_merge(self): border = Boundary() border.merge(boundary.get_tile(Vect(0, 0), 'FFFF')) self.assertEqual(len(border), 4) self.assertEqual(border.labels, list('FFFF')) border.merge(boundary.get_tile(Vect(1, 0), 'FFFF')) self.assertEqual(len(border), 6) self.assertEqual(border.labels, list('FFFFFF'))
def test_common_segments_1(self): tile1 = boundary.get_tile(Vect(2, 1), 'FFFF') self.assertEqual(self.border.common_segments(tile1), [(3, 0, 0)]) tile2 = boundary.get_tile(Vect(1, 1), 'FFFF') self.assertEqual(self.border.common_segments(tile2), [(3, 0, 1)]) self.assertEqual(tile1.common_segments(tile2), [(3, 1, 1)]) self.assertEqual(tile2.common_segments(tile1), [(1, 3, 1)]) tile3 = Boundary() tile3.append(Vect(2, 2), 'F') tile3.append(Vect(1, 2), 'F') tile3.append(Vect(1, 1), 'F') tile3.append(Vect(2, 1), 'F') self.assertEqual(tile1.common_segments(tile3), [(3, 3, 1)]) self.assertEqual(tile3.common_segments(tile1), [(3, 3, 1)])
def main(): initialitation("RayCast") conn = DataBaseHandle.__conn__() display = py.display.set_mode([400, 400]) time = py.time.Clock() running = 1 wall = Boundary(300, 100, 300, 300) ray = Ray(100, 200) hilo = MainThread( [[display.fill, [colors.BLACK]], [wall.show, [display, colors.WITHE]], [ray.show, [display, colors.WITHE]], [py.display.flip, []], [time.tick, [5]]], py) t1 = Thread(name="non-block", target=updateActionsThread, args=(hilo, )) t1.start() hilo.mainThread()
def test_segment_labels(self): placed_tile = PlacedTile(self.test_tile, Vect(2, 1), r = 0, segment = (42, 1, 2)) self.assertEqual(list(Boundary.label_getter(placed_tile.iter_segment())), list('PT')) self.assertEqual(list(Boundary.label_getter(placed_tile.iter_complement_segment())), list('PF')) placed_tile = PlacedTile(self.test_tile, Vect(2, 1), r = 1, segment = (42, 1, 2)) self.assertEqual(list(Boundary.label_getter(placed_tile.iter_segment())), list('FP')) self.assertEqual(list(Boundary.label_getter(placed_tile.iter_complement_segment())), list('TP')) placed_tile = PlacedTile(self.test_tile, Vect(2, 1), r = 0, segment = (42, 1, 0)) self.assertEqual(list(Boundary.label_getter(placed_tile.iter_segment())), []) self.assertEqual(list(Boundary.label_getter(placed_tile.iter_complement_segment())), list('PTPF'))
def setUp(self): self.num_timestamps = 1000 self.tk_renderer = TKRenderer(canvas_width=800, canvas_height=700) self.boundary = Boundary([(100, 100), (300, 100), (300, 200), (100, 200)]) self.boundary_renderer = BoundaryRenderer(self.boundary) self.random_moving_objects = [ RandomlyMovingObject(boundary=self.boundary, num_timestamps=self.num_timestamps), RandomlyMovingObject(boundary=self.boundary, num_timestamps=self.num_timestamps) ] self.viewable_objects_renderer = ViewableObjectsRenderer( viewable_objects=self.random_moving_objects) self.animator = Animator(num_timestamps=self.num_timestamps, seconds_per_timestamp=0.2) self.animator.add_element_renderers( [self.viewable_objects_renderer, self.boundary_renderer]) self.tk_renderer.set_mouse_click_callback(self.animator.play) return self
def setUp(self, num_randomly_moving_objects=10): self.num_randomly_moving_objects = num_randomly_moving_objects self.num_timestamps = 60 self.tag_gps_angle_threshold = math.radians(7) self.object_universe = ObjectUniverse( num_timestamps=self.num_timestamps) self.camera = Camera() self.camera.set_actual_position((100, 400)).\ set_gps_position((100,380)).\ set_gps_max_error(25).\ set_fov_rad(math.pi/2) self.boundary = Boundary([(220, 300), (420, 100), (420, 700), (220, 500)]) self.tag = RandomlyMovingTag(boundary=self.boundary) self.viewable_objects = [self.tag] for _ in range(self.num_randomly_moving_objects): self.viewable_objects.append( RandomlyMovingObject(boundary=self.boundary)) self.object_universe.add_camera(self.camera).\ add_viewable_objects(self.viewable_objects) for timestamp in range(self.num_timestamps): self.camera.set_state_of_pan_motor_angle_at_timestamp(0, timestamp) self.camera.get_computer_vision().set_cv_ids_for_all_camera_time() self.object_motion_analyzer = ObjectMotionAnalyzer( self.camera, self.tag, tag_gps_angle_threshold=self.tag_gps_angle_threshold) self.frames = self.object_motion_analyzer.get_complete_frames() return self
def __init__(self): # Setup physical environment self.num_timestamps = 100 self.camera = Camera() self.camera.set_actual_position((100,300)).\ set_gps_position((100,290)).\ set_gps_max_error(10).\ set_fov_deg(70) for timestamp in range(self.num_timestamps): self.camera.set_pan_angle_deg(0, timestamp) self.cv = ComputerVision() self.camera.set_computer_vision(self.cv) self.boundary = Boundary([(150, 100), (150, 550), (300, 550), (300, 100)]) self.viewable_objects = [] for _ in range(20): self.viewable_objects.append( RandomlyMovingObject(boundary=self.boundary)) self.object_universe = ObjectUniverse( num_timestamps=self.num_timestamps) self.object_universe.add_camera(self.camera).\ add_viewable_objects(self.viewable_objects) self.cv.set_cv_ids_for_all_camera_time() # Rendering renderable_objects = [ self.boundary, self.object_universe, ] RenderOrchestrator(self.num_timestamps, seconds_per_timestamp=0.2, renderable_objects=renderable_objects).run()
def setUp(self, num_randomly_moving_objects=0): self.num_randomly_moving_objects = num_randomly_moving_objects self.num_timestamps = 100 self.object_universe = ObjectUniverse( num_timestamps=self.num_timestamps) self.camera = Camera() self.camera.set_fov_rad(math.pi / 2).\ set_actual_position((100,400)).\ set_gps_position((100,410)).\ set_gps_max_error(12).\ set_num_timestamps(self.num_timestamps) for timestamp in range(self.num_timestamps): self.camera.set_state_of_pan_motor_angle_at_timestamp(0, timestamp) self.viewable_objects = [] for y in range(100, 800, 50): self.viewable_objects.append(StationaryObject((301, y))) self.boundary = Boundary([(200, 200), (400, 200), (400, 600), (200, 600)]) for _ in range(self.num_randomly_moving_objects): self.viewable_objects.append( RandomlyMovingObject(boundary=self.boundary)) self.viewable_objects.append(RandomlyMovingTag(boundary=self.boundary)) self.object_universe.add_camera(self.camera).\ add_viewable_objects(self.viewable_objects) self.camera.get_computer_vision().set_cv_ids_for_all_camera_time() self.image_renderer = ImageRenderer(self.camera.get_image_generator()) self.image_renderer.set_computer_vision( self.camera.get_computer_vision()) return self
def setUp(self, tag_gps_angle_threshold=6, compass_err_deg=3.7): self.tag_gps_angle_threshold = tag_gps_angle_threshold self.compass_err_deg = compass_err_deg self.num_timestamps = 50 self.tag_gps_angle_threshold = math.radians(self.tag_gps_angle_threshold) self.object_universe = ObjectUniverse(num_timestamps=self.num_timestamps) self.camera = Camera() self.camera.set_actual_position((100, 400)).\ set_gps_position((100,380)).\ set_gps_max_error(25).\ set_fov_rad(math.pi/2).\ set_compass_error_rad(math.radians(self.compass_err_deg)) self.boundary = Boundary([(220,300), (420,100), (420,700), (220, 500)]) self.tag = RandomlyMovingTag(boundary=self.boundary) self.viewable_objects = [self.tag] self.object_universe.add_camera(self.camera).\ add_viewable_objects(self.viewable_objects) for timestamp in range(self.num_timestamps): self.camera.set_state_of_pan_motor_angle_at_timestamp(0, timestamp) self.camera.get_computer_vision().set_cv_ids_for_all_camera_time() self.base_position_calibrator = BasePositionCalibrator(self.camera, self.tag, tag_gps_angle_threshold=self.tag_gps_angle_threshold) self.base_angle_calibrator = BaseAngleCalibrator(self.base_position_calibrator) return self
def run(self): logger.info('agent starting skyline %s' % skyline_app) Boundary(getpid()).start() while 1: sleep(100)
from plot import Plot from staticmap import StaticMap from boundary import Boundary, Range, LatLon import pickle import pprint import glob from fileio import Fileio x_range = Range(-87.69215,-87.634896) y_range = Range(41.858952,41.886565) boundary = Boundary(x_range, y_range) center = boundary.center() center_latlon = LatLon(lon=center[0], lat=center[1]) print StaticMap.latlon2xy_tile(center_latlon.lat, center_latlon.lon, 12) print center_latlon metainfo = StaticMap.get_map("chicago.png", \ center={'lat':center_latlon.lat, 'lon':center_latlon.lon}, \ zoom=14, scale=2, maptype="roadmap") pprint.pprint(metainfo) print StaticMap.xy2latlon(metainfo, 0, 0) print StaticMap.latlon2xy_centered(metainfo, center_latlon.lat, center_latlon.lon) ll = metainfo['bbox']['low_left']