00001 //part of the source code of master thesis, source code produced by Jiri Divis 00009 #ifndef VO_G2O_TYPE_VERTEX_POSE_H_ 00010 #define VO_G2O_TYPE_VERTEX_POSE_H_ 00011 00012 00013 #include <Eigen/Dense> 00014 #include <g2o/core/base_vertex.h> 00015 #include "se3_for_g2o.h" 00016 00017 00018 namespace vslam{ 00019 00020 namespace g2o_types{ 00021 00030 template<class PoseGraphT> class VertexSE3 : public g2o::BaseVertex<6, SE3G2O> { 00031 protected: 00032 typedef typename graph_traits<PoseGraphT>::vertex_descriptor VertexD; 00033 PoseGraphT * g; 00034 VertexD vd; 00035 bool initialized; 00036 00037 public: 00038 EIGEN_MAKE_ALIGNED_OPERATOR_NEW; 00039 00040 bool save_state; 00041 00042 00043 VertexSE3(PoseGraphT& _g, VertexD _vd) : vd(_vd), initialized(true) { 00044 g=&_g; 00045 save_state=true; 00046 } 00047 00049 VertexSE3() : g(NULL), initialized(false) {} 00050 00051 virtual void setToOriginImpl() { 00052 _estimate = SE3G2O(); 00053 } 00054 00059 00060 virtual bool read(std::istream& is) { assert(false); return true; } 00061 00062 virtual bool write(std::ostream& os) const { 00063 Vector6d v = _estimate.toVector(); 00064 os << v.transpose(); 00065 return os.good(); 00066 }; 00068 00069 virtual void oplusImpl(const double* update) 00070 { 00071 Eigen::Map<const Vector6d> v(update); 00072 SE3G2O increment = SE3G2O::exp(v); 00073 _estimate = increment * _estimate; 00074 } 00075 00076 virtual ~VertexSE3(){ 00077 if(save_state){ 00078 assert(initialized); 00079 get(vertex_transform, *g, vd) = _estimate; 00080 } 00081 } 00082 }; 00083 }//namespace g2o_types 00084 }//namespace vslam 00085 00086 00087 #endif