36 #include "ndarray/eigen.h"
79 template <
typename Derived>
80 ndarray::Array<typename Eigen::MatrixBase<Derived>::Scalar, 2, 2> toNdArray(
81 Eigen::MatrixBase<Derived>
const &matrix) {
82 ndarray::Array<typename Eigen::MatrixBase<Derived>::Scalar, 2, 2> array =
83 ndarray::allocate(ndarray::makeVector(matrix.rows(), matrix.cols()));
84 ndarray::asEigenMatrix(array) = matrix;
99 return coeffs.size() > 1 && coeffs[0] == 0.0 && coeffs[1] != 0.0;
119 int const nCoeffs = coeffs.
size() - 1;
120 ndarray::Array<double, 2, 2>
const polyCoeffs = ndarray::allocate(ndarray::makeVector(nCoeffs, 3));
121 for (
size_t i = 1; i < coeffs.
size(); ++i) {
122 polyCoeffs[i - 1][0] = coeffs[i];
123 polyCoeffs[i - 1][1] = 1;
124 polyCoeffs[i - 1][2] = i;
127 return ast::PolyMap(polyCoeffs, 1,
"IterInverse=1, TolInverse=1e-8, NIterInverse=30");
135 Eigen::Matrix2d jacobian = original.
getJacobian(inPoint);
136 for (
int i = 0; i < 2; ++i) {
139 buffer <<
"Transform ill-defined: " << inPoint <<
" -> " << outPoint;
143 if (!jacobian.allFinite()) {
145 buffer <<
"Transform not continuous at " << inPoint <<
": J = " << jacobian;
150 auto offset = outPoint.asEigen() - jacobian * inPoint.asEigen();
162 return std::make_shared<TransformPoint2ToPoint2>(*map);
166 if (!areRadialCoefficients(coeffs)) {
168 buffer <<
"Invalid coefficient vector: " << coeffs;
172 if (coeffs.
empty()) {
173 return std::make_shared<TransformPoint2ToPoint2>(
ast::UnitMap(2));
178 ast::PolyMap const distortion = makeOneDDistortion(coeffs);
185 if (forwardCoeffs.
empty() != inverseCoeffs.
empty()) {
188 "makeRadialTransform must have either both empty or both non-empty coefficient vectors.");
190 if (forwardCoeffs.
empty()) {
192 return std::make_shared<TransformPoint2ToPoint2>(
ast::UnitMap(2));
195 if (!areRadialCoefficients(forwardCoeffs)) {
197 buffer <<
"Invalid forward coefficient vector: " << forwardCoeffs;
200 if (!areRadialCoefficients(inverseCoeffs)) {
202 buffer <<
"Invalid inverse coefficient vector: " << inverseCoeffs;
208 ast::PolyMap const forward = makeOneDDistortion(forwardCoeffs);
209 auto inverse = makeOneDDistortion(inverseCoeffs).inverted();
215 return std::make_shared<TransformPoint2ToPoint2>(
ast::UnitMap(2));