se2.h
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef TUTORIAL_SE2_H
00018 #define TUTORIAL_SE2_H
00019 
00020 #include "g2o/stuff/misc.h"
00021 #include "g2o/stuff/macros.h"
00022 #include <Eigen/Core>
00023 #include <Eigen/Geometry>
00024 
00025 namespace g2o {
00026   using namespace Eigen;
00027 
00028   namespace tutorial {
00029 
00030     class SE2 {
00031       public:
00032         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00033           SE2():_R(0),_t(0,0){}
00034 
00035         SE2(double x, double y, double theta):_R(theta),_t(x,y){}
00036 
00037         const Vector2d& translation() const {return _t;}
00038 
00039         Vector2d& translation() {return _t;}
00040 
00041         const Rotation2Dd& rotation() const {return _R;}
00042 
00043         Rotation2Dd& rotation() {return _R;}
00044 
00045         SE2 operator * (const SE2& tr2) const{
00046           SE2 result(*this);
00047           result._t += _R*tr2._t;
00048           result._R.angle()+= tr2._R.angle();
00049           result._R.angle()=normalize_theta(result._R.angle());
00050           return result;
00051         }
00052 
00053         SE2& operator *= (const SE2& tr2){
00054           _t+=_R*tr2._t;
00055           _R.angle()+=tr2._R.angle();
00056           _R.angle()=normalize_theta(_R.angle());
00057           return *this;
00058         }
00059 
00060         Vector2d operator * (const Vector2d& v) const {
00061           return _t+_R*v;
00062         }
00063 
00064         SE2 inverse() const{
00065           SE2 ret;
00066           ret._R=_R.inverse();
00067           ret._R.angle()=normalize_theta(ret._R.angle());
00068           ret._t=ret._R*(_t*-1.);
00069           return ret;
00070         }
00071 
00072         double operator [](int i) const {
00073           assert (i>=0 && i<3);
00074           if (i<2)
00075             return _t(i);
00076           return _R.angle();
00077         }
00078 
00079         double& operator [](int i) {
00080           assert (i>=0 && i<3);
00081           if (i<2)
00082             return _t(i);
00083           return _R.angle();
00084         }
00085 
00086         void fromVector (const Vector3d& v){
00087           *this=SE2(v[0], v[1], v[2]);
00088         }
00089 
00090         Vector3d toVector() const {
00091           Vector3d ret;
00092           for (int i=0; i<3; i++){
00093             ret(i)=(*this)[i];
00094           }
00095           return ret;
00096         }
00097 
00098       protected:
00099         Rotation2Dd _R;
00100         Vector2d _t;
00101     };
00102 
00103   } // end namespace
00104 } // end namespace
00105 
00106 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:23