Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/visualize_floorplan.py
612 views
1
#!/usr/bin/python3
2
3
import numpy as np
4
import matplotlib.pyplot as plt
5
import sys
6
7
usage = """
8
usage: visualize_floorplan.py <flp_file> <filename>.png (or)
9
visualize_floorplan.py --without-names <flp_file> <filename>.png
10
11
Creates a visual representation of the floorplan file and saves
12
it as a PNG with the name <filename>.png, with or without the names
13
of each floorplan element
14
"""
15
16
if len(sys.argv) == 3:
17
include_names = True
18
flp_filename = sys.argv[1]
19
output_filename = sys.argv[2]
20
elif len(sys.argv) == 4 and sys.argv[1] == "--without-names":
21
include_names = False
22
flp_filename = sys.argv[2]
23
output_filename = sys.argv[3]
24
else:
25
print(usage)
26
sys.exit(0)
27
28
fig, axs = plt.subplots(1)
29
total_width = -np.inf
30
total_length = -np.inf
31
32
with open(flp_filename, "r") as fp:
33
for line in fp:
34
35
# Ignore blank lines and comments
36
if line == "\n" or line[0] == '#':
37
continue
38
39
parts = line.split()
40
name = parts[0]
41
width = float(parts[1])
42
length = float(parts[2])
43
x = float(parts[3])
44
y = float(parts[4])
45
46
rectangle = plt.Rectangle((x, y), width, length, fc="none", ec="black")
47
axs.add_patch(rectangle)
48
49
if include_names:
50
plt.text(x, y, name)
51
52
total_width = max(total_width, x + width)
53
total_length = max(total_length, y + length)
54
55
56
axs.set_xticks([n for n in np.linspace(0, total_width, 5)])
57
axs.set_xticklabels([n*(10**3) for n in np.linspace(0, total_width, 5)])
58
axs.set_xlabel("Horizontal Position (mm)")
59
60
axs.set_yticks([n for n in np.linspace(0, total_length, 5)])
61
axs.set_yticklabels([n*(10**3) for n in np.linspace(0, total_length, 5)])
62
axs.set_ylabel("Vertical Position (mm)")
63
64
plt.axis('scaled')
65
plt.savefig(output_filename)
66
67