-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize.py
103 lines (87 loc) · 2.59 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#python3 spr.py env_01.txt 1.0 2.0 3.0 4.0import sys
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
import numpy as np
import sys
'''
Set up matplotlib to create a plot with an empty square
'''
def setupPlot():
fig = plt.figure(num=None, figsize=(5, 5), dpi=120, facecolor='w', edgecolor='k')
plt.autoscale(False)
plt.axis('off')
ax = fig.add_subplot(1,1,1)
ax.set_axis_off()
ax.add_patch(patches.Rectangle(
(0,0), # (x,y)
1, # width
1, # height
fill=False
))
return fig, ax
'''
Make a patch for a single pology
'''
def createPolygonPatch(polygon):
verts = []
codes= []
for v in range(0, len(polygon)):
xy = polygon[v]
verts.append((xy[0]/10., xy[1]/10.))
if v == 0:
codes.append(Path.MOVETO)
else:
codes.append(Path.LINETO)
verts.append(verts[0])
codes.append(Path.CLOSEPOLY)
path = Path(verts, codes)
patch = patches.PathPatch(path, facecolor='gray', lw=1)
return patch
'''
Make a patch for the robot
'''
def createPolygonPatchForRobot(polygon):
verts = []
codes= []
for v in range(0, len(polygon)):
xy = polygon[v]
verts.append((xy[0]/10., xy[1]/10.))
if v == 0:
codes.append(Path.MOVETO)
else:
codes.append(Path.LINETO)
verts.append(verts[0])
codes.append(Path.CLOSEPOLY)
path = Path(verts, codes)
patch = patches.PathPatch(path, facecolor='gray', lw=1)
return patch
'''
Render polygon obstacles
'''
def drawPolygons(polygons):
fig, ax = setupPlot()
for p in range(0, len(polygons)):
patch = createPolygonPatch(polygons[p])
ax.add_patch(patch)
plt.show()
if __name__ == "__main__":
# Retrive file name for input data
if(len(sys.argv) < 2):
print("Please provide input file: python visualize.py [env-file]")
exit()
filename = sys.argv[1]
# Read data and parse polygons
lines = [line.rstrip('\n') for line in open(filename)]
polygons = []
for line in range(0, len(lines)):
xys = lines[line].split(';')
polygon = []
for p in range(0, len(xys)):
polygon.append(list(map(float, xys[p].split(','))))
polygons.append(polygon)
# Print out the data
for p in range(0, len(polygons)):
print(str(polygons[p]))
# Draw the polygons
drawPolygons(polygons)