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 <gael.guennebaud@inria.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 #ifndef EIGEN_SCALING_H
11 #define EIGEN_SCALING_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
35 namespace internal
36 {
37  // This helper helps nvcc+MSVC to properly parse this file.
38  // See bug 1412.
39  template <typename Scalar, int Dim, int Mode>
40  struct uniformscaling_times_affine_returntype
41  {
42  enum
43  {
44  NewMode = int(Mode) == int(Isometry) ? Affine : Mode
45  };
46  typedef Transform <Scalar, Dim, NewMode> type;
47  };
48 }
49 
50 template<typename Scalar_>
52 {
53 public:
55  typedef Scalar_ Scalar;
56 
57 protected:
58 
60 
61 public:
62 
66  explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
67 
68  inline const Scalar& factor() const { return m_factor; }
69  inline Scalar& factor() { return m_factor; }
70 
72  inline UniformScaling operator* (const UniformScaling& other) const
73  { return UniformScaling(m_factor * other.factor()); }
74 
76  template<int Dim>
78 
80  template<int Dim, int Mode, int Options>
81  inline typename
84  {
86  res.prescale(factor());
87  return res;
88  }
89 
91  // TODO returns an expression
92  template<typename Derived>
93  inline typename Eigen::internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
94  { return other * m_factor; }
95 
96  template<typename Derived,int Dim>
98  { return r.toRotationMatrix() * m_factor; }
99 
101  inline UniformScaling inverse() const
102  { return UniformScaling(Scalar(1)/m_factor); }
103 
109  template<typename NewScalarType>
111  { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
112 
114  template<typename OtherScalarType>
115  inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
116  { m_factor = Scalar(other.factor()); }
117 
122  bool isApprox(const UniformScaling& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
123  { return internal::isApprox(m_factor, other.factor(), prec); }
124 
125 };
126 
129 
133 // NOTE this operator is defined in MatrixBase and not as a friend function
134 // of UniformScaling to fix an internal crash of Intel's ICC
135 template<typename Derived,typename Scalar>
136 EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,Scalar,product)
137 operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s)
138 { return matrix.derived() * s.factor(); }
139 
145 template<typename RealScalar>
146 inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
148 
150 template<typename Scalar>
151 inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
152 { return DiagonalMatrix<Scalar,2>(sx, sy); }
154 template<typename Scalar>
155 inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
156 { return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
157 
161 template<typename Derived>
163 { return coeffs.asDiagonal(); }
164 
166 template<typename Derived>
168 { return typename DiagonalWrapper<const Derived>::PlainObject(std::move(coeffs.derived())); }
169 
179 
180 template<typename Scalar>
181 template<int Dim>
184 {
186  res.matrix().setZero();
187  res.linear().diagonal().fill(factor());
188  res.translation() = factor() * t.vector();
189  res(Dim,Dim) = Scalar(1);
190  return res;
191 }
192 
193 } // end namespace Eigen
194 
195 #endif // EIGEN_SCALING_H
#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR, SCALAR, OPNAME)
Definition: Macros.h:1203
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
DiagonalMatrix< Scalar, DiagonalVectorType::SizeAtCompileTime, DiagonalVectorType::MaxSizeAtCompileTime > PlainObject
Represents a diagonal matrix with its storage.
Expression of a diagonal matrix.
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
const DiagonalWrapper< const Derived > asDiagonal() const
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Common base class for compact rotation representations.
Definition: RotationBase.h:32
RotationMatrixType toRotationMatrix() const
Definition: RotationBase.h:47
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:207
Represents a translation transformation.
Definition: Translation.h:33
const VectorType & vector() const
Definition: Translation.h:89
Represents a generic uniform scaling transformation.
Definition: Scaling.h:52
Scalar & factor()
Definition: Scaling.h:69
UniformScaling inverse() const
Definition: Scaling.h:101
bool isApprox(const UniformScaling &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Scaling.h:122
Matrix< Scalar, Dim, Dim > operator*(const RotationBase< Derived, Dim > &r) const
Definition: Scaling.h:97
UniformScaling< NewScalarType > cast() const
Definition: Scaling.h:110
UniformScaling operator*(const UniformScaling &other) const
Definition: Scaling.h:72
UniformScaling(const Scalar &s)
Definition: Scaling.h:66
const Scalar & factor() const
Definition: Scaling.h:68
UniformScaling(const UniformScaling< OtherScalarType > &other)
Definition: Scaling.h:115
@ Affine
Definition: Constants.h:464
@ Isometry
Definition: Constants.h:461
bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
: InteropHeaders
Definition: Core:139
UniformScaling< float > Scaling(float s)
Definition: Scaling.h:141
DiagonalMatrix< double, 3 > AlignedScaling3d
Definition: Scaling.h:177
DiagonalMatrix< float, 3 > AlignedScaling3f
Definition: Scaling.h:175
DiagonalMatrix< float, 2 > AlignedScaling2f
Definition: Scaling.h:171
DiagonalMatrix< double, 2 > AlignedScaling2d
Definition: Scaling.h:173
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231