Changeset 167 in flair-src for trunk/lib/FlairCore


Ignore:
Timestamp:
Apr 12, 2017, 1:59:38 PM (4 years ago)
Author:
Sanahuja Guillaume
Message:

modifs pour template vectors

Location:
trunk/lib/FlairCore/src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/AhrsData.cpp

    r15 r167  
    4343  void CopyData(char *destination) const {
    4444    float data;
    45     Vector3D angularRates;
     45    Vector3Df angularRates;
    4646    Euler eulerAngles;
    4747    Quaternion quaternion;
     
    138138}
    139139
    140 Vector3D AhrsData::GetAngularRates(void) const {
    141   Vector3D out;
     140Vector3Df AhrsData::GetAngularRates(void) const {
     141  Vector3Df out;
    142142  GetMutex();
    143143  out = angularRates;
     
    147147
    148148void AhrsData::GetQuaternionAndAngularRates(Quaternion &outQuaternion,
    149                                             Vector3D &outAngularRates) const {
     149                                            Vector3Df &outAngularRates) const {
    150150  GetMutex();
    151151  outQuaternion = quaternion;
     
    155155
    156156void AhrsData::SetQuaternionAndAngularRates(const Quaternion &inQuaternion,
    157                                             const Vector3D &inAngularRates) {
     157                                            const Vector3Df &inAngularRates) {
    158158  GetMutex();
    159159  quaternion = inQuaternion;
     
    168168}
    169169
    170 void AhrsData::SetAngularRates(const Vector3D &inAngularRates) {
     170void AhrsData::SetAngularRates(const Vector3Df &inAngularRates) {
    171171  GetMutex();
    172172  angularRates = inAngularRates;
  • trunk/lib/FlairCore/src/AhrsData.h

    r15 r167  
    121121  *
    122122  */
    123   void SetAngularRates(const Vector3D &angularRates);
     123  void SetAngularRates(const Vector3Df &angularRates);
    124124
    125125  /*!
     
    131131  *
    132132  */
    133   Vector3D GetAngularRates(void) const;
     133  Vector3Df GetAngularRates(void) const;
    134134
    135135  /*!
     
    143143  */
    144144  void GetQuaternionAndAngularRates(Quaternion &quaternion,
    145                                     Vector3D &angularRates) const;
     145                                    Vector3Df &angularRates) const;
    146146
    147147  /*!
     
    155155  */
    156156  void SetQuaternionAndAngularRates(const Quaternion &quaternion,
    157                                     const Vector3D &angularRates);
     157                                    const Vector3Df &angularRates);
    158158
    159159  const Type &GetDataType() const { return dataType; }
     
    182182  *
    183183  */
    184   Vector3D angularRates;
     184  Vector3Df angularRates;
    185185
    186186  Type dataType;
  • trunk/lib/FlairCore/src/GpsData.h

    r51 r167  
    1919
    2020  class IODataElement;
    21   class Vector3D;
    2221
    2322/*! \class GpsData
  • trunk/lib/FlairCore/src/ImuData.cpp

    r15 r167  
    4444  void CopyData(char *dst) const {
    4545    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();
    4949    switch (plotableData) {
    5050    case ImuData::RawAx:
     
    121121ImuData::~ImuData() {}
    122122
    123 Vector3D ImuData::GetRawAcc(void) const {
    124   Vector3D out;
     123Vector3Df ImuData::GetRawAcc(void) const {
     124  Vector3Df out;
    125125  GetMutex();
    126126  out = rawAcc;
     
    129129}
    130130
    131 Vector3D ImuData::GetRawMag(void) const {
    132   Vector3D out;
     131Vector3Df ImuData::GetRawMag(void) const {
     132  Vector3Df out;
    133133  GetMutex();
    134134  out = rawMag;
     
    137137}
    138138
    139 Vector3D ImuData::GetRawGyr(void) const {
    140   Vector3D out;
     139Vector3Df ImuData::GetRawGyr(void) const {
     140  Vector3Df out;
    141141  GetMutex();
    142142  out = rawGyr;
     
    145145}
    146146
    147 void ImuData::GetRawAccMagAndGyr(Vector3D &inRawAcc, Vector3D &inRawMag,
    148                                  Vector3D &inRawGyr) const {
     147void ImuData::GetRawAccMagAndGyr(Vector3Df &inRawAcc, Vector3Df &inRawMag,
     148                                 Vector3Df &inRawGyr) const {
    149149  GetMutex();
    150150  inRawAcc = rawAcc;
     
    154154}
    155155
    156 void ImuData::SetRawAcc(const Vector3D &inRawAcc) {
     156void ImuData::SetRawAcc(const Vector3Df &inRawAcc) {
    157157  GetMutex();
    158158  rawAcc = inRawAcc;
     
    160160}
    161161
    162 void ImuData::SetRawMag(const Vector3D &inRawMag) {
     162void ImuData::SetRawMag(const Vector3Df &inRawMag) {
    163163  GetMutex();
    164164  rawMag = inRawMag;
     
    166166}
    167167
    168 void ImuData::SetRawGyr(const Vector3D &inRawGyr) {
     168void ImuData::SetRawGyr(const Vector3Df &inRawGyr) {
    169169  GetMutex();
    170170  rawGyr = inRawGyr;
     
    172172}
    173173
    174 void ImuData::SetRawAccMagAndGyr(const Vector3D &inRawAcc,
    175                                  const Vector3D &inRawMag,
    176                                  const Vector3D &inRawGyr) {
     174void ImuData::SetRawAccMagAndGyr(const Vector3Df &inRawAcc,
     175                                 const Vector3Df &inRawMag,
     176                                 const Vector3Df &inRawGyr) {
    177177  GetMutex();
    178178  rawAcc = inRawAcc;
  • trunk/lib/FlairCore/src/ImuData.h

    r15 r167  
    104104  *
    105105  */
    106   Vector3D GetRawAcc(void) const;
     106  Vector3Df GetRawAcc(void) const;
    107107
    108108  /*!
     
    114114  *
    115115  */
    116   Vector3D GetRawMag(void) const;
     116  Vector3Df GetRawMag(void) const;
    117117
    118118  /*!
     
    124124  *
    125125  */
    126   Vector3D GetRawGyr(void) const;
     126  Vector3Df GetRawGyr(void) const;
    127127
    128128  /*!
     
    136136  *
    137137  */
    138   void GetRawAccMagAndGyr(Vector3D &rawAcc, Vector3D &rawMag,
    139                           Vector3D &rawGyr) const;
     138  void GetRawAccMagAndGyr(Vector3Df &rawAcc, Vector3Df &rawMag,
     139                          Vector3Df &rawGyr) const;
    140140
    141141  /*!
     
    147147  *
    148148  */
    149   void SetRawAcc(const Vector3D &rawAcc);
     149  void SetRawAcc(const Vector3Df &rawAcc);
    150150
    151151  /*!
     
    157157  *
    158158  */
    159   void SetRawMag(const Vector3D &rawMag);
     159  void SetRawMag(const Vector3Df &rawMag);
    160160
    161161  /*!
     
    167167  *
    168168  */
    169   void SetRawGyr(const Vector3D &rawGyr);
     169  void SetRawGyr(const Vector3Df &rawGyr);
    170170
    171171  /*!
     
    179179  *
    180180  */
    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);
    183183
    184184  Type const &GetDataType() const { return dataType; }
     
    199199  *
    200200  */
    201   Vector3D rawAcc;
     201  Vector3Df rawAcc;
    202202
    203203  /*!
     
    205205  *
    206206  */
    207   Vector3D rawGyr;
     207  Vector3Df rawGyr;
    208208
    209209  /*!
     
    211211  *
    212212  */
    213   Vector3D rawMag;
     213  Vector3Df rawMag;
    214214
    215215  void Queue(char **dst, const void *src, size_t size) const;
  • trunk/lib/FlairCore/src/OneAxisRotation.cpp

    r147 r167  
    2424#include "OneAxisRotation.h"
    2525#include "OneAxisRotation_impl.h"
    26 #include <Vector3D.h>
    2726#include <Euler.h>
    2827
     
    3231namespace core {
    3332
     33template void OneAxisRotation::ComputeRotation(core::Vector3D<float> &) const;
     34template void OneAxisRotation::ComputeRotation(core::Vector3D<double> &) const;
     35 
    3436OneAxisRotation::OneAxisRotation(const gui::LayoutPosition *position,
    3537                                 string name)
     
    4042OneAxisRotation::~OneAxisRotation() { delete pimpl_; }
    4143
    42 void OneAxisRotation::ComputeRotation(Vector3D &vector) const {
     44template <typename T> void OneAxisRotation::ComputeRotation(Vector3D<T> &vector) const {
    4345  pimpl_->ComputeRotation(vector);
    4446}
  • trunk/lib/FlairCore/src/OneAxisRotation.h

    r147 r167  
    1515
    1616#include <GroupBox.h>
     17#include <Vector3D.h>
    1718
    1819class OneAxisRotation_impl;
     
    2425
    2526namespace core {
    26 class Vector3D;
    2727class Euler;
    2828class Quaternion;
     
    5757  * \brief Compute rotation
    5858  *
    59   * \param vector Vector3D to rotate
     59  * \param vector Vector3Df to rotate
    6060  */
    61   void ComputeRotation(core::Vector3D &vector) const;
     61  template <typename T> void ComputeRotation(core::Vector3D<T> &vector) const;
    6262
    6363  /*!
  • trunk/lib/FlairCore/src/OneAxisRotation_impl.cpp

    r144 r167  
    2020#include "ComboBox.h"
    2121#include "DoubleSpinBox.h"
    22 #include <Vector3D.h>
    2322#include <Euler.h>
    2423#include <Quaternion.h>
     
    2726using namespace flair::core;
    2827using namespace flair::gui;
     28
     29template void OneAxisRotation_impl::ComputeRotation(Vector3D<float>&) const;
     30template void OneAxisRotation_impl::ComputeRotation(Vector3D<double>&) const;
    2931
    3032OneAxisRotation_impl::OneAxisRotation_impl(GroupBox *box) {
     
    4143// compute rotation of each axis through ComputeRotation(Vector3D& vector)
    4244void 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);
    4446  ComputeRotation(rot);
    4547  quat.q1 = rot.x;
     
    5456// on utilise la rotation d'un vector pour faire une rotation de repere
    5557// d'ou le signe negatif
    56 void OneAxisRotation_impl::ComputeRotation(Vector3D &vector) const {
     58template <typename T> void OneAxisRotation_impl::ComputeRotation(Vector3D<T> &vector) const {
    5759  switch (rot_axe->CurrentIndex()) {
    5860  case 0:
  • trunk/lib/FlairCore/src/Quaternion.cpp

    r161 r167  
    1717
    1818#include "Quaternion.h"
    19 #include "Vector3D.h"
    2019#include "Euler.h"
    2120#include "RotationMatrix.h"
     
    6362}
    6463
    65 void Quaternion::GetLogarithm(Vector3D &logarithm) {
     64void Quaternion::GetLogarithm(Vector3Df &logarithm) {
    6665  Normalize();
    6766  float v_norm = sqrtf(q1 * q1 + q2 * q2 + q3 * q3);
     
    7978}
    8079
    81 Vector3D Quaternion::GetLogarithm(void) {
    82   Vector3D vector;
     80Vector3Df Quaternion::GetLogarithm(void) {
     81  Vector3Df vector;
    8382  GetLogarithm(vector);
    8483  return vector;
    8584}
    8685
    87 Quaternion Quaternion::GetDerivative(const Vector3D &angularSpeed) const {
     86Quaternion Quaternion::GetDerivative(const Vector3Df &angularSpeed) const {
    8887  const Quaternion Qw(0, angularSpeed.x, angularSpeed.y, angularSpeed.z);
    8988  return 0.5 * (*this) * Qw;
    9089}
    9190
    92 void Quaternion::Derivate(const Vector3D &angularSpeed) {
     91void Quaternion::Derivate(const Vector3Df &angularSpeed) {
    9392  Quaternion Q = GetDerivative(angularSpeed);
    9493  (*this) = Q;
  • trunk/lib/FlairCore/src/Quaternion.h

    r15 r167  
    1313#define QUATERNION_H
    1414
     15#include <Vector3D.h>
     16
    1517namespace flair {
    1618namespace core {
    1719class Euler;
    18 class Vector3D;
    1920class RotationMatrix;
    2021
     
    6263  * \param logarithm output logarithm
    6364  */
    64   void GetLogarithm(Vector3D &logarithm);
     65  void GetLogarithm(Vector3Df &logarithm);
    6566
    6667  /*!
     
    7172  * \return output logarithm
    7273  */
    73   Vector3D GetLogarithm(void);
     74  Vector3Df GetLogarithm(void);
    7475
    7576  /*!
     
    9293  * \return derivative
    9394  */
    94   Quaternion GetDerivative(const Vector3D &angularSpeed) const;
     95  Quaternion GetDerivative(const Vector3Df &angularSpeed) const;
    9596
    9697  /*!
     
    99100  * \param w rotationonal speed
    100101  */
    101   void Derivate(const Vector3D &angularSpeed);
     102  void Derivate(const Vector3Df &angularSpeed);
    102103
    103104  /*!
  • trunk/lib/FlairCore/src/Vector2D.cpp

    r161 r167  
    2222namespace flair {
    2323namespace core {
     24 
     25template class Vector2D<double>;
     26template Vector2D<double> operator+(const Vector2D<double>&, const Vector2D<double>&);
     27template Vector2D<double> operator-(const Vector2D<double>&, const Vector2D<double>&);
     28template Vector2D<double> operator-(const Vector2D<double>&);
     29template Vector2D<double> operator/(const Vector2D<double>&, float);
     30template Vector2D<double> operator*(const Vector2D<double>&, float);
     31template Vector2D<double> operator*(float, const Vector2D<double>&);
    2432
    25 Vector2D::Vector2D(float inX, float inY) : x(inX), y(inY) {}
     33template class Vector2D<float>;
     34template Vector2D<float> operator+(const Vector2D<float>&, const Vector2D<float>&);
     35template Vector2D<float> operator-(const Vector2D<float>&, const Vector2D<float>&);
     36template Vector2D<float> operator-(const Vector2D<float>&);
     37template Vector2D<float> operator/(const Vector2D<float>&, float);
     38template Vector2D<float> operator*(const Vector2D<float>&, float);
     39template Vector2D<float> operator*(float, const Vector2D<float>&);
    2640
    27 Vector2D::~Vector2D() {}
     41template <typename T> Vector2D<T>::Vector2D(T inX, T inY) : x(inX), y(inY) {}
    2842
    29 Vector2D &Vector2D::operator=(const Vector2D &vector) {
    30   x = vector.x;
    31   y = vector.y;
    32   return (*this);
    33 }
     43template <typename T> Vector2D<T>::~Vector2D() {}
    3444
    35 Vector2D &Vector2D::operator+=(const Vector2D &vector) {
     45template <typename T> Vector2D<T> &Vector2D<T>::operator+=(const Vector2D<T> &vector) {
    3646  x += vector.x;
    3747  y += vector.y;
     
    3949}
    4050
    41 Vector2D &Vector2D::operator-=(const Vector2D &vector) {
     51template <typename T> Vector2D<T> &Vector2D<T>::operator-=(const Vector2D<T> &vector) {
    4252  x -= vector.x;
    4353  y -= vector.y;
     
    4555}
    4656
    47 Vector2D operator+(const Vector2D &vectorA, const Vector2D &vectorB) {
    48   return Vector2D(vectorA.x + vectorB.x, vectorA.y + vectorB.y);
     57template <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);
    4959}
    5060
    51 Vector2D operator-(const Vector2D &vectorA, const Vector2D &vectorB) {
    52   return Vector2D(vectorA.x - vectorB.x, vectorA.y - vectorB.y);
     61template <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);
    5363}
    5464
    55 Vector2D operator-(const Vector2D &vectorA) {
    56  return Vector2D(-vectorA.x, -vectorA.y);
     65template <typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA) {
     66 return Vector2D<T>(-vectorA.x, -vectorA.y);
    5767}
    5868
    59 Vector2D operator/(const Vector2D &vector, float coeff) {
     69template <typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff) {
    6070  if (coeff != 0) {
    61     return Vector2D(vector.x / coeff, vector.y / coeff);
     71    return Vector2D<T>(vector.x / coeff, vector.y / coeff);
    6272  } else {
    63     return Vector2D(0, 0);
     73    return Vector2D<T>(0, 0);
    6474  }
    6575}
    6676
    67 Vector2D operator*(const Vector2D &vector, float coeff) {
    68   return Vector2D(vector.x * coeff, vector.y * coeff);
     77template <typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff) {
     78  return Vector2D<T>(vector.x * coeff, vector.y * coeff);
    6979}
    7080
    71 Vector2D operator*(float coeff, const Vector2D &vector) {
    72   return Vector2D(vector.x * coeff, vector.y * coeff);
     81template <typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector) {
     82  return Vector2D<T>(vector.x * coeff, vector.y * coeff);
    7383}
    7484
    75 void Vector2D::Rotate(float value) {
     85template <typename T> void Vector2D<T>::Rotate(float value) {
    7686  float xTmp;
    7787  xTmp = x * cosf(value) - y * sinf(value);
     
    8090}
    8191
    82 void Vector2D::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }
     92template <typename T> void Vector2D<T>::RotateDeg(float value) { Rotate(Euler::ToRadian(value)); }
    8393
    84 float Vector2D::GetNorm(void) const { return sqrt(x * x + y * y); }
     94template <typename T> float Vector2D<T>::GetNorm(void) const { return sqrt(x * x + y * y); }
    8595
    86 void Vector2D::Normalize(void) {
     96template <typename T> void Vector2D<T>::Normalize(void) {
    8797  float n = GetNorm();
    8898  if (n != 0) {
     
    92102}
    93103
    94 void Vector2D::Saturate(Vector2D min, Vector2D max) {
     104template <typename T> void Vector2D<T>::Saturate(Vector2D min, Vector2D max) {
    95105  if (x < min.x)
    96106    x = min.x;
     
    104114}
    105115
    106 void Vector2D::Saturate(float min, float max) {
     116template <typename T> void Vector2D<T>::Saturate(float min, float max) {
    107117  Saturate(Vector2D(min, min), Vector2D(max, max));
    108118}
    109119
    110 void Vector2D::Saturate(const Vector2D &value) {
     120template <typename T> void Vector2D<T>::Saturate(const Vector2D &value) {
    111121  float x = fabs(value.x);
    112122  float y = fabs(value.y);
     
    114124}
    115125
    116 void Vector2D::Saturate(float value) {
     126template <typename T> void Vector2D<T>::Saturate(float value) {
    117127  float sat = fabs(value);
    118128  Saturate(Vector2D(-sat, -sat), Vector2D(sat, sat));
  • trunk/lib/FlairCore/src/Vector2D.h

    r161 r167  
    2121* \brief Class defining a 2D vector
    2222*/
     23template <typename T>
    2324class Vector2D {
    2425public:
     
    3132  * \param y
    3233  */
    33   Vector2D(float x = 0, float y = 0);
     34  Vector2D(T x = 0, T y = 0);
    3435
    3536  /*!
     
    7374  * \param max maximum Vector2D value
    7475  */
    75   void Saturate(Vector2D min, Vector2D max);
     76  void Saturate(Vector2D<T> min, Vector2D<T> max);
    7677
    7778  /*!
     
    9293  * \param value saturation Vector2D value
    9394  */
    94   void Saturate(const Vector2D &value);
     95  void Saturate(const Vector2D<T> &value);
    9596
    9697  /*!
     
    106107  * \brief x
    107108  */
    108   float x;
     109  T x;
    109110
    110111  /*!
    111112  * \brief y
    112113  */
    113   float y;
     114  T y;
    114115
    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);
    118123};
     124
     125typedef Vector2D<float> Vector2Df;
    119126
    120127/*! Add
     
    125132* \param vectorB vector
    126133*/
    127 Vector2D operator+(const Vector2D &vectorA, const Vector2D &vectorB);
     134template<typename T> Vector2D<T> operator+(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB);
    128135
    129136/*! Substract
     
    134141* \param vectorB vector
    135142*/
    136 Vector2D operator-(const Vector2D &vectorA, const Vector2D &vectorB);
     143template<typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA, const Vector2D<T> &vectorB);
    137144
    138145/*! Opposite
     
    144151* \return -vectorA
    145152*/
    146 Vector2D operator-(const Vector2D &vectorA);
     153template<typename T> Vector2D<T> operator-(const Vector2D<T> &vectorA);
    147154
    148155/*! Divid
     
    154161* \return vector/coefficient
    155162*/
    156 Vector2D operator/(const Vector2D &vector, float coeff);
     163template<typename T> Vector2D<T> operator/(const Vector2D<T> &vector, float coeff);
    157164
    158165/*! Multiply
     
    164171* \return coefficient*vector
    165172*/
    166 Vector2D operator*(const Vector2D &vector, float coeff);
     173template<typename T> Vector2D<T> operator*(const Vector2D<T> &vector, float coeff);
    167174
    168175/*! Multiply
     
    174181* \return coefficient*vector
    175182*/
    176 Vector2D operator*(float coeff, const Vector2D &vector);
     183template<typename T> Vector2D<T> operator*(float coeff, const Vector2D<T> &vector);
    177184
    178185} // end namespace core
  • trunk/lib/FlairCore/src/Vector3D.cpp

    r15 r167  
    2323#include "Object.h"
    2424#include <math.h>
    25 //#include "Vector3DSpinBox.h"
    2625
    2726namespace flair {
    2827namespace core {
    29 
    30 Vector3D::Vector3D(float inX, float inY, float inZ) : x(inX), y(inY), z(inZ) {}
    31 
    32 Vector3D::~Vector3D() {}
     28 
     29template class Vector3D<double>;
     30template Vector3D<double> operator+(const Vector3D<double>&, const Vector3D<double>&);
     31template Vector3D<double> operator-(const Vector3D<double>&, const Vector3D<double>&);
     32template Vector3D<double> operator-(const Vector3D<double>&);
     33template Vector3D<double> operator/(const Vector3D<double>&, float);
     34template Vector3D<double> operator*(const Vector3D<double>&, const Vector3D<double>&);
     35template Vector3D<double> operator*(const Vector3D<double>&, float);
     36template Vector3D<double> operator*(float, const Vector3D<double>&);
     37template Vector3D<double> CrossProduct(const Vector3D<double>&, const Vector3D<double>&);
     38template float DotProduct(const Vector3D<double>&, const Vector3D<double>&);
     39
     40template class Vector3D<float>;
     41template Vector3D<float> operator+(const Vector3D<float>&, const Vector3D<float>&);
     42template Vector3D<float> operator-(const Vector3D<float>&, const Vector3D<float>&);
     43template Vector3D<float> operator-(const Vector3D<float>&);
     44template Vector3D<float> operator/(const Vector3D<float>&, float);
     45template Vector3D<float> operator*(const Vector3D<float>&, const Vector3D<float>&);
     46template Vector3D<float> operator*(const Vector3D<float>&, float);
     47template Vector3D<float> operator*(float, const Vector3D<float>&);
     48template Vector3D<float> CrossProduct(const Vector3D<float>&, const Vector3D<float>&);
     49template float DotProduct(const Vector3D<float>&, const Vector3D<float>&);
     50
     51template <typename T> Vector3D<T>::Vector3D(T inX, T inY, T inZ) {
     52  x=inX;
     53  y=inY;
     54  z=inZ;
     55}
     56
     57template <typename T> Vector3D<T>::~Vector3D() {}
     58
    3359/*
    3460void Vector3D::operator=(const gui::Vector3DSpinBox *vector) {
     
    3864    z=vect.z;
    3965}*/
    40 
    41 Vector3D &Vector3D::operator=(const Vector3D &vector) {
     66/*
     67template<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) {
    4269  x = vector.x;
    4370  y = vector.y;
     
    4572  return (*this);
    4673}
    47 
    48 Vector3D &Vector3D::operator+=(const Vector3D &vector) {
     74*/
     75template <typename T> Vector3D<T> &Vector3D<T>::operator+=(const Vector3D<T> &vector) {
    4976  x += vector.x;
    5077  y += vector.y;
     
    5380}
    5481
    55 Vector3D &Vector3D::operator-=(const Vector3D &vector) {
     82template <typename T> Vector3D<T> &Vector3D<T>::operator-=(const Vector3D<T> &vector) {
    5683  x -= vector.x;
    5784  y -= vector.y;
     
    6087}
    6188
    62 float &Vector3D::operator[](size_t idx) {
     89template <typename T> T &Vector3D<T>::operator[](size_t idx) {
    6390  if (idx == 0) {
    6491    return x;
     
    73100}
    74101
    75 const float &Vector3D::operator[](size_t idx) const {
     102template <typename T> const T &Vector3D<T>::operator[](size_t idx) const {
    76103  if (idx == 0) {
    77104    return x;
     
    86113}
    87114
    88 Vector3D CrossProduct(const Vector3D &vectorA, const Vector3D &vectorB) {
    89   return Vector3D(vectorA.y * vectorB.z - vectorA.z * vectorB.y,
     115template <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,
    90117                  vectorA.z * vectorB.x - vectorA.x * vectorB.z,
    91118                  vectorA.x * vectorB.y - vectorA.y * vectorB.x);
    92119}
    93120
    94 float DotProduct(const Vector3D &vectorA, const Vector3D &vectorB) {
     121template <typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB) {
    95122  return vectorA.x * vectorB.x + vectorA.y * vectorB.y + vectorA.z * vectorB.z;
    96123}
    97124
    98 Vector3D operator+(const Vector3D &vectorA, const Vector3D &vectorB) {
    99   return Vector3D(vectorA.x + vectorB.x, vectorA.y + vectorB.y,
     125template <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,
    100127                  vectorA.z + vectorB.z);
    101128}
    102129
    103 Vector3D operator-(const Vector3D &vectorA, const Vector3D &vectorB) {
    104   return Vector3D(vectorA.x - vectorB.x, vectorA.y - vectorB.y,
     130template <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,
    105132                  vectorA.z - vectorB.z);
    106133}
    107134
    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,
     135template <typename T> Vector3D<T> operator-(const Vector3D<T> &vector) {
     136  return Vector3D<T>(-vector.x, -vector.y, -vector.z);
     137}
     138
     139template <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,
    114141                  vectorA.z * vectorB.z);
    115142}
    116143
    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) {
     144template <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
     148template <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
     152template <typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff) {
    126153  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);
    128155  } else {
    129156    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
     161template <typename T> void Vector3D<T>::RotateX(float value) {
    135162  float y_tmp;
    136163  y_tmp = y * cosf(value) - z * sinf(value);
     
    139166}
    140167
    141 void Vector3D::RotateXDeg(float value) { RotateX(Euler::ToRadian(value)); }
    142 
    143 void Vector3D::RotateY(float value) {
     168template <typename T> void Vector3D<T>::RotateXDeg(float value) { RotateX(Euler::ToRadian(value)); }
     169
     170template <typename T> void Vector3D<T>::RotateY(float value) {
    144171  float x_tmp;
    145172  x_tmp = x * cosf(value) + z * sinf(value);
     
    148175}
    149176
    150 void Vector3D::RotateYDeg(float value) { RotateY(Euler::ToRadian(value)); }
    151 
    152 void Vector3D::RotateZ(float value) {
     177template <typename T> void Vector3D<T>::RotateYDeg(float value) { RotateY(Euler::ToRadian(value)); }
     178
     179template <typename T> void Vector3D<T>::RotateZ(float value) {
    153180  float x_tmp;
    154181  x_tmp = x * cosf(value) - y * sinf(value);
     
    157184}
    158185
    159 void Vector3D::RotateZDeg(float value) { RotateZ(Euler::ToRadian(value)); }
    160 
    161 void Vector3D::Rotate(const RotationMatrix &matrix) {
    162   float a[3] = {0, 0, 0};
    163   float b[3] = {x, y, z};
     186template <typename T> void Vector3D<T>::RotateZDeg(float value) { RotateZ(Euler::ToRadian(value)); }
     187
     188template <typename T> void Vector3D<T>::Rotate(const RotationMatrix &matrix) {
     189  T a[3] = {0, 0, 0};
     190  T b[3] = {x, y, z};
    164191
    165192  for (int i = 0; i < 3; i++) {
     
    174201}
    175202
    176 void Vector3D::Rotate(const Quaternion &quaternion) {
     203template <typename T> void Vector3D<T>::Rotate(const Quaternion &quaternion) {
    177204  RotationMatrix matrix;
    178205  quaternion.ToRotationMatrix(matrix);
     
    180207}
    181208
    182 void Vector3D::To2Dxy(Vector2D &vector) const {
     209template <typename T> void Vector3D<T>::To2Dxy(Vector2D<T> &vector) const {
    183210  vector.x = x;
    184211  vector.y = y;
    185212}
    186213
    187 Vector2D Vector3D::To2Dxy(void) const {
    188   Vector2D vect;
     214template <typename T> Vector2D<T> Vector3D<T>::To2Dxy(void) const {
     215  Vector2D<T> vect;
    189216  To2Dxy(vect);
    190217  return vect;
    191218}
    192219
    193 float Vector3D::GetNorm(void) const { return sqrt(x * x + y * y + z * z); }
    194 
    195 void Vector3D::Normalize(void) {
     220template <typename T> float Vector3D<T>::GetNorm(void) const { return sqrt(x * x + y * y + z * z); }
     221
     222template <typename T> void Vector3D<T>::Normalize(void) {
    196223  float n = GetNorm();
    197224  if (n != 0) {
     
    202229}
    203230
    204 void Vector3D::Saturate(const Vector3D &min, const Vector3D &max) {
     231template <typename T> void Vector3D<T>::Saturate(const Vector3D<T> &min, const Vector3D<T> &max) {
    205232  if (x < min.x)
    206233    x = min.x;
     
    219246}
    220247
    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) {
     248template <typename T> void Vector3D<T>::Saturate(float min, float max) {
     249  Saturate(Vector3D<T>(min, min, min), Vector3D<T>(max, max, max));
     250}
     251
     252template <typename T> void Vector3D<T>::Saturate(const Vector3D<T> &value) {
    226253  float x = fabs(value.x);
    227254  float y = fabs(value.y);
    228255  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
     259template <typename T> void Vector3D<T>::Saturate(float value) {
    233260  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));
    235262}
    236263
  • trunk/lib/FlairCore/src/Vector3D.h

    r15 r167  
    1515
    1616#include <stddef.h>
     17#include <Vector2D.h>
    1718
    1819namespace flair {
    1920namespace core {
    20 class Vector2D;
    2121class RotationMatrix;
    2222class Quaternion;
     
    2626* \brief Class defining a 3D vector
    2727*/
     28template <typename T>
    2829class Vector3D {
    2930public:
     
    3738  * \param z
    3839  */
    39   Vector3D(float x = 0, float y = 0, float z = 0);
     40  Vector3D(T x = 0, T y = 0, T z = 0);
    4041
    4142  /*!
     
    4849  * \brief x
    4950  */
    50   float x;
     51  T x;
    5152
    5253  /*!
    5354  * \brief y
    5455  */
    55   float y;
     56  T y;
    5657
    5758  /*!
    5859  * \brief z
    5960  */
    60   float z;
     61  T z;
    6162
    6263  /*!
     
    126127  * \param vector destination
    127128  */
    128   void To2Dxy(Vector2D &vector) const;
     129  void To2Dxy(Vector2D<T> &vector) const;
    129130
    130131  /*!
     
    135136  * \return destination
    136137  */
    137   Vector2D To2Dxy(void) const;
     138  Vector2D<T> To2Dxy(void) const;
    138139
    139140  /*!
     
    157158  * \param max maximum value
    158159  */
    159   void Saturate(const Vector3D &min, const Vector3D &max);
     160  void Saturate(const Vector3D<T> &min, const Vector3D<T> &max);
    160161
    161162  /*!
     
    176177  * \param value saturation Vector3D value
    177178  */
    178   void Saturate(const Vector3D &value);
     179  void Saturate(const Vector3D<T> &value);
    179180
    180181  /*!
     
    188189  void Saturate(float value);
    189190
    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);
    195202
    196203private:
    197204};
    198205
     206typedef Vector3D<float> Vector3Df;
     207
    199208/*! Add
    200209*
     
    206215* \return vectorA+vectorB
    207216*/
    208 Vector3D operator+(const Vector3D &vectorA, const Vector3D &vectorB);
     217template<typename T> Vector3D<T> operator+(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    209218
    210219/*! Substract
     
    217226* \return vectorA-vectorB
    218227*/
    219 Vector3D operator-(const Vector3D &vectorA, const Vector3D &vectorB);
     228template<typename T> Vector3D<T> operator-(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    220229
    221230/*! Minus
     
    227236* \return -vector
    228237*/
    229 Vector3D operator-(const Vector3D &vector);
     238template<typename T> Vector3D<T> operator-(const Vector3D<T> &vector);
    230239
    231240/*! Divid
     
    238247* \return vector/coefficient
    239248*/
    240 Vector3D operator/(const Vector3D &vector, float coeff);
     249template<typename T> Vector3D<T> operator/(const Vector3D<T> &vector, float coeff);
    241250
    242251/*! Hadamard product
     
    249258* \return Hadamard product
    250259*/
    251 Vector3D operator*(const Vector3D &vectorA, const Vector3D &vectorB);
     260template<typename T> Vector3D<T> operator*(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    252261
    253262/*! Multiply
     
    260269* \return coefficient*vector
    261270*/
    262 Vector3D operator*(const Vector3D &vector, float coeff);
     271template<typename T> Vector3D<T> operator*(const Vector3D<T> &vector, float coeff);
    263272
    264273/*! Multiply
     
    271280* \return coefficient*vector
    272281*/
    273 Vector3D operator*(float coeff, const Vector3D &vector);
     282template<typename T> Vector3D<T> operator*(float coeff, const Vector3D<T> &vector);
    274283
    275284/*! Cross product
     
    282291* \return cross product
    283292*/
    284 Vector3D CrossProduct(const Vector3D &vectorA, const Vector3D &vectorB);
     293template<typename T> Vector3D<T> CrossProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    285294
    286295/*! Dot product
     
    293302* \return dot product
    294303*/
    295 float DotProduct(const Vector3D &vectorA, const Vector3D &vectorB);
     304template<typename T> float DotProduct(const Vector3D<T> &vectorA, const Vector3D<T> &vectorB);
    296305
    297306} // end namespace core
  • trunk/lib/FlairCore/src/Vector3DSpinBox.cpp

    r15 r167  
    2626Vector3DSpinBox::Vector3DSpinBox(const LayoutPosition *position, string name,
    2727                                 double min, double max, double step,
    28                                  int decimals, core::Vector3D default_value)
     28                                 int decimals, core::Vector3Df default_value)
    2929    : Box(position, name, "Vector3DSpinBox") {
    3030  // update value from xml file
     
    5252}
    5353*/
    54 core::Vector3D Vector3DSpinBox::Value(void) const {
    55   core::Vector3D tmp;
     54core::Vector3Df Vector3DSpinBox::Value(void) const {
     55  core::Vector3Df tmp;
    5656
    5757  GetMutex();
  • trunk/lib/FlairCore/src/Vector3DSpinBox.h

    r15 r167  
    4444  Vector3DSpinBox(const LayoutPosition *position, std::string name, double min,
    4545                  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));
    4747
    4848  /*!
     
    5757  * \return value
    5858  */
    59   core::Vector3D Value(void) const;
     59  core::Vector3Df Value(void) const;
    6060  // operator core::Vector3D() const;
    6161private:
     
    6868  void XmlEvent(void);
    6969
    70   core::Vector3D box_value;
     70  core::Vector3Df box_value;
    7171};
    7272
  • trunk/lib/FlairCore/src/Vector3Ddata.h

    r15 r167  
    2626* User must manually use the io_data's Mutex to access to Vector3D values.
    2727*/
    28 class Vector3Ddata : public io_data, public Vector3D {
     28class Vector3Ddata : public io_data, public Vector3Df {
    2929public:
    3030  /*!
  • trunk/lib/FlairCore/src/unexported/OneAxisRotation_impl.h

    r144 r167  
    1414#define ONEAXISROTATION_IMPL_H
    1515
     16#include <Vector3D.h>
     17
    1618namespace flair {
    1719namespace core {
    18 class Vector3D;
    1920class Euler;
    2021class Quaternion;
     
    3637  OneAxisRotation_impl(flair::gui::GroupBox *box);
    3738  ~OneAxisRotation_impl();
    38   void ComputeRotation(flair::core::Vector3D &point) const;
     39  template <typename T> void ComputeRotation(flair::core::Vector3D<T> &point) const;
    3940  void ComputeRotation(flair::core::Quaternion &quat) const;
    4041  void ComputeRotation(flair::core::RotationMatrix &matrix) const;
Note: See TracChangeset for help on using the changeset viewer.