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 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_SCALING_H
26 #define EIGEN_SCALING_H
27 
28 namespace Eigen {
29 
47 template<typename _Scalar>
49 {
50 public:
52  typedef _Scalar Scalar;
53 
54 protected:
55 
57 
58 public:
59 
63  explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
64 
65  inline const Scalar& factor() const { return m_factor; }
66  inline Scalar& factor() { return m_factor; }
67 
69  inline UniformScaling operator* (const UniformScaling& other) const
70  { return UniformScaling(m_factor * other.factor()); }
71 
73  template<int Dim>
75 
77  template<int Dim, int Mode, int Options>
79 
81  // TODO returns an expression
82  template<typename Derived>
83  inline typename internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
84  { return other * m_factor; }
85 
86  template<typename Derived,int Dim>
88  { return r.toRotationMatrix() * m_factor; }
89 
91  inline UniformScaling inverse() const
92  { return UniformScaling(Scalar(1)/m_factor); }
93 
99  template<typename NewScalarType>
101  { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
102 
104  template<typename OtherScalarType>
105  inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
106  { m_factor = Scalar(other.factor()); }
107 
113  { return internal::isApprox(m_factor, other.factor(), prec); }
114 
115 };
116 
118 // NOTE this operator is defiend in MatrixBase and not as a friend function
119 // of UniformScaling to fix an internal crash of Intel's ICC
120 template<typename Derived> typename MatrixBase<Derived>::ScalarMultipleReturnType
122 { return derived() * s.factor(); }
123 
125 static inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
127 static inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
129 template<typename RealScalar>
130 static inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
131 { return UniformScaling<std::complex<RealScalar> >(s); }
132 
134 template<typename Scalar>
135 static inline DiagonalMatrix<Scalar,2> Scaling(Scalar sx, Scalar sy)
136 { return DiagonalMatrix<Scalar,2>(sx, sy); }
138 template<typename Scalar>
139 static inline DiagonalMatrix<Scalar,3> Scaling(Scalar sx, Scalar sy, Scalar sz)
140 { return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
141 
145 template<typename Derived>
146 static inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
147 { return coeffs.asDiagonal(); }
148 
160 
161 template<typename Scalar>
162 template<int Dim>
165 {
167  res.matrix().setZero();
168  res.linear().diagonal().fill(factor());
169  res.translation() = factor() * t.vector();
170  res(Dim,Dim) = Scalar(1);
171  return res;
172 }
173 
174 template<typename Scalar>
175 template<int Dim,int Mode,int Options>
178 {
180  res.prescale(factor());
181  return res;
182 }
183 
184 } // end namespace Eigen
185 
186 #endif // EIGEN_SCALING_H