Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_ALIGNED_VECTOR3
00026 #define EIGEN_ALIGNED_VECTOR3
00027
00028 #include <Eigen/Geometry>
00029
00030 namespace Eigen {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template<typename _Scalar> class AlignedVector3;
00056
00057 namespace internal {
00058 template<typename _Scalar> struct traits<AlignedVector3<_Scalar> >
00059 : traits<Matrix<_Scalar,3,1,0,4,1> >
00060 {
00061 };
00062 }
00063
00064 template<typename _Scalar> class AlignedVector3
00065 : public MatrixBase<AlignedVector3<_Scalar> >
00066 {
00067 typedef Matrix<_Scalar,4,1> CoeffType;
00068 CoeffType m_coeffs;
00069 public:
00070
00071 typedef MatrixBase<AlignedVector3<_Scalar> > Base;
00072 EIGEN_DENSE_PUBLIC_INTERFACE(AlignedVector3)
00073 using Base::operator*;
00074
00075 inline Index rows() const { return 3; }
00076 inline Index cols() const { return 1; }
00077
00078 inline const Scalar& coeff(Index row, Index col) const
00079 { return m_coeffs.coeff(row, col); }
00080
00081 inline Scalar& coeffRef(Index row, Index col)
00082 { return m_coeffs.coeffRef(row, col); }
00083
00084 inline const Scalar& coeff(Index index) const
00085 { return m_coeffs.coeff(index); }
00086
00087 inline Scalar& coeffRef(Index index)
00088 { return m_coeffs.coeffRef(index);}
00089
00090
00091 inline AlignedVector3(const Scalar& x, const Scalar& y, const Scalar& z)
00092 : m_coeffs(x, y, z, Scalar(0))
00093 {}
00094
00095 inline AlignedVector3(const AlignedVector3& other)
00096 : Base(), m_coeffs(other.m_coeffs)
00097 {}
00098
00099 template<typename XprType, int Size=XprType::SizeAtCompileTime>
00100 struct generic_assign_selector {};
00101
00102 template<typename XprType> struct generic_assign_selector<XprType,4>
00103 {
00104 inline static void run(AlignedVector3& dest, const XprType& src)
00105 {
00106 dest.m_coeffs = src;
00107 }
00108 };
00109
00110 template<typename XprType> struct generic_assign_selector<XprType,3>
00111 {
00112 inline static void run(AlignedVector3& dest, const XprType& src)
00113 {
00114 dest.m_coeffs.template head<3>() = src;
00115 dest.m_coeffs.w() = Scalar(0);
00116 }
00117 };
00118
00119 template<typename Derived>
00120 inline explicit AlignedVector3(const MatrixBase<Derived>& other)
00121 {
00122 generic_assign_selector<Derived>::run(*this,other.derived());
00123 }
00124
00125 inline AlignedVector3& operator=(const AlignedVector3& other)
00126 { m_coeffs = other.m_coeffs; return *this; }
00127
00128
00129 inline AlignedVector3 operator+(const AlignedVector3& other) const
00130 { return AlignedVector3(m_coeffs + other.m_coeffs); }
00131
00132 inline AlignedVector3& operator+=(const AlignedVector3& other)
00133 { m_coeffs += other.m_coeffs; return *this; }
00134
00135 inline AlignedVector3 operator-(const AlignedVector3& other) const
00136 { return AlignedVector3(m_coeffs - other.m_coeffs); }
00137
00138 inline AlignedVector3 operator-=(const AlignedVector3& other)
00139 { m_coeffs -= other.m_coeffs; return *this; }
00140
00141 inline AlignedVector3 operator*(const Scalar& s) const
00142 { return AlignedVector3(m_coeffs * s); }
00143
00144 inline friend AlignedVector3 operator*(const Scalar& s,const AlignedVector3& vec)
00145 { return AlignedVector3(s * vec.m_coeffs); }
00146
00147 inline AlignedVector3& operator*=(const Scalar& s)
00148 { m_coeffs *= s; return *this; }
00149
00150 inline AlignedVector3 operator/(const Scalar& s) const
00151 { return AlignedVector3(m_coeffs / s); }
00152
00153 inline AlignedVector3& operator/=(const Scalar& s)
00154 { m_coeffs /= s; return *this; }
00155
00156 inline Scalar dot(const AlignedVector3& other) const
00157 {
00158 eigen_assert(m_coeffs.w()==Scalar(0));
00159 eigen_assert(other.m_coeffs.w()==Scalar(0));
00160 return m_coeffs.dot(other.m_coeffs);
00161 }
00162
00163 inline void normalize()
00164 {
00165 m_coeffs /= norm();
00166 }
00167
00168 inline AlignedVector3 normalized()
00169 {
00170 return AlignedVector3(m_coeffs / norm());
00171 }
00172
00173 inline Scalar sum() const
00174 {
00175 eigen_assert(m_coeffs.w()==Scalar(0));
00176 return m_coeffs.sum();
00177 }
00178
00179 inline Scalar squaredNorm() const
00180 {
00181 eigen_assert(m_coeffs.w()==Scalar(0));
00182 return m_coeffs.squaredNorm();
00183 }
00184
00185 inline Scalar norm() const
00186 {
00187 return internal::sqrt(squaredNorm());
00188 }
00189
00190 inline AlignedVector3 cross(const AlignedVector3& other) const
00191 {
00192 return AlignedVector3(m_coeffs.cross3(other.m_coeffs));
00193 }
00194
00195 template<typename Derived>
00196 inline bool isApprox(const MatrixBase<Derived>& other, RealScalar eps=NumTraits<Scalar>::dummy_precision()) const
00197 {
00198 return m_coeffs.template head<3>().isApprox(other,eps);
00199 }
00200 };
00201
00202
00203
00204 }
00205
00206 #endif // EIGEN_ALIGNED_VECTOR3