LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
LinearTransform.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_LINEAR_TRANSFORM_H
23#define LSST_GEOM_LINEAR_TRANSFORM_H
24
25#include "Eigen/Core"
26#include "Eigen/Geometry"
27
29#include "lsst/geom/Point.h"
30#include "lsst/geom/Angle.h"
31
32namespace lsst {
33namespace geom {
34
37
38
69class LinearTransform final {
70public:
71 enum Parameters { XX = 0, YX = 1, XY = 2, YY = 3 };
72
73 typedef Eigen::Matrix<double, 4, 1> ParameterVector;
74 typedef Eigen::Matrix<double, 2, 4> TransformDerivativeMatrix;
75 typedef Eigen::Matrix<double, 4, 4> ProductDerivativeMatrix;
76
77 typedef Eigen::Matrix<double, 2, 2, Eigen::DontAlign> Matrix;
78
80 LinearTransform() noexcept : _matrix(Matrix::Identity()) {}
81
83 explicit LinearTransform(Matrix const& matrix) noexcept : _matrix(matrix) {}
84
85 // Can't use both =default and noexcept until Eigen supports noexcept
86 LinearTransform(LinearTransform const& other) noexcept : _matrix(other._matrix){};
87 LinearTransform(LinearTransform&& other) noexcept : _matrix(std::move(other._matrix)){};
88 ~LinearTransform() noexcept = default;
89
90 LinearTransform operator*(LinearTransform const& other) const noexcept {
91 return LinearTransform(getMatrix() * other.getMatrix());
92 }
93
94 static LinearTransform makeScaling(double s) noexcept {
95 return LinearTransform((Matrix() << s, 0.0, 0.0, s).finished());
96 }
97
98 static LinearTransform makeScaling(double s, double t) noexcept {
99 return LinearTransform((Matrix() << s, 0.0, 0.0, t).finished());
100 }
101
102 static LinearTransform makeRotation(Angle t) noexcept {
103 return LinearTransform(Matrix(Eigen::Rotation2D<double>(t.asRadians())));
104 }
105
106 // Can't use both =default and noexcept until Eigen supports noexcept
107 LinearTransform& operator=(LinearTransform const& other) noexcept {
108 _matrix = other._matrix;
109 return *this;
110 }
112 _matrix = std::move(other._matrix);
113 return *this;
114 }
115
117 _matrix += other._matrix;
118 return *this;
119 }
120
122 LinearTransform tmp(*this);
123 tmp += other;
124 return tmp;
125 }
126
128 _matrix -= other._matrix;
129 return *this;
130 }
131
133 LinearTransform tmp(*this);
134 tmp -= other;
135 return tmp;
136 }
137
143 ParameterVector const getParameterVector() const noexcept;
149 void setParameterVector(ParameterVector const& vector) noexcept;
150
151 Matrix const& getMatrix() const noexcept { return _matrix; }
152 Matrix& getMatrix() noexcept { return _matrix; }
153
154 double& operator[](int i) { return _matrix(i % 2, i / 2); }
155 double const& operator[](int i) const { return const_cast<Matrix&>(_matrix)(i % 2, i / 2); }
156
162 LinearTransform const inverted() const;
163
167 double computeDeterminant() const noexcept;
168
170 bool isIdentity() const noexcept { return getMatrix().isIdentity(); }
171
178 Point2D operator()(Point2D const& p) const noexcept { return Point2D(getMatrix() * p.asEigen()); }
179
186 Extent2D operator()(Extent2D const& p) const noexcept { return Extent2D(getMatrix() * p.asEigen()); }
187
189
195 double applyX(double x, double y) const noexcept { return _matrix(0, 0)*x + _matrix(0, 1)*y; }
196 double applyY(double x, double y) const noexcept { return _matrix(1, 0)*x + _matrix(1, 1)*y; }
198
202 TransformDerivativeMatrix dTransform(Point2D const& input) const noexcept;
203
205 TransformDerivativeMatrix dTransform(Extent2D const& input) const noexcept {
206 return dTransform(Point2D(input));
207 }
208
209private:
210 Matrix _matrix;
211};
212
214
215} // namespace geom
216} // namespace lsst
217
218#endif // !LSST_GEOM_LINEAR_TRANSFORM_H
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition Exception.h:69
int y
Definition SpanSet.cc:48
A class representing an angle.
Definition Angle.h:128
A 2D linear coordinate transformation.
Point2D operator()(Point2D const &p) const noexcept
Transform a Point2D object.
Eigen::Matrix< double, 4, 4 > ProductDerivativeMatrix
LinearTransform operator+(LinearTransform const &other) noexcept
LinearTransform & operator-=(LinearTransform const &other) noexcept
Eigen::Matrix< double, 2, 2, Eigen::DontAlign > Matrix
LinearTransform(LinearTransform &&other) noexcept
double applyX(double x, double y) const noexcept
Transform a point given and returned as separate double values.
Matrix & getMatrix() noexcept
LinearTransform operator-(LinearTransform const &other) noexcept
Extent2D operator()(Extent2D const &p) const noexcept
Transform a Extent2D object.
static LinearTransform makeScaling(double s, double t) noexcept
static LinearTransform makeRotation(Angle t) noexcept
double applyY(double x, double y) const noexcept
static LinearTransform makeScaling(double s) noexcept
~LinearTransform() noexcept=default
LinearTransform(Matrix const &matrix) noexcept
Construct an LinearTransform from an Eigen::Matrix.
LinearTransform & operator+=(LinearTransform const &other) noexcept
LinearTransform & operator=(LinearTransform &&other) noexcept
Eigen::Matrix< double, 4, 1 > ParameterVector
double const & operator[](int i) const
TransformDerivativeMatrix dTransform(Extent2D const &input) const noexcept
Derivative of (*this)(input) with respect to the transform elements (for Extent);.
LinearTransform() noexcept
Construct an empty (identity) LinearTransform.
LinearTransform(LinearTransform const &other) noexcept
LinearTransform & operator=(LinearTransform const &other) noexcept
Eigen::Matrix< double, 2, 4 > TransformDerivativeMatrix
Reports errors that are due to events beyond the control of the program.
Definition Runtime.h:104
T move(T... args)
Extent< double, 2 > Extent2D
Definition Extent.h:400
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Point< double, 2 > Point2D
Definition Point.h:324