27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/model.h>
29#include <easy3d/renderer/drawable_points.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/algo/point_cloud_ransac.h>
32#include <easy3d/util/resource.h>
33#include <easy3d/util/initializer.h>
43 if (!viewer || !model)
46 auto cloud =
dynamic_cast<PointCloud *
>(model);
49 std::cerr <<
"Plane extraction using RANSAC requires normal information but it is not available" << std::endl;
57 const int num = algo.
detect(cloud, 200, 0.005f, 0.02f, 0.8f, 0.001f);
59 std::cout << num <<
" primitives extracted" << std::endl;
62 auto segments = cloud->vertex_property<
int>(
"v:primitive_index");
63 const std::string color_name =
"v:color-segments";
64 auto coloring = cloud->vertex_property<
vec3>(color_name,
vec3(0, 0, 0));
65 Renderer::color_from_segmentation(cloud, segments, coloring);
67 auto drawable = cloud->renderer()->get_points_drawable(
"vertices");
68 drawable->set_property_coloring(State::VERTEX, color_name);
77int main(
int argc,
char **argv) {
81 const std::string file = resource::directory() +
"/data/polyhedron.bin";
84 Viewer viewer(EXAMPLE_TITLE);
86 Model *model = viewer.add_model(file,
true);
88 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
95 drawable->set_point_size(3.0f);
98 viewer.set_usage(
"'Ctrl + e': extract planes");
100 viewer.bind(extract_plane, model, Viewer::KEY_E, Viewer::MODIF_CTRL);
The base class of renderable 3D models.
Definition: model.h:49
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
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. returns an invalid VertexProperty if the property does ...
Definition: point_cloud.h:340
Extract primitives from point clouds using RANSAC.Usage example:
Definition: point_cloud_ransac.h:48
int detect(PointCloud *cloud, unsigned int min_support=1000, float dist_threshold=0.005f, float bitmap_resolution=0.02f, float normal_threshold=0.8f, float overlook_probability=0.001f)
Extract primitives from a point cloud.
Definition: point_cloud_ransac.cpp:242
void add_primitive_type(PrimType t)
Setup the primitive types to be extracted.
Definition: point_cloud_ransac.cpp:232
PointsDrawable * get_points_drawable(const std::string &name) const
Definition: renderer.cpp:286
void set_uniform_coloring(const vec4 &color)
Definition: state.cpp:89
The built-in Easy3D viewer.
Definition: viewer.h:61
void update() const
Update the display (i.e., repaint).
Definition: viewer.cpp:631
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35