CVB++ 15.0
metric.hpp
1#pragma once
2
3#include "../affine_matrix_3d.hpp"
4#include "../_cexports/c_metric.h"
5
6#include "../point_cloud.hpp"
7#include "_decl/decl_metric_calibration_configuration.hpp"
8#include "_decl/decl_metric_segmentor_dense_point_cloud.hpp"
9#include "_decl/decl_metric_segmentor_range_map.hpp"
10
11namespace Cvb
12{
13 CVB_BEGIN_INLINE_NS
14
15 namespace Foundation
16 {
17 namespace Metric
18 {
19 using DensePointCloudSegmentorPtr = std::shared_ptr<DensePointCloudSegmentor>;
20 using RangeMapSegmentorPtr = std::shared_ptr<RangeMapSegmentor>;
21
24 {
27 };
28
31 {
33 KmeansClustering = CExports::CVMSM_KmeansClustering
34 };
35
37
43
45
51 } // namespace Metric
52 } // namespace Foundation
53
54 namespace Foundation
55 {
57
75 namespace Metric
76 {
78
91 const std::vector<Point3D<double>> &measuredPoints)
92 {
93 if (referencePoints.size() != measuredPoints.size())
94 throw std::invalid_argument("vector of reference and measured points must have the same size");
95
96 AffineMatrix3D trafo;
97 Internal::DoResCall([&]() {
98 return CVB_CALL_CAPI(
99 CVMCalculateAffineTransformation(reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
100 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
101 static_cast<CExports::cvbdim_t>(referencePoints.size()),
102 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo)));
103 });
104
105 return trafo;
106 }
107
109
127 const std::vector<Point3D<double>> &referencePoints, const std::vector<Point3D<double>> &measuredPoints,
130 bool estimateEncoderStep = true, bool calculateResiduals = true)
131 {
132 if (referencePoints.size() != measuredPoints.size())
133 throw std::invalid_argument("vector of reference and measured points must have the same size");
134
135 AffineMatrix3D trafo;
137
138 if (calculateResiduals)
139 {
140 auto residuals = std::vector<Point3D<double>>(referencePoints.size());
141
142 Internal::DoResCall([&]() {
143 return CVB_CALL_CAPI(CVMCalculateCorrectionOfLaserPlaneInclinationWithParams(
144 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
145 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
146 static_cast<CExports::cvbdim_t>(referencePoints.size()),
147 static_cast<CExports::CVMExtrinsicTransformationModel>(model),
148 static_cast<CExports::cvbbool_t>(estimateEncoderStep),
149 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
150 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara),
151 reinterpret_cast<CExports::CVC3DPointD *>(residuals.data())));
152 });
153
154 if (!std::isnan(trafoPara.InclinationX))
155 return std::make_tuple(std::move(trafo), std::move(residuals), std::move(trafoPara));
156 else
157 return std::make_tuple(std::move(trafo), std::move(residuals),
159 }
160 else
161 {
162 Internal::DoResCall([&]() {
163 return CVB_CALL_CAPI(CVMCalculateCorrectionOfLaserPlaneInclinationWithParams(
164 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
165 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
166 static_cast<CExports::cvbdim_t>(referencePoints.size()),
167 static_cast<CExports::CVMExtrinsicTransformationModel>(model),
168 static_cast<CExports::cvbbool_t>(estimateEncoderStep),
169 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
170 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara), nullptr));
171 });
172
173 if (!std::isnan(trafoPara.InclinationX))
175 std::move(trafoPara));
176 else
179 }
180 }
181
183
194 const std::vector<Point3D<double>> &measuredPoints,
195 bool calculateResiduals = true)
196 {
197 if (referencePoints.size() != measuredPoints.size())
198 throw std::invalid_argument("vector of reference and measured points must have the same size");
199
200 AffineMatrix3D trafo;
202
203 if (calculateResiduals)
204 {
205 auto residuals = std::vector<Point3D<double>>(referencePoints.size());
206
207 Internal::DoResCall([&]() {
208 return CVB_CALL_CAPI(CVMCalculateRigidBodyTransformationWithParams(
209 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
210 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
211 static_cast<CExports::cvbdim_t>(referencePoints.size()),
212 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
213 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara),
214 reinterpret_cast<CExports::CVC3DPointD *>(residuals.data())));
215 });
216
217 return std::make_tuple(std::move(trafo), std::move(residuals), std::move(trafoPara));
218 }
219 else
220 {
221 Internal::DoResCall([&]() {
222 return CVB_CALL_CAPI(CVMCalculateRigidBodyTransformationWithParams(
223 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
224 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
225 static_cast<CExports::cvbdim_t>(referencePoints.size()),
226 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
227 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara), nullptr));
228 });
229
231 }
232 }
233 } // namespace Metric
234 } // namespace Foundation
235 CVB_END_INLINE_NS
236} // namespace Cvb
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition affine_matrix_3d.hpp:140
ExtrinsicCalibrationModel
Enum for extrinsic calibration model.
Definition decl_metric_calibration_configuration.hpp:80
@ SpecificTransformationParameters
Transformation parameters like rotation, scale and shear are estimated (recommended).
Definition decl_metric_calibration_configuration.hpp:93
Multi-purpose 3D vector class.
Definition point_3d.hpp:22
This class is a replacement for C++17 std::optional.
Definition optional.hpp:61
T isnan(T... args)
T make_tuple(T... args)
T move(T... args)
Namespace specific to AQS12 calibration pieces.
Definition decl_metric_aqs12_calibration_piece.hpp:16
Namespace for metric calibration.
Definition decl_metric_aqs12_calibration_piece.hpp:13
TransformationResult CalculateCorrectionOfLaserPlaneInclination(const std::vector< Point3D< double > > &referencePoints, const std::vector< Point3D< double > > &measuredPoints, CalibrationConfiguration::ExtrinsicCalibrationModel model=CalibrationConfiguration::ExtrinsicCalibrationModel::SpecificTransformationParameters, bool estimateEncoderStep=true, bool calculateResiduals=true)
Calculates an extrinsic calibration and the correction for the laser plane inclination.
Definition metric.hpp:126
AffineMatrix3D CalculateAffineTransformation(const std::vector< Point3D< double > > &referencePoints, const std::vector< Point3D< double > > &measuredPoints)
Calculates an affine transformation.
Definition metric.hpp:90
RigidBodyTransformationResult CalculateRigidBodyTransformation(const std::vector< Point3D< double > > &referencePoints, const std::vector< Point3D< double > > &measuredPoints, bool calculateResiduals=true)
Calculates a rigid body transformation.
Definition metric.hpp:193
CalibrationPiece
Defines the calibration piece to use for face segmentation.
Definition metric.hpp:24
SegmentationMethod
Defines the segmentation method for labeling the faces of the calibration piece.
Definition metric.hpp:31
@ KmeansClustering
Clustering top, base and faces using kmeans.
Definition metric.hpp:33
std::tuple< AffineMatrix3D, Cvb::optional< std::vector< Point3D< double > > >, Cvb::optional< AffineTransformationParameters > > TransformationResult
Result for calculating an extrinsic transformation.
Definition metric.hpp:41
std::tuple< AffineMatrix3D, Cvb::optional< std::vector< Point3D< double > > >, AffineTransformationParameters > RigidBodyTransformationResult
Result for calculating a rigid body transformation.
Definition metric.hpp:49
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
Parameters of a 3D affine transformation matrix correcting an inclined laser plane.
Definition affine_matrix_3d.hpp:36
double InclinationX
Inclination of laser plane (rotation about x axis) in [degree].
Definition affine_matrix_3d.hpp:50