-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvis_utils.py
59 lines (46 loc) · 1.75 KB
/
vis_utils.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
import open3d as o3d
import numpy as np
import matplotlib.pyplot as plt
def get_pts(pcd):
points = np.asarray(pcd.points)
X = []
Y = []
Z = []
for pt in range(points.shape[0]):
X.append(points[pt][0])
Y.append(points[pt][1])
Z.append(points[pt][2])
return np.asarray(X), np.asarray(Y), np.asarray(Z)
def set_axes_equal(ax):
x_limits = ax.get_xlim3d()
y_limits = ax.get_ylim3d()
z_limits = ax.get_zlim3d()
x_range = abs(x_limits[1] - x_limits[0])
x_middle = np.mean(x_limits)
y_range = abs(y_limits[1] - y_limits[0])
y_middle = np.mean(y_limits)
z_range = abs(z_limits[1] - z_limits[0])
z_middle = np.mean(z_limits)
plot_radius = 0.5*max([x_range, y_range, z_range])
ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius])
ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius])
ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius])
def plot_single_pcd(points, save_path, scale=4):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# ax.set_aspect('equal')
pcd = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(points))
rotation_matrix = np.asarray([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
pcd = pcd.transform(rotation_matrix)
X, Y, Z = get_pts(pcd)
t = Z
ax.scatter(X, Y, Z, c=t, cmap='jet', marker='o', s=scale, linewidths=0)
# ax.scatter(X, Y, Z, c=t, cmap='Reds', marker='o', s=10, linewidths=0)
ax.grid(False)
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
set_axes_equal(ax)
plt.axis('off')
plt.savefig(save_path, format='png', dpi=600)
plt.close()