lsst.afw  13.0-98-g5a654715e+2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
28 #include "lsst/pex/exceptions/Runtime.h"
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 
37 LSST_EXCEPTION_TYPE(SingularTransformException, lsst::pex::exceptions::RuntimeError,
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 operator*(LinearTransform const& other) const {
88  return LinearTransform(getMatrix() * other.getMatrix());
89  }
90 
91  static LinearTransform makeScaling(double s) {
92  return LinearTransform((Matrix() << s, 0.0, 0.0, s).finished());
93  }
94 
95  static LinearTransform makeScaling(double s, double t) {
96  return LinearTransform((Matrix() << s, 0.0, 0.0, t).finished());
97  }
98 
99  static LinearTransform makeRotation(Angle t) {
100  return LinearTransform(Matrix(Eigen::Rotation2D<double>(t.asRadians())));
101  }
102 
103  LinearTransform& operator=(LinearTransform const& other) {
104  _matrix = other._matrix;
105  return *this;
106  }
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 
192 std::ostream& operator<<(std::ostream& os, lsst::afw::geom::LinearTransform const& t);
193 }
194 }
195 } // namespace lsst::afw::geom
196 
197 #endif // !LSST_AFW_GEOM_LINEAR_TRANSFORM_H
LinearTransform operator-(LinearTransform const &other)
Extent2D operator()(Extent2D const &p) const
Transform a Extent2D object.
Extent< double, 2 > Extent2D
Definition: Extent.h:344
Matrix const & getMatrix() const
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
bool isIdentity() const
Whether the transform is a no-op.
LinearTransform & operator-=(LinearTransform const &other)
static LinearTransform makeScaling(double s)
Eigen::Matrix< double, 4, 1 > ParameterVector
LinearTransform & operator=(LinearTransform const &other)
Point2D operator()(Point2D const &p) const
Transform a Point2D object.
LinearTransform()
Construct an empty (identity) LinearTransform.
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
double const & operator[](int i) const
A 2D linear coordinate transformation.
A class representing an angle.
Definition: Angle.h:102
LinearTransform & operator+=(LinearTransform const &other)
LinearTransform operator*(LinearTransform const &other) const
Point< double, 2 > Point2D
Definition: Point.h:273
static LinearTransform makeRotation(Angle t)
TransformDerivativeMatrix dTransform(Extent2D const &input) const
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
constexpr double asRadians() const noexcept
Return an Angle&#39;s value in radians.
Definition: Angle.h:139
static LinearTransform makeScaling(double s, double t)
metadata input
LinearTransform(Matrix const &matrix)
Construct an LinearTransform from an Eigen::Matrix.
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
LinearTransform operator+(LinearTransform const &other)