7#include "openmp_mutex.h"
8#include "hyper_graph.h"
9#include "jacobian_workspace.h"
12#include "optimization_algorithm_property.h"
13#include "robust_kernel.h"
25 class HyperGraphAction;
58 friend struct OptimizableGraph;
60 ~Data() {
delete _next; };
62 const Data* next()
const {
return _next; }
63 Data* next() {
return _next; }
64 void setNext(Data* next_) { _next = next_; }
66 Data* _next =
nullptr;
75 return v1->
id() < v2->
id();
83 bool operator() (
const OGEdge* e1,
const OGEdge* e2)
const
99 friend struct OptimizableGraph;
114 virtual const g_type&
hessian(
int i,
int j)
const = 0;
115 virtual g_type&
hessian(
int i,
int j) = 0;
116 virtual g_type hessianDeterminant()
const = 0;
117 virtual g_type* hessianData() = 0;
129 virtual const g_type&
b(
int i)
const = 0;
130 virtual g_type&
b(
int i) = 0;
163 assert((dim == -1) || (estimate.size() == std::size_t(dim)));
185 estimate.resize(dim);
213 assert((dim == -1) || (estimate.size() == std::size_t(dim)));
235 estimate.resize(dim);
270 int G2O_ATTRIBUTE_DEPRECATED(tempIndex()
const) {
return hessianIndex(); }
273 void G2O_ATTRIBUTE_DEPRECATED(setTempIndex(
int ti)) {
setHessianIndex(ti); }
326 friend struct OptimizableGraph;
357 virtual g_type
chi2()
const = 0;
418 lib_assert(!
vertex(v.id()),
"Vertex with this ID already contained in the graph");
431 lib_assert(e,
"Edge does not inherit from OptimizableGraph::OGEdge");
445 for (
auto it = this->
edges().begin(); it != this->
edges().end(); ++it)
510 for (
auto it = vset.begin(); it != vset.end(); ++it) {
518 for (
auto it = vset.begin(); it != vset.end(); ++it) {
528 for (
auto it = vset.begin(); it != vset.end(); ++it)
543 if (vertDims_.size() == 0)
545 const Set<sint04>& vertDims = vertDims_.
size() == 0 ? auxDims : vertDims_;
546 bool suitableSolver =
true;
547 if (vertDims.
size() == 2)
550 suitableSolver = vertDims.count(solverProperty.
poseDim) == 1 && vertDims.count(solverProperty.
landmarkDim) == 1;
552 suitableSolver = solverProperty.
poseDim == -1;
554 else if (vertDims.
size() == 1)
556 suitableSolver = vertDims.count(solverProperty.
poseDim) == 1 || solverProperty.
poseDim == -1;
562 return suitableSolver;
The equivelent of std::vector but with a bit more control.
abstract Vertex, your types must derive from that one
int _id
Unique identifier for this vertex.
int id() const
returns the id
HyperGraph()
constructs an empty hyper graph
virtual void clear()
removes a vertex from the graph. Returns true on success (vertex was present)
virtual bool addEdge(HGEdge *e)
Adds an edge to the graph.
const Dictionary< int, HGVertex * > & vertices() const
const Buffer< HGEdge * > & edges() const
Dictionary< int, HGVertex * > _vertices
Map from vertex id to vertex pointer.
virtual bool addVertex(HGVertex &v)
adds a vertex to the graph.
HGVertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
provide memory workspace for computing the Jacobians
Base edge class for the optimizable graph, adding error computation and robust kernels.
virtual void mapHessianMemory(g_type *d, int i, int j, bool rowMajor)=0
maps the internal matrix to some external memory location, you need to provide the memory before call...
RobustKernel * _robustKernel
Optional robust kernel for this edge.
virtual void linearizeOplusAndConstructQuadraticForm(JacobianWorkspace &jacobianWorkspace)=0
Linearizes the constraint in the edge in the manifold space, and store the result in the given worksp...
virtual const g_type * informationData() const =0
returns the memory of the information matrix, usable for example with a Eigen::Map<MatrixXd>
virtual void computeError()=0
Computes the error of the edge and stores it internally.
void clearRobustKernel()
Removes the robust kernel from this edge.
OGEdge()
Default constructor.
int level() const
returns the level of the edge
virtual sint04 dimension() const =0
returns the dimensions of the error function
virtual g_type chi2() const =0
computes the chi2 based on the cached error value, only valid after computeError has been called.
void setLevel(int l)
sets the level of the edge
int _level
Optimization level for multi-level optimization.
int _internalId
Internal sequential id assigned on insertion.
virtual bool allVerticesFixed() const =0
Returns true if all vertices connected to this edge are fixed.
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
long long internalId() const
the internal ID of the edge
void setRobustKernel(RobustKernel &ptr)
specify the robust kernel to be used in this edge
A general case Vertex for optimization.
virtual const g_type & b(int i) const =0
get the b vector element
int _hessianIndex
Index of this vertex in the Hessian.
virtual bool getEstimateData(Buffer< g_type > &estimate) const
writes the estimater to an array of g_type
bool setEstimateData(const Buffer< g_type > &estimate)
sets the initial estimate from an array of g_type Implement setEstimateDataImpl()
bool _fixed
Whether this vertex is fixed during optimization.
bool fixed() const
true => this node is fixed during the optimization
virtual bool getMinimalEstimateData(Buffer< g_type > &estimate) const
writes the estimate to an array of g_type
virtual bool setMinimalEstimateDataImpl(const g_type *)
sets the initial estimate from an array of g_type
virtual void mapHessianMemory(g_type *d)=0
maps the internal matrix to some external memory location
virtual g_type solveDirect(g_type lambda=0)=0
updates the current vertex with the direct solution x += H_ii\b_ii
void setColInHessian(int c)
set the row of this vertex in the Hessian
virtual sint04 copyB(g_type *b_) const =0
copies the b vector in the array b_
virtual sint04 dimension() const =0
dimension of the estimated state belonging to this node
virtual sint04 estimateDimension() const
returns the dimension of the extended representation used by get/setEstimate(g_type*) -1 if it is not...
virtual void discardTop()=0
pop the last element from the stack, without restoring the current estimate
virtual g_type * bData()=0
return a pointer to the b vector associated with this vertex
virtual void setId(int id)
sets the id of the node in the graph be sure that the graph keeps consistent after changing the id
virtual int stackSize() const =0
return the stack size
bool setEstimateData(const g_type *estimate)
sets the initial estimate from an array of g_type Implement setEstimateDataImpl()
virtual void clearQuadraticForm()=0
set the b vector part of this vertex to zero
int hessianIndex() const
temporary index of this node in the parameter vector obtained from linearization
virtual bool getMinimalEstimateData(g_type *) const
writes the estimate to an array of g_type
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
int _colInHessian
Column of this vertex in the Hessian matrix.
virtual void oplusImpl(const g_type *v)=0
update the position of the node from the parameters in v.
virtual bool getEstimateData(g_type *) const
writes the estimater to an array of g_type
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
virtual sint04 minimalEstimateDimension() const
returns the dimension of the extended representation used by get/setEstimate(g_type*) -1 if it is not...
bool _marginalized
Whether this vertex is marginalized (Schur complement).
virtual const g_type & hessian(int i, int j) const =0
get the element from the hessian matrix
bool marginalized() const
true => this node is marginalized out during the optimization
virtual void push()=0
backup the position of the vertex to a stack
bool setMinimalEstimateData(const Buffer< g_type > &estimate)
sets the initial estimate from an array of g_type.
void oplus(const g_type *v)
Update the position of the node from the parameters in v.
int colInHessian() const
get the row of this vertex in the Hessian
virtual void pop()=0
restore the position of the vertex by retrieving the position from the stack
bool setMinimalEstimateData(const g_type *estimate)
sets the initial estimate from an array of g_type.
void setHessianIndex(int ti)
set the temporary index of the vertex in the parameter blocks
virtual bool setEstimateDataImpl(const g_type *)
writes the estimater to an array of g_type
base for all robust cost functions
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
uint04 size() const
Returns the number of elements in the Set.
The primary namespace for the NDEVR SDK.
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
order edges based on the internal ID, which is assigned to the edge in addEdge()
order vertices based on their ID
This is an abstract class that represents one optimization problem.
OptimizableGraph()
empty constructor
virtual bool addEdge(HyperGraph::HGEdge *e_) final override
adds a new edge.
sint04 maxDimension() const
return the maximum dimension of all vertices in the graph
JacobianWorkspace _jacobianWorkspace
Workspace for computing Jacobians.
virtual void push()
push the estimate of all variables onto a stack
Buffer< OptimizableGraph::OGVertex * > VertexContainer
vector container for vertices
virtual bool addVertex(HyperGraph::HGVertex &v) final override
adds a new vertex.
int _nextEdgeId
Counter for assigning internal edge IDs.
JacobianWorkspace & jacobianWorkspace()
verify that all the information of the edges are semi positive definite, i.e., all Eigenvalues are >=...
Set< sint04 > dimensions() const
iterates over all vertices and returns a set of all the vertex dimensions in the graph
virtual void discardTop()
discard the last backup of the estimate for all variables by removing it from the stack
virtual void setFixed(Set< HyperGraph::HGVertex * > &vset, bool fixed)
fixes/releases a set of vertices
Buffer< OptimizableGraph::OGEdge * > EdgeContainer
vector container for edges
ActionType
Types of actions that can be registered for optimization callbacks.
@ AT_POSTITERATION
Action invoked after each iteration.
@ AT_NUM_ELEMENTS
Sentinel value; keep as last element.
@ AT_PREITERATION
Action invoked before each iteration.
virtual void push(Set< HyperGraph::HGVertex * > &vset)
push the estimate of a subset of the variables onto a stack
const JacobianWorkspace & jacobianWorkspace() const
Returns a const reference to the Jacobian workspace.
bool isSolverSuitable(const OptimizationAlgorithmProperty &solverProperty, const Set< sint04 > &vertDims_=Set< int >()) const
test whether a solver is suitable for optimizing this graph.
g_type chi2() const
returns the chi2 of the current configuration
virtual void pop(Set< HyperGraph::HGVertex * > &vset)
pop (restore) the estimate a subset of the variables from the stack
virtual void pop()
pop (restore) the estimate of all variables from the stack
describe the properties of a solver
bool requiresMarginalize
whether the solver requires marginalization of landmarks
sint04 landmarkDim
dimension of the landmar vertices (-1 if variable)
sint04 poseDim
dimension of the pose vertices (-1 if variable)