Algorithmcore
Taubin smoothing
Also called lambda-mu smoothing.
Alternates a shrinking Laplacian step with factor lambda and an expanding one with factor mu < -lambda, a low-pass filter that smooths without shrinking.
- Time
- Θ(K n) worst
- Space
- Θ(n) extra
- Where
- K = the number of passes; n = the number of vertices
- Model
- Real RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Gabriel Taubin, 1995
Taubin smoothing repeats a pass of two Laplacian smoothing steps, , first with a positive factor , which shrinks, and then with a negative factor , which inflates. is the umbrella vector, the centroid of the neighbours of vertex minus . On the eigenvectors of the uniform Laplacian, a pass multiplies the part of frequency by . This factor is about 1 for low frequencies, the overall shape, and well below 1 for high frequencies, the noise. So the method is a low-pass filter, and a closed mesh keeps its size, where plain Laplacian smoothing shrinks it to a point. A pass costs time.
In plain words
Plain smoothing moves each corner a bit toward the middle of its neighbours. That removes bumps, but it also pulls a round shape inward, a little at every step.
Taubin's idea is to follow each such step by a step the other way, slightly larger, which pushes each corner away from the middle of its neighbours. A large bump, such as the round shape itself, is pulled in by the first step and pushed back out by the second, and stays about the same. A small sharp bump is cut down a lot by the first step. The second step then pushes back only a little of it, so the bump stays small. After a few pairs of steps the noise is gone and the shape has kept its size.
The problem
The input is a triangle mesh with vertex positions , two factors and , a number of passes , and a set of fixed vertices, by default the border vertices. The output is new positions with the same connectivity, with the high frequencies damped and the low frequencies kept. As for Laplacian smoothing, there is no single target shape. The user picks , and .
The algorithm
Let be the neighbours of vertex , , and .
TAUBIN-SMOOTH(x[1 .. n], faces, λ, μ, K, F)- 1
require λ > 0 and μ < −λ; N ← the neighbour lists; F ← the border vertices if not given - 2
for k ← 1 to K do - 3
for each factor f in (λ, μ) do - 4
for each vertex i ∉ F do y_i ← x_i + f (c_i − x_i) ▷ c_i from the old x - 5
y_i ← x_i for each i ∈ F - 6
x ← y return x
Write for the uniform Laplacian of the edge graph, with the adjacency matrix and , so that . On a closed mesh, one pass is
has real eigenvalues , the frequencies, and a basis of eigenvectors. A pass multiplies the part of along an eigenvector of frequency by the transfer function
It has , and again at the pass-band frequency
which is positive because . Values of from about to are the usual choice. With and , as in the code, .
Example
The six modes of a hexagon. Take a closed polygon with 6 vertices, the graph of a cycle, where each vertex has the two neighbours . The eigenvectors of are with frequencies , that is for . Use one coordinate and , .
For , . At vertex 0 the neighbours average to , so the step gives . All other vertices scale by the same factor . The step then scales by , and ends at . For , , the noisiest shape. The step gives and the step multiplies by , so .
| , one Taubin pass | , two Laplacian steps | |
|---|---|---|
| 0 | 1 | 1 |
| 2 |
Both damp the noise, but the two Laplacian steps also cut the low mode by 30 percent, and the Taubin pass cuts it by 2 percent. On a longer cycle the lowest modes have near 0 and are kept almost exactly.
A sphere. On the icosphere with 162 vertices on the unit sphere, 10 Taubin passes with , change the volume by the measured factor . Twenty Laplacian steps with , the same work, give . After 50 passes the factors are and .
Correctness
These are proved in the correctness file:
- A pass is the matrix product. Lines L3 to L6 compute on the free rows and keep the fixed rows. The tests compare the code with the product of the two step matrices exactly.
- The transfer function. On a closed mesh, an eigenvector of with frequency is multiplied by in each pass. The tests check this exactly on the hexagon.
- The shape of . For and , , for , and decreases on . So every frequency above is damped and the method is stable, exactly when . The largest gain is , which is for the factors above.
- Affine invariance and the weighted centroid. Each step is an affine combination with weights summing to 1, and on a closed mesh each step keeps , as for Laplacian smoothing.
The gain above 1 means that Taubin smoothing does not converge as grows. The frequencies in grow slowly, which is why the measured volume of the sphere grows by 3 percent in 50 passes. The method is a filter used for a fixed small , not an iteration to a limit. The volume figures above are measured, not proved.
Proof: A Taubin pass is the product of two Laplacian step matrices, it scales each eigenvector of the uniform Laplacian by (1 - lambda k)(1 - mu k), and this transfer function keeps the low frequencies and damps the othersfull
Setup. The mesh graph has vertices , neighbour sets , valences , adjacency matrix , and . Let . is the set of fixed vertices. The positions are treated one coordinate at a time. The factors satisfy and , which line L1 checks. The loop runs passes of two steps each, so the algorithm stops; the claims are about what it computes.
Lemma 1 (matrix form). For a factor , lines L4 to L6 map to , where row of is row of for and row of for . One pass maps to .
Proof. Line L4 uses the old array for every , since is separate until line L6. For , . Line L5 keeps the fixed rows. Line L3 applies the step with and then the step with .
Lemma 2 (the steps commute). .
Proof. Let be with the rows of set to zero. Then , and two polynomials in the same matrix commute.
Lemma 3 (spectrum). is similar to the symmetric matrix , so it has real eigenvalues and a basis of eigenvectors. The eigenvalues lie in , and has the eigenvector .
Proof. . The eigenvalues of lie in : for and with largest, . So the eigenvalues of lie in , and because each row of sums to 1.
Theorem 1 (transfer function). Let . If , then one pass maps to with . For a general in an eigenvector basis, passes give .
Proof. With , , so and . The general case follows by linearity.
Theorem 2 (shape of the transfer function). Let , and . Then:
- , and .
- for , with the largest value at .
- is strictly decreasing on , so for .
- for all if and only if .
Proof. . Both and , so . Expand , which gives (1). Since , is a parabola that opens downward with roots of at and . So between them, its top is at the midpoint , and . That is (2) and (3). For (4), on the function decreases from 1, so its values lie in , and they all have absolute value less than 1 exactly when .
Corollary (low-pass filter). On a closed mesh with , the parts of with frequency in tend to 0 as grows, the part with , the weighted centroid, stays, and the parts with grow by at most the factor . So Taubin smoothing is not a convergent iteration. It is used for a fixed small , and then the low band is kept up to a factor near 1.
Proof. Theorems 1 and 2 and Lemma 3. For , , so .
Lemma 4 (the weighted centroid). If , each step keeps , for any factor .
Proof. , and the double sum counts once for each of its neighbours.
Lemma 5 (affine invariance). Each new position is with , so smoothing commutes with every affine map of .
Proof. Row of sums to or is a row of , and products of such matrices have rows that sum to 1.
What is measured. The volume changes of the icosphere in the example, after 10 passes and after 50, are measured. They agree with the corollary: the sphere is mostly made of low frequencies, which are kept or grow slightly.
Complexity
The neighbour lists take time to build. Each pass does two Laplacian steps, each with additions and one division per free vertex, so passes take time on the real RAM. The extra space is the array and the lists, . The cost is twice that of Laplacian steps.
Properties
- A polynomial filter. passes apply the polynomial of degree to the spectrum of , without computing any eigenvector. This is a finite impulse response filter on the mesh graph.
- No shrinkage in the low band. Frequencies below are kept or very slightly amplified. Plain Laplacian smoothing damps every nonzero frequency.
- Linear. The result is a linear function of the input positions, so noise added to a shape is filtered on its own. A test checks this exactly on a cycle.
- Exact. With rational input and rational factors, all values are exact.
- Connectivity-dependent. With the uniform weights, the frequencies depend on the graph, not on the geometry, and flat irregular regions drift inside the plane.
Variants and improvements
- Other weights. Use the cotangent weights, or Fujiwara's inverse edge-length weights, in place of the uniform average. The spectral analysis then holds for the generalized eigenproblem of the weighted Laplacian.
- Other polynomials. Taubin, Zhang and Golub (1996) designed polynomial low-pass filters of higher degree with a sharper cut-off than , evaluated with the recurrence of the Chebyshev polynomials. The Butterworth filter is a 1-D analogue.
- Implicit steps. Implicit fairing solves a linear system per step and is stable for any step size, at a higher cost per step.
- Curves. The same two steps smooth a closed polygon, as in the hexagon example, and any graph with positions.
When to use it
Use it to remove noise from a scanned or reconstructed mesh without changing its size, when a fast explicit method is wanted and the noise is at the scale of a few edges. It is the default non-shrinking smoother in many mesh libraries. Use implicit fairing when the mesh is irregular and the geometry should decide the smoothing, and Laplacian smoothing when shrinking does not matter or the border is fixed and close.
Pitfalls
- too close to . Then is near 0 and almost everything is damped, as in plain smoothing. If is much larger than , is large and the low band grows.
- Too many passes. The gain above 1 in makes the low frequencies grow. Hundreds of passes inflate the mesh slowly.
- too large. If , then gives , and the highest frequencies grow with alternating sign.
- Wrong order of steps. The two step matrices commute, so the order does not change the linear map. But doing all steps first and then all steps can lose precision in floating point, because the intermediate shape is tiny.
- A free border. On an open mesh without fixed vertices, the border moves inward in the step and outward in the step, and does not stay where it was.
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
# 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
taubin_smoothing.py 57 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/taubin-smoothing/. The authors are listed in prov/Y17GAM.jsonl.
"""Taubin's lambda-mu smoothing (SIGGRAPH 1995) with the uniform weights.
Each pass does two Laplacian steps, x <- x + f (c - x), first with the
shrinking factor f = lam > 0 and then with the inflating factor f = mu < -lam,
where c_i is the centroid of the neighbours of vertex i. A frequency k of
the graph Laplacian I - D^-1 A is multiplied by (1 - lam k)(1 - mu k) per pass.
The steps work on any graph, given by its neighbour lists, so that a test can
use a cycle, whose eigenvectors are known.
"""
from fractions import Fraction
from typing import Iterable, Optional, Sequence
from mp2mesh import boundary_vertices, neighbours
Point = tuple
def taubin_graph(points: Sequence[Sequence], nb: Sequence[Sequence[int]], lam, mu, passes: int,
fixed: Iterable[int] = ()) -> list[Point]:
"""Taubin smoothing on a graph with neighbour lists nb."""
stay = set(fixed)
x = [tuple(p) for p in points]
for _ in range(passes): # @line L2
for f in (lam, mu): # @line L3
y = list(x) # @line L5
for i in range(len(x)): # @line L4
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(len(x[i])))
y[i] = tuple(x[i][k] + f * (c[k] - x[i][k]) for k in range(len(x[i])))
x = y # @line L6
return x
def taubin_smoothing(points: Sequence[Sequence], faces: Sequence[Sequence[int]], lam=Fraction(33, 100),
mu=Fraction(-34, 100), passes: int = 1, fixed: Optional[Iterable[int]] = None) -> list[Point]:
"""Taubin smoothing of a triangle mesh. The border vertices are fixed unless `fixed` is given."""
if not (lam > 0 and mu < -lam):
raise ValueError("need lam > 0 and mu < -lam")
nb = neighbours(len(points), faces) # @line L1
stay = boundary_vertices(faces) if fixed is None else set(fixed)
return taubin_graph(points, nb, lam, mu, passes, stay)
def transfer(k, lam, mu):
"""The factor (1 - lam k)(1 - mu k) of one pass on the frequency k."""
return (1 - lam * k) * (1 - mu * k)
def pass_band(lam, mu):
"""The frequency k_PB = 1/lam + 1/mu > 0 where the transfer function is 1 again."""
return 1 / lam + 1 / mu
test_taubin_smoothing.py 144 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/taubin-smoothing/. The authors are listed in prov/Y17GAM.jsonl.
import random
from fractions import Fraction as Fr
from mp2mesh import boundary_vertices, grid_mesh, icosphere, neighbours, signed_volume
from taubin_smoothing import pass_band, taubin_graph, taubin_smoothing, transfer
LAM, MU = Fr(33, 100), Fr(-34, 100)
# The hexagon modes cos(pi m i / 3), m = 0, 1, 2, 3, have the frequencies k = 1 - cos(pi m / 3).
HEX_MODES = {
0: ([1, 1, 1, 1, 1, 1], Fr(0)),
1: ([1, Fr(1, 2), Fr(-1, 2), -1, Fr(-1, 2), Fr(1, 2)], Fr(1, 2)),
2: ([1, Fr(-1, 2), Fr(-1, 2), 1, Fr(-1, 2), Fr(-1, 2)], Fr(3, 2)),
3: ([1, -1, 1, -1, 1, -1], Fr(2)),
}
def cycle(n):
return [[(i - 1) % n, (i + 1) % n] for i in range(n)]
# ---- brute force: the product of the two step matrices, as dense matrices ----
def step_matrix(nb, f, fixed):
n = len(nb)
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 - f
for j in nb[i]:
S[i][j] += f / len(nb[i])
return S
def matmul(A, B):
n = len(A)
return [[sum(A[i][k] * B[k][j] for k in range(n)) for j in range(n)] for i in range(n)]
def matrix_taubin(points, nb, lam, mu, passes, fixed):
T = matmul(step_matrix(nb, mu, fixed), step_matrix(nb, lam, fixed))
x = [list(p) for p in points]
d = len(points[0])
for _ in range(passes):
x = [[sum(T[i][j] * x[j][k] for j in range(len(x))) for k in range(d)] for i in range(len(x))]
return [tuple(r) for r in x]
def test_hexagon_modes_are_scaled_by_the_transfer_function() -> None:
assert transfer(Fr(1, 2), LAM, MU) == Fr(19539, 20000)
assert transfer(Fr(3, 2), LAM, MU) == Fr(15251, 20000)
assert transfer(Fr(2), LAM, MU) == Fr(357, 625)
for m, (v, k) in HEX_MODES.items():
x = [(Fr(c),) for c in v]
for passes in (1, 2, 3):
y = taubin_graph(x, cycle(6), LAM, MU, passes)
g = transfer(k, LAM, MU) ** passes
assert y == [(g * c[0],) for c in x]
def test_example_trace() -> None:
x = [(Fr(c),) for c in HEX_MODES[1][0]]
assert taubin_graph(x, cycle(6), LAM, 0, 1)[0] == (Fr(167, 200),)
assert taubin_graph(x, cycle(6), LAM, MU, 1)[0] == (Fr(19539, 20000),)
x = [(Fr(c),) for c in HEX_MODES[3][0]]
assert taubin_graph(x, cycle(6), LAM, 0, 1)[0] == (Fr(17, 50),)
assert taubin_graph(x, cycle(6), LAM, MU, 1)[0] == (Fr(357, 625),)
def test_against_matrix_product() -> None:
rng = random.Random(17)
for _ in range(12):
p, f = grid_mesh(rng.randrange(1, 4), rng.randrange(1, 4))
p = [(Fr(a) + Fr(rng.randrange(-2, 3), 8), Fr(b) + Fr(rng.randrange(-2, 3), 8), Fr(rng.randrange(-4, 5), 8))
for a, b, _ in p]
lam = Fr(rng.randrange(1, 9), 10)
mu = -lam - Fr(rng.randrange(1, 5), 100)
k = rng.randrange(1, 3)
nb = neighbours(len(p), f)
fixed = boundary_vertices(f)
assert taubin_smoothing(p, f, lam, mu, k) == matrix_taubin(p, nb, lam, mu, k, fixed)
assert taubin_smoothing(p, f, lam, mu, k, fixed=()) == matrix_taubin(p, nb, lam, mu, k, set())
def test_border_fixed() -> None:
rng = random.Random(4)
p, f = grid_mesh(4, 3)
p = [(Fr(a), Fr(b), Fr(rng.randrange(-4, 5), 8)) for a, b, _ in p]
x = taubin_smoothing(p, f, passes=4)
for v in boundary_vertices(f):
assert x[v] == p[v]
def test_pass_band() -> None:
kpb = pass_band(LAM, MU)
assert kpb == Fr(50, 561)
assert transfer(kpb, LAM, MU) == 1 and transfer(0, LAM, MU) == 1
for i in range(1, 201):
k = Fr(i, 100)
g = transfer(k, LAM, MU)
if k < kpb:
assert 1 < g < Fr(10003, 10000) # a slight gain on the lowest frequencies
else:
assert -1 < g < 1 # damped, and stable up to k = 2
def test_shrinks_much_less_than_laplacian() -> None:
p, f = icosphere(2)
v0 = signed_volume(p, f)
x = taubin_smoothing(p, f, 0.33, -0.34, 10)
assert 0.99 < signed_volume(x, f) / v0 < 1.02 # measured: 1.0064
nb = neighbours(len(p), f)
y = taubin_graph(p, nb, 0.33, 0.0, 20) # 20 plain Laplacian steps, the same work
assert signed_volume(y, f) / v0 < 0.5 # measured: 0.409
def test_high_frequency_noise_is_removed() -> None:
n = 12
rng = random.Random(9)
base = [(Fr(rng.randrange(-8, 9), 8),) for _ in range(n)]
smooth = taubin_graph(base, cycle(n), LAM, MU, 0)
alt = [(Fr((-1) ** i, 10),) for i in range(n)]
x = [(a[0] + b[0],) for a, b in zip(base, alt)]
y = taubin_graph(x, cycle(n), LAM, MU, 3)
z = taubin_graph(smooth, cycle(n), LAM, MU, 3)
# linearity: the result is the smoothed base plus the alternating mode times f(2)^3
g = transfer(Fr(2), LAM, MU) ** 3
assert y == [(a[0] + g * b[0],) for a, b in zip(z, alt)]
def test_bad_parameters() -> None:
p, f = grid_mesh(1, 1)
for lam, mu in ((Fr(1, 3), Fr(-1, 3)), (Fr(-1, 3), Fr(-1, 2)), (Fr(1, 3), Fr(1, 2))):
try:
taubin_smoothing(p, f, lam, mu)
except ValueError:
continue
raise AssertionError("bad parameters were accepted")
History
Taubin published the method in 1995, in a SIGGRAPH paper on fair surface design and in an ICCV paper on curve and surface smoothing without shrinkage, while he was at IBM. He viewed the vertex positions as a signal on the mesh graph, the eigenvectors of the Laplacian as its frequencies, and plain Laplacian smoothing as a filter with transfer function . The second step with a negative factor gave a low-pass filter. In 1996 Taubin, Zhang and Golub designed sharper polynomial filters, and in 1999 Desbrun, Meyer, Schröder and Barr replaced the explicit steps by implicit fairing with cotangent weights.
References
- Gabriel Taubin, A signal processing approach to fair surface design, Proceedings of SIGGRAPH 95, 1995, 351 to 358, the lambda-mu algorithm, its transfer function (1 - lambda k)(1 - mu k), and the pass-band frequency 1/lambda + 1/mu
- Gabriel Taubin, Curve and surface smoothing without shrinkage, Proceedings of the Fifth International Conference on Computer Vision (ICCV), 1995, 852 to 857, the same two-step filter for curves and surfaces, with the analysis of the shrinkage of plain Laplacian smoothing
- Mario Botsch, Leif Kobbelt, Mark Pauly, Pierre Alliez and Bruno Lévy, Polygon Mesh Processing, AK Peters, 2010, Chapter 4, Smoothing (the spectral view of Laplacian smoothing and the lambda-mu filter)
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 Y17GAM Edit this page History Report an error Markdown