10 #include "IntrinsicScaleOffset.hpp"
11 #include "IntrinsicInitMode.hpp"
12 #include "Distortion.hpp"
13 #include "Undistortion.hpp"
32 std::shared_ptr<Distortion> distortion =
nullptr,
33 std::shared_ptr<Undistortion> undistortion =
nullptr)
35 _pDistortion(distortion),
36 _pUndistortion(undistortion)
41 _distortionInitializationMode(other._distortionInitializationMode)
43 if (other._pDistortion)
45 _pDistortion = std::shared_ptr<Distortion>(other._pDistortion->clone());
49 _pDistortion =
nullptr;
52 if (other._pUndistortion)
54 _pUndistortion = std::shared_ptr<Undistortion>(other._pUndistortion->clone());
58 _pUndistortion =
nullptr;
62 static std::shared_ptr<IntrinsicScaleOffsetDisto> cast(std::shared_ptr<IntrinsicBase> sptr);
81 void setDistortionObject(std::shared_ptr<Distortion>
object) { _pDistortion = object; }
83 bool hasDistortion()
const override {
return _pDistortion !=
nullptr || _pUndistortion !=
nullptr; }
94 return _pDistortion->addDistortion(p);
96 else if (_pUndistortion)
114 else if (_pDistortion)
116 return _pDistortion->removeDistortion(p);
127 std::size_t getDistortionParamsSize()
const
131 return _pDistortion->getParameters().size();
136 std::vector<double> getDistortionParams()
const
140 return std::vector<double>();
142 return _pDistortion->getParameters();
145 void setDistortionParams(
const std::vector<double>& distortionParams)
147 std::size_t expected = 0;
148 if (_pDistortion !=
nullptr)
150 expected = _pDistortion->getDistortionParametersCount();
153 if (distortionParams.size() != expected)
155 throwSetDistortionParamsCountError(expected, distortionParams.size());
160 _pDistortion->getParameters() = distortionParams;
165 void setDistortionParamsFn(F&& callback)
167 if (_pDistortion ==
nullptr)
170 auto& params = _pDistortion->getParameters();
171 for (std::size_t i = 0; i < params.size(); ++i)
173 params[i] = callback(i);
178 void setDistortionParamsFn(std::size_t count, F&& callback)
180 if (_pDistortion ==
nullptr)
184 throwSetDistortionParamsCountError(0, count);
189 auto& params = _pDistortion->getParameters();
190 if (params.size() != count)
192 throwSetDistortionParamsCountError(params.size(), count);
195 for (std::size_t i = 0; i < params.size(); ++i)
197 params[i] = callback(i);
204 std::vector<double> params = {_scale(0), _scale(1), _offset(0), _offset(1)};
214 float getMaximalDistortion([[maybe_unused]]
double minRadius,
double maxRadius)
const override
216 if (_pDistortion ==
nullptr)
221 return _pDistortion->getUndistortedRadius(maxRadius);
224 Eigen::Matrix<double, 2, 2> getDerivativeAddDistoWrtPt(
const Vec2& pt)
const
226 if (this->_pDistortion ==
nullptr)
228 return Eigen::Matrix<double, 2, 2>::Identity();
230 return this->_pDistortion->getDerivativeAddDistoWrtPt(pt);
233 Eigen::Matrix<double, 2, 2> getDerivativeRemoveDistoWrtPt(
const Vec2& pt)
const
235 if (this->_pDistortion ==
nullptr)
237 return Eigen::Matrix<double, 2, 2>::Identity();
240 return this->_pDistortion->getDerivativeRemoveDistoWrtPt(pt);
243 Eigen::MatrixXd getDerivativeAddDistoWrtDisto(
const Vec2& pt)
const
245 if (this->_pDistortion ==
nullptr)
247 return Eigen::MatrixXd(0, 0);
250 return this->_pDistortion->getDerivativeAddDistoWrtDisto(pt);
253 Eigen::MatrixXd getDerivativeRemoveDistoWrtDisto(
const Vec2& pt)
const
255 if (this->_pDistortion ==
nullptr)
257 return Eigen::MatrixXd(0, 0);
260 return this->_pDistortion->getDerivativeRemoveDistoWrtDisto(pt);
263 virtual Eigen::Matrix<double, 2, Eigen::Dynamic> getDerivativeTransformProjectWrtDistortion(
const Eigen::Matrix4d& pose,
264 const Vec4& pt)
const = 0;
266 virtual Eigen::Matrix<double, 3, Eigen::Dynamic> getDerivativeBackProjectUnitWrtDistortion(
const Vec2& pt2D)
const = 0;
274 _distortionInitializationMode = distortionInitializationMode;
283 std::shared_ptr<Distortion> getDistortion()
const {
return _pDistortion; }
287 void setUndistortionObject(std::shared_ptr<Undistortion>
object) { _pUndistortion = object; }
289 std::shared_ptr<Undistortion> getUndistortion()
const {
return _pUndistortion; }
292 void throwSetDistortionParamsCountError(std::size_t expected, std::size_t received)
295 s <<
"IntrinsicScaleOffsetDisto::setDistortionParams*: "
296 <<
"wrong number of distortion parameters (expected: " << expected <<
", given:" << received <<
").";
297 throw std::runtime_error(s.str());
300 std::shared_ptr<Distortion> _pDistortion;
301 std::shared_ptr<Undistortion> _pUndistortion;
304 EInitMode _distortionInitializationMode = EInitMode::NONE;