Changeset 167 in flair-src for trunk/lib/FlairCore/src
- Timestamp:
- Apr 12, 2017, 1:59:38 PM (8 years ago)
- Location:
- trunk/lib/FlairCore/src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/AhrsData.cpp
r15 r167 43 43 void CopyData(char *destination) const { 44 44 float data; 45 Vector3D angularRates;45 Vector3Df angularRates; 46 46 Euler eulerAngles; 47 47 Quaternion quaternion; … … 138 138 } 139 139 140 Vector3D AhrsData::GetAngularRates(void) const {141 Vector3D out;140 Vector3Df AhrsData::GetAngularRates(void) const { 141 Vector3Df out; 142 142 GetMutex(); 143 143 out = angularRates; … … 147 147 148 148 void AhrsData::GetQuaternionAndAngularRates(Quaternion &outQuaternion, 149 Vector3D &outAngularRates) const {149 Vector3Df &outAngularRates) const { 150 150 GetMutex(); 151 151 outQuaternion = quaternion; … … 155 155 156 156 void AhrsData::SetQuaternionAndAngularRates(const Quaternion &inQuaternion, 157 const Vector3D &inAngularRates) {157 const Vector3Df &inAngularRates) { 158 158 GetMutex(); 159 159 quaternion = inQuaternion; … … 168 168 } 169 169 170 void AhrsData::SetAngularRates(const Vector3D &inAngularRates) {170 void AhrsData::SetAngularRates(const Vector3Df &inAngularRates) { 171 171 GetMutex(); 172 172 angularRates = inAngularRates; -
trunk/lib/FlairCore/src/AhrsData.h
r15 r167 121 121 * 122 122 */ 123 void SetAngularRates(const Vector3D &angularRates);123 void SetAngularRates(const Vector3Df &angularRates); 124 124 125 125 /*! … … 131 131 * 132 132 */ 133 Vector3D GetAngularRates(void) const;133 Vector3Df GetAngularRates(void) const; 134 134 135 135 /*! … … 143 143 */ 144 144 void GetQuaternionAndAngularRates(Quaternion &quaternion, 145 Vector3D &angularRates) const;145 Vector3Df &angularRates) const; 146 146 147 147 /*! … … 155 155 */ 156 156 void SetQuaternionAndAngularRates(const Quaternion &quaternion, 157 const Vector3D &angularRates);157 const Vector3Df &angularRates); 158 158 159 159 const Type &GetDataType() const { return dataType; } … … 182 182 * 183 183 */ 184 Vector3D angularRates;184 Vector3Df angularRates; 185 185 186 186 Type dataType; -
trunk/lib/FlairCore/src/GpsData.h
r51 r167 19 19 20 20 class IODataElement; 21 class Vector3D;22 21 23 22 /*! \class GpsData -
trunk/lib/FlairCore/src/ImuData.cpp
r15 r167 44 44 void CopyData(char *dst) const { 45 45 float data; 46 Vector3D rawAcc = imudata->GetRawAcc();47 Vector3D rawMag = imudata->GetRawMag();48 Vector3D rawGyr = imudata->GetRawGyr();46 Vector3Df rawAcc = imudata->GetRawAcc(); 47 Vector3Df rawMag = imudata->GetRawMag(); 48 Vector3Df rawGyr = imudata->GetRawGyr(); 49 49 switch (plotableData) { 50 50 case ImuData::RawAx: … … 121 121 ImuData::~ImuData() {} 122 122 123 Vector3D ImuData::GetRawAcc(void) const {124 Vector3D out;123 Vector3Df ImuData::GetRawAcc(void) const { 124 Vector3Df out; 125 125 GetMutex(); 126 126 out = rawAcc; … … 129 129 } 130 130 131 Vector3D ImuData::GetRawMag(void) const {132 Vector3D out;131 Vector3Df ImuData::GetRawMag(void) const { 132 Vector3Df out; 133 133 GetMutex(); 134 134 out = rawMag; … … 137 137 } 138 138 139 Vector3D ImuData::GetRawGyr(void) const {140 Vector3D out;139 Vector3Df ImuData::GetRawGyr(void) const { 140 Vector3Df out; 141 141 GetMutex(); 142 142 out = rawGyr; … … 145 145 } 146 146 147 void ImuData::GetRawAccMagAndGyr(Vector3D &inRawAcc, Vector3D&inRawMag,148 Vector3D &inRawGyr) const {147 void ImuData::GetRawAccMagAndGyr(Vector3Df &inRawAcc, Vector3Df &inRawMag, 148 Vector3Df &inRawGyr) const { 149 149 GetMutex(); 150 150 inRawAcc = rawAcc; … … 154 154 } 155 155 156 void ImuData::SetRawAcc(const Vector3D &inRawAcc) {156 void ImuData::SetRawAcc(const Vector3Df &inRawAcc) { 157 157 GetMutex(); 158 158 rawAcc = inRawAcc; … … 160 160 } 161 161 162 void ImuData::SetRawMag(const Vector3D &inRawMag) {162 void ImuData::SetRawMag(const Vector3Df &inRawMag) { 163 163 GetMutex(); 164 164 rawMag = inRawMag; … … 166 166 } 167 167 168 void ImuData::SetRawGyr(const Vector3D &inRawGyr) {168 void ImuData::SetRawGyr(const Vector3Df &inRawGyr) { 169 169 GetMutex(); 170 170 rawGyr = inRawGyr; … … 172 172 } 173 173 174 void ImuData::SetRawAccMagAndGyr(const Vector3D &inRawAcc,175 const Vector3D &inRawMag,176 const Vector3D &inRawGyr) {174 void ImuData::SetRawAccMagAndGyr(const Vector3Df &inRawAcc, 175 const Vector3Df &inRawMag, 176 const Vector3Df &inRawGyr) { 177 177 GetMutex(); 178 178 rawAcc = inRawAcc; -
trunk/lib/FlairCore/src/ImuData.h
r15 r167 104 104 * 105 105 */ 106 Vector3D GetRawAcc(void) const;106 Vector3Df GetRawAcc(void) const; 107 107 108 108 /*! … … 114 114 * 115 115 */ 116 Vector3D GetRawMag(void) const;116 Vector3Df GetRawMag(void) const; 117 117 118 118 /*! … … 124 124 * 125 125 */ 126 Vector3D GetRawGyr(void) const;126 Vector3Df GetRawGyr(void) const; 127 127 128 128 /*! … … 136 136 * 137 137 */ 138 void GetRawAccMagAndGyr(Vector3D &rawAcc, Vector3D&rawMag,139 Vector3D &rawGyr) const;138 void GetRawAccMagAndGyr(Vector3Df &rawAcc, Vector3Df &rawMag, 139 Vector3Df &rawGyr) const; 140 140 141 141 /*! … … 147 147 * 148 148 */ 149 void SetRawAcc(const Vector3D &rawAcc);149 void SetRawAcc(const Vector3Df &rawAcc); 150 150 151 151 /*! … … 157 157 * 158 158 */ 159 void SetRawMag(const Vector3D &rawMag);159 void SetRawMag(const Vector3Df &rawMag); 160 160 161 161 /*! … … 167 167 * 168 168 */ 169 void SetRawGyr(const Vector3D &rawGyr);169 void SetRawGyr(const Vector3Df &rawGyr); 170 170 171 171 /*! … … 179 179 * 180 180 */ 181 void SetRawAccMagAndGyr(const Vector3D &rawAcc, const Vector3D&rawMag,182 const Vector3D &rawGyr);181 void SetRawAccMagAndGyr(const Vector3Df &rawAcc, const Vector3Df &rawMag, 182 const Vector3Df &rawGyr); 183 183 184 184 Type const &GetDataType() const { return dataType; } … … 199 199 * 200 200 */ 201 Vector3D rawAcc;201 Vector3Df rawAcc; 202 202 203 203 /*! … … 205 205 * 206 206 */ 207 Vector3D rawGyr;207 Vector3Df rawGyr; 208 208 209 209 /*! … … 211 211 * 212 212 */ 213 Vector3D rawMag;213 Vector3Df rawMag; 214 214 215 215 void Queue(char **dst, const void *src, size_t size) const; -
trunk/lib/FlairCore/src/OneAxisRotation.cpp
r147 r167 24 24 #include "OneAxisRotation.h" 25 25 #include "OneAxisRotation_impl.h" 26 #include <Vector3D.h>27 26 #include <Euler.h> 28 27 … … 32 31 namespace core { 33 32 33 template void OneAxisRotation::ComputeRotation(core::Vector3D<float> &) const; 34 template void OneAxisRotation::ComputeRotation(core::Vector3D<double> &) const; 35 34 36 OneAxisRotation::OneAxisRotation(const gui::LayoutPosition *position, 35 37 string name) … … 40 42 OneAxisRotation::~OneAxisRotation() { delete pimpl_; } 41 43 42 void OneAxisRotation::ComputeRotation(Vector3D&vector) const {44 template <typename T> void OneAxisRotation::ComputeRotation(Vector3D<T> &vector) const { 43 45 pimpl_->ComputeRotation(vector); 44 46 } -
trunk/lib/FlairCore/src/OneAxisRotation.h
r147 r167 15 15 16 16 #include <GroupBox.h> 17 #include <Vector3D.h> 17 18 18 19 class OneAxisRotation_impl; … … 24 25 25 26 namespace core { 26 class Vector3D;27 27 class Euler; 28 28 class Quaternion; … … 57 57 * \brief Compute rotation 58 58 * 59 * \param vector Vector3D to rotate59 * \param vector Vector3Df to rotate 60 60 */ 61 void ComputeRotation(core::Vector3D&vector) const;61 template <typename T> void ComputeRotation(core::Vector3D<T> &vector) const; 62 62 63 63 /*! -
trunk/lib/FlairCore/src/OneAxisRotation_impl.cpp
r144 r167 20 20 #include "ComboBox.h" 21 21 #include "DoubleSpinBox.h" 22 #include <Vector3D.h>23 22 #include <Euler.h> 24 23 #include <Quaternion.h> … … 27 26 using namespace flair::core; 28 27 using namespace flair::gui; 28 29 template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const; 30 template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const; 29 31 30 32 OneAxisRotation_impl::OneAxisRotation_impl(GroupBox *box) { … … 41 43 // compute rotation of each axis through ComputeRotation(Vector3D& vector) 42 44 void OneAxisRotation_impl::ComputeRotation(Quaternion &quat) const { 43 Vector3D rot = Vector3D(quat.q1, quat.q2, quat.q3);45 Vector3Df rot = Vector3Df(quat.q1, quat.q2, quat.q3); 44 46 ComputeRotation(rot); 45 47 quat.q1 = rot.x; … … 54 56 // on utilise la rotation d'un vector pour faire une rotation de repere 55 57 // d'ou le signe negatif 56 void OneAxisRotation_impl::ComputeRotation(Vector3D&vector) const {58 template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const { 57 59 switch (rot_axe->CurrentIndex()) { 58 60 case 0: -
trunk/lib/FlairCore/src/Quaternion.cpp
r161 r167 17 17 18 18 #include "Quaternion.h" 19 #include "Vector3D.h"20 19 #include "Euler.h" 21 20 #include "RotationMatrix.h" … … 63 62 } 64 63 65 void Quaternion::GetLogarithm(Vector3D &logarithm) {64 void Quaternion::GetLogarithm(Vector3Df &logarithm) { 66 65 Normalize(); 67 66 float v_norm = sqrtf(q1 * q1 + q2 * q2 + q3 * q3); … … 79 78 } 80 79 81 Vector3D Quaternion::GetLogarithm(void) {82 Vector3D vector;80 Vector3Df Quaternion::GetLogarithm(void) { 81 Vector3Df vector; 83 82 GetLogarithm(vector); 84 83 return vector; 85 84 } 86 85 87 Quaternion Quaternion::GetDerivative(const Vector3D &angularSpeed) const {86 Quaternion Quaternion::GetDerivative(const Vector3Df &angularSpeed) const { 88 87 const Quaternion Qw(0, angularSpeed.x, angularSpeed.y, angularSpeed.z); 89 88 return 0.5 * (*this) * Qw; 90 89 } 91 90 92 void Quaternion::Derivate(const Vector3D &angularSpeed) {91 void Quaternion::Derivate(const Vector3Df &angularSpeed) { 93 92 Quaternion Q = GetDerivative(angularSpeed); 94 93 (*this) = Q; -
trunk/lib/FlairCore/src/Quaternion.h
r15 r167 13 13 #define QUATERNION_H 14 14 15 #include <Vector3D.h> 16 15 17 namespace flair { 16 18 namespace core { 17 19 class Euler; 18 class Vector3D;19 20 class RotationMatrix; 20 21 … … 62 63 * \param logarithm output logarithm 63 64 */ 64 void GetLogarithm(Vector3D &logarithm);65 void GetLogarithm(Vector3Df &logarithm); 65 66 66 67 /*! … … 71 72 * \return output logarithm 72 73 */ 73 Vector3D GetLogarithm(void);74 Vector3Df GetLogarithm(void); 74 75 75 76 /*! … … 92 93 * \return derivative 93 94 */ 94 Quaternion GetDerivative(const Vector3D &angularSpeed) const;95 Quaternion GetDerivative(const Vector3Df &angularSpeed) const; 95 96 96 97 /*! … … 99 100 * \param w rotationonal speed 100 101 */ 101 void Derivate(const Vector3D &angularSpeed);102 void Derivate(const Vector3Df &angularSpeed); 102 103 103 104 /*! -
trunk/lib/FlairCore/src/Vector2D.cpp
r161 r167 22 22 namespace flair { 23 23 namespace core { 24 25 template class Vector2D<double>; 26 template Vector2D<double> operator+(const Vector2D<double>&, const Vector2D<double>&); 27 template Vector2D<double> operator-(const Vector2D<double>&, const Vector2D<double>&); 28 template Vector2D<double> operator-(const Vector2D<double>&); 29 template Vector2D<double> operator/(const Vector2D<double>&, float); 30 template Vector2D<double> operator*(const Vector2D<double>&, float); 31 template Vector2D<double> operator*(float, const Vector2D<double>&); 24 32 25 Vector2D::Vector2D(float inX, float inY) : x(inX), y(inY) {} 33 template class Vector2D<float>; 34 template Vector2D<float> operator+(const Vector2D<float>&, const Vector2D<float>&); 35 template Vector2D<float> operator-(const Vector2D<float>&, const Vector2D<float>&); 36 template Vector2D<float> operator-(const Vector2D<float>&); 37 template Vector2D<float> operator/(const Vector2D<float>&, float); 38 template Vector2D<float> operator*(const Vector2D<float>&, float); 39 template Vector2D<float> operator*(float, const Vector2D<float>&); 26 40 27 Vector2D::~Vector2D() {}41 template <typename T> Vector2D<T>::Vector2D(T inX, T inY) : x(inX), y(inY) {} 28 42 29 Vector2D &Vector2D::operator=(const Vector2D &vector) { 30 x = vector.x; 31 y = vector.y; 32 return (*this); 33 } 43 template <typename T> Vector2D<T>::~Vector2D() {} 34 44 35 Vector2D &Vector2D::operator+=(const Vector2D&vector) {45 template <typename T> Vector2D<T> &Vector2D<T>::operator+=(const Vector2D<T> &vector) { 36 46 x += vector.x; 37 47 y += vector.y; … … 39 49 } 40 50 41 Vector2D &Vector2D::operator-=(const Vector2D&vector) {51 template <typename T> Vector2D<T> &Vector2D<T>::operator-=(const Vector2D<T> &vector) { 42 52 x -= vector.x; 43 53 y -= vector.y; … … 45 55 } 46 56 47 Vector2D operator+(const Vector2D &vectorA, const Vector2D&vectorB) {48 return Vector2D (vectorA.x + vectorB.x, vectorA.y + vectorB.y);57 template <typename T> Vector2D<T> operator+(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB) { 58 return Vector2D<T>(vectorA.x + vectorB.x, vectorA.y + vectorB.y); 49 59 } 50 60 51 Vector2D operator-(const Vector2D &vectorA, const Vector2D&vectorB) {52 return Vector2D (vectorA.x - vectorB.x, vectorA.y - vectorB.y);61 template <typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB) { 62 return Vector2D<T>(vectorA.x - vectorB.x, vectorA.y - vectorB.y); 53 63 } 54 64 55 Vector2D operator-(const Vector2D&vectorA) {56 return Vector2D (-vectorA.x, -vectorA.y);65 template <typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA) { 66 return Vector2D<T>(-vectorA.x, -vectorA.y); 57 67 } 58 68 59 Vector2D operator/(const Vector2D&vector, float coeff) {69 template <typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff) { 60 70 if (coeff != 0) { 61 return Vector2D (vector.x / coeff, vector.y / coeff);71 return Vector2D<T>(vector.x / coeff, vector.y / coeff); 62 72 } else { 63 return Vector2D (0, 0);73 return Vector2D<T>(0, 0); 64 74 } 65 75 } 66 76 67 Vector2D operator*(const Vector2D&vector, float coeff) {68 return Vector2D (vector.x * coeff, vector.y * coeff);77 template <typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff) { 78 return Vector2D<T>(vector.x * coeff, vector.y * coeff); 69 79 } 70 80 71 Vector2D operator*(float coeff, const Vector2D&vector) {72 return Vector2D (vector.x * coeff, vector.y * coeff);81 template <typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector) { 82 return Vector2D<T>(vector.x * coeff, vector.y * coeff); 73 83 } 74 84 75 void Vector2D::Rotate(float value) {85 template <typename T> void Vector2D<T>::Rotate(float value) { 76 86 float xTmp; 77 87 xTmp = x * cosf(value) - y * sinf(value); … … 80 90 } 81 91 82 void Vector2D::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }92 template <typename T> void Vector2D<T>::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); } 83 93 84 float Vector2D::GetNorm(void) const { return sqrt(x * x + y * y); }94 template <typename T> float Vector2D<T>::GetNorm(void) const { return sqrt(x * x + y * y); } 85 95 86 void Vector2D::Normalize(void) {96 template <typename T> void Vector2D<T>::Normalize(void) { 87 97 float n = GetNorm(); 88 98 if (n != 0) { … … 92 102 } 93 103 94 void Vector2D::Saturate(Vector2D min, Vector2D max) {104 template <typename T> void Vector2D<T>::Saturate(Vector2D min, Vector2D max) { 95 105 if (x < min.x) 96 106 x = min.x; … … 104 114 } 105 115 106 void Vector2D::Saturate(float min, float max) {116 template <typename T> void Vector2D<T>::Saturate(float min, float max) { 107 117 Saturate(Vector2D(min, min), Vector2D(max, max)); 108 118 } 109 119 110 void Vector2D::Saturate(const Vector2D &value) {120 template <typename T> void Vector2D<T>::Saturate(const Vector2D &value) { 111 121 float x = fabs(value.x); 112 122 float y = fabs(value.y); … … 114 124 } 115 125 116 void Vector2D::Saturate(float value) {126 template <typename T> void Vector2D<T>::Saturate(float value) { 117 127 float sat = fabs(value); 118 128 Saturate(Vector2D(-sat, -sat), Vector2D(sat, sat)); -
trunk/lib/FlairCore/src/Vector2D.h
r161 r167 21 21 * \brief Class defining a 2D vector 22 22 */ 23 template <typename T> 23 24 class Vector2D { 24 25 public: … … 31 32 * \param y 32 33 */ 33 Vector2D( float x = 0, floaty = 0);34 Vector2D(T x = 0, T y = 0); 34 35 35 36 /*! … … 73 74 * \param max maximum Vector2D value 74 75 */ 75 void Saturate(Vector2D min, Vector2Dmax);76 void Saturate(Vector2D<T> min, Vector2D<T> max); 76 77 77 78 /*! … … 92 93 * \param value saturation Vector2D value 93 94 */ 94 void Saturate(const Vector2D &value);95 void Saturate(const Vector2D<T> &value); 95 96 96 97 /*! … … 106 107 * \brief x 107 108 */ 108 floatx;109 T x; 109 110 110 111 /*! 111 112 * \brief y 112 113 */ 113 floaty;114 T y; 114 115 115 Vector2D &operator=(const Vector2D &vector); 116 Vector2D &operator+=(const Vector2D &vector); 117 Vector2D &operator-=(const Vector2D &vector); 116 template<typename S> Vector2D<T> &operator=(const Vector2D<S> &vector) { 117 x = vector.x; 118 y = vector.y; 119 return (*this); 120 } 121 Vector2D<T> &operator+=(const Vector2D<T> &vector); 122 Vector2D<T> &operator-=(const Vector2D<T> &vector); 118 123 }; 124 125 typedef Vector2D<float> Vector2Df; 119 126 120 127 /*! Add … … 125 132 * \param vectorB vector 126 133 */ 127 Vector2D operator+(const Vector2D &vectorA, const Vector2D&vectorB);134 template<typename T> Vector2D<T> operator+(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB); 128 135 129 136 /*! Substract … … 134 141 * \param vectorB vector 135 142 */ 136 Vector2D operator-(const Vector2D &vectorA, const Vector2D&vectorB);143 template<typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB); 137 144 138 145 /*! Opposite … … 144 151 * \return -vectorA 145 152 */ 146 Vector2D operator-(const Vector2D&vectorA);153 template<typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA); 147 154 148 155 /*! Divid … … 154 161 * \return vector/coefficient 155 162 */ 156 Vector2D operator/(const Vector2D&vector, float coeff);163 template<typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff); 157 164 158 165 /*! Multiply … … 164 171 * \return coefficient*vector 165 172 */ 166 Vector2D operator*(const Vector2D&vector, float coeff);173 template<typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff); 167 174 168 175 /*! Multiply … … 174 181 * \return coefficient*vector 175 182 */ 176 Vector2D operator*(float coeff, const Vector2D&vector);183 template<typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector); 177 184 178 185 } // end namespace core -
trunk/lib/FlairCore/src/Vector3D.cpp
r15 r167 23 23 #include "Object.h" 24 24 #include <math.h> 25 //#include "Vector3DSpinBox.h"26 25 27 26 namespace flair { 28 27 namespace core { 29 30 Vector3D::Vector3D(float inX, float inY, float inZ) : x(inX), y(inY), z(inZ) {} 31 32 Vector3D::~Vector3D() {} 28 29 template class Vector3D<double>; 30 template Vector3D<double> operator+(const Vector3D<double>&, const Vector3D<double>&); 31 template Vector3D<double> operator-(const Vector3D<double>&, const Vector3D<double>&); 32 template Vector3D<double> operator-(const Vector3D<double>&); 33 template Vector3D<double> operator/(const Vector3D<double>&, float); 34 template Vector3D<double> operator*(const Vector3D<double>&, const Vector3D<double>&); 35 template Vector3D<double> operator*(const Vector3D<double>&, float); 36 template Vector3D<double> operator*(float, const Vector3D<double>&); 37 template Vector3D<double> CrossProduct(const Vector3D<double>&, const Vector3D<double>&); 38 template float DotProduct(const Vector3D<double>&, const Vector3D<double>&); 39 40 template class Vector3D<float>; 41 template Vector3D<float> operator+(const Vector3D<float>&, const Vector3D<float>&); 42 template Vector3D<float> operator-(const Vector3D<float>&, const Vector3D<float>&); 43 template Vector3D<float> operator-(const Vector3D<float>&); 44 template Vector3D<float> operator/(const Vector3D<float>&, float); 45 template Vector3D<float> operator*(const Vector3D<float>&, const Vector3D<float>&); 46 template Vector3D<float> operator*(const Vector3D<float>&, float); 47 template Vector3D<float> operator*(float, const Vector3D<float>&); 48 template Vector3D<float> CrossProduct(const Vector3D<float>&, const Vector3D<float>&); 49 template float DotProduct(const Vector3D<float>&, const Vector3D<float>&); 50 51 template <typename T> Vector3D<T>::Vector3D(T inX, T inY, T inZ) { 52 x=inX; 53 y=inY; 54 z=inZ; 55 } 56 57 template <typename T> Vector3D<T>::~Vector3D() {} 58 33 59 /* 34 60 void Vector3D::operator=(const gui::Vector3DSpinBox *vector) { … … 38 64 z=vect.z; 39 65 }*/ 40 41 Vector3D &Vector3D::operator=(const Vector3D &vector) { 66 /* 67 template<typename T,typename S> Vector3D<T> &Vector3D<T>::operator=(const Vector3D<S> &vector) { 68 //template <typename T> Vector3D<T> &Vector3D<T>::operator=(const Vector3D<T> &vector) { 42 69 x = vector.x; 43 70 y = vector.y; … … 45 72 return (*this); 46 73 } 47 48 Vector3D &Vector3D::operator+=(const Vector3D&vector) {74 */ 75 template <typename T> Vector3D<T> &Vector3D<T>::operator+=(const Vector3D<T> &vector) { 49 76 x += vector.x; 50 77 y += vector.y; … … 53 80 } 54 81 55 Vector3D &Vector3D::operator-=(const Vector3D&vector) {82 template <typename T> Vector3D<T> &Vector3D<T>::operator-=(const Vector3D<T> &vector) { 56 83 x -= vector.x; 57 84 y -= vector.y; … … 60 87 } 61 88 62 float &Vector3D::operator[](size_t idx) {89 template <typename T> T &Vector3D<T>::operator[](size_t idx) { 63 90 if (idx == 0) { 64 91 return x; … … 73 100 } 74 101 75 const float &Vector3D::operator[](size_t idx) const {102 template <typename T> const T &Vector3D<T>::operator[](size_t idx) const { 76 103 if (idx == 0) { 77 104 return x; … … 86 113 } 87 114 88 Vector3D CrossProduct(const Vector3D &vectorA, const Vector3D&vectorB) {89 return Vector3D (vectorA.y * vectorB.z - vectorA.z * vectorB.y,115 template <typename T> Vector3D<T> CrossProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB) { 116 return Vector3D<T>(vectorA.y * vectorB.z - vectorA.z * vectorB.y, 90 117 vectorA.z * vectorB.x - vectorA.x * vectorB.z, 91 118 vectorA.x * vectorB.y - vectorA.y * vectorB.x); 92 119 } 93 120 94 float DotProduct(const Vector3D &vectorA, const Vector3D&vectorB) {121 template <typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB) { 95 122 return vectorA.x * vectorB.x + vectorA.y * vectorB.y + vectorA.z * vectorB.z; 96 123 } 97 124 98 Vector3D operator+(const Vector3D &vectorA, const Vector3D&vectorB) {99 return Vector3D (vectorA.x + vectorB.x, vectorA.y + vectorB.y,125 template <typename T> Vector3D<T> operator+(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB) { 126 return Vector3D<T>(vectorA.x + vectorB.x, vectorA.y + vectorB.y, 100 127 vectorA.z + vectorB.z); 101 128 } 102 129 103 Vector3D operator-(const Vector3D &vectorA, const Vector3D&vectorB) {104 return Vector3D (vectorA.x - vectorB.x, vectorA.y - vectorB.y,130 template <typename T> Vector3D<T> operator-(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB) { 131 return Vector3D<T>(vectorA.x - vectorB.x, vectorA.y - vectorB.y, 105 132 vectorA.z - vectorB.z); 106 133 } 107 134 108 Vector3D operator-(const Vector3D&vector) {109 return Vector3D (-vector.x, -vector.y, -vector.z);110 } 111 112 Vector3D operator*(const Vector3D &vectorA, const Vector3D&vectorB) {113 return Vector3D (vectorA.x * vectorB.x, vectorA.y * vectorB.y,135 template <typename T> Vector3D<T> operator-(const Vector3D<T> &vector) { 136 return Vector3D<T>(-vector.x, -vector.y, -vector.z); 137 } 138 139 template <typename T> Vector3D<T> operator*(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB) { 140 return Vector3D<T>(vectorA.x * vectorB.x, vectorA.y * vectorB.y, 114 141 vectorA.z * vectorB.z); 115 142 } 116 143 117 Vector3D operator*(const Vector3D&vector, float coeff) {118 return Vector3D (vector.x * coeff, vector.y * coeff, vector.z * coeff);119 } 120 121 Vector3D operator*(float coeff, const Vector3D&vector) {122 return Vector3D (vector.x * coeff, vector.y * coeff, vector.z * coeff);123 } 124 125 Vector3D operator/(const Vector3D&vector, float coeff) {144 template <typename T> Vector3D<T> operator*(const Vector3D<T> &vector, float coeff) { 145 return Vector3D<T>(vector.x * coeff, vector.y * coeff, vector.z * coeff); 146 } 147 148 template <typename T> Vector3D<T> operator*(float coeff, const Vector3D<T> &vector) { 149 return Vector3D<T>(vector.x * coeff, vector.y * coeff, vector.z * coeff); 150 } 151 152 template <typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff) { 126 153 if (coeff != 0) { 127 return Vector3D (vector.x / coeff, vector.y / coeff, vector.z / coeff);154 return Vector3D<T>(vector.x / coeff, vector.y / coeff, vector.z / coeff); 128 155 } else { 129 156 printf("Vector3D: err divinding by 0\n"); 130 return Vector3D (0, 0, 0);131 } 132 } 133 134 void Vector3D::RotateX(float value) {157 return Vector3D<T>(0, 0, 0); 158 } 159 } 160 161 template <typename T> void Vector3D<T>::RotateX(float value) { 135 162 float y_tmp; 136 163 y_tmp = y * cosf(value) - z * sinf(value); … … 139 166 } 140 167 141 void Vector3D::RotateXDeg(float value) { RotateX(Euler::ToRadian(value)); }142 143 void Vector3D::RotateY(float value) {168 template <typename T> void Vector3D<T>::RotateXDeg(float value) { RotateX(Euler::ToRadian(value)); } 169 170 template <typename T> void Vector3D<T>::RotateY(float value) { 144 171 float x_tmp; 145 172 x_tmp = x * cosf(value) + z * sinf(value); … … 148 175 } 149 176 150 void Vector3D::RotateYDeg(float value) { RotateY(Euler::ToRadian(value)); }151 152 void Vector3D::RotateZ(float value) {177 template <typename T> void Vector3D<T>::RotateYDeg(float value) { RotateY(Euler::ToRadian(value)); } 178 179 template <typename T> void Vector3D<T>::RotateZ(float value) { 153 180 float x_tmp; 154 181 x_tmp = x * cosf(value) - y * sinf(value); … … 157 184 } 158 185 159 void Vector3D::RotateZDeg(float value) { RotateZ(Euler::ToRadian(value)); }160 161 void Vector3D::Rotate(const RotationMatrix &matrix) {162 floata[3] = {0, 0, 0};163 floatb[3] = {x, y, z};186 template <typename T> void Vector3D<T>::RotateZDeg(float value) { RotateZ(Euler::ToRadian(value)); } 187 188 template <typename T> void Vector3D<T>::Rotate(const RotationMatrix &matrix) { 189 T a[3] = {0, 0, 0}; 190 T b[3] = {x, y, z}; 164 191 165 192 for (int i = 0; i < 3; i++) { … … 174 201 } 175 202 176 void Vector3D::Rotate(const Quaternion &quaternion) {203 template <typename T> void Vector3D<T>::Rotate(const Quaternion &quaternion) { 177 204 RotationMatrix matrix; 178 205 quaternion.ToRotationMatrix(matrix); … … 180 207 } 181 208 182 void Vector3D::To2Dxy(Vector2D&vector) const {209 template <typename T> void Vector3D<T>::To2Dxy(Vector2D<T> &vector) const { 183 210 vector.x = x; 184 211 vector.y = y; 185 212 } 186 213 187 Vector2D Vector3D::To2Dxy(void) const {188 Vector2D vect;214 template <typename T> Vector2D<T> Vector3D<T>::To2Dxy(void) const { 215 Vector2D<T> vect; 189 216 To2Dxy(vect); 190 217 return vect; 191 218 } 192 219 193 float Vector3D::GetNorm(void) const { return sqrt(x * x + y * y + z * z); }194 195 void Vector3D::Normalize(void) {220 template <typename T> float Vector3D<T>::GetNorm(void) const { return sqrt(x * x + y * y + z * z); } 221 222 template <typename T> void Vector3D<T>::Normalize(void) { 196 223 float n = GetNorm(); 197 224 if (n != 0) { … … 202 229 } 203 230 204 void Vector3D::Saturate(const Vector3D &min, const Vector3D&max) {231 template <typename T> void Vector3D<T>::Saturate(const Vector3D<T> &min, const Vector3D<T> &max) { 205 232 if (x < min.x) 206 233 x = min.x; … … 219 246 } 220 247 221 void Vector3D::Saturate(float min, float max) {222 Saturate(Vector3D (min, min, min), Vector3D(max, max, max));223 } 224 225 void Vector3D::Saturate(const Vector3D&value) {248 template <typename T> void Vector3D<T>::Saturate(float min, float max) { 249 Saturate(Vector3D<T>(min, min, min), Vector3D<T>(max, max, max)); 250 } 251 252 template <typename T> void Vector3D<T>::Saturate(const Vector3D<T> &value) { 226 253 float x = fabs(value.x); 227 254 float y = fabs(value.y); 228 255 float z = fabs(value.z); 229 Saturate(Vector3D (-x, -y, -z), Vector3D(x, y, z));230 } 231 232 void Vector3D::Saturate(float value) {256 Saturate(Vector3D<T>(-x, -y, -z), Vector3D<T>(x, y, z)); 257 } 258 259 template <typename T> void Vector3D<T>::Saturate(float value) { 233 260 float sat = fabs(value); 234 Saturate(Vector3D (-sat, -sat, -sat), Vector3D(sat, sat, sat));261 Saturate(Vector3D<T>(-sat, -sat, -sat), Vector3D<T>(sat, sat, sat)); 235 262 } 236 263 -
trunk/lib/FlairCore/src/Vector3D.h
r15 r167 15 15 16 16 #include <stddef.h> 17 #include <Vector2D.h> 17 18 18 19 namespace flair { 19 20 namespace core { 20 class Vector2D;21 21 class RotationMatrix; 22 22 class Quaternion; … … 26 26 * \brief Class defining a 3D vector 27 27 */ 28 template <typename T> 28 29 class Vector3D { 29 30 public: … … 37 38 * \param z 38 39 */ 39 Vector3D( float x = 0, float y = 0, floatz = 0);40 Vector3D(T x = 0, T y = 0, T z = 0); 40 41 41 42 /*! … … 48 49 * \brief x 49 50 */ 50 floatx;51 T x; 51 52 52 53 /*! 53 54 * \brief y 54 55 */ 55 floaty;56 T y; 56 57 57 58 /*! 58 59 * \brief z 59 60 */ 60 floatz;61 T z; 61 62 62 63 /*! … … 126 127 * \param vector destination 127 128 */ 128 void To2Dxy(Vector2D &vector) const;129 void To2Dxy(Vector2D<T> &vector) const; 129 130 130 131 /*! … … 135 136 * \return destination 136 137 */ 137 Vector2D To2Dxy(void) const;138 Vector2D<T> To2Dxy(void) const; 138 139 139 140 /*! … … 157 158 * \param max maximum value 158 159 */ 159 void Saturate(const Vector3D &min, const Vector3D&max);160 void Saturate(const Vector3D<T> &min, const Vector3D<T> &max); 160 161 161 162 /*! … … 176 177 * \param value saturation Vector3D value 177 178 */ 178 void Saturate(const Vector3D &value);179 void Saturate(const Vector3D<T> &value); 179 180 180 181 /*! … … 188 189 void Saturate(float value); 189 190 190 float &operator[](size_t idx); 191 const float &operator[](size_t idx) const; 192 Vector3D &operator=(const Vector3D &vector); 193 Vector3D &operator+=(const Vector3D &vector); 194 Vector3D &operator-=(const Vector3D &vector); 191 T &operator[](size_t idx); 192 const T &operator[](size_t idx) const; 193 //Vector3D<T> &operator=(const Vector3D<T> &vector); 194 template<typename S> Vector3D<T> &operator=(const Vector3D<S> &vector) { 195 x = vector.x; 196 y = vector.y; 197 z = vector.z; 198 return (*this); 199 } 200 Vector3D<T> &operator+=(const Vector3D<T> &vector); 201 Vector3D<T> &operator-=(const Vector3D<T> &vector); 195 202 196 203 private: 197 204 }; 198 205 206 typedef Vector3D<float> Vector3Df; 207 199 208 /*! Add 200 209 * … … 206 215 * \return vectorA+vectorB 207 216 */ 208 Vector3D operator+(const Vector3D &vectorA, const Vector3D&vectorB);217 template<typename T> Vector3D<T> operator+(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB); 209 218 210 219 /*! Substract … … 217 226 * \return vectorA-vectorB 218 227 */ 219 Vector3D operator-(const Vector3D &vectorA, const Vector3D&vectorB);228 template<typename T> Vector3D<T> operator-(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB); 220 229 221 230 /*! Minus … … 227 236 * \return -vector 228 237 */ 229 Vector3D operator-(const Vector3D&vector);238 template<typename T> Vector3D<T> operator-(const Vector3D<T> &vector); 230 239 231 240 /*! Divid … … 238 247 * \return vector/coefficient 239 248 */ 240 Vector3D operator/(const Vector3D&vector, float coeff);249 template<typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff); 241 250 242 251 /*! Hadamard product … … 249 258 * \return Hadamard product 250 259 */ 251 Vector3D operator*(const Vector3D &vectorA, const Vector3D&vectorB);260 template<typename T> Vector3D<T> operator*(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB); 252 261 253 262 /*! Multiply … … 260 269 * \return coefficient*vector 261 270 */ 262 Vector3D operator*(const Vector3D&vector, float coeff);271 template<typename T> Vector3D<T> operator*(const Vector3D<T> &vector, float coeff); 263 272 264 273 /*! Multiply … … 271 280 * \return coefficient*vector 272 281 */ 273 Vector3D operator*(float coeff, const Vector3D&vector);282 template<typename T> Vector3D<T> operator*(float coeff, const Vector3D<T> &vector); 274 283 275 284 /*! Cross product … … 282 291 * \return cross product 283 292 */ 284 Vector3D CrossProduct(const Vector3D &vectorA, const Vector3D&vectorB);293 template<typename T> Vector3D<T> CrossProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB); 285 294 286 295 /*! Dot product … … 293 302 * \return dot product 294 303 */ 295 float DotProduct(const Vector3D &vectorA, const Vector3D&vectorB);304 template<typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB); 296 305 297 306 } // end namespace core -
trunk/lib/FlairCore/src/Vector3DSpinBox.cpp
r15 r167 26 26 Vector3DSpinBox::Vector3DSpinBox(const LayoutPosition *position, string name, 27 27 double min, double max, double step, 28 int decimals, core::Vector3D default_value)28 int decimals, core::Vector3Df default_value) 29 29 : Box(position, name, "Vector3DSpinBox") { 30 30 // update value from xml file … … 52 52 } 53 53 */ 54 core::Vector3D Vector3DSpinBox::Value(void) const {55 core::Vector3D tmp;54 core::Vector3Df Vector3DSpinBox::Value(void) const { 55 core::Vector3Df tmp; 56 56 57 57 GetMutex(); -
trunk/lib/FlairCore/src/Vector3DSpinBox.h
r15 r167 44 44 Vector3DSpinBox(const LayoutPosition *position, std::string name, double min, 45 45 double max, double step, int decimals = 2, 46 core::Vector3D default_value = core::Vector3D(0, 0, 0));46 core::Vector3Df default_value = core::Vector3Df(0, 0, 0)); 47 47 48 48 /*! … … 57 57 * \return value 58 58 */ 59 core::Vector3D Value(void) const;59 core::Vector3Df Value(void) const; 60 60 // operator core::Vector3D() const; 61 61 private: … … 68 68 void XmlEvent(void); 69 69 70 core::Vector3D box_value;70 core::Vector3Df box_value; 71 71 }; 72 72 -
trunk/lib/FlairCore/src/Vector3Ddata.h
r15 r167 26 26 * User must manually use the io_data's Mutex to access to Vector3D values. 27 27 */ 28 class Vector3Ddata : public io_data, public Vector3D {28 class Vector3Ddata : public io_data, public Vector3Df { 29 29 public: 30 30 /*! -
trunk/lib/FlairCore/src/unexported/OneAxisRotation_impl.h
r144 r167 14 14 #define ONEAXISROTATION_IMPL_H 15 15 16 #include <Vector3D.h> 17 16 18 namespace flair { 17 19 namespace core { 18 class Vector3D;19 20 class Euler; 20 21 class Quaternion; … … 36 37 OneAxisRotation_impl(flair::gui::GroupBox *box); 37 38 ~OneAxisRotation_impl(); 38 void ComputeRotation(flair::core::Vector3D&point) const;39 template <typename T> void ComputeRotation(flair::core::Vector3D<T> &point) const; 39 40 void ComputeRotation(flair::core::Quaternion &quat) const; 40 41 void ComputeRotation(flair::core::RotationMatrix &matrix) const;
Note:
See TracChangeset
for help on using the changeset viewer.