LSSTApplications  21.0.0+1b62c9342b,21.0.0+45a059f35e,21.0.0-1-ga51b5d4+ceb9cf20a3,21.0.0-17-gf9a0284+9e5b25d042,21.0.0-2-g103fe59+513edb8842,21.0.0-2-g1367e85+d9bb5204cb,21.0.0-2-g2909d54+45a059f35e,21.0.0-2-g45278ab+1b62c9342b,21.0.0-2-g4bc9b9f+36532ac5d2,21.0.0-2-g5242d73+d9bb5204cb,21.0.0-2-g54e2caa+0b4b33a26b,21.0.0-2-g66bcc37+0525a04256,21.0.0-2-g7f82c8f+8938dec807,21.0.0-2-g8dde007+7bfb5851c8,21.0.0-2-g8f08a60+73884b2cf5,21.0.0-2-g973f35b+44678ca34c,21.0.0-2-ga326454+8938dec807,21.0.0-2-ga63a54e+682c8ce20e,21.0.0-2-ga885a99+9a92674037,21.0.0-2-gc738bc1+5ce50b2a03,21.0.0-2-gde069b7+5a8f2956b8,21.0.0-2-ge17e5af+d9bb5204cb,21.0.0-2-ge712728+d5c34dc911,21.0.0-2-gecfae73+8bdf007ced,21.0.0-2-gfc62afb+d9bb5204cb,21.0.0-21-g006371a9+5abec3504c,21.0.0-3-g4c5b185+4e2de95c30,21.0.0-3-g6d51c4a+0525a04256,21.0.0-3-gaa929c8+fca53d2b73,21.0.0-3-gd222c45+afc8332dbe,21.0.0-3-gd5de2f2+0525a04256,21.0.0-4-g3300ddd+1b62c9342b,21.0.0-4-g8a80011+23661db33a,21.0.0-5-gb7080ec+ee9551b7be,21.0.0-5-gcff38f6+e51f0852ce,21.0.0-6-gd3283ba+fca53d2b73,21.0.0-8-g19111d86+898b2b281f,21.0.0-8-gd9c33f4a0+b58bb1f4d6,w.2021.03
LSSTDataManagementBasePackage
LinearTransform.h
Go to the documentation of this file.
1 /*
2  * Developed for the LSST Data Management System.
3  * This product includes software developed by the LSST Project
4  * (https://www.lsst.org).
5  * See the COPYRIGHT file at the top-level directory of this distribution
6  * for details of code ownership.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef LSST_GEOM_LINEAR_TRANSFORM_H
23 #define LSST_GEOM_LINEAR_TRANSFORM_H
24 
25 #include "Eigen/Core"
26 #include "Eigen/Geometry"
27 
29 #include "lsst/geom/Point.h"
30 #include "lsst/geom/Angle.h"
31 
32 namespace lsst {
33 namespace geom {
34 
37 
38 
69 class LinearTransform final {
70 public:
71  enum Parameters { XX = 0, YX = 1, XY = 2, YY = 3 };
72 
73  typedef Eigen::Matrix<double, 4, 1> ParameterVector;
74  typedef Eigen::Matrix<double, 2, 4> TransformDerivativeMatrix;
75  typedef Eigen::Matrix<double, 4, 4> ProductDerivativeMatrix;
76 
77  typedef Eigen::Matrix<double, 2, 2, Eigen::DontAlign> Matrix;
78 
80  LinearTransform() noexcept : _matrix(Matrix::Identity()) {}
81 
83  explicit LinearTransform(Matrix const& matrix) noexcept : _matrix(matrix) {}
84 
85  // Can't use both =default and noexcept until Eigen supports noexcept
86  LinearTransform(LinearTransform const& other) noexcept : _matrix(other._matrix){};
87  LinearTransform(LinearTransform&& other) noexcept : _matrix(std::move(other._matrix)){};
88  ~LinearTransform() noexcept = default;
89 
90  LinearTransform operator*(LinearTransform const& other) const noexcept {
91  return LinearTransform(getMatrix() * other.getMatrix());
92  }
93 
94  static LinearTransform makeScaling(double s) noexcept {
95  return LinearTransform((Matrix() << s, 0.0, 0.0, s).finished());
96  }
97 
98  static LinearTransform makeScaling(double s, double t) noexcept {
99  return LinearTransform((Matrix() << s, 0.0, 0.0, t).finished());
100  }
101 
102  static LinearTransform makeRotation(Angle t) noexcept {
103  return LinearTransform(Matrix(Eigen::Rotation2D<double>(t.asRadians())));
104  }
105 
106  // Can't use both =default and noexcept until Eigen supports noexcept
108  _matrix = other._matrix;
109  return *this;
110  }
112  _matrix = std::move(other._matrix);
113  return *this;
114  }
115 
117  _matrix += other._matrix;
118  return *this;
119  }
120 
122  LinearTransform tmp(*this);
123  tmp += other;
124  return tmp;
125  }
126 
128  _matrix -= other._matrix;
129  return *this;
130  }
131 
133  LinearTransform tmp(*this);
134  tmp -= other;
135  return tmp;
136  }
137 
143  ParameterVector const getParameterVector() const noexcept;
149  void setParameterVector(ParameterVector const& vector) noexcept;
150 
151  Matrix const& getMatrix() const noexcept { return _matrix; }
152  Matrix& getMatrix() noexcept { return _matrix; }
153 
154  double& operator[](int i) { return _matrix(i % 2, i / 2); }
155  double const& operator[](int i) const { return const_cast<Matrix&>(_matrix)(i % 2, i / 2); }
156 
162  LinearTransform const inverted() const;
163 
167  double computeDeterminant() const noexcept;
168 
170  bool isIdentity() const noexcept { return getMatrix().isIdentity(); }
171 
178  Point2D operator()(Point2D const& p) const noexcept { return Point2D(getMatrix() * p.asEigen()); }
179 
186  Extent2D operator()(Extent2D const& p) const noexcept { return Extent2D(getMatrix() * p.asEigen()); }
187 
189 
195  double applyX(double x, double y) const noexcept { return _matrix(0, 0)*x + _matrix(0, 1)*y; }
196  double applyY(double x, double y) const noexcept { return _matrix(1, 0)*x + _matrix(1, 1)*y; }
198 
202  TransformDerivativeMatrix dTransform(Point2D const& input) const noexcept;
203 
205  TransformDerivativeMatrix dTransform(Extent2D const& input) const noexcept {
206  return dTransform(Point2D(input));
207  }
208 
209 private:
210  Matrix _matrix;
211 };
212 
214 
215 } // namespace geom
216 } // namespace lsst
217 
218 #endif // !LSST_GEOM_LINEAR_TRANSFORM_H
lsst.pipe.tasks.cli.cmd.commands.default
default
Definition: commands.py:50
y
int y
Definition: SpanSet.cc:49
Angle.h
lsst::geom::LinearTransform::makeRotation
static LinearTransform makeRotation(Angle t) noexcept
Definition: LinearTransform.h:102
lsst::geom::LinearTransform::operator+=
LinearTransform & operator+=(LinearTransform const &other) noexcept
Definition: LinearTransform.h:116
lsst::geom::LinearTransform::getMatrix
Matrix & getMatrix() noexcept
Definition: LinearTransform.h:152
std::move
T move(T... args)
lsst::geom::LinearTransform
A 2D linear coordinate transformation.
Definition: LinearTransform.h:69
lsst::geom::LinearTransform::operator-
LinearTransform operator-(LinearTransform const &other) noexcept
Definition: LinearTransform.h:132
lsst::geom::LinearTransform::operator=
LinearTransform & operator=(LinearTransform const &other) noexcept
Definition: LinearTransform.h:107
lsst::geom::Point2D
Point< double, 2 > Point2D
Definition: Point.h:324
lsst::geom::LinearTransform::LinearTransform
LinearTransform(Matrix const &matrix) noexcept
Construct an LinearTransform from an Eigen::Matrix.
Definition: LinearTransform.h:83
lsst::geom::LinearTransform::operator[]
double & operator[](int i)
Definition: LinearTransform.h:154
lsst::geom::LinearTransform::operator()
Point2D operator()(Point2D const &p) const noexcept
Transform a Point2D object.
Definition: LinearTransform.h:178
lsst::geom::LinearTransform::applyX
double applyX(double x, double y) const noexcept
Transform a point given and returned as separate double values.
Definition: LinearTransform.h:195
lsst::geom::LinearTransform::makeScaling
static LinearTransform makeScaling(double s) noexcept
Definition: LinearTransform.h:94
lsst::geom::LinearTransform::LinearTransform
LinearTransform(LinearTransform &&other) noexcept
Definition: LinearTransform.h:87
std::ostream
STL class.
lsst::geom::LinearTransform::~LinearTransform
~LinearTransform() noexcept=default
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst::geom::LinearTransform::Parameters
Parameters
Definition: LinearTransform.h:71
lsst::geom::LinearTransform::LinearTransform
LinearTransform(LinearTransform const &other) noexcept
Definition: LinearTransform.h:86
lsst::geom::LinearTransform::operator[]
double const & operator[](int i) const
Definition: LinearTransform.h:155
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::geom::LinearTransform::LinearTransform
LinearTransform() noexcept
Construct an empty (identity) LinearTransform.
Definition: LinearTransform.h:80
lsst::geom::LinearTransform::ParameterVector
Eigen::Matrix< double, 4, 1 > ParameterVector
Definition: LinearTransform.h:73
lsst::geom::LinearTransform::operator-=
LinearTransform & operator-=(LinearTransform const &other) noexcept
Definition: LinearTransform.h:127
lsst::geom::LinearTransform::dTransform
TransformDerivativeMatrix dTransform(Extent2D const &input) const noexcept
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
Definition: LinearTransform.h:205
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::geom::operator<<
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Definition: AffineTransform.cc:72
lsst::meas::modelfit::Matrix
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition: common.h:45
lsst::geom::LinearTransform::applyY
double applyY(double x, double y) const noexcept
Definition: LinearTransform.h:196
lsst::geom
Definition: AffineTransform.h:36
os
std::ostream * os
Definition: Schema.cc:746
Runtime.h
lsst::geom::LinearTransform::makeScaling
static LinearTransform makeScaling(double s, double t) noexcept
Definition: LinearTransform.h:98
lsst::geom::LinearTransform::operator+
LinearTransform operator+(LinearTransform const &other) noexcept
Definition: LinearTransform.h:121
lsst::geom::Point< double, 2 >
lsst::geom::LinearTransform::ProductDerivativeMatrix
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
Definition: LinearTransform.h:75
lsst::geom::LinearTransform::operator()
Extent2D operator()(Extent2D const &p) const noexcept
Transform a Extent2D object.
Definition: LinearTransform.h:186
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
lsst::geom::LinearTransform::TransformDerivativeMatrix
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
Definition: LinearTransform.h:74
Point.h
lsst::geom::Extent2D
Extent< double, 2 > Extent2D
Definition: Extent.h:400
lsst::geom::SingularTransformException
Definition: LinearTransform.h:36
lsst::geom::LinearTransform::Matrix
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
Definition: LinearTransform.h:77
LSST_EXCEPTION_TYPE
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
lsst::geom::Extent< double, 2 >
lsst.pex::exceptions::RuntimeError
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
lsst::geom::LinearTransform::operator=
LinearTransform & operator=(LinearTransform &&other) noexcept
Definition: LinearTransform.h:111