LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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
Extent2D operator()(Extent2D const &p) const
Transform a Extent2D object.
A coordinate class intended to represent absolute positions.
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.
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
static LinearTransform makeScaling(double s)
Point< double, 2 > Point2D
Definition: Point.h:286
LinearTransform & operator=(LinearTransform const &other)
Point2D operator()(Point2D const &p) const
Transform a Point2D object.
LinearTransform()
Construct an empty (identity) LinearTransform.
double const & operator[](int i) const
A 2D linear coordinate transformation.
LinearTransform operator*(LinearTransform const &other) const
static LinearTransform makeRotation(Angle t)
Eigen::Matrix< double, 4, 1 > ParameterVector
TransformDerivativeMatrix dTransform(Extent2D const &input) const
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
double asRadians() const
Definition: Angle.h:122
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
static LinearTransform makeScaling(double s, double t)
LinearTransform(Matrix const &matrix)
Construct an LinearTransform from an Eigen::Matrix.
Extent< double, 2 > Extent2D
Definition: Extent.h:358
#define LSST_EXCEPTION_TYPE(t, b, c)
Definition: Exception.h:68