pyvista 3D Smoothing

Preface:

vtk style of pipeline programming is often tedius and obscure. What makes it worse is that most authors tend to throw at you a huge junk of code contains mostly boilerplate code,  with no explanation on why certain filter is used.

Here I would recommend this vtk artile, showing how vtk articles should be written.

VTK introduction

Why Smoothing:

Point cloud data contains noises, which makes recontructed surface to be coarse and bumpy. Smoothing is often the first step to obtain a better model to work with.

Here I quote from VTK User Guide:

Polygonal meshes often contain noise or excessive roughness that affect the quality of the rendered image.

For example, isosurfacing low resolution data can show aliasing, or stepping effects.

One way to treat this problem is to use smoothing.

Smoothing is a process that adjusts the positions of points to reduce the noise content in the surface.

 Two Smoothing Types:

1. vtkSmoothPolyDataFilter (aka laplacian smoothing)

2. vtkWindowedSincPolyDataFilter (aka taubin smoothing)

Taubin smoothing is better, it is faster, more effective (need less iterations)and reduce the amount of shrinkage.

How to use:

n_iter, the higher iteration, the more smooth for the resulting model.

FeatureEdgeSmoothing, default is off, which means the smoothing will apply to all data causing the feature edges blur out. If it is turned on, smoothing will preserve the feature edges.

pyvista Examples:

import pyvista as pv
from pyvista import examples

mesh = examples.download_face()
smoothed_mesh = mesh.smooth(n_iter = 100)
dargs = dict(color=True)

p = pv.Plotter(shape=(1, 2))
p.add_mesh(mesh,**dargs)

p.subplot(0,1)
p.link_views()
p.add_mesh(smoothed_mesh,**dargs)

p.show()

Pyvista plotter:

1. see how subplots are generated

2. see how kw arguments can be set as a dictionary and then passed to add_mesh to control the graph appearance. The trick is useful when the kw arguments are long.

3. link_views() to sync two graph to move together.

mesh_curve = mesh.curvature('mean')
mesh['mean_curve'] = mesh_curve
smooth_mesh_curve = smoothed_mesh.curvature('mean')
smoothed_mesh['mean_curve'] = smooth_mesh_curve

dargs = dict(clim =[-50,50])
p = pv.Plotter(shape=(1, 2))
p.add_mesh(mesh,**dargs)
p.subplot(0,1)
p.link_views()
p.add_mesh(smoothed_mesh,**dargs)
p.show()

Note:

1. mesh can store attribute data (mass, temperature, elevation, curvature) in its geographic structure (points and cells)

mesh_curve = mesh.curvature('mean'), computes curvature for each points

mesh['mean_curve'] = mesh_curve, creates an attribute data array with the name mean_curve, sets the values as mesh_curve

mean_curve appears in the data array after this setting. And since it is highlighted, it is the current active scalars for the mesh.

Plotter will use the current active scalars for coloring.

Use set_active_scalars() to activate a different scalars.

mesh.clear_data() to clear all data array

2.  Smoothing filter improves the result of curvature filter, makes the curvature vales to be more uniform and the regions are somehow better connected. (Smoothing will round up sharp edges, hence increase its curvature, However smoothing doesnt change concave and convex nature of the surface)

3. taubin smoothing seems always better than regular smoothing. (Use taubin)

mesh.clear_data()
smoothed_mesh_taubin = mesh.smooth_taubin(n_iter = 10)

p = pv.Plotter(shape=(1, 2))

p.add_mesh(mesh)
p.subplot(0,1)
p.add_mesh(smoothed_mesh_taubin)
p.link_views()
p.show()


p = pv.Plotter(shape=(1, 2))
p.add_mesh(mesh,scalars = mesh.curvature())
p.subplot(0,1)
p.link_views()
p.add_mesh(smoothed_mesh_taubin, scalars = smoothed_mesh_taubin.curvature())
p.show()

  • 22
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值