Example #1
0
def run(source, destination, show, prediction, seed):
    (graph, ways, data) = read_xml(config.osm_path, config.elev_path)
    source = sys.argv[1].lower()
    dest = sys.argv[2].lower()

    try:
        source = int(source)
        assert source in graph
    except:
        if source in ways:
            source = ways[source][0]
        else:
            print('Source must be a valid node ID or a street name')
            return
    
    try:
        dest = int(dest)
        assert dest in graph
    except:
        if dest in ways:
            dest = ways[dest][0]
        else:
            print('Destination must be a valid node ID or a street name')
            return
    
    costfunc = None
    heuristic = None
    if prediction == 'toblers':
        costfunc = astar.toblers
        heuristic = astar.toblers_heuristic
    if prediction in ('linear', 'nearest'):
        walks = models.read_walk_data(config.walk_data_path, graph, data)
        training_walks, test_walks = models.partition_walks(walks, seed=seed)
        train = models.build_dist_elev_examples(training_walks, data)
        test = models.build_dist_elev_examples(test_walks, data)
        if prediction == 'linear':
            model = models.linear_model(train)
            costfunc = lambda a, b: model([astar.euclidean(a, b), b.z_m - a.z_m])
            heuristic = costfunc
        elif prediction == 'nearest':
            model = models.nearest_neighbor_model(train)
            costfunc = lambda a, b: model([astar.euclidean(a, b), b.z_m - a.z_m])
            heuristic = lambda a, b: 0

    result = astar.astar(costfunc, heuristic, graph, data, source, dest)
    if result is None:
        print('No path to destination found')

    pathstr = ', '.join((str(nd) for nd in result[0]))
    print('\npath: {}\n'.format(pathstr))
    print('time: {:.2f} minutes\n'.format(result[1]))

    #walk_data = models.read_walk_data(config.walk_data_path, graph, data)
    #print(walk_data)
    #if seed == None:
    #    seed = random.random()
    #models.compare_models(walk_data, data, seed)

    if show:
        graphics.display(graph, data, result[0], result[1])
def draw_solid(polydata):
    win_width = 500
    win_height = 500
    renderer, renderer_window = gr.init_graphics(win_width, win_height)
    gr.add_geometry(renderer,
                    polydata,
                    color=[0.0, 1.0, 0.0],
                    wire=False,
                    edges=True)
    gr.display(renderer_window)
def draw_segmentations(contours):
    num_segs = len(contours)

    ## Create renderer and graphics window.
    win_width = 500
    win_height = 500
    renderer, renderer_window = gr.init_graphics(win_width, win_height)
    ## Show contours.
    for sid in range(num_segs):
        seg = contours[sid]
        control_points = seg.get_control_points()
        gr.create_segmentation_geometry(renderer, seg)

    # Display window.
    gr.display(renderer_window)
Example #4
0
box_pd = box.get_polydata()
print("  Box: num nodes: {0:d}".format(box_pd.GetNumberOfPoints()))

## Create a cylinder.
print("Create a cylinder ...") 
center = [0.0, 0.0, 1.0]
axis = [0.0, 0.0, 1.0]
radius = 1.5
length = 10.0
cylinder = modeler.cylinder(center, axis, radius, length)
cylinder_pd = cylinder.get_polydata() 

## Subtract the cylinder from the box.
print("Union the cylinder and the box ...")
result = modeler.union(model1=box, model2=cylinder)
result_pd = result.get_polydata()

## Create renderer and graphics window.
win_width = 500
win_height = 500
renderer, renderer_window = gr.init_graphics(win_width, win_height)

## Add model polydata.
gr.add_geometry(renderer, box_pd, color=[0.0, 1.0, 0.0], wire=True, edges=False)
gr.add_geometry(renderer, cylinder_pd, color=[0.0, 0.0, 1.0], wire=True, edges=False)
#gr.add_geometry(renderer, result_pd, color=[1.0, 0.0, 0.0], wire=False, edges=False)

# Display window.
gr.display(renderer_window)

#Fifth step. Each unavailable node v computes the rank r of ID v in
#	S v and colors itself r. Each available node colors itself
#	1. Let this coloring of vertices be denoted χ  . Note that
#	this vertex coloring need not be proper.


def func():
    for vert in vertices:
        g.pygame.draw.rect(g.image, g.WHITE,
                           vert + [vertex_width, vertex_width])
    # for edge in edges:
    # g.pygame.draw.line(g.image,g.RED,vertices[edge[0]],vertices[edge[1]],edge_width)
    for edge in edges:
        # pass
        g.pygame.draw.line(g.image, g.RED, vertices[edge[0]],
                           vertices[edge[1]], edge_width)
    for i in range(len(vertices)):
        g.text_to_screen(g.image,
                         texts[i],
                         vertices[i][0],
                         vertices[i][1],
                         size=text_size)


# Graphics
g.init_graphics(500, 500)

g.add_loop_function(func)

g.display()
Example #6
0
        # Octant VII
        draw_line(screen, 0, yres - 1, xres - 75, 0, color)

        color = RGB_BLUE
        # Octant V
        draw_line(screen, xres - 1, yres - 1, 0, 75, color)
        # Octant VI
        draw_line(screen, xres - 1, yres - 1, 75, 0, color)
        # Octant IV
        draw_line(screen, xres - 1, 0, 0, yres - 75, color)
        # Octant III
        draw_line(screen, xres - 1, 0, 75, yres - 1, color)

        color = RGB_RED
        # y = x
        draw_line(screen, 0, 0, xres - 1, yres - 1, color)
        # y = -x
        draw_line(screen, 0, yres - 1, xres - 1, 0, color)

        # horizontal
        draw_line(screen, 0, yres / 2, xres - 1, yres / 2, color)
        # vertical
        draw_line(screen, xres / 2, 0, xres / 2, yres - 1, color)

        # display the image

    if args.no_display:
        save_extension(screen, args.filename)
    else:
        display(screen, args.filename)