LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
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 
37 LSST_EXCEPTION_TYPE(SingularTransformException, lsst::pex::exceptions::RuntimeError, lsst::afw::geom::SingularTransformException)
38 
39 
71 public:
72  enum Parameters {XX=0,YX=1,XY=2,YY=3};
73 
74  typedef Eigen::Matrix<double,4,1> ParameterVector;
75  typedef Eigen::Matrix<double,2,4> TransformDerivativeMatrix;
76  typedef Eigen::Matrix<double,4,4> ProductDerivativeMatrix;
77 
78  typedef Eigen::Matrix<double,2,2,Eigen::DontAlign> Matrix;
79 
81  LinearTransform() : _matrix(Matrix::Identity()) {}
82 
84  explicit LinearTransform(Matrix const & matrix) : _matrix(matrix) {}
85 
86  LinearTransform operator*(LinearTransform const & other) const {
87  return LinearTransform(getMatrix() * other.getMatrix());
88  }
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 
130  ParameterVector const getParameterVector() const;
131  void setParameterVector(ParameterVector const & vector);
132 
133  Matrix const & getMatrix() const { return _matrix; }
134  Matrix & getMatrix() { return _matrix; }
135 
136  double & operator[](int i) { return _matrix(i % 2, i / 2); }
137  double const & operator[](int i) const {
138  return const_cast<Matrix&>(_matrix)(i % 2, i / 2);
139  }
140 
141  LinearTransform const invert() const;
142 
143  double computeDeterminant() const;
144 
146  bool isIdentity() const { return getMatrix().isIdentity(); }
147 
154  Point2D operator()(Point2D const & p) const { return Point2D(getMatrix() * p.asEigen()); }
155 
162  Extent2D operator()(Extent2D const & p) const { return Extent2D(getMatrix() * p.asEigen()); }
163 
164  TransformDerivativeMatrix dTransform(Point2D const & input) const;
165 
167  TransformDerivativeMatrix dTransform(Extent2D const & input) const {
168  return dTransform(Point2D(input));
169  }
170 
171 private:
172  Matrix _matrix;
173 };
174 
175 std::ostream & operator<<(std::ostream & os, lsst::afw::geom::LinearTransform const & t);
176 
177 }}} // namespace lsst::afw::geom
178 
179 #endif // !LSST_AFW_GEOM_LINEAR_TRANSFORM_H
A coordinate class intended to represent absolute positions.
Eigen::Matrix< double, 4, 1 > ParameterVector
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
Extent< double, 2 > Extent2D
Definition: Extent.h:361
LinearTransform & operator-=(LinearTransform const &other)
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
bool isIdentity() const
Whether the transform is a no-op.
LinearTransform(Matrix const &matrix)
Construct an LinearTransform from an Eigen::Matrix.
Extent2D operator()(Extent2D const &p) const
Transform a Extent2D object.
LinearTransform operator-(LinearTransform const &other)
static LinearTransform makeScaling(double s)
Point2D operator()(Point2D const &p) const
Transform a Point2D object.
A 2D linear coordinate transformation.
static LinearTransform makeRotation(Angle t)
TransformDerivativeMatrix dTransform(Extent2D const &input) const
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
double const & operator[](int i) const
LinearTransform operator+(LinearTransform const &other)
LinearTransform()
Construct an empty (identity) LinearTransform.
A class representing an Angle.
Definition: Angle.h:103
LinearTransform & operator=(LinearTransform const &other)
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
Matrix const & getMatrix() const
static LinearTransform makeScaling(double s, double t)
LinearTransform operator*(LinearTransform const &other) const
metadata input
Point< double, 2 > Point2D
Definition: Point.h:288
double asRadians() const
Return an Angle&#39;s value as a double in radians.
Definition: Angle.h:121
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:68
LinearTransform & operator+=(LinearTransform const &other)