OPEN3D学习笔记(⼆)——MeshTransformation
OPEN3D学习笔记(⼆)
Mesh
Open3D具有3D三⾓形⽹格的数据结构,称为TriangleMesh。下⾯的代码显⽰了如何从层中读取三⾓形⽹格并打印其顶点和三⾓形。
print("Testing mesh in open3d ...")
mesh = _knot_mesh()
print(mesh)
print('Vertices:')
print(np.asarray(mesh.vertices))# 每个点的坐标xyz
print('Triangles:')
print(np.iangles))# 每个⾯的三个点的索引
'''
Testing mesh in open3d ...
geometry::TriangleMesh with 1440 points and 2880 triangles.
Vertices:
[[  4.51268387  28.68865967 -76.55680847]
[  7.63622284  35.52046967 -69.78063965]
[  6.21986008  44.22465134 -64.82303619]
...
[-22.12651634  31.28466606 -87.37570953]
[-13.91188431  25.4865818  -86.25827026]
[ -5.27768707  23.36245346 -81.43279266]]
Triangles:
[[  0  12  13]
transform和convert的区别[  0  13    1]
[  1  13  14]
...
[1438  11 1439]
[1439  11    0]
[1439    0 1428]]
'''
可视化Mesh
print("Try to render a mesh with normals (exist: "+
str(mesh.has_vertex_normals())+") and colors (exist: "+
str(mesh.has_vertex_colors())+")")
o3d.visualization.draw_geometries([mesh])
print("A mesh with no normals and no colors does not look good.")
# 输出
# Try to render a mesh with normals (exist: True) and colors (exist: False)
您可以旋转和移动⽹格,但是⽹格被涂成均匀的灰⾊,看起来不像“ 3d”。原因是当前⽹格没有顶点或⾯的法线。因此,使⽤统⼀的颜⾊底纹代替更复杂的Phong底纹。
表⾯法线估计
print("Computing normal and rendering it.")
meshpute_vertex_normals()# 计算顶点法线
print(np.iangle_normals))# 打印每个顶点的法线
o3d.visualization.draw_geometries([mesh])
'''
Computing normal and rendering it.
[[ 0.79164373 -0.53951444  0.28674793]
[ 0.8319824  -0.53303008  0.15389681]
[ 0.83488162 -0.09250101  0.54260136]
...
[ 0.16269924 -0.76215917 -0.6266118 ]
[ 0.52755226 -0.83707495 -0.14489352]
[ 0.56778973 -0.76467734 -0.30476777]]
'''
裁剪Mesh
通过直接在⽹格的三⾓形和triangle_normals数据字段上进⾏操作,可以去除表⾯的⼀半。这是通过numpy完成的。
print("We make a partial mesh of only the first half triangles.")
mesh1 = copy.deepcopy(mesh)
np.iangles)[:iangles)//2,:])
np.iangle_normals)[:iangle_normals)//2,:])
iangles)# 打印三⾓形的个数
o3d.visualization.draw_geometries([mesh1])
'''
We make a partial mesh of only the first half triangles.
std::vector<Eigen::Vector3i> with 1440 elements.
Use numpy.asarray() to access data.
'''
上颜⾊
print("Painting the mesh")
mesh1.paint_uniform_color([1,0.706,0])
o3d.visualization.draw_geometries([mesh1])
Mesh⽹格属性(不太懂)
1.is_edge_manifold 和 is_vertex_manifold
如果每个边都边界⼀个或两个三⾓形,则三⾓形⽹格是边缘流形edge manifold
函数is_edge_manifold具有bool参数allow_boundary_edges,该参数定义是否应允许有界边
此外,如果顶点的星形是边缘流形和边缘连接的,例如两个或多个仅通过顶点⽽不通过边缘连接的⾯,则三⾓形⽹格是顶点流形vertex manifold
2.另⼀个特性是⾃相交的测试。如果⽹格中存在与另⼀个⽹格相交的三⾓形,则函数is_self_intersecting返回True。可以将⽔密⽹格定义为边缘流形,顶点流形并且不⾃相交的⽹格。函数is_watertight在Open3D中实现此检查。
3.我们也可以测试三⾓形⽹格(如果它是可定向的),即三⾓形可以以所有法线指向外部的⽅式定向。Open3D中的相应功能称为
is_orientable。
⽹格过滤
平均过滤器(Average filter)
拉普拉斯式(Laplacian)
陶宾过滤器(Taubin filter)
采样(Sampling)
⽹格细分
Mesh subdivision
在⽹格细分中,我们将每个三⾓形划分为多个较⼩的三⾓形。在最简单的情况下,我们计算每个三⾓形每侧的中点,并将三⾓形划分为四个较⼩的三⾓形。这是在subdivide_midpoint函数中实现的。3D曲⾯和⾯积保持不变,但顶点和三⾓形的数量增加。参数
number_of_iterations定义重复此过程的频率。
⽹格简化
有时,我们希望⽤较少的三⾓形和顶点来表⽰⾼分辨率的⽹格,但是低分辨率的⽹格仍然应该接近⾼分辨率的⽹格。为此,Open3D实现了许多⽹格简化⽅法。
顶点聚类、⽹格抽取
连接的组建
先跳过
Transformation
Translate平移
vt=v+t
在某个左边实现值的位移,相对的
mesh = ate_coordinate_frame()# 直接就是坐标轴,没有点的
mesh_tx = copy.deepcopy(mesh).translate((1.3,0,0))
mesh_ty = copy.deepcopy(mesh).translate((0,1.3,0))
print(f'Center of mesh: {_center()}')
print(f'Center of mesh tx: {_center()}')# get_center()返回顶点的均值
print(f'Center of mesh ty: {_center()}')
o3d.visualization.draw_geometries([mesh, mesh_tx, mesh_ty])
'''
输出:
Center of mesh: [0.05167549 0.05167549 0.05167549]
Center of mesh tx: [1.35167549 0.05167549 0.05167549]
Center of mesh ty: [0.05167549 1.35167549 0.05167549]
'''
该⽅法采⽤relative第⼆个参数,默认设置为true。如果将其更改为False,则⼏何中⼼将直接平移到第⼀个参数中指定的位置。(绝对的)
mesh = ate_coordinate_frame()
mesh_mv = copy.deepcopy(mesh).translate((2,2,2), relative=False)
print(f'Center of mesh: {_center()}')
print(f'Center of translated mesh: {_center()}')
o3d.visualization.draw_geometries([mesh, mesh_mv])
# 输出
# Center of mesh: [0.05167549 0.05167549 0.05167549]
# Center of translated mesh: [2. 2. 2.]
Rotation旋转
Convert from Euler angles with get_rotation_matrix_from_xyz (where xyz can also be of the form yzx zxy, xzy, zyx, and yxz) Convert from Axis-angle representation with get_rotation_matrix_from_axis_angle
Convert from Quaternions with get_rotation_matrix_from_quaternion
函数rotate具有第⼆个参数中⼼,默认情况下设置为True。这表明对象在应⽤旋转之前先居中,然后⼜移回其先前的中⼼。如果将此参数设置为False,则将直接应⽤旋转,这将围绕坐标中⼼旋转整个⼏何。这意味着旋转后可以更改⽹格中⼼。
Scale缩放
vs=s⋅v
mesh = ate_coordinate_frame()# 坐标轴
mesh_s = copy.deepcopy(mesh).translate((2,1,0))
mesh_s.scale(0.5, center=(0,0,0))# 缩放,是原来的0.5倍
o3d.visualization.draw_geometries([mesh, mesh_s])
General transformation⼀般转换
⽤4*4的矩阵
mesh = ate_coordinate_frame()
T = np.eye(4)# ⽣成⼀个矩阵,4*4的,对⾓线为1
T[:3,:3]= _rotation_matrix_from_xyz((0,np.pi/3, np.pi/2))# 定义旋转矩阵
T[0,3]=1
T[1,3]=1.3# 定义平移向量
print(T)
mesh_t = copy.deepcopy(mesh).transform(T)
o3d.visualization.draw_geometries([mesh, mesh_t])
'''
[[ 3.06161700e-17 -5.00000000e-01  8.66025404e-01  1.00000000e+00]
[ 1.00000000e+00  6.12323400e-17  0.00000000e+00  1.30000000e+00]
[-5.30287619e-17  8.66025404e-01  5.00000000e-01  0.00000000e+00]
[ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
'''

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。