Estimating per-vertex curvature on a triangle mesh and visualizing it as a color-mapped scalar field.
Overview
This tutorial is the first of the surface-mesh geometry-processing series. It loads the bunny triangle mesh, estimates discrete curvature at every vertex with SurfaceMeshCurvature, and paints the result on the surface with a colormap. Three scalar fields are available (mean, Gaussian, and maximum absolute curvature) and can be switched interactively. Curvature is a fundamental shape descriptor: it tells you where a surface is flat, where it bends, and where it has sharp features, and it drives many downstream algorithms (smoothing, remeshing, feature detection).
The technique
On a smooth surface, curvature describes how fast the surface turns. At each point there are two principal curvatures k1 and k2 (the extreme bending rates over all tangent directions); from them we form the mean curvature H = (k1 + k2) / 2 and the Gaussian curvature K = k1 * k2. H is zero on minimal (soap-film-like) surfaces and measures average bending; K is positive on dome-like (elliptic) regions, negative on saddle-like (hyperbolic) regions, and zero on flat or developable regions — it is an intrinsic measure tied to the angle defect of the surface. A triangle mesh has no smooth derivatives, so curvature must be estimated discretely from the local neighborhood. Easy3D follows the discrete differential-geometry operators of Meyer et al. (2003, "Discrete Differential-Geometry
Operators for Triangulated 2-Manifolds") and the normal-cycle / restricted-Delaunay approach of Cohen-Steiner and Morvan (2003): principal curvatures are recovered per vertex from the surrounding faces/edges, boundary vertices are interpolated from their interior neighbors, and a few smoothing iterations suppress estimation noise. The maximum absolute curvature max(|k1|, |k2|) highlights the strongest bending regardless of sign, which is useful for spotting creases and corners.
Easy3D API
- SurfaceMeshCurvature: construct it on a SurfaceMesh, call analyze() to estimate the principal curvatures (stored as "v:curv-min" / "v:curv-max"), then compute_mean_curvature(), compute_gauss_curvature(), or compute_max_abs_curvature() to fill the derived vertex properties "v:curv-mean", "v:curv-gauss", "v:curv-max_abs".
- DrawableTriangles::set_scalar_coloring(): maps a per-vertex scalar property to a colormap so the field becomes visible on the surface.
- Viewer::bind_shortcut() / set_usage(): register the Ctrl-key shortcuts and the on-screen help text.
- Renderer::update(): re-extracts rendering buffers after the property used for coloring changes.
Running it
The mean curvature is shown first. Press Ctrl+e for mean curvature, Ctrl+g for Gaussian curvature, and Ctrl+k for maximum absolute curvature; the surface is recolored each time.
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_triangles.h>
32#include <easy3d/algo/surface_mesh_curvature.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
93 bool apply_curvature(
int type,
Viewer *viewer,
Model *model) {
106 std::string property;
109 property =
"v:curv-mean";
110 }
else if (type == 1) {
112 property =
"v:curv-gauss";
115 property =
"v:curv-max_abs";
120 auto drawable = mesh->renderer()->get_triangles_drawable(
"faces");
121 drawable->set_scalar_coloring(State::VERTEX, property);
122 mesh->renderer()->update();
129int main(
int argc,
char **argv) {
134 const std::string file = resource::directory() +
"/data/bunny.ply";
137 Viewer viewer(EXAMPLE_TITLE);
138 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file,
true));
140 std::cerr <<
"failed to load model. Please make sure the file exists and format is correct" << std::endl;
145 viewer.camera()->set_view_direction(
vec3(0, 1, 0));
148 apply_curvature(0, &viewer, mesh);
152 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return apply_curvature(0, v, m); }, mesh, Viewer::KEY_E, Viewer::MODIF_CTRL);
153 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return apply_curvature(1, v, m); }, mesh, Viewer::KEY_G, Viewer::MODIF_CTRL);
154 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return apply_curvature(2, v, m); }, mesh, Viewer::KEY_K, Viewer::MODIF_CTRL);
157 "Ctrl + e: mean curvature\n" "Ctrl + g: Gaussian curvature\n" "Ctrl + k: maximum absolute curvature");
Base class for spatial models with optional rendering and manipulation state.
Definition model.h:53
Compute per-vertex curvatures, i.e., principal (min, max), mean, Gaussian.
Definition surface_mesh_curvature.h:29
void compute_gauss_curvature()
Definition surface_mesh_curvature.cpp:323
void compute_max_abs_curvature()
Computes the maximum absolute curvature.
Definition surface_mesh_curvature.cpp:331
void compute_mean_curvature()
Definition surface_mesh_curvature.cpp:313
void analyze(unsigned int post_smoothing_steps=0)
Computes principal curvature information for each vertex.
Definition surface_mesh_curvature.cpp:30
A halfedge data structure for polygonal meshes of 2-manifold topology.
Definition surface_mesh.h:51
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Definition collider.cpp:182
- See also
- SurfaceMeshCurvature, SurfaceMesh, DrawableTriangles, Tutorial_802_Mesh_Smoothing