Open3d之网格变形

如果我们想使用少量的约束使得三角网格变形,得使用相应的网格变形算法。Open3d实现了[SorkineAndAlexa2007] 中的尽可能严格的算法,该方法优化了以下能量函数:

这里的R_{i}表示 我们要优化的旋转矩阵,P_{i}P_{i}^{'}分别表示优化前后的顶点位置。N(i)表示顶点i的邻域集合。权重w_{ij}​表示余切权重(cot weights)。

Open3d实现的算法的接口是deform_as_rigid_as_possible。这个算法的第一个参数是一组constraint_ids,它是引用的三角网格的顶点。第二个参数constrint_pos定义了这些顶点优化后的位置。因为这个优化过程是一个迭代的过程,所以我们也能通过max_iter定义迭代次数。

# -*- coding: UTF-8 -*-
import numpy as np
import open3d as o3d
import Open3D.examples.python.open3d_tutorial as o3dtut

# 获取网格ply文件,若不存在则下载
mesh = o3dtut.get_armadillo_mesh()
# 获取网格顶点
vertices = np.asarray(mesh.vertices)
# 获取y小于-30m的顶点的id
static_ids = [idx for idx in np.where(vertices[:, 1] < -30)[0]]
# 求所有顶点坐标
static_pos = []
for idx in static_ids:
    static_pos.append(vertices[idx])

handle_ids = [2490]
handle_pos = [vertices[2490] + np.array((-40, -40, -40))]

# 顶点优化后的位置
constraint_ids = o3d.utility.IntVector(static_ids + handle_ids)
constraint_pos = o3d.utility.Vector3dVector(static_pos + handle_pos)

# 网格变形
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
    mesh_prime = mesh.deform_as_rigid_as_possible(
        constraint_ids, constraint_pos, max_iter=50)
# 可视化
print('Original Mesh')
R = mesh.get_rotation_matrix_from_xyz((0, np.pi, 0))
o3d.visualization.draw_geometries([mesh.rotate(R, center=mesh.get_center())])
print('Deformed Mesh')
mesh_prime.compute_vertex_normals()
o3d.visualization.draw_geometries(
    [mesh_prime.rotate(R, center=mesh_prime.get_center())])

 

在这里插入图片描述

 

在这里插入图片描述

Smoothed ARAP

Open3d实现了ARAP目标的平滑版本,定义为:

这惩罚相邻旋转矩阵的偏差,α 是正则项的权衡参数,A是表面积。
通过将参数energySmoothed一起使用,可以在deform_as_rigid_as_possible中使用这个平滑目标。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值