LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 <boost/shared_ptr.hpp>
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 boost::shared_ptr<AffineTransform> Ptr;
80  typedef boost::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 
112  explicit AffineTransform(LinearTransform const & linear)
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 
195  static AffineTransform makeScaling(double s) {
197  }
198 
212  static AffineTransform makeScaling(double s, double t) {
214  }
229  }
230 
243  static AffineTransform makeTranslation(Extent2D translation) {
244  return AffineTransform(translation);
245  }
246 
247  TransformDerivativeMatrix dTransform(Point2D const & input) const;
248  TransformDerivativeMatrix dTransform(Extent2D const & input) const;
249 
250 private:
251 
254 };
255 
256 std::ostream & operator<<(std::ostream & os, lsst::afw::geom::AffineTransform const & transform);
257 
258 
259 //
260 // Returns the unique AffineTransform A such that A(p_i)=q_i for i=1,2,3
261 //
263  Point2D const &q1, Point2D const &q2, Point2D const &q3);
264 
265 
266 }}}
267 
268 #endif // !LSST_AFW_MATH_AFFINE_TRANSFORM_H
AffineTransform(Eigen::Matrix3d const &matrix)
Matrix const getMatrix() const
A coordinate class intended to represent absolute positions.
static AffineTransform makeScaling(double s)
Construct a new AffineTransform that represents a uniform scaling.
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix
AffineTransform const invert() const
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
boost::shared_ptr< AffineTransform > Ptr
Extent< double, 2 > Extent2D
Definition: Extent.h:358
static AffineTransform makeRotation(Angle t)
Construct a new AffineTransform that represents a CCW rotation in radians.
static LinearTransform makeRotation(Angle t)
static AffineTransform makeTranslation(Extent2D translation)
Construct a new AffineTransform that represents a pure translation.
AffineTransform & operator=(AffineTransform const &other)
AffineTransform(Eigen::Vector2d const &translation)
AffineTransform operator*(AffineTransform const &other) const
A 2D linear coordinate transformation.
Extent2D operator()(Extent2D const &p) const
An affine coordinate transformation consisting of a linear transformation and an offset.
AffineTransform(Extent2D const &translation)
static LinearTransform makeScaling(double s)
AffineTransform(LinearTransform const &linear)
Eigen::Matrix< double, 6, 1 > ParameterVector
ParameterVector const getParameterVector() const
LinearTransform const & getLinear() const
static AffineTransform makeScaling(double s, double t)
Construct a new AffineTransform that represents a non-uniform scaling.
void setParameterVector(ParameterVector const &vector)
TransformDerivativeMatrix dTransform(Point2D const &input) const
AffineTransform(LinearTransform const &linear, Extent2D const &translation)
Extent2D const & getTranslation() const
AffineTransform(Eigen::Matrix2d const &linear)
Point< double, 2 > Point2D
Definition: Point.h:286
Point2D operator()(Point2D const &p) 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)
boost::shared_ptr< AffineTransform const > ConstPtr
double operator[](int i) const