LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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)
A coordinate class intended to represent absolute positions.
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
AffineTransform(LinearTransform const &linear)
AffineTransform const invert() const
static LinearTransform makeScaling(double s)
Extent2D const & getTranslation() const
Point< double, 2 > Point2D
Definition: Point.h:286
TransformDerivativeMatrix dTransform(Point2D const &input) const
static AffineTransform makeScaling(double s, double t)
Construct a new AffineTransform that represents a non-uniform scaling.
Extent2D operator()(Extent2D const &p) const
A 2D linear coordinate transformation.
Eigen::Matrix< double, 6, 1 > ParameterVector
boost::shared_ptr< AffineTransform const > ConstPtr
static LinearTransform makeRotation(Angle t)
An affine coordinate transformation consisting of a linear transformation and an offset.
static AffineTransform makeRotation(Angle t)
Construct a new AffineTransform that represents a CCW rotation in radians.
Point2D operator()(Point2D const &p) const
static AffineTransform makeTranslation(Extent2D translation)
Construct a new AffineTransform that represents a pure translation.
AffineTransform(Extent2D const &translation)
static AffineTransform makeScaling(double s)
Construct a new AffineTransform that represents a uniform scaling.
AffineTransform operator*(AffineTransform const &other) const
ParameterVector const getParameterVector() const
AffineTransform(LinearTransform const &linear, Extent2D const &translation)
AffineTransform(Eigen::Matrix2d const &linear)
LinearTransform const & getLinear() const
Extent< double, 2 > Extent2D
Definition: Extent.h:358
void setParameterVector(ParameterVector const &vector)
AffineTransform & operator=(AffineTransform const &other)
AffineTransform(Eigen::Vector2d const &translation)
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)
Matrix const getMatrix() const
boost::shared_ptr< AffineTransform > Ptr
AffineTransform(Eigen::Matrix2d const &linear, Eigen::Vector2d const &translation)
Eigen::Matrix< double, 2, 6 > TransformDerivativeMatrix