Removing noise from a triangle mesh with explicit and implicit Laplacian smoothing.
Overview
This tutorial demonstrates mesh smoothing (denoising) with SurfaceMeshSmoothing. To make the effect obvious, Gaussian noise is first added to the bunny mesh; the smoothing shortcuts then progressively remove it. Two variants are provided: explicit Laplacian smoothing (a few local averaging iterations) and implicit Laplacian smoothing (a single global solve). Smoothing is the workhorse for cleaning up scanned or reconstructed geometry before further processing.
The technique
Laplacian smoothing moves each vertex toward the average of its neighbors, which attenuates high-frequency noise. The discrete Laplacian of the vertex positions is L(p); with the cotangent weights it approximates the mean-curvature normal, so iterating p <- p + dt * L(p) is a discretization of mean-curvature flow (the surface diffuses like heat). Explicit smoothing applies this update directly for a fixed number of iterations: it is cheap and local, but the timestep must be small or the iteration becomes unstable, and repeated averaging also shrinks the mesh and blurs features. Implicit smoothing instead solves (I - dt * L) p_new = p_old in one sparse linear system. Because the update is implicit (backward Euler), it is unconditionally stable for large timesteps and removes noise in a single step, at the cost of solving a global system. Both approaches are described in Desbrun et al., "Implicit fairing of irregular meshes using diffusion and curvature flow" (SIGGRAPH 1999); see also Kazhdan et al. (CGF 2012) on non-singular mean-curvature flow. Easy3D defaults to the cotangent (geometry-aware) Laplacian rather than uniform weights.
Easy3D API
- SurfaceMeshSmoothing: explicit_smoothing(iters) runs local averaging iterations; implicit_smoothing(timestep) solves the global implicit system.
- GaussianNoise::apply(): perturbs vertex positions along their normals with a given standard deviation, used here to synthesize a noisy input.
- Renderer::update(): re-extracts the rendering buffers after the vertex positions change.
- Viewer::bind_shortcut() / set_usage(): register the Ctrl shortcuts and the help text.
Running it
The model starts noisy. Press Ctrl+e for explicit smoothing (10 iterations), Ctrl+i for implicit smoothing, and Ctrl+n to add Gaussian noise again so you can repeat the comparison.
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/surface_mesh.h>
29#include <easy3d/renderer/camera.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/algo/surface_mesh_smoothing.h>
32#include <easy3d/algo/gaussian_noise.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
90 const float sigma = mesh->bounding_box().diagonal_length() * 0.003f;
91 GaussianNoise::apply(mesh, sigma);
92 mesh->renderer()->update();
101 mesh->renderer()->update();
107 bool smooth_explicit(
Viewer *viewer,
Model *model) {
113 mesh->renderer()->update();
119 bool smooth_implicit(
Viewer *viewer,
Model *model) {
125 mesh->renderer()->update();
132int main(
int argc,
char **argv) {
137 Viewer viewer(EXAMPLE_TITLE);
139 const std::string file = resource::directory() +
"/data/bunny.ply";
140 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file,
true));
142 std::cerr <<
"failed to load model. Please make sure the file exists and format is correct" << std::endl;
147 viewer.camera()->set_view_direction(
vec3(0, 1, 0));
153 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return smooth_explicit(v, m); }, mesh, Viewer::KEY_E, Viewer::MODIF_CTRL);
154 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return smooth_implicit(v, m); }, mesh, Viewer::KEY_I, Viewer::MODIF_CTRL);
155 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return noise(v, m); }, mesh, Viewer::KEY_N, Viewer::MODIF_CTRL);
158 "Ctrl + e: explicit Laplacian smoothing (10 iterations)\n" "Ctrl + i: implicit Laplacian smoothing\n" "Ctrl + n: add Gaussian noise again");
Base class for spatial models with optional rendering and manipulation state.
Definition model.h:53
A halfedge data structure for polygonal meshes of 2-manifold topology.
Definition surface_mesh.h:51
A class for Laplacian smoothing.
Definition surface_mesh_smoothing.h:26
void implicit_smoothing(float timestep=0.001, bool use_uniform_laplace=false, bool rescale=false)
Perform implicit Laplacian smoothing with timestep.
Definition surface_mesh_smoothing.cpp:127
void explicit_smoothing(unsigned int iters=10, bool use_uniform_laplace=false)
Perform iters iterations of explicit Laplacian smoothing.
Definition surface_mesh_smoothing.cpp:77
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Definition collider.cpp:182
- See also
- SurfaceMeshSmoothing, GaussianNoise, SurfaceMesh, Tutorial_803_Mesh_Fairing