Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:18

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_SCALING_H
0011 #define EIGEN_SCALING_H
0012 
0013 namespace RivetEigen { 
0014 
0015 /** \geometry_module \ingroup Geometry_Module
0016   *
0017   * \class UniformScaling
0018   *
0019   * \brief Represents a generic uniform scaling transformation
0020   *
0021   * \tparam _Scalar the scalar type, i.e., the type of the coefficients.
0022   *
0023   * This class represent a uniform scaling transformation. It is the return
0024   * type of Scaling(Scalar), and most of the time this is the only way it
0025   * is used. In particular, this class is not aimed to be used to store a scaling transformation,
0026   * but rather to make easier the constructions and updates of Transform objects.
0027   *
0028   * To represent an axis aligned scaling, use the DiagonalMatrix class.
0029   *
0030   * \sa Scaling(), class DiagonalMatrix, MatrixBase::asDiagonal(), class Translation, class Transform
0031   */
0032 
0033 namespace internal
0034 {
0035   // This helper helps nvcc+MSVC to properly parse this file.
0036   // See bug 1412.
0037   template <typename Scalar, int Dim, int Mode>
0038   struct uniformscaling_times_affine_returntype
0039   {
0040     enum
0041     {
0042       NewMode = int(Mode) == int(Isometry) ? Affine : Mode
0043     };
0044     typedef Transform <Scalar, Dim, NewMode> type;
0045   };
0046 }
0047 
0048 template<typename _Scalar>
0049 class UniformScaling
0050 {
0051 public:
0052   /** the scalar type of the coefficients */
0053   typedef _Scalar Scalar;
0054 
0055 protected:
0056 
0057   Scalar m_factor;
0058 
0059 public:
0060 
0061   /** Default constructor without initialization. */
0062   UniformScaling() {}
0063   /** Constructs and initialize a uniform scaling transformation */
0064   explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
0065 
0066   inline const Scalar& factor() const { return m_factor; }
0067   inline Scalar& factor() { return m_factor; }
0068 
0069   /** Concatenates two uniform scaling */
0070   inline UniformScaling operator* (const UniformScaling& other) const
0071   { return UniformScaling(m_factor * other.factor()); }
0072 
0073   /** Concatenates a uniform scaling and a translation */
0074   template<int Dim>
0075   inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const;
0076 
0077   /** Concatenates a uniform scaling and an affine transformation */
0078   template<int Dim, int Mode, int Options>
0079   inline typename
0080     internal::uniformscaling_times_affine_returntype<Scalar,Dim,Mode>::type
0081     operator* (const Transform<Scalar, Dim, Mode, Options>& t) const
0082   {
0083     typename internal::uniformscaling_times_affine_returntype<Scalar,Dim,Mode>::type res = t;
0084     res.prescale(factor());
0085     return res;
0086   }
0087 
0088   /** Concatenates a uniform scaling and a linear transformation matrix */
0089   // TODO returns an expression
0090   template<typename Derived>
0091   inline typename RivetEigen::internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
0092   { return other * m_factor; }
0093 
0094   template<typename Derived,int Dim>
0095   inline Matrix<Scalar,Dim,Dim> operator*(const RotationBase<Derived,Dim>& r) const
0096   { return r.toRotationMatrix() * m_factor; }
0097 
0098   /** \returns the inverse scaling */
0099   inline UniformScaling inverse() const
0100   { return UniformScaling(Scalar(1)/m_factor); }
0101 
0102   /** \returns \c *this with scalar type casted to \a NewScalarType
0103     *
0104     * Note that if \a NewScalarType is equal to the current scalar type of \c *this
0105     * then this function smartly returns a const reference to \c *this.
0106     */
0107   template<typename NewScalarType>
0108   inline UniformScaling<NewScalarType> cast() const
0109   { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
0110 
0111   /** Copy constructor with scalar type conversion */
0112   template<typename OtherScalarType>
0113   inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
0114   { m_factor = Scalar(other.factor()); }
0115 
0116   /** \returns \c true if \c *this is approximately equal to \a other, within the precision
0117     * determined by \a prec.
0118     *
0119     * \sa MatrixBase::isApprox() */
0120   bool isApprox(const UniformScaling& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
0121   { return internal::isApprox(m_factor, other.factor(), prec); }
0122 
0123 };
0124 
0125 /** \addtogroup Geometry_Module */
0126 // @{
0127 
0128 /** Concatenates a linear transformation matrix and a uniform scaling
0129   * \relates UniformScaling
0130   */
0131 // NOTE this operator is defined in MatrixBase and not as a friend function
0132 // of UniformScaling to fix an internal crash of Intel's ICC
0133 template<typename Derived,typename Scalar>
0134 EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,Scalar,product)
0135 operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s)
0136 { return matrix.derived() * s.factor(); }
0137 
0138 /** Constructs a uniform scaling from scale factor \a s */
0139 inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
0140 /** Constructs a uniform scaling from scale factor \a s */
0141 inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
0142 /** Constructs a uniform scaling from scale factor \a s */
0143 template<typename RealScalar>
0144 inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
0145 { return UniformScaling<std::complex<RealScalar> >(s); }
0146 
0147 /** Constructs a 2D axis aligned scaling */
0148 template<typename Scalar>
0149 inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
0150 { return DiagonalMatrix<Scalar,2>(sx, sy); }
0151 /** Constructs a 3D axis aligned scaling */
0152 template<typename Scalar>
0153 inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
0154 { return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
0155 
0156 /** Constructs an axis aligned scaling expression from vector expression \a coeffs
0157   * This is an alias for coeffs.asDiagonal()
0158   */
0159 template<typename Derived>
0160 inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
0161 { return coeffs.asDiagonal(); }
0162 
0163 /** \deprecated */
0164 typedef DiagonalMatrix<float, 2> AlignedScaling2f;
0165 /** \deprecated */
0166 typedef DiagonalMatrix<double,2> AlignedScaling2d;
0167 /** \deprecated */
0168 typedef DiagonalMatrix<float, 3> AlignedScaling3f;
0169 /** \deprecated */
0170 typedef DiagonalMatrix<double,3> AlignedScaling3d;
0171 // @}
0172 
0173 template<typename Scalar>
0174 template<int Dim>
0175 inline Transform<Scalar,Dim,Affine>
0176 UniformScaling<Scalar>::operator* (const Translation<Scalar,Dim>& t) const
0177 {
0178   Transform<Scalar,Dim,Affine> res;
0179   res.matrix().setZero();
0180   res.linear().diagonal().fill(factor());
0181   res.translation() = factor() * t.vector();
0182   res(Dim,Dim) = Scalar(1);
0183   return res;
0184 }
0185 
0186 } // end namespace RivetEigen
0187 
0188 #endif // EIGEN_SCALING_H