-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvisualize_3d.py
More file actions
59 lines (44 loc) · 1.42 KB
/
visualize_3d.py
File metadata and controls
59 lines (44 loc) · 1.42 KB
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
# Visualize solved MAPF instance in 3D
import argparse
import numpy as np
import matplotlib.pyplot as plt
import yaml
from mpl_toolkits.mplot3d import Axes3D
import argparse
def drawObs(data, obs):
for ob in obs:
data[ob[0], ob[1], :] = 1
def drawPath(path):
makespan = path[-1]['t']
x, y = [], []
for p in path:
x.append(int(p['x']))
y.append(int(p['y']))
z = range(int(makespan+1))
return x, y, z
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("map", help='map yaml file')
parser.add_argument("path", help='solved MAPF instance yaml file')
args = parser.parse_args()
with open(args.map) as map_file:
map_data = yaml.load(map_file, Loader=yaml.FullLoader)
with open(args.path) as path_file:
path_data = yaml.load(path_file, Loader=yaml.FullLoader)
dim = map_data["dimensions"]
obs = map_data["obstacles"]
agents = path_data["schedule"]
makespan = 0
for agent in agents:
if makespan < agents[agent][-1]['t']:
makespan = agents[agent][-1]['t']
data = np.zeros(shape=(dim[0], dim[1], makespan+1))
drawObs(data, obs)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# ax.set_box_aspect((dim[0], dim[1], makespan+1))
ax.voxels(data, alpha=.6)
for agent in agents:
x,y,z = drawPath(agents[agent])
ax.plot3D(x,y,z)
plt.show()