lsst.afw  15.0-17-g0b88e3da8+6
GridTransform.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
29 
30 namespace lsst {
31 namespace afw {
32 namespace geom {
33 namespace ellipses {
34 
36  : _input(input), _eig(Quadrupole(input).getMatrix()) {}
37 
38 LinearTransform::Matrix BaseCore::GridTransform::getMatrix() const { return _eig.operatorInverseSqrt(); }
39 
40 BaseCore::GridTransform::operator LinearTransform() const {
41  return LinearTransform(_eig.operatorInverseSqrt());
42 }
43 
45  /*
46  Grid transform is easiest to differentiate in the ReducedShear/DeterminantRadius parametrization.
47  But we actually differentiate the inverse of the transform, and then use
48  $dM^{-1}/dt = -M^{-1} dM/dt M^{-1} to compute the derivative of the inverse.
49 
50  The inverse of the grid transform in ReducedShear/DeterminantRadius is:
51  $\frac{r}{\sqrt{1-g^2}}(\sigma_x + g_1 \sigma_z + g2 \sigma_y)$, where $\sigma_i$ are the
52  Pauli spin matrices.
53  */
55  C core;
56  Jacobian rhs = core.dAssign(_input);
57  double g1 = core.getE1();
58  double g2 = core.getE2();
59  double g = core.getEllipticity().getE();
60  double r = core.getRadius();
61  double beta = 1.0 - g * g;
62  double alpha = r / std::sqrt(beta);
63 
64  Eigen::Matrix2d sigma_z, sigma_y;
65  sigma_z << 1.0, 0.0, 0.0, -1.0;
66  sigma_y << 0.0, 1.0, 1.0, 0.0;
67  Eigen::Matrix2d t = _eig.operatorSqrt();
68  Eigen::Matrix2d tInv = _eig.operatorInverseSqrt();
69  Eigen::Matrix2d dt_dg1 = t * g1 / beta + alpha * sigma_z;
70  Eigen::Matrix2d dt_dg2 = t * g2 / beta + alpha * sigma_y;
71  Eigen::Matrix2d dt_dr = t * (1.0 / r);
72  Eigen::Matrix2d dtInv_dg1 = -tInv * dt_dg1 * tInv;
73  Eigen::Matrix2d dtInv_dg2 = -tInv * dt_dg2 * tInv;
74  Eigen::Matrix2d dtInv_dr = -tInv * dt_dr * tInv;
75 
77  mid(LinearTransform::XX, C::E1) = dtInv_dg1(0, 0);
78  mid(LinearTransform::XY, C::E1) = mid(LinearTransform::YX, C::E1) = dtInv_dg1(0, 1);
79  mid(LinearTransform::YY, C::E1) = dtInv_dg1(1, 1);
80  mid(LinearTransform::XX, C::E2) = dtInv_dg2(0, 0);
81  mid(LinearTransform::XY, C::E2) = mid(LinearTransform::YX, C::E2) = dtInv_dg2(0, 1);
82  mid(LinearTransform::YY, C::E2) = dtInv_dg2(1, 1);
83  mid(LinearTransform::XX, C::RADIUS) = dtInv_dr(0, 0);
84  mid(LinearTransform::XY, C::RADIUS) = mid(LinearTransform::YX, C::RADIUS) = dtInv_dr(0, 1);
85  mid(LinearTransform::YY, C::RADIUS) = dtInv_dr(1, 1);
86  return mid * rhs;
87 }
88 
89 double BaseCore::GridTransform::getDeterminant() const { return sqrt(1.0 / _eig.eigenvalues().prod()); }
90 
91 LinearTransform BaseCore::GridTransform::invert() const { return LinearTransform(_eig.operatorSqrt()); }
92 
93 Ellipse::GridTransform::GridTransform(Ellipse const& input) : _input(input), _coreGt(input.getCore()) {}
94 
96  AffineTransform::Matrix r = AffineTransform::Matrix::Zero();
97  r.block<2, 2>(0, 0) = _coreGt.getMatrix();
98  r.block<2, 1>(0, 2) = -r.block<2, 2>(0, 0) * _input.getCenter().asEigen();
99  r(2, 2) = 1.0;
100  return r;
101 }
102 
104  DerivativeMatrix r = DerivativeMatrix::Zero();
105  LinearTransform linear = _coreGt;
106  r.block<4, 3>(0, 0) = _coreGt.d();
107  double x = -_input.getCenter().getX();
108  double y = -_input.getCenter().getY();
113  r(AffineTransform::X, 0) = x * r(AffineTransform::XX, 0) + y * r(AffineTransform::XY, 0);
114  r(AffineTransform::Y, 0) = x * r(AffineTransform::YX, 0) + y * r(AffineTransform::YY, 0);
115  r(AffineTransform::X, 1) = x * r(AffineTransform::XX, 1) + y * r(AffineTransform::XY, 1);
116  r(AffineTransform::Y, 1) = x * r(AffineTransform::YX, 1) + y * r(AffineTransform::YY, 1);
117  r(AffineTransform::X, 2) = x * r(AffineTransform::XX, 2) + y * r(AffineTransform::XY, 2);
118  r(AffineTransform::Y, 2) = x * r(AffineTransform::YX, 2) + y * r(AffineTransform::YY, 2);
119  return r;
120 }
121 
122 double Ellipse::GridTransform::getDeterminant() const { return _coreGt.getDeterminant(); }
123 
124 Ellipse::GridTransform::operator AffineTransform() const {
125  LinearTransform linear = _coreGt;
126  return AffineTransform(linear, linear(Point2D() - _input.getCenter()));
127 }
128 
130  return AffineTransform(_coreGt.invert(), afw::geom::Extent2D(_input.getCenter()));
131 }
132 }
133 }
134 }
135 } // namespace lsst::afw::geom::ellipses
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Jacobian dAssign(BaseCore const &other)
Assign other to this and return the derivative of the conversion, d(this)/d(other).
Definition: BaseCore.cc:169
Extent< double, 2 > Extent2D
Definition: Extent.h:383
DerivativeMatrix d() const
Return the derivative of the transform with respect to input core.
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
double getDeterminant() const
Return the determinant of the LinearTransform.
A 2D linear coordinate transformation.
Eigen::Matrix< double, 4, 3 > DerivativeMatrix
Matrix type for derivative with respect to ellipse parameters.
Definition: GridTransform.h:51
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
A base class for image defects.
AffineTransform::Matrix getMatrix() const
Return the transform matrix as an Eigen object.
Point< double, 2 > Point2D
Definition: Point.h:304
An affine coordinate transformation consisting of a linear transformation and an offset.
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
double getDeterminant() const
Return the determinant of the AffineTransform.
double x
LinearTransform invert() const
Return the inverse of the LinearTransform;.
GridTransform(BaseCore const &input)
Standard constructor.
AffineTransform invert() const
Return the inverse of the AffineTransform.
GridTransform(Ellipse const &input)
Standard constructor.
An ellipse core with a complex ellipticity and radius parameterization.
Definition: radii.h:44
Eigen::Matrix3d Jacobian
Parameter Jacobian matrix type.
Definition: BaseCore.h:64
Point2D const & getCenter() const
Return the center point.
Definition: Ellipse.h:62
A base class for parametrizations of the "core" of an ellipse - the ellipticity and size...
Definition: BaseCore.h:55
T sqrt(T... args)
Eigen::Matrix< double, 6, 5 > DerivativeMatrix
Matrix type for derivative with respect to input ellipse parameters.
Definition: GridTransform.h:83
LinearTransform::Matrix getMatrix() const
Return the transform matrix as an Eigen object.
int y
Definition: SpanSet.cc:44
DerivativeMatrix d() const
Return the derivative of transform with respect to input ellipse.