Easy3D 2.5.3
point_cloud_ransac.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_ALGO_POINT_CLOUD_RANSAC_H
28#define EASY3D_ALGO_POINT_CLOUD_RANSAC_H
29
30
31#include <easy3d/core/types.h>
32
33
34namespace easy3d {
35
36 class PointCloud;
37
49 public:
50 enum PrimType { // Do NOT modify the order!!! Values have to be exactly the same as in RANSAC
51 PLANE = 0,
52 SPHERE = 1,
53 CYLINDER = 2,
54 CONE = 3,
55 TORUS = 4,
56 UNKNOWN = -1
57 };
58
59 public:
64 void add_primitive_type(PrimType t);
69 void remove_primitive_type(PrimType t);
70
85 int detect(
86 PointCloud *cloud,
87 unsigned int min_support = 1000,
88 float dist_threshold = 0.005f,
89 float bitmap_resolution = 0.02f,
90 float normal_threshold = 0.8f,
91 float overlook_probability = 0.001f
92 );
93
94
110 int detect(
111 PointCloud *cloud,
112 const std::vector<int> &vertices,
113 unsigned int min_support = 1000,
114 float dist_threshold = 0.005f,
115 float bitmap_resolution = 0.02f,
116 float normal_threshold = 0.8f,
117 float overlook_probability = 0.001f
118 );
119
120 //Todo: implement storing parameters for spheres, toruses, and cones.
121
122 // In addition to the primitive information (primitive type and index stored as per-vertex properties,
123 // the parameters of the detected primitives can be queried using the perspective functions.
124 struct PlanePrim {
125 int primitive_index; // the index of this plane (w.r.t. the entire list of detected primitives)
126 std::vector<int> vertices; // the vertex indices (w.r.t. the point cloud) of this plane
127 Plane3 plane; // the plane equation
128 vec3 position;
129 vec3 normal;
130 };
131 const std::vector<PlanePrim>& get_planes() const { return plane_primitives_; }
132
134 int primitive_index; // the index of this cylinder w.r.t. the entire list of detected primitives
135 std::vector<int> vertices; // the vertex indices (w.r.t. the point cloud) of this cylinder
136 float radius;
137 vec3 position;
138 vec3 direction;
139 };
140 const std::vector<CylinderPrim>& get_cylinders() const { return cylinder_primitives_; }
141
142 private:
143 std::set<PrimType> types_;
144
145 std::vector<PlanePrim> plane_primitives_;
146 std::vector<CylinderPrim> cylinder_primitives_;
147 };
148
149}
150
151
152#endif // EASY3D_ALGO_POINT_CLOUD_RANSAC_H
A data structure for point clouds.
Definition: point_cloud.h:45
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
void remove_primitive_type(PrimType t)
Exclude a primitive types to be extracted.
Definition: point_cloud_ransac.cpp:237
Definition: collider.cpp:182
Definition: point_cloud_ransac.h:133
Definition: point_cloud_ransac.h:124