-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtest.py
More file actions
104 lines (84 loc) · 2.71 KB
/
test.py
File metadata and controls
104 lines (84 loc) · 2.71 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from utils3d.helpers import timeit
import utils3d
from tqdm import trange
import numpy as np
import time
import open3d as o3d
import trimesh
import plyfile
import meshio
test_file = "debug/dragon_poly.ply"
def u3d_read_ply(file_path):
data = utils3d.np.read_ply(file_path)
data['vertex']['x'] += 0 # dummy operation to prevent optimization
return data
def plyfile_read_ply(file_path):
plydata = plyfile.PlyData.read(file_path)
vertex = plydata['vertex']
x = vertex['x'] # dummy operation to prevent optimization
x += 0
return plydata
def trimesh_read_ply(file_path):
mesh = trimesh.load_mesh(file_path, preprocess=False)
return mesh
def o3d_read_ply(file_path):
# mesh = o3d.io.read_triangle_mesh(file_path)
# np.asanyarray(mesh.vertices)
# np.asanyarray(mesh.triangles)
# return mesh
pcd = o3d.io.read_point_cloud(file_path)
np.asarray(pcd.points)
return pcd
def meshio_read_ply(file_path):
mesh = meshio.read(file_path)
return mesh
reader = {
'utils3d': u3d_read_ply,
# 'Open3D': o3d_read_ply,
# 'Trimesh': trimesh_read_ply,
# 'plyfile': plyfile_read_ply,
# 'meshio': meshio_read_ply,
}
def plyfile_write_ply(file_path, data):
data.write(file_path)
def trimesh_write_ply(file_path, data):
data.export(file_path)
def o3d_write_ply(file_path, data):
# o3d.io.write_triangle_mesh(file_path, data)
o3d.io.write_point_cloud(file_path, data)
def meshio_write_ply(file_path, data):
meshio.write(file_path, data)
writer = {
'utils3d': utils3d.np.write_ply,
'Open3D': o3d_write_ply,
'Trimesh': trimesh_write_ply,
'plyfile': plyfile_write_ply,
'meshio': meshio_write_ply,
}
reader_times = []
writer_times = []
ROUND = 10
for name, func in reader.items():
try:
data = func(test_file) # warm up
except Exception as e:
print(f"Error while testing {name}: {e}")
reader_times.append(float('inf'))
writer_times.append(float('inf'))
continue
start_read_time = time.time()
for _ in trange(ROUND, desc=f"Testing {name}"):
data = func(test_file)
end_read_time = time.time()
reader_times.append((end_read_time - start_read_time) / ROUND)
start_write_time = time.time()
for _ in trange(ROUND, desc=f"Testing {name} write"):
writer[name](f"debug/{name}_out.ply", data)
end_write_time = time.time()
average_write_time = (end_write_time - start_write_time) / ROUND
writer_times.append(average_write_time)
# print row in markdown table format
print(" | ".join(reader.keys()))
print(" | ".join([f"{t * 1000:.1f} ms" for t in reader_times]))
print(" | ".join(writer.keys()))
print(" | ".join([f"{t * 1000:.1f} ms" for t in writer_times]))