def __get_vis(self): poly = [] for p in self.path.to_polygons(): poly.append(vis.Polygon([vis.Point(*v) for v in p[:-1][::-1]])) env = vis.Environment(poly) vg = vis.Visibility_Graph(env, self.epsilon) return env, vg
def __get_visibility_graph(self): vg = vis.Visibility_Graph(self.env, self.eps) nx_vg = nx.Graph() tgt = [i for i in xrange(vg.n()) if self.__is_reflex(self.env(i))] for i, j in itertools.combinations(tgt, 2): if vg(i, j): u = (self.env(i).x(), self.env(i).y()) v = (self.env(j).x(), self.env(j).y()) dist = np.linalg.norm(np.array(u) - np.array(v)) nx_vg.add_edge(u, v, weight=dist) return nx_vg
def get_point_visibility_graph(self,points): vis_points = points_to_vis_points(points) graph = vis.Visibility_Graph(vis_points,self.environment,1e-12) res = [] for pidx1 in range(len(points)): adjlist = [] for pidx2 in range(len(points)): if graph(pidx1,pidx2): adjlist.append(pidx2) res.append(adjlist) return res
def vis_graph(poly): P = poly_list(poly) vis_polygons = [] for p in P: vis_polygons.append(vis.Polygon([vis.Point(x, y) for x, y in p])) env = vis.Environment(vis_polygons) vg = vis.Visibility_Graph(env, 0.000001) edges = [] for i, j in itertools.combinations(range(vg.n()), 2): if vg(i, j): edges.append([[env(i).x(), env(i).y()], [env(j).x(), env(j).y()]]) plt.gca().add_collection(mc.LineCollection(edges, color='g')) print len(edges)
def environments(epsilon=0.0000001): wall_choords = [(0, 0), (700, 0), (700, 900), (0, 900)] wall = vis.Polygon([vis.Point(x, y) for x, y in wall_choords]) holes_choords = [[(100, 300), (100, 500), (150, 500), (150, 300)], [(300, 300), (300, 500), (400, 550), (400, 300)], [(90, 700), (250, 750), (220, 600), (150, 600)], [(330, 700), (330, 800), (530, 850), (530, 790)], [(230, 50), (250, 90), (390, 90), (390, 50)]] holes = [] for hc in holes_choords: holes.append(vis.Polygon([vis.Point(x, y) for x, y in hc])) draw_env(wall_choords, holes_choords) env = vis.Environment([wall] + holes) return env, vis.Visibility_Graph(env, epsilon)
def vis_graph(poly): P = poly_list(poly) vis_polygons = [] for p in P: vis_polygons.append(vis.Polygon([vis.Point(x, y) for x, y in p])) env = vis.Environment(vis_polygons) vg = vis.Visibility_Graph(env, 0.000001) edges = [] G = nx.Graph() for i, j in itertools.combinations(range(vg.n()), 2): if vg(i, j): edges.append([[env(i).x(), env(i).y()], [env(j).x(), env(j).y()]]) G.add_edge(i, j, weight=np.linalg.norm( np.array(edges[-1][0]) - np.array(edges[-1][1]))) plt.gca().add_collection(mc.LineCollection(edges, color='g')) s, t = get_st(env) sp = [i for i in nx.shortest_path(G, s, t, 'weight')] sp_edges = [[[env(i).x(), env(i).y()], [env(j).x(), env(j).y()]] for i, j in zip(sp[:-1], sp[1:])] plt.gca().add_collection(mc.LineCollection(sp_edges, color='r', lw=2))