lsst.geom  15.0-1-g417ea41+3
AffineTransform.h
Go to the documentation of this file.
1 /*
2  * Developed for the LSST Data Management System.
3  * This product includes software developed by the LSST Project
4  * (https://www.lsst.org).
5  * See the COPYRIGHT file at the top-level directory of this distribution
6  * for details of code ownership.
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 GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef LSST_GEOM_AFFINE_TRANSFORM_H
23 #define LSST_GEOM_AFFINE_TRANSFORM_H
24 
25 #include <memory>
26 #include <iostream>
27 
28 #include "Eigen/Core"
29 
30 #include "lsst/geom/Point.h"
31 #include "lsst/geom/Extent.h"
33 #include "lsst/geom/Angle.h"
34 
35 namespace lsst {
36 namespace geom {
37 
76 public:
77  enum Parameters { XX = 0, YX = 1, XY = 2, YY = 3, X = 4, Y = 5 };
78 
79  typedef Eigen::Matrix3d Matrix;
80  typedef Eigen::Matrix<double, 6, 1> ParameterVector;
81  typedef Eigen::Matrix<double, 2, 6> TransformDerivativeMatrix;
82 
84  AffineTransform() : _linear(), _translation() {}
85 
87  explicit AffineTransform(Eigen::Matrix3d const &matrix)
88  : _linear(matrix.block<2, 2>(0, 0)), _translation(matrix.block<2, 1>(0, 2)) {}
89 
91  explicit AffineTransform(Eigen::Matrix2d const &linear) : _linear(linear), _translation() {}
92 
94  explicit AffineTransform(Eigen::Vector2d const &translation) : _linear(), _translation(translation) {}
95 
97  explicit AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
98  : _linear(linear), _translation(translation) {}
99 
101  AffineTransform(LinearTransform const &linear) : _linear(linear), _translation() {}
102 
104  explicit AffineTransform(Extent2D const &translation) : _linear(), _translation(translation) {}
105 
107  explicit AffineTransform(LinearTransform const &linear, Extent2D const &translation)
108  : _linear(linear), _translation(translation) {}
109 
110  AffineTransform(AffineTransform const &) = default;
111  AffineTransform(AffineTransform &&) = default;
112  ~AffineTransform() = default;
113 
119  AffineTransform const invert() const;
120 
122  bool isIdentity() const { return getMatrix().isIdentity(); }
123 
129  Point2D operator()(Point2D const &p) const { return Point2D(_linear(p) + _translation); }
130 
136  Extent2D operator()(Extent2D const &p) const { return Extent2D(_linear(p)); }
137 
138  Extent2D const &getTranslation() const { return _translation; }
139  Extent2D &getTranslation() { return _translation; }
140 
141  LinearTransform const &getLinear() const { return _linear; }
142  LinearTransform &getLinear() { return _linear; }
143 
147  Matrix const getMatrix() const;
148 
154  ParameterVector const getParameterVector() const;
160  void setParameterVector(ParameterVector const &vector);
161 
162  double &operator[](int i) { return (i < 4) ? _linear[i] : _translation[i - 4]; }
163  double operator[](int i) const { return (i < 4) ? _linear[i] : _translation[i - 4]; }
164 
169  return AffineTransform(getLinear() * other.getLinear(),
170  getLinear()(other.getTranslation()) + getTranslation());
171  }
172 
173  AffineTransform &operator=(AffineTransform const &) = default;
175 
177  _linear += other._linear;
178  _translation += other._translation;
179  return *this;
180  }
181 
183  AffineTransform tmp(*this);
184  tmp += other;
185  return tmp;
186  }
187 
189  _linear -= other._linear;
190  _translation -= other._translation;
191  return *this;
192  }
193 
195  AffineTransform tmp(*this);
196  tmp -= other;
197  return tmp;
198  }
199 
213 
227  static AffineTransform makeScaling(double s, double t) {
229  }
243 
256  static AffineTransform makeTranslation(Extent2D translation) { return AffineTransform(translation); }
257 
261  TransformDerivativeMatrix dTransform(Point2D const &input) const;
265  TransformDerivativeMatrix dTransform(Extent2D const &input) const;
266 
267 private:
268  LinearTransform _linear;
269  Extent2D _translation;
270 };
271 
273 
274 //
275 // Returns the unique AffineTransform A such that A(p_i)=q_i for i=1,2,3
276 //
278  Point2D const &q1, Point2D const &q2, Point2D const &q3);
279 } // namespace geom
280 } // namespace lsst
281 
282 #endif // !LSST_GEOM_AFFINE_TRANSFORM_H
static LinearTransform makeRotation(Angle t)
static LinearTransform makeScaling(double s)
An affine coordinate transformation consisting of a linear transformation and an offset.
static AffineTransform makeTranslation(Extent2D translation)
Construct a new AffineTransform that represents a pure translation.
AffineTransform & operator+=(AffineTransform const &other)
AffineTransform operator+(AffineTransform const &other)
Extent2D operator()(Extent2D const &p) const
Transform an Extent object.
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix
AffineTransform(LinearTransform const &linear, Extent2D const &translation)
Construct an AffineTransform from a LinearTransform and Extent2D.
Matrix const getMatrix() const
Return the transform as a full 3x3 matrix.
Eigen::Matrix< double, 6, 1 > ParameterVector
AffineTransform()
Construct an empty (identity) AffineTransform.
A class representing an angle.
Definition: Angle.h:120
AffineTransform operator*(AffineTransform const &other) const
Construct a new AffineTransform from two others: (B * A)(p) = B(A(p))
Point< double, 2 > Point2D
Definition: Point.h:300
AffineTransform(Eigen::Matrix3d const &matrix)
Construct an AffineTransform from a 3x3 matrix.
ParameterVector const getParameterVector() const
Return the transform matrix elements as a parameter vector.
AffineTransform(LinearTransform const &linear)
Construct an AffineTransform from a LinearTransform.
AffineTransform & operator=(AffineTransform const &)=default
double operator[](int i) const
void setParameterVector(ParameterVector const &vector)
Set the transform matrix elements from a parameter vector.
AffineTransform(Eigen::Vector2d const &translation)
Construct a translation-only AffineTransform from a vector.
AffineTransform(Extent2D const &translation)
Construct a translation-only AffineTransform from an Extent2D.
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
AffineTransform operator-(AffineTransform const &other)
TransformDerivativeMatrix dTransform(Point2D const &input) const
Take the derivative of (*this)(input) w.r.t the transform elements.
static AffineTransform makeRotation(Angle t)
Construct a new AffineTransform that represents a CCW rotation in radians.
LinearTransform const & getLinear() const
AffineTransform(Eigen::Matrix2d const &linear)
Construct an AffineTransform with no translation from a 2x2 matrix.
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
Construct an AffineTransform from a 2x2 matrix and vector.
bool isIdentity() const
Whether the transform is a no-op.
AffineTransform const invert() const
Return the inverse transform.
Point2D operator()(Point2D const &p) const
Transform a Point object.
AffineTransform & operator-=(AffineTransform const &other)
Extent< double, 2 > Extent2D
Definition: Extent.h:379
STL class.
Extent2D const & getTranslation() const
A 2D linear coordinate transformation.
static AffineTransform makeScaling(double s)
Construct a new AffineTransform that represents a uniform scaling.
LinearTransform & getLinear()
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)
static AffineTransform makeScaling(double s, double t)
Construct a new AffineTransform that represents a non-uniform scaling.