36 #include "ndarray/eigen.h" 54 std::ostream &operator<<(std::ostream &os, std::vector<T>
const &v) {
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 array.asEigen() = 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=20");
134 Eigen::Matrix2d jacobian = original.
getJacobian(inPoint);
135 for (
int i = 0; i < 2; ++i) {
138 buffer <<
"Transform ill-defined: " << inPoint <<
" -> " << outPoint;
142 if (!jacobian.allFinite()) {
144 buffer <<
"Transform not continuous at " << inPoint <<
": J = " << jacobian;
149 auto offset = outPoint.asEigen() - jacobian * inPoint.
asEigen();
160 return std::make_shared<TransformPoint2ToPoint2>(*map);
164 if (!areRadialCoefficients(coeffs)) {
166 buffer <<
"Invalid coefficient vector: " << coeffs;
170 if (coeffs.
empty()) {
171 return std::make_shared<TransformPoint2ToPoint2>(
ast::UnitMap(2));
176 ast::PolyMap const distortion = makeOneDDistortion(coeffs);
183 if (forwardCoeffs.
empty() != inverseCoeffs.
empty()) {
186 "makeRadialTransform must have either both empty or both non-empty coefficient vectors.");
188 if (forwardCoeffs.
empty()) {
190 return std::make_shared<TransformPoint2ToPoint2>(
ast::UnitMap(2));
193 if (!areRadialCoefficients(forwardCoeffs)) {
195 buffer <<
"Invalid forward coefficient vector: " << forwardCoeffs;
198 if (!areRadialCoefficients(inverseCoeffs)) {
200 buffer <<
"Invalid inverse coefficient vector: " << inverseCoeffs;
206 ast::PolyMap const forward = makeOneDDistortion(forwardCoeffs);
207 auto inverse = makeOneDDistortion(inverseCoeffs).getInverse();
213 return std::make_shared<TransformPoint2ToPoint2>(
ast::UnitMap(2));
std::shared_ptr< TransformPoint2ToPoint2 > makeIdentityTransform()
Trivial Transform x → x.
std::shared_ptr< TransformPoint2ToPoint2 > makeRadialTransform(std::vector< double > const &coeffs)
A purely radial polynomial distortion.
SeriesMap then(Mapping const &next) const
std::shared_ptr< Mapping > simplify() const
A coordinate class intended to represent absolute positions.
AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, Point2D const &inPoint)
Approximate a Transform by its local linearization.
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
A base class for image defects.
Point< double, 2 > Point2D
std::shared_ptr< Mapping > makeRadialMapping(std::vector< double > const ¢er, Mapping const &mapping1d)
virtual std::vector< double > dataFromPoint(Point const &point) const override
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(AffineTransform const &affine)
Wrap an AffineTransform as a Transform.
#define LSST_EXCEPT(type,...)