g2o
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
g2o::BaseVariableSizedEdge< D, E > Class Template Reference

base class to represent an edge connecting an arbitrary number of nodes More...

#include <base_variable_sized_edge.h>

Inheritance diagram for g2o::BaseVariableSizedEdge< D, E >:
Inheritance graph
[legend]
Collaboration diagram for g2o::BaseVariableSizedEdge< D, E >:
Collaboration graph
[legend]

Classes

struct  HessianHelper
 helper for mapping the Hessian memory of the upper triangular block More...
 

Public Types

typedef BaseEdge< D, E >::Measurement Measurement
 
typedef MatrixX::MapType JacobianType
 
typedef BaseEdge< D, E >::ErrorVector ErrorVector
 
typedef BaseEdge< D, E >::InformationType InformationType
 
typedef Eigen::Map< MatrixX, MatrixX::Flags &Eigen::PacketAccessBit ? Eigen::Aligned :Eigen::Unaligned > HessianBlockType
 
- Public Types inherited from g2o::BaseEdge< D, E >
typedef E Measurement
 
typedef internal::BaseEdgeTraits< D >::ErrorVector ErrorVector
 
typedef internal::BaseEdgeTraits< D >::InformationType InformationType
 

Public Member Functions

 BaseVariableSizedEdge ()
 
virtual void linearizeOplus (JacobianWorkspace &jacobianWorkspace)
 
virtual void linearizeOplus ()
 
virtual void resize (size_t size)
 
virtual bool allVerticesFixed () const
 
virtual void constructQuadraticForm ()
 
virtual void mapHessianMemory (double *d, int i, int j, bool rowMajor)
 
- Public Member Functions inherited from g2o::BaseEdge< D, E >
 BaseEdge ()
 
BaseEdgeoperator= (const BaseEdge &)=delete
 
 BaseEdge (const BaseEdge &)=delete
 
virtual ~BaseEdge ()
 
virtual double chi2 () const
 
virtual const double * errorData () const
 returns the error vector cached after calling the computeError;
 
virtual double * errorData ()
 
const ErrorVectorerror () const
 
ErrorVectorerror ()
 
EIGEN_STRONG_INLINE const InformationTypeinformation () const
 information matrix of the constraint
 
EIGEN_STRONG_INLINE InformationTypeinformation ()
 
void setInformation (const InformationType &information)
 
virtual const double * informationData () const
 
virtual double * informationData ()
 
EIGEN_STRONG_INLINE const Measurementmeasurement () const
 accessor functions for the measurement represented by the edge
 
virtual void setMeasurement (const Measurement &m)
 
virtual int rank () const
 
virtual void initialEstimate (const OptimizableGraph::VertexSet &, OptimizableGraph::Vertex *)
 
template<int Dim = D>
std::enable_if< Dim==-1, void >::type setDimension (int dim)
 
- Public Member Functions inherited from g2o::OptimizableGraph::Edge
 Edge ()
 
virtual ~Edge ()
 
virtual void computeError ()=0
 
virtual bool setMeasurementData (const double *m)
 
virtual bool getMeasurementData (double *m) const
 
virtual int measurementDimension () const
 
virtual bool setMeasurementFromState ()
 
RobustKernelrobustKernel () const
 if NOT NULL, error of this edge will be robustifed with the kernel
 
void setRobustKernel (RobustKernel *ptr)
 
virtual double initialEstimatePossible (const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
 
int level () const
 returns the level of the edge
 
void setLevel (int l)
 sets the level of the edge
 
int dimension () const
 returns the dimensions of the error function
 
 G2O_ATTRIBUTE_DEPRECATED (virtual Vertex *createFrom())
 
 G2O_ATTRIBUTE_DEPRECATED (virtual Vertex *createTo())
 
virtual VertexcreateVertex (int)
 
virtual bool read (std::istream &is)=0
 read the vertex from a stream, i.e., the internal state of the vertex
 
virtual bool write (std::ostream &os) const =0
 write the vertex to a stream
 
long long internalId () const
 the internal ID of the edge
 
OptimizableGraphgraph ()
 
const OptimizableGraphgraph () const
 
bool setParameterId (int argNum, int paramId)
 
const Parameterparameter (int argNo) const
 
size_t numParameters () const
 
void resizeParameters (size_t newSize)
 
- Public Member Functions inherited from g2o::HyperGraph::Edge
 Edge (int id=InvalidId)
 creates and empty edge with no vertices
 
const VertexContainervertices () const
 
VertexContainervertices ()
 
const Vertexvertex (size_t i) const
 
Vertexvertex (size_t i)
 
void setVertex (size_t i, Vertex *v)
 
int id () const
 
void setId (int id)
 
virtual HyperGraphElementType elementType () const
 
int numUndefinedVertices () const
 
- Public Member Functions inherited from g2o::HyperGraph::HyperGraphElement
virtual ~HyperGraphElement ()
 
- Public Member Functions inherited from g2o::HyperGraph::DataContainer
 DataContainer ()
 
virtual ~DataContainer ()
 
const DatauserData () const
 the user data associated with this vertex
 
DatauserData ()
 
void setUserData (Data *obs)
 
void addUserData (Data *obs)
 

Static Public Attributes

static constexpr int Dimension = BaseEdge<D, E>::Dimension
 
- Static Public Attributes inherited from g2o::BaseEdge< D, E >
static constexpr int Dimension = internal::BaseEdgeTraits<D>::Dimension
 

Protected Member Functions

void computeQuadraticForm (const InformationType &omega, const ErrorVector &weightedError)
 
- Protected Member Functions inherited from g2o::BaseEdge< D, E >
InformationType robustInformation (const Vector3 &rho) const
 
bool writeInformationMatrix (std::ostream &os) const
 write the upper trinagular part of the information matrix into the stream
 
bool readInformationMatrix (std::istream &is)
 
bool writeParamIds (std::ostream &os) const
 write the param IDs that are potentially used by the edge
 
bool readParamIds (std::istream &is)
 reads the param IDs from the stream
 
- Protected Member Functions inherited from g2o::OptimizableGraph::Edge
template<typename ParameterType >
bool installParameter (ParameterType *&p, size_t argNo, int paramId=-1)
 
template<typename CacheType >
void resolveCache (CacheType *&cache, OptimizableGraph::Vertex *, const std::string &_type, const ParameterVector &parameters)
 
bool resolveParameters ()
 
virtual bool resolveCaches ()
 

Protected Attributes

std::vector< HessianHelper_hessian
 
std::vector< JacobianType_jacobianOplus
 jacobians of the edge (w.r.t. oplus)
 
- Protected Attributes inherited from g2o::BaseEdge< D, E >
Measurement _measurement
 the measurement of the edge
 
InformationType _information
 
ErrorVector _error
 
- Protected Attributes inherited from g2o::OptimizableGraph::Edge
int _dimension
 
int _level
 
RobustKernel_robustKernel
 
long long _internalId
 
std::vector< int > _cacheIds
 
std::vector< std::string > _parameterTypes
 
std::vector< Parameter ** > _parameters
 
std::vector< int > _parameterIds
 
- Protected Attributes inherited from g2o::HyperGraph::Edge
VertexContainer _vertices
 
int _id
 unique id
 
- Protected Attributes inherited from g2o::HyperGraph::DataContainer
Data_userData
 

Detailed Description

template<int D, typename E>
class g2o::BaseVariableSizedEdge< D, E >

base class to represent an edge connecting an arbitrary number of nodes

D - Dimension of the measurement E - type to represent the measurement

Definition at line 50 of file base_variable_sized_edge.h.

Member Typedef Documentation

◆ ErrorVector

template<int D, typename E >
typedef BaseEdge<D,E>::ErrorVector g2o::BaseVariableSizedEdge< D, E >::ErrorVector

Definition at line 65 of file base_variable_sized_edge.h.

◆ HessianBlockType

template<int D, typename E >
typedef Eigen::Map<MatrixX, MatrixX::Flags & Eigen::PacketAccessBit ? Eigen::Aligned : Eigen::Unaligned> g2o::BaseVariableSizedEdge< D, E >::HessianBlockType

Definition at line 70 of file base_variable_sized_edge.h.

◆ InformationType

template<int D, typename E >
typedef BaseEdge<D,E>::InformationType g2o::BaseVariableSizedEdge< D, E >::InformationType

Definition at line 66 of file base_variable_sized_edge.h.

◆ JacobianType

template<int D, typename E >
typedef MatrixX::MapType g2o::BaseVariableSizedEdge< D, E >::JacobianType

Definition at line 64 of file base_variable_sized_edge.h.

◆ Measurement

template<int D, typename E >
typedef BaseEdge<D,E>::Measurement g2o::BaseVariableSizedEdge< D, E >::Measurement

Definition at line 63 of file base_variable_sized_edge.h.

Constructor & Destructor Documentation

◆ BaseVariableSizedEdge()

template<int D, typename E >
g2o::BaseVariableSizedEdge< D, E >::BaseVariableSizedEdge ( )
inline

Definition at line 72 of file base_variable_sized_edge.h.

72: BaseEdge<D, E>() {}

Member Function Documentation

◆ allVerticesFixed()

template<int D, typename E >
bool BaseVariableSizedEdge::allVerticesFixed ( ) const
virtual

Implements g2o::OptimizableGraph::Edge.

Definition at line 147 of file base_variable_sized_edge.hpp.

147 {
148 for (size_t i = 0; i < _vertices.size(); ++i) {
149 if (!static_cast<const OptimizableGraph::Vertex*>(_vertices[i])->fixed()) {
150 return false;
151 }
152 }
153 return true;
154}
VertexContainer _vertices

◆ computeQuadraticForm()

template<int D, typename E >
void BaseVariableSizedEdge::computeQuadraticForm ( const InformationType omega,
const ErrorVector weightedError 
)
protected

Definition at line 157 of file base_variable_sized_edge.hpp.

158 {
159 for (size_t i = 0; i < _vertices.size(); ++i) {
160 OptimizableGraph::Vertex* from =
161 static_cast<OptimizableGraph::Vertex*>(_vertices[i]);
162 bool istatus = !(from->fixed());
163
164 if (istatus) {
165 const JacobianType& A = _jacobianOplus[i];
166
167 MatrixX AtO = A.transpose() * omega;
168 int fromDim = from->dimension();
169 assert(fromDim >= 0);
170 Eigen::Map<MatrixX> fromMap(from->hessianData(), fromDim, fromDim);
171 Eigen::Map<VectorX> fromB(from->bData(), fromDim);
172
173 // ii block in the hessian
174 {
175 internal::QuadraticFormLock lck(*from);
176 fromMap.noalias() += AtO * A;
177 fromB.noalias() += A.transpose() * weightedError;
178 }
179
180 // compute the off-diagonal blocks ij for all j
181 for (size_t j = i + 1; j < _vertices.size(); ++j) {
182 OptimizableGraph::Vertex* to =
183 static_cast<OptimizableGraph::Vertex*>(_vertices[j]);
184
185 bool jstatus = !(to->fixed());
186 if (jstatus) {
187 internal::QuadraticFormLock lck(*to);
188 const JacobianType& B = _jacobianOplus[j];
190 assert(idx < (int)_hessian.size());
191 HessianHelper& hhelper = _hessian[idx];
192 if (hhelper
193 .transposed) { // we have to write to the block as transposed
194 hhelper.matrix.noalias() += B.transpose() * AtO.transpose();
195 } else {
196 hhelper.matrix.noalias() += AtO * B;
197 }
198 }
199 }
200 }
201 }
202}
std::vector< JacobianType > _jacobianOplus
jacobians of the edge (w.r.t. oplus)
std::vector< HessianHelper > _hessian
MatrixN< Eigen::Dynamic > MatrixX
Definition eigen_types.h:74
int computeUpperTriangleIndex(int i, int j)

References g2o::OptimizableGraph::Vertex::bData(), internal::computeUpperTriangleIndex(), g2o::OptimizableGraph::Vertex::dimension(), g2o::OptimizableGraph::Vertex::fixed(), g2o::OptimizableGraph::Vertex::hessianData(), and g2o::BaseVariableSizedEdge< D, E >::HessianHelper::matrix.

◆ constructQuadraticForm()

template<int D, typename E >
void BaseVariableSizedEdge::constructQuadraticForm ( )
virtual

Linearizes the constraint in the edge. Makes side effect on the vertices of the graph by changing the parameter vector b and the hessian blocks ii and jj. The off diagoinal block is accessed via _hessian.

Implements g2o::OptimizableGraph::Edge.

Definition at line 37 of file base_variable_sized_edge.hpp.

37 {
38 if (this->robustKernel()) {
39 double error = this->chi2();
40 Vector3 rho;
41 this->robustKernel()->robustify(error, rho);
42 Eigen::Matrix<double, D, 1, Eigen::ColMajor> omega_r =
44 omega_r *= rho[1];
45 computeQuadraticForm(this->robustInformation(rho), omega_r);
46 } else {
48 }
49}
InformationType _information
Definition base_edge.h:147
virtual double chi2() const
Definition base_edge.h:99
const ErrorVector & error() const
Definition base_edge.h:103
InformationType robustInformation(const Vector3 &rho) const
Definition base_edge.h:156
ErrorVector _error
Definition base_edge.h:149
void computeQuadraticForm(const InformationType &omega, const ErrorVector &weightedError)
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
virtual void robustify(double squaredError, Vector3 &rho) const =0
VectorN< 3 > Vector3
Definition eigen_types.h:51

◆ linearizeOplus() [1/2]

template<int D, typename E >
void BaseVariableSizedEdge::linearizeOplus ( )
virtual

Linearizes the oplus operator in the vertex, and stores the result in temporary variable vector _jacobianOplus

Reimplemented in g2o::EdgeSE2LotsOfXY, and g2o::EdgeSE3LotsOfXYZ.

Definition at line 66 of file base_variable_sized_edge.hpp.

66 {
67 const double delta = cst(1e-9);
68 const double scalar = 1 / (2 * delta);
69 ErrorVector errorBak;
70 ErrorVector errorBeforeNumeric = _error;
71
72 for (size_t i = 0; i < _vertices.size(); ++i) {
73 // Xi - estimate the jacobian numerically
74 OptimizableGraph::Vertex* vi =
75 static_cast<OptimizableGraph::Vertex*>(_vertices[i]);
76
77 if (vi->fixed()) {
78 continue;
79 }
80
81 internal::QuadraticFormLock lck(*vi);
82 const int vi_dim = vi->dimension();
83 assert(vi_dim >= 0);
84
85 assert(_dimension >= 0);
86 assert(_jacobianOplus[i].rows() == _dimension &&
87 _jacobianOplus[i].cols() == vi_dim &&
88 "jacobian cache dimension does not match");
89 _jacobianOplus[i].resize(_dimension, vi_dim);
90 // add small step along the unit vector in each dimension
91 ceres::internal::FixedArray<double> add_vi(vi_dim);
92 add_vi.fill(0.);
93 for (int d = 0; d < vi_dim; ++d) {
94 vi->push();
95 add_vi[d] = delta;
96 vi->oplus(add_vi.data());
98 errorBak = _error;
99 vi->pop();
100 vi->push();
101 add_vi[d] = -delta;
102 vi->oplus(add_vi.data());
103 computeError();
104 errorBak -= _error;
105 vi->pop();
106 add_vi[d] = 0.0;
107
108 _jacobianOplus[i].col(d) = scalar * errorBak;
109 } // end dimension
110 _error = errorBeforeNumeric;
111 }
112}
BaseEdge< D, E >::ErrorVector ErrorVector
virtual void computeError()=0
constexpr double cst(long double v)
Definition misc.h:60

References g2o::cst().

◆ linearizeOplus() [2/2]

template<int D, typename E >
void BaseVariableSizedEdge::linearizeOplus ( JacobianWorkspace jacobianWorkspace)
virtual

Linearizes the constraint in the edge in the manifold space, and store the result in the given workspace

Implements g2o::OptimizableGraph::Edge.

Definition at line 52 of file base_variable_sized_edge.hpp.

53 {
54 for (size_t i = 0; i < _vertices.size(); ++i) {
55 OptimizableGraph::Vertex* v =
56 static_cast<OptimizableGraph::Vertex*>(_vertices[i]);
57 assert(v->dimension() >= 0);
58 new (&_jacobianOplus[i])
59 JacobianType(jacobianWorkspace.workspaceForVertex(i),
60 D < 0 ? _dimension : D, v->dimension());
61 }
63}

References g2o::OptimizableGraph::Vertex::dimension(), and g2o::JacobianWorkspace::workspaceForVertex().

◆ mapHessianMemory()

template<int D, typename E >
void BaseVariableSizedEdge::mapHessianMemory ( double *  d,
int  i,
int  j,
bool  rowMajor 
)
virtual

maps the internal matrix to some external memory location, you need to provide the memory before calling constructQuadraticForm

Parameters
dthe memory location to which we map
iindex of the vertex i
jindex of the vertex j (j > i, upper triangular fashion)
rowMajorif true, will write in rowMajor order to the block. Since EIGEN is columnMajor by default, this results in writing the transposed

Implements g2o::OptimizableGraph::Edge.

Definition at line 115 of file base_variable_sized_edge.hpp.

116 {
118 assert(idx < (int)_hessian.size());
119 OptimizableGraph::Vertex* vi =
120 static_cast<OptimizableGraph::Vertex*>(HyperGraph::Edge::vertex(i));
121 OptimizableGraph::Vertex* vj =
122 static_cast<OptimizableGraph::Vertex*>(HyperGraph::Edge::vertex(j));
123 assert(vi->dimension() >= 0);
124 assert(vj->dimension() >= 0);
125 HessianHelper& h = _hessian[idx];
126 if (rowMajor) {
127 if (h.matrix.data() != d || h.transposed != rowMajor)
128 new (&h.matrix) HessianBlockType(d, vj->dimension(), vi->dimension());
129 } else {
130 if (h.matrix.data() != d || h.transposed != rowMajor)
131 new (&h.matrix) HessianBlockType(d, vi->dimension(), vj->dimension());
132 }
133 h.transposed = rowMajor;
134}
Eigen::Map< MatrixX, MatrixX::Flags &Eigen::PacketAccessBit ? Eigen::Aligned :Eigen::Unaligned > HessianBlockType
const Vertex * vertex(size_t i) const

References internal::computeUpperTriangleIndex(), g2o::OptimizableGraph::Vertex::dimension(), g2o::BaseVariableSizedEdge< D, E >::HessianHelper::matrix, and g2o::BaseVariableSizedEdge< D, E >::HessianHelper::transposed.

◆ resize()

template<int D, typename E >
void BaseVariableSizedEdge::resize ( size_t  size)
virtual

resizes the number of vertices connected by this edge

Reimplemented from g2o::HyperGraph::Edge.

Definition at line 137 of file base_variable_sized_edge.hpp.

137 {
139 int n = (int)_vertices.size();
140 int maxIdx = (n * (n - 1)) / 2;
141 assert(maxIdx >= 0);
142 _hessian.resize(maxIdx);
143 _jacobianOplus.resize(size, JacobianType(0, 0, 0));
144}
virtual void resize(size_t size)

Member Data Documentation

◆ _hessian

template<int D, typename E >
std::vector<HessianHelper> g2o::BaseVariableSizedEdge< D, E >::_hessian
protected

Definition at line 99 of file base_variable_sized_edge.h.

◆ _jacobianOplus

template<int D, typename E >
std::vector<JacobianType> g2o::BaseVariableSizedEdge< D, E >::_jacobianOplus
protected

jacobians of the edge (w.r.t. oplus)

Definition at line 101 of file base_variable_sized_edge.h.

◆ Dimension

template<int D, typename E >
constexpr int g2o::BaseVariableSizedEdge< D, E >::Dimension = BaseEdge<D, E>::Dimension
staticconstexpr

Definition at line 62 of file base_variable_sized_edge.h.


The documentation for this class was generated from the following files: