lsst.afw  14.0-60-ga423a1d65+2
AffineTransform.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2014 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_MATH_AFFINE_TRANSFORM_H
26 #define LSST_AFW_MATH_AFFINE_TRANSFORM_H
27 
28 #include <memory>
29 #include "Eigen/Core"
30 #include <iostream>
31 #include "lsst/afw/geom/Point.h"
32 #include "lsst/afw/geom/Extent.h"
34 #include "lsst/afw/geom/Angle.h"
35 
36 namespace lsst {
37 namespace afw {
38 namespace geom {
39 
78 public:
79  enum Parameters { XX = 0, YX = 1, XY = 2, YY = 3, X = 4, Y = 5 };
80 
81  typedef Eigen::Matrix3d Matrix;
82  typedef Eigen::Matrix<double, 6, 1> ParameterVector;
83  typedef Eigen::Matrix<double, 2, 6> TransformDerivativeMatrix;
84 
86  AffineTransform() : _linear(), _translation() {}
87 
89  explicit AffineTransform(Eigen::Matrix3d const &matrix)
90  : _linear(matrix.block<2, 2>(0, 0)), _translation(matrix.block<2, 1>(0, 2)) {}
91 
93  explicit AffineTransform(Eigen::Matrix2d const &linear) : _linear(linear), _translation() {}
94 
96  explicit AffineTransform(Eigen::Vector2d const &translation) : _linear(), _translation(translation) {}
97 
99  explicit AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
100  : _linear(linear), _translation(translation) {}
101 
103  AffineTransform(LinearTransform const &linear) : _linear(linear), _translation() {}
104 
106  explicit AffineTransform(Extent2D const &translation) : _linear(), _translation(translation) {}
107 
109  explicit AffineTransform(LinearTransform const &linear, Extent2D const &translation)
110  : _linear(linear), _translation(translation) {}
111 
112  AffineTransform(AffineTransform const &) = default;
113  AffineTransform(AffineTransform &&) = default;
114  ~AffineTransform() = default;
115 
121  AffineTransform const invert() const;
122 
124  bool isIdentity() const { return getMatrix().isIdentity(); }
125 
131  Point2D operator()(Point2D const &p) const { return Point2D(_linear(p) + _translation); }
132 
138  Extent2D operator()(Extent2D const &p) const { return Extent2D(_linear(p)); }
139 
140  Extent2D const &getTranslation() const { return _translation; }
141  Extent2D &getTranslation() { return _translation; }
142 
143  LinearTransform const &getLinear() const { return _linear; }
144  LinearTransform &getLinear() { return _linear; }
145 
149  Matrix const getMatrix() const;
150 
156  ParameterVector const getParameterVector() const;
162  void setParameterVector(ParameterVector const &vector);
163 
164  double &operator[](int i) { return (i < 4) ? _linear[i] : _translation[i - 4]; }
165  double operator[](int i) const { return (i < 4) ? _linear[i] : _translation[i - 4]; }
166 
171  return AffineTransform(getLinear() * other.getLinear(),
172  getLinear()(other.getTranslation()) + getTranslation());
173  }
174 
175  AffineTransform &operator=(AffineTransform const &) = default;
177 
179  _linear += other._linear;
180  _translation += other._translation;
181  return *this;
182  }
183 
185  AffineTransform tmp(*this);
186  tmp += other;
187  return tmp;
188  }
189 
191  _linear -= other._linear;
192  _translation -= other._translation;
193  return *this;
194  }
195 
197  AffineTransform tmp(*this);
198  tmp -= other;
199  return tmp;
200  }
201 
215 
229  static AffineTransform makeScaling(double s, double t) {
231  }
245 
258  static AffineTransform makeTranslation(Extent2D translation) { return AffineTransform(translation); }
259 
263  TransformDerivativeMatrix dTransform(Point2D const &input) const;
267  TransformDerivativeMatrix dTransform(Extent2D const &input) const;
268 
269 private:
270  LinearTransform _linear;
271  Extent2D _translation;
272 };
273 
275 
276 //
277 // Returns the unique AffineTransform A such that A(p_i)=q_i for i=1,2,3
278 //
280  Point2D const &q1, Point2D const &q2, Point2D const &q3);
281 }
282 }
283 }
284 
285 #endif // !LSST_AFW_MATH_AFFINE_TRANSFORM_H
AffineTransform operator-(AffineTransform const &other)
AffineTransform(Eigen::Matrix3d const &matrix)
Construct an AffineTransform from a 3x3 matrix.
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix
AffineTransform & operator-=(AffineTransform const &other)
Extent< double, 2 > Extent2D
Definition: Extent.h:383
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
LinearTransform const & getLinear() const
AffineTransform(LinearTransform const &linear)
Construct an AffineTransform from a LinearTransform.
static LinearTransform makeScaling(double s)
AffineTransform operator*(AffineTransform const &other) const
Construct a new AffineTransform from two others: (B * A)(p) = B(A(p))
Extent2D operator()(Extent2D const &p) const
Transform an Extent object.
static AffineTransform makeScaling(double s, double t)
Construct a new AffineTransform that represents a non-uniform scaling.
ParameterVector const getParameterVector() const
Return the transform matrix elements as a parameter vector.
A 2D linear coordinate transformation.
A class representing an angle.
Definition: Angle.h:102
Eigen::Matrix< double, 6, 1 > ParameterVector
A base class for image defects.
Point2D operator()(Point2D const &p) const
Transform a Point object.
Point< double, 2 > Point2D
Definition: Point.h:300
static LinearTransform makeRotation(Angle t)
An affine coordinate transformation consisting of a linear transformation and an offset.
static AffineTransform makeRotation(Angle t)
Construct a new AffineTransform that represents a CCW rotation in radians.
static AffineTransform makeTranslation(Extent2D translation)
Construct a new AffineTransform that represents a pure translation.
AffineTransform(Extent2D const &translation)
Construct a translation-only AffineTransform from an Extent2D.
static AffineTransform makeScaling(double s)
Construct a new AffineTransform that represents a uniform scaling.
Matrix const getMatrix() const
Return the transform as a full 3x3 matrix.
AffineTransform operator+(AffineTransform const &other)
AffineTransform()
Construct an empty (identity) AffineTransform.
AffineTransform(LinearTransform const &linear, Extent2D const &translation)
Construct an AffineTransform from a LinearTransform and Extent2D.
AffineTransform(Eigen::Matrix2d const &linear)
Construct an AffineTransform with no translation from a 2x2 matrix.
void setParameterVector(ParameterVector const &vector)
Set the transform matrix elements from a parameter vector.
AffineTransform & operator=(AffineTransform const &)=default
AffineTransform(Eigen::Vector2d const &translation)
Construct a translation-only AffineTransform from a vector.
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)
table::Key< int > transform
STL class.
AffineTransform const invert() const
Return the inverse transform.
Extent2D const & getTranslation() const
AffineTransform & operator+=(AffineTransform const &other)
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
Construct an AffineTransform from a 2x2 matrix and vector.
TransformDerivativeMatrix dTransform(Point2D const &input) const
Take the derivative of (*this)(input) w.r.t the transform elements.
bool isIdentity() const
Whether the transform is a no-op.