g2o
Loading...
Searching...
No Matches
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 <Eigen/Cholesky>
31#include <Eigen/Core>
32#include <Eigen/Dense>
33#include <cassert>
34#include <stack>
35
36#include "creators.h"
37#include "g2o/stuff/macros.h"
38#include "optimizable_graph.h"
39
40namespace g2o {
41#define G2O_VERTEX_DIM ((D == Eigen::Dynamic) ? _dimension : D)
50template <int D, typename T>
52 public:
53 using EstimateType = T;
54 using BackupStackType = std::stack<EstimateType, std::vector<EstimateType> >;
55
56 static const int Dimension =
57 D;
58
60 Eigen::Map<Eigen::Matrix<double, D, D, Eigen::ColMajor>,
61 Eigen::Matrix<double, D, D, Eigen::ColMajor>::Flags &
62 Eigen::PacketAccessBit
63 ? Eigen::Aligned
64 : Eigen::Unaligned>;
65
66 public:
67 BaseVertex();
68 BaseVertex& operator=(const BaseVertex&) = delete;
69 BaseVertex(const BaseVertex&) = delete;
70
71 virtual const double& hessian(int i, int j) const {
72 assert(i < G2O_VERTEX_DIM && j < G2O_VERTEX_DIM);
73 return _hessian(i, j);
74 }
75 virtual double& hessian(int i, int j) {
76 assert(i < G2O_VERTEX_DIM && j < G2O_VERTEX_DIM);
77 return _hessian(i, j);
78 }
79 virtual double hessianDeterminant() const { return _hessian.determinant(); }
80 virtual double* hessianData() { return const_cast<double*>(_hessian.data()); }
81
82 inline virtual void mapHessianMemory(double* d);
83
84 virtual int copyB(double* b_) const {
85 const int vertexDim = G2O_VERTEX_DIM;
86 memcpy(b_, _b.data(), vertexDim * sizeof(double));
87 return vertexDim;
88 }
89
90 virtual const double& b(int i) const {
91 assert(i < D);
92 return _b(i);
93 }
94 virtual double& b(int i) {
95 assert(i < G2O_VERTEX_DIM);
96 return _b(i);
97 }
98 virtual double* bData() { return _b.data(); }
99
100 inline virtual void clearQuadraticForm();
101
104 inline virtual double solveDirect(double lambda = 0);
105
107 Eigen::Matrix<double, D, 1, Eigen::ColMajor>& b() { return _b; }
108 const Eigen::Matrix<double, D, 1, Eigen::ColMajor>& b() const { return _b; }
111 const HessianBlockType& A() const { return _hessian; }
112
113 virtual void push() { _backup.push(_estimate); }
114 virtual void pop() {
115 assert(!_backup.empty());
116 _estimate = _backup.top();
117 _backup.pop();
118 updateCache();
119 }
120 virtual void discardTop() {
121 assert(!_backup.empty());
122 _backup.pop();
123 }
124 virtual int stackSize() const { return _backup.size(); }
125
127 const EstimateType& estimate() const { return _estimate; }
129 void setEstimate(const EstimateType& et) {
130 _estimate = et;
131 updateCache();
132 }
133
134 protected:
136 Eigen::Matrix<double, D, 1, Eigen::ColMajor> _b;
139
140 public:
141 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
142};
143
144#include "base_vertex.hpp"
145
146#undef G2O_VERTEX_DIM
147
148} // end namespace g2o
149
150#endif
#define G2O_VERTEX_DIM
Definition base_vertex.h:41
Templatized BaseVertex.
Definition base_vertex.h:51
virtual double solveDirect(double lambda=0)
virtual double hessianDeterminant() const
Definition base_vertex.h:79
BaseVertex & operator=(const BaseVertex &)=delete
virtual void clearQuadraticForm()
virtual double & b(int i)
Definition base_vertex.h:94
Eigen::Matrix< double, D, 1, Eigen::ColMajor > _b
BaseVertex(const BaseVertex &)=delete
Eigen::Matrix< double, D, 1, Eigen::ColMajor > & b()
return right hand side b of the constructed linear system
virtual int copyB(double *b_) const
Definition base_vertex.h:84
const HessianBlockType & A() const
virtual void pop()
virtual void mapHessianMemory(double *d)
virtual double * bData()
return a pointer to the b vector associated with this vertex
Definition base_vertex.h:98
virtual double * hessianData()
Definition base_vertex.h:80
virtual void discardTop()
virtual int stackSize() const
return the stack size
const EstimateType & estimate() const
return the current estimate of the vertex
std::stack< EstimateType, std::vector< EstimateType > > BackupStackType
Definition base_vertex.h:54
BackupStackType _backup
static const int Dimension
dimension of the estimate (minimal) in the manifold space
Definition base_vertex.h:56
Eigen::Map< Eigen::Matrix< double, D, D, Eigen::ColMajor >, Eigen::Matrix< double, D, D, Eigen::ColMajor >::Flags &Eigen::PacketAccessBit ? Eigen::Aligned :Eigen::Unaligned > HessianBlockType
Definition base_vertex.h:64
EstimateType _estimate
virtual double & hessian(int i, int j)
Definition base_vertex.h:75
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
virtual const double & hessian(int i, int j) const
get the element from the hessian matrix
Definition base_vertex.h:71
HessianBlockType & A()
return the hessian block associated with the vertex
virtual void push()
backup the position of the vertex to a stack
virtual const double & b(int i) const
get the b vector element
Definition base_vertex.h:90
const Eigen::Matrix< double, D, 1, Eigen::ColMajor > & b() const
HessianBlockType _hessian
A general case Vertex for optimization.