CVB++ 15.0
match_3d.hpp
1#pragma once
2
3#include "../_cexports/c_match_3d.h"
4
5#include "../affine_matrix_3d.hpp"
6#include "../global.hpp"
7#include "../point_cloud.hpp"
8
9namespace Cvb
10{
11
12 CVB_BEGIN_INLINE_NS
13
15
26 namespace Match3D
27 {
28
31 {
35 ClassicICP = CExports::CVM3DCT_ClassicICP,
36
40 ConsensusICP = CExports::CVM3DCT_ConsensusICP
41 };
42
43 class MatchingParameters;
44 class MatchingResult;
45
46 inline MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model,
47 const MatchingParameters &parameters);
48
54 {
55 friend MatchingResult IcpMatch(const PointCloud &model, const PointCloud &scene,
56 const MatchingParameters &parameters);
57
58 public:
60
65 MatchingParameters() noexcept {}
66
68
75 MatchingParameters(std::size_t maxScenePoints, std::size_t maxModelPoints) noexcept
76 {
77 SetMaxModelPoints(maxModelPoints);
78 SetMaxScenePoints(maxScenePoints);
79 }
80
82
100 MatchingParameters(std::size_t maxScenePoints, std::size_t maxModelPoints, int maxIterations, double tolerance,
101 double minImprovement, double correspondenceThreshold, double convergenceRadius, bool prealign,
102 CorrespondenceType correspondenceMethod) noexcept
103 {
104 SetMaxModelPoints(maxModelPoints);
105 SetMaxScenePoints(maxScenePoints);
106
107 params_.major = static_cast<Cvb::CExports::cvbint32_t>(0);
108 params_.minor = static_cast<Cvb::CExports::cvbint32_t>(1);
109 SetMaxIterations(maxIterations);
110 SetTolerance(tolerance);
111 SetMinImprovement(minImprovement);
112 SetCorrespondenceThreshold(correspondenceThreshold);
113 SetConvergenceRadius(convergenceRadius);
114 SetPrealign(prealign);
115 SetCorrespondenceMethod(correspondenceMethod);
116 }
117
119
124 {
125 return static_cast<std::size_t>(maxModelPoints_);
126 }
127
129
133 void SetMaxModelPoints(std::size_t maxModelPoints) noexcept
134 {
135 maxModelPoints_ = static_cast<std::int64_t>(maxModelPoints);
136 }
137
139
144 {
145 return static_cast<std::size_t>(maxScenePoints_);
146 }
147
149
153 void SetMaxScenePoints(std::size_t maxScenePoints) noexcept
154 {
155 maxScenePoints_ = static_cast<std::int64_t>(maxScenePoints);
156 }
157
159
163 int MaxIterations() const noexcept
164 {
165 return static_cast<int>(params_.MaxIterations);
166 }
167
169
173 void SetMaxIterations(int value) noexcept
174 {
175 params_.MaxIterations = static_cast<Cvb::CExports::cvbval_t>(value);
176 }
177
179
184 double Tolerance() const noexcept
185 {
186 return params_.Tolerance;
187 }
188
190
194 void SetTolerance(double value) noexcept
195 {
196 params_.Tolerance = value;
197 }
198
200
206 double MinImprovement() const noexcept
207 {
208 return params_.MinImprovement;
209 }
210
212
216 void SetMinImprovement(double value) noexcept
217 {
218 params_.MinImprovement = value;
219 }
220
222
228 double CorrespondenceThreshold() const noexcept
229 {
230 return params_.CorrespondenceThreshold;
231 }
232
234
240 void SetCorrespondenceThreshold(double value) noexcept
241 {
242 params_.CorrespondenceThreshold = value;
243 }
244
246
250 double ConvergenceRadius() const noexcept
251 {
252 return params_.ConvergenceRadius;
253 }
254
256
261 void SetConvergenceRadius(double value) noexcept
262 {
263 params_.ConvergenceRadius = value;
264 }
265
267
271 bool Prealign() const noexcept
272 {
273 return static_cast<bool>(params_.Prealign);
274 }
275
277
281 void SetPrealign(bool value) noexcept
282 {
283 params_.Prealign = static_cast<Cvb::CExports::cvbbool_t>(value);
284 }
285
287
292 {
293 return static_cast<CorrespondenceType>(params_.CorrespondenceMethod);
294 }
295
297
302 {
303 params_.CorrespondenceMethod = static_cast<Cvb::CExports::CVM3DCorrespondenceType>(value);
304 }
305
306 private:
307 std::int64_t maxModelPoints_ = 0;
308 std::int64_t maxScenePoints_ = 0;
309
310 CExports::CVM3DMatchParameters params_ = CExports::CVM3DDefaultParameters;
311 };
312
317 class MatchingResult final
318 {
319 friend MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model,
320 const MatchingParameters &parameters);
321
322 public:
324
328 double DistanceRMS() const noexcept
329 {
330 return rmsDistance_;
331 }
332
335
340 {
341 return transformation_;
342 }
343
345
349 int NumIterations() const noexcept
350 {
351 return numIterations_;
352 }
353
354 private:
355 MatchingResult() noexcept = default;
356
357 double rmsDistance_ = std::numeric_limits<double>::quiet_NaN();
358 CExports::cvbval_t numIterations_ = 0;
359 AffineMatrix3D transformation_;
360 };
361
363
374 inline MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model,
375 const MatchingParameters &parameters)
376 {
377 MatchingResult result;
378
379 Internal::DoResCall([&]() {
380 return CVB_CALL_CAPI(CVM3DMatchPointCloudsAdvanced(
381 scene.Handle(), parameters.maxScenePoints_, model.Handle(), parameters.maxModelPoints_, parameters.params_,
382 result.rmsDistance_, result.numIterations_,
383 *reinterpret_cast<CExports::CVC3DTransformation *>(&result.transformation_)));
384 });
385
386 return result;
387 }
388
390
396 inline double DistanceRMS(const PointCloud &scene, const PointCloud &model)
397 {
398 return Internal::DoResCallValueOut<double>([&](double &value) {
399 return CVB_CALL_CAPI(CVM3DRmsDistanceOfPointClouds(scene.Handle(), model.Handle(), value));
400 });
401 }
402
403 } // namespace Match3D
404
405 CVB_END_INLINE_NS
406
407} // namespace Cvb
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition affine_matrix_3d.hpp:140
A parameter set for matching and down sampling point clouds.
Definition match_3d.hpp:54
void SetPrealign(bool value) noexcept
Set true, if pre-alignment of point clouds should be done using the center of gravity.
Definition match_3d.hpp:281
std::size_t MaxScenePoints() const noexcept
Gets maximum number of scene points to use.
Definition match_3d.hpp:143
void SetCorrespondenceThreshold(double value) noexcept
Sets special metric used for consensus ICP.
Definition match_3d.hpp:240
double Tolerance() const noexcept
Gets tolerance for stopping criteria.
Definition match_3d.hpp:184
CorrespondenceType CorrespondenceMethod() const noexcept
Gets correspondence type used.
Definition match_3d.hpp:291
void SetMaxIterations(int value) noexcept
Sets maximum number of iterations to execute.
Definition match_3d.hpp:173
double ConvergenceRadius() const noexcept
Gets convergence radius to define when two points are considered as a converged match.
Definition match_3d.hpp:250
MatchingParameters(std::size_t maxScenePoints, std::size_t maxModelPoints) noexcept
Create a parameter set to control the matching algorithm with default values.
Definition match_3d.hpp:75
friend MatchingResult IcpMatch(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters)
This function matches two point clouds.
Definition match_3d.hpp:374
void SetTolerance(double value) noexcept
Sets tolerance for stopping criteria.
Definition match_3d.hpp:194
void SetCorrespondenceMethod(CorrespondenceType value) noexcept
Sets correspondence type used.
Definition match_3d.hpp:301
MatchingParameters() noexcept
Create a parameter set to control the matching algorithm with default values.
Definition match_3d.hpp:65
void SetMaxScenePoints(std::size_t maxScenePoints) noexcept
Sets maximum number of scene points to use.
Definition match_3d.hpp:153
std::size_t MaxModelPoints() const noexcept
Gets maximum number of model points to use.
Definition match_3d.hpp:123
void SetConvergenceRadius(double value) noexcept
Sets convergence radius to define when two points are considered as a converged match.
Definition match_3d.hpp:261
double MinImprovement() const noexcept
Gets threshold for minimum improvement for early stopping criteria.
Definition match_3d.hpp:206
bool Prealign() const noexcept
Gets true, if pre-alignment of point clouds should be done using the center of gravity.
Definition match_3d.hpp:271
MatchingParameters(std::size_t maxScenePoints, std::size_t maxModelPoints, int maxIterations, double tolerance, double minImprovement, double correspondenceThreshold, double convergenceRadius, bool prealign, CorrespondenceType correspondenceMethod) noexcept
Create a parameter set to control the Match3d ICP algorithm.
Definition match_3d.hpp:100
void SetMinImprovement(double value) noexcept
Sets threshold for minimum improvement for early stopping criteria.
Definition match_3d.hpp:216
int MaxIterations() const noexcept
Gets maximum number of iterations to execute.
Definition match_3d.hpp:163
void SetMaxModelPoints(std::size_t maxModelPoints) noexcept
Sets maximum number of model points to use.
Definition match_3d.hpp:133
double CorrespondenceThreshold() const noexcept
Gets special metric used for consensus ICP.
Definition match_3d.hpp:228
Results of a matching and down sampling operation.
Definition match_3d.hpp:318
AffineMatrix3D Transformation() const noexcept
Get the affine transformation (rotation matrix and translation vector), which maps the scene to the m...
Definition match_3d.hpp:339
int NumIterations() const noexcept
Get number of iterations needed.
Definition match_3d.hpp:349
friend MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model, const MatchingParameters &parameters)
This function matches two point clouds.
Definition match_3d.hpp:374
double DistanceRMS() const noexcept
Get the final root mean square of distances between model and scene.
Definition match_3d.hpp:328
A point cloud object.
Definition decl_point_cloud.hpp:48
void * Handle() const noexcept
Returns C-API style handle to Node Object.
Definition decl_point_cloud.hpp:773
Namespace for Match3D ICP.
Definition match_3d.hpp:27
MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model, const MatchingParameters &parameters)
This function matches two point clouds.
Definition match_3d.hpp:374
CorrespondenceType
Correspondence type used for algorithm in Cvb::Match3D::IcpMatch.
Definition match_3d.hpp:31
@ ClassicICP
Definition match_3d.hpp:35
@ ConsensusICP
Definition match_3d.hpp:40
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17