LSSTApplications  16.0-10-gc1446dd+46,16.0-11-g09ed895+1,16.0-11-gffd197f+3,16.0-13-g7649090,16.0-14-g0a28612+1,16.0-14-g6c7ed55+20,16.0-15-ga29f190+1,16.0-16-g89065d4+19,16.0-16-gd8e3590+20,16.0-17-g7e0e4ff+14,16.0-17-ga3d2e9f+4,16.0-18-g8b9f497+2,16.0-19-gb830ed4e+20,16.0-2-g0febb12+21,16.0-2-g9d5294e+63,16.0-2-ga8830df+5,16.0-26-gc0e79ff+1,16.0-27-ge118ca2+3,16.0-3-ge00e371+25,16.0-4-g18f3627+7,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+20,16.0-4-gade8416+13,16.0-4-gb13d127+5,16.0-44-ga6515cd1+3,16.0-5-g6a53317+25,16.0-5-gb3f8a4b+78,16.0-6-g9321be7+4,16.0-6-gcbc7b31+32,16.0-6-gf49912c+20,16.0-65-g76fe3eef2,16.0-7-g00e1f5f+1,16.0-7-gd2eeba5+41,16.0-8-g21fd5fe+20,16.0-8-g3a9f023+14,16.0-8-g4734f7a,16.0-9-g85d1a16+20,16.0-9-gf5c1f43+2,master-gdbf645fb6d+1,w.2018.50
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;
122  AffineTransform const invert() const { return inverted(); };
124 
126  bool isIdentity() const noexcept { return getMatrix().isIdentity(); }
127 
133  Point2D operator()(Point2D const &p) const noexcept { return Point2D(_linear(p) + _translation); }
134 
140  Extent2D operator()(Extent2D const &p) const noexcept { return Extent2D(_linear(p)); }
141 
142  Extent2D const &getTranslation() const noexcept { return _translation; }
143  Extent2D &getTranslation() noexcept { return _translation; }
144 
145  LinearTransform const &getLinear() const noexcept { return _linear; }
146  LinearTransform &getLinear() noexcept { return _linear; }
147 
151  Matrix const getMatrix() const noexcept;
152 
158  ParameterVector const getParameterVector() const noexcept;
164  void setParameterVector(ParameterVector const &vector) noexcept;
165 
166  double &operator[](int i) { return (i < 4) ? _linear[i] : _translation[i - 4]; }
167  double operator[](int i) const { return (i < 4) ? _linear[i] : _translation[i - 4]; }
168 
173  return AffineTransform(getLinear() * other.getLinear(),
174  getLinear()(other.getTranslation()) + getTranslation());
175  }
176 
177  AffineTransform &operator=(AffineTransform const &) noexcept = default;
178  AffineTransform &operator=(AffineTransform &&) noexcept = default;
179 
181  _linear += other._linear;
182  _translation += other._translation;
183  return *this;
184  }
185 
187  AffineTransform tmp(*this);
188  tmp += other;
189  return tmp;
190  }
191 
193  _linear -= other._linear;
194  _translation -= other._translation;
195  return *this;
196  }
197 
199  AffineTransform tmp(*this);
200  tmp -= other;
201  return tmp;
202  }
203 
216  static AffineTransform makeScaling(double s) noexcept {
218  }
219 
233  static AffineTransform makeScaling(double s, double t) noexcept {
235  }
248  static AffineTransform makeRotation(Angle t) noexcept {
250  }
251 
264  static AffineTransform makeTranslation(Extent2D translation) noexcept {
265  return AffineTransform(translation);
266  }
267 
271  TransformDerivativeMatrix dTransform(Point2D const &input) const noexcept;
275  TransformDerivativeMatrix dTransform(Extent2D const &input) const noexcept;
276 
277 private:
278  LinearTransform _linear;
279  Extent2D _translation;
280 };
281 
283 
284 //
285 // Returns the unique AffineTransform A such that A(p_i)=q_i for i=1,2,3
286 //
288  Point2D const &q1, Point2D const &q2, Point2D const &q3);
289 } // namespace geom
290 } // namespace lsst
291 
292 #endif // !LSST_GEOM_AFFINE_TRANSFORM_H
Extent2D operator()(Extent2D const &p) const noexcept
Transform an Extent object.
AffineTransform(LinearTransform const &linear, Extent2D const &translation) noexcept
Construct an AffineTransform from a LinearTransform and Extent2D.
void setParameterVector(ParameterVector const &vector) noexcept
Set the transform matrix elements from a parameter vector.
AffineTransform(Eigen::Matrix2d const &linear) noexcept
Construct an AffineTransform with no translation from a 2x2 matrix.
An affine coordinate transformation consisting of a linear transformation and an offset.
AffineTransform & operator=(AffineTransform const &) noexcept=default
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix
static AffineTransform makeScaling(double s) noexcept
Construct a new AffineTransform that represents a uniform scaling.
Point2D operator()(Point2D const &p) const noexcept
Transform a Point object.
AffineTransform(Eigen::Matrix3d const &matrix) noexcept
Construct an AffineTransform from a 3x3 matrix.
AffineTransform(Eigen::Vector2d const &translation) noexcept
Construct a translation-only AffineTransform from a vector.
AffineTransform & operator+=(AffineTransform const &other) noexcept
AffineTransform operator+(AffineTransform const &other) noexcept
static AffineTransform makeScaling(double s, double t) noexcept
Construct a new AffineTransform that represents a non-uniform scaling.
AffineTransform & operator-=(AffineTransform const &other) noexcept
Eigen::Matrix< double, 6, 1 > ParameterVector
static AffineTransform makeTranslation(Extent2D translation) noexcept
Construct a new AffineTransform that represents a pure translation.
A class representing an angle.
Definition: Angle.h:127
Point< double, 2 > Point2D
Definition: Point.h:324
bool isIdentity() const noexcept
Whether the transform is a no-op.
Matrix const getMatrix() const noexcept
Return the transform as a full 3x3 matrix.
double operator[](int i) const
static AffineTransform makeRotation(Angle t) noexcept
Construct a new AffineTransform that represents a CCW rotation in radians.
~AffineTransform() noexcept=default
LinearTransform & getLinear() noexcept
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation) noexcept
Construct an AffineTransform from a 2x2 matrix and vector.
A base class for image defects.
Definition: cameraGeom.dox:3
AffineTransform(Extent2D const &translation) noexcept
Construct a translation-only AffineTransform from an Extent2D.
Extent2D & getTranslation() noexcept
ParameterVector const getParameterVector() const noexcept
Return the transform matrix elements as a parameter vector.
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
solver_t * s
static LinearTransform makeScaling(double s) noexcept
LinearTransform const & getLinear() const noexcept
AffineTransform operator-(AffineTransform const &other) noexcept
AffineTransform operator*(AffineTransform const &other) const noexcept
Construct a new AffineTransform from two others: (B * A)(p) = B(A(p))
TransformDerivativeMatrix dTransform(Point2D const &input) const noexcept
Take the derivative of (*this)(input) w.r.t the transform elements.
static LinearTransform makeRotation(Angle t) noexcept
AffineTransform const invert() const
Return the inverse transform.
ItemVariant const * other
Definition: Schema.cc:56
Extent< double, 2 > Extent2D
Definition: Extent.h:400
STL class.
AffineTransform const inverted() const
Return the inverse transform.
A 2D linear coordinate transformation.
std::ostream * os
Definition: Schema.cc:746
AffineTransform() noexcept
Construct an empty (identity) AffineTransform.
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)
AffineTransform(LinearTransform const &linear) noexcept
Construct an AffineTransform from a LinearTransform.
Extent2D const & getTranslation() const noexcept