-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDocs_Geometry_Working_With_NumPy.py
39 lines (34 loc) · 1.77 KB
/
Docs_Geometry_Working_With_NumPy.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
import open3d as o3d
import numpy as np
# http://www.open3d.org/docs/release/tutorial/geometry/working_with_numpy.html
########################################################################################################################
# 1. Working with NumPy
########################################################################################################################
# Generate some neat n times 3 matrix using a variant of sync function
x = np.linspace(-3, 3, 401)
mesh_x, mesh_y = np.meshgrid(x, x)
z = np.sinc((np.power(mesh_x, 2) + np.power(mesh_y, 2)))
z_norm = (z - z.min()) / (z.max() - z.min())
xyz = np.zeros((np.size(mesh_x), 3))
xyz[:, 0] = np.reshape(mesh_x, -1)
xyz[:, 1] = np.reshape(mesh_y, -1)
xyz[:, 2] = np.reshape(z_norm, -1)
print('xyz')
print(xyz)
########################################################################################################################
# 2. From NumPy to open3d.PointCloud
########################################################################################################################
# Pass xyz to Open3D.o3d.geometry.PointCloud and visualize
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)
o3d.io.write_point_cloud("sync.ply", pcd)
########################################################################################################################
# 3. From open3d.PointCloud to NumPy
########################################################################################################################
# Load saved point cloud and visualize it
pcd_load = o3d.io.read_point_cloud("sync.ply")
# Convert Open3D.o3d.geometry.PointCloud to numpy array
xyz_load = np.asarray(pcd_load.points)
print('xyz_load')
print(xyz_load)
o3d.visualization.draw_geometries([pcd_load], width=800, height=600)