Eigen2Support/Geometry/Scaling.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
11 
12 namespace Eigen {
13 
28 template<typename _Scalar, int _Dim>
29 class Scaling
30 {
31 public:
34  enum { Dim = _Dim };
36  typedef _Scalar Scalar;
45 
46 protected:
47 
48  VectorType m_coeffs;
49 
50 public:
51 
53  Scaling() {}
55  explicit inline Scaling(const Scalar& s) { m_coeffs.setConstant(s); }
57  inline Scaling(const Scalar& sx, const Scalar& sy)
58  {
59  ei_assert(Dim==2);
60  m_coeffs.x() = sx;
61  m_coeffs.y() = sy;
62  }
64  inline Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
65  {
66  ei_assert(Dim==3);
67  m_coeffs.x() = sx;
68  m_coeffs.y() = sy;
69  m_coeffs.z() = sz;
70  }
72  explicit inline Scaling(const VectorType& coeffs) : m_coeffs(coeffs) {}
73 
74  const VectorType& coeffs() const { return m_coeffs; }
75  VectorType& coeffs() { return m_coeffs; }
76 
78  inline Scaling operator* (const Scaling& other) const
79  { return Scaling(coeffs().cwise() * other.coeffs()); }
80 
82  inline TransformType operator* (const TranslationType& t) const;
83 
85  inline TransformType operator* (const TransformType& t) const;
86 
88  // TODO returns an expression
89  inline LinearMatrixType operator* (const LinearMatrixType& other) const
90  { return coeffs().asDiagonal() * other; }
91 
93  // TODO returns an expression
94  friend inline LinearMatrixType operator* (const LinearMatrixType& other, const Scaling& s)
95  { return other * s.coeffs().asDiagonal(); }
96 
97  template<typename Derived>
98  inline LinearMatrixType operator*(const RotationBase<Derived,Dim>& r) const
99  { return *this * r.toRotationMatrix(); }
100 
102  inline VectorType operator* (const VectorType& other) const
103  { return coeffs().asDiagonal() * other; }
104 
106  inline Scaling inverse() const
107  { return Scaling(coeffs().cwise().inverse()); }
108 
109  inline Scaling& operator=(const Scaling& other)
110  {
111  m_coeffs = other.m_coeffs;
112  return *this;
113  }
114 
120  template<typename NewScalarType>
122  { return typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type(*this); }
123 
125  template<typename OtherScalarType>
126  inline explicit Scaling(const Scaling<OtherScalarType,Dim>& other)
127  { m_coeffs = other.coeffs().template cast<Scalar>(); }
128 
133  bool isApprox(const Scaling& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
134  { return m_coeffs.isApprox(other.m_coeffs, prec); }
135 
136 };
137 
145 
146 template<typename Scalar, int Dim>
148 Scaling<Scalar,Dim>::operator* (const TranslationType& t) const
149 {
150  TransformType res;
151  res.matrix().setZero();
152  res.linear().diagonal() = coeffs();
153  res.translation() = m_coeffs.cwise() * t.vector();
154  res(Dim,Dim) = Scalar(1);
155  return res;
156 }
157 
158 template<typename Scalar, int Dim>
160 Scaling<Scalar,Dim>::operator* (const TransformType& t) const
161 {
162  TransformType res = t;
163  res.prescale(m_coeffs);
164  return res;
165 }
166 
167 } // end namespace Eigen
Represents a possibly non uniform scaling transformation.
Scaling(const VectorType &coeffs)
Matrix< Scalar, Dim, Dim > LinearMatrixType
const VectorType & vector() const
#define ei_assert
Scaling< double, 3 > Scaling3d
Scaling(const Scalar &sx, const Scalar &sy)
Definition: LDLT.h:16
Scaling operator*(const Scaling &other) const
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
LinearMatrixType operator*(const RotationBase< Derived, Dim > &r) const
bool isApprox(const Scaling &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const
Represents a translation transformation.
const VectorType & coeffs() const
internal::cast_return_type< Scaling, Scaling< NewScalarType, Dim > >::type cast() const
Translation< Scalar, Dim > TranslationType
Scaling & operator=(const Scaling &other)
Scaling< float, 3 > Scaling3f
Transform< Scalar, Dim > TransformType
Common base class for compact rotation representations.
Matrix< Scalar, Dim, 1 > VectorType
Derived & setZero(Index size)
ConstTranslationPart translation() const
Derived & setConstant(Index size, const Scalar &value)
Transform & prescale(const MatrixBase< OtherDerived > &other)
Scaling< float, 2 > Scaling2f
const MatrixType & matrix() const
Scaling(const Scalar &sx, const Scalar &sy, const Scalar &sz)
Scaling< double, 2 > Scaling2d
ConstLinearPart linear() const
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Represents an homogeneous transformation in a N dimensional space.
Scaling(const Scaling< OtherScalarType, Dim > &other)
RotationMatrixType toRotationMatrix() const


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:56