mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-21 00:59:36 +08:00
Matrix product refactoring (rhs products only).
Added strong inlines required for MSVC for proper inlining. Added specializations for DiagonalMatrix products to RotationBase. Added left- and righ-hand-side products with DiagonalMatrix to Transform. RHS Transform products now return Matrix objects only. Split the geo_transformations unit test. Some tests were not made for projectivities. Removed unused variables from main.h that caused warnings.
This commit is contained in:
parent
d4b664c4cd
commit
55c7848877
@ -440,7 +440,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the expression of the sum of the vector \a other to each subvector of \c *this */
|
/** Returns the expression of the sum of the vector \a other to each subvector of \c *this */
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived> EIGEN_STRONG_INLINE
|
||||||
CwiseBinaryOp<ei_scalar_sum_op<Scalar>,
|
CwiseBinaryOp<ei_scalar_sum_op<Scalar>,
|
||||||
ExpressionType,
|
ExpressionType,
|
||||||
typename ExtendedType<OtherDerived>::Type>
|
typename ExtendedType<OtherDerived>::Type>
|
||||||
|
@ -199,7 +199,7 @@ class CoeffBasedProduct
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implicit conversion to the nested type (trigger the evaluation of the product)
|
// Implicit conversion to the nested type (trigger the evaluation of the product)
|
||||||
operator const PlainObject& () const
|
EIGEN_STRONG_INLINE operator const PlainObject& () const
|
||||||
{
|
{
|
||||||
m_result.lazyAssign(*this);
|
m_result.lazyAssign(*this);
|
||||||
return m_result;
|
return m_result;
|
||||||
|
@ -362,7 +362,7 @@
|
|||||||
|
|
||||||
#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \
|
#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \
|
||||||
template<typename OtherDerived> \
|
template<typename OtherDerived> \
|
||||||
inline const CwiseBinaryOp<FUNCTOR<Scalar>, Derived, OtherDerived> \
|
EIGEN_STRONG_INLINE const CwiseBinaryOp<FUNCTOR<Scalar>, Derived, OtherDerived> \
|
||||||
METHOD(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
|
METHOD(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
|
||||||
{ \
|
{ \
|
||||||
return CwiseBinaryOp<FUNCTOR<Scalar>, Derived, OtherDerived>(derived(), other.derived()); \
|
return CwiseBinaryOp<FUNCTOR<Scalar>, Derived, OtherDerived>(derived(), other.derived()); \
|
||||||
|
@ -87,6 +87,14 @@ class RotationBase
|
|||||||
inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r)
|
inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r)
|
||||||
{ return l.derived() * r.toRotationMatrix(); }
|
{ return l.derived() * r.toRotationMatrix(); }
|
||||||
|
|
||||||
|
/** \returns the concatenation of a scaling \a l with the rotation \a r */
|
||||||
|
friend inline Transform<Scalar,Dim,Affine> operator*(const DiagonalMatrix<Scalar,Dim>& l, const Derived& r)
|
||||||
|
{
|
||||||
|
Transform<Scalar,Dim,Affine> res(r);
|
||||||
|
res.linear().applyOnTheLeft(l);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/** \returns the concatenation of the rotation \c *this with a transformation \a t */
|
/** \returns the concatenation of the rotation \c *this with a transformation \a t */
|
||||||
template<int Mode>
|
template<int Mode>
|
||||||
inline Transform<Scalar,Dim,Mode> operator*(const Transform<Scalar,Dim,Mode>& t) const
|
inline Transform<Scalar,Dim,Mode> operator*(const Transform<Scalar,Dim,Mode>& t) const
|
||||||
@ -107,6 +115,18 @@ struct ei_rotation_base_generic_product_selector<RotationDerived,MatrixType,fals
|
|||||||
{ return r.toRotationMatrix() * m; }
|
{ return r.toRotationMatrix() * m; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename RotationDerived, typename Scalar, int Dim, int MaxDim>
|
||||||
|
struct ei_rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix<Scalar,Dim,MaxDim>, false >
|
||||||
|
{
|
||||||
|
typedef Transform<Scalar,Dim,Affine> ReturnType;
|
||||||
|
inline static ReturnType run(const RotationDerived& r, const DiagonalMatrix<Scalar,Dim,MaxDim>& m)
|
||||||
|
{
|
||||||
|
ReturnType res(r);
|
||||||
|
res.linear() *= m;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename RotationDerived,typename OtherVectorType>
|
template<typename RotationDerived,typename OtherVectorType>
|
||||||
struct ei_rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
|
struct ei_rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,8 @@ template< typename Other,
|
|||||||
int Dim,
|
int Dim,
|
||||||
int HDim,
|
int HDim,
|
||||||
int OtherRows=Other::RowsAtCompileTime,
|
int OtherRows=Other::RowsAtCompileTime,
|
||||||
int OtherCols=Other::ColsAtCompileTime>
|
int OtherCols=Other::ColsAtCompileTime,
|
||||||
|
bool IsProjective = (Mode==(int)Projective)>
|
||||||
struct ei_transform_right_product_impl;
|
struct ei_transform_right_product_impl;
|
||||||
|
|
||||||
template<typename TransformType> struct ei_transform_take_affine_part;
|
template<typename TransformType> struct ei_transform_take_affine_part;
|
||||||
@ -353,7 +354,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
// note: this function is defined here because some compilers cannot find the respective declaration
|
// note: this function is defined here because some compilers cannot find the respective declaration
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
inline const typename ei_transform_right_product_impl<OtherDerived,Mode,_Dim,_Dim+1>::ResultType
|
EIGEN_STRONG_INLINE const typename ei_transform_right_product_impl<OtherDerived,Mode,_Dim,_Dim+1>::ResultType
|
||||||
operator * (const EigenBase<OtherDerived> &other) const
|
operator * (const EigenBase<OtherDerived> &other) const
|
||||||
{ return ei_transform_right_product_impl<OtherDerived,Mode,Dim,HDim>::run(*this,other.derived()); }
|
{ return ei_transform_right_product_impl<OtherDerived,Mode,Dim,HDim>::run(*this,other.derived()); }
|
||||||
|
|
||||||
@ -369,6 +370,37 @@ public:
|
|||||||
operator * (const EigenBase<OtherDerived> &a, const Transform &b)
|
operator * (const EigenBase<OtherDerived> &a, const Transform &b)
|
||||||
{ return ei_transform_left_product_impl<OtherDerived,Mode,Dim,HDim>::run(a.derived(),b); }
|
{ return ei_transform_left_product_impl<OtherDerived,Mode,Dim,HDim>::run(a.derived(),b); }
|
||||||
|
|
||||||
|
/** \returns The product expression of a transform \a a times a diagonal matrix \a b
|
||||||
|
*
|
||||||
|
* The rhs diagonal matrix is interpreted as an affine scaling transformation. The
|
||||||
|
* product results in a Transform of the same type (mode) as the lhs only if the lhs
|
||||||
|
* mode is no isometry. In that case, the returned transform is an affinity.
|
||||||
|
*/
|
||||||
|
friend inline const Transform<Scalar,Dim,((Mode==(int)Isometry)?Affine:(int)Mode)>
|
||||||
|
operator * (const Transform &a, const DiagonalMatrix<Scalar,Dim> &b)
|
||||||
|
{
|
||||||
|
Transform<Scalar,Dim,((Mode==(int)Isometry)?Affine:(int)Mode)> res(a);
|
||||||
|
res.linear() *= b;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \returns The product expression of a diagonal matrix \a a times a transform \a b
|
||||||
|
*
|
||||||
|
* The lhs diagonal matrix is interpreted as an affine scaling transformation. The
|
||||||
|
* product results in a Transform of the same type (mode) as the lhs only if the lhs
|
||||||
|
* mode is no isometry. In that case, the returned transform is an affinity.
|
||||||
|
*/
|
||||||
|
friend inline const Transform<Scalar,Dim,((Mode==(int)Isometry)?Affine:(int)Mode)>
|
||||||
|
operator * (const DiagonalMatrix<Scalar,Dim> &a, const Transform &b)
|
||||||
|
{
|
||||||
|
Transform<Scalar,Dim,((Mode==(int)Isometry)?Affine:(int)Mode)> res;
|
||||||
|
res.linear().noalias() = a*b.linear();
|
||||||
|
res.translation().noalias() = a*b.translation();
|
||||||
|
if (Mode!=int(AffineCompact))
|
||||||
|
res.matrix().row(Dim) = b.matrix().row(Dim);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
inline Transform& operator*=(const EigenBase<OtherDerived>& other) { return *this = *this * other; }
|
inline Transform& operator*=(const EigenBase<OtherDerived>& other) { return *this = *this * other; }
|
||||||
|
|
||||||
@ -431,6 +463,8 @@ public:
|
|||||||
inline Transform& operator*=(const UniformScaling<Scalar>& s) { return scale(s.factor()); }
|
inline Transform& operator*=(const UniformScaling<Scalar>& s) { return scale(s.factor()); }
|
||||||
inline Transform operator*(const UniformScaling<Scalar>& s) const;
|
inline Transform operator*(const UniformScaling<Scalar>& s) const;
|
||||||
|
|
||||||
|
inline Transform& operator*=(const DiagonalMatrix<Scalar,Dim>& s) { linear() *= s; return *this; }
|
||||||
|
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
inline Transform& operator=(const RotationBase<Derived,Dim>& r);
|
inline Transform& operator=(const RotationBase<Derived,Dim>& r);
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
@ -1058,9 +1092,9 @@ struct ei_transform_construct_from_matrix<Other, AffineCompact,Dim,HDim, HDim,HD
|
|||||||
{ transform->matrix() = other.template block<Dim,HDim>(0,0); }
|
{ transform->matrix() = other.template block<Dim,HDim>(0,0); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*********************************************************
|
/**********************************************************
|
||||||
*** Specializations of operator* with a EigenBase ***
|
*** Specializations of operator* with rhs EigenBase ***
|
||||||
*********************************************************/
|
**********************************************************/
|
||||||
|
|
||||||
// ei_general_product_return_type is a generalization of ProductReturnType, for all types (including e.g. DiagonalBase...),
|
// ei_general_product_return_type is a generalization of ProductReturnType, for all types (including e.g. DiagonalBase...),
|
||||||
// instead of being restricted to MatrixBase.
|
// instead of being restricted to MatrixBase.
|
||||||
@ -1085,145 +1119,48 @@ struct ei_transform_product_result
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Projective * set of homogeneous column vectors
|
template< typename Other, int Mode, int Dim, int HDim, int OtherCols >
|
||||||
template<typename Other, int Dim, int HDim>
|
struct ei_transform_right_product_impl<Other, Mode, Dim, HDim, HDim, OtherCols, true>
|
||||||
struct ei_transform_right_product_impl<Other,Projective, Dim,HDim, HDim, Dynamic>
|
|
||||||
{
|
{
|
||||||
typedef Transform<typename Other::Scalar,Dim,Projective> TransformType;
|
typedef typename Other::Scalar Scalar;
|
||||||
typedef typename TransformType::MatrixType MatrixType;
|
typedef typename Other::PlainObject ResultType;
|
||||||
typedef typename ProductReturnType<MatrixType,Other>::Type ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return tr.matrix() * other; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Projective * homogeneous column vector
|
EIGEN_STRONG_INLINE static ResultType run(const Transform<Scalar,Dim,Projective>& T, const Other& other)
|
||||||
template<typename Other, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Projective, Dim,HDim, HDim, 1>
|
|
||||||
{
|
{
|
||||||
typedef Transform<typename Other::Scalar,Dim,Projective> TransformType;
|
return T.matrix() * other;
|
||||||
typedef typename TransformType::MatrixType MatrixType;
|
|
||||||
typedef typename ProductReturnType<MatrixType,Other>::Type ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return tr.matrix() * other; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Projective * column vector
|
|
||||||
template<typename Other, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Projective, Dim,HDim, Dim, 1>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Projective> TransformType;
|
|
||||||
typedef Matrix<typename Other::Scalar,HDim,1> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return tr.matrix().template block<HDim,Dim>(0,0) * other + tr.matrix().col(Dim); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Affine * column vector
|
|
||||||
template<typename Other, int Mode, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Mode, Dim,HDim, Dim,1>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Mode> TransformType;
|
|
||||||
typedef Matrix<typename Other::Scalar,Dim,1> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return tr.linear() * other + tr.translation(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Affine * set of column vectors
|
|
||||||
// FIXME use a ReturnByValue to remove the temporary
|
|
||||||
template<typename Other, int Mode, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Mode, Dim,HDim, Dim,Dynamic>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Mode> TransformType;
|
|
||||||
typedef Matrix<typename Other::Scalar,Dim,Dynamic> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return (tr.linear() * other).colwise() + tr.translation(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Affine * homogeneous column vector
|
|
||||||
// FIXME added for backward compatibility, but I'm not sure we should keep it
|
|
||||||
template<typename Other, int Mode, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Mode, Dim,HDim, HDim,1>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Mode> TransformType;
|
|
||||||
typedef Matrix<typename Other::Scalar,HDim,1> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return tr.matrix() * other; }
|
|
||||||
};
|
|
||||||
template<typename Other, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,AffineCompact, Dim,HDim, HDim,1>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,AffineCompact> TransformType;
|
|
||||||
typedef Matrix<typename Other::Scalar,HDim,1> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{
|
|
||||||
ResultType res;
|
|
||||||
res.template head<HDim>() = tr.matrix() * other;
|
|
||||||
res.coeffRef(Dim) = other.coeff(Dim);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// T * linear matrix => T
|
template< typename Other, int Mode, int Dim, int HDim, int OtherRows, int OtherCols >
|
||||||
template<typename Other, int Mode, int Dim, int HDim>
|
struct ei_transform_right_product_impl<Other, Mode, Dim, HDim, OtherRows, OtherCols, false>
|
||||||
struct ei_transform_right_product_impl<Other,Mode, Dim,HDim, Dim,Dim>
|
|
||||||
{
|
{
|
||||||
typedef Transform<typename Other::Scalar,Dim,Mode> TransformType;
|
typedef typename Other::Scalar Scalar;
|
||||||
typedef typename TransformType::MatrixType MatrixType;
|
typedef typename Other::PlainObject ResultType;
|
||||||
typedef TransformType ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
EIGEN_STRONG_INLINE static ResultType run(const Transform<Scalar,Dim,Mode>& T, const Other& other)
|
||||||
{
|
{
|
||||||
TransformType res;
|
EIGEN_STATIC_ASSERT(OtherRows==Dim || OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
|
||||||
res.matrix().col(Dim) = tr.matrix().col(Dim);
|
|
||||||
res.linearExt().noalias() = (tr.linearExt() * other);
|
typedef Block<ResultType, Dim, OtherCols> TopLeftLhs;
|
||||||
if(Mode==int(Affine))
|
typedef Block<Other, Dim, OtherCols> TopLeftRhs;
|
||||||
res.matrix().row(Dim).template head<Dim>() = tr.matrix().row(Dim).template head<Dim>();
|
|
||||||
return res;
|
ResultType res(other.rows(),other.cols());
|
||||||
}
|
|
||||||
};
|
TopLeftLhs(res, 0, 0, Dim, other.cols()) =
|
||||||
|
( T.linear() * TopLeftRhs(other, 0, 0, Dim, other.cols()) ).colwise() +
|
||||||
// T * affine matrix => T
|
T.translation();
|
||||||
template<typename Other, int Mode, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Mode, Dim,HDim, Dim,HDim>
|
// we need to take .rows() because OtherRows might be Dim or HDim
|
||||||
{
|
if (OtherRows==HDim)
|
||||||
typedef Transform<typename Other::Scalar,Dim,Mode> TransformType;
|
res.row(other.rows()) = other.row(other.rows());
|
||||||
typedef typename TransformType::MatrixType MatrixType;
|
|
||||||
typedef TransformType ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{
|
|
||||||
TransformType res;
|
|
||||||
enum { Rows = Mode==int(Projective) ? HDim : Dim };
|
|
||||||
res.matrix().template block<Rows,HDim>(0,0).noalias() = (tr.linearExt() * other);
|
|
||||||
res.translationExt() += tr.translationExt();
|
|
||||||
if(Mode!=int(Affine))
|
|
||||||
res.makeAffine();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// T * generic matrix => Projective
|
|
||||||
template<typename Other, int Mode, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,Mode, Dim,HDim, HDim,HDim>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Mode> TransformType;
|
|
||||||
typedef typename TransformType::MatrixType MatrixType;
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Projective> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{ return ResultType(tr.matrix() * other); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// AffineCompact * generic matrix => Projective
|
|
||||||
template<typename Other, int Dim, int HDim>
|
|
||||||
struct ei_transform_right_product_impl<Other,AffineCompact, Dim,HDim, HDim,HDim>
|
|
||||||
{
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,AffineCompact> TransformType;
|
|
||||||
typedef Transform<typename Other::Scalar,Dim,Projective> ResultType;
|
|
||||||
static ResultType run(const TransformType& tr, const Other& other)
|
|
||||||
{
|
|
||||||
ResultType res;
|
|
||||||
res.affine().noalias() = tr.matrix() * other;
|
|
||||||
res.makeAffine();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**********************************************************
|
||||||
|
*** Specializations of operator* with lhs EigenBase ***
|
||||||
|
**********************************************************/
|
||||||
|
|
||||||
// generic HDim x HDim matrix * T => Projective
|
// generic HDim x HDim matrix * T => Projective
|
||||||
template<typename Other,int Mode, int Dim, int HDim>
|
template<typename Other,int Mode, int Dim, int HDim>
|
||||||
|
@ -27,6 +27,81 @@
|
|||||||
#include <Eigen/LU>
|
#include <Eigen/LU>
|
||||||
#include <Eigen/SVD>
|
#include <Eigen/SVD>
|
||||||
|
|
||||||
|
template<typename Scalar, int Mode> void non_projective_only(void)
|
||||||
|
{
|
||||||
|
/* this test covers the following files:
|
||||||
|
Cross.h Quaternion.h, Transform.cpp
|
||||||
|
*/
|
||||||
|
typedef Matrix<Scalar,2,2> Matrix2;
|
||||||
|
typedef Matrix<Scalar,3,3> Matrix3;
|
||||||
|
typedef Matrix<Scalar,4,4> Matrix4;
|
||||||
|
typedef Matrix<Scalar,2,1> Vector2;
|
||||||
|
typedef Matrix<Scalar,3,1> Vector3;
|
||||||
|
typedef Matrix<Scalar,4,1> Vector4;
|
||||||
|
typedef Quaternion<Scalar> Quaternionx;
|
||||||
|
typedef AngleAxis<Scalar> AngleAxisx;
|
||||||
|
typedef Transform<Scalar,2,Mode> Transform2;
|
||||||
|
typedef Transform<Scalar,3,Mode> Transform3;
|
||||||
|
typedef Transform<Scalar,2,Isometry> Isometry2;
|
||||||
|
typedef Transform<Scalar,3,Isometry> Isometry3;
|
||||||
|
typedef typename Transform3::MatrixType MatrixType;
|
||||||
|
typedef DiagonalMatrix<Scalar,2> AlignedScaling2;
|
||||||
|
typedef DiagonalMatrix<Scalar,3> AlignedScaling3;
|
||||||
|
typedef Translation<Scalar,2> Translation2;
|
||||||
|
typedef Translation<Scalar,3> Translation3;
|
||||||
|
|
||||||
|
Scalar largeEps = test_precision<Scalar>();
|
||||||
|
if (ei_is_same_type<Scalar,float>::ret)
|
||||||
|
largeEps = 1e-2f;
|
||||||
|
|
||||||
|
Vector3 v0 = Vector3::Random(),
|
||||||
|
v1 = Vector3::Random();
|
||||||
|
|
||||||
|
Transform3 t0, t1, t2;
|
||||||
|
|
||||||
|
Scalar a = ei_random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
|
||||||
|
|
||||||
|
Quaternionx q1, q2;
|
||||||
|
|
||||||
|
q1 = AngleAxisx(a, v0.normalized());
|
||||||
|
|
||||||
|
t0 = Transform3::Identity();
|
||||||
|
VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
|
||||||
|
|
||||||
|
t0.linear() = q1.toRotationMatrix();
|
||||||
|
|
||||||
|
v0 << 50, 2, 1;
|
||||||
|
t0.scale(v0);
|
||||||
|
|
||||||
|
VERIFY_IS_APPROX( (t0 * Vector3(1,0,0)).template head<3>().norm(), v0.x());
|
||||||
|
|
||||||
|
t0.setIdentity();
|
||||||
|
t1.setIdentity();
|
||||||
|
v1 << 1, 2, 3;
|
||||||
|
t0.linear() = q1.toRotationMatrix();
|
||||||
|
t0.pretranslate(v0);
|
||||||
|
t0.scale(v1);
|
||||||
|
t1.linear() = q1.conjugate().toRotationMatrix();
|
||||||
|
t1.prescale(v1.cwiseInverse());
|
||||||
|
t1.translate(-v0);
|
||||||
|
|
||||||
|
VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));
|
||||||
|
|
||||||
|
t1.fromPositionOrientationScale(v0, q1, v1);
|
||||||
|
VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
|
||||||
|
VERIFY_IS_APPROX(t1*v1, t0*v1);
|
||||||
|
|
||||||
|
// translation * vector
|
||||||
|
t0.setIdentity();
|
||||||
|
t0.translate(v0);
|
||||||
|
VERIFY_IS_APPROX((t0 * v1).template head<3>(), Translation3(v0) * v1);
|
||||||
|
|
||||||
|
// AlignedScaling * vector
|
||||||
|
t0.setIdentity();
|
||||||
|
t0.scale(v0);
|
||||||
|
VERIFY_IS_APPROX((t0 * v1).template head<3>(), AlignedScaling3(v0) * v1);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Scalar, int Mode> void transformations(void)
|
template<typename Scalar, int Mode> void transformations(void)
|
||||||
{
|
{
|
||||||
/* this test covers the following files:
|
/* this test covers the following files:
|
||||||
@ -42,6 +117,8 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
typedef AngleAxis<Scalar> AngleAxisx;
|
typedef AngleAxis<Scalar> AngleAxisx;
|
||||||
typedef Transform<Scalar,2,Mode> Transform2;
|
typedef Transform<Scalar,2,Mode> Transform2;
|
||||||
typedef Transform<Scalar,3,Mode> Transform3;
|
typedef Transform<Scalar,3,Mode> Transform3;
|
||||||
|
typedef Transform<Scalar,2,Isometry> Isometry2;
|
||||||
|
typedef Transform<Scalar,3,Isometry> Isometry3;
|
||||||
typedef typename Transform3::MatrixType MatrixType;
|
typedef typename Transform3::MatrixType MatrixType;
|
||||||
typedef DiagonalMatrix<Scalar,2> AlignedScaling2;
|
typedef DiagonalMatrix<Scalar,2> AlignedScaling2;
|
||||||
typedef DiagonalMatrix<Scalar,3> AlignedScaling3;
|
typedef DiagonalMatrix<Scalar,3> AlignedScaling3;
|
||||||
@ -115,17 +192,6 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
t0 = Transform3::Identity();
|
t0 = Transform3::Identity();
|
||||||
VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
|
VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
|
||||||
|
|
||||||
t0.linear() = q1.toRotationMatrix();
|
|
||||||
t1.setIdentity();
|
|
||||||
t1.linear() = q1.toRotationMatrix();
|
|
||||||
|
|
||||||
v0 << 50, 2, 1;//= ei_random_matrix<Vector3>().cwiseProduct(Vector3(10,2,0.5));
|
|
||||||
t0.scale(v0);
|
|
||||||
t1.prescale(v0);
|
|
||||||
|
|
||||||
VERIFY_IS_APPROX( (t0 * Vector3(1,0,0)).template head<3>().norm(), v0.x());
|
|
||||||
//VERIFY(!ei_isApprox((t1 * Vector3(1,0,0)).norm(), v0.x()));
|
|
||||||
|
|
||||||
t0.setIdentity();
|
t0.setIdentity();
|
||||||
t1.setIdentity();
|
t1.setIdentity();
|
||||||
v1 << 1, 2, 3;
|
v1 << 1, 2, 3;
|
||||||
@ -140,7 +206,6 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
|
|
||||||
t1.fromPositionOrientationScale(v0, q1, v1);
|
t1.fromPositionOrientationScale(v0, q1, v1);
|
||||||
VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
|
VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
|
||||||
VERIFY_IS_APPROX(t1*v1, t0*v1);
|
|
||||||
|
|
||||||
t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix());
|
t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix());
|
||||||
t1.setIdentity(); t1.scale(v0).rotate(q1);
|
t1.setIdentity(); t1.scale(v0).rotate(q1);
|
||||||
@ -248,20 +313,20 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
t0.setIdentity();
|
t0.setIdentity();
|
||||||
t0.prerotate(q1).prescale(v0).pretranslate(v0);
|
t0.prerotate(q1).prescale(v0).pretranslate(v0);
|
||||||
// translation * aligned scaling and transformation * mat
|
// translation * aligned scaling and transformation * mat
|
||||||
t1 = (Translation3(v0) * AlignedScaling3(v0)) * Matrix3(q1);
|
t1 = (Translation3(v0) * AlignedScaling3(v0)) * Transform3(q1);
|
||||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||||
// scaling * mat and translation * mat
|
// scaling * mat and translation * mat
|
||||||
t1 = Translation3(v0) * (AlignedScaling3(v0) * Matrix3(q1));
|
t1 = Translation3(v0) * (AlignedScaling3(v0) * Transform3(q1));
|
||||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||||
|
|
||||||
t0.setIdentity();
|
t0.setIdentity();
|
||||||
t0.scale(v0).translate(v0).rotate(q1);
|
t0.scale(v0).translate(v0).rotate(q1);
|
||||||
// translation * mat and aligned scaling * transformation
|
// translation * mat and aligned scaling * transformation
|
||||||
t1 = AlignedScaling3(v0) * (Translation3(v0) * Matrix3(q1));
|
t1 = AlignedScaling3(v0) * (Translation3(v0) * Transform3(q1));
|
||||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||||
// transformation * aligned scaling
|
// transformation * aligned scaling
|
||||||
t0.scale(v0);
|
t0.scale(v0);
|
||||||
t1 = t1 * AlignedScaling3(v0);
|
t1 *= AlignedScaling3(v0);
|
||||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||||
// transformation * translation
|
// transformation * translation
|
||||||
t0.translate(v0);
|
t0.translate(v0);
|
||||||
@ -302,16 +367,6 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
t1 = t1 * (q1 * AlignedScaling3(v1));
|
t1 = t1 * (q1 * AlignedScaling3(v1));
|
||||||
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
||||||
|
|
||||||
// translation * vector
|
|
||||||
t0.setIdentity();
|
|
||||||
t0.translate(v0);
|
|
||||||
VERIFY_IS_APPROX((t0 * v1).template head<3>(), Translation3(v0) * v1);
|
|
||||||
|
|
||||||
// AlignedScaling * vector
|
|
||||||
t0.setIdentity();
|
|
||||||
t0.scale(v0);
|
|
||||||
VERIFY_IS_APPROX((t0 * v1).template head<3>(), AlignedScaling3(v0) * v1);
|
|
||||||
|
|
||||||
// test transform inversion
|
// test transform inversion
|
||||||
t0.setIdentity();
|
t0.setIdentity();
|
||||||
t0.translate(v0);
|
t0.translate(v0);
|
||||||
@ -327,11 +382,6 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
t044.block(0,0,t0.matrix().rows(),4) = t0.matrix();
|
t044.block(0,0,t0.matrix().rows(),4) = t0.matrix();
|
||||||
VERIFY_IS_APPROX(t0.inverse(Isometry).matrix(), t044.inverse().block(0,0,t0.matrix().rows(),4));
|
VERIFY_IS_APPROX(t0.inverse(Isometry).matrix(), t044.inverse().block(0,0,t0.matrix().rows(),4));
|
||||||
|
|
||||||
// test extract rotation and aligned scaling
|
|
||||||
// t0.setIdentity();
|
|
||||||
// t0.translate(v0).rotate(q1).scale(v1);
|
|
||||||
// VERIFY_IS_APPROX(t0.rotation() * v1, Matrix3(q1) * v1);
|
|
||||||
|
|
||||||
Matrix3 mat_rotation, mat_scaling;
|
Matrix3 mat_rotation, mat_scaling;
|
||||||
t0.setIdentity();
|
t0.setIdentity();
|
||||||
t0.translate(v0).rotate(q1).scale(v1);
|
t0.translate(v0).rotate(q1).scale(v1);
|
||||||
@ -372,8 +422,12 @@ template<typename Scalar, int Mode> void transformations(void)
|
|||||||
void test_geo_transformations()
|
void test_geo_transformations()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < g_repeat; i++) {
|
for(int i = 0; i < g_repeat; i++) {
|
||||||
//CALL_SUBTEST_1(( transformations<double,Affine>() ));
|
CALL_SUBTEST_1(( transformations<double,Affine>() ));
|
||||||
//CALL_SUBTEST_2(( transformations<float,AffineCompact>() ));
|
CALL_SUBTEST_1(( non_projective_only<double,Affine>() ));
|
||||||
|
|
||||||
|
CALL_SUBTEST_2(( transformations<float,AffineCompact>() ));
|
||||||
|
CALL_SUBTEST_2(( non_projective_only<float,AffineCompact>() ));
|
||||||
|
|
||||||
CALL_SUBTEST_3(( transformations<double,Projective>() ));
|
CALL_SUBTEST_3(( transformations<double,Projective>() ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ namespace Eigen
|
|||||||
for (uint ai=0 ; ai<ei_assert_list.size() ; ++ai) \
|
for (uint ai=0 ; ai<ei_assert_list.size() ; ++ai) \
|
||||||
std::cerr << " " << ei_assert_list[ai] << "\n"; \
|
std::cerr << " " << ei_assert_list[ai] << "\n"; \
|
||||||
VERIFY(Eigen::should_raise_an_assert && # a); \
|
VERIFY(Eigen::should_raise_an_assert && # a); \
|
||||||
} catch (Eigen::ei_assert_exception e) { \
|
} catch (Eigen::ei_assert_exception) { \
|
||||||
Eigen::ei_push_assert = false; VERIFY(true); \
|
Eigen::ei_push_assert = false; VERIFY(true); \
|
||||||
} \
|
} \
|
||||||
Eigen::report_on_cerr_on_assert_failure = true; \
|
Eigen::report_on_cerr_on_assert_failure = true; \
|
||||||
@ -144,7 +144,7 @@ namespace Eigen
|
|||||||
a; \
|
a; \
|
||||||
VERIFY(Eigen::should_raise_an_assert && # a); \
|
VERIFY(Eigen::should_raise_an_assert && # a); \
|
||||||
} \
|
} \
|
||||||
catch (Eigen::ei_assert_exception& e) { VERIFY(true); } \
|
catch (Eigen::ei_assert_exception&) { VERIFY(true); } \
|
||||||
Eigen::report_on_cerr_on_assert_failure = true; \
|
Eigen::report_on_cerr_on_assert_failure = true; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user