g2o
base_vertex.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, 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 #ifndef G2O_BASE_VERTEX_H
28 #define G2O_BASE_VERTEX_H
29 
30 #include "optimizable_graph.h"
31 #include "creators.h"
32 #include "g2o/stuff/macros.h"
33 
34 #include <Eigen/Core>
35 #include <Eigen/Dense>
36 #include <Eigen/Cholesky>
37 #include <Eigen/StdVector>
38 #include <stack>
39 
40 namespace g2o {
41 
49  template <int D, typename T>
51  public:
52  typedef T EstimateType;
53  typedef std::stack<EstimateType,
54  std::vector<EstimateType, Eigen::aligned_allocator<EstimateType> > >
56 
57  static const int Dimension = D;
58 
59  typedef Eigen::Map<Eigen::Matrix<double, D, D, Eigen::ColMajor>, Eigen::Matrix<double, D, D, Eigen::ColMajor>::Flags & Eigen::AlignedBit ? Eigen::Aligned : Eigen::Unaligned > HessianBlockType;
60 
61  public:
62  BaseVertex();
63 
64  virtual const double& hessian(int i, int j) const { assert(i<D && j<D); return _hessian(i,j);}
65  virtual double& hessian(int i, int j) { assert(i<D && j<D); return _hessian(i,j);}
66  virtual double hessianDeterminant() const {return _hessian.determinant();}
67  virtual double* hessianData() { return const_cast<double*>(_hessian.data());}
68 
69  virtual void mapHessianMemory(double* d);
70 
71  virtual int copyB(double* b_) const {
72  memcpy(b_, _b.data(), Dimension * sizeof(double));
73  return Dimension;
74  }
75 
76  virtual const double& b(int i) const { assert(i < D); return _b(i);}
77  virtual double& b(int i) { assert(i < D); return _b(i);}
78  virtual double* bData() { return _b.data();}
79 
80  virtual void clearQuadraticForm();
81 
84  virtual double solveDirect(double lambda=0);
85 
87  Eigen::Matrix<double, D, 1, Eigen::ColMajor>& b() { return _b;}
88  const Eigen::Matrix<double, D, 1, Eigen::ColMajor>& b() const { return _b;}
90  HessianBlockType& A() { return _hessian;}
91  const HessianBlockType& A() const { return _hessian;}
92 
93  virtual void push() { _backup.push(_estimate);}
94  virtual void pop() { assert(!_backup.empty()); _estimate = _backup.top(); _backup.pop(); updateCache();}
95  virtual void discardTop() { assert(!_backup.empty()); _backup.pop();}
96  virtual int stackSize() const {return _backup.size();}
97 
99  const EstimateType& estimate() const { return _estimate;}
101  void setEstimate(const EstimateType& et) { _estimate = et; updateCache();}
102 
103  protected:
104  HessianBlockType _hessian;
105  Eigen::Matrix<double, D, 1, Eigen::ColMajor> _b;
106  EstimateType _estimate;
108  public:
109  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
110 };
111 
112 #include "base_vertex.hpp"
113 
114 } // end namespace g2o
115 
116 
117 #endif
virtual void push()
backup the position of the vertex to a stack
Definition: base_vertex.h:93
BackupStackType _backup
Definition: base_vertex.h:107
virtual double solveDirect(double lambda=0)
Definition: base_vertex.h:37
virtual void discardTop()
pop the last element from the stack, without restoring the current estimate
Definition: base_vertex.h:95
Eigen::Matrix< double, D, 1, Eigen::ColMajor > _b
Definition: base_vertex.h:105
const HessianBlockType & A() const
Definition: base_vertex.h:91
virtual const double & hessian(int i, int j) const
get the element from the hessian matrix
Definition: base_vertex.h:64
virtual const double & b(int i) const
get the b vector element
Definition: base_vertex.h:76
virtual int copyB(double *b_) const
Definition: base_vertex.h:71
Templatized BaseVertex.
Definition: base_vertex.h:50
virtual double & b(int i)
Definition: base_vertex.h:77
virtual double * bData()
return a pointer to the b vector associated with this vertex
Definition: base_vertex.h:78
HessianBlockType & A()
return the hessian block associated with the vertex
Definition: base_vertex.h:90
HessianBlockType _hessian
Definition: base_vertex.h:104
Eigen::Matrix< double, D, 1, Eigen::ColMajor > & b()
return right hand side b of the constructed linear system
Definition: base_vertex.h:87
virtual void clearQuadraticForm()
Definition: base_vertex.h:48
std::stack< EstimateType, std::vector< EstimateType, Eigen::aligned_allocator< EstimateType > > > BackupStackType
Definition: base_vertex.h:55
const Eigen::Matrix< double, D, 1, Eigen::ColMajor > & b() const
Definition: base_vertex.h:88
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
A general case Vertex for optimization.
virtual void pop()
restore the position of the vertex by retrieving the position from the stack
Definition: base_vertex.h:94
Eigen::Map< Eigen::Matrix< double, D, D, Eigen::ColMajor >, Eigen::Matrix< double, D, D, Eigen::ColMajor >::Flags &Eigen::AlignedBit?Eigen::Aligned:Eigen::Unaligned > HessianBlockType
Definition: base_vertex.h:59
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual double * hessianData()
Definition: base_vertex.h:67
virtual int stackSize() const
return the stack size
Definition: base_vertex.h:96
EstimateType _estimate
Definition: base_vertex.h:106
virtual double & hessian(int i, int j)
Definition: base_vertex.h:65
virtual double hessianDeterminant() const
Definition: base_vertex.h:66
virtual void mapHessianMemory(double *d)
Definition: base_vertex.h:53
static const int Dimension
dimension of the estimate (minimal) in the manifold space
Definition: base_vertex.h:57