Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00058 estimate()=SE3Quat::exp(update)*estimate();
00059
00060
00061
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
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
00177
00178
00179
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
00199
00200 };
00201
00202 }
00203
00204 #endif