Algorithmintro
Laplacian smoothing
Also called umbrella smoothing.
Moves each vertex toward the average of its neighbours, step by step. It removes noise but also shrinks the mesh.
- Time
- Θ(K n) worst
- Space
- Θ(n) extra
- Where
- K = the number of steps; n = the number of vertices
- Model
- Real RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- David A. Field, Gabriel Taubin, 1988
Laplacian smoothing moves every vertex of a mesh a fraction of the way toward the average of its neighbours, and repeats this step times. The average minus the vertex is the umbrella vector , the uniform graph Laplacian of the positions, so one step is , an explicit step of the diffusion . Noise is the part of the shape that changes fast from vertex to vertex, and the step damps it most. But every step also pulls a closed mesh inward, and after many steps the mesh collapses to a point. On an open mesh, the border is held fixed, and the vertices tend to the solution of a discrete Laplace equation. It costs time per step on a mesh with vertices.
In plain words
Each corner of the mesh looks at the corners joined to it, finds their middle, and steps part of the way there. A corner that sticks out of a smooth surface, because of noise, is far from the middle of its neighbours, so it moves a lot. A corner on a smooth part moves little.
All corners move at once, using the old positions, and the whole thing is repeated a few times. The surface gets smoother after each round.
The catch is that on a round surface the middle of the neighbours is always a bit inside, so every corner moves a bit inward, even where there is no noise. A ball smoothed many times gets smaller and smaller and ends as a point. Corners on the edge of an open sheet are kept still, so that the sheet does not pull in from its edges.
The problem
The input is a triangle mesh with vertex positions , its faces, a factor , a number of steps , and a set of fixed vertices, by default the border vertices of the mesh. The output is new positions with the same connectivity, smoother in the sense that the high-frequency part of the shape is damped. There is no single target shape: the result depends on and , and the user stops when the noise is gone. The Taubin smoothing and implicit fairing pages solve the same task with less shrinkage and with larger steps.
The algorithm
Let be the set of neighbours of vertex and its valence. The centroid of the neighbours is , and the umbrella vector is .
LAPLACIAN-SMOOTH(x[1 .. n], faces, λ, K, F)- 1
N ← the neighbour lists of the mesh; F ← the border vertices if not given - 2
for k ← 1 to K do - 3
for each vertex i ∉ F do - 4
c_i ← (1 / d_i) Σ_{j ∈ N(i)} x_j - 5
y_i ← x_i + λ (c_i − x_i) - 6
y_i ← x_i for each i ∈ F - 7
x ← y ▷ all vertices move at once return x
All new positions are computed from the old ones, which is a Jacobi step. In matrix form, one step on the free vertices is with
where is the adjacency matrix of the edge graph and , and is the identity on the rows of . The positions are treated one coordinate at a time, and the step uses no geometric predicate, only sums and one division per vertex. With rational coordinates and a rational , it is exact, and the code follows it with Fraction.
Example
One noisy vertex in a flat grid. Take the grid of points , , with each square cut by the diagonal from to . The four inner vertices , , , have valence 6, and the twelve border vertices are fixed. Lift to height and smooth with . The and coordinates do not move, because each inner vertex of this grid is the centroid of its six neighbours. Only the heights change.
| step | ||||
|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 |
| 1 | ||||
| 2 | ||||
| 3 |
In step 1, the neighbours of all have height 0, so . Each of has as one of its six neighbours, so its centroid has height and it moves to . In step 2, has three neighbours at and three on the border, so has height and . The bump spreads and sinks, and the heights tend to 0, the flat grid held by its border.
A closed mesh. On the octahedron with vertices , , , the four neighbours of each vertex sum to 0, so and each step with halves every position. After three steps the octahedron is of its size, with the same shape. On the icosphere with 162 vertices on the unit sphere, the measured volume after 1, 10 and 50 steps with is , and times the start. The mesh has no noise at all, and smoothing still shrinks it.
Correctness
Smoothing has no single right output, so the claims are about what each step does and where the steps lead. These are proved:
- The step is the matrix . Line L5 is , row of . So steps give , and the tests compare the code with this product exactly.
- Affine invariance. Each new position is an affine combination of old ones, with weights summing to 1, so smoothing commutes with rotations, translations and scalings, and a mesh in a plane stays in the plane.
- Fixed points. A vertex whose position is the centroid of its neighbours does not move. Every inner vertex of the regular grid above is such a vertex, by point symmetry of its six neighbours.
- A closed mesh tends to one point. With no fixed vertex, is the same after every step. If the mesh is connected and , all positions converge to the weighted centroid . This is the shrinkage, in its limit.
- An open mesh tends to a membrane. If every connected part of the mesh has a fixed vertex and , the free positions converge to the unique solution of for all , the discrete harmonic map with the uniform weights, as in a Tutte embedding.
The rate of shrinking on a given mesh is only measured, as in the example. The proofs are in the correctness file.
Proof: Each Laplacian smoothing step is the matrix S, it keeps the degree-weighted centroid, and the steps converge to a point on a closed mesh and to the harmonic membrane on a mesh with a fixed borderfull
Setup. The mesh has vertices with neighbour sets and valences . Let be the adjacency matrix of the edge graph, , and , so that is the centroid of the neighbours. is the set of fixed vertices and the set of free ones. The positions are treated one coordinate at a time, so . The factor satisfies . The algorithm stops after steps, so termination is clear; the claims are about what the steps compute.
Lemma 1 (matrix form). One pass of lines L3 to L7 maps to with for and for .
Proof. Line L4 computes from the old array , since is a separate array and line L7 copies it only after all vertices are done. Line L5 sets . Line L6 keeps the fixed vertices.
Lemma 2 (affine invariance). For an affine map of , smoothing gives of the smoothed .
Proof. By Lemma 1, each is with , or . An affine map commutes with combinations whose weights sum to 1.
Lemma 3 (the weighted centroid is kept). If , then .
Proof. . Each appears in the double sum once for each neighbour of , that is times, so the double sum is , and the total is .
Lemma 4 (spectrum). is similar to the symmetric matrix , so it has real eigenvalues and a basis of eigenvectors. Its eigenvalues lie in . If the graph is connected, the eigenvalue 1 is simple, with eigenvector .
Proof. , and is symmetric. For an eigenvector , take with largest. Then , so . If and is largest with (replace by if needed), then is the average of its neighbours, all at most , so all are equal to . Repeating this along paths shows that is constant on the connected graph, so the eigenspace of 1 is spanned by .
Theorem 1 (closed mesh). Let , the edge graph be connected, and . Then after steps every position tends, as , to .
Proof. By Lemma 1 the step is , and has the eigenvectors of with eigenvalues . By Lemma 4, , so , and since . The value 1 occurs only for , whose eigenspace is spanned by . Every other eigenvalue has absolute value less than 1. Write with in the span of the other eigenvectors. Then . The eigenvectors of are orthogonal, so those of are orthogonal in the inner product , and is -orthogonal to , that is, . Hence . This agrees with Lemma 3, which keeps along the way.
So the shrinkage is not a numerical effect: the limit is one point, for every closed connected mesh.
Lemma 5 (substochastic block). Suppose every connected part of the edge graph contains a vertex of . Let be the block of on the free vertices. Every eigenvalue of has .
Proof. is similar to the symmetric , so its eigenvalues are real. Let with and , and let be attained at . Then . So , that is, has no fixed neighbour, and every neighbour of has . Repeating this from each such reaches every free vertex of the connected part of . That part has a fixed vertex, so some free vertex on a path to it has a fixed neighbour, which contradicts .
Theorem 2 (open mesh). Under the hypothesis of Lemma 5 and , the free positions converge, as , to the unique solution of for all , with the fixed positions as given.
Proof. By Lemma 1, the free part follows with . By Lemma 5, the eigenvalues of are with , so they lie in , inside , and is diagonalizable. So the iteration converges for every start to the unique fixed point of . That equation is , which says for each free , and is invertible because 1 is not an eigenvalue of .
Claim (fixed points of one step). A free vertex with does not move in a step. On the grid of the example, every inner vertex has the neighbours , , , , which are symmetric about , so , and the flat grid is a fixed point of every step. This follows directly from line L5.
Complexity
A manifold triangle mesh with vertices has at most edges, so . Line L1 builds the neighbour lists in time from the faces. Each step does additions and one division per free vertex, in total on the real RAM, so steps take time. The extra space is the array and the lists, . With exact Fraction coordinates the numbers grow in size with , and the time per step grows too, which is why exact runs are only for tests.
The number of steps for a given effect depends on the mesh. A feature that spans edges needs about steps to be smoothed away, as for any diffusion, which is why large features take many steps and why implicit fairing uses one large stable step instead.
Properties
- A low-pass filter. For a closed mesh, write in the eigenvectors of , with eigenvalues , which play the role of frequencies. One step multiplies the part of frequency by . High frequencies, the noise, are damped most, but every frequency except is damped a little. This is Taubin's view, and the cause of the shrinkage.
- Stable only for small steps. The factor lies in for all exactly when . With , frequencies near flip sign and grow.
- Depends on the connectivity. The uniform weights ignore edge lengths and angles. On a flat but irregular mesh, , so vertices slide inside the plane: at the origin with the neighbours , , , , , one step with moves the vertex to . This tangential motion makes the triangles more regular, which is useful in remeshing, but it also distorts textures and parameterizations.
- Exact. With rational input and rational , all values are exact.
Variants and improvements
- Cotangent weights. Replace the average by with the cotangent weights. The step then follows the mean curvature normal, has no tangential drift on flat regions, and needs the weights to be recomputed after each step. Weights can be negative on obtuse triangles.
- Taubin smoothing. Alternate a step with and a step with a negative factor , so that low frequencies keep their size. See Taubin smoothing.
- Implicit steps. Solve instead, which is stable for any . See implicit fairing.
- Volume correction. Scale the mesh after each step so that its volume stays the same. This stops the collapse, but does not stop the change of shape that shrinkage causes.
- Gauss-Seidel order. Update in place, so that later vertices see the new positions. This converges faster but depends on the order of the vertices and is not symmetric.
- Tangential smoothing. Keep only the part of in the tangent plane of the vertex. The shape stays, and the vertices spread more evenly, which is the relaxation step of isotropic remeshing.
- Feature-aware weights. Lower the weight of an edge across a sharp crease, so that the crease is not rounded.
When to use it
Use it for a quick cleanup of small noise, for the relaxation of vertex positions inside a remesher, for fairing a small patch inside a fixed border, as after Liepa hole filling, and as a baseline. Do not use it for many steps on a closed shape, because the shape shrinks and loses its features. For that, use Taubin smoothing or implicit fairing. For images, the same idea is image smoothing with a box or Gaussian kernel.
Pitfalls
- Shrinkage. A closed mesh shrinks after every step, even without noise, and converges to a point. Count steps, and correct the volume or use a non-shrinking method.
- A free border. If the border vertices are not fixed, they move to the average of their neighbours, which lie on one side, and the border pulls inward.
- In-place updates by mistake. Writing into during the loop gives a Gauss-Seidel sweep whose result depends on the vertex order.
- Too large a factor. makes the highest frequencies grow or oscillate.
- Non-manifold input. A vertex where two fans meet averages over both, and can be pulled between two separate sheets.
- Sliding in flat regions. On an irregular mesh, vertices move inside the surface. If the texture coordinates or the triangle shapes must stay, use cotangent weights.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/laplacian-smoothing/. The authors are listed in prov/8BS9ES.jsonl.
"""Laplacian smoothing of a triangle mesh with the uniform (umbrella) weights.
Each step moves every free vertex a fraction lam of the way to the average of
its neighbours, all at once (a Jacobi step): x_i <- x_i + lam (c_i - x_i).
The border vertices of an open mesh are fixed by default. The coordinates can
be int, float or Fraction, so a test can follow the steps exactly.
"""
from fractions import Fraction
from typing import Iterable, Optional, Sequence
from mp2mesh import boundary_vertices, neighbours
Point = tuple
def laplacian_smoothing(points: Sequence[Sequence], faces: Sequence[Sequence[int]], lam=Fraction(1, 2),
iterations: int = 1, fixed: Optional[Iterable[int]] = None) -> list[Point]:
"""Return the points after `iterations` uniform Laplacian steps with factor lam.
fixed: the vertices that do not move. The default is the border vertices.
"""
n = len(points)
nb = neighbours(n, faces) # @line L1
stay = set(boundary_vertices(faces) if fixed is None else fixed)
x = [tuple(p) for p in points]
for _ in range(iterations): # @line L2
y = list(x) # @line L6
for i in range(n): # @line L3
if i in stay or not nb[i]:
continue
d = len(nb[i])
c = tuple(sum(x[j][k] for j in nb[i]) / d for k in range(3)) # @line L4
y[i] = tuple(x[i][k] + lam * (c[k] - x[i][k]) for k in range(3)) # @line L5
x = y # @line L7
return x
def umbrella(points: Sequence[Sequence], faces: Sequence[Sequence[int]]) -> list[Point]:
"""The uniform Laplacian U(x)_i = c_i - x_i at every vertex."""
nb = neighbours(len(points), faces)
out = []
for i, p in enumerate(points):
if not nb[i]:
out.append((0, 0, 0))
continue
d = len(nb[i])
out.append(tuple(sum(points[j][k] for j in nb[i]) / d - p[k] for k in range(3)))
return out
mp2mesh.py 252 lines
# SPDX-License-Identifier: MIT
# Shared helper of the mp2 cad pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small tools for triangle meshes, used by the mp2 pages.
A mesh is a list of points (tuples of 3 numbers) and a list of faces
(tuples of 3 vertex indices, oriented by the right-hand rule). The helper has
the adjacency, the cotangent weights and the lumped mass, a sparse conjugate
gradient solver, a dense solver, and the test meshes. It does not hold the
algorithm of any page.
"""
from math import sqrt
from typing import Sequence
Vec = tuple
# ---- vectors ----
def sub(a: Sequence, b: Sequence) -> Vec:
return tuple(x - y for x, y in zip(a, b))
def add(a: Sequence, b: Sequence) -> Vec:
return tuple(x + y for x, y in zip(a, b))
def scale(c, a: Sequence) -> Vec:
return tuple(c * x for x in a)
def dot(a: Sequence, b: Sequence):
return sum(x * y for x, y in zip(a, b))
def cross(a: Sequence, b: Sequence) -> Vec:
return (a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0])
def norm(a: Sequence) -> float:
return sqrt(dot(a, a))
# ---- adjacency ----
def edges(faces: Sequence[Sequence[int]]) -> list[tuple[int, int]]:
"""The undirected edges (i, j) with i < j, sorted."""
out = set()
for f in faces:
for k in range(3):
i, j = f[k], f[(k + 1) % 3]
out.add((min(i, j), max(i, j)))
return sorted(out)
def edge_faces(faces: Sequence[Sequence[int]]) -> dict[tuple[int, int], list[int]]:
"""For each undirected edge, the indices of the faces that contain it."""
out: dict[tuple[int, int], list[int]] = {}
for fi, f in enumerate(faces):
for k in range(3):
i, j = f[k], f[(k + 1) % 3]
out.setdefault((min(i, j), max(i, j)), []).append(fi)
return out
def neighbours(n: int, faces: Sequence[Sequence[int]]) -> list[list[int]]:
"""The sorted neighbours of each of the n vertices."""
nb: list[set[int]] = [set() for _ in range(n)]
for i, j in edges(faces):
nb[i].add(j)
nb[j].add(i)
return [sorted(s) for s in nb]
def boundary_vertices(faces: Sequence[Sequence[int]]) -> set[int]:
"""The vertices on an edge that has one face."""
out: set[int] = set()
for (i, j), fs in edge_faces(faces).items():
if len(fs) == 1:
out.update((i, j))
return out
def euler_characteristic(n: int, faces: Sequence[Sequence[int]]) -> int:
used = {v for f in faces for v in f}
return len(used) - len(edges(faces)) + len(faces)
# ---- geometry ----
def face_area(points: Sequence[Sequence[float]], f: Sequence[int]) -> float:
a, b, c = (points[v] for v in f)
return norm(cross(sub(b, a), sub(c, a))) / 2
def cot_at(p: Sequence[float], q: Sequence[float], r: Sequence[float]) -> float:
"""The cotangent of the angle at p of the triangle p, q, r."""
u, v = sub(q, p), sub(r, p)
return dot(u, v) / norm(cross(u, v))
def cotan_weights(points: Sequence[Sequence[float]], faces: Sequence[Sequence[int]]) -> dict[tuple[int, int], float]:
"""w[(i, j)] = (cot a + cot b) / 2 over the angles opposite the edge (one term on the boundary)."""
w: dict[tuple[int, int], float] = {}
for f in faces:
for k in range(3):
i, j, o = f[k], f[(k + 1) % 3], f[(k + 2) % 3]
e = (min(i, j), max(i, j))
w[e] = w.get(e, 0.0) + cot_at(points[o], points[i], points[j]) / 2
return w
def stiffness_matrix(points, faces) -> list[dict[int, float]]:
"""C = -L for the cotangent Laplacian L: C[i][j] = -w_ij, C[i][i] = sum of w_ij."""
n = len(points)
C: list[dict[int, float]] = [dict() for _ in range(n)]
for (i, j), wij in cotan_weights(points, faces).items():
C[i][j] = C[i].get(j, 0.0) - wij
C[j][i] = C[j].get(i, 0.0) - wij
C[i][i] = C[i].get(i, 0.0) + wij
C[j][j] = C[j].get(j, 0.0) + wij
return C
def lumped_mass(points, faces) -> list[float]:
"""The barycentric vertex areas: one third of the area of each face at the vertex."""
m = [0.0] * len(points)
for f in faces:
a = face_area(points, f) / 3
for v in f:
m[v] += a
return m
def signed_volume(points, faces) -> float:
"""The volume enclosed by a closed oriented mesh (outward normals give a positive value)."""
return sum(dot(points[a], cross(points[b], points[c])) for a, b, c in faces) / 6
def mean_edge_length(points, faces) -> float:
es = edges(faces)
return sum(norm(sub(points[i], points[j])) for i, j in es) / len(es)
# ---- linear algebra ----
def mat_vec(A: Sequence[dict[int, float]], x: Sequence[float]) -> list[float]:
return [sum(a * x[j] for j, a in row.items()) for row in A]
def conjugate_gradient(A, b, x0=None, tol: float = 1e-12, max_iter: int | None = None) -> list[float]:
"""Solve A x = b for a sparse symmetric positive definite A (a list of dict rows)."""
n = len(b)
x = list(x0) if x0 is not None else [0.0] * n
Ax = mat_vec(A, x)
r = [bi - ai for bi, ai in zip(b, Ax)]
p = list(r)
rr = dot(r, r)
bb = max(dot(b, b), 1e-300)
for _ in range(max_iter or 10 * n + 10):
if rr <= tol * tol * bb:
break
Ap = mat_vec(A, p)
alpha = rr / dot(p, Ap)
x = [xi + alpha * pi for xi, pi in zip(x, p)]
r = [ri - alpha * qi for ri, qi in zip(r, Ap)]
rr_new = dot(r, r)
p = [ri + (rr_new / rr) * pi for ri, pi in zip(r, p)]
rr = rr_new
return x
def solve_dense(A: Sequence[Sequence], b: Sequence) -> list:
"""Gaussian elimination with partial pivoting. Works with float or Fraction entries."""
n = len(b)
M = [list(A[i]) + [b[i]] for i in range(n)]
for c in range(n):
p = max(range(c, n), key=lambda r: abs(M[r][c]))
if M[p][c] == 0:
raise ValueError("singular matrix")
M[c], M[p] = M[p], M[c]
for r in range(c + 1, n):
f = M[r][c] / M[c][c]
if f:
for k in range(c, n + 1):
M[r][k] -= f * M[c][k]
x = [0] * n
for c in range(n - 1, -1, -1):
x[c] = (M[c][n] - sum(M[c][k] * x[k] for k in range(c + 1, n))) / M[c][c]
return x
def dense(A: Sequence[dict[int, float]]) -> list[list[float]]:
n = len(A)
return [[A[i].get(j, 0.0) for j in range(n)] for i in range(n)]
# ---- test meshes ----
def grid_mesh(m: int, n: int, h=1.0):
"""The (m+1) x (n+1) grid in the plane z = 0, each square cut by the diagonal from (i, j) to (i+1, j+1)."""
pts = [(i * h, j * h, 0 * h) for j in range(n + 1) for i in range(m + 1)]
def v(i, j):
return j * (m + 1) + i
faces = []
for j in range(n):
for i in range(m):
faces.append((v(i, j), v(i + 1, j), v(i + 1, j + 1)))
faces.append((v(i, j), v(i + 1, j + 1), v(i, j + 1)))
return pts, faces
def octahedron():
pts = [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)]
faces = [(0, 2, 4), (2, 1, 4), (1, 3, 4), (3, 0, 4), (2, 0, 5), (1, 2, 5), (3, 1, 5), (0, 3, 5)]
return pts, faces
def icosphere(level: int):
"""The icosahedron, with each triangle cut into 4 `level` times, on the unit sphere."""
t = (1 + sqrt(5)) / 2
raw = [(-1, t, 0), (1, t, 0), (-1, -t, 0), (1, -t, 0), (0, -1, t), (0, 1, t),
(0, -1, -t), (0, 1, -t), (t, 0, -1), (t, 0, 1), (-t, 0, -1), (-t, 0, 1)]
pts = [scale(1 / norm(p), p) for p in raw]
faces = [(0, 11, 5), (0, 5, 1), (0, 1, 7), (0, 7, 10), (0, 10, 11), (1, 5, 9), (5, 11, 4),
(11, 10, 2), (10, 7, 6), (7, 1, 8), (3, 9, 4), (3, 4, 2), (3, 2, 6), (3, 6, 8),
(3, 8, 9), (4, 9, 5), (2, 4, 11), (6, 2, 10), (8, 6, 7), (9, 8, 1)]
for _ in range(level):
mid: dict[tuple[int, int], int] = {}
def m(i, j):
key = (min(i, j), max(i, j))
if key not in mid:
p = scale(0.5, add(pts[i], pts[j]))
pts.append(scale(1 / norm(p), p))
mid[key] = len(pts) - 1
return mid[key]
new = []
for a, b, c in faces:
ab, bc, ca = m(a, b), m(b, c), m(c, a)
new += [(a, ab, ca), (b, bc, ab), (c, ca, bc), (ab, bc, ca)]
faces = new
return pts, faces
test_laplacian_smoothing.py 126 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/laplacian-smoothing/. The authors are listed in prov/8BS9ES.jsonl.
import random
from fractions import Fraction as Fr
from laplacian_smoothing import laplacian_smoothing, umbrella
from mp2mesh import boundary_vertices, grid_mesh, icosphere, neighbours, norm, octahedron, signed_volume
def exact(points):
return [tuple(Fr(c) for c in p) for p in points]
def noisy_grid(m, n, rng, den=8):
p, f = grid_mesh(m, n)
q = [(Fr(x) + Fr(rng.randrange(-2, 3), den), Fr(y) + Fr(rng.randrange(-2, 3), den), Fr(rng.randrange(-4, 5), den))
for x, y, _ in p]
return q, f
# ---- brute force: the step as a dense matrix, applied K times ----
def matrix_smoothing(points, faces, lam, iterations, fixed):
n = len(points)
nb = neighbours(n, faces)
S = [[Fr(0)] * n for _ in range(n)]
for i in range(n):
if i in fixed or not nb[i]:
S[i][i] = Fr(1)
continue
S[i][i] = 1 - lam
for j in nb[i]:
S[i][j] += lam / len(nb[i])
x = [list(p) for p in points]
for _ in range(iterations):
x = [[sum(S[i][j] * x[j][k] for j in range(n)) for k in range(3)] for i in range(n)]
return [tuple(r) for r in x]
def test_example_trace() -> None:
p, f = grid_mesh(3, 3)
p = exact(p)
p[5] = (Fr(1), Fr(1), Fr(1))
x1 = laplacian_smoothing(p, f, Fr(1, 2), 1)
assert [x1[i][2] for i in (5, 6, 9, 10)] == [Fr(1, 2), Fr(1, 12), Fr(1, 12), Fr(1, 12)]
x2 = laplacian_smoothing(x1, f, Fr(1, 2), 1)
assert [x2[i][2] for i in (5, 6, 9, 10)] == [Fr(13, 48), Fr(13, 144), Fr(13, 144), Fr(7, 72)]
assert laplacian_smoothing(p, f, Fr(1, 2), 2) == x2
def test_octahedron_halves() -> None:
p, f = octahedron()
p = exact(p)
x = laplacian_smoothing(p, f, Fr(1, 2), 3)
assert x == [tuple(c / 8 for c in q) for q in p]
def test_against_matrix_form() -> None:
rng = random.Random(7)
for _ in range(20):
p, f = noisy_grid(rng.randrange(1, 4), rng.randrange(1, 4), rng)
lam = Fr(rng.randrange(1, 10), 10)
k = rng.randrange(1, 4)
fixed = boundary_vertices(f)
assert laplacian_smoothing(p, f, lam, k) == matrix_smoothing(p, f, lam, k, fixed)
none = set()
assert laplacian_smoothing(p, f, lam, k, fixed=none) == matrix_smoothing(p, f, lam, k, none)
def test_border_fixed() -> None:
rng = random.Random(3)
p, f = noisy_grid(4, 3, rng)
x = laplacian_smoothing(p, f, Fr(1, 3), 5)
for v in boundary_vertices(f):
assert x[v] == p[v]
def test_flat_regular_grid_is_fixed() -> None:
p, f = grid_mesh(5, 4)
p = exact(p)
assert laplacian_smoothing(p, f, Fr(1, 2), 4) == p
assert all(u == (0, 0, 0) for i, u in enumerate(umbrella(p, f)) if i not in boundary_vertices(f))
def test_flat_irregular_fan_drifts() -> None:
pts = exact([(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (-1, 0, 0), (0, -1, 0)])
fs = [(0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 5), (0, 5, 1)]
x = laplacian_smoothing(pts, fs, Fr(1, 2), 1)
assert x[0] == (Fr(1, 10), Fr(1, 10), 0) # moves inside a flat region
assert all(q[2] == 0 for q in x) # but stays in the plane
def test_degree_weighted_centroid_is_conserved() -> None:
rng = random.Random(11)
p, f = icosphere(1)
p = [tuple(Fr(round(c * 64)) / 64 + Fr(rng.randrange(-3, 4), 256) for c in q) for q in p]
nb = neighbours(len(p), f)
def moment(x):
return tuple(sum(len(nb[i]) * x[i][k] for i in range(len(x))) for k in range(3))
m0 = moment(p)
x = p
for _ in range(3):
x = laplacian_smoothing(x, f, Fr(2, 5), 1)
assert moment(x) == m0
def test_closed_mesh_shrinks_to_a_point() -> None:
p, f = icosphere(2)
v0 = signed_volume(p, f)
prev = v0
x = p
for _ in range(10):
x = laplacian_smoothing(x, f, 0.5, 5)
v = signed_volume(x, f)
assert v < prev
prev = v
assert prev / v0 < 0.05 # measured: 0.034 after 50 steps
x = laplacian_smoothing(x, f, 0.5, 300)
assert max(norm(q) for q in x) < 1e-3 # the centroid of the sphere is the origin
p, f = icosphere(1)
x = laplacian_smoothing(p, f, 0.5, 200)
assert max(norm(q) for q in x) < 1e-7 # measured: 2e-8
History
Moving each node of a finite element mesh to the centroid of its neighbours was in use in mesh generation before 1988, and Field's paper of that year, which studies how it changes the angles of a Delaunay triangulation in the plane, is the usual reference. In 1995 Taubin applied the same step to the vertices of a surface mesh, showed that it is a filter on the eigenvectors of the Laplacian with transfer function , explained the shrinkage, and fixed it with a second step of negative factor. In 1999 Desbrun, Meyer, Schröder and Barr replaced the uniform weights by cotangent weights and the explicit step by an implicit one, the basis of most later smoothing methods.
References
- David A. Field, Laplacian smoothing and Delaunay triangulations, Communications in Applied Numerical Methods 4(6), 1988, 709 to 712, the smoothing step that moves each node to the centroid of its neighbours, and its effect on the angles of a planar triangulation
- Gabriel Taubin, A signal processing approach to fair surface design, Proceedings of SIGGRAPH 95, 1995, 351 to 358, the Laplacian smoothing step as a filter on the eigenvectors of the Laplacian, its transfer function 1 - lambda k, and the shrinkage it causes
- Mario Botsch, Leif Kobbelt, Mark Pauly, Pierre Alliez and Bruno Lévy, Polygon Mesh Processing, AK Peters, 2010, Chapter 4, Smoothing (Laplacian smoothing as diffusion with an explicit step, uniform and cotangent weights, shrinkage)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 8BS9ES Edit this page History Report an error Markdown