Debian Codegraph @

plugins/core/Standard/qRANSAC_SD/include/qRANSAC_SD.h

raw
1 //##########################################################################
2 //# #
3 //# CLOUDCOMPARE PLUGIN: qRANSAC_SD #
4 //# #
5 //# This program is free software; you can redistribute it and/or modify #
6 //# it under the terms of the GNU General Public License as published by #
7 //# the Free Software Foundation; version 2 or later of the License. #
8 //# #
9 //# This program is distributed in the hope that it will be useful, #
10 //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 //# GNU General Public License for more details. #
13 //# #
14 //# COPYRIGHT: Daniel Girardeau-Montaut #
15 //# #
16 //##########################################################################
17
18 #ifndef Q_RANSAC_SD_PLUGIN_HEADER
19 #define Q_RANSAC_SD_PLUGIN_HEADER
20
21 #include "ccStdPluginInterface.h"
22
23
24 //! Wrapper to Schnabel et al. library for automatic shape detection in point cloud
25 /** "Efficient RANSAC for Point-Cloud Shape Detection", Ruwen Schnabel, Roland Wahl,
26 and Reinhard Klein, in Computer Graphics Forum (June 2007), 26:2(214-226)
27 http://cg.cs.uni-bonn.de/en/publications/paper-details/schnabel-2007-efficient/
28 **/
29 class qRansacSD : public QObject, public ccStdPluginInterface
30 {
31 Q_OBJECT
32 Q_INTERFACES( ccPluginInterface ccStdPluginInterface )
33
34 Q_PLUGIN_METADATA( IID "cccorp.cloudcompare.plugin.qRansacSD" FILE "../info.json" )
35
36 public:
37 enum RANSAC_PRIMITIVE_TYPES
38 {
39 RPT_PLANE = 0,
40 RPT_SPHERE = 1,
41 RPT_CYLINDER = 2,
42 RPT_CONE = 3,
43 RPT_TORUS = 4,
44 };
45
46 struct RansacParams
47 {
48 float epsilon; // distance threshold
49 float bitmapEpsilon; //bitmap resolution
50 unsigned supportPoints; // this is the minimal numer of points required for a primitive
51 float maxNormalDev_deg; // maximal normal deviation from ideal shape (in degrees)
52 float probability; // probability that no better candidate was overlooked during sampling
53 bool randomColor; // should the resulting detected shapes sub point cloud be colored randomly
54 bool createCloudFromLeftOverPoints; // should the points that were not associated with a shape be saved
55 bool primEnabled[5]; //RANSAC_PRIMITIVE_TYPES
56 bool allowSimplification;
57 bool allowFitting;
58 float minSphereRadius;
59 float maxSphereRadius;
60 float minCylinderRadius;
61 float maxCylinderRadius;
62 float maxCylinderLength;
63 float maxConeRadius;
64 float maxConeAngle_deg;
65 float maxConeLength;
66 float minTorusMinorRadius;
67 float minTorusMajorRadius;
68 float maxTorusMinorRadius;
69 float maxTorusMajorRadius;
70
71 RansacParams() : epsilon(0.005f)
72 , bitmapEpsilon(0.001f)
73 , supportPoints(500)
74 , maxNormalDev_deg(25.0f)
75 , probability(0.01f)
76 , randomColor(true)
77 , createCloudFromLeftOverPoints(true)
78 , allowSimplification(true)
79 , allowFitting(true)
80 , minSphereRadius(-std::numeric_limits<float>::infinity())
81 , maxSphereRadius(std::numeric_limits<float>::infinity())
82 , minCylinderRadius(-std::numeric_limits<float>::infinity())
83 , maxCylinderRadius(std::numeric_limits<float>::infinity())
84 , maxCylinderLength(std::numeric_limits<float>::infinity())
85 , maxConeRadius(std::numeric_limits<float>::infinity())
86 , maxConeAngle_deg(std::numeric_limits<float>::infinity())
87 , maxConeLength(std::numeric_limits<float>::infinity())
88 , minTorusMinorRadius(std::numeric_limits<float>::infinity())
89 , minTorusMajorRadius(std::numeric_limits<float>::infinity())
90 , maxTorusMinorRadius(std::numeric_limits<float>::infinity())
91 , maxTorusMajorRadius(std::numeric_limits<float>::infinity())
92 {
93 primEnabled[RPT_PLANE] = true;
94 primEnabled[RPT_SPHERE] = true;
95 primEnabled[RPT_CYLINDER] = true;
96 primEnabled[RPT_CONE] = false;
97 primEnabled[RPT_TORUS] = false;
98 };
99
100 RansacParams(float scale) : epsilon(0.005f * scale)
101 , bitmapEpsilon(0.001f)
102 , supportPoints(500)
103 , maxNormalDev_deg(25.0f)
104 , probability(0.01f)
105 , randomColor(true)
106 , createCloudFromLeftOverPoints(true)
107 , allowSimplification(true)
108 , allowFitting(true)
109 , minSphereRadius(-std::numeric_limits<float>::infinity())
110 , maxSphereRadius(std::numeric_limits<float>::infinity())
111 , minCylinderRadius(-std::numeric_limits<float>::infinity())
112 , maxCylinderRadius(std::numeric_limits<float>::infinity())
113 , maxCylinderLength(std::numeric_limits<float>::infinity())
114 , maxConeRadius(std::numeric_limits<float>::infinity())
115 , maxConeAngle_deg(std::numeric_limits<float>::infinity())
116 , maxConeLength(std::numeric_limits<float>::infinity())
117 , minTorusMinorRadius(std::numeric_limits<float>::infinity())
118 , minTorusMajorRadius(std::numeric_limits<float>::infinity())
119 , maxTorusMinorRadius(std::numeric_limits<float>::infinity())
120 , maxTorusMajorRadius(std::numeric_limits<float>::infinity())
121 {
122 primEnabled[RPT_PLANE] = true;
123 primEnabled[RPT_SPHERE] = true;
124 primEnabled[RPT_CYLINDER] = true;
125 primEnabled[RPT_CONE] = false;
126 primEnabled[RPT_TORUS] = false;
127 };
128
129 };
130 //! Default constructor
131 explicit qRansacSD(QObject* parent = nullptr);
132
133 //inherited from ccStdPluginInterface
134 virtual void onNewSelection(const ccHObject::Container& selectedEntities) override;
135 virtual QList<QAction *> getActions() override;
136 virtual void registerCommands(ccCommandLineInterface* cmd) override;
137
138 static ccHObject* executeRANSAC(ccPointCloud* ccPC, const RansacParams& params, bool silent = false);
139 protected:
140
141 //! Slot called when associated ation is triggered
142 void doAction();
143
144 protected:
145
146 //! Associated action
147 QAction* m_action;
148 };
149
150 #endif