LSSTApplications  19.0.0-11-g2ce9f25+4,20.0.0+1,20.0.0+10,20.0.0+11,20.0.0+13,20.0.0+2,20.0.0+3,20.0.0+4,20.0.0+6,20.0.0-1-g10df615+10,20.0.0-1-g253301a+5,20.0.0-1-g596936a+11,20.0.0-1-g8a53f90+1,20.0.0-1-gc96f8cb+12,20.0.0-1-gd1c87d7+1,20.0.0-17-g41c5faf,20.0.0-2-g04cfba9+4,20.0.0-2-gd11eeda,20.0.0-2-gec03fae+3,20.0.0-3-g082faa5+1,20.0.0-3-gbdbfa727+3,20.0.0-3-gc53c7b6,20.0.0-4-gde602ef96+4,20.0.0-4-ge48a6ca+6,20.0.0-4-ge987224+1,20.0.0-8-g7eef53f7+7,20.0.0-9-g8e1b333,w.2020.28
LSSTDataManagementBasePackage
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 
75 class AffineTransform final {
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() noexcept : _linear(), _translation() {}
85 
87  explicit AffineTransform(Eigen::Matrix3d const &matrix) noexcept
88  : _linear(matrix.block<2, 2>(0, 0)), _translation(matrix.block<2, 1>(0, 2)) {}
89 
91  explicit AffineTransform(Eigen::Matrix2d const &linear) noexcept : _linear(linear), _translation() {}
92 
94  explicit AffineTransform(Eigen::Vector2d const &translation) noexcept
95  : _linear(), _translation(translation) {}
96 
98  explicit AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation) noexcept
99  : _linear(linear), _translation(translation) {}
100 
102  AffineTransform(LinearTransform const &linear) noexcept : _linear(linear), _translation() {}
103 
105  explicit AffineTransform(Extent2D const &translation) noexcept : _linear(), _translation(translation) {}
106 
108  explicit AffineTransform(LinearTransform const &linear, Extent2D const &translation) noexcept
109  : _linear(linear), _translation(translation) {}
110 
111  AffineTransform(AffineTransform const &) noexcept = default;
112  AffineTransform(AffineTransform &&) noexcept = default;
113  ~AffineTransform() noexcept = default;
114 
116 
121  AffineTransform const inverted() const;
123 
125  bool isIdentity() const noexcept { return getMatrix().isIdentity(); }
126 
132  Point2D operator()(Point2D const &p) const noexcept { return Point2D(_linear(p) + _translation); }
133 
139  Extent2D operator()(Extent2D const &p) const noexcept { return Extent2D(_linear(p)); }
140 
142 
148  double applyX(double x, double y) const noexcept { return _linear.applyX(x, y) + _translation.getX(); }
149  double applyY(double x, double y) const noexcept { return _linear.applyY(x, y) + _translation.getY(); }
151 
152  Extent2D const &getTranslation() const noexcept { return _translation; }
153  Extent2D &getTranslation() noexcept { return _translation; }
154 
155  LinearTransform const &getLinear() const noexcept { return _linear; }
156  LinearTransform &getLinear() noexcept { return _linear; }
157 
161  Matrix const getMatrix() const noexcept;
162 
168  ParameterVector const getParameterVector() const noexcept;
174  void setParameterVector(ParameterVector const &vector) noexcept;
175 
176  double &operator[](int i) { return (i < 4) ? _linear[i] : _translation[i - 4]; }
177  double operator[](int i) const { return (i < 4) ? _linear[i] : _translation[i - 4]; }
178 
183  return AffineTransform(getLinear() * other.getLinear(),
184  getLinear()(other.getTranslation()) + getTranslation());
185  }
186 
187  AffineTransform &operator=(AffineTransform const &) noexcept = default;
188  AffineTransform &operator=(AffineTransform &&) noexcept = default;
189 
190  AffineTransform &operator+=(AffineTransform const &other) noexcept {
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 
203  _linear -= other._linear;
204  _translation -= other._translation;
205  return *this;
206  }
207 
209  AffineTransform tmp(*this);
210  tmp -= other;
211  return tmp;
212  }
213 
226  static AffineTransform makeScaling(double s) noexcept {
228  }
229 
243  static AffineTransform makeScaling(double s, double t) noexcept {
245  }
258  static AffineTransform makeRotation(Angle t) noexcept {
260  }
261 
274  static AffineTransform makeTranslation(Extent2D translation) noexcept {
275  return AffineTransform(translation);
276  }
277 
281  TransformDerivativeMatrix dTransform(Point2D const &input) const noexcept;
285  TransformDerivativeMatrix dTransform(Extent2D const &input) const noexcept;
286 
287 private:
288  LinearTransform _linear;
289  Extent2D _translation;
290 };
291 
293 
294 //
295 // Returns the unique AffineTransform A such that A(p_i)=q_i for i=1,2,3
296 //
297 AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3,
298  Point2D const &q1, Point2D const &q2, Point2D const &q3);
299 } // namespace geom
300 } // namespace lsst
301 
302 #endif // !LSST_GEOM_AFFINE_TRANSFORM_H
y
int y
Definition: SpanSet.cc:49
lsst::geom::AffineTransform::AffineTransform
AffineTransform(Extent2D const &translation) noexcept
Construct a translation-only AffineTransform from an Extent2D.
Definition: AffineTransform.h:105
lsst::geom::AffineTransform::makeTranslation
static AffineTransform makeTranslation(Extent2D translation) noexcept
Construct a new AffineTransform that represents a pure translation.
Definition: AffineTransform.h:274
lsst::geom::LinearTransform::makeRotation
static LinearTransform makeRotation(Angle t) noexcept
Definition: LinearTransform.h:102
lsst::geom::AffineTransform::makeRotation
static AffineTransform makeRotation(Angle t) noexcept
Construct a new AffineTransform that represents a CCW rotation in radians.
Definition: AffineTransform.h:258
lsst::geom::AffineTransform::Parameters
Parameters
Definition: AffineTransform.h:77
lsst::geom::AffineTransform::dTransform
TransformDerivativeMatrix dTransform(Point2D const &input) const noexcept
Take the derivative of (*this)(input) w.r.t the transform elements.
Definition: AffineTransform.cc:58
lsst::geom::AffineTransform::operator=
AffineTransform & operator=(AffineTransform &&) noexcept=default
lsst::geom::AffineTransform::AffineTransform
AffineTransform(Eigen::Matrix2d const &linear) noexcept
Construct an AffineTransform with no translation from a 2x2 matrix.
Definition: AffineTransform.h:91
lsst::geom::AffineTransform::operator()
Extent2D operator()(Extent2D const &p) const noexcept
Transform an Extent object.
Definition: AffineTransform.h:139
lsst::geom::AffineTransform::makeScaling
static AffineTransform makeScaling(double s) noexcept
Construct a new AffineTransform that represents a uniform scaling.
Definition: AffineTransform.h:226
lsst::geom::AffineTransform::AffineTransform
AffineTransform(AffineTransform const &) noexcept=default
lsst::geom::LinearTransform
A 2D linear coordinate transformation.
Definition: LinearTransform.h:69
lsst::geom::AffineTransform::XY
@ XY
Definition: AffineTransform.h:77
Angle.h
lsst::geom::AffineTransform::inverted
AffineTransform const inverted() const
Return the inverse transform.
Definition: AffineTransform.cc:53
lsst::geom::AffineTransform::AffineTransform
AffineTransform(Eigen::Vector2d const &translation) noexcept
Construct a translation-only AffineTransform from a vector.
Definition: AffineTransform.h:94
lsst::geom::AffineTransform::AffineTransform
AffineTransform(LinearTransform const &linear, Extent2D const &translation) noexcept
Construct an AffineTransform from a LinearTransform and Extent2D.
Definition: AffineTransform.h:108
lsst::geom::AffineTransform::getTranslation
Extent2D const & getTranslation() const noexcept
Definition: AffineTransform.h:152
lsst::geom::AffineTransform::makeScaling
static AffineTransform makeScaling(double s, double t) noexcept
Construct a new AffineTransform that represents a non-uniform scaling.
Definition: AffineTransform.h:243
lsst::geom::Point2D
Point< double, 2 > Point2D
Definition: Point.h:324
lsst::geom::AffineTransform::getLinear
LinearTransform & getLinear() noexcept
Definition: AffineTransform.h:156
lsst::geom::LinearTransform::applyX
double applyX(double x, double y) const noexcept
Transform a point given and returned as separate double values.
Definition: LinearTransform.h:195
lsst::geom::AffineTransform::operator[]
double operator[](int i) const
Definition: AffineTransform.h:177
lsst::geom::AffineTransform::YX
@ YX
Definition: AffineTransform.h:77
lsst::geom::LinearTransform::makeScaling
static LinearTransform makeScaling(double s) noexcept
Definition: LinearTransform.h:94
lsst::geom::AffineTransform
An affine coordinate transformation consisting of a linear transformation and an offset.
Definition: AffineTransform.h:75
lsst::geom::AffineTransform::YY
@ YY
Definition: AffineTransform.h:77
Extent.h
lsst::geom::AffineTransform::isIdentity
bool isIdentity() const noexcept
Whether the transform is a no-op.
Definition: AffineTransform.h:125
lsst::geom::AffineTransform::Matrix
Eigen::Matrix3d Matrix
Definition: AffineTransform.h:79
lsst::geom::AffineTransform::applyY
double applyY(double x, double y) const noexcept
Definition: AffineTransform.h:149
std::ostream
STL class.
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst::geom::AffineTransform::AffineTransform
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation) noexcept
Construct an AffineTransform from a 2x2 matrix and vector.
Definition: AffineTransform.h:98
lsst::geom::AffineTransform::getLinear
LinearTransform const & getLinear() const noexcept
Definition: AffineTransform.h:155
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::geom::AffineTransform::applyX
double applyX(double x, double y) const noexcept
Transform a point given and returned as separate double values.
Definition: AffineTransform.h:148
lsst::geom::AffineTransform::XX
@ XX
Definition: AffineTransform.h:77
LinearTransform.h
lsst::geom::AffineTransform::operator*
AffineTransform operator*(AffineTransform const &other) const noexcept
Construct a new AffineTransform from two others: (B * A)(p) = B(A(p))
Definition: AffineTransform.h:182
lsst::geom::AffineTransform::operator+
AffineTransform operator+(AffineTransform const &other) noexcept
Definition: AffineTransform.h:196
lsst::geom::AffineTransform::ParameterVector
Eigen::Matrix< double, 6, 1 > ParameterVector
Definition: AffineTransform.h:80
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::geom::operator<<
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Definition: AffineTransform.cc:72
lsst::geom::AffineTransform::setParameterVector
void setParameterVector(ParameterVector const &vector) noexcept
Set the transform matrix elements from a parameter vector.
Definition: AffineTransform.cc:38
lsst::geom::AffineTransform::AffineTransform
AffineTransform() noexcept
Construct an empty (identity) AffineTransform.
Definition: AffineTransform.h:84
lsst::geom::LinearTransform::applyY
double applyY(double x, double y) const noexcept
Definition: LinearTransform.h:196
lsst::geom
Definition: AffineTransform.h:36
os
std::ostream * os
Definition: Schema.cc:746
lsst::geom::AffineTransform::AffineTransform
AffineTransform(LinearTransform const &linear) noexcept
Construct an AffineTransform from a LinearTransform.
Definition: AffineTransform.h:102
lsst::geom::AffineTransform::getParameterVector
ParameterVector const getParameterVector() const noexcept
Return the transform matrix elements as a parameter vector.
Definition: AffineTransform.cc:32
lsst::geom::AffineTransform::operator()
Point2D operator()(Point2D const &p) const noexcept
Transform a Point object.
Definition: AffineTransform.h:132
Point.h
lsst::geom::AffineTransform::Y
@ Y
Definition: AffineTransform.h:77
lsst::geom::Point< double, 2 >
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
lsst::geom::Extent2D
Extent< double, 2 > Extent2D
Definition: Extent.h:400
transform
table::Key< int > transform
Definition: TransformMap.cc:299
lsst::geom::AffineTransform::X
@ X
Definition: AffineTransform.h:77
lsst::geom::AffineTransform::operator=
AffineTransform & operator=(AffineTransform const &) noexcept=default
lsst::geom::AffineTransform::getTranslation
Extent2D & getTranslation() noexcept
Definition: AffineTransform.h:153
lsst::geom::AffineTransform::TransformDerivativeMatrix
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix
Definition: AffineTransform.h:81
lsst::geom::AffineTransform::operator-=
AffineTransform & operator-=(AffineTransform const &other) noexcept
Definition: AffineTransform.h:202
lsst::geom::AffineTransform::AffineTransform
AffineTransform(AffineTransform &&) noexcept=default
lsst::geom::AffineTransform::operator-
AffineTransform operator-(AffineTransform const &other) noexcept
Definition: AffineTransform.h:208
lsst::geom::makeAffineTransformFromTriple
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)
Definition: AffineTransform.cc:88
lsst::geom::Extent< double, 2 >
lsst::geom::AffineTransform::getMatrix
Matrix const getMatrix() const noexcept
Return the transform as a full 3x3 matrix.
Definition: AffineTransform.cc:47
lsst::geom::AffineTransform::AffineTransform
AffineTransform(Eigen::Matrix3d const &matrix) noexcept
Construct an AffineTransform from a 3x3 matrix.
Definition: AffineTransform.h:87