lsst.geom  15.0-1-g417ea41+6
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 
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() : _matrix(Matrix::Identity()) {}
81 
83  explicit LinearTransform(Matrix const& matrix) : _matrix(matrix) {}
84 
85  LinearTransform(LinearTransform const&) = default;
86  LinearTransform(LinearTransform&&) = default;
87  ~LinearTransform() = default;
88 
89  LinearTransform operator*(LinearTransform const& other) const {
90  return LinearTransform(getMatrix() * other.getMatrix());
91  }
92 
93  static LinearTransform makeScaling(double s) {
94  return LinearTransform((Matrix() << s, 0.0, 0.0, s).finished());
95  }
96 
97  static LinearTransform makeScaling(double s, double t) {
98  return LinearTransform((Matrix() << s, 0.0, 0.0, t).finished());
99  }
100 
101  static LinearTransform makeRotation(Angle t) {
102  return LinearTransform(Matrix(Eigen::Rotation2D<double>(t.asRadians())));
103  }
104 
105  LinearTransform& operator=(LinearTransform const&) = default;
106  LinearTransform& operator=(LinearTransform&&) = default;
107 
108  LinearTransform& operator+=(LinearTransform const& other) {
109  _matrix += other._matrix;
110  return *this;
111  }
112 
113  LinearTransform operator+(LinearTransform const& other) {
114  LinearTransform tmp(*this);
115  tmp += other;
116  return tmp;
117  }
118 
119  LinearTransform& operator-=(LinearTransform const& other) {
120  _matrix -= other._matrix;
121  return *this;
122  }
123 
124  LinearTransform operator-(LinearTransform const& other) {
125  LinearTransform tmp(*this);
126  tmp -= other;
127  return tmp;
128  }
129 
135  ParameterVector const getParameterVector() const;
141  void setParameterVector(ParameterVector const& vector);
142 
143  Matrix const& getMatrix() const { return _matrix; }
144  Matrix& getMatrix() { return _matrix; }
145 
146  double& operator[](int i) { return _matrix(i % 2, i / 2); }
147  double const& operator[](int i) const { return const_cast<Matrix&>(_matrix)(i % 2, i / 2); }
148 
154  LinearTransform const invert() const;
155 
159  double computeDeterminant() const;
160 
162  bool isIdentity() const { return getMatrix().isIdentity(); }
163 
170  Point2D operator()(Point2D const& p) const { return Point2D(getMatrix() * p.asEigen()); }
171 
178  Extent2D operator()(Extent2D const& p) const { return Extent2D(getMatrix() * p.asEigen()); }
179 
183  TransformDerivativeMatrix dTransform(Point2D const& input) const;
184 
186  TransformDerivativeMatrix dTransform(Extent2D const& input) const { return dTransform(Point2D(input)); }
187 
188 private:
189  Matrix _matrix;
190 };
191 
193 
194 } // namespace geom
195 } // namespace lsst
196 
197 #endif // !LSST_GEOM_LINEAR_TRANSFORM_H
static LinearTransform makeRotation(Angle t)
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
static LinearTransform makeScaling(double s)
LinearTransform & operator-=(LinearTransform const &other)
constexpr double asRadians() const noexcept
Return an Angle&#39;s value in radians.
Definition: Angle.h:159
Relationship invert(Relationship r)
bool isIdentity() const
Whether the transform is a no-op.
LinearTransform(Matrix const &matrix)
Construct an LinearTransform from an Eigen::Matrix.
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
LinearTransform & operator+=(LinearTransform const &other)
A class representing an angle.
Definition: Angle.h:120
Extent2D operator()(Extent2D const &p) const
Transform a Extent2D object.
Point< double, 2 > Point2D
Definition: Point.h:300
LinearTransform operator-(LinearTransform const &other)
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Eigen::Matrix< double, 4, 1 > ParameterVector
Matrix const & getMatrix() const
TransformDerivativeMatrix dTransform(Extent2D const &input) const
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
LinearTransform operator+(LinearTransform const &other)
double const & operator[](int i) const
LinearTransform()
Construct an empty (identity) LinearTransform.
static LinearTransform makeScaling(double s, double t)
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
Extent< double, 2 > Extent2D
Definition: Extent.h:379
#define LSST_EXCEPTION_TYPE(t, b, c)
LinearTransform operator*(LinearTransform const &other) const
STL class.
A 2D linear coordinate transformation.
Point2D operator()(Point2D const &p) const
Transform a Point2D object.