2021-06-04 17:12:30 +08:00
|
|
|
'''
|
|
|
|
@ Date: 2021-04-25 15:52:01
|
|
|
|
@ Author: Qing Shuai
|
|
|
|
@ LastEditors: Qing Shuai
|
2021-06-25 21:17:22 +08:00
|
|
|
@ LastEditTime: 2021-06-20 15:22:59
|
2021-06-04 17:12:30 +08:00
|
|
|
@ FilePath: /EasyMocap/easymocap/visualize/o3dwrapper.py
|
|
|
|
'''
|
|
|
|
import open3d as o3d
|
|
|
|
import numpy as np
|
2021-06-25 21:17:22 +08:00
|
|
|
from .geometry import create_ground as create_ground_
|
|
|
|
from .geometry import create_point as create_point_
|
|
|
|
from .geometry import create_line as create_line_
|
2021-06-04 17:12:30 +08:00
|
|
|
|
|
|
|
Vector3dVector = o3d.utility.Vector3dVector
|
|
|
|
Vector3iVector = o3d.utility.Vector3iVector
|
|
|
|
Vector2iVector = o3d.utility.Vector2iVector
|
|
|
|
TriangleMesh = o3d.geometry.TriangleMesh
|
|
|
|
load_mesh = o3d.io.read_triangle_mesh
|
2021-06-25 21:17:22 +08:00
|
|
|
vis = o3d.visualization.draw_geometries
|
|
|
|
|
|
|
|
def _create_cylinder():
|
|
|
|
# create_cylinder(radius=1.0, height=2.0, resolution=20, split=4, create_uv_map=False)
|
|
|
|
pass
|
2021-06-04 17:12:30 +08:00
|
|
|
|
|
|
|
def create_mesh(vertices, faces, colors=None, **kwargs):
|
|
|
|
mesh = TriangleMesh()
|
|
|
|
mesh.vertices = Vector3dVector(vertices)
|
|
|
|
mesh.triangles = Vector3iVector(faces)
|
|
|
|
if colors is not None:
|
|
|
|
mesh.vertex_colors = Vector3dVector(colors)
|
|
|
|
else:
|
|
|
|
mesh.paint_uniform_color([1., 0.8, 0.8])
|
|
|
|
mesh.compute_vertex_normals()
|
|
|
|
return mesh
|
|
|
|
|
2021-06-25 21:17:22 +08:00
|
|
|
def create_point(**kwargs):
|
|
|
|
return create_mesh(**create_point_(**kwargs))
|
|
|
|
|
|
|
|
def create_line(**kwargs):
|
|
|
|
return create_mesh(**create_line_(**kwargs))
|
|
|
|
|
2021-06-04 17:12:30 +08:00
|
|
|
def create_ground(**kwargs):
|
|
|
|
ground = create_ground_(**kwargs)
|
|
|
|
return create_mesh(**ground)
|
|
|
|
|
2021-06-25 21:17:22 +08:00
|
|
|
def create_coord(camera = [0,0,0], radius=1, scale=1):
|
2021-06-04 17:12:30 +08:00
|
|
|
camera_frame = TriangleMesh.create_coordinate_frame(
|
|
|
|
size=radius, origin=camera)
|
2021-06-25 21:17:22 +08:00
|
|
|
camera_frame.scale(scale)
|
2021-06-04 17:12:30 +08:00
|
|
|
return camera_frame
|
|
|
|
|
|
|
|
def create_bbox(min_bound=(-3., -3., 0), max_bound=(3., 3., 2), flip=False):
|
|
|
|
if flip:
|
|
|
|
min_bound_ = min_bound.copy()
|
|
|
|
max_bound_ = max_bound.copy()
|
|
|
|
min_bound = [min_bound_[0], -max_bound_[1], -max_bound_[2]]
|
|
|
|
max_bound = [max_bound_[0], -min_bound_[1], -min_bound_[2]]
|
|
|
|
bbox = o3d.geometry.AxisAlignedBoundingBox(min_bound, max_bound)
|
|
|
|
return bbox
|