LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
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  typedef std::shared_ptr<AffineTransform> Ptr;
80  typedef std::shared_ptr<AffineTransform const> ConstPtr;
81 
82  enum Parameters {XX=0,YX=1,XY=2,YY=3,X=4,Y=5};
83 
84  typedef Eigen::Matrix3d Matrix;
85  typedef Eigen::Matrix<double,6,1> ParameterVector;
86  typedef Eigen::Matrix<double,2,6> TransformDerivativeMatrix;
87 
88 
91 
93  explicit AffineTransform(Eigen::Matrix3d const & matrix)
94  : _linear(matrix.block<2,2>(0,0)),
95  _translation(matrix.block<2,1>(0,2))
96  {}
97 
99  explicit AffineTransform(Eigen::Matrix2d const & linear)
100  : _linear(linear), _translation() {}
101 
103  explicit AffineTransform(Eigen::Vector2d const & translation)
104  : _linear(), _translation(translation) {}
105 
107  explicit AffineTransform(
108  Eigen::Matrix2d const & linear, Eigen::Vector2d const & translation
109  ) : _linear(linear), _translation(translation) {}
110 
113  : _linear(linear), _translation() {}
114 
116  explicit AffineTransform(Extent2D const & translation)
117  : _linear(), _translation(translation) {}
118 
120  explicit AffineTransform(
121  LinearTransform const & linear, Extent2D const & translation
122  ) : _linear(linear), _translation(translation) {}
123 
124 
125  AffineTransform const invert() const;
126 
128  bool isIdentity() const { return getMatrix().isIdentity(); }
129 
130 
136  Point2D operator()(Point2D const &p) const {
137  return Point2D(_linear(p) + _translation);
138  }
139 
145  Extent2D operator()(Extent2D const &p) const {
146  return Extent2D(_linear(p));
147  }
148 
149  Extent2D const & getTranslation() const {return _translation;}
151 
152  LinearTransform const & getLinear() const {return _linear;}
154 
155  Matrix const getMatrix() const;
156 
157  ParameterVector const getParameterVector() const;
158  void setParameterVector(ParameterVector const & vector);
159 
160  double & operator[](int i) {
161  return (i < 4) ? _linear[i] : _translation[i - 4];
162  }
163  double operator[](int i) const {
164  return (i < 4) ? _linear[i] : _translation[i - 4];
165  }
166 
171  return AffineTransform(
172  getLinear()*other.getLinear(),
174  );
175  }
176 
178  _linear = other._linear;
179  _translation = other._translation;
180  return *this;
181  }
182 
184  _linear += other._linear;
185  _translation += other._translation;
186  return *this;
187  }
188 
190  AffineTransform tmp(*this);
191  tmp += other;
192  return tmp;
193  }
194 
196  _linear -= other._linear;
197  _translation -= other._translation;
198  return *this;
199  }
200 
202  AffineTransform tmp(*this);
203  tmp -= other;
204  return tmp;
205  }
206 
219  static AffineTransform makeScaling(double s) {
221  }
222 
236  static AffineTransform makeScaling(double s, double t) {
238  }
253  }
254 
268  return AffineTransform(translation);
269  }
270 
273 
274 private:
275 
278 };
279 
280 std::ostream & operator<<(std::ostream & os, lsst::afw::geom::AffineTransform const & transform);
281 
282 
283 //
284 // Returns the unique AffineTransform A such that A(p_i)=q_i for i=1,2,3
285 //
287  Point2D const &q1, Point2D const &q2, Point2D const &q3);
288 
289 
290 }}}
291 
292 #endif // !LSST_AFW_MATH_AFFINE_TRANSFORM_H
TransformDerivativeMatrix dTransform(Point2D const &input) const
void setParameterVector(ParameterVector const &vector)
A coordinate class intended to represent absolute positions.
bool isIdentity() const
Whether the transform is a no-op.
AffineTransform(LinearTransform const &linear, Extent2D const &translation)
Construct an AffineTransform from a LinearTransform and Extent2D.
AffineTransform const invert() const
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
AffineTransform(LinearTransform const &linear)
Construct an AffineTransform from a LinearTransform.
Point2D operator()(Point2D const &p) const
Transform a Point object.
Extent< double, 2 > Extent2D
Definition: Extent.h:361
AffineTransform(Eigen::Matrix2d const &linear)
Construct an AffineTransform with no translation from a 2x2 matrix.
Extent2D operator()(Extent2D const &p) const
Transform an Extent object.
AffineTransform operator*(AffineTransform const &other) const
Construct a new AffineTransform from two others: (B * A)(p) = B(A(p))
AffineTransform(Extent2D const &translation)
Construct a translation-only AffineTransform from an Extent2D.
AffineTransform & operator=(AffineTransform const &other)
LinearTransform const & getLinear() const
static LinearTransform makeScaling(double s)
static AffineTransform makeScaling(double s, double t)
Construct a new AffineTransform that represents a non-uniform scaling.
A 2D linear coordinate transformation.
static LinearTransform makeRotation(Angle t)
AffineTransform()
Construct an empty (identity) AffineTransform.
AffineTransform & operator+=(AffineTransform const &other)
A class representing an Angle.
Definition: Angle.h:103
ParameterVector const getParameterVector() const
An affine coordinate transformation consisting of a linear transformation and an offset.
AffineTransform operator+(AffineTransform const &other)
AffineTransform & operator-=(AffineTransform const &other)
std::shared_ptr< AffineTransform const > ConstPtr
static AffineTransform makeTranslation(Extent2D translation)
Construct a new AffineTransform that represents a pure translation.
AffineTransform(Eigen::Matrix3d const &matrix)
Construct an AffineTransform from a 3x3 matrix.
metadata input
Point< double, 2 > Point2D
Definition: Point.h:288
AffineTransform(Eigen::Vector2d const &translation)
Construct a translation-only AffineTransform from a vector.
Extent2D const & getTranslation() const
Matrix const getMatrix() const
AffineTransform operator-(AffineTransform const &other)
Eigen::Matrix< double, 6, 1 > ParameterVector
double operator[](int i) const
A coordinate class intended to represent offsets and dimensions.
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)
static AffineTransform makeRotation(Angle t)
Construct a new AffineTransform that represents a CCW rotation in radians.
static AffineTransform makeScaling(double s)
Construct a new AffineTransform that represents a uniform scaling.
std::shared_ptr< AffineTransform > Ptr
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
Construct an AffineTransform from a 2x2 matrix and vector.