types_six_dof_expmap.cpp
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 #include "types_six_dof_expmap.h"
28 
29 #include "../core/factory.h"
30 #include "../stuff/macros.h"
31 
32 namespace g2o {
33 
34 using namespace std;
35 
36 
37 Vector2d project2d(const Vector3d& v) {
38  Vector2d res;
39  res(0) = v(0)/v(2);
40  res(1) = v(1)/v(2);
41  return res;
42 }
43 
44 Vector3d unproject2d(const Vector2d& v) {
45  Vector3d res;
46  res(0) = v(0);
47  res(1) = v(1);
48  res(2) = 1;
49  return res;
50 }
51 
53 }
54 
55 bool VertexSE3Expmap::read(std::istream& is) {
56  Vector7d est;
57  for (int i=0; i<7; i++)
58  is >> est[i];
59  SE3Quat cam2world;
60  cam2world.fromVector(est);
61  setEstimate(cam2world.inverse());
62  return true;
63 }
64 
65 bool VertexSE3Expmap::write(std::ostream& os) const {
66  SE3Quat cam2world(estimate().inverse());
67  for (int i=0; i<7; i++)
68  os << cam2world[i] << " ";
69  return os.good();
70 }
71 
72 
74 }
75 
76 bool EdgeSE3ProjectXYZ::read(std::istream& is){
77  for (int i=0; i<2; i++){
78  is >> _measurement[i];
79  }
80  for (int i=0; i<2; i++)
81  for (int j=i; j<2; j++) {
82  is >> information()(i,j);
83  if (i!=j)
84  information()(j,i)=information()(i,j);
85  }
86  return true;
87 }
88 
89 bool EdgeSE3ProjectXYZ::write(std::ostream& os) const {
90 
91  for (int i=0; i<2; i++){
92  os << measurement()[i] << " ";
93  }
94 
95  for (int i=0; i<2; i++)
96  for (int j=i; j<2; j++){
97  os << " " << information()(i,j);
98  }
99  return os.good();
100 }
101 
102 
104  VertexSE3Expmap * vj = static_cast<VertexSE3Expmap *>(_vertices[1]);
105  SE3Quat T(vj->estimate());
106  VertexSBAPointXYZ* vi = static_cast<VertexSBAPointXYZ*>(_vertices[0]);
107  Vector3d xyz = vi->estimate();
108  Vector3d xyz_trans = T.map(xyz);
109 
110  double x = xyz_trans[0];
111  double y = xyz_trans[1];
112  double z = xyz_trans[2];
113  double z_2 = z*z;
114 
115  Matrix<double,2,3> tmp;
116  tmp(0,0) = fx;
117  tmp(0,1) = 0;
118  tmp(0,2) = -x/z*fx;
119 
120  tmp(1,0) = 0;
121  tmp(1,1) = fy;
122  tmp(1,2) = -y/z*fy;
123 
124  _jacobianOplusXi = -1./z * tmp * T.rotation().toRotationMatrix();
125 
126  _jacobianOplusXj(0,0) = x*y/z_2 *fx;
127  _jacobianOplusXj(0,1) = -(1+(x*x/z_2)) *fx;
128  _jacobianOplusXj(0,2) = y/z *fx;
129  _jacobianOplusXj(0,3) = -1./z *fx;
130  _jacobianOplusXj(0,4) = 0;
131  _jacobianOplusXj(0,5) = x/z_2 *fx;
132 
133  _jacobianOplusXj(1,0) = (1+y*y/z_2) *fy;
134  _jacobianOplusXj(1,1) = -x*y/z_2 *fy;
135  _jacobianOplusXj(1,2) = -x/z *fy;
136  _jacobianOplusXj(1,3) = 0;
137  _jacobianOplusXj(1,4) = -1./z *fy;
138  _jacobianOplusXj(1,5) = y/z_2 *fy;
139 }
140 
141 Vector2d EdgeSE3ProjectXYZ::cam_project(const Vector3d & trans_xyz) const{
142  Vector2d proj = project2d(trans_xyz);
143  Vector2d res;
144  res[0] = proj[0]*fx + cx;
145  res[1] = proj[1]*fy + cy;
146  return res;
147 }
148 
149 
150 Vector3d EdgeStereoSE3ProjectXYZ::cam_project(const Vector3d & trans_xyz, const float &bf) const{
151  const float invz = 1.0f/trans_xyz[2];
152  Vector3d res;
153  res[0] = trans_xyz[0]*invz*fx + cx;
154  res[1] = trans_xyz[1]*invz*fy + cy;
155  res[2] = res[0] - bf*invz;
156  return res;
157 }
158 
160 }
161 
162 bool EdgeStereoSE3ProjectXYZ::read(std::istream& is){
163  for (int i=0; i<=3; i++){
164  is >> _measurement[i];
165  }
166  for (int i=0; i<=2; i++)
167  for (int j=i; j<=2; j++) {
168  is >> information()(i,j);
169  if (i!=j)
170  information()(j,i)=information()(i,j);
171  }
172  return true;
173 }
174 
175 bool EdgeStereoSE3ProjectXYZ::write(std::ostream& os) const {
176 
177  for (int i=0; i<=3; i++){
178  os << measurement()[i] << " ";
179  }
180 
181  for (int i=0; i<=2; i++)
182  for (int j=i; j<=2; j++){
183  os << " " << information()(i,j);
184  }
185  return os.good();
186 }
187 
189  VertexSE3Expmap * vj = static_cast<VertexSE3Expmap *>(_vertices[1]);
190  SE3Quat T(vj->estimate());
191  VertexSBAPointXYZ* vi = static_cast<VertexSBAPointXYZ*>(_vertices[0]);
192  Vector3d xyz = vi->estimate();
193  Vector3d xyz_trans = T.map(xyz);
194 
195  const Matrix3d R = T.rotation().toRotationMatrix();
196 
197  double x = xyz_trans[0];
198  double y = xyz_trans[1];
199  double z = xyz_trans[2];
200  double z_2 = z*z;
201 
202  _jacobianOplusXi(0,0) = -fx*R(0,0)/z+fx*x*R(2,0)/z_2;
203  _jacobianOplusXi(0,1) = -fx*R(0,1)/z+fx*x*R(2,1)/z_2;
204  _jacobianOplusXi(0,2) = -fx*R(0,2)/z+fx*x*R(2,2)/z_2;
205 
206  _jacobianOplusXi(1,0) = -fy*R(1,0)/z+fy*y*R(2,0)/z_2;
207  _jacobianOplusXi(1,1) = -fy*R(1,1)/z+fy*y*R(2,1)/z_2;
208  _jacobianOplusXi(1,2) = -fy*R(1,2)/z+fy*y*R(2,2)/z_2;
209 
210  _jacobianOplusXi(2,0) = _jacobianOplusXi(0,0)-bf*R(2,0)/z_2;
211  _jacobianOplusXi(2,1) = _jacobianOplusXi(0,1)-bf*R(2,1)/z_2;
212  _jacobianOplusXi(2,2) = _jacobianOplusXi(0,2)-bf*R(2,2)/z_2;
213 
214  _jacobianOplusXj(0,0) = x*y/z_2 *fx;
215  _jacobianOplusXj(0,1) = -(1+(x*x/z_2)) *fx;
216  _jacobianOplusXj(0,2) = y/z *fx;
217  _jacobianOplusXj(0,3) = -1./z *fx;
218  _jacobianOplusXj(0,4) = 0;
219  _jacobianOplusXj(0,5) = x/z_2 *fx;
220 
221  _jacobianOplusXj(1,0) = (1+y*y/z_2) *fy;
222  _jacobianOplusXj(1,1) = -x*y/z_2 *fy;
223  _jacobianOplusXj(1,2) = -x/z *fy;
224  _jacobianOplusXj(1,3) = 0;
225  _jacobianOplusXj(1,4) = -1./z *fy;
226  _jacobianOplusXj(1,5) = y/z_2 *fy;
227 
228  _jacobianOplusXj(2,0) = _jacobianOplusXj(0,0)-bf*y/z_2;
229  _jacobianOplusXj(2,1) = _jacobianOplusXj(0,1)+bf*x/z_2;
232  _jacobianOplusXj(2,4) = 0;
233  _jacobianOplusXj(2,5) = _jacobianOplusXj(0,5)-bf/z_2;
234 }
235 
236 
237 //Only Pose
238 
239 bool EdgeSE3ProjectXYZOnlyPose::read(std::istream& is){
240  for (int i=0; i<2; i++){
241  is >> _measurement[i];
242  }
243  for (int i=0; i<2; i++)
244  for (int j=i; j<2; j++) {
245  is >> information()(i,j);
246  if (i!=j)
247  information()(j,i)=information()(i,j);
248  }
249  return true;
250 }
251 
252 bool EdgeSE3ProjectXYZOnlyPose::write(std::ostream& os) const {
253 
254  for (int i=0; i<2; i++){
255  os << measurement()[i] << " ";
256  }
257 
258  for (int i=0; i<2; i++)
259  for (int j=i; j<2; j++){
260  os << " " << information()(i,j);
261  }
262  return os.good();
263 }
264 
265 
267  VertexSE3Expmap * vi = static_cast<VertexSE3Expmap *>(_vertices[0]);
268  Vector3d xyz_trans = vi->estimate().map(Xw);
269 
270  double x = xyz_trans[0];
271  double y = xyz_trans[1];
272  double invz = 1.0/xyz_trans[2];
273  double invz_2 = invz*invz;
274 
275  _jacobianOplusXi(0,0) = x*y*invz_2 *fx;
276  _jacobianOplusXi(0,1) = -(1+(x*x*invz_2)) *fx;
277  _jacobianOplusXi(0,2) = y*invz *fx;
278  _jacobianOplusXi(0,3) = -invz *fx;
279  _jacobianOplusXi(0,4) = 0;
280  _jacobianOplusXi(0,5) = x*invz_2 *fx;
281 
282  _jacobianOplusXi(1,0) = (1+y*y*invz_2) *fy;
283  _jacobianOplusXi(1,1) = -x*y*invz_2 *fy;
284  _jacobianOplusXi(1,2) = -x*invz *fy;
285  _jacobianOplusXi(1,3) = 0;
286  _jacobianOplusXi(1,4) = -invz *fy;
287  _jacobianOplusXi(1,5) = y*invz_2 *fy;
288 }
289 
290 Vector2d EdgeSE3ProjectXYZOnlyPose::cam_project(const Vector3d & trans_xyz) const{
291  Vector2d proj = project2d(trans_xyz);
292  Vector2d res;
293  res[0] = proj[0]*fx + cx;
294  res[1] = proj[1]*fy + cy;
295  return res;
296 }
297 
298 
299 Vector3d EdgeStereoSE3ProjectXYZOnlyPose::cam_project(const Vector3d & trans_xyz) const{
300  const float invz = 1.0f/trans_xyz[2];
301  Vector3d res;
302  res[0] = trans_xyz[0]*invz*fx + cx;
303  res[1] = trans_xyz[1]*invz*fy + cy;
304  res[2] = res[0] - bf*invz;
305  return res;
306 }
307 
308 
310  for (int i=0; i<=3; i++){
311  is >> _measurement[i];
312  }
313  for (int i=0; i<=2; i++)
314  for (int j=i; j<=2; j++) {
315  is >> information()(i,j);
316  if (i!=j)
317  information()(j,i)=information()(i,j);
318  }
319  return true;
320 }
321 
322 bool EdgeStereoSE3ProjectXYZOnlyPose::write(std::ostream& os) const {
323 
324  for (int i=0; i<=3; i++){
325  os << measurement()[i] << " ";
326  }
327 
328  for (int i=0; i<=2; i++)
329  for (int j=i; j<=2; j++){
330  os << " " << information()(i,j);
331  }
332  return os.good();
333 }
334 
336  VertexSE3Expmap * vi = static_cast<VertexSE3Expmap *>(_vertices[0]);
337  Vector3d xyz_trans = vi->estimate().map(Xw);
338 
339  double x = xyz_trans[0];
340  double y = xyz_trans[1];
341  double invz = 1.0/xyz_trans[2];
342  double invz_2 = invz*invz;
343 
344  _jacobianOplusXi(0,0) = x*y*invz_2 *fx;
345  _jacobianOplusXi(0,1) = -(1+(x*x*invz_2)) *fx;
346  _jacobianOplusXi(0,2) = y*invz *fx;
347  _jacobianOplusXi(0,3) = -invz *fx;
348  _jacobianOplusXi(0,4) = 0;
349  _jacobianOplusXi(0,5) = x*invz_2 *fx;
350 
351  _jacobianOplusXi(1,0) = (1+y*y*invz_2) *fy;
352  _jacobianOplusXi(1,1) = -x*y*invz_2 *fy;
353  _jacobianOplusXi(1,2) = -x*invz *fy;
354  _jacobianOplusXi(1,3) = 0;
355  _jacobianOplusXi(1,4) = -invz *fy;
356  _jacobianOplusXi(1,5) = y*invz_2 *fy;
357 
358  _jacobianOplusXi(2,0) = _jacobianOplusXi(0,0)-bf*y*invz_2;
359  _jacobianOplusXi(2,1) = _jacobianOplusXi(0,1)+bf*x*invz_2;
362  _jacobianOplusXi(2,4) = 0;
363  _jacobianOplusXi(2,5) = _jacobianOplusXi(0,5)-bf*invz_2;
364 }
365 
366 
367 } // end namespace
const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:77
Vector2d project2d(const Vector3d &v)
Matrix< double, 7, 1 > Vector7d
Definition: se3quat.h:39
bool write(std::ostream &os) const
write the vertex to a stream
bool write(std::ostream &os) const
write the vertex to a stream
bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Templatized BaseVertex.
Definition: base_vertex.h:53
const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:69
TFSIMD_FORCE_INLINE const tfScalar & y() const
SE3Quat inverse() const
Definition: se3quat.h:123
Vector3d cam_project(const Vector3d &trans_xyz, const float &bf) const
Point vertex, XYZ.
Definition: types_sba.h:40
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VertexSE3Expmap()
SE3 Vertex parameterized internally with a transformation matrix and externally with its exponential ...
Vector3d cam_project(const Vector3d &trans_xyz) const
Vector3d unproject2d(const Vector2d &v)
TFSIMD_FORCE_INLINE Quaternion inverse(const Quaternion &q)
void fromVector(const Vector7d &v)
Definition: se3quat.h:150
TFSIMD_FORCE_INLINE const tfScalar & x() const
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:104
TFSIMD_FORCE_INLINE const tfScalar & z() const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeSE3ProjectXYZ()
bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
bool write(std::ostream &os) const
write the vertex to a stream
bool write(std::ostream &os) const
write the vertex to a stream
Vector2d cam_project(const Vector3d &trans_xyz) const
bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:102
Vector2d cam_project(const Vector3d &trans_xyz) const
Vector3d map(const Vector3d &xyz) const
Definition: se3quat.h:217
bool write(std::ostream &os) const
write the vertex to a stream
bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeStereoSE3ProjectXYZ()
VertexContainer _vertices
Definition: hyper_graph.h:154


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05