This example shows how to reconstruct a smooth surface from a point cloud using the Poisson surface reconstruction method.
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/model.h>
29#include <easy3d/renderer/drawable_triangles.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/algo/point_cloud_poisson_reconstruction.h>
32#include <easy3d/util/resource.h>
33#include <easy3d/util/initializer.h>
46 if (!viewer || !model)
49 auto cloud =
dynamic_cast<PointCloud *
>(model);
52 std::cerr <<
"Poisson surface reconstruction method requires normal information."
53 <<
" Please provide normal information. Alternatively, you can use the "
54 <<
" Tutorial_701_Cloud_NormalEstimation for normal estimation" << std::endl;
61 std::cout <<
"reconstruction depth: " << depth << std::endl;
63 if (surface !=
nullptr) {
64 viewer->add_model(std::shared_ptr<Model>(surface),
true);
66 auto faces = surface->renderer()->get_triangles_drawable(
"faces");
67 faces->set_coloring_method(State::UNIFORM_COLOR);
68 viewer->delete_model(cloud);
76int main(
int argc,
char **argv) {
80 const std::string file = resource::directory() +
"/data/polyhedron.bin";
83 Viewer viewer(EXAMPLE_TITLE);
85 Model *model = viewer.add_model(file,
true);
87 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
92 viewer.bind(reconstruction, model, Viewer::KEY_R, Viewer::MODIF_CTRL);
94 viewer.set_usage(
"",
"Ctrl + r: run reconstruction");
The base class of renderable 3D models.
Definition model.h:50
A data structure for point clouds.
Definition point_cloud.h:45
VertexProperty< T > get_vertex_property(const std::string &name) const
Get the vertex property named name of type T.
Definition point_cloud.h:513
Poisson surface reconstruction.
Definition point_cloud_poisson_reconstruction.h:43
void set_depth(int d)
Set reconstruction depth.
Definition point_cloud_poisson_reconstruction.h:62
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
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182