CVB++ 15.0
Loading...
Searching...
No Matches
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
61 namespace Metric
62 {
64
77 const std::vector<Point3D<double>> &measuredPoints)
78 {
79 if (referencePoints.size() != measuredPoints.size())
80 throw std::invalid_argument("vector of reference and measured points must have the same size");
81
82 AffineMatrix3D trafo;
83 Internal::DoResCall([&]() {
84 return CVB_CALL_CAPI(
85 CVMCalculateAffineTransformation(reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
86 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
87 static_cast<CExports::cvbdim_t>(referencePoints.size()),
88 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo)));
89 });
90
91 return trafo;
92 }
93
95
113 const std::vector<Point3D<double>> &referencePoints, const std::vector<Point3D<double>> &measuredPoints,
116 bool estimateEncoderStep = true, bool calculateResiduals = true)
117 {
118 if (referencePoints.size() != measuredPoints.size())
119 throw std::invalid_argument("vector of reference and measured points must have the same size");
120
121 AffineMatrix3D trafo;
123
124 if (calculateResiduals)
125 {
126 auto residuals = std::vector<Point3D<double>>(referencePoints.size());
127
128 Internal::DoResCall([&]() {
129 return CVB_CALL_CAPI(CVMCalculateCorrectionOfLaserPlaneInclinationWithParams(
130 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
131 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
132 static_cast<CExports::cvbdim_t>(referencePoints.size()),
133 static_cast<CExports::CVMExtrinsicTransformationModel>(model),
134 static_cast<CExports::cvbbool_t>(estimateEncoderStep),
135 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
136 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara),
137 reinterpret_cast<CExports::CVC3DPointD *>(residuals.data())));
138 });
139
140 if (!std::isnan(trafoPara.InclinationX))
141 return std::make_tuple(std::move(trafo), std::move(residuals), std::move(trafoPara));
142 else
143 return std::make_tuple(std::move(trafo), std::move(residuals),
145 }
146 else
147 {
148 Internal::DoResCall([&]() {
149 return CVB_CALL_CAPI(CVMCalculateCorrectionOfLaserPlaneInclinationWithParams(
150 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
151 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
152 static_cast<CExports::cvbdim_t>(referencePoints.size()),
153 static_cast<CExports::CVMExtrinsicTransformationModel>(model),
154 static_cast<CExports::cvbbool_t>(estimateEncoderStep),
155 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
156 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara), nullptr));
157 });
158
159 if (!std::isnan(trafoPara.InclinationX))
161 std::move(trafoPara));
162 else
165 }
166 }
167
169
180 const std::vector<Point3D<double>> &measuredPoints,
181 bool calculateResiduals = true)
182 {
183 if (referencePoints.size() != measuredPoints.size())
184 throw std::invalid_argument("vector of reference and measured points must have the same size");
185
186 AffineMatrix3D trafo;
188
189 if (calculateResiduals)
190 {
191 auto residuals = std::vector<Point3D<double>>(referencePoints.size());
192
193 Internal::DoResCall([&]() {
194 return CVB_CALL_CAPI(CVMCalculateRigidBodyTransformationWithParams(
195 reinterpret_cast<const CExports::CVC3DPointD *>(referencePoints.data()),
196 reinterpret_cast<const CExports::CVC3DPointD *>(measuredPoints.data()),
197 static_cast<CExports::cvbdim_t>(referencePoints.size()),
198 *reinterpret_cast<CExports::CVC3DTransformation *>(&trafo),
199 *reinterpret_cast<CExports::CVC3DAffineTransformationParameters *>(&trafoPara),
200 reinterpret_cast<CExports::CVC3DPointD *>(residuals.data())));
201 });
202
203 return std::make_tuple(std::move(trafo), std::move(residuals), std::move(trafoPara));
204 }
205 else
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), nullptr));
214 });
215
217 }
218 }
219 } // namespace Metric
220 } // namespace Foundation
221 CVB_END_INLINE_NS
222} // 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:86
@ SpecificTransformationParameters
Transformation parameters like rotation, scale and shear are estimated (recommended).
Definition decl_metric_calibration_configuration.hpp:99
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:22
Namespace for metric calibration.
Definition decl_metric_aqs12_calibration_piece.hpp:19
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:112
AffineMatrix3D CalculateAffineTransformation(const std::vector< Point3D< double > > &referencePoints, const std::vector< Point3D< double > > &measuredPoints)
Calculates an affine transformation.
Definition metric.hpp:76
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:179
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