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
12CVB_BEGIN_INLINE_NS
13
15
25namespace Match3D
26{
27
30{
34 ClassicICP = CExports::CVM3DCT_ClassicICP,
35
39 ConsensusICP = CExports::CVM3DCT_ConsensusICP
40};
41
42class MatchingParameters;
43class MatchingResult;
44
45inline MatchingResult
46IcpMatch(const PointCloud &scene, const PointCloud &model, const MatchingParameters &parameters);
47
53{
54 friend MatchingResult
55 IcpMatch(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters);
56
57public:
59
65 {
66 }
67
69
76 MatchingParameters(std::size_t maxScenePoints, std::size_t maxModelPoints) noexcept
77 {
78 SetMaxModelPoints(maxModelPoints);
79 SetMaxScenePoints(maxScenePoints);
80 }
81
83
102 std::size_t maxModelPoints,
103 int maxIterations, double tolerance,
104 double minImprovement, double correspondenceThreshold,
105 double convergenceRadius, bool prealign, CorrespondenceType correspondenceMethod) noexcept
106 {
107 SetMaxModelPoints(maxModelPoints);
108 SetMaxScenePoints(maxScenePoints);
109
110 params_.major = static_cast<Cvb::CExports::cvbint32_t>(0);
111 params_.minor = static_cast<Cvb::CExports::cvbint32_t>(1);
112 SetMaxIterations(maxIterations);
113 SetTolerance(tolerance);
114 SetMinImprovement(minImprovement);
115 SetCorrespondenceThreshold(correspondenceThreshold);
116 SetConvergenceRadius(convergenceRadius);
117 SetPrealign(prealign);
118 SetCorrespondenceMethod(correspondenceMethod);
119 }
120
122
126 std::size_t MaxModelPoints() const noexcept
127 {
128 return static_cast<std::size_t>(maxModelPoints_);
129 }
130
132
136 void SetMaxModelPoints(std::size_t maxModelPoints) noexcept
137 {
138 maxModelPoints_ = static_cast<std::int64_t>(maxModelPoints);
139 }
140
142
146 std::size_t MaxScenePoints() const noexcept
147 {
148 return static_cast<std::size_t>(maxScenePoints_);
149 }
150
152
156 void SetMaxScenePoints(std::size_t maxScenePoints) noexcept
157 {
158 maxScenePoints_ = static_cast<std::int64_t>(maxScenePoints);
159 }
160
162
166 int MaxIterations() const noexcept
167 {
168 return static_cast<int>(params_.MaxIterations);
169 }
170
172
176 void SetMaxIterations(int value) noexcept
177 {
178 params_.MaxIterations = static_cast<Cvb::CExports::cvbval_t>(value);
179 }
180
182
187 double Tolerance() const noexcept
188 {
189 return params_.Tolerance;
190 }
191
193
197 void SetTolerance(double value) noexcept
198 {
199 params_.Tolerance = value;
200 }
201
203
209 double MinImprovement() const noexcept
210 {
211 return params_.MinImprovement;
212 }
213
215
219 void SetMinImprovement(double value) noexcept
220 {
221 params_.MinImprovement = value;
222 }
223
225
231 double CorrespondenceThreshold() const noexcept
232 {
233 return params_.CorrespondenceThreshold;
234 }
235
237
243 void SetCorrespondenceThreshold(double value) noexcept
244 {
245 params_.CorrespondenceThreshold = value;
246 }
247
249
253 double ConvergenceRadius() const noexcept
254 {
255 return params_.ConvergenceRadius;
256 }
257
259
264 void SetConvergenceRadius(double value) noexcept
265 {
266 params_.ConvergenceRadius = value;
267 }
268
270
274 bool Prealign() const noexcept
275 {
276 return static_cast<bool>(params_.Prealign);
277 }
278
280
284 void SetPrealign(bool value) noexcept
285 {
286 params_.Prealign = static_cast<Cvb::CExports::cvbbool_t>(value);
287 }
288
290
295 {
296 return static_cast<CorrespondenceType>(params_.CorrespondenceMethod);
297 }
298
300
305 {
306 params_.CorrespondenceMethod = static_cast<Cvb::CExports::CVM3DCorrespondenceType>(value);
307 }
308
309private:
310 std::int64_t maxModelPoints_ = 0;
311 std::int64_t maxScenePoints_ = 0;
312
313 CExports::CVM3DMatchParameters params_ = CExports::CVM3DDefaultParameters;
314};
315
320class MatchingResult final
321{
322 friend MatchingResult
323 IcpMatch(const PointCloud &scene, const PointCloud& model, const MatchingParameters &parameters);
324
325public:
327
331 double DistanceRMS() const noexcept
332 {
333 return rmsDistance_;
334 }
335
337
342 {
343 return transformation_;
344 }
345
347
351 int NumIterations() const noexcept
352 {
353 return numIterations_;
354 }
355
356private:
357 MatchingResult() noexcept = default;
358
359 double rmsDistance_ = std::numeric_limits<double>::quiet_NaN();
360 CExports::cvbval_t numIterations_ = 0;
361 AffineMatrix3D transformation_;
362};
363
365
375inline MatchingResult
376IcpMatch(const PointCloud &scene, const PointCloud &model, const MatchingParameters &parameters)
377{
378 MatchingResult result;
379
380 Internal::DoResCall([&]() {
381 return CVB_CALL_CAPI(
382 CVM3DMatchPointCloudsAdvanced(
383 scene.Handle(),
384 parameters.maxScenePoints_,
385 model.Handle(),
386 parameters.maxModelPoints_,
387 parameters.params_,
388 result.rmsDistance_,
389 result.numIterations_,
390 *reinterpret_cast<CExports::CVC3DTransformation*>(&result.transformation_)));
391 });
392
393 return result;
394}
395
397
403inline double DistanceRMS(const PointCloud &scene, const PointCloud& model)
404{
405 return Internal::DoResCallValueOut<double>([&](double &value) {
406 return CVB_CALL_CAPI(CVM3DRmsDistanceOfPointClouds(scene.Handle(), model.Handle(), value));
407 });
408}
409
410}
411
412CVB_END_INLINE_NS
413
414}
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition: affine_matrix_3d.hpp:147
A parameter set for matching and down sampling point clouds.
Definition: match_3d.hpp:53
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:284
std::size_t MaxScenePoints() const noexcept
Gets maximum number of scene points to use.
Definition: match_3d.hpp:146
void SetCorrespondenceThreshold(double value) noexcept
Sets special metric used for consensus ICP.
Definition: match_3d.hpp:243
double Tolerance() const noexcept
Gets tolerance for stopping criteria.
Definition: match_3d.hpp:187
CorrespondenceType CorrespondenceMethod() const noexcept
Gets correspondence type used.
Definition: match_3d.hpp:294
void SetMaxIterations(int value) noexcept
Sets maximum number of iterations to execute.
Definition: match_3d.hpp:176
double ConvergenceRadius() const noexcept
Gets convergence radius to define when two points are considered as a converged match.
Definition: match_3d.hpp:253
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:76
friend MatchingResult IcpMatch(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters)
This function matches two point clouds.
Definition: match_3d.hpp:376
void SetTolerance(double value) noexcept
Sets tolerance for stopping criteria.
Definition: match_3d.hpp:197
void SetCorrespondenceMethod(CorrespondenceType value) noexcept
Sets correspondence type used.
Definition: match_3d.hpp:304
MatchingParameters() noexcept
Create a parameter set to control the matching algorithm with default values.
Definition: match_3d.hpp:64
void SetMaxScenePoints(std::size_t maxScenePoints) noexcept
Sets maximum number of scene points to use.
Definition: match_3d.hpp:156
std::size_t MaxModelPoints() const noexcept
Gets maximum number of model points to use.
Definition: match_3d.hpp:126
void SetConvergenceRadius(double value) noexcept
Sets convergence radius to define when two points are considered as a converged match.
Definition: match_3d.hpp:264
double MinImprovement() const noexcept
Gets threshold for minimum improvement for early stopping criteria.
Definition: match_3d.hpp:209
bool Prealign() const noexcept
Gets true, if pre-alignment of point clouds should be done using the center of gravity.
Definition: match_3d.hpp:274
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:101
void SetMinImprovement(double value) noexcept
Sets threshold for minimum improvement for early stopping criteria.
Definition: match_3d.hpp:219
int MaxIterations() const noexcept
Gets maximum number of iterations to execute.
Definition: match_3d.hpp:166
void SetMaxModelPoints(std::size_t maxModelPoints) noexcept
Sets maximum number of model points to use.
Definition: match_3d.hpp:136
double CorrespondenceThreshold() const noexcept
Gets special metric used for consensus ICP.
Definition: match_3d.hpp:231
Results of a matching and down sampling operation.
Definition: match_3d.hpp:321
AffineMatrix3D Transformation() const noexcept
Get the affine transformation (rotation matrix and translation vector), which maps the scene to the m...
Definition: match_3d.hpp:341
int NumIterations() const noexcept
Get number of iterations needed.
Definition: match_3d.hpp:351
friend MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model, const MatchingParameters &parameters)
This function matches two point clouds.
Definition: match_3d.hpp:376
double DistanceRMS() const noexcept
Get the final root mean square of distances between model and scene.
Definition: match_3d.hpp:331
A point cloud object.
Definition: decl_point_cloud.hpp:49
void * Handle() const noexcept
Returns C-API style handle to Node Object.
Definition: decl_point_cloud.hpp:768
MatchingResult IcpMatch(const PointCloud &scene, const PointCloud &model, const MatchingParameters &parameters)
This function matches two point clouds.
Definition: match_3d.hpp:376
CorrespondenceType
Correspondence type used for algorithm in Cvb::Match3D::IcpMatch.
Definition: match_3d.hpp:30
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24