dof_variance.h
Go to the documentation of this file.
00001 
00059 /*
00060  * dof_variance.h
00061  *
00062  *  Created on: 27.05.2012
00063  *      Author: josh
00064  */
00065 
00066 #ifndef DOF_VARIANCE_H_
00067 #define DOF_VARIANCE_H_
00068 
00069 #include "euler.h"
00070 #include <ros/time.h>
00071 
00073 namespace DOF6
00074 {
00075 
00079   template <typename _SOURCE1, typename _SOURCE2>
00080   class DOF6_Source
00081   {
00082   public:
00083     typedef _SOURCE1 SOURCE1;
00084     typedef _SOURCE2 SOURCE2;
00085     typedef typename SOURCE1::TYPE TYPE;
00086     typedef Eigen::Matrix<TYPE,3,1> Vector;
00087     typedef boost::shared_ptr<SOURCE1> Source1_Ptr;
00088     typedef boost::shared_ptr<SOURCE2> Source2_Ptr;
00089     typedef boost::shared_ptr<const SOURCE1> Source1_ConstPtr;
00090     typedef boost::shared_ptr<const SOURCE2> Source2_ConstPtr;
00091     typedef EulerAngles<TYPE> TROTATION;
00092 
00093   private:
00094     Source1_Ptr src1_;
00095     Source2_Ptr src2_;
00096 
00097   public:
00098 
00099     DOF6_Source(Source1_Ptr src1, Source2_Ptr src2)
00100     :src1_(src1),src2_(src2)
00101     {
00102       ROS_ASSERT(src1_);
00103       ROS_ASSERT(src2_);
00104     }
00105 
00106     DOF6_Source()
00107     :src1_(new SOURCE1),src2_(new SOURCE2)
00108     {
00109     }
00110 
00111     void deepCopy(const DOF6_Source &o)
00112     {
00113         src1_->deepCopy(*o.src1_);
00114         src2_->deepCopy(*o.src2_);
00115     }
00116 
00117     Source1_Ptr getSource1() {return src1_;}
00118     Source2_Ptr getSource2() {return src2_;}
00119 
00120     Source1_ConstPtr getSource1() const {return src1_;}
00121     Source2_ConstPtr getSource2() const {return src2_;}
00122 
00123     TYPE getRotationVariance() const
00124     {
00125       const TYPE C1 = src1_->getRotationVariance();
00126       const TYPE C2 = src2_->getRotationVariance();
00127       return C1 - C1*C1/(C1+C2);
00128     }
00129 
00130     TYPE getTranslationVariance() const
00131     {
00132       const TYPE C1 = src1_->getTranslationVariance();
00133       const TYPE C2 = src2_->getTranslationVariance();
00134       return C1 - C1*C1/(C1+C2);
00135     }
00136 
00137     DOF6_Source<SOURCE1,SOURCE2> transpose() const //TODO: rename to inverse
00138     {
00139       DOF6_Source r;
00140       *r.src1_ = src1_->transpose();
00141       *r.src2_ = src2_->transpose();
00142       return r;
00143     }
00144 
00145     DOF6_Source<SOURCE1,SOURCE2> operator+(const DOF6_Source<SOURCE1,SOURCE2> &o) const    
00146     {
00147       DOF6_Source r;
00148       *r.src1_ = *src1_ + *o.src1_;
00149       *r.src2_ = *src2_ + *o.src2_;
00150       return r;
00151     }
00152 
00153     EulerAngles<TYPE> getRotation() const
00154     {
00155       if(src1_->isRealSource() && src2_->isRealSource())
00156       {
00157         const EulerAngles<TYPE> X1 = src1_->getRotation();
00158         const EulerAngles<TYPE> X2 = src2_->getRotation();
00159         const TYPE C1 = src1_->getRotationVariance2();
00160         const TYPE C2 = src2_->getRotationVariance2();
00161         return X1 + C1/(C1+C2) * (X2-X1);
00162       }
00163       else if(src1_->isRealSource())
00164         return src1_->getRotation();
00165       else
00166         return src2_->getRotation();
00167     }
00168 
00169     Vector getTranslation() const
00170     {
00171       if(src1_->isRealSource() && src2_->isRealSource())
00172       {
00173         const Vector X1 = src1_->getTranslation();
00174         const Vector X2 = src2_->getTranslation();
00175         const TYPE C1 = src1_->getTranslationVariance2();
00176         const TYPE C2 = src2_->getTranslationVariance2();
00177         return X1 + C1/(C1+C2) * (X2-X1);
00178       }
00179       else if(src1_->isRealSource())
00180         return src1_->getTranslation();
00181       else
00182         return src2_->getTranslation();
00183     }
00184 
00185     void reset() {
00186       src1_->reset();
00187       src2_->reset();
00188     }
00189 
00190     void setTime(const double time_in_sec)
00191     {
00192       src1_->setTime(time_in_sec);
00193       src2_->setTime(time_in_sec);
00194     }
00195 
00196     inline bool isRealSource() const {return src1_->isRealSource()||src2_->isRealSource();}
00197 
00198     void setVariance(const TYPE Tvar, const Vector &tr, const TYPE Rvar, const EulerAngles<TYPE> &rot)
00199     {
00200       src1_->setVariance(Tvar, tr, Rvar, rot);
00201       src2_->setVariance(Tvar, tr, Rvar, rot);
00202     }
00203 
00204     Eigen::Matrix4f getTF4() const {
00205       Eigen::Matrix4f r=Eigen::Matrix4f::Identity();
00206       r.topLeftCorner(3,3) = (Eigen::Matrix3f)getRotation();
00207       r.col(3).head<3>()   = getTranslation();
00208       return r;
00209     }
00210 
00211   };
00212 
00213   template <typename _SOURCE1, typename _SOURCE2>
00214   std::ostream &operator<<(std::ostream &os, const DOF6_Source<_SOURCE1,_SOURCE2> &s)
00215   {
00216     os<<"DOF6_Source\n\n";
00217 
00218     os<<"rot\n"<<s.getRotation()<<"\n";
00219     os<<"tr\n"<<s.getTranslation()<<"\n";
00220     os<<"var rot: "<<s.getRotationVariance()<<"\n";
00221     os<<"var tr:  "<<s.getTranslationVariance()<<"\n";
00222 
00223     os<< *s.getSource1()<<"\n";
00224     os<< *s.getSource2();
00225 
00226     return os;
00227   }
00228 
00229 }
00230 
00231 
00232 
00233 #endif /* DOF_VARIANCE_H_ */


cob_3d_mapping_slam
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:04:50