Upload 11 files
Browse files- data/zarr_database.zip +3 -0
- qdgset/__init__.py +0 -0
- qdgset/examples/list_objects.py +26 -0
- qdgset/examples/make_zarr_database_tree.py +30 -0
- qdgset/examples/read_zarr_database.py +18 -0
- qdgset/utils/__init__.py +0 -0
- qdgset/utils/export_utils.py +107 -0
- qdgset/utils/import_utils.py +13 -0
- qdgset/utils/visualize.py +32 -0
- requirements.txt +4 -0
- setup.py +3 -0
data/zarr_database.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7efb99c7a750431758b50ff350d8b1e5afe9d13a4ceb89ec34466d36d64fa3f1
|
3 |
+
size 3324683211
|
qdgset/__init__.py
ADDED
File without changes
|
qdgset/examples/list_objects.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import zarr
|
2 |
+
from multiprocessing import Pool
|
3 |
+
import argparse
|
4 |
+
|
5 |
+
def list_all_objects_name(dataset_root_group):
|
6 |
+
return [data_object for dataset in dataset_root_group.datasets.values() for data_object in dataset.keys()]
|
7 |
+
|
8 |
+
|
9 |
+
if __name__=='__main__':
|
10 |
+
def arg_parser():
|
11 |
+
parser = argparse.ArgumentParser()
|
12 |
+
parser.add_argument("-d", "--database", help="QDGset zipped zarr data path", type=str)
|
13 |
+
return parser.parse_args()
|
14 |
+
|
15 |
+
parser = arg_parser()
|
16 |
+
|
17 |
+
|
18 |
+
path = parser.database
|
19 |
+
|
20 |
+
|
21 |
+
with zarr.ZipStore(path, mode='r') as store:
|
22 |
+
root = zarr.group(store=store)
|
23 |
+
|
24 |
+
all_objects_name = list_all_objects_name(root)
|
25 |
+
|
26 |
+
print(f"There are {len(all_objects_name)} objects in the database")
|
qdgset/examples/make_zarr_database_tree.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import zarr
|
2 |
+
import argparse
|
3 |
+
|
4 |
+
if __name__=='__main__':
|
5 |
+
import zarr
|
6 |
+
from pprint import pprint
|
7 |
+
|
8 |
+
|
9 |
+
import argparse
|
10 |
+
|
11 |
+
def arg_parser():
|
12 |
+
parser = argparse.ArgumentParser()
|
13 |
+
parser.add_argument("-d", "--database", help="QDGset zipped zarr data path", type=str)
|
14 |
+
return parser.parse_args()
|
15 |
+
|
16 |
+
parser = arg_parser()
|
17 |
+
|
18 |
+
|
19 |
+
path = parser.database
|
20 |
+
store = zarr.ZipStore(path, mode='r')
|
21 |
+
root = zarr.group(store=store)
|
22 |
+
|
23 |
+
with open("dataset_zarr_tree_display.txt", "w") as output_file:
|
24 |
+
pprint(root.attrs["schema"], stream=output_file)
|
25 |
+
output_file.write("########################\n########################\n")
|
26 |
+
|
27 |
+
output_file.write(str(root.tree()))
|
28 |
+
|
29 |
+
print("tree written")
|
30 |
+
store.close()
|
qdgset/examples/read_zarr_database.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from qdgset.utils.visualize import visualize_from_obj_group
|
2 |
+
import zarr
|
3 |
+
import argparse
|
4 |
+
|
5 |
+
if __name__=='__main__':
|
6 |
+
|
7 |
+
def arg_parser():
|
8 |
+
parser = argparse.ArgumentParser()
|
9 |
+
parser.add_argument("-d", "--database", help="QDGset zipped zarr data path", type=str)
|
10 |
+
return parser.parse_args()
|
11 |
+
|
12 |
+
parser = arg_parser()
|
13 |
+
|
14 |
+
path = parser.database
|
15 |
+
|
16 |
+
with zarr.ZipStore(path, mode='r') as store:
|
17 |
+
root = zarr.group(store=store)
|
18 |
+
visualize_from_obj_group(root.datasets.net3d.net3D_obj_433.obj)
|
qdgset/utils/__init__.py
ADDED
File without changes
|
qdgset/utils/export_utils.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import yaml
|
3 |
+
|
4 |
+
import open3d as o3d
|
5 |
+
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
import zarr
|
9 |
+
from tempfile import NamedTemporaryFile
|
10 |
+
import fsspec
|
11 |
+
|
12 |
+
|
13 |
+
from qdgset.utils.import_utils import load_mesh_from_vertices_and_triangles
|
14 |
+
|
15 |
+
def export_to_obj_and_urdf_and_npz(object_group, directory_path, fs = fsspec.filesystem('local')):
|
16 |
+
vertices = object_group.obj.vertices
|
17 |
+
triangles = object_group.obj.faces
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
path = directory_path + object_group.name
|
22 |
+
name = path.split("/")[-1]
|
23 |
+
|
24 |
+
obj_path = path + "/" + name + ".obj"
|
25 |
+
urdf_path = path + "/"+ name + ".urdf"
|
26 |
+
grasps_path = path + "/"+ "individuals_0.npz"
|
27 |
+
|
28 |
+
fs.makedirs(path)
|
29 |
+
|
30 |
+
mesh = load_mesh_from_vertices_and_triangles(vertices, triangles)
|
31 |
+
|
32 |
+
base_name = os.path.basename(obj_path)
|
33 |
+
|
34 |
+
with NamedTemporaryFile(suffix=".obj") as tmp_file:
|
35 |
+
o3d.io.write_triangle_mesh(tmp_file.name, mesh)
|
36 |
+
fs.cp(tmp_file.name, obj_path)
|
37 |
+
|
38 |
+
inertia_xyz_str = " ".join(map(str,np.asarray(object_group.obj.inertia_origin[:3])))
|
39 |
+
mass = object_group.obj.mass[0]
|
40 |
+
ixx, ixy, ixz, iyy, iyz, izz = object_group.obj.inertia
|
41 |
+
|
42 |
+
with fs.open(urdf_path, "w") as urdf_file:
|
43 |
+
urdf_file.write(f"""
|
44 |
+
<?xml version="1.0"?>
|
45 |
+
<robot name="object">
|
46 |
+
<link name="object_link">
|
47 |
+
<visual>
|
48 |
+
<origin rpy="0 0 0" xyz="0 0 0" />
|
49 |
+
<geometry>
|
50 |
+
<mesh filename="{base_name}" scale="1 1 1" />
|
51 |
+
</geometry>
|
52 |
+
</visual>
|
53 |
+
<collision>
|
54 |
+
<origin rpy="0 0 0" xyz="0 0 0" />
|
55 |
+
<geometry>
|
56 |
+
<mesh filename="{base_name}" scale="1 1 1" />
|
57 |
+
</geometry>
|
58 |
+
</collision>
|
59 |
+
<inertial>
|
60 |
+
<origin rpy="0 0 0" xyz="{inertia_xyz_str}" />
|
61 |
+
<mass value="{mass}" />
|
62 |
+
<inertia ixx="{ixx}" ixy="{ixy}" ixz="{ixz}"
|
63 |
+
iyy="{iyy}" iyz="{iyz}" izz="{izz}" />
|
64 |
+
</inertial>
|
65 |
+
</link>
|
66 |
+
</robot>""".strip()) #!!IMPORTANT WE ASSUME NO ROTATION BETWEEN INERTIAL FRAME AND GEOMETRY FRAME!!
|
67 |
+
|
68 |
+
|
69 |
+
if "grasps" in object_group.keys():
|
70 |
+
info_keys = np.asarray(['xyz_pose_x', 'xyz_pose_y', 'xyz_pose_z', 'quat_1', 'quat_2', 'quat_3', 'quat_4'])
|
71 |
+
|
72 |
+
with fs.open(grasps_path,"wb") as grasp_file:
|
73 |
+
np.savez(grasp_file, infos=np.asarray(object_group.grasps), infos_keys=info_keys)
|
74 |
+
else:
|
75 |
+
print(f"WARN: Object {object_group.name} has no grasps")
|
76 |
+
|
77 |
+
|
78 |
+
if __name__=="__main__":
|
79 |
+
import multiprocessing
|
80 |
+
from multiprocessing import Pool, cpu_count
|
81 |
+
import zarr
|
82 |
+
zarr.blosc.use_threads = False
|
83 |
+
|
84 |
+
import argparse
|
85 |
+
|
86 |
+
def arg_parser():
|
87 |
+
parser = argparse.ArgumentParser()
|
88 |
+
parser.add_argument("-o", "--out", help="Export path", type=str, required=True)
|
89 |
+
parser.add_argument("-i", "--in_zarr", help="Path of the zarr database", type=str, required=True)
|
90 |
+
return parser.parse_args()
|
91 |
+
|
92 |
+
parser = arg_parser()
|
93 |
+
export_directory = parser.out
|
94 |
+
def export(obj):
|
95 |
+
return export_to_obj_and_urdf_and_npz(obj, export_directory)
|
96 |
+
|
97 |
+
|
98 |
+
nb_cpu = cpu_count() -2
|
99 |
+
p = Pool(nb_cpu)
|
100 |
+
|
101 |
+
zarr_path = parser.in_zarr
|
102 |
+
with zarr.ZipStore(zarr_path, mode='r') as store:
|
103 |
+
root = zarr.group(store=store)
|
104 |
+
|
105 |
+
for dataset in root.datasets:
|
106 |
+
print(f"INFO: Export {dataset} objects and grasps")
|
107 |
+
p.map(export, root.datasets[dataset].values())
|
qdgset/utils/import_utils.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import open3d as o3d
|
2 |
+
|
3 |
+
def load_mesh_from_path(path):
|
4 |
+
mesh = o3d.io.read_triangle_mesh(path)
|
5 |
+
|
6 |
+
return mesh
|
7 |
+
|
8 |
+
def load_mesh_from_vertices_and_triangles(vertices, triangles):
|
9 |
+
mesh = o3d.geometry.TriangleMesh()
|
10 |
+
mesh.vertices = o3d.utility.Vector3dVector(vertices)
|
11 |
+
mesh.triangles = o3d.utility.Vector3iVector(triangles)
|
12 |
+
|
13 |
+
return mesh
|
qdgset/utils/visualize.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from qdgset.utils.import_utils import load_mesh_from_path, load_mesh_from_vertices_and_triangles
|
2 |
+
|
3 |
+
import open3d as o3d
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
def visualize_from_obj_group(obj_group):
|
8 |
+
visualize_from_vertices_and_triangles(obj_group.vertices, obj_group.faces)
|
9 |
+
|
10 |
+
|
11 |
+
def visualize_mesh(mesh):
|
12 |
+
vis = o3d.visualization.Visualizer()
|
13 |
+
vis.create_window()
|
14 |
+
mesh.compute_vertex_normals()
|
15 |
+
vis.add_geometry(mesh)
|
16 |
+
vis.run()
|
17 |
+
vis.destroy_window()
|
18 |
+
|
19 |
+
def visualize_from_path(path):
|
20 |
+
mesh = load_mesh_from_path(path)
|
21 |
+
visualize_mesh(mesh)
|
22 |
+
|
23 |
+
def visualize_from_vertices_and_triangles(vertices, triangles):
|
24 |
+
# Create mesh
|
25 |
+
mesh = load_mesh_from_vertices_and_triangles(vertices, triangles)
|
26 |
+
|
27 |
+
# Compute vertex normals
|
28 |
+
mesh.compute_vertex_normals()
|
29 |
+
|
30 |
+
# Visualize mesh
|
31 |
+
visualize_mesh(mesh)
|
32 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
zarr==2.18.2
|
2 |
+
numpy==1.26.3
|
3 |
+
open3d==0.18.0
|
4 |
+
fsspec==2024.2.0
|
setup.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from setuptools import setup, find_packages
|
2 |
+
|
3 |
+
setup(name='qdgset', version='0.1', packages=find_packages(), install_requires=['zarr', 'fsspec',"open3d","numpy"])
|