This example shows how to reconstruct a smooth surface from a point cloud using the Poisson surface reconstruction method.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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>
34
41
43
44
46 if (!viewer || !model)
47 return false;
48
49 auto cloud =
dynamic_cast<PointCloud *
>(model);
51 if (!normals) {
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;
55 return false;
56 }
57
58 const int depth = 6;
61 std::cout << "reconstruction depth: " << depth << std::endl;
63 if (surface != nullptr) {
64 viewer->add_model(std::shared_ptr<Model>(surface), true);
65
66 auto faces = surface->renderer()->get_triangles_drawable("faces");
68 viewer->delete_model(cloud);
69 viewer->update();
70 }
71
72 return true;
73}
74
75
76int main(int argc, char **argv) {
77
79
81
82
83 Viewer viewer(EXAMPLE_TITLE);
84
85 Model *model = viewer.add_model(file,
true);
86 if (!model) {
87 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
88 return EXIT_FAILURE;
89 }
90
91
92 viewer.bind(reconstruction, model, Viewer::KEY_R, Viewer::MODIF_CTRL);
93
94 viewer.set_usage("", "Ctrl + r: run reconstruction");
95
96
97 return viewer.run();
98}
99
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
@ UNIFORM_COLOR
Uniformly colored.
Definition state.h:58
The built-in Easy3D viewer.
Definition viewer.h:63
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39