CVB++ 15.0
decl_calibrator_3d.hpp
1#pragma once
2
3#include <limits>
4#include <memory>
5#include <numeric>
6
7#include "../_cexports/c_core_3d.h"
8
9#include "../string.hpp"
10#include "../affine_matrix_3d.hpp"
11#include "../matrix_3d.hpp"
12#include "../matrix_3d_h.hpp"
13#include "../rect.hpp"
14#include "../size_2d.hpp"
15#include "../point_2d.hpp"
16
17#include "../core_3d.hpp"
18#include "../utilities/system_info.hpp"
19#include "../shims/stdoptional.hpp"
20
21#include "../_detail/detail_dyn_loader.hpp"
22
23namespace Cvb
24{
25
26 CVB_BEGIN_INLINE_NS
27
28 class Calibrator3D;
29 template <>
30 inline HandleGuard<Calibrator3D>::HandleGuard(void *handle) noexcept
31 : HandleGuard<Calibrator3D>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
32 {
33 }
34
35 namespace CExports
36 {
37
38 typedef cvbres_t(CVB_API *FP_CVMWrite3DCalibrator)(CVC3DCALIBRATOR Calibrator, const char *FileName);
39 typedef cvbres_t(CVB_API *FP_CVMWrite3DCalibratorW)(CVC3DCALIBRATOR Calibrator, const wchar_t *FileName);
40
41 inline cvbres_t _ppCVMWrite3DCalibratorTyped(CVC3DCALIBRATOR Calibrator, const char *FileName)
42 {
43 Internal::DynLoader loader(CVB_LIT("CVMetric"));
44 auto call = reinterpret_cast<FP_CVMWrite3DCalibrator>(loader.LoadSymbol(CVB_LIT("CVMWrite3DCalibrator")));
45 if (!call)
46 throw std::runtime_error("failed to load symbol: CVMWrite3DCalibrator");
47 return call(Calibrator, FileName);
48 }
49
50 inline cvbres_t _ppCVMWrite3DCalibratorTyped(CVC3DCALIBRATOR Calibrator, const wchar_t *FileName)
51 {
52 Internal::DynLoader loader(CVB_LIT("CVMetric"));
53 auto call = reinterpret_cast<FP_CVMWrite3DCalibratorW>(loader.LoadSymbol(CVB_LIT("CVMWrite3DCalibratorW")));
54 if (!call)
55 throw std::runtime_error("failed to load symbol: CVMWrite3DCalibratorW");
56 return call(Calibrator, FileName);
57 }
58
59 } // namespace CExports
60
66 class Calibrator3D
67 {
68 friend class Calibrator3DFactory;
69
70 protected:
71 struct ProtectedTag
72 {
73 };
74
75 public:
76 using GuardType = HandleGuard<Calibrator3D>;
77
78 Calibrator3D(HandleGuard<Calibrator3D> &&guard, ProtectedTag) noexcept
79 : handle_(std::move(guard))
80 {
81 }
82
83 Calibrator3D(const Calibrator3D &otehr) = delete;
84 Calibrator3D &operator=(const Calibrator3D &otehr) = delete;
85 Calibrator3D(Calibrator3D &&otehr) = delete;
86 Calibrator3D &operator=(Calibrator3D &&otehr) = delete;
87 virtual ~Calibrator3D() = default;
88
90
94 {
95 const auto value = Internal::DoResCallValueOut<double>([&](double &rangeMapIgnoreValue) {
96 return CVB_CALL_CAPI(CVC3DCalibratorGetRangeMapIgnoreValue(handle_.Handle(), rangeMapIgnoreValue));
97 });
98 if (std::isnan(value))
99 return {};
100 else
101 return value;
102 }
103
105
111 template <class T>
112 static std::shared_ptr<T> Load(const String &fileName);
113
115
119 {
120 CVB_CALL_CAPI(CVC3DCalibratorSetRangeMapIgnoreValue(
121 handle_.Handle(), rangeMapIgnoreValue.value_or(std::numeric_limits<double>::quiet_NaN())));
122 }
123
125
130 {
131 AffineMatrix3D transformation;
132 Internal::DoResCall([&]() {
133 return CVB_CALL_CAPI(CVC3DCalibratorGetExtrinsicMatrix(
134 Handle(), *reinterpret_cast<CExports::CVC3DTransformation *>(&transformation)));
135 });
136 return transformation;
137 }
138
141
145 void SetExtrinsicMatrix(const AffineMatrix3D &transformation)
146 {
147 Internal::DoResCall([&]() {
148 return CVB_CALL_CAPI(CVC3DCalibratorSetExtrinsicMatrix(
149 Handle(), *reinterpret_cast<const CExports::CVC3DTransformation *>(&transformation)));
150 });
151 }
152
154
160 void Save(const String &fileName) const
161 {
162 Internal::DoResCall([&]() { return CVB_CALL_CAPI(CVMWrite3DCalibratorTyped(Handle(), fileName.c_str())); });
163 }
164
166
173 static Calibrator3DPtr FromHandle(HandleGuard<Calibrator3D> &&guard);
174
175 template <class T>
176 static Calibrator3DPtr FromHandle(HandleGuard<Calibrator3D> &&guard)
177 {
178 return FromHandle(std::move(guard));
179 }
180
182
185 void *Handle() const noexcept
186 {
187 return handle_.Handle();
188 }
189
190 private:
191 enum class CalibratorType
192 {
193 Unknown = 0,
194 Factors,
195 LaserPlaneMatrixH,
196 LaserPlanePolynom,
197 LaserPlaneZigZag,
198 LaserPlaneAT,
199 MatrixH,
200 Pinhole
201 };
202
203 static CalibratorType TypeId(void *handle)
204 {
205 return static_cast<CalibratorType>(Internal::DoResCallValueOut<Cvb::CExports::CVC3DCalibratorType>(
206 [&](Cvb::CExports::CVC3DCalibratorType &type) {
207 return CVB_CALL_CAPI(CVC3DGetCalibratorType(handle, type));
208 }));
209 }
210
211 private:
212 HandleGuard<Calibrator3D> handle_;
213 };
214
215 CVB_END_INLINE_NS
216
217} // namespace Cvb
Affine transformation for 3D containing a transformation matrix and a translation vector.
Definition affine_matrix_3d.hpp:140
Base calibration class to apply 3D calibration to point clouds.
Definition decl_calibrator_3d.hpp:67
Cvb::optional< double > RangeMapIgnoreValue() const
Gets value to be ignored in range map.
Definition decl_calibrator_3d.hpp:93
void SetRangeMapIgnoreValue(Cvb::optional< double > rangeMapIgnoreValue)
Sets value to be ignored in range map in the calibrator.
Definition decl_calibrator_3d.hpp:118
static Calibrator3DPtr FromHandle(HandleGuard< Calibrator3D > &&guard)
Creates a calibrator from a classic API handle.
Definition detail_calibrator_3d.hpp:17
void Save(const String &fileName) const
Write the current content calibrator to a file.
Definition decl_calibrator_3d.hpp:160
AffineMatrix3D ExtrinsicMatrix() const
Gets the extrinsic transformation matrix (rigid body transformation) of the calibrator.
Definition decl_calibrator_3d.hpp:129
void * Handle() const noexcept
Returns C-API style handle to Node Object.
Definition decl_calibrator_3d.hpp:185
static std::shared_ptr< T > Load(const String &fileName)
Loads a 3D calibration from file.
Definition detail_calibrator_3d.hpp:43
void SetExtrinsicMatrix(const AffineMatrix3D &transformation)
Sets the extrinsic transformation matrix (rigid body transformation with rotation and translation) of...
Definition decl_calibrator_3d.hpp:145
This class is a replacement for C++17 std::optional.
Definition optional.hpp:61
T value_or(U &&default_value) const
Gets the contained value if has_value() is true; default_value otherwise.
Definition optional.hpp:385
cvbbool_t ReleaseObject(OBJ &Object)
T isnan(T... args)
T move(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
std::shared_ptr< Calibrator3D > Calibrator3DPtr
Convenience shared pointer for Calibrator3D.
Definition core_3d.hpp:52
@ Unknown
Definition global.hpp:136
T quiet_NaN(T... args)