tflink.h
Go to the documentation of this file.
00001 
00059 #pragma once
00060 
00061 #include <ros/console.h>
00062 #include <ros/assert.h>
00063 #include <eigen3/Eigen/Dense>
00064 
00066 namespace DOF6
00067 {
00068 
00069   template<typename INPUT>
00070   class TFLink
00071   {
00072   public:
00073     typedef typename INPUT::Scalar TYPE;
00074     typedef Eigen::Matrix<TYPE,3,3> Matrix;
00075     typedef Eigen::Matrix<TYPE,4,4> Matrix4;
00076     typedef Eigen::Matrix<TYPE,3,1> Vector;
00077 
00078   private:
00079 
00080     Matrix covariance_, variance_x_, variance_y_;
00081     Matrix translation_;
00082     Vector var_;
00083 
00084     Matrix rot_;
00085     Vector tr_;
00086 
00087     Vector var_x_, var_y_;
00088     INPUT sum_x_, sum_y_;
00089     TYPE rot_sum_, rot_var_, tr_var_, accumlated_weight_, accumlated_weight_t_;
00090 
00091     std::vector<Vector> corsA_, corsB_;
00092 #ifdef DEBUG_
00093     bool initialized_;
00094 #endif
00095 
00096   public:
00097     typedef boost::shared_ptr<TFLink<INPUT> > Ptr;
00098 
00104     struct TFLinkObj
00105     {
00106       Matrix translation_M_;
00107       Vector next_point_;
00108       float length_;
00109       Vector rotation_n_;
00110       float weight_R_,weight_t_;
00111       bool plane_;
00112 
00113       /*
00114        * normal is vector from view point to mid of cube or next point on plane
00115        */
00116       TFLinkObj(const INPUT &normal,
00117                 const bool plane,
00118                 const bool norm=false, const TYPE wR=1., const TYPE wT=1.)
00119       :weight_R_(wR),weight_t_(wT), plane_(plane)
00120       {
00121         rotation_n_ = normal;
00122 
00123         if(plane_) //plane or point
00124         {
00125           length_ = rotation_n_.norm();
00126           if(norm)
00127           {
00128             next_point_.fill(0);
00129             translation_M_ = translation_M_.Zero(); 
00130           }
00131           else
00132           {
00133             translation_M_ = normal*normal.transpose()/normal.squaredNorm(); 
00134             next_point_ = normal;
00135           }
00136         }
00137         else {
00138           length_ = 1.f;
00139           next_point_ = normal;
00140           translation_M_ = translation_M_.Identity();
00141         }
00142 
00143       }
00144     };
00145 
00146     TFLink()
00147     {
00148       reset();
00149     }
00150 
00151     void deepCopy(const TFLink &o)
00152     {
00153       *this = o;
00154     }
00155 
00156     void reset()
00157     {
00158 #ifdef DEBUG_
00159       initialized_ = false;
00160 #endif
00161       rot_var_ = 10000; //depends on max. speed
00162       tr_var_ = 10000;  //depends on max. speed
00163 
00164       rot_ = Matrix::Identity();
00165       tr_.fill(0);
00166       accumlated_weight_t_ = accumlated_weight_ = 0;
00167 
00168       rot_sum_ = 0;
00169       covariance_.fill(0);
00170       sum_x_.fill(0);
00171       sum_y_.fill(0);
00172 
00173       translation_.fill(0);
00174       var_x_.fill(0);
00175       var_y_.fill(0);
00176 
00177       variance_x_.fill(0);
00178       variance_y_.fill(0);
00179 
00180       corsA_.clear();
00181       corsB_.clear();
00182     }
00183 
00184     void debug_print() {
00185       std::cout<<"TRANSLATION MATRIX\n"<<translation_<<"\n";
00186     }
00187 
00188     void operator()(const TFLinkObj &obj, const TFLinkObj &cor_obj);    
00189     TFLink operator+(const TFLink &o) const;    
00190     void operator+=(const TFLink &o);    
00191 
00192     TFLink<INPUT> transpose() const;   
00193     void finish();      
00194 
00195     inline Matrix getRotation() const {return rot_;}
00196     inline Vector getTranslation() const {return tr_;}
00197     Matrix4 getTransformation() const;  
00198 
00199     inline void setRotation(const Matrix &m)    {rot_=m;}
00200     inline void setTranslation(const Vector &m) {tr_=m;}
00201 
00202     TYPE getRotationVariance() const {return rot_var_;}
00203     TYPE getTranslationVariance() const {return tr_var_;}
00204 
00205     void check() const;
00206 
00207     inline Ptr makeShared () { return Ptr (new TFLink<INPUT> (*this)); }
00208 
00209     void setTime(const double time_in_sec)
00210     {
00211       //not used
00212     }
00213 
00214     inline bool isRealSource() const {return true;}
00215 
00216     void setVariance(const TYPE Tvar, const Vector &tr, const TYPE Rvar, const Matrix &rot)
00217     {
00218       //not used
00219     }
00220 
00221     TYPE getRotationVariance2() const
00222     {
00223       return getRotationVariance();
00224     }
00225 
00226     TYPE getTranslationVariance2() const
00227     {
00228       return getTranslationVariance();
00229     }
00230 
00231     bool isSet() const {return accumlated_weight_t_!=0;}
00232 
00233   };
00234 
00235   template<typename INPUT>
00236   std::ostream &operator<<(std::ostream &os, const TFLink<INPUT> &s)
00237   {
00238 
00239     os<<"TFLink\n\n";
00240 
00241     os<<"rot\n"<<s.getRotation()<<"\n";
00242     os<<"tr\n"<<s.getTranslation()<<"\n";
00243     os<<"var rot: "<<s.getRotationVariance()<<"\n";
00244     os<<"var tr:  "<<s.getTranslationVariance()<<"\n";
00245 
00246     return os;
00247   }
00248 
00249   typedef TFLink<Eigen::Vector3f> TFLinkvf;
00250   typedef TFLink<Eigen::Vector3d> TFLinkvd;
00251 
00252 #include "impl/tflink.hpp"
00253 }


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