LSSTApplications  16.0-10-g9d3e444,16.0-10-gb7df26b+3,16.0-10-gbd9fc95,16.0-11-g09ed895+3,16.0-11-g12e47bd+11,16.0-12-g5c924a4+21,16.0-12-g71e5ef5+10,16.0-15-g7af1f30+2,16.0-15-gdd5ca33+2,16.0-16-gf0259e2+1,16.0-18-gcf94535+13,16.0-19-g283fd30+1,16.0-19-g9d290d5+13,16.0-2-g0febb12+22,16.0-2-g9d5294e+76,16.0-20-g42ca1a7,16.0-20-g8d11721+2,16.0-23-g28ad22d+2,16.0-25-g723f23e8+2,16.0-29-g44d5b4c,16.0-32-ga392cb8+2,16.0-32-gc794025+1,16.0-4-g18f3627+20,16.0-4-g5f3a788+21,16.0-4-g6d309fa,16.0-4-ga3eb747+11,16.0-4-gabf74b7+42,16.0-4-gb13d127+7,16.0-5-g27fb78a+20,16.0-5-g6a53317+47,16.0-5-gb3f8a4b+101,16.0-6-g9321be7+5,16.0-6-gcbc7b31+58,16.0-6-gf49912c+44,16.0-65-g12857137,16.0-76-g802307b6d+2,16.0-8-g21fd5fe+45,16.0-8-g3a9f023+27,16.0-8-gc11f1cf+11,master-g5605b1aa4d+2,w.2019.05
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 
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 
158 
165  LinearTransform const inverted() const;
167 
171  double computeDeterminant() const noexcept;
172 
174  bool isIdentity() const noexcept { return getMatrix().isIdentity(); }
175 
182  Point2D operator()(Point2D const& p) const noexcept { return Point2D(getMatrix() * p.asEigen()); }
183 
190  Extent2D operator()(Extent2D const& p) const noexcept { return Extent2D(getMatrix() * p.asEigen()); }
191 
195  TransformDerivativeMatrix dTransform(Point2D const& input) const noexcept;
196 
198  TransformDerivativeMatrix dTransform(Extent2D const& input) const noexcept {
199  return dTransform(Point2D(input));
200  }
201 
202 private:
203  Matrix _matrix;
204 };
205 
207 
208 } // namespace geom
209 } // namespace lsst
210 
211 #endif // !LSST_GEOM_LINEAR_TRANSFORM_H
LinearTransform & operator+=(LinearTransform const &other) noexcept
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
Matrix const & getMatrix() const noexcept
LinearTransform & operator=(LinearTransform const &other) noexcept
bool isIdentity() const noexcept
Whether the transform is a no-op.
LinearTransform & operator=(LinearTransform &&other) noexcept
static LinearTransform makeScaling(double s, double t) noexcept
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
LinearTransform(Matrix const &matrix) noexcept
Construct an LinearTransform from an Eigen::Matrix.
Matrix & getMatrix() noexcept
A class representing an angle.
Definition: Angle.h:127
Point< double, 2 > Point2D
Definition: Point.h:324
A base class for image defects.
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Typedefs to be used for probability and parameter values.
Definition: common.h:45
LinearTransform(LinearTransform const &other) noexcept
LinearTransform() noexcept
Construct an empty (identity) LinearTransform.
Point2D operator()(Point2D const &p) const noexcept
Transform a Point2D object.
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Eigen::Matrix< double, 4, 1 > ParameterVector
LinearTransform & operator-=(LinearTransform const &other) noexcept
solver_t * s
static LinearTransform makeScaling(double s) noexcept
T move(T... args)
LinearTransform(LinearTransform &&other) noexcept
LinearTransform operator*(LinearTransform const &other) const noexcept
LinearTransform operator-(LinearTransform const &other) noexcept
LinearTransform operator+(LinearTransform const &other) noexcept
double const & operator[](int i) const
static LinearTransform makeRotation(Angle t) noexcept
TransformDerivativeMatrix dTransform(Extent2D const &input) const noexcept
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
Extent2D operator()(Extent2D const &p) const noexcept
Transform a Extent2D object.
ItemVariant const * other
Definition: Schema.cc:56
Extent< double, 2 > Extent2D
Definition: Extent.h:400
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
STL class.
A 2D linear coordinate transformation.
std::ostream * os
Definition: Schema.cc:746
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104