LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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  ParameterVector const getParameterVector() const;
109  void setParameterVector(ParameterVector const & vector);
110 
111  Matrix const & getMatrix() const { return _matrix; }
112  Matrix & getMatrix() { return _matrix; }
113 
114  double & operator[](int i) { return _matrix(i % 2, i / 2); }
115  double const & operator[](int i) const {
116  return const_cast<Matrix&>(_matrix)(i % 2, i / 2);
117  }
118 
119 
120  LinearTransform const invert() const;
121 
122  double computeDeterminant() const;
123 
125  bool isIdentity() const { return getMatrix().isIdentity(); }
126 
133  Point2D operator()(Point2D const & p) const { return Point2D(getMatrix() * p.asEigen()); }
134 
141  Extent2D operator()(Extent2D const & p) const { return Extent2D(getMatrix() * p.asEigen()); }
142 
143  TransformDerivativeMatrix dTransform(Point2D const & input) const;
144 
146  TransformDerivativeMatrix dTransform(Extent2D const & input) const {
147  return dTransform(Point2D(input));
148  }
149 
150 private:
151  Matrix _matrix;
152 };
153 
154 std::ostream & operator<<(std::ostream & os, lsst::afw::geom::LinearTransform const & t);
155 
156 }}} // namespace lsst::afw::geom
157 
158 #endif // !LSST_AFW_GEOM_LINEAR_TRANSFORM_H
LinearTransform(Matrix const &matrix)
Construct an LinearTransform from an Eigen::Matrix.
A coordinate class intended to represent absolute positions.
Eigen::Matrix< double, 4, 1 > ParameterVector
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
Extent< double, 2 > Extent2D
Definition: Extent.h:358
Extent2D operator()(Extent2D const &p) const
Transform a Extent2D object.
LinearTransform operator*(LinearTransform const &other) const
static LinearTransform makeRotation(Angle t)
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
double asRadians() const
Definition: Angle.h:122
A 2D linear coordinate transformation.
static LinearTransform makeScaling(double s, double t)
LinearTransform()
Construct an empty (identity) LinearTransform.
Point2D operator()(Point2D const &p) const
Transform a Point2D object.
static LinearTransform makeScaling(double s)
Matrix const & getMatrix() const
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
double const & operator[](int i) const
LinearTransform & operator=(LinearTransform const &other)
Point< double, 2 > Point2D
Definition: Point.h:286
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
#define LSST_EXCEPTION_TYPE(t, b, c)
Definition: Exception.h:68
TransformDerivativeMatrix dTransform(Extent2D const &input) const
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
bool isIdentity() const
Whether the transform is a no-op.