-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug-plot.py
82 lines (66 loc) · 2.12 KB
/
debug-plot.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
from typing import List
import matplotlib.pyplot as plt # type: ignore[import]
import numpy as np # type: ignore[import]
def get_rays(file: str) -> List[List[List[float]]]:
"""Read rays from file.
Args:
file: str
file from which rays are read. Format of file is
x11, y11, z11
x12, y12, z12
. . .
x1n, y1n, z1n
x21, y21, z21
x22, y22, z22
. . .
x2n, y2n, z2n
Returns:
List[List[List[float]]]: Description
"""
rays = []
with open(file, "r") as f:
lines = f.readlines()
skip_counter = 0
tmp = []
for line in lines:
length = len(line)
if length > 3:
skip_counter = 0
line = line.lstrip().rstrip()
line = line.replace(" ", " ")
line = line.replace(" ", " ")
line = line.replace(" ", " ")
data = line.split(" ")
tmp.append(list(map(float, data)))
else:
if skip_counter == 0:
if len(tmp) != 0:
rays.append(tmp)
tmp = []
skip_counter += 1
if skip_counter == 3:
skip_counter = 0
tmp = []
continue
return rays
def plot_rays(rays: List[List[List[float]]]) -> None:
"""Plot rays in 3D line plot with each ray the same colour
Args:
rays (List[List[List[float]]]): Description
"""
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
for ray in rays:
ray = np.array(ray).T
ax.plot(*ray, color="#1f77b4")
ax.scatter(*ray, color="#ff7f0e")
plt.show()
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("-f", "--file", type=str,
help="Name of file to be plotted.")
args = parser.parse_args()
file = args.file
rays = get_rays(file)
plot_rays(rays)