Reconstructing a smooth surface mesh from an oriented point cloud (Poisson reconstruction).
Overview
This interactive tutorial loads the polyhedron point cloud (which already carries normals) and, on Ctrl+R, reconstructs a continuous surface from it. The point cloud is then replaced by the resulting triangle mesh in the viewer. It builds directly on Tutorial_701_Cloud_NormalEstimation: Poisson reconstruction needs consistently oriented normals as input.
The technique
Poisson surface reconstruction (Kazhdan, Bolitho, and Hoppe, "Poisson Surface Reconstruction", Symposium on Geometry Processing 2006) casts reconstruction as a spatial Poisson problem. The oriented normals define a vector field; the method finds an indicator function (1 inside the object, 0 outside) whose gradient best matches that field, then extracts an isosurface as a triangle mesh. It solves on an adaptive octree, so the "depth" parameter caps the resolution: depth d corresponds to a voxel grid no finer than 2^d x 2^d x 2^d. Higher depth captures more detail at greater memory/time cost. The result is a smooth, watertight SurfaceMesh.
Easy3D API
- PoissonReconstruction: the algorithm wrapper. set_depth(d) caps the octree depth; apply(cloud) runs the reconstruction and returns a new SurfaceMesh (or nullptr on failure).
- PointCloud::get_vertex_property<vec3>("v:normal"): checks that normals exist before reconstructing.
- Viewer::add_model() / delete_model(): swap the cloud for the reconstructed surface.
- TrianglesDrawable::set_coloring_method(State::UNIFORM_COLOR): draw the mesh in a single color.
Running it
Press Ctrl+R to run the reconstruction (depth 6, printed to the console). The point cloud is removed and the reconstructed surface is shown in its place. If the cloud has no normals, an error message points you to Tutorial_701 for estimating them first.
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/point_cloud.h>
29#include <easy3d/core/model.h>
30#include <easy3d/core/surface_mesh.h>
31#include <easy3d/renderer/drawable_triangles.h>
32#include <easy3d/renderer/renderer.h>
33#include <easy3d/algo/point_cloud_poisson_reconstruction.h>
34#include <easy3d/util/resource.h>
35#include <easy3d/util/initializer.h>
82 if (!viewer || !model)
85 auto cloud =
dynamic_cast<PointCloud *
>(model);
89 std::cerr <<
"Poisson surface reconstruction method requires normal information."
90 <<
" Please provide normal information. Alternatively, you can use the "
91 <<
" Tutorial_701_Cloud_NormalEstimation for normal estimation" << std::endl;
99 std::cout <<
"reconstruction depth: " << depth << std::endl;
101 auto surface = algo.
apply(cloud);
102 if (surface !=
nullptr) {
104 viewer->add_model(surface,
true);
106 auto faces = surface->renderer()->get_triangles_drawable(
"faces");
107 faces->set_coloring_method(State::UNIFORM_COLOR);
108 viewer->delete_model(cloud);
115int main(
int argc,
char **argv) {
120 const std::string file = resource::directory() +
"/data/polyhedron.bin";
123 Viewer viewer(EXAMPLE_TITLE);
125 Model *model = viewer.add_model(file,
true);
127 std::cerr <<
"failed to load model. Please make sure the file exists and format is correct" << std::endl;
132 viewer.bind_shortcut(reconstruction, model, Viewer::KEY_R, Viewer::MODIF_CTRL);
134 viewer.set_usage(
"default",
"Ctrl + r: run reconstruction");
Base class for spatial models with optional rendering and manipulation state.
Definition model.h:53
A data structure for point clouds.
Definition point_cloud.h:46
VertexProperty< T > get_vertex_property(const std::string &name) const
Get the vertex property named name of type T.
Definition point_cloud.h:514
Poisson surface reconstruction.
Definition point_cloud_poisson_reconstruction.h:44
std::shared_ptr< SurfaceMesh > apply(const PointCloud *cloud, const std::string &density_attr_name="v:density") const
Perform Poisson surface reconstruction.
Definition point_cloud_poisson_reconstruction.cpp:193
void set_depth(int d)
Set reconstruction depth.
Definition point_cloud_poisson_reconstruction.h:63
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143
Definition collider.cpp:182
- See also
- PoissonReconstruction, SurfaceMesh, Tutorial_701_Cloud_NormalEstimation