Smooth surface mesh
Smooth Surface Mesh Using Average, Laplacian, and Taubin Filters
Define the x-, y-, and z- coordinates of the vertices.
[x,y] = meshgrid(1:15,1:15); z = peaks(15); vertices = [x(:) y(:) z(:)];
Define triangular faces for the vertices using Delaunay triangulation.
faces = delaunay(x,y);
Define a surface mesh from the vertices and faces.
surfaceMeshIn = surfaceMesh(vertices,faces);
Visualize the surface mesh.
Smooth Surface Mesh using Average Filter
Smooth the surface mesh using the average filter with varying number of iterations. Visualize the smooth surface meshes. Observe that the smoothing increases with number of iterations. The mesh shrinkage also increases with number of iterations.
for numIterations = [2 5 10] surfaceMeshOut = smoothSurfaceMesh(surfaceMeshIn,numIterations); surfaceMeshShow(surfaceMeshOut,Title="Average Filter (Iterations = "+numIterations+")") end
Smooth Surface Mesh using Laplacian Filter
Smooth the surface mesh using the Laplacian filter with varying scale factor. Visualize the smooth surface meshes. Observe that the smoothing increases with the scale factor.
numIterations = 5; for scaleFactor = [0.3 0.6 0.9] surfaceMeshOut = smoothSurfaceMesh(surfaceMeshIn,numIterations,Method="Laplacian",ScaleFactor=scaleFactor); surfaceMeshShow(surfaceMeshOut,Title="Laplacian Filter (Scale Factor = "+scaleFactor+")") end
Smooth Surface Mesh using Taubin Filter
Smooth the surface mesh using the Taubin filter. Visualize the smooth surface meshes. Observe that the mesh does not shrink even after 5 iterations.
numIterations = 5; scaleFactor = [-0.62 0.6]; surfaceMeshOut = smoothSurfaceMesh(surfaceMeshIn,numIterations,Method="Taubin",ScaleFactor=scaleFactor); surfaceMeshShow(surfaceMeshOut,Title="Taubin Filter")
surfaceMeshIn — Surface mesh to smooth
Surface mesh to smooth, specified as a
numIterations — Number of iterations
Number of iterations, specified as a numeric scalar.
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
smoothSurfaceMesh(surfaceMeshIn,numIterations,Method="Laplacian") smooths the
input surface mesh using the Laplacian filter.
Method — Method for smoothing
"Average" (default) |
Method for smoothing, specified as
Average filter — Repeatedly replaces each vertex in the input surface mesh with the mean average of its neighbors, including itself. The average filter is suitable for surface meshes without any sharp features.
Laplacian filter — Repeatedly moves each adjustable vertex to the weighted average of the vertices adjacent to it. The weights assigned to neighboring vertices depend on their connectivity with the adjusted vertex. The Laplacian filter is suitable for surface meshes that have various densities of vertices in different regions.
Taubin filter — Repeatedly uses two Laplacian filters with scaling factors that have different magnitudes and signs. Unlike the average and Laplacian filters, the Taubin filter prevents mesh shrinkage.
Smoothing surface meshes over multiple iterations can result in shrinkage of the original surface mesh. Thus, the average and Laplacian filters give better results across a small number of iterations. Increasing the number of iterations can result in surface mesh shrinkage for these methods. The Taubin filter prevents surface mesh shrinkage, but it requires more iterations than the average and Laplacian filters to perform a similar level of smoothing.
ScaleFactor — Scale factor for Laplacian and Taubin filters
numeric scalar | two-element numeric vector
Scale factor for the Laplacian and Taubin filters, specified as a numeric scalar
or two-element numeric vector. A large scale factor results in more smoothing of the
surface mesh. Specify the scale factor based on the value of the
Method name-value argument.
"Laplacian"— Specify the scale factor as a scalar in the range (
1). The default value for the scale factor for the Laplacian filter is
"Taubin"— Specify the scale factor as a two-element vector, such that the two scale factors in the vector satisfy these requirements.
The absolute values of the scale factors are in the range (
One scale factor is positive and the other is negative.
The absolute value of the positive scale factor is smaller than the absolute value of the negative scale factor.
To prevent surface mesh shrinkage, the difference between the absolute values of the positive and negative scale factors must be small. The default value for the scale factor for the Taubin filter is
SmoothVertexColors — Smooth vertex colors
1 (default) |
Smooth vertex colors, specified as a logical
true to smooth the
vertex colors of the surface mesh.
Introduced in R2023a