g2o
types_six_dof_expmap.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 H. Strasdat
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_SIX_DOF_TYPES_EXPMAP
28 #define G2O_SIX_DOF_TYPES_EXPMAP
29 
30 #include "g2o/core/base_vertex.h"
33 #include "types_sba.h"
34 #include <Eigen/Geometry>
35 
36 namespace g2o {
37 namespace types_six_dof_expmap {
38 void init();
39 }
40 
41 typedef Eigen::Matrix<double, 6, 6, Eigen::ColMajor> Matrix6d;
42 
44 {
45  public:
48 
49  CameraParameters(double focal_length,
50  const Vector2D & principle_point,
51  double baseline)
52  : focal_length(focal_length),
53  principle_point(principle_point),
54  baseline(baseline){}
55 
56  Vector2D cam_map (const Vector3D & trans_xyz) const;
57 
58  Vector3D stereocam_uvu_map (const Vector3D & trans_xyz) const;
59 
60  virtual bool read (std::istream& is){
61  is >> focal_length;
62  is >> principle_point[0];
63  is >> principle_point[1];
64  is >> baseline;
65  return true;
66  }
67 
68  virtual bool write (std::ostream& os) const {
69  os << focal_length << " ";
70  os << principle_point.x() << " ";
71  os << principle_point.y() << " ";
72  os << baseline << " ";
73  return true;
74  }
75 
76  double focal_length;
78  double baseline;
79 };
80 
85 class G2O_TYPES_SBA_API VertexSE3Expmap : public BaseVertex<6, SE3Quat>{
86 public:
87  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
88 
90 
91  bool read(std::istream& is);
92 
93  bool write(std::ostream& os) const;
94 
95  virtual void setToOriginImpl() {
96  _estimate = SE3Quat();
97  }
98 
99  virtual void oplusImpl(const double* update_) {
100  Eigen::Map<const Vector6d> update(update_);
101  setEstimate(SE3Quat::exp(update)*estimate());
102  }
103 };
104 
105 
109 class G2O_TYPES_SBA_API EdgeSE3Expmap : public BaseBinaryEdge<6, SE3Quat, VertexSE3Expmap, VertexSE3Expmap>{
110  public:
112  EdgeSE3Expmap();
113 
114  bool read(std::istream& is);
115 
116  bool write(std::ostream& os) const;
117 
118  void computeError() {
119  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[0]);
120  const VertexSE3Expmap* v2 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
121 
122  SE3Quat C(_measurement);
123  SE3Quat error_= v2->estimate().inverse()*C*v1->estimate();
124  _error = error_.log();
125  }
126 
127  virtual void linearizeOplus();
128 };
129 
130 
131 class G2O_TYPES_SBA_API EdgeProjectXYZ2UV : public BaseBinaryEdge<2, Vector2D, VertexSBAPointXYZ, VertexSE3Expmap>{
132  public:
134 
136 
137  bool read(std::istream& is);
138 
139  bool write(std::ostream& os) const;
140 
141  void computeError() {
142  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
143  const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
144  const CameraParameters * cam
145  = static_cast<const CameraParameters *>(parameter(0));
146  Vector2D obs(_measurement);
147  _error = obs-cam->cam_map(v1->estimate().map(v2->estimate()));
148  }
149 
150  virtual void linearizeOplus();
151 
153 };
154 
155 
157 {
158 public:
159  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
160 
162  resizeParameters(1);
163  installParameter(_cam, 0);
164  }
165 
166  virtual bool read (std::istream& is);
167  virtual bool write (std::ostream& os) const;
168  void computeError ();
169  virtual void linearizeOplus ();
171 };
172 
173 
174 
175 //Stereo Observations
176 // U: left u
177 // V: left v
178 // U: right u
179 class G2O_TYPES_SBA_API EdgeProjectXYZ2UVU : public BaseBinaryEdge<3, Vector3D, VertexSBAPointXYZ, VertexSE3Expmap>{
180  public:
182 
184 
185  bool read(std::istream& is);
186 
187  bool write(std::ostream& os) const;
188 
189  void computeError(){
190  const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
191  const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
192  const CameraParameters * cam
193  = static_cast<const CameraParameters *>(parameter(0));
194  Vector3D obs(_measurement);
195  _error = obs-cam->stereocam_uvu_map(v1->estimate().map(v2->estimate()));
196  }
197  // virtual void linearizeOplus();
199 };
200 
201 } // end namespace
202 
203 #endif
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
#define G2O_TYPES_SBA_API
Vector2D cam_map(const Vector3D &trans_xyz) const
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
Eigen::Matrix< double, 6, 6, Eigen::ColMajor > Matrix6d
virtual bool read(std::istream &is)
read the data from a stream
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
Vector3D map(const Vector3D &xyz) const
Definition: se3quat.h:214
virtual void oplusImpl(const double *update_)
Templatized BaseVertex.
Definition: base_vertex.h:50
virtual bool write(std::ostream &os) const
write the data to a stream
Vector6d log() const
Definition: se3quat.h:175
SE3Quat inverse() const
Definition: se3quat.h:120
Point vertex, XYZ.
Definition: types_sba.h:137
SE3 Vertex parameterized internally with a transformation matrix and externally with its exponential ...
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeProjectPSI2UV()
static SE3Quat exp(const Vector6d &update)
Definition: se3quat.h:220
base class to represent an edge connecting an arbitrary number of nodes
Vector3D stereocam_uvu_map(const Vector3D &trans_xyz) const
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
6D edge between two Vertex6
CameraParameters(double focal_length, const Vector2D &principle_point, double baseline)