Improving triangle quality with uniform and curvature-adaptive incremental remeshing.
Overview
This tutorial demonstrates surface remeshing with SurfaceMeshRemeshing. Remeshing rebuilds the triangulation of a surface so that the triangles are well-shaped and appropriately sized, while staying close to the original geometry. Two schemes are shown on the bunny: uniform remeshing toward a single target edge length, and adaptive remeshing that puts smaller triangles where the surface curves sharply. The edges are drawn so the new triangulation is visible. Remeshing is a key preprocessing step for simulation, deformation, and multiresolution modeling, where poor or uneven triangles cause artifacts.
The technique
Easy3D uses incremental remeshing (Botsch and Kobbelt, "A remeshing approach to multiresolution
modeling", SGP 2004): it repeatedly applies four local operations — split edges that are too long, collapse edges that are too short, flip edges to improve valence/shape (toward the Delaunay-like optimum), and relax vertices tangentially to equalize triangle areas — followed by back-projection onto the original surface so the shape is preserved. Uniform remeshing drives every edge toward one target length, giving an isotropic mesh. Adaptive remeshing (Dunyach et al., "Adaptive remeshing for
real-time mesh deformation", EG 2013) instead uses a curvature-based sizing field: the local target edge length shrinks where curvature is high, bounded by a minimum/maximum edge length and a maximum approximation error, so detail is concentrated where it matters and flat regions stay coarse.
Easy3D API
- SurfaceMeshRemeshing::uniform_remeshing(edge_length): isotropic remeshing toward a target length.
- SurfaceMeshRemeshing::adaptive_remeshing(min_len, max_len, approx_error): curvature-driven remeshing within the given edge-length bounds and approximation tolerance (lengths here are fractions of the bounding-box diagonal so they scale with the model).
- DrawableLines ("edges"): made visible to reveal the triangulation.
- Renderer::update(): re-extracts the rendering buffers after the connectivity changes.
- Viewer::bind_shortcut() / set_usage(): register the Ctrl shortcuts and the help text.
Running it
Press Ctrl+u for uniform remeshing (target = 1.5 x the current average edge length) and Ctrl+a for adaptive remeshing; the console prints the resulting vertex/face counts after each operation.
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/surface_mesh.h>
29#include <easy3d/renderer/camera.h>
30#include <easy3d/renderer/drawable_lines.h>
31#include <easy3d/renderer/renderer.h>
32#include <easy3d/algo/surface_mesh_remeshing.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
89 float average_edge_length(
const SurfaceMesh *mesh) {
91 for (
auto e : mesh->edges())
92 len += distance(mesh->position(mesh->vertex(e, 0)), mesh->position(mesh->vertex(e, 1)));
93 return mesh->n_edges() > 0 ? len /
static_cast<float>(mesh->n_edges()) : 0.0f;
101 const float target = average_edge_length(mesh) * 1.5f;
104 std::cout <<
"uniform remeshing: " << mesh->n_vertices() <<
" vertices / " << mesh->n_faces() <<
" faces"
106 mesh->renderer()->update();
113 bool adaptive_remesh(
Viewer *viewer,
Model *model) {
117 const float bb = mesh->bounding_box().diagonal_length();
120 std::cout <<
"adaptive remeshing: " << mesh->n_vertices() <<
" vertices / " << mesh->n_faces() <<
" faces"
122 mesh->renderer()->update();
129int main(
int argc,
char **argv) {
133 const std::string file = resource::directory() +
"/data/bunny.ply";
136 Viewer viewer(EXAMPLE_TITLE);
137 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file,
true));
139 std::cerr <<
"failed to load model. Please make sure the file exists and format is correct" << std::endl;
143 viewer.camera()->set_view_direction(
vec3(0, 1, 0));
146 mesh->renderer()->get_lines_drawable(
"edges")->set_visible(
true);
149 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return uniform_remesh(v, m); }, mesh, Viewer::KEY_U, Viewer::MODIF_CTRL);
150 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return adaptive_remesh(v, m); }, mesh, Viewer::KEY_A, Viewer::MODIF_CTRL);
153 "Ctrl + u: uniform remeshing (target = 1.5 x average edge length)\n" "Ctrl + a: adaptive remeshing (curvature-driven)");
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 uniform and adaptive surface remeshing.
Definition surface_mesh_remeshing.h:31
void adaptive_remeshing(float min_edge_length, float max_edge_length, float approx_error, unsigned int iterations=10, bool use_projection=true)
Perform adaptive remeshing.
Definition surface_mesh_remeshing.cpp:70
void uniform_remeshing(float edge_length, unsigned int iterations=10, bool use_projection=true)
Perform uniform remeshing.
Definition surface_mesh_remeshing.cpp:37
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Definition collider.cpp:182
- See also
- SurfaceMeshRemeshing, SurfaceMesh, DrawableLines, Tutorial_806_Mesh_Simplification, Tutorial_807_Mesh_Subdivision