Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Triangle meshes: smoothing, decimation and slicing

ProblemRemove noise from a triangle mesh without shrinking it, reduce its triangle count while keeping its shape, and cut it with planes into contours
Devised byLeonard Herrmann (1976), Laplacian smoothing; Gabriel Taubin (1995), λ|μ smoothing; Michael Garland and Paul Heckbert (1997), quadric error decimation
AccuracyTaubin smoothing keeps the mean radius of a noisy sphere within 0.1%; decimation to 2000 of 9216 triangles stays within 0.003 of a torus of tube radius 0.4; slices match the exact lengths to the mesh’s own discretisation error (tables below)
CostSmoothing per iteration; decimation ; slicing per plane
Read firstGeometric types: points, vectors, shapes and shared tables
APIlaplacian_smoothing, taubin_smoothing, decimate, vertex_neighbours, boundary_vertices, slice_mesh, slice_mesh_levels, Contour (length, simplified)

Overview

Surfaces from 3D scanners, medical imaging and simulations arrive as triangle meshes: a list of vertex positions and a list of triangles indexing them. Meshes from measurement are noisy, often far denser than needed, and must be turned into other forms for manufacturing. This entry covers three operations on such indexed meshes. Smoothing moves each vertex towards its neighbours to remove noise. Decimation collapses edges to cut the triangle count while keeping the shape. Slicing cuts the mesh with a plane into closed contours, which is the first step of 3D printing and of cross-sectional views.

The functions take plain slices of [f64; 3] vertices and [usize; 3] triangles, rather than the table-based mesh types, so they work on data from any source.

Where it is used

Meshes come from scanners, simulations and design tools, and they are rarely ready for use.

  • 3-D scanning. Smoothing removes scanner noise without shrinking the object; decimation reduces millions of triangles to a model a phone can render.
  • Simulation. A coarser mesh makes a finite-element or fluid calculation affordable.
  • 3-D printing. Slicing a mesh at a series of heights gives the layer outlines that a printer follows.
  • Medical imaging. Surfaces extracted from CT and MRI volumes are cleaned and simplified before analysis.

History

Leonard Herrmann (1976) smoothed finite-element meshes by moving each node to the average of its neighbours. On closed surfaces that process shrinks the shape towards a point. Gabriel Taubin (1995) explained smoothing as low-pass filtering of the surface signal and removed the shrinkage by alternating a shrinking and an inflating step. Mesh simplification grew with laser scanning in the 1990s. Hoppe’s progressive meshes (1996) used edge collapses, and Michael Garland and Paul Heckbert (1997) made them fast with quadric error metrics, still the standard in modelling tools. Slicing is the core of the STL-based 3D-printing pipeline that followed Chuck Hull’s stereolithography (1986).

The idea

Laplacian and Taubin smoothing

The umbrella operator at vertex is the vector from the vertex to the mean of its neighbours,

A Laplacian step moves every vertex by with . On a mesh the umbrella operator acts like a second derivative. Each step damps a surface wave of frequency by a factor , where runs from 0 (a uniform shift) up to 2 (alternating vertices). High frequencies, the noise, die quickly. The low frequencies that make up the overall shape are damped too, only more slowly, so a closed surface shrinks.

Taubin’s method follows each step with a step . One pair multiplies frequency by . That is 1 at and also at the pass-band frequency (0.11 for the usual , ). It stays close to 1 in between, and falls off above. The result is a low-pass filter that removes noise but leaves the overall shape, and its size, nearly alone.

Figure 24.10. Smoothing.

spheremean radiusrms deviation from it
noisy (4% radial noise)0.99950.0403
Laplacian, 20 steps0.97150.0040
Taubin, 20 steps1.00110.0122
Laplacian, 60 steps0.91800.0042
Taubin, 60 steps1.00450.0098

Figure 24.11. Smoothing curves.

Laplacian smoothing removes more roughness, because it also flattens the bumps whose wavelength is several triangles, but the sphere keeps shrinking: by 3% after 20 steps and 8% after 60. Taubin’s sphere keeps its radius to 0.1% and stays a little lumpy, since long-wavelength noise is in its pass band.

Quadric error decimation

Collapsing an edge merges its two vertices into one and removes the two triangles on the edge. Garland and Heckbert measure the error of placing the merged vertex at by the sum of squared distances from to the planes of the original triangles around and . For a plane with unit , the squared distance is , where and with . Sums of planes are sums of these quadrics, so each vertex carries one matrix, and a collapse adds two. The best position minimises the quadratic form, which takes solving a linear system.

Edges wait in a priority queue ordered by error, and the cheapest is collapsed first. In the library each plane is weighted by its triangle’s area. A collapse is skipped if it would flip a triangle’s normal or create a non-manifold surface (the link condition). Boundary vertices never move, so open edges stay where they were.

Figure 24.12. Decimation.

trianglesverticeslargest vertex distance from the toruslargest centroid distancevolume errortime
921646083.3e-161.4e-3-0.36%—
200010002.6e-34.8e-3-0.53%8.2 ms
5002501.2e-21.8e-2-1.58%9.6 ms
150753.8e-25.2e-2-5.43%9.9 ms

The vertices of the full mesh lie exactly on the torus, but its flat triangles fall short of it by up to 0.0014 in between, which is why its volume is 0.36% low. Decimation to 2000 triangles roughly triples that error. At 150 triangles the torus is still recognisable.

Slicing

A plane cuts each triangle it crosses along a segment, between the two points where the triangle’s edges pass through the plane. Chaining the segments end to end, by matching their endpoints, gives the contours: closed loops for a closed surface. A vertex exactly on the plane (within a tolerance) counts as a crossing. An edge lying in the plane is reported by both of its triangles and is kept once. Without that rule, a plane through a ring of vertices produces duplicate segments that chain into hundreds of tiny loops.

Figure 24.13. Slices.

Every horizontal cut of a torus with radii and is two circles of radii , so the total length is at every height:

Table 24.6. Contours from slicing a torus at several heights.

height zcontoursall closedtotal lengthrelative to 4πR
-0.352true12.56581-4.46e-5
-0.202true12.56581-4.46e-5
-0.052true12.56581-4.46e-5
+0.102true12.56581-4.46e-5
+0.252true12.56581-4.46e-5
+0.382true12.56581-4.46e-5

The relative error is that of the mesh itself: a regular 192-gon is shorter than its circumscribed circle by the factor . The plane at passes exactly through a ring of vertices.

Algorithm

Smoothing.

  1. From the list of triangles, build for each vertex the set of its neighbours (the vertices it shares an edge with).
  2. For each step: compute the umbrella vector of every vertex from the current positions; then move every free vertex by the step’s factor times its vector. Computing all the vectors before moving any vertex makes the result independent of the order of the vertices.
  3. Laplacian smoothing uses the factor at every step. Taubin smoothing alternates and .

Each step costs time proportional to the number of edges.

Decimation to a target number of triangles.

  1. Quadrics. For each triangle, form the quadric of its plane, weighted by its area, and add it to the quadrics of its three vertices.
  2. Costs. For each edge, add the quadrics of its two ends, find the position that minimises the sum (or use the midpoint of the edge if the system is singular), and push the edge on a min-heap with the error at that position as its key.
  3. Collapse. Pop the cheapest edge. Skip it if it is stale (one of its ends has since been merged or its cost changed), or if the collapse would flip a triangle’s normal or break the link condition. Otherwise merge its two vertices at the optimal position, add their quadrics, remove the two triangles on the edge, and push the edges of the merged vertex with their new costs.
  4. Repeat step 3 until the target is reached or the heap is empty.
  5. Compact. Remove the unused vertices and renumber the triangles.

Slicing by a plane.

  1. Compute the signed distance of every vertex from the plane.
  2. For each triangle whose vertices are not all on one side, find the two points where its edges cross the plane, by linear interpolation of the distances, and record the segment between them.
  3. Remove duplicate segments (from edges lying in the plane).
  4. Chain the segments: snap their endpoints to a grid of the tolerance, so that endpoints that should coincide do, and follow each segment to the one that shares its end, until each chain closes or runs out.

Implementation

fn umbrella_step(vertices: &mut [V3], neighbours: &[BTreeSet<usize>], fixed: &[bool], factor: f64) {
    let old = vertices.to_vec();
    for (i, v) in vertices.iter_mut().enumerate() {
        if fixed[i] || neighbours[i].is_empty() {
            continue;
        }
        let k = neighbours[i].len() as f64;
        for d in 0..3 {
            let mean = neighbours[i].iter().map(|&j| old[j][d]).sum::<f64>() / k;
            v[d] += factor * (mean - old[i][d]);
        }
    }
}
pub fn slice_mesh(vertices: &[[f64; 3]], triangles: &[[usize; 3]], plane_point: [f64; 3], normal: [f64; 3], tol: f64) -> Vec<Contour> {
    let tol = tol.max(f64::MIN_POSITIVE);
    // A mesh edge lying in the plane is reported by both triangles that share it; keep one copy.
    let key = |p: [f64; 3]| -> (i64, i64, i64) { ((p[0] / tol).round() as i64, (p[1] / tol).round() as i64, (p[2] / tol).round() as i64) };
    let mut seen = std::collections::HashSet::new();
    let segments: Vec<([f64; 3], [f64; 3])> = triangles
        .iter()
        .filter_map(|t| {
            let (a, b, c) = (*vertices.get(t[0])?, *vertices.get(t[1])?, *vertices.get(t[2])?);
            triangle_plane(a, b, c, plane_point, normal, tol)
        })
        .filter(|&(p, q)| {
            let (kp, kq) = (key(p), key(q));
            seen.insert(if kp <= kq { (kp, kq) } else { (kq, kp) })
        })
        .collect();
    chain_segments(&segments, tol)
}
  • Smoothing can hold boundary vertices fixed (keep_boundary), so open patches keep their outline.
  • decimate returns new, compacted vertex and triangle arrays; the target is approximate, since collapses that would damage the surface are skipped.
  • slice_mesh_levels slices at several heights along an axis; Contour::simplified removes points that lie on straight runs.

In practice

//! Smoothing, decimating and slicing a triangle mesh.

use lib_jsl_geometry::algorithms::{decimate, laplacian_smoothing, slice_mesh, taubin_smoothing};
use std::f64::consts::PI;

fn main() {
    // A torus of radii 1 and 0.3, as a 48 × 24 grid of quads, with a little bumpiness.
    let (m, k) = (48, 24);
    let mut vertices = Vec::new();
    for i in 0..m {
        for j in 0..k {
            let (u, w) = (2.0 * PI * i as f64 / m as f64, 2.0 * PI * j as f64 / k as f64);
            let r = 0.3 + 0.01 * ((7 * i + 3 * j) % 5) as f64;
            vertices.push([(1.0 + r * w.cos()) * u.cos(), (1.0 + r * w.cos()) * u.sin(), r * w.sin()]);
        }
    }
    let id = |i: usize, j: usize| (i % m) * k + (j % k);
    let triangles: Vec<[usize; 3]> = (0..m).flat_map(|i| (0..k).flat_map(move |j| [[id(i, j), id(i + 1, j), id(i + 1, j + 1)], [id(i, j), id(i + 1, j + 1), id(i, j + 1)]])).collect();
    let tube = |v: &[[f64; 3]]| v.iter().map(|p| ((p[0] * p[0] + p[1] * p[1]).sqrt() - 1.0).hypot(p[2])).sum::<f64>() / v.len() as f64;
    println!("{} triangles, mean tube radius {:.4}", triangles.len(), tube(&vertices));
    println!("Laplacian, 10 steps: mean tube radius {:.4}", tube(&laplacian_smoothing(&vertices, &triangles, 10, 0.5, true)));
    println!("Taubin, 10 steps:    mean tube radius {:.4}", tube(&taubin_smoothing(&vertices, &triangles, 10, 0.5, -0.53, true)));

    let (v, t) = decimate(&vertices, &triangles, 400);
    println!("decimated to {} triangles on {} vertices, mean tube radius {:.4}", t.len(), v.len(), tube(&v));

    for contour in slice_mesh(&vertices, &triangles, [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], 1e-12) {
        println!("slice at z = 0: {} points, closed {}, length {:.4}", contour.points.len(), contour.closed, contour.length());
    }
}
2304 triangles, mean tube radius 0.3200
Laplacian, 10 steps: mean tube radius 0.2824
Taubin, 10 steps:    mean tube radius 0.3218
decimated to 400 triangles on 200 vertices, mean tube radius 0.3298
slice at z = 0: 48 points, closed true, length 8.3721
slice at z = 0: 48 points, closed true, length 4.4277

The bumps are to on a tube of radius . Laplacian smoothing removes them but shrinks the tube by 12%, while Taubin’s changes it by under 1%. The cut at gives the outer and inner circles of the torus.

Strengths

  • Standard, robust mesh operations on plain arrays.
  • Decimation that respects boundaries and manifoldness, and slicing that handles vertices and edges lying in the plane.

Weaknesses

  • Uniform (umbrella) weights: on irregular meshes they also slide vertices along the surface; cotangent weights would not.
  • No remeshing, hole filling, or attribute (normal, colour) preservation during decimation.

Exercises

  1. Show that one Taubin pair multiplies the frequency- component by , and find the pass-band frequency.
  2. Show that the squared distance from a point to a plane is a quadratic form in homogeneous coordinates, and that sums of such forms are minimised by solving a system.
  3. State the link condition for an edge collapse, and draw a mesh where violating it makes the surface non-manifold.
  4. Prove that every horizontal cut of a torus has total length .
  5. Explain why chaining slice segments needs a tolerance, and what goes wrong if it is too large.
Hints and answers
  1. A Laplacian smoothing step multiplies the frequency- component by , so a pair with and multiplies it by ; the pass-band frequency satisfies (where the factor is 1).
  2. The squared distance to the plane with unit normal is with and , a quadratic form . A sum of such forms is minimised by setting the gradient to zero, which is a linear system in .
  3. The link condition: the vertex neighbourhoods of the edge’s endpoints intersect exactly in the two opposite vertices of its adjacent triangles. If other common neighbours exist, the collapse glues unrelated parts of the surface and makes it non-manifold.
  4. A torus with major radius and minor radius cut at height gives two circles of radii and with , whose circumferences add to .
  5. Slice segments from different triangles meet at endpoints that agree only to rounding; a tolerance matches them. If it is too large, distinct nearby endpoints merge and the contour acquires false connections.

Further reading

  • G. Taubin, “A signal processing approach to fair surface design”, Proceedings of SIGGRAPH 95, 351–358.
  • M. Garland and P. S. Heckbert, “Surface simplification using quadric error metrics”, Proceedings of SIGGRAPH 97, 209–216.
  • M. Botsch, L. Kobbelt, M. Pauly, P. Alliez and B. Lévy, Polygon Mesh Processing, A K Peters, 2010.
  • L. R. Herrmann, “Laplacian-isoparametric grid generation scheme”, Journal of the Engineering Mechanics Division 102 (1976) 749–756.