lsst.afw  14.0-63-g921e36d6a
LinearTransform.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2014 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #ifndef LSST_AFW_GEOM_LINEAR_TRANSFORM_H
24 #define LSST_AFW_GEOM_LINEAR_TRANSFORM_H
25 
26 #include "Eigen/Core"
27 #include "Eigen/Geometry"
29 
30 #include "lsst/afw/geom/Point.h"
31 #include "lsst/afw/geom/Angle.h"
32 
33 namespace lsst {
34 namespace afw {
35 namespace geom {
36 
39 
40 
72 public:
73  enum Parameters { XX = 0, YX = 1, XY = 2, YY = 3 };
74 
75  typedef Eigen::Matrix<double, 4, 1> ParameterVector;
76  typedef Eigen::Matrix<double, 2, 4> TransformDerivativeMatrix;
77  typedef Eigen::Matrix<double, 4, 4> ProductDerivativeMatrix;
78 
79  typedef Eigen::Matrix<double, 2, 2, Eigen::DontAlign> Matrix;
80 
82  LinearTransform() : _matrix(Matrix::Identity()) {}
83 
85  explicit LinearTransform(Matrix const& matrix) : _matrix(matrix) {}
86 
87  LinearTransform(LinearTransform const&) = default;
88  LinearTransform(LinearTransform&&) = default;
89  ~LinearTransform() = default;
90 
91  LinearTransform operator*(LinearTransform const& other) const {
92  return LinearTransform(getMatrix() * other.getMatrix());
93  }
94 
95  static LinearTransform makeScaling(double s) {
96  return LinearTransform((Matrix() << s, 0.0, 0.0, s).finished());
97  }
98 
99  static LinearTransform makeScaling(double s, double t) {
100  return LinearTransform((Matrix() << s, 0.0, 0.0, t).finished());
101  }
102 
103  static LinearTransform makeRotation(Angle t) {
104  return LinearTransform(Matrix(Eigen::Rotation2D<double>(t.asRadians())));
105  }
106 
107  LinearTransform& operator=(LinearTransform const&) = default;
108  LinearTransform& operator=(LinearTransform&&) = default;
109 
110  LinearTransform& operator+=(LinearTransform const& other) {
111  _matrix += other._matrix;
112  return *this;
113  }
114 
115  LinearTransform operator+(LinearTransform const& other) {
116  LinearTransform tmp(*this);
117  tmp += other;
118  return tmp;
119  }
120 
121  LinearTransform& operator-=(LinearTransform const& other) {
122  _matrix -= other._matrix;
123  return *this;
124  }
125 
126  LinearTransform operator-(LinearTransform const& other) {
127  LinearTransform tmp(*this);
128  tmp -= other;
129  return tmp;
130  }
131 
137  ParameterVector const getParameterVector() const;
143  void setParameterVector(ParameterVector const& vector);
144 
145  Matrix const& getMatrix() const { return _matrix; }
146  Matrix& getMatrix() { return _matrix; }
147 
148  double& operator[](int i) { return _matrix(i % 2, i / 2); }
149  double const& operator[](int i) const { return const_cast<Matrix&>(_matrix)(i % 2, i / 2); }
150 
156  LinearTransform const invert() const;
157 
161  double computeDeterminant() const;
162 
164  bool isIdentity() const { return getMatrix().isIdentity(); }
165 
172  Point2D operator()(Point2D const& p) const { return Point2D(getMatrix() * p.asEigen()); }
173 
180  Extent2D operator()(Extent2D const& p) const { return Extent2D(getMatrix() * p.asEigen()); }
181 
185  TransformDerivativeMatrix dTransform(Point2D const& input) const;
186 
188  TransformDerivativeMatrix dTransform(Extent2D const& input) const { return dTransform(Point2D(input)); }
189 
190 private:
191  Matrix _matrix;
192 };
193 
195 }
196 }
197 } // namespace lsst::afw::geom
198 
199 #endif // !LSST_AFW_GEOM_LINEAR_TRANSFORM_H
bool isIdentity() const
Whether the transform is a no-op.
LinearTransform operator-(LinearTransform const &other)
TransformDerivativeMatrix dTransform(Extent2D const &input) const
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
LinearTransform operator*(LinearTransform const &other) const
Matrix const & getMatrix() const
Extent< double, 2 > Extent2D
Definition: Extent.h:383
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
LinearTransform & operator-=(LinearTransform const &other)
static LinearTransform makeScaling(double s)
Eigen::Matrix< double, 4, 1 > ParameterVector
LinearTransform()
Construct an empty (identity) LinearTransform.
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
A 2D linear coordinate transformation.
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
A class representing an angle.
Definition: Angle.h:102
A base class for image defects.
LinearTransform & operator+=(LinearTransform const &other)
Point< double, 2 > Point2D
Definition: Point.h:304
static LinearTransform makeRotation(Angle t)
Extent2D operator()(Extent2D const &p) const
Transform a Extent2D object.
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
double const & operator[](int i) const
Point2D operator()(Point2D const &p) const
Transform a Point2D object.
constexpr double asRadians() const noexcept
Return an Angle&#39;s value in radians.
Definition: Angle.h:141
static LinearTransform makeScaling(double s, double t)
LinearTransform(Matrix const &matrix)
Construct an LinearTransform from an Eigen::Matrix.
#define LSST_EXCEPTION_TYPE(t, b, c)
STL class.
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
LinearTransform operator+(LinearTransform const &other)