Skip to content

Commit d0aa399

Browse files
committed
Update
1 parent 1827c17 commit d0aa399

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

model_viewer.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import glob
2+
import os
3+
4+
import matplotlib.pyplot as plt
5+
import numpy as np
6+
7+
8+
def view_point_cloud_model_and_affordance(number_of_object_per_category=5):
9+
"""
10+
View model and grasp affordance
11+
12+
:return:
13+
"""
14+
list_pc_paths = [f for f in glob.glob('./dataset/*.npy', recursive=True)]
15+
set_objects = set([os.path.basename(pc_path).split('_')[0] for pc_path in list_pc_paths])
16+
17+
for obj in set_objects:
18+
try:
19+
# load point cloud models
20+
pc_models = np.load('./dataset/{}_point_cloud_models.npy'.format(obj))[
21+
:number_of_object_per_category]
22+
# load point cloud grasp affordance
23+
pc_affordance = np.load('./dataset/{}_point_cloud_grasp_affordance.npy'.format(obj))[
24+
:number_of_object_per_category]
25+
26+
# visualization
27+
for i, m in enumerate(pc_models):
28+
fig = plt.figure()
29+
ax = fig.add_subplot(projection='3d')
30+
list_model_x, list_model_y, list_model_z = [], [], []
31+
list_affordance_x, list_affordance_y, list_affordance_z = [], [], []
32+
33+
for x in range(32):
34+
for y in range(32):
35+
for z in range(32):
36+
if pc_affordance[i, x, y, z] == 1:
37+
list_affordance_x.append(x)
38+
list_affordance_y.append(y)
39+
list_affordance_z.append(z)
40+
elif m[x, y, z] == 1:
41+
list_model_x.append(x)
42+
list_model_y.append(y)
43+
list_model_z.append(z)
44+
45+
ax.scatter(list_model_x, list_model_y, list_model_z, c='#0c457d')
46+
ax.scatter(list_affordance_x, list_affordance_y, list_affordance_z, c='#e8702a', alpha=0.35)
47+
ax.set_xlim(0, 32)
48+
ax.set_ylim(0, 32)
49+
ax.set_zlim(0, 32)
50+
plt.show()
51+
52+
except FileNotFoundError:
53+
print('Some point cloud npy files are not found.')
54+
continue
55+
56+
57+
if __name__ == '__main__':
58+
view_point_cloud_model_and_affordance(number_of_object_per_category=5)

0 commit comments

Comments
 (0)