base_unary_edge.hpp
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, H. Strasdat, W. Burgard
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 template <int D, typename E, typename VertexXiType>
28 void BaseUnaryEdge<D, E, VertexXiType>::resize(size_t size)
29 {
30  if (size != 1) {
31  std::cerr << "WARNING, attempting to resize unary edge " << BaseEdge<D, E>::id() << " to " << size << std::endl;
32  }
33  BaseEdge<D, E>::resize(size);
34 }
35 
36 template <int D, typename E, typename VertexXiType>
37 bool BaseUnaryEdge<D, E, VertexXiType>::allVerticesFixed() const
38 {
39  return static_cast<const VertexXiType*> (_vertices[0])->fixed();
40 }
41 
42 template <int D, typename E, typename VertexXiType>
43 void BaseUnaryEdge<D, E, VertexXiType>::constructQuadraticForm()
44 {
45  VertexXiType* from=static_cast<VertexXiType*>(_vertices[0]);
46 
47  // chain rule to get the Jacobian of the nodes in the manifold domain
48  const JacobianXiOplusType& A = jacobianOplusXi();
49  const InformationType& omega = _information;
50 
51  bool istatus = !from->fixed();
52  if (istatus) {
53 #ifdef G2O_OPENMP
54  from->lockQuadraticForm();
55 #endif
56  if (this->robustKernel()) {
57  double error = this->chi2();
58  Eigen::Vector3d rho;
59  this->robustKernel()->robustify(error, rho);
60  InformationType weightedOmega = this->robustInformation(rho);
61 
62  from->b().noalias() -= rho[1] * A.transpose() * omega * _error;
63  from->A().noalias() += A.transpose() * weightedOmega * A;
64  } else {
65  from->b().noalias() -= A.transpose() * omega * _error;
66  from->A().noalias() += A.transpose() * omega * A;
67  }
68 #ifdef G2O_OPENMP
69  from->unlockQuadraticForm();
70 #endif
71  }
72 }
73 
74 template <int D, typename E, typename VertexXiType>
75 void BaseUnaryEdge<D, E, VertexXiType>::linearizeOplus(JacobianWorkspace& jacobianWorkspace)
76 {
77  new (&_jacobianOplusXi) JacobianXiOplusType(jacobianWorkspace.workspaceForVertex(0), D, VertexXiType::Dimension);
78  linearizeOplus();
79 }
80 
81 template <int D, typename E, typename VertexXiType>
82 void BaseUnaryEdge<D, E, VertexXiType>::linearizeOplus()
83 {
84  //Xi - estimate the jacobian numerically
85  VertexXiType* vi = static_cast<VertexXiType*>(_vertices[0]);
86 
87  if (vi->fixed())
88  return;
89 
90 #ifdef G2O_OPENMP
91  vi->lockQuadraticForm();
92 #endif
93 
94  const double delta = 1e-9;
95  const double scalar = 1.0 / (2*delta);
96  ErrorVector error1;
97  ErrorVector errorBeforeNumeric = _error;
98 
99  double add_vi[VertexXiType::Dimension];
100  std::fill(add_vi, add_vi + VertexXiType::Dimension, 0.0);
101  // add small step along the unit vector in each dimension
102  for (int d = 0; d < VertexXiType::Dimension; ++d) {
103  vi->push();
104  add_vi[d] = delta;
105  vi->oplus(add_vi);
106  computeError();
107  error1 = _error;
108  vi->pop();
109  vi->push();
110  add_vi[d] = -delta;
111  vi->oplus(add_vi);
112  computeError();
113  vi->pop();
114  add_vi[d] = 0.0;
115 
116  _jacobianOplusXi.col(d) = scalar * (error1 - _error);
117  } // end dimension
118 
119  _error = errorBeforeNumeric;
120 #ifdef G2O_OPENMP
121  vi->unlockQuadraticForm();
122 #endif
123 }
124 
125 template <int D, typename E, typename VertexXiType>
126 void BaseUnaryEdge<D, E, VertexXiType>::initialEstimate(const OptimizableGraph::VertexSet&, OptimizableGraph::Vertex*)
127 {
128  std::cerr << __PRETTY_FUNCTION__ << " is not implemented, please give implementation in your derived class" << std::endl;
129 }
d
#define __PRETTY_FUNCTION__
Definition: macros.h:95


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47