Warning, /include/eigen3/unsupported/Eigen/AlignedVector3 is written in an unsupported language. File is not indexed.
0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009 Gael Guennebaud <g.gael@free.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_ALIGNED_VECTOR3
0011 #define EIGEN_ALIGNED_VECTOR3
0012
0013 #include "../../Eigen/Geometry"
0014
0015 #include "../../Eigen/src/Core/util/DisableStupidWarnings.h"
0016
0017 namespace Eigen {
0018
0019 /**
0020 * \defgroup AlignedVector3_Module Aligned vector3 module
0021 *
0022 * \code
0023 * #include <unsupported/Eigen/AlignedVector3>
0024 * \endcode
0025 */
0026 //@{
0027
0028
0029 /** \class AlignedVector3
0030 *
0031 * \brief A vectorization friendly 3D vector
0032 *
0033 * This class represents a 3D vector internally using a 4D vector
0034 * such that vectorization can be seamlessly enabled. Of course,
0035 * the same result can be achieved by directly using a 4D vector.
0036 * This class makes this process simpler.
0037 *
0038 */
0039 // TODO specialize Cwise
0040 template<typename _Scalar> class AlignedVector3;
0041
0042 namespace internal {
0043 template<typename _Scalar> struct traits<AlignedVector3<_Scalar> >
0044 : traits<Matrix<_Scalar,3,1,0,4,1> >
0045 {
0046 };
0047 }
0048
0049 template<typename _Scalar> class AlignedVector3
0050 : public MatrixBase<AlignedVector3<_Scalar> >
0051 {
0052 typedef Matrix<_Scalar,4,1> CoeffType;
0053 CoeffType m_coeffs;
0054 public:
0055
0056 typedef MatrixBase<AlignedVector3<_Scalar> > Base;
0057 EIGEN_DENSE_PUBLIC_INTERFACE(AlignedVector3)
0058 using Base::operator*;
0059
0060 inline Index rows() const { return 3; }
0061 inline Index cols() const { return 1; }
0062
0063 Scalar* data() { return m_coeffs.data(); }
0064 const Scalar* data() const { return m_coeffs.data(); }
0065 Index innerStride() const { return 1; }
0066 Index outerStride() const { return 3; }
0067
0068 inline const Scalar& coeff(Index row, Index col) const
0069 { return m_coeffs.coeff(row, col); }
0070
0071 inline Scalar& coeffRef(Index row, Index col)
0072 { return m_coeffs.coeffRef(row, col); }
0073
0074 inline const Scalar& coeff(Index index) const
0075 { return m_coeffs.coeff(index); }
0076
0077 inline Scalar& coeffRef(Index index)
0078 { return m_coeffs.coeffRef(index);}
0079
0080
0081 inline AlignedVector3()
0082 {}
0083
0084 inline AlignedVector3(const Scalar& x, const Scalar& y, const Scalar& z)
0085 : m_coeffs(x, y, z, Scalar(0))
0086 {}
0087
0088 inline AlignedVector3(const AlignedVector3& other)
0089 : Base(), m_coeffs(other.m_coeffs)
0090 {}
0091
0092 template<typename XprType, int Size=XprType::SizeAtCompileTime>
0093 struct generic_assign_selector {};
0094
0095 template<typename XprType> struct generic_assign_selector<XprType,4>
0096 {
0097 inline static void run(AlignedVector3& dest, const XprType& src)
0098 {
0099 dest.m_coeffs = src;
0100 }
0101 };
0102
0103 template<typename XprType> struct generic_assign_selector<XprType,3>
0104 {
0105 inline static void run(AlignedVector3& dest, const XprType& src)
0106 {
0107 dest.m_coeffs.template head<3>() = src;
0108 dest.m_coeffs.w() = Scalar(0);
0109 }
0110 };
0111
0112 template<typename Derived>
0113 inline AlignedVector3(const MatrixBase<Derived>& other)
0114 {
0115 generic_assign_selector<Derived>::run(*this,other.derived());
0116 }
0117
0118 inline AlignedVector3& operator=(const AlignedVector3& other)
0119 { m_coeffs = other.m_coeffs; return *this; }
0120
0121 template <typename Derived>
0122 inline AlignedVector3& operator=(const MatrixBase<Derived>& other)
0123 {
0124 generic_assign_selector<Derived>::run(*this,other.derived());
0125 return *this;
0126 }
0127
0128 inline AlignedVector3 operator+(const AlignedVector3& other) const
0129 { return AlignedVector3(m_coeffs + other.m_coeffs); }
0130
0131 inline AlignedVector3& operator+=(const AlignedVector3& other)
0132 { m_coeffs += other.m_coeffs; return *this; }
0133
0134 inline AlignedVector3 operator-(const AlignedVector3& other) const
0135 { return AlignedVector3(m_coeffs - other.m_coeffs); }
0136
0137 inline AlignedVector3 operator-() const
0138 { return AlignedVector3(-m_coeffs); }
0139
0140 inline AlignedVector3 operator-=(const AlignedVector3& other)
0141 { m_coeffs -= other.m_coeffs; return *this; }
0142
0143 inline AlignedVector3 operator*(const Scalar& s) const
0144 { return AlignedVector3(m_coeffs * s); }
0145
0146 inline friend AlignedVector3 operator*(const Scalar& s,const AlignedVector3& vec)
0147 { return AlignedVector3(s * vec.m_coeffs); }
0148
0149 inline AlignedVector3& operator*=(const Scalar& s)
0150 { m_coeffs *= s; return *this; }
0151
0152 inline AlignedVector3 operator/(const Scalar& s) const
0153 { return AlignedVector3(m_coeffs / s); }
0154
0155 inline AlignedVector3& operator/=(const Scalar& s)
0156 { m_coeffs /= s; return *this; }
0157
0158 inline Scalar dot(const AlignedVector3& other) const
0159 {
0160 eigen_assert(m_coeffs.w()==Scalar(0));
0161 eigen_assert(other.m_coeffs.w()==Scalar(0));
0162 return m_coeffs.dot(other.m_coeffs);
0163 }
0164
0165 inline void normalize()
0166 {
0167 m_coeffs /= norm();
0168 }
0169
0170 inline AlignedVector3 normalized() const
0171 {
0172 return AlignedVector3(m_coeffs / norm());
0173 }
0174
0175 inline Scalar sum() const
0176 {
0177 eigen_assert(m_coeffs.w()==Scalar(0));
0178 return m_coeffs.sum();
0179 }
0180
0181 inline Scalar squaredNorm() const
0182 {
0183 eigen_assert(m_coeffs.w()==Scalar(0));
0184 return m_coeffs.squaredNorm();
0185 }
0186
0187 inline Scalar norm() const
0188 {
0189 using std::sqrt;
0190 return sqrt(squaredNorm());
0191 }
0192
0193 inline AlignedVector3 cross(const AlignedVector3& other) const
0194 {
0195 return AlignedVector3(m_coeffs.cross3(other.m_coeffs));
0196 }
0197
0198 template<typename Derived>
0199 inline bool isApprox(const MatrixBase<Derived>& other, const RealScalar& eps=NumTraits<Scalar>::dummy_precision()) const
0200 {
0201 return m_coeffs.template head<3>().isApprox(other,eps);
0202 }
0203
0204 CoeffType& coeffs() { return m_coeffs; }
0205 const CoeffType& coeffs() const { return m_coeffs; }
0206 };
0207
0208 namespace internal {
0209
0210 template<typename _Scalar>
0211 struct eval<AlignedVector3<_Scalar>, Dense>
0212 {
0213 typedef const AlignedVector3<_Scalar>& type;
0214 };
0215
0216 template<typename Scalar>
0217 struct evaluator<AlignedVector3<Scalar> >
0218 : evaluator<Matrix<Scalar,4,1> >
0219 {
0220 typedef AlignedVector3<Scalar> XprType;
0221 typedef evaluator<Matrix<Scalar,4,1> > Base;
0222
0223 evaluator(const XprType &m) : Base(m.coeffs()) {}
0224 };
0225
0226 }
0227
0228 //@}
0229
0230 }
0231
0232 #include "../../Eigen/src/Core/util/ReenableStupidWarnings.h"
0233
0234 #endif // EIGEN_ALIGNED_VECTOR3