aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/src/EulerAngles
diff options
context:
space:
mode:
authorGravatar Tal Hadad <tal_hd@hotmail.com>2016-06-02 22:12:57 +0300
committerGravatar Tal Hadad <tal_hd@hotmail.com>2016-06-02 22:12:57 +0300
commit2aaaf22623cdd92a772fc7e0f6523ae2c423e5de (patch)
tree5dc29c221a88504f805830d80cb6a16b1f25a727 /unsupported/Eigen/src/EulerAngles
parentc006ecace15602e8c4b9a543af108a1dadc080db (diff)
Fix Gael reports (except documention)
- "Scalar angle(int) const" should be "const Vector& angles() const" - then method "coeffs" could be removed. - avoid one letter names like h, p, r -> use alpha(), beta(), gamma() ;) - about the "fromRotation" methods: - replace the ones which are not static by operator= (as in Quaternion) - the others are actually static methods: use a capital F: FromRotation - method "invert" should be removed. - use a macro to define both float and double EulerAnglesXYZ* typedefs - AddConstIf -> not used - no needs for NegateIfXor, compilers are extremely good at optimizing away branches based on compile time constants: if(IsHeadingOpposite-=IsEven) res.alpha() = -res.alpha();
Diffstat (limited to 'unsupported/Eigen/src/EulerAngles')
-rw-r--r--unsupported/Eigen/src/EulerAngles/EulerAngles.h168
-rw-r--r--unsupported/Eigen/src/EulerAngles/EulerSystem.h153
2 files changed, 116 insertions, 205 deletions
diff --git a/unsupported/Eigen/src/EulerAngles/EulerAngles.h b/unsupported/Eigen/src/EulerAngles/EulerAngles.h
index d21f52491..66050a426 100644
--- a/unsupported/Eigen/src/EulerAngles/EulerAngles.h
+++ b/unsupported/Eigen/src/EulerAngles/EulerAngles.h
@@ -29,7 +29,7 @@ namespace Eigen
class EulerAngles : public RotationBase<EulerAngles<_Scalar, _System>, 3>
{
public:
- /** the scalar type of the coefficients */
+ /** the scalar type of the angles */
typedef _Scalar Scalar;
typedef _System System;
@@ -38,16 +38,19 @@ namespace Eigen
typedef Quaternion<Scalar> QuaternionType;
typedef AngleAxis<Scalar> AngleAxisType;
- static Vector3 HeadingAxisVector() {
- return internal::NegativeIf<System::IsHeadingOpposite>::run(Vector3::Unit(System::HeadingAxisAbs - 1));
+ static Vector3 AlphaAxisVector() {
+ const Vector3& u = Vector3::Unit(System::AlphaAxisAbs - 1);
+ return System::IsAlphaOpposite ? -u : u;
}
- static Vector3 PitchAxisVector() {
- return internal::NegativeIf<System::IsPitchOpposite>::run(Vector3::Unit(System::PitchAxisAbs - 1));
+ static Vector3 BetaAxisVector() {
+ const Vector3& u = Vector3::Unit(System::BetaAxisAbs - 1);
+ return System::IsBetaOpposite ? -u : u;
}
- static Vector3 RollAxisVector() {
- return internal::NegativeIf<System::IsRollOpposite>::run(Vector3::Unit(System::RollAxisAbs - 1));
+ static Vector3 GammaAxisVector() {
+ const Vector3& u = Vector3::Unit(System::GammaAxisAbs - 1);
+ return System::IsGammaOpposite ? -u : u;
}
private:
@@ -56,7 +59,7 @@ namespace Eigen
public:
EulerAngles() {}
- inline EulerAngles(Scalar a0, Scalar a1, Scalar a2) : m_angles(a0, a1, a2) {}
+ inline EulerAngles(Scalar alpha, Scalar beta, Scalar gamma) : m_angles(alpha, beta, gamma) {}
template<typename Derived>
inline EulerAngles(const MatrixBase<Derived>& m) { *this = m; }
@@ -64,11 +67,11 @@ namespace Eigen
template<typename Derived>
inline EulerAngles(
const MatrixBase<Derived>& m,
- bool positiveRangeHeading,
- bool positiveRangePitch,
- bool positiveRangeRoll) {
+ bool positiveRangeAlpha,
+ bool positiveRangeBeta,
+ bool positiveRangeGamma) {
- fromRotation(m, positiveRangeHeading, positiveRangePitch, positiveRangeRoll);
+ System::CalcEulerAngles(*this, m, positiveRangeAlpha, positiveRangeBeta, positiveRangeGamma);
}
template<typename Derived>
@@ -77,35 +80,24 @@ namespace Eigen
template<typename Derived>
inline EulerAngles(
const RotationBase<Derived, 3>& rot,
- bool positiveRangeHeading,
- bool positiveRangePitch,
- bool positiveRangeRoll) {
+ bool positiveRangeAlpha,
+ bool positiveRangeBeta,
+ bool positiveRangeGamma) {
- fromRotation(rot, positiveRangeHeading, positiveRangePitch, positiveRangeRoll);
+ System::CalcEulerAngles(*this, rot.toRotationMatrix(), positiveRangeAlpha, positiveRangeBeta, positiveRangeGamma);
}
- Scalar angle(int i) const { return m_angles.coeff(i); }
- Scalar& angle(int i) { return m_angles.coeffRef(i); }
+ const Vector3& angles() const { return m_angles; }
+ Vector3& angles() { return m_angles; }
- const Vector3& coeffs() const { return m_angles; }
- Vector3& coeffs() { return m_angles; }
+ Scalar alpha() const { return m_angles[0]; }
+ Scalar& alpha() { return m_angles[0]; }
- Scalar h() const { return m_angles[0]; }
- Scalar& h() { return m_angles[0]; }
+ Scalar beta() const { return m_angles[1]; }
+ Scalar& beta() { return m_angles[1]; }
- Scalar p() const { return m_angles[1]; }
- Scalar& p() { return m_angles[1]; }
-
- Scalar r() const { return m_angles[2]; }
- Scalar& r() { return m_angles[2]; }
-
- EulerAngles invert() const
- {
- //m_angles = -m_angles;// I want to do this but there could be an aliasing issue!
- m_angles *= -1;
-
- return *this;
- }
+ Scalar gamma() const { return m_angles[2]; }
+ Scalar& gamma() { return m_angles[2]; }
EulerAngles inverse() const
{
@@ -121,59 +113,26 @@ namespace Eigen
/** Constructs and \returns an equivalent 3x3 rotation matrix.
*/
- template<typename Derived>
- EulerAngles& fromRotation(const MatrixBase<Derived>& m)
- {
- System::eulerAngles(*this, m);
- return *this;
- }
-
template<
- bool PositiveRangeHeading,
- bool PositiveRangePitch,
- bool PositiveRangeRoll,
+ bool PositiveRangeAlpha,
+ bool PositiveRangeBeta,
+ bool PositiveRangeGamma,
typename Derived>
- EulerAngles& fromRotation(const MatrixBase<Derived>& m)
+ static EulerAngles FromRotation(const MatrixBase<Derived>& m)
{
- System::eulerAngles<PositiveRangeHeading, PositiveRangePitch, PositiveRangeRoll>(*this, m);
- return *this;
- }
-
- template<typename Derived>
- EulerAngles& fromRotation(
- const MatrixBase<Derived>& m,
- bool positiveRangeHeading,
- bool positiveRangePitch,
- bool positiveRangeRoll)
- {
- System::eulerAngles(*this, m, positiveRangeHeading, positiveRangePitch, positiveRangeRoll);
- return *this;
- }
-
- template<typename Derived>
- EulerAngles& fromRotation(const RotationBase<Derived, 3>& rot)
- {
- return fromRotation(rot.toRotationMatrix());
+ EulerAngles e;
+ System::CalcEulerAngles<PositiveRangeAlpha, PositiveRangeBeta, PositiveRangeGamma>(e, m);
+ return e;
}
template<
- bool PositiveRangeHeading,
- bool PositiveRangePitch,
- bool PositiveRangeRoll,
+ bool PositiveRangeAlpha,
+ bool PositiveRangeBeta,
+ bool PositiveRangeGamma,
typename Derived>
- EulerAngles& fromRotation(const RotationBase<Derived, 3>& rot)
+ static EulerAngles& FromRotation(const RotationBase<Derived, 3>& rot)
{
- return fromRotation<PositiveRangeHeading, PositiveRangePitch, PositiveRangeRoll>(rot.toRotationMatrix());
- }
-
- template<typename Derived>
- EulerAngles& fromRotation(
- const RotationBase<Derived, 3>& rot,
- bool positiveRangeHeading,
- bool positiveRangePitch,
- bool positiveRangeRoll)
- {
- return fromRotation(rot.toRotationMatrix(), positiveRangeHeading, positiveRangePitch, positiveRangeRoll);
+ return FromRotation<PositiveRangeAlpha, PositiveRangeBeta, PositiveRangeGamma>(rot.toRotationMatrix());
}
/*EulerAngles& fromQuaternion(const QuaternionType& q)
@@ -193,8 +152,9 @@ namespace Eigen
/** Set \c *this from a rotation matrix(i.e. pure orthogonal matrix with determinent of +1).
*/
template<typename Derived>
- EulerAngles& operator=(const MatrixBase<Derived>& mat) {
- return fromRotation(mat);
+ EulerAngles& operator=(const MatrixBase<Derived>& m) {
+ System::CalcEulerAngles(*this, m);
+ return *this;
}
// TODO: Assign and construct from another EulerAngles (with different system)
@@ -203,7 +163,8 @@ namespace Eigen
*/
template<typename Derived>
EulerAngles& operator=(const RotationBase<Derived, 3>& rot) {
- return fromRotation(rot.toRotationMatrix());
+ System::CalcEulerAngles(*this, rot.toRotationMatrix());
+ return *this;
}
// TODO: Support isApprox function
@@ -216,9 +177,9 @@ namespace Eigen
QuaternionType toQuaternion() const
{
return
- AngleAxisType(h(), HeadingAxisVector()) *
- AngleAxisType(p(), PitchAxisVector()) *
- AngleAxisType(r(), RollAxisVector());
+ AngleAxisType(alpha(), AlphaAxisVector()) *
+ AngleAxisType(beta(), BetaAxisVector()) *
+ AngleAxisType(gamma(), GammaAxisVector());
}
operator QuaternionType() const
@@ -227,20 +188,27 @@ namespace Eigen
}
};
- typedef EulerAngles<double, EulerSystemXYZ> EulerAnglesXYZd;
- typedef EulerAngles<double, EulerSystemXYX> EulerAnglesXYXd;
- typedef EulerAngles<double, EulerSystemXZY> EulerAnglesXZYd;
- typedef EulerAngles<double, EulerSystemXZX> EulerAnglesXZXd;
-
- typedef EulerAngles<double, EulerSystemYZX> EulerAnglesYZXd;
- typedef EulerAngles<double, EulerSystemYZY> EulerAnglesYZYd;
- typedef EulerAngles<double, EulerSystemYXZ> EulerAnglesYXZd;
- typedef EulerAngles<double, EulerSystemYXY> EulerAnglesYXYd;
-
- typedef EulerAngles<double, EulerSystemZXY> EulerAnglesZXYd;
- typedef EulerAngles<double, EulerSystemZXZ> EulerAnglesZXZd;
- typedef EulerAngles<double, EulerSystemZYX> EulerAnglesZYXd;
- typedef EulerAngles<double, EulerSystemZYZ> EulerAnglesZYZd;
+#define EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(SYSTEM, SCALAR_TYPE, SCALAR_POSTFIX) \
+ typedef EulerAngles<SCALAR_TYPE, SYSTEM> SYSTEM##SCALAR_POSTFIX;
+
+#define EIGEN_EULER_ANGLES_TYPEDEFS(SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemXYZ, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemXYX, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemXZY, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemXZX, SCALAR_TYPE, SCALAR_POSTFIX) \
+ \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemYZX, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemYZY, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemYXZ, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemYXY, SCALAR_TYPE, SCALAR_POSTFIX) \
+ \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemZXY, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemZXZ, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemZYX, SCALAR_TYPE, SCALAR_POSTFIX) \
+ EIGEN_EULER_ANGLES_SINGLE_TYPEDEF(EulerSystemZYZ, SCALAR_TYPE, SCALAR_POSTFIX)
+
+EIGEN_EULER_ANGLES_TYPEDEFS(float, f)
+EIGEN_EULER_ANGLES_TYPEDEFS(double, d)
namespace internal
{
diff --git a/unsupported/Eigen/src/EulerAngles/EulerSystem.h b/unsupported/Eigen/src/EulerAngles/EulerSystem.h
index 9699dd10d..f37c62f8e 100644
--- a/unsupported/Eigen/src/EulerAngles/EulerSystem.h
+++ b/unsupported/Eigen/src/EulerAngles/EulerSystem.h
@@ -30,69 +30,6 @@ namespace Eigen
{
enum { value = -Num };
};
-
- template <bool Cond>
- struct NegativeIf
- {
- template <typename T>
- static T run(const T& t)
- {
- return -t;
- }
- };
-
- template <>
- struct NegativeIf<false>
- {
- template <typename T>
- static T run(const T& t)
- {
- return t;
- }
- };
-
- template <bool Cond>
- struct NegateIf
- {
- template <typename T>
- static void run(T& t)
- {
- t = -t;
- }
- };
-
- template <>
- struct NegateIf<false>
- {
- template <typename T>
- static void run(T&)
- {
- // no op
- }
- };
-
- template <bool Cond1, bool Cond2>
- struct NegateIfXor : NegateIf<Cond1 != Cond2> {};
-
- template <typename Type, Type value, bool Cond>
- struct AddConstIf
- {
- template <typename T>
- static void run(T& t)
- {
- t += T(value);
- }
- };
-
- template <typename Type, Type value>
- struct AddConstIf<Type, value, false>
- {
- template <typename T>
- static void run(T&)
- {
- // no op
- }
- };
template <int Axis>
struct IsValidAxis
@@ -108,36 +45,36 @@ namespace Eigen
EULER_Z = 3
};
- template <int _HeadingAxis, int _PitchAxis, int _RollAxis>
+ template <int _AlphaAxis, int _BetaAxis, int _GammaAxis>
class EulerSystem
{
public:
// It's defined this way and not as enum, because I think
// that enum is not guerantee to support negative numbers
- static const int HeadingAxis = _HeadingAxis;
- static const int PitchAxis = _PitchAxis;
- static const int RollAxis = _RollAxis;
+ static const int AlphaAxis = _AlphaAxis;
+ static const int BetaAxis = _BetaAxis;
+ static const int GammaAxis = _GammaAxis;
enum
{
- HeadingAxisAbs = internal::Abs<HeadingAxis>::value,
- PitchAxisAbs = internal::Abs<PitchAxis>::value,
- RollAxisAbs = internal::Abs<RollAxis>::value,
+ AlphaAxisAbs = internal::Abs<AlphaAxis>::value,
+ BetaAxisAbs = internal::Abs<BetaAxis>::value,
+ GammaAxisAbs = internal::Abs<GammaAxis>::value,
- IsHeadingOpposite = (HeadingAxis < 0) ? 1 : 0,
- IsPitchOpposite = (PitchAxis < 0) ? 1 : 0,
- IsRollOpposite = (RollAxis < 0) ? 1 : 0,
+ IsAlphaOpposite = (AlphaAxis < 0) ? 1 : 0,
+ IsBetaOpposite = (BetaAxis < 0) ? 1 : 0,
+ IsGammaOpposite = (GammaAxis < 0) ? 1 : 0,
- IsOdd = ((HeadingAxisAbs)%3 == (PitchAxisAbs - 1)%3) ? 0 : 1,
+ IsOdd = ((AlphaAxisAbs)%3 == (BetaAxisAbs - 1)%3) ? 0 : 1,
IsEven = IsOdd ? 0 : 1,
// TODO: Assert this, and sort it in a better way
- IsValid = ((unsigned)HeadingAxisAbs != (unsigned)PitchAxisAbs &&
- (unsigned)PitchAxisAbs != (unsigned)RollAxisAbs &&
- internal::IsValidAxis<HeadingAxis>::value && internal::IsValidAxis<PitchAxis>::value && internal::IsValidAxis<RollAxis>::value) ? 1 : 0,
+ IsValid = ((unsigned)AlphaAxisAbs != (unsigned)BetaAxisAbs &&
+ (unsigned)BetaAxisAbs != (unsigned)GammaAxisAbs &&
+ internal::IsValidAxis<AlphaAxis>::value && internal::IsValidAxis<BetaAxis>::value && internal::IsValidAxis<GammaAxis>::value) ? 1 : 0,
// TODO: After a proper assertation, remove the "IsValid" from this expression
- IsTaitBryan = (IsValid && (unsigned)HeadingAxisAbs != (unsigned)RollAxisAbs) ? 1 : 0
+ IsTaitBryan = (IsValid && (unsigned)AlphaAxisAbs != (unsigned)GammaAxisAbs) ? 1 : 0
};
private:
@@ -147,13 +84,14 @@ namespace Eigen
// I, J, K are the pivot indexes permutation for the rotation matrix, that match this euler system.
// They are used in this class converters.
// They are always different from each other, and their possible values are: 0, 1, or 2.
- I = HeadingAxisAbs - 1,
- J = (HeadingAxisAbs - 1 + 1 + IsOdd)%3,
- K = (HeadingAxisAbs - 1 + 2 - IsOdd)%3
+ I = AlphaAxisAbs - 1,
+ J = (AlphaAxisAbs - 1 + 1 + IsOdd)%3,
+ K = (AlphaAxisAbs - 1 + 2 - IsOdd)%3
};
+ // TODO: Get @mat parameter in form that avoids double evaluation.
template <typename Derived>
- static void eulerAngles_imp(Matrix<typename MatrixBase<Derived>::Scalar, 3, 1>& res, const MatrixBase<Derived>& mat, internal::true_type /*isTaitBryan*/)
+ static void CalcEulerAngles_imp(Matrix<typename MatrixBase<Derived>::Scalar, 3, 1>& res, const MatrixBase<Derived>& mat, internal::true_type /*isTaitBryan*/)
{
using std::atan2;
using std::sin;
@@ -176,7 +114,7 @@ namespace Eigen
}
template <typename Derived>
- static void eulerAngles_imp(Matrix<typename MatrixBase<Derived>::Scalar,3,1>& res, const MatrixBase<Derived>& mat, internal::false_type /*isTaitBryan*/)
+ static void CalcEulerAngles_imp(Matrix<typename MatrixBase<Derived>::Scalar,3,1>& res, const MatrixBase<Derived>& mat, internal::false_type /*isTaitBryan*/)
{
using std::atan2;
using std::sin;
@@ -216,50 +154,55 @@ namespace Eigen
public:
template<typename Scalar>
- static void eulerAngles(
+ static void CalcEulerAngles(
EulerAngles<Scalar, EulerSystem>& res,
const typename EulerAngles<Scalar, EulerSystem>::Matrix3& mat)
{
- eulerAngles(res, mat, false, false, false);
+ CalcEulerAngles(res, mat, false, false, false);
}
template<
typename Scalar,
- bool PositiveRangeHeading,
- bool PositiveRangePitch,
- bool PositiveRangeRoll>
- static void eulerAngles(
+ bool PositiveRangeAlpha,
+ bool PositiveRangeBeta,
+ bool PositiveRangeGamma>
+ static void CalcEulerAngles(
EulerAngles<Scalar, EulerSystem>& res,
const typename EulerAngles<Scalar, EulerSystem>::Matrix3& mat)
{
- eulerAngles(res, mat, PositiveRangeHeading, PositiveRangePitch, PositiveRangeRoll);
+ CalcEulerAngles(res, mat, PositiveRangeAlpha, PositiveRangeBeta, PositiveRangeGamma);
}
template<typename Scalar>
- static void eulerAngles(
+ static void CalcEulerAngles(
EulerAngles<Scalar, EulerSystem>& res,
const typename EulerAngles<Scalar, EulerSystem>::Matrix3& mat,
- bool positiveRangeHeading,
- bool positiveRangePitch,
- bool positiveRangeRoll)
+ bool PositiveRangeAlpha,
+ bool PositiveRangeBeta,
+ bool PositiveRangeGamma)
{
- eulerAngles_imp(
- res.coeffs(), mat,
+ CalcEulerAngles_imp(
+ res.angles(), mat,
typename internal::conditional<IsTaitBryan, internal::true_type, internal::false_type>::type());
- internal::NegateIfXor<IsHeadingOpposite, IsEven>::run(res.h());
- internal::NegateIfXor<IsPitchOpposite, IsEven>::run(res.p());
- internal::NegateIfXor<IsRollOpposite, IsEven>::run(res.r());
+ if (IsAlphaOpposite == IsOdd)
+ res.alpha() = -res.alpha();
+
+ if (IsBetaOpposite == IsOdd)
+ res.beta() = -res.beta();
+
+ if (IsGammaOpposite == IsOdd)
+ res.gamma() = -res.gamma();
// Saturate results to the requested range
- if (positiveRangeHeading && (res.h() < 0))
- res.h() += Scalar(2 * EIGEN_PI);
+ if (PositiveRangeAlpha && (res.alpha() < 0))
+ res.alpha() += Scalar(2 * EIGEN_PI);
- if (positiveRangePitch && (res.p() < 0))
- res.p() += Scalar(2 * EIGEN_PI);
+ if (PositiveRangeBeta && (res.beta() < 0))
+ res.beta() += Scalar(2 * EIGEN_PI);
- if (positiveRangeRoll && (res.r() < 0))
- res.r() += Scalar(2 * EIGEN_PI);
+ if (PositiveRangeGamma && (res.gamma() < 0))
+ res.gamma() += Scalar(2 * EIGEN_PI);
}
};