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.
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.
3D平滑处理是一种减少锯齿(阶梯状线条)的技术。 平滑处理可设置为有利于提高系统性能或改进图象质量。(功能可以查看3Dmax blender等等)
网格平滑属于数字几何处理领域的问题,计算机图形学和计算机辅助设计中,用多边形网格可以表示复杂的三维实体。随着三维扫描和曲面重建技术的发展,得到这些实体表面的多边形网格表示已经不是难事,但所得到的表面往往包含含噪声。在形状设计领域,在散乱点拟合和光滑形伏、纹理映射等应用领域,都有对平滑曲面的极大需求。故产生了网格平滑这一个研究点。
原文链接:https://blog.youkuaiyun.com/chenweiyu11962/article/details/112210226
这篇链接《Mesh平滑处理的几种算法比较》对算法有具体描述。
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()