4#include "optimizable_graph.h"
9 class ActivePathCostFunction;
23 friend class ActivePathCostFunction;
101 Eigen::Vector3<g_type> rho;
105 if (e->robustKernel())
107 e->robustKernel()->robustify(e->chi2(), rho);
162 for (
auto eit = v->
edges().begin(); eit != v->
edges().end(); ++eit)
182 _ivMap.resize(vlist.size());
184 for (
int k = 0; k < 2; k++)
185 for (
auto it = vlist.begin(); it != vlist.end(); ++it) {
205 _ivMap[i]->setHessianIndex(-1);
223 if (
edges().size() == 0)
225 lib_assert(
false,
": Attempt to initialize an empty graph");
235 for (
const auto& vset_it : vset)
241 for (
auto it = vEdges.begin(); it != vEdges.end(); ++it)
244 if (level < 0 || e->level() == level)
249 if (!vset.hasKey(e->
vertex(i)->
id()))
251 allVerticesOK =
false;
257 auxEdgeSet.insert(e);
270 for (
auto it = auxEdgeSet.begin(); it != auxEdgeSet.end(); ++it)
288 for (
auto it = eset.begin(); it != eset.end(); ++it)
297 for (
auto it = auxVertexSet.begin(); it != auxVertexSet.end(); ++it)
348 for (
auto it = vlist.begin(); it != vlist.end(); ++it)
354 for (
auto it = vlist.begin(); it != vlist.end(); ++it)
360 for (
auto it = vlist.begin(); it != vlist.end(); ++it)
370 for (
auto it = vlist.begin(); it != vlist.end(); ++it)
382 for (
auto it = vlist.begin(); it != vlist.end(); ++it)
447 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
The equivelent of std::vector but with a bit more control.
virtual const HGVertex * vertex(uint04 i) const =0
Returns a const pointer to the i-th vertex.
virtual uint04 vertexCount() const =0
Returns the number of vertices connected by this edge.
int id() const
returns the id
const Buffer< HGEdge * > & edges() const
returns the set of hyper-edges that are leaving/entering in this vertex
virtual void clear()
removes a vertex from the graph. Returns true on success (vertex was present)
const Dictionary< int, HGVertex * > & vertices() const
const Buffer< HGEdge * > & edges() const
Base edge class for the optimizable graph, adding error computation and robust kernels.
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.
virtual bool allVerticesFixed() const =0
Returns true if all vertices connected to this edge are fixed.
A general case Vertex for optimization.
bool fixed() const
true => this node is fixed during the optimization
virtual sint04 dimension() const =0
dimension of the estimated state belonging to this node
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
void oplus(const g_type *v)
Update the position of the node from the parameters in v.
virtual void pop()=0
restore the position of the vertex by retrieving the position from the stack
void setHessianIndex(int ti)
set the temporary index of the vertex in the parameter blocks
Generic interface for a non-linear solver operating on a graph.
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.
Sparse optimizer that manages active vertices and edges for graph-based optimization.
g_type activeChi2() const
Returns the total chi-squared error of all active edges.
void push() final override
Remove a vertex.
const VertexContainer & indexMapping() const
the index mapping of the vertices
void update(const g_type *update)
update the estimate of the active vertices
void pop(Set< HyperGraph::HGVertex * > &vlist) final override
pop (restore) the estimate a subset of the variables from the stack
void discardTop() final override
discard the last backup of the estimate for all variables by removing it from the stack
OGVertex * findGauge()
Finds a gauge vertex (first vertex with maximum dimension) for fixing.
void computeActiveErrors()
computes the error vectors of all edges in the activeSet, and caches them
bool * _forceStopFlag
External flag to force stopping the optimization.
OGVertex *const * findActiveVertex(const OGVertex *v) const
Finds an active vertex by pointer using binary search.
void pop() final override
pop (restore) the estimate of all variables from the stack
void sortVectorContainers()
Sorts active vertices and edges by their ID comparators for deterministic ordering.
void setForceStopFlag(bool *flag)
sets a variable checked at every iteration to force a user stop.
bool initializeOptimization(int level=0)
Initializes the structures for optimizing a portion of the graph specified by a subset of vertices.
VertexContainer _activeVertices
Active vertices, sorted by VertexIDCompare.
VertexContainer _ivMap
Index-to-vertex mapping for the Hessian.
bool isReadyToUpdate() const
Returns true if the index mapping has been built and the optimizer is ready.
void linearizeSystem()
Linearizes the system by computing the Jacobians for the nodes and edges in the graph.
bool initializeOptimization(Set< HyperGraph::HGVertex * > &eset)
Initializes optimization from a specific edge set.
bool gaugeFreedom()
Returns true if the graph has gauge freedom (no fixed vertex of maximum dimension).
void push(Set< HyperGraph::HGVertex * > &vlist) final override
push the estimate of a subset of the variables onto a stack
void clear() final override
Clears all internal structures and the base graph.
void clearIndexMapping()
Clears the index mapping, resetting all vertex Hessian indices to -1.
OptimizableGraph::OGEdge *const * findActiveEdge(const OptimizableGraph::OGEdge *e) const
Finds an active edge by pointer using binary search.
EdgeContainer _activeEdges
Active edges, sorted by EdgeIDCompare.
g_type activeRobustChi2() const
Returns the total robustified chi-squared error of all active edges.
bool terminate()
if external stop flag is given, return its state. False otherwise
const VertexContainer & activeVertices() const
the vertices active in the current optimization
bool buildIndexMapping(SparseOptimizer::VertexContainer &vlist)
Builds the index mapping from active vertices to Hessian positions.
bool * forceStopFlag() const
Returns the external force-stop flag pointer.
const EdgeContainer & activeEdges() const
the edges active in the current optimization
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 > ...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
order edges based on the internal ID, which is assigned to the edge in addEdge()
order vertices based on their ID
OptimizableGraph()
empty constructor
JacobianWorkspace _jacobianWorkspace
Workspace for computing Jacobians.
Buffer< OptimizableGraph::OGVertex * > VertexContainer
vector container for vertices
Buffer< OptimizableGraph::OGEdge * > EdgeContainer
vector container for edges
@ AT_NUM_ELEMENTS
Sentinel value; keep as last element.