Go to the documentation of this file.00001
00059 #pragma once
00060
00061 #include <eigen3/Eigen/Dense>
00062
00064 namespace DOF6
00065 {
00066
00067
00068 template<typename TYPE>
00069 class Translation
00070 {
00071 typedef Eigen::Matrix<TYPE,3,3> Matrix;
00072 typedef Eigen::Matrix<TYPE,3,1> Vector;
00073 typedef Eigen::Matrix<TYPE,2,1> Vector2;
00075 typedef Eigen::EigenSolver<Matrix> EigenSolver;
00076
00077 Matrix variance_;
00078 Matrix axis_;
00079 Vector var_;
00080 #ifdef DEBUG_
00081 bool initialized_;
00082 #endif
00083
00084 public:
00085 RotationAxis()
00086 #ifdef DEBUG_
00087 :initialized_(false)
00088 #endif
00089 {
00090 axis_.fill(0);
00091 }
00092 RotationAxis(const Vector &n_old, const Vector &n_new, const Vector &var)
00093 #ifdef DEBUG_
00094 :initialized_(false)
00095 #endif
00096 {
00097 set(n_old,n_new,var);
00098 }
00099
00100 void set(const Vector &n_old, const Vector &n_new, const Vector &var) {
00101 #ifdef DEBUG_
00102 initialized_ = false;
00103 #endif
00104 Matrix V,Q;
00105 Vector v,u,w;
00106
00107
00108 V.fill(0);
00109 V(0,0) = var(0);
00110 V(1,1) = var(1);
00111 V(2,2) = var(2);
00112
00113
00114 v=n_new-n_old;
00115 u=n_old+v/2;
00116 w=v.cross(u);
00117
00118 v.normalize();
00119 u.normalize();
00120 w.normalize();
00121
00122 variance_.col(0)=v;
00123 variance_.col(1)=u;
00124 variance_.col(2)=w;
00125
00126
00127 variance_ = variance_*V*variance_.inverse();
00128 }
00129
00135 void operator+=(const RotationAxis &r)
00136 {
00137 #ifdef DEBUG_
00138 initialized_ = false;
00139 #endif
00140 translation_ = translation_ + variance_*(variance_+r.variance_).inverse()*(r.translation-translation);
00141 variance_ = variance_ - variance_*(variance_+r.variance_).inverse()*variance_;
00142 }
00143
00150 void calc() {
00151 EigenSolver solver(variance_);
00152
00153
00154
00155
00156
00157
00158 var_ = solver.eigenvalues().real();
00159 axis_= solver.eigenvectors().real();
00160
00161 #ifdef DEBUG_
00162 initialized_ = true;
00163 #endif
00164 }
00165
00166 inline const Matrix &getRotationAxis() const {
00167 #ifdef DEBUG_
00168 ROS_ASSERT(initialized_);
00169 #endif
00170 return axis_;
00171 }
00172
00173 int getMainAxis() const {
00174 if(var_(0)>var_(1) && var_(0)>var_(2))
00175 return 0;
00176 else if(var_(1)>var_(2))
00177 return 1;
00178 return 2;
00179 }
00180 };
00181
00182 typedef Translation<float> Translationf;
00183 typedef Translation<double> Translationd;
00184
00185 #include "impl/translation.hpp"
00186
00187 }