Reducing a mesh's vertex count with quadric-error-metric edge collapse (decimation).
Overview
This tutorial demonstrates mesh simplification (decimation) with SurfaceMeshSimplification. Each press of the shortcut collapses the mesh down to half of its current vertices (with a floor of 100), so you can watch detail disappear progressively while the overall shape is preserved. The edges are drawn to make the coarsening visible. Simplification is essential for level-of-detail rendering, faster processing, and compact storage of high-resolution scans.
The technique
The algorithm is incremental greedy decimation by halfedge collapse: repeatedly merge one vertex into a neighbor, removing the two adjacent triangles, until the target vertex count is reached. The key question is which collapse to do next and where to place the surviving vertex. Easy3D uses the quadric error metric of Garland and Heckbert, "Surface simplification using quadric error metrics" (SIGGRAPH 1997): each vertex accumulates a 4x4 symmetric matrix Q that encodes the sum of squared distances to the planes of its incident faces. The cost of placing a vertex at position p is p^T Q p, so the optimal collapse position minimizes this quadratic error, and collapses are prioritized by their error in a heap (cheapest first). This preserves the geometry far better than naive midpoint collapse. The implementation also follows the general decimation framework of Kobbelt et al. (Graphics Interface 1998), with optional fairness/quality constraints (aspect ratio, normal deviation, Hausdorff error).
Easy3D API
- SurfaceMeshSimplification: initialize() sets up the quadrics and priority queue; simplify(n_vertices) collapses edges until roughly n_vertices remain.
- DrawableLines ("edges"): made visible to reveal the coarsening triangulation.
- Renderer::update(): re-extracts the rendering buffers after the connectivity changes.
- Viewer::bind_shortcut() / set_usage(): register the Ctrl shortcut and the help text.
Running it
Press Ctrl+d to simplify to half of the current vertices; repeat to decimate further. The console prints the resulting vertex/face counts after each pass.
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/renderer/drawable_lines.h>
32#include <easy3d/algo/surface_mesh_simplification.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
93 const unsigned int target = std::max(100u, mesh->n_vertices() / 2);
95 std::cout <<
"simplified to " << mesh->n_vertices() <<
" vertices / " << mesh->n_faces() <<
" faces"
97 mesh->renderer()->update();
104int main(
int argc,
char **argv) {
108 const std::string file = resource::directory() +
"/data/bunny.ply";
111 Viewer viewer(EXAMPLE_TITLE);
112 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file,
true));
114 std::cerr <<
"failed to load model. Please make sure the file exists and format is correct" << std::endl;
118 viewer.camera()->set_view_direction(
vec3(0, 1, 0));
121 mesh->renderer()->get_lines_drawable(
"edges")->set_visible(
true);
124 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return simplify(v, m); }, mesh, Viewer::KEY_D, Viewer::MODIF_CTRL);
125 viewer.set_usage(
"default",
"Ctrl + d: simplify to half of the current vertices");
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
Surface mesh simplification based on approximation error and fairness criteria.
Definition surface_mesh_simplification.h:33
void simplify(unsigned int n_vertices)
Simplify mesh to n vertices.
Definition surface_mesh_simplification.cpp:124
void initialize(float aspect_ratio=0.0, float edge_length=0.0, unsigned int max_valence=0, float normal_deviation=0.0, float hausdorff_error=0.0)
Initialize with given parameters.
Definition surface_mesh_simplification.cpp:42
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Definition collider.cpp:182
- See also
- SurfaceMeshSimplification, SurfaceMesh, DrawableLines, Tutorial_805_Mesh_Remeshing, Tutorial_807_Mesh_Subdivision