types_six_dof_expmap.h
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 H. Strasdat
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 SIX_DOF_TYPES_EXPMAP
00018 #define SIX_DOF_TYPES_EXPMAP
00019 
00020 #include "g2o/core/base_vertex.h"
00021 #include "g2o/core/base_binary_edge.h"
00022 #include "g2o/math_groups/se3_ops.h"
00023 #include "types_sba.h"
00024 #include <Eigen/Geometry>
00025 
00026 namespace g2o {
00027 
00028   using namespace Eigen;
00029 
00030   typedef Matrix<double, 6, 6> Matrix6d;
00031 
00036   class VertexSE3Expmap : public BaseVertex<6, SE3Quat>
00037     {
00038     public:
00039       EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00040 
00041       VertexSE3Expmap();
00042       bool read(std::istream& is);
00043       bool write(std::ostream& os) const;
00044 
00045       virtual void setToOrigin() {
00046         _estimate = SE3Quat();
00047       }
00048       
00049       virtual void oplus(double* update_)
00050       {
00051 
00052         Vector6d update;
00053         for (int i=0; i<6; i++)
00054           update[i]=update_[i];
00055 
00056 
00057         //SE3 res = s*SE3(estimate());
00058          estimate()=SE3Quat::exp(update)*estimate();
00059 
00060             //SE3Quat(Quaterniond(res._R),
00061               //             res.translation());
00062       }
00063 
00064       Vector2d _principle_point;
00065       Vector2d _focal_length;
00066       double _baseline;
00067 
00068 
00069       Vector2d cam_map(const Vector3d & trans_xyz) const
00070       {
00071         Vector2d proj = project(trans_xyz);
00072 
00073         Vector2d res;
00074         res[0] = proj[0]*_focal_length[0] + _principle_point[0];
00075         res[1] = proj[1]*_focal_length[1] + _principle_point[1];
00076         return res;
00077       }
00078 
00079 
00080       Vector3d stereocam_uvq_map(const Vector3d & trans_xyz) const
00081       {
00082         Vector2d uv_left = cam_map(trans_xyz);
00083 
00084         double proj_x_right = (trans_xyz[0]-_baseline)/trans_xyz[2];
00085         double u_right = proj_x_right*_focal_length[0] + _principle_point[0];
00086 
00087         Vector3d res;
00088         res[0] = uv_left[0];
00089         res[1] = uv_left[1];
00090         res[2] = (uv_left[0]-u_right)/_baseline;
00091         return res;
00092       }
00093 
00094       Vector3d stereocam_uvu_map(const Vector3d & trans_xyz) const
00095       {
00096         Vector2d uv_left = cam_map(trans_xyz);
00097 
00098         double proj_x_right = (trans_xyz[0]-_baseline)/trans_xyz[2];
00099         double u_right = proj_x_right*_focal_length[0] + _principle_point[0];
00100 
00101 
00102         return Vector3d(uv_left[0],uv_left[1],u_right);
00103       }
00104 
00105 };
00106 
00107 
00111 class EdgeSE3Expmap : public BaseBinaryEdge<6, SE3Quat, VertexSE3Expmap, VertexSE3Expmap>
00112 {
00113   // no chain rule, numeric differentiation on linearizeOplus
00114   public:
00115     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00116     EdgeSE3Expmap();
00117     bool read(std::istream& is);
00118     bool write(std::ostream& os) const;
00119     void computeError()
00120     {
00121       const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[0]);
00122       const VertexSE3Expmap* v2 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
00123 
00124       SE3Quat C(_measurement);
00125       SE3Quat error_= v2->estimate().inverse()*C*v1->estimate();
00126       _error = error_.log();
00127     }
00128 
00129     virtual void linearizeOplus();
00130 
00131 };
00132 
00133 
00134 class EdgeProjectXYZ2UV : public  BaseBinaryEdge<2, Vector2d, VertexPointXYZ, VertexSE3Expmap>
00135 {
00136   public:
00137     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00138     EdgeProjectXYZ2UV();
00139     bool read(std::istream& is);
00140     bool write(std::ostream& os) const;
00141 
00142     void computeError()
00143     {
00144       const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
00145       const VertexPointXYZ* v2 = static_cast<const VertexPointXYZ*>(_vertices[0]);
00146 
00147       Vector2d obs(_measurement);
00148       _error = obs-v1->cam_map(v1->estimate().map(v2->estimate()));
00149     }
00150 
00151     virtual void linearizeOplus();
00152 };
00153 
00154 
00155 class EdgeProjectXYZ2UVQ : public  BaseBinaryEdge<3, Vector3d, VertexPointXYZ, VertexSE3Expmap>
00156 {
00157   public:
00158     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00159     EdgeProjectXYZ2UVQ();
00160     bool read(std::istream& is);
00161     bool write(std::ostream& os) const;
00162 
00163     void computeError()
00164     {
00165       const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
00166       const VertexPointXYZ* v2 = static_cast<const VertexPointXYZ*>(_vertices[0]);
00167 
00168       Vector3d obs(_measurement);
00169       _error = obs-v1->stereocam_uvq_map(v1->estimate().map(v2->estimate()));
00170     }
00171 
00172     virtual void linearizeOplus();
00173 
00174 };
00175 
00176 //Stereo Observations
00177 // U: left u
00178 // V: left v
00179 // U: right u
00180 class EdgeProjectXYZ2UVU : public  BaseBinaryEdge<3, Vector3d, VertexPointXYZ, VertexSE3Expmap>
00181 {
00182   public:
00183     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00184     EdgeProjectXYZ2UVU();
00185 
00186     bool read(std::istream& is);
00187     bool write(std::ostream& os) const;
00188 
00189     void computeError()
00190     {
00191       const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
00192       const VertexPointXYZ* v2 = static_cast<const VertexPointXYZ*>(_vertices[0]);
00193 
00194       Vector3d obs(_measurement);
00195       _error = obs-v1->stereocam_uvu_map(v1->estimate().map(v2->estimate()));
00196     }
00197 
00198     //virtual void linearizeOplus();
00199 
00200 };
00201 
00202 } // end namespace
00203 
00204 #endif


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