merge with special_matrix branch

This commit is contained in:
Gael Guennebaud 2009-08-03 16:17:32 +02:00
commit 912da9fade
7 changed files with 54 additions and 43 deletions

View File

@ -63,6 +63,7 @@ inline int ei_exp(int) { ei_assert(false); return 0; }
inline int ei_log(int) { ei_assert(false); return 0; } inline int ei_log(int) { ei_assert(false); return 0; }
inline int ei_sin(int) { ei_assert(false); return 0; } inline int ei_sin(int) { ei_assert(false); return 0; }
inline int ei_cos(int) { ei_assert(false); return 0; } inline int ei_cos(int) { ei_assert(false); return 0; }
inline int ei_atan2(int, int) { ei_assert(false); return 0; }
inline int ei_pow(int x, int y) inline int ei_pow(int x, int y)
{ {
int res = 1; int res = 1;
@ -117,6 +118,7 @@ inline float ei_exp(float x) { return std::exp(x); }
inline float ei_log(float x) { return std::log(x); } inline float ei_log(float x) { return std::log(x); }
inline float ei_sin(float x) { return std::sin(x); } inline float ei_sin(float x) { return std::sin(x); }
inline float ei_cos(float x) { return std::cos(x); } inline float ei_cos(float x) { return std::cos(x); }
inline float ei_atan2(float y, float x) { return std::atan2(y,x); }
inline float ei_pow(float x, float y) { return std::pow(x, y); } inline float ei_pow(float x, float y) { return std::pow(x, y); }
template<> inline float ei_random(float a, float b) template<> inline float ei_random(float a, float b)
@ -165,6 +167,7 @@ inline double ei_exp(double x) { return std::exp(x); }
inline double ei_log(double x) { return std::log(x); } inline double ei_log(double x) { return std::log(x); }
inline double ei_sin(double x) { return std::sin(x); } inline double ei_sin(double x) { return std::sin(x); }
inline double ei_cos(double x) { return std::cos(x); } inline double ei_cos(double x) { return std::cos(x); }
inline double ei_atan2(double y, double x) { return std::atan2(y,x); }
inline double ei_pow(double x, double y) { return std::pow(x, y); } inline double ei_pow(double x, double y) { return std::pow(x, y); }
template<> inline double ei_random(double a, double b) template<> inline double ei_random(double a, double b)
@ -211,6 +214,7 @@ inline float ei_abs2(const std::complex<float>& x) { return std::norm(x); }
inline std::complex<float> ei_exp(std::complex<float> x) { return std::exp(x); } inline std::complex<float> ei_exp(std::complex<float> x) { return std::exp(x); }
inline std::complex<float> ei_sin(std::complex<float> x) { return std::sin(x); } inline std::complex<float> ei_sin(std::complex<float> x) { return std::sin(x); }
inline std::complex<float> ei_cos(std::complex<float> x) { return std::cos(x); } inline std::complex<float> ei_cos(std::complex<float> x) { return std::cos(x); }
inline std::complex<float> ei_atan2(std::complex<float>, std::complex<float> ) { ei_assert(false); return 0; }
template<> inline std::complex<float> ei_random() template<> inline std::complex<float> ei_random()
{ {
@ -247,6 +251,7 @@ inline double ei_abs2(const std::complex<double>& x) { return std::norm(x); }
inline std::complex<double> ei_exp(std::complex<double> x) { return std::exp(x); } inline std::complex<double> ei_exp(std::complex<double> x) { return std::exp(x); }
inline std::complex<double> ei_sin(std::complex<double> x) { return std::sin(x); } inline std::complex<double> ei_sin(std::complex<double> x) { return std::sin(x); }
inline std::complex<double> ei_cos(std::complex<double> x) { return std::cos(x); } inline std::complex<double> ei_cos(std::complex<double> x) { return std::cos(x); }
inline std::complex<double> ei_atan2(std::complex<double>, std::complex<double>) { ei_assert(false); return 0; }
template<> inline std::complex<double> ei_random() template<> inline std::complex<double> ei_random()
{ {
@ -285,6 +290,7 @@ inline long double ei_exp(long double x) { return std::exp(x); }
inline long double ei_log(long double x) { return std::log(x); } inline long double ei_log(long double x) { return std::log(x); }
inline long double ei_sin(long double x) { return std::sin(x); } inline long double ei_sin(long double x) { return std::sin(x); }
inline long double ei_cos(long double x) { return std::cos(x); } inline long double ei_cos(long double x) { return std::cos(x); }
inline long double ei_atan2(long double y, long double x) { return std::atan2(y,x); }
inline long double ei_pow(long double x, long double y) { return std::pow(x, y); } inline long double ei_pow(long double x, long double y) { return std::pow(x, y); }
template<> inline long double ei_random(long double a, long double b) template<> inline long double ei_random(long double a, long double b)

View File

@ -60,31 +60,31 @@ MatrixBase<Derived>::eulerAngles(int a0, int a1, int a2) const
if (a0==a2) if (a0==a2)
{ {
Scalar s = Vector2(coeff(j,i) , coeff(k,i)).norm(); Scalar s = Vector2(coeff(j,i) , coeff(k,i)).norm();
res[1] = std::atan2(s, coeff(i,i)); res[1] = ei_atan2(s, coeff(i,i));
if (s > epsilon) if (s > epsilon)
{ {
res[0] = std::atan2(coeff(j,i), coeff(k,i)); res[0] = ei_atan2(coeff(j,i), coeff(k,i));
res[2] = std::atan2(coeff(i,j),-coeff(i,k)); res[2] = ei_atan2(coeff(i,j),-coeff(i,k));
} }
else else
{ {
res[0] = Scalar(0); res[0] = Scalar(0);
res[2] = (coeff(i,i)>0?1:-1)*std::atan2(-coeff(k,j), coeff(j,j)); res[2] = (coeff(i,i)>0?1:-1)*ei_atan2(-coeff(k,j), coeff(j,j));
} }
} }
else else
{ {
Scalar c = Vector2(coeff(i,i) , coeff(i,j)).norm(); Scalar c = Vector2(coeff(i,i) , coeff(i,j)).norm();
res[1] = std::atan2(-coeff(i,k), c); res[1] = ei_atan2(-coeff(i,k), c);
if (c > epsilon) if (c > epsilon)
{ {
res[0] = std::atan2(coeff(j,k), coeff(k,k)); res[0] = ei_atan2(coeff(j,k), coeff(k,k));
res[2] = std::atan2(coeff(i,j), coeff(i,i)); res[2] = ei_atan2(coeff(i,j), coeff(i,i));
} }
else else
{ {
res[0] = Scalar(0); res[0] = Scalar(0);
res[2] = (coeff(i,k)>0?1:-1)*std::atan2(-coeff(k,j), coeff(j,j)); res[2] = (coeff(i,k)>0?1:-1)*ei_atan2(-coeff(k,j), coeff(j,j));
} }
} }
if (!odd) if (!odd)

View File

@ -62,11 +62,13 @@ struct ei_traits<Homogeneous<MatrixType,Direction> >
template<typename MatrixType,typename Lhs> struct ei_homogeneous_left_product_impl; template<typename MatrixType,typename Lhs> struct ei_homogeneous_left_product_impl;
template<typename MatrixType,typename Rhs> struct ei_homogeneous_right_product_impl; template<typename MatrixType,typename Rhs> struct ei_homogeneous_right_product_impl;
template<typename MatrixType,int Direction> class Homogeneous template<typename MatrixType,int _Direction> class Homogeneous
: public MatrixBase<Homogeneous<MatrixType,Direction> > : public MatrixBase<Homogeneous<MatrixType,_Direction> >
{ {
public: public:
enum { Direction = _Direction };
EIGEN_GENERIC_PUBLIC_INTERFACE(Homogeneous) EIGEN_GENERIC_PUBLIC_INTERFACE(Homogeneous)
inline Homogeneous(const MatrixType& matrix) inline Homogeneous(const MatrixType& matrix)

View File

@ -25,8 +25,9 @@
#ifndef EIGEN_ROTATIONBASE_H #ifndef EIGEN_ROTATIONBASE_H
#define EIGEN_ROTATIONBASE_H #define EIGEN_ROTATIONBASE_H
// this file aims to contains the various representations of rotation/orientation // forward declaration
// in 2D and 3D space excepted Matrix and Quaternion. template<typename RotationDerived, typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime>
struct ei_rotation_base_generic_product_selector;
/** \class RotationBase /** \class RotationBase
* *
@ -47,25 +48,6 @@ class RotationBase
typedef Matrix<Scalar,Dim,Dim> RotationMatrixType; typedef Matrix<Scalar,Dim,Dim> RotationMatrixType;
typedef Matrix<Scalar,Dim,1> VectorType; typedef Matrix<Scalar,Dim,1> VectorType;
protected:
template<typename MatrixType, bool IsVector=MatrixType::IsVectorAtCompileTime>
struct generic_product_selector
{
typedef RotationMatrixType ReturnType;
inline static RotationMatrixType run(const Derived& r, const MatrixType& m)
{ return r.toRotationMatrix() * m; }
};
template<typename OtherVectorType>
struct generic_product_selector<OtherVectorType,true>
{
typedef VectorType ReturnType;
inline static VectorType run(const Derived& r, const OtherVectorType& v)
{
return r._transformVector(v);
}
};
public: public:
inline const Derived& derived() const { return *static_cast<const Derived*>(this); } inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
inline Derived& derived() { return *static_cast<Derived*>(this); } inline Derived& derived() { return *static_cast<Derived*>(this); }
@ -90,9 +72,9 @@ class RotationBase
* - a vector of size Dim * - a vector of size Dim
*/ */
template<typename OtherDerived> template<typename OtherDerived>
inline typename generic_product_selector<OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType inline typename ei_rotation_base_generic_product_selector<Derived,OtherDerived,OtherDerived::IsVectorAtCompileTime>::ReturnType
operator*(const MultiplierBase<OtherDerived>& e) const operator*(const MatrixBase<OtherDerived>& e) const
{ return generic_product_selector<OtherDerived>::run(derived(), e.derived()); } { return ei_rotation_base_generic_product_selector<Derived,OtherDerived>::run(derived(), e.derived()); }
/** \returns the concatenation of a linear transformation \a l with the rotation \a r */ /** \returns the concatenation of a linear transformation \a l with the rotation \a r */
template<typename OtherDerived> friend template<typename OtherDerived> friend
@ -109,6 +91,27 @@ class RotationBase
{ return toRotationMatrix() * v; } { return toRotationMatrix() * v; }
}; };
// implementation of the generic product rotation * matrix
template<typename RotationDerived, typename MatrixType>
struct ei_rotation_base_generic_product_selector<RotationDerived,MatrixType,false>
{
enum { Dim = RotationDerived::Dim };
typedef Matrix<typename RotationDerived::Scalar,Dim,Dim> ReturnType;
inline static ReturnType run(const RotationDerived& r, const MatrixType& m)
{ return r.toRotationMatrix() * m; }
};
template<typename RotationDerived,typename OtherVectorType>
struct ei_rotation_base_generic_product_selector<RotationDerived,OtherVectorType,true>
{
enum { Dim = RotationDerived::Dim };
typedef Matrix<typename RotationDerived::Scalar,Dim,1> ReturnType;
inline static ReturnType run(const RotationDerived& r, const OtherVectorType& v)
{
return r._transformVector(v);
}
};
/** \geometry_module /** \geometry_module
* *
* Constructs a Dim x Dim rotation matrix from the rotation \a r * Constructs a Dim x Dim rotation matrix from the rotation \a r

View File

@ -537,9 +537,9 @@ template<typename Scalar, int Dim, int Mode>
QMatrix Transform<Scalar,Dim,Mode>::toQMatrix(void) const QMatrix Transform<Scalar,Dim,Mode>::toQMatrix(void) const
{ {
EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE) EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
return QMatrix(other.coeffRef(0,0), other.coeffRef(1,0), return QMatrix(matrix.coeff(0,0), matrix.coeff(1,0),
other.coeffRef(0,1), other.coeffRef(1,1), matrix.coeff(0,1), matrix.coeff(1,1),
other.coeffRef(0,2), other.coeffRef(1,2)); matrix.coeff(0,2), matrix.coeff(1,2));
} }
/** Initialises \c *this from a QTransform assuming the dimension is 2. /** Initialises \c *this from a QTransform assuming the dimension is 2.
@ -571,12 +571,12 @@ Transform<Scalar,Dim,Mode>& Transform<Scalar,Dim,Mode>::operator=(const QTransfo
* This function is available only if the token EIGEN_QT_SUPPORT is defined. * This function is available only if the token EIGEN_QT_SUPPORT is defined.
*/ */
template<typename Scalar, int Dim, int Mode> template<typename Scalar, int Dim, int Mode>
QMatrix Transform<Scalar,Dim,Mode>::toQTransform(void) const QTransform Transform<Scalar,Dim,Mode>::toQTransform(void) const
{ {
EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE) EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
return QTransform(other.coeffRef(0,0), other.coeffRef(1,0), other.coeffRef(2,0) return QTransform(matrix.coeff(0,0), matrix.coeff(1,0), matrix.coeff(2,0)
other.coeffRef(0,1), other.coeffRef(1,1), other.coeffRef(2,1) matrix.coeff(0,1), matrix.coeff(1,1), matrix.coeff(2,1)
other.coeffRef(0,2), other.coeffRef(1,2), other.coeffRef(2,2); matrix.coeff(0,2), matrix.coeff(1,2), matrix.coeff(2,2);
} }
#endif #endif

View File

@ -74,7 +74,7 @@ macro(ei_add_test testname)
string(STRIP "${ARGV2}" ARGV2_stripped) string(STRIP "${ARGV2}" ARGV2_stripped)
string(LENGTH "${ARGV2_stripped}" ARGV2_stripped_length) string(LENGTH "${ARGV2_stripped}" ARGV2_stripped_length)
if(${ARGV2_stripped_length} GREATER 0) if(${ARGV2_stripped_length} GREATER 0)
target_link_libraries(${targetname} ${ARGV2}) target_link_libraries(${targetname} "${ARGV2}")
endif(${ARGV2_stripped_length} GREATER 0) endif(${ARGV2_stripped_length} GREATER 0)
endif(${ARGC} GREATER 2) endif(${ARGC} GREATER 2)

View File

@ -142,7 +142,7 @@ if(QT4_FOUND)
else(QT_QTCORE_LIBRARY_DEBUG) else(QT_QTCORE_LIBRARY_DEBUG)
set(QT_QTCORE_LIBRARY ${QT_QTCORE_LIBRARY_RELEASE}) set(QT_QTCORE_LIBRARY ${QT_QTCORE_LIBRARY_RELEASE})
endif(QT_QTCORE_LIBRARY_DEBUG) endif(QT_QTCORE_LIBRARY_DEBUG)
ei_add_test(qtvector " " ${QT_QTCORE_LIBRARY}) ei_add_test(qtvector " " "${QT_QTCORE_LIBRARY}")
endif(QT4_FOUND) endif(QT4_FOUND)
ei_add_test(sparse_vector) ei_add_test(sparse_vector)
ei_add_test(sparse_basic) ei_add_test(sparse_basic)