CVB++ 14.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
21namespace Match3D
22{
23
25class MatchingResult;
26
27inline MatchingResult
28MatchDownSampledPointClouds(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters);
29
35{
36 friend MatchingResult
37 MatchDownsampledPointClouds(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters);
38
39public:
41
46 MatchingParameters(std::size_t maxModelPoints, std::size_t maxScenePoints) noexcept
47 {
48 SetMaxModelPoints(maxModelPoints);
49 SetMaxScenePoints(maxScenePoints);
50 }
51
53
62 std::size_t maxScenePoints,
63 int maxIterations,
64 double maxDistanceStdDev,
65 double deltaThresholdRMS) noexcept
66 {
67 SetMaxModelPoints(maxModelPoints);
68 SetMaxScenePoints(maxScenePoints);
69 SetMaxIterations(maxIterations);
70 SetMaxDistanceStdDev(maxDistanceStdDev);
71 SetDeltaThresholdRMS(deltaThresholdRMS);
72 }
73
75
79 std::size_t MaxModelPoints() const noexcept { return static_cast<std::size_t>(maxModelPoints_); }
80
82
86 void SetMaxModelPoints(std::size_t maxModelPoints) noexcept
87 {
88 maxModelPoints_ = static_cast<std::int64_t>(maxModelPoints);
89 }
90
92
96 std::size_t MaxScenePoints() const noexcept { return static_cast<std::size_t>(maxScenePoints_); }
97
99
103 void SetMaxScenePoints(std::size_t maxScenePoints) noexcept
104 {
105 maxScenePoints_ = static_cast<std::int64_t>(maxScenePoints);
106 }
107
109
113 int MaxIterations() const noexcept { return static_cast<int>(params_.MaxIterations); }
114
116
120 void SetMaxIterations(int maxIterations) noexcept
121 {
122 params_.MaxIterations = static_cast<CExports::cvbval_t>(maxIterations);
123 }
124
126
130 double MaxDistanceStdDev() const noexcept { return params_.MaxDistanceStdDev; }
131
133
137 void SetMaxDistanceStdDev(double maxDistanceStdDev) noexcept { params_.MaxDistanceStdDev = maxDistanceStdDev; }
138
140
144 double DeltaThresholdRMS() const noexcept { return params_.DeltaRmsThreshold; }
145
147
151 void SetDeltaThresholdRMS(double deltaThresholdRMS) noexcept { params_.DeltaRmsThreshold = deltaThresholdRMS; }
152
153private:
154 std::int64_t maxModelPoints_;
155 std::int64_t maxScenePoints_;
156
157 CExports::CVM3DMatchParameters params_ = CExports::CVM3DDefaultParameters;
158};
159
164class MatchingResult final
165{
166 friend MatchingResult
167 MatchDownsampledPointClouds(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters);
168
169public:
171
175 double DistanceRMS() const noexcept { return rmsDistance_; }
176
178
182 AffineMatrix3D Transformation() const noexcept { return transformation_; }
183
185
189 int NumIterations() const noexcept { return numIterations_; }
190
191private:
192 MatchingResult() noexcept = default;
193
194 double rmsDistance_;
195 CExports::cvbval_t numIterations_;
196 AffineMatrix3D transformation_;
197};
198
200
210inline MatchingResult
211MatchDownsampledPointClouds(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters)
212{
213 MatchingResult result;
214 Internal::DoResCall([&]() {
215 return CVB_CALL_CAPI(
216 CVM3DMatchDownsampledPointClouds(model.Handle(),
217 parameters.maxModelPoints_,
218 scene.Handle(),
219 parameters.maxScenePoints_,
220 parameters.params_,
221 result.rmsDistance_,
222 result.numIterations_,
223 *reinterpret_cast<CExports::CVC3DTransformation *>(&result.transformation_)));
224 });
225 return result;
226}
227
229
235inline double DistanceRMS(const PointCloud &model, const PointCloud &scene)
236{
237 return Internal::DoResCallValueOut<double>([&](double &value) {
238 return CVB_CALL_CAPI(CVM3DRmsDistanceOfPointClouds(model.Handle(), scene.Handle(), value));
239 });
240}
241
242}
243
244CVB_END_INLINE_NS
245
246}
Affine transformation matrix for 3D.
Definition: affine_matrix_3d.hpp:98
A parameter set for matching and down sampling point clouds.
Definition: match_3d.hpp:35
std::size_t MaxScenePoints() const noexcept
Gets maximum number of scene points to use.
Definition: match_3d.hpp:96
void SetMaxIterations(int maxIterations) noexcept
Sets maximum number of iterations to execute.
Definition: match_3d.hpp:120
double MaxDistanceStdDev() const noexcept
Gets how far points are to be considered corresponding to a point.
Definition: match_3d.hpp:130
void SetMaxDistanceStdDev(double maxDistanceStdDev) noexcept
Sets how far points are to be considered corresponding to a point.
Definition: match_3d.hpp:137
MatchingParameters(std::size_t maxModelPoints, std::size_t maxScenePoints) noexcept
Create a parameter set to control the matching algorithm.
Definition: match_3d.hpp:46
void SetDeltaThresholdRMS(double deltaThresholdRMS) noexcept
Sets the threshold for RMS to stop iteration.
Definition: match_3d.hpp:151
void SetMaxScenePoints(std::size_t maxScenePoints) noexcept
Sets maximum number of scene points to use.
Definition: match_3d.hpp:103
std::size_t MaxModelPoints() const noexcept
Gets maximum number of model points to use.
Definition: match_3d.hpp:79
MatchingParameters(std::size_t maxModelPoints, std::size_t maxScenePoints, int maxIterations, double maxDistanceStdDev, double deltaThresholdRMS) noexcept
Create a parameter set to control the matching algorithm.
Definition: match_3d.hpp:61
int MaxIterations() const noexcept
Gets maximum number of iterations to execute.
Definition: match_3d.hpp:113
double DeltaThresholdRMS() const noexcept
Gets the threshold for RMS to stop iteration.
Definition: match_3d.hpp:144
void SetMaxModelPoints(std::size_t maxModelPoints) noexcept
Sets maximum number of model points to use.
Definition: match_3d.hpp:86
friend MatchingResult MatchDownsampledPointClouds(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters)
This function matches two point clouds.
Definition: match_3d.hpp:211
Results of a matching and down sampling operation.
Definition: match_3d.hpp:165
AffineMatrix3D Transformation() const noexcept
Get the affine transformation (rotation matrix and translation vector), which maps the scene to the m...
Definition: match_3d.hpp:182
int NumIterations() const noexcept
Get number of iterations needed.
Definition: match_3d.hpp:189
double DistanceRMS() const noexcept
Get the final root mean square of distances between model and scene.
Definition: match_3d.hpp:175
friend MatchingResult MatchDownsampledPointClouds(const PointCloud &model, const PointCloud &scene, const MatchingParameters &parameters)
This function matches two point clouds.
Definition: match_3d.hpp:211
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:767
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24