Refining a coarse mesh into a smooth surface with Catmull-Clark, Loop, and sqrt(3) subdivision.
Overview
This tutorial demonstrates subdivision surfaces with SurfaceMeshSubdivision. Starting from a coarse cube, each shortcut applies one subdivision step (and can be repeated), turning the faceted control mesh into an increasingly smooth limit surface. Three classic schemes are available: Catmull-Clark (for polygon meshes), Loop and sqrt(3) (for triangle meshes). The edges are drawn so the refinement is visible. Subdivision is the standard way to model smooth organic shapes from a coarse control cage and is widely used in animation and CAD.
The technique
Subdivision repeatedly refines the mesh topology and repositions vertices with weighted averaging rules so that, in the limit, the mesh converges to a smooth surface. Catmull-Clark (Catmull and Clark, 1978) works on arbitrary polygon meshes: each face gains a face point, each edge an edge point, and original vertices are updated; an n-sided face becomes n quads, and the limit surface is bicubic B-spline-like (C2 away from extraordinary vertices). Loop (Loop, 1987) is the triangle analogue: each triangle is split into four by inserting edge midpoints, with weights that approximate a quartic box spline; it is an approximating scheme (the surface generally does not pass through the control vertices). sqrt(3) (Kobbelt, 2000) also operates on triangles but inserts a vertex at each face centroid and flips the old edges, tripling the face count per step (edge length shrinks by sqrt(3)), which gives a slower, more uniform refinement than Loop's factor-of-four. Because Loop and sqrt(3) require triangles, the mesh is triangulated first for those two schemes.
Easy3D API
Running it
Press Ctrl+c for Catmull-Clark, Ctrl+l for Loop, and Ctrl+t for sqrt(3) subdivision; press repeatedly to apply further refinement steps and watch the cube smooth out.
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_subdivision.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
88 bool subdivide(
int scheme,
Viewer *viewer,
Model *model) {
96 ok = SurfaceMeshSubdivision::catmull_clark(mesh);
100 ok = (scheme == 1) ? SurfaceMeshSubdivision::loop(mesh) : SurfaceMeshSubdivision::sqrt3(mesh);
103 std::cerr <<
"subdivision failed" << std::endl;
106 mesh->renderer()->update();
113int main(
int argc,
char **argv) {
118 const std::string file = resource::directory() +
"/data/quad_mesh/cube_quad.off";
121 Viewer viewer(EXAMPLE_TITLE);
122 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file,
true));
124 std::cerr <<
"failed to load model. Please make sure the file exists and format is correct" << std::endl;
129 viewer.camera()->set_view_direction(
vec3(1, 1, -1));
132 mesh->renderer()->get_lines_drawable(
"edges")->set_visible(
true);
135 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return subdivide(0, v, m); }, mesh, Viewer::KEY_C, Viewer::MODIF_CTRL);
136 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return subdivide(1, v, m); }, mesh, Viewer::KEY_L, Viewer::MODIF_CTRL);
137 viewer.bind_shortcut([](
Viewer *v,
Model *m) {
return subdivide(2, v, m); }, mesh, Viewer::KEY_T, Viewer::MODIF_CTRL);
140 "Ctrl + c: Catmull-Clark subdivision\n" "Ctrl + l: Loop subdivision\n" "Ctrl + t: sqrt(3) subdivision");
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
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Definition collider.cpp:182
- See also
- SurfaceMeshSubdivision, SurfaceMesh, DrawableLines, Tutorial_805_Mesh_Remeshing, Tutorial_806_Mesh_Simplification